1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-21 14:02:57 +02:00

Merge LinkingHtmlWindow into HelpSystem...

... they cooperated closely in a cycle of two not worth breaking
This commit is contained in:
Paul Licameli
2019-07-10 10:29:01 -04:00
parent f4b370d1e2
commit d6317ae6af
13 changed files with 215 additions and 282 deletions

View File

@@ -8,6 +8,15 @@
Leland Lucius
Richard Ash
was merged with LinkingHtmlWindow.h
Vaughan Johnson
Dominic Mazzoni
utility fn and
descendant of HtmlWindow that opens links in the user's
default browser
*//********************************************************************/
#include "../Audacity.h" // for USE_* macros
@@ -32,7 +41,6 @@
#include <wx/regex.h>
#include "../FileNames.h"
#include "LinkingHtmlWindow.h"
#include "../AllThemeResources.h"
#include "../ShuttleGui.h"
#include "../HelpText.h"
@@ -399,3 +407,154 @@ void HelpSystem::ShowHelp(wxWindow *parent,
bModal
);
}
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#include <wx/mimetype.h>
#include <wx/filename.h>
#include <wx/uri.h>
BEGIN_EVENT_TABLE(BrowserDialog, wxDialogWrapper)
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()
BrowserDialog::BrowserDialog(wxWindow *pParent, const wxString &title)
: wxDialogWrapper{ pParent, ID, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER /*| wxMAXIMIZE_BOX */ }
{
int width, height;
const int minWidth = 400;
const int minHeight = 250;
gPrefs->Read(wxT("/GUI/BrowserWidth"), &width, minWidth);
gPrefs->Read(wxT("/GUI/BrowserHeight"), &height, minHeight);
if (width < minWidth || width > wxSystemSettings::GetMetric(wxSYS_SCREEN_X))
width = minWidth;
if (height < minHeight || height > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y))
height = minHeight;
SetMinSize(wxSize(minWidth, minHeight));
SetSize(wxDefaultPosition.x, wxDefaultPosition.y, width, height, wxSIZE_AUTO);
}
void BrowserDialog::OnForward(wxCommandEvent & WXUNUSED(event))
{
mpHtml->HistoryForward();
UpdateButtons();
}
void BrowserDialog::OnBackward(wxCommandEvent & WXUNUSED(event))
{
mpHtml->HistoryBack();
UpdateButtons();
}
void BrowserDialog::OnClose(wxCommandEvent & WXUNUSED(event))
{
if (IsModal() && !mDismissed)
{
mDismissed = true;
EndModal(wxID_CANCEL);
}
auto parent = GetParent();
gPrefs->Write(wxT("/GUI/BrowserWidth"), GetSize().GetX());
gPrefs->Write(wxT("/GUI/BrowserHeight"), GetSize().GetY());
gPrefs->Flush();
#ifdef __WXMAC__
auto grandparent = GetParent()->GetParent();
#endif
parent->Destroy();
#ifdef __WXMAC__
if(grandparent && grandparent->IsShown()) {
grandparent->Raise();
}
#endif
}
void BrowserDialog::OnKeyDown(wxKeyEvent & event)
{
bool bSkip = true;
if (event.GetKeyCode() == WXK_ESCAPE)
{
bSkip = false;
Close(false);
}
event.Skip(bSkip);
}
void BrowserDialog::UpdateButtons()
{
wxWindow * pWnd;
if( (pWnd = FindWindowById( wxID_BACKWARD, this )) != NULL )
{
pWnd->Enable(mpHtml->HistoryCanBack());
}
if( (pWnd = FindWindowById( wxID_FORWARD, this )) != NULL )
{
pWnd->Enable(mpHtml->HistoryCanForward());
}
}
void OpenInDefaultBrowser(const wxHtmlLinkInfo& link)
{
wxURI uri(link.GetHref());
wxLaunchDefaultBrowser(uri.BuildURI());
}
LinkingHtmlWindow::LinkingHtmlWindow(wxWindow *parent, wxWindowID id /*= -1*/,
const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/,
long style /*= wxHW_SCROLLBAR_AUTO*/) :
HtmlWindow(parent, id, pos, size, style)
{
}
void LinkingHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
{
wxString href = link.GetHref();
if( href.StartsWith(wxT("innerlink:")) )
{
wxString FileName =
wxFileName( FileNames::HtmlHelpDir(), href.Mid( 10 ) + wxT(".htm") ).GetFullPath();
if( wxFileExists( FileName ) )
{
HelpSystem::ShowHelp(this, FileName, wxEmptyString, false);
return;
}
else
{
SetPage( HelpText( href.Mid( 10 )));
wxGetTopLevelParent(this)->SetLabel( TitleText( href.Mid( 10 )));
}
}
else if( href.StartsWith(wxT("mailto:")) || href.StartsWith(wxT("file:")) )
{
OpenInDefaultBrowser( link );
return;
}
else if( !href.StartsWith( wxT("http:")) && !href.StartsWith( wxT("https:")) )
{
HtmlWindow::OnLinkClicked( link );
}
else
{
OpenInDefaultBrowser(link);
return;
}
BrowserDialog * pDlg = wxDynamicCast(
GetRelatedFrame()->FindWindow(BrowserDialog::ID), BrowserDialog );
if( pDlg )
{
pDlg->UpdateButtons();
};
}

View File

@@ -7,6 +7,15 @@
Jimmy Johnson
James Crook
was merged with LinkingHtmlWindow.h
Vaughan Johnson
Dominic Mazzoni
utility fn and
descendant of HtmlWindow that opens links in the user's
default browser
**********************************************************************/
#ifndef __AUDACITY_HELPSYSTEM__
@@ -104,4 +113,46 @@ public:
class ShuttleGui;
#include "HtmlWindow.h" // to inherit
void OpenInDefaultBrowser(const wxHtmlLinkInfo& link);
/// \brief An HtmlWindow that handles linked clicked - usually the
/// link will go to our own local copy of the manual, but it could
/// launch a new browser window.
class AUDACITY_DLL_API LinkingHtmlWindow final : public HtmlWindow
{
public:
LinkingHtmlWindow(wxWindow *parent, wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHW_SCROLLBAR_AUTO);
void OnLinkClicked(const wxHtmlLinkInfo& link) override;
//void OnSetTitle(const wxString& title) override;
};
/// Adds some event handling to an HtmlWindow
class BrowserDialog /* not final */ : public wxDialogWrapper
{
public:
enum { ID = 0 };
BrowserDialog(wxWindow *pParent, const wxString &title);
void OnForward(wxCommandEvent & event);
void OnBackward(wxCommandEvent & event);
void OnClose(wxCommandEvent & event);
void OnKeyDown(wxKeyEvent & event);
void UpdateButtons();
//void SetLabel(const wxString& label) override;
HtmlWindow * mpHtml;
bool mDismissed{};
DECLARE_EVENT_TABLE()
};
#endif // __AUDACITY_HELPSYSTEM__

View File

@@ -1,176 +0,0 @@
/**********************************************************************
Audacity: A Digital Audio Editor
LinkingHtmlWindow.cpp
Vaughan Johnson
Dominic Mazzoni
utility fn and
descendant of HtmlWindow that opens links in the user's
default browser
**********************************************************************/
#include "../Audacity.h"
#include "LinkingHtmlWindow.h"
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#include <wx/mimetype.h>
#include <wx/filename.h>
#include <wx/frame.h>
#include <wx/uri.h>
#include <wx/settings.h>
#include <wx/log.h>
#include "../HelpText.h"
#include "../FileNames.h"
#include "../Prefs.h"
#include "HelpSystem.h"
BEGIN_EVENT_TABLE(BrowserDialog, wxDialogWrapper)
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()
BrowserDialog::BrowserDialog(wxWindow *pParent, const wxString &title)
: wxDialogWrapper{ pParent, ID, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER /*| wxMAXIMIZE_BOX */ }
{
int width, height;
const int minWidth = 400;
const int minHeight = 250;
gPrefs->Read(wxT("/GUI/BrowserWidth"), &width, minWidth);
gPrefs->Read(wxT("/GUI/BrowserHeight"), &height, minHeight);
if (width < minWidth || width > wxSystemSettings::GetMetric(wxSYS_SCREEN_X))
width = minWidth;
if (height < minHeight || height > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y))
height = minHeight;
SetMinSize(wxSize(minWidth, minHeight));
SetSize(wxDefaultPosition.x, wxDefaultPosition.y, width, height, wxSIZE_AUTO);
}
void BrowserDialog::OnForward(wxCommandEvent & WXUNUSED(event))
{
mpHtml->HistoryForward();
UpdateButtons();
}
void BrowserDialog::OnBackward(wxCommandEvent & WXUNUSED(event))
{
mpHtml->HistoryBack();
UpdateButtons();
}
void BrowserDialog::OnClose(wxCommandEvent & WXUNUSED(event))
{
if (IsModal() && !mDismissed)
{
mDismissed = true;
EndModal(wxID_CANCEL);
}
auto parent = GetParent();
gPrefs->Write(wxT("/GUI/BrowserWidth"), GetSize().GetX());
gPrefs->Write(wxT("/GUI/BrowserHeight"), GetSize().GetY());
gPrefs->Flush();
#ifdef __WXMAC__
auto grandparent = GetParent()->GetParent();
#endif
parent->Destroy();
#ifdef __WXMAC__
if(grandparent && grandparent->IsShown()) {
grandparent->Raise();
}
#endif
}
void BrowserDialog::OnKeyDown(wxKeyEvent & event)
{
bool bSkip = true;
if (event.GetKeyCode() == WXK_ESCAPE)
{
bSkip = false;
Close(false);
}
event.Skip(bSkip);
}
void BrowserDialog::UpdateButtons()
{
wxWindow * pWnd;
if( (pWnd = FindWindowById( wxID_BACKWARD, this )) != NULL )
{
pWnd->Enable(mpHtml->HistoryCanBack());
}
if( (pWnd = FindWindowById( wxID_FORWARD, this )) != NULL )
{
pWnd->Enable(mpHtml->HistoryCanForward());
}
}
void OpenInDefaultBrowser(const wxHtmlLinkInfo& link)
{
wxURI uri(link.GetHref());
wxLaunchDefaultBrowser(uri.BuildURI());
}
LinkingHtmlWindow::LinkingHtmlWindow(wxWindow *parent, wxWindowID id /*= -1*/,
const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/,
long style /*= wxHW_SCROLLBAR_AUTO*/) :
HtmlWindow(parent, id, pos, size, style)
{
}
void LinkingHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
{
wxString href = link.GetHref();
if( href.StartsWith(wxT("innerlink:")) )
{
wxString FileName =
wxFileName( FileNames::HtmlHelpDir(), href.Mid( 10 ) + wxT(".htm") ).GetFullPath();
if( wxFileExists( FileName ) )
{
HelpSystem::ShowHelp(this, FileName, wxEmptyString, false);
return;
}
else
{
SetPage( HelpText( href.Mid( 10 )));
wxGetTopLevelParent(this)->SetLabel( TitleText( href.Mid( 10 )));
}
}
else if( href.StartsWith(wxT("mailto:")) || href.StartsWith(wxT("file:")) )
{
OpenInDefaultBrowser( link );
return;
}
else if( !href.StartsWith( wxT("http:")) && !href.StartsWith( wxT("https:")) )
{
HtmlWindow::OnLinkClicked( link );
}
else
{
OpenInDefaultBrowser(link);
return;
}
BrowserDialog * pDlg = wxDynamicCast(
GetRelatedFrame()->FindWindow(BrowserDialog::ID), BrowserDialog );
if( pDlg )
{
pDlg->UpdateButtons();
};
}

View File

@@ -1,62 +0,0 @@
/**********************************************************************
Audacity: A Digital Audio Editor
LinkingHtmlWindow.h
Vaughan Johnson
Dominic Mazzoni
utility fn and
descendant of HtmlWindow that opens links in the user's
default browser
**********************************************************************/
#ifndef __AUDACITY_LINKINGHTMLWINDOW__
#define __AUDACITY_LINKINGHTMLWINDOW__
#include "HtmlWindow.h" // to inherit
#include "wxPanelWrapper.h" // to inherit
void OpenInDefaultBrowser(const wxHtmlLinkInfo& link);
/// \brief An HtmlWindow that handles linked clicked - usually the
/// link will go to our own local copy of the manual, but it could
/// launch a new browser window.
class AUDACITY_DLL_API LinkingHtmlWindow final : public HtmlWindow
{
public:
LinkingHtmlWindow(wxWindow *parent, wxWindowID id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxHW_SCROLLBAR_AUTO);
void OnLinkClicked(const wxHtmlLinkInfo& link) override;
//void OnSetTitle(const wxString& title) override;
};
/// Adds some event handling to an HtmlWindow
class BrowserDialog /* not final */ : public wxDialogWrapper
{
public:
enum { ID = 0 };
BrowserDialog(wxWindow *pParent, const wxString &title);
void OnForward(wxCommandEvent & event);
void OnBackward(wxCommandEvent & event);
void OnClose(wxCommandEvent & event);
void OnKeyDown(wxKeyEvent & event);
void UpdateButtons();
//void SetLabel(const wxString& label) override;
HtmlWindow * mpHtml;
bool mDismissed{};
DECLARE_EVENT_TABLE()
};
#endif // __AUDACITY_LINKINGHTMLWINDOW__