Audacity 3.2.0
Public Member Functions | Protected Member Functions | List of all members
wxWidgetsBasicUI Class Referencefinal

An implementation of BasicUI::Services in terms of the wxWidgets toolkit. More...

#include <wxWidgetsBasicUI.h>

Inheritance diagram for wxWidgetsBasicUI:
[legend]
Collaboration diagram for wxWidgetsBasicUI:
[legend]

Public Member Functions

 ~wxWidgetsBasicUI () override
 
- Public Member Functions inherited from BasicUI::Services
virtual ~Services ()
 
virtual void DoCallAfter (const Action &action)=0
 
virtual void DoYield ()=0
 
virtual void DoShowErrorDialog (const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options)=0
 
virtual MessageBoxResult DoMessageBox (const TranslatableString &message, MessageBoxOptions options)=0
 
virtual std::unique_ptr< ProgressDialogDoMakeProgress (const TranslatableString &title, const TranslatableString &message, unsigned flag, const TranslatableString &remainingLabelText)=0
 
virtual std::unique_ptr< GenericProgressDialogDoMakeGenericProgress (const WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message, int style)=0
 
virtual int DoMultiDialog (const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log)=0
 
virtual bool DoOpenInDefaultBrowser (const wxString &url)=0
 
virtual std::unique_ptr< WindowPlacementDoFindFocus ()=0
 
virtual void DoSetFocus (const WindowPlacement &focus)=0
 
virtual bool IsUsingRtlLayout () const =0
 
virtual bool IsUiThread () const =0
 

Protected Member Functions

void DoCallAfter (const BasicUI::Action &action) override
 
void DoYield () override
 
void DoShowErrorDialog (const BasicUI::WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const BasicUI::ErrorDialogOptions &options) override
 
BasicUI::MessageBoxResult DoMessageBox (const TranslatableString &message, BasicUI::MessageBoxOptions options) override
 
std::unique_ptr< BasicUI::ProgressDialogDoMakeProgress (const TranslatableString &title, const TranslatableString &message, unsigned flags, const TranslatableString &remainingLabelText) override
 
std::unique_ptr< BasicUI::GenericProgressDialogDoMakeGenericProgress (const BasicUI::WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message, int style) override
 
int DoMultiDialog (const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log) override
 
bool DoOpenInDefaultBrowser (const wxString &url) override
 
std::unique_ptr< BasicUI::WindowPlacementDoFindFocus () override
 
void DoSetFocus (const BasicUI::WindowPlacement &focus) override
 
bool IsUsingRtlLayout () const override
 
bool IsUiThread () const override
 

Detailed Description

An implementation of BasicUI::Services in terms of the wxWidgets toolkit.

This is a singleton that doesn't need WX_INIT_API visibility

Definition at line 20 of file wxWidgetsBasicUI.h.

Constructor & Destructor Documentation

◆ ~wxWidgetsBasicUI()

wxWidgetsBasicUI::~wxWidgetsBasicUI ( )
overridedefault

Member Function Documentation

◆ DoCallAfter()

void wxWidgetsBasicUI::DoCallAfter ( const BasicUI::Action action)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 29 of file wxWidgetsBasicUI.cpp.

30{
31 wxTheApp->CallAfter(action);
32}

◆ DoFindFocus()

std::unique_ptr< BasicUI::WindowPlacement > wxWidgetsBasicUI::DoFindFocus ( )
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 243 of file wxWidgetsBasicUI.cpp.

244{
245 return std::make_unique<wxWidgetsWindowPlacement>(wxWindow::FindFocus());
246}
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:383

References BasicUI::FindFocus().

Here is the call graph for this function:

◆ DoMakeGenericProgress()

std::unique_ptr< GenericProgressDialog > wxWidgetsBasicUI::DoMakeGenericProgress ( const BasicUI::WindowPlacement placement,
const TranslatableString title,
const TranslatableString message,
int  style 
)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 208 of file wxWidgetsBasicUI.cpp.

213{
214 // Compute the style argument to pass to wxWidgets
215 int flags = 0;
216 if ((style & ProgressCanAbort))
217 flags |= wxPD_CAN_ABORT;
218 if ((style & ProgressAppModal))
219 flags |= wxPD_APP_MODAL;
221 flags |= wxPD_ELAPSED_TIME;
222 if ((style & ProgressSmooth))
223 flags |= wxPD_SMOOTH;
224
225 return std::make_unique<MyGenericProgress>(
226 title, message, wxWidgetsWindowPlacement::GetParent(placement), flags);
227}
static const auto title
@ ProgressCanAbort
Definition: BasicUI.h:148
@ ProgressShowElapsedTime
Definition: BasicUI.h:150
@ ProgressSmooth
Definition: BasicUI.h:151
@ ProgressAppModal
Definition: BasicUI.h:149
static wxWindow * GetParent(const WindowPlacement &placement)
Retrieve the pointer to window, if placement is of this type; else null.

References wxWidgetsWindowPlacement::GetParent(), BasicUI::ProgressAppModal, BasicUI::ProgressCanAbort, BasicUI::ProgressShowElapsedTime, BasicUI::ProgressSmooth, anonymous_namespace{AudacityDontAskAgainMessageDialog.cpp}::style, and title.

Here is the call graph for this function:

◆ DoMakeProgress()

std::unique_ptr< BasicUI::ProgressDialog > wxWidgetsBasicUI::DoMakeProgress ( const TranslatableString title,
const TranslatableString message,
unsigned  flags,
const TranslatableString remainingLabelText 
)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 159 of file wxWidgetsBasicUI.cpp.

163{
164 unsigned options = 0;
165 if (!(flags & ProgressShowStop))
166 options |= pdlgHideStopButton;
167 if (!(flags & ProgressShowCancel))
168 options |= pdlgHideCancelButton;
169 if ((flags & ProgressHideTime))
170 options |= pdlgHideElapsedTime;
171 if ((flags & ProgressConfirmStopOrCancel))
172 options |= pdlgConfirmStopCancel;
173 // Usually wxWindow objects should not be managed by std::unique_ptr
174 // See https://docs.wxwidgets.org/3.0/overview_windowdeletion.html
175 // But on macOS the use of wxWindowPtr for the progress dialog sometimes
176 // causes hangs.
177 return std::make_unique<::ProgressDialog>(
178 title, message, options, remainingLabelText);
179}
@ pdlgConfirmStopCancel
@ pdlgHideStopButton
@ pdlgHideElapsedTime
@ pdlgHideCancelButton
@ ProgressHideTime
Definition: BasicUI.h:143
@ ProgressShowCancel
Definition: BasicUI.h:142
@ ProgressConfirmStopOrCancel
Definition: BasicUI.h:144
@ ProgressShowStop
Definition: BasicUI.h:141

References pdlgConfirmStopCancel, pdlgHideCancelButton, pdlgHideElapsedTime, pdlgHideStopButton, BasicUI::ProgressConfirmStopOrCancel, BasicUI::ProgressHideTime, BasicUI::ProgressShowCancel, BasicUI::ProgressShowStop, and title.

◆ DoMessageBox()

BasicUI::MessageBoxResult wxWidgetsBasicUI::DoMessageBox ( const TranslatableString message,
BasicUI::MessageBoxOptions  options 
)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 88 of file wxWidgetsBasicUI.cpp.

91{
92 // Compute the style argument to pass to wxWidgets
93 long style = 0;
94 switch (options.iconStyle) {
95 case Icon::Warning :
96 style = wxICON_WARNING;
97 break;
98 case Icon::Error :
99 style = wxICON_ERROR;
100 break;
101 case Icon::Question :
102 style = wxICON_QUESTION;
103 break;
104 case Icon::Information :
105 style = wxICON_INFORMATION;
106 break;
107 default:
108 break;
109 }
110 switch (options.buttonStyle) {
111 case Button::Ok :
112 style |= wxOK;
113 break;
114 case Button::YesNo :
115 style |= wxYES_NO;
116 break;
117 default:
118 break;
119 }
120 if (!options.yesOrOkDefaultButton && options.buttonStyle == Button::YesNo)
121 style |= wxNO_DEFAULT;
122 if (options.cancelButton)
123 style |= wxCANCEL;
124 if (options.centered)
125 style |= wxCENTER;
126
127 // Preserving the default style AudacityMessageBox had,
128 // when none of the above were explicitly specified
129 if (!style)
130 style = wxOK | wxCENTRE;
131
132 // This calls through to ::wxMessageBox:
133 auto wxResult =
134 ::AudacityMessageBox(message, options.caption, style,
135 options.parent
137 : nullptr);
138 // This switch exhausts all possibilities for the return from::wxMessageBox.
139 // see utilscmn.cpp in wxWidgets.
140 // Remap to our toolkit-neutral enumeration.
141 switch (wxResult) {
142 case wxYES:
143 return MessageBoxResult::Yes;
144 case wxNO:
145 return MessageBoxResult::No;
146 case wxOK:
147 return MessageBoxResult::Ok;
148 case wxCANCEL:
149 return MessageBoxResult::Cancel;
150 case wxHELP:
151 // should not happen, because we don't ever pass wxHELP
152 default:
153 wxASSERT(false);
154 return MessageBoxResult::None;
155 }
156}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
TranslatableString caption
Definition: BasicUI.h:124
WindowPlacement * parent
Definition: BasicUI.h:123

References AudacityMessageBox(), BasicUI::MessageBoxOptions::buttonStyle, BasicUI::MessageBoxOptions::cancelButton, BasicUI::MessageBoxOptions::caption, BasicUI::MessageBoxOptions::centered, wxWidgetsWindowPlacement::GetParent(), BasicUI::MessageBoxOptions::iconStyle, BasicUI::MessageBoxOptions::parent, anonymous_namespace{AudacityDontAskAgainMessageDialog.cpp}::style, and BasicUI::MessageBoxOptions::yesOrOkDefaultButton.

Here is the call graph for this function:

◆ DoMultiDialog()

int wxWidgetsBasicUI::DoMultiDialog ( const TranslatableString message,
const TranslatableString title,
const TranslatableStrings buttons,
const ManualPageID helpPage,
const TranslatableString boxMsg,
bool  log 
)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 229 of file wxWidgetsBasicUI.cpp.

234{
235 return ::ShowMultiDialog(message, title, buttons, helpPage, boxMsg, log);
236}
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.
Definition: BasicUI.h:367

References BasicUI::ShowMultiDialog(), and title.

Here is the call graph for this function:

◆ DoOpenInDefaultBrowser()

bool wxWidgetsBasicUI::DoOpenInDefaultBrowser ( const wxString &  url)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 238 of file wxWidgetsBasicUI.cpp.

239{
240 return wxLaunchDefaultBrowser(url);
241}

◆ DoSetFocus()

void wxWidgetsBasicUI::DoSetFocus ( const BasicUI::WindowPlacement focus)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 248 of file wxWidgetsBasicUI.cpp.

249{
250 auto pWindow = wxWidgetsWindowPlacement::GetParent(focus);
251 pWindow->SetFocus();
252}

References wxWidgetsWindowPlacement::GetParent().

Here is the call graph for this function:

◆ DoShowErrorDialog()

void wxWidgetsBasicUI::DoShowErrorDialog ( const BasicUI::WindowPlacement placement,
const TranslatableString dlogTitle,
const TranslatableString message,
const ManualPageID helpPage,
const BasicUI::ErrorDialogOptions options 
)
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 39 of file wxWidgetsBasicUI.cpp.

45{
46 using namespace BasicUI;
47 bool modal = true;
48 auto parent = wxWidgetsWindowPlacement::GetParent(placement);
49 switch (options.type) {
50 case ErrorDialogType::ModalErrorReport: {
51#ifdef HAS_SENTRY_REPORTING
52 ErrorReportDialog dlog(parent, dlogTitle, message, helpPage,
53 options.log, modal);
54
55 dlog.CentreOnParent();
56 dlog.ShowModal();
57 return;
58#else
59 break;
60#endif
61 }
62 case ErrorDialogType::ModelessError: {
63 if (!parent)
64 parent = wxTheApp->GetTopWindow();
65 // To be nonmodal, either it needs a parent, to avoid leaks, or it must
66 // guarantee eventual deletion of itself. There might be no top window
67 // on MacOS. Let's just force it to be modal in that case.
68 if (parent)
69 modal = false;
70 break;
71 }
72 default:
73 break;
74 }
75 auto pDlog = Destroy_ptr<ErrorDialog>( safenew ErrorDialog{ parent,
76 dlogTitle, message, helpPage, options.log,
77 options.modalHelp, modal } );
78 pDlog->CentreOnParent();
79 if (modal)
80 pDlog->ShowModal();
81 else {
82 pDlog->Show();
83 pDlog.release(); // not a memory leak, because it has a parent
84 }
85}
#define safenew
Definition: MemoryX.h:10
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:164
Gives an Error message with an option for help.
Definition: ErrorDialog.h:26
A dialog, that has "Send", "Don't send" and help buttons.
ErrorDialogType type
Type of help dialog.
Definition: BasicUI.h:70
std::wstring log
Optional extra logging information to be shown.
Definition: BasicUI.h:74
bool modalHelp
Whether the secondary help dialog with more information should be modal.
Definition: BasicUI.h:72

References wxWidgetsWindowPlacement::GetParent(), BasicUI::ErrorDialogOptions::log, BasicUI::ErrorDialogOptions::modalHelp, safenew, and BasicUI::ErrorDialogOptions::type.

Here is the call graph for this function:

◆ DoYield()

void wxWidgetsBasicUI::DoYield ( )
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 34 of file wxWidgetsBasicUI.cpp.

35{
36 wxTheApp->Yield();
37}

◆ IsUiThread()

bool wxWidgetsBasicUI::IsUiThread ( ) const
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 259 of file wxWidgetsBasicUI.cpp.

260{
261 return wxIsMainThread();
262}

◆ IsUsingRtlLayout()

bool wxWidgetsBasicUI::IsUsingRtlLayout ( ) const
overrideprotectedvirtual

Implements BasicUI::Services.

Definition at line 254 of file wxWidgetsBasicUI.cpp.

255{
256 return wxLayout_RightToLeft == wxTheApp->GetLayoutDirection();
257}

The documentation for this class was generated from the following files: