From bb3b5a27be167576e9bfa1e9145c3977865a6b26 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 20 Jun 2016 14:02:44 -0400 Subject: [PATCH] Bug1407, better fix: but Timer Record Help dialog is now modal --- src/widgets/ErrorDialog.h | 5 ++-- src/widgets/HelpSystem.cpp | 39 +++++++++++++++++-------------- src/widgets/LinkingHtmlWindow.cpp | 31 ++++++++++++++---------- src/widgets/LinkingHtmlWindow.h | 4 +++- 4 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/widgets/ErrorDialog.h b/src/widgets/ErrorDialog.h index 0f1daad1e..e0c759138 100644 --- a/src/widgets/ErrorDialog.h +++ b/src/widgets/ErrorDialog.h @@ -41,10 +41,11 @@ private: }; // Helper class to make browser "simulate" a modal dialog -class HtmlTextHelpDialog final : public BrowserFrame +class HtmlTextHelpDialog final : public BrowserDialog { public: - HtmlTextHelpDialog() : BrowserFrame() + HtmlTextHelpDialog(wxWindow *pParent, const wxString &title) + : BrowserDialog{ pParent, title } { #if !wxCHECK_VERSION(3, 0, 0) MakeModal( true ); diff --git a/src/widgets/HelpSystem.cpp b/src/widgets/HelpSystem.cpp index 0c859fe2d..54dc179c8 100644 --- a/src/widgets/HelpSystem.cpp +++ b/src/widgets/HelpSystem.cpp @@ -100,13 +100,8 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, { LinkingHtmlWindow *html; - BrowserFrame * pWnd; - if( bModal ) - pWnd = new HtmlTextHelpDialog(); - else - pWnd = new BrowserFrame(); - - pWnd->Create(pParent, wxID_ANY, Title, wxDefaultPosition, wxDefaultSize, + auto pFrame = safenew wxFrame { + pParent, wxID_ANY, Title, wxDefaultPosition, wxDefaultSize, #if defined(__WXMAC__) // On OSX, the html frame can go behind the help dialog and if the help // html frame is modal, you can't get back to it. Pressing escape gets @@ -115,9 +110,15 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, // but acceptable in this case. wxSTAY_ON_TOP | #endif - wxDEFAULT_FRAME_STYLE); + wxDEFAULT_FRAME_STYLE + }; + + BrowserDialog * pWnd; + if( bModal ) + pWnd = safenew HtmlTextHelpDialog{ pFrame, Title }; + else + pWnd = safenew BrowserDialog{ pFrame, Title }; - pWnd->SetName(pWnd->GetTitle()); ShuttleGui S( pWnd, eIsCreating ); S.SetStyle( wxNO_BORDER | wxTAB_TRAVERSAL ); @@ -141,7 +142,7 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, bIsFile ? wxSize(500, 400) : wxSize(480, 240), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); - html->SetRelatedFrame( pWnd, wxT("Help: %s") ); + html->SetRelatedFrame( pFrame, wxT("Help: %s") ); if( bIsFile ) html->LoadFile( HtmlText ); else @@ -162,18 +163,22 @@ void HelpSystem::ShowHtmlText(wxWindow *pParent, wxIcon ic{}; ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48)); #endif - pWnd->SetIcon( ic ); + pFrame->SetIcon( ic ); // -- END of ICON stuff ----- pWnd->mpHtml = html; pWnd->SetBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - pWnd->CreateStatusBar(); - pWnd->Centre(); - pWnd->Layout(); - pWnd->Fit(); - pWnd->SetSizeHints(pWnd->GetSize()); - pWnd->Show( true ); + + pFrame->CreateStatusBar(); + pFrame->Centre(); + pFrame->Layout(); + pFrame->Fit(); + pFrame->SetSizeHints(pWnd->GetSize()); + + pFrame->SetName(Title); + pFrame->Show( true ); + pWnd->ShowModal(); html->SetRelatedStatusBar( 0 ); html->SetFocus(); diff --git a/src/widgets/LinkingHtmlWindow.cpp b/src/widgets/LinkingHtmlWindow.cpp index df5642e9c..11fc55473 100644 --- a/src/widgets/LinkingHtmlWindow.cpp +++ b/src/widgets/LinkingHtmlWindow.cpp @@ -28,32 +28,38 @@ #include "ErrorDialog.h" #include "HelpSystem.h" -BEGIN_EVENT_TABLE(BrowserFrame, wxFrame) - EVT_BUTTON(wxID_FORWARD, BrowserFrame::OnForward) - EVT_BUTTON(wxID_BACKWARD, BrowserFrame::OnBackward) - EVT_BUTTON(wxID_CANCEL, BrowserFrame::OnClose) - EVT_KEY_DOWN(BrowserFrame::OnKeyDown) +BEGIN_EVENT_TABLE(BrowserDialog, wxDialog) + EVT_BUTTON(wxID_FORWARD, BrowserDialog::OnForward) + EVT_BUTTON(wxID_BACKWARD, BrowserDialog::OnBackward) + EVT_BUTTON(wxID_CANCEL, BrowserDialog::OnClose) + EVT_KEY_DOWN(BrowserDialog::OnKeyDown) END_EVENT_TABLE() -void BrowserFrame::OnForward(wxCommandEvent & WXUNUSED(event)) +BrowserDialog::BrowserDialog(wxWindow *pParent, const wxString &title) + : wxDialog{ pParent, ID, title } +{ + +} + +void BrowserDialog::OnForward(wxCommandEvent & WXUNUSED(event)) { mpHtml->HistoryForward(); UpdateButtons(); } -void BrowserFrame::OnBackward(wxCommandEvent & WXUNUSED(event)) +void BrowserDialog::OnBackward(wxCommandEvent & WXUNUSED(event)) { mpHtml->HistoryBack(); UpdateButtons(); } -void BrowserFrame::OnClose(wxCommandEvent & WXUNUSED(event)) +void BrowserDialog::OnClose(wxCommandEvent & WXUNUSED(event)) { - Close(); + EndModal(wxID_CANCEL); } -void BrowserFrame::OnKeyDown(wxKeyEvent & event) +void BrowserDialog::OnKeyDown(wxKeyEvent & event) { bool bSkip = true; if (event.GetKeyCode() == WXK_ESCAPE) @@ -65,7 +71,7 @@ void BrowserFrame::OnKeyDown(wxKeyEvent & event) } -void BrowserFrame::UpdateButtons() +void BrowserDialog::UpdateButtons() { wxWindow * pWnd; if( (pWnd = FindWindowById( wxID_BACKWARD, this )) != NULL ) @@ -124,7 +130,8 @@ void LinkingHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link) OpenInDefaultBrowser(link); return; } - BrowserFrame * pDlg = wxDynamicCast( GetRelatedFrame(), BrowserFrame ); + BrowserDialog * pDlg = wxDynamicCast( + GetRelatedFrame()->FindWindow(BrowserDialog::ID), BrowserDialog ); if( pDlg ) { pDlg->UpdateButtons(); diff --git a/src/widgets/LinkingHtmlWindow.h b/src/widgets/LinkingHtmlWindow.h index bd4bd6e07..045e7eecf 100644 --- a/src/widgets/LinkingHtmlWindow.h +++ b/src/widgets/LinkingHtmlWindow.h @@ -36,9 +36,11 @@ class AUDACITY_DLL_API LinkingHtmlWindow final : public HtmlWindow }; -class BrowserFrame /* not final */ : public wxFrame +class BrowserDialog /* not final */ : public wxDialog { public: + enum { ID = 0 }; + BrowserDialog(wxWindow *pParent, const wxString &title); void OnForward(wxCommandEvent & event); void OnBackward(wxCommandEvent & event);