mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 17:30:17 +01:00
Merge LinkingHtmlWindow into HelpSystem...
... they cooperated closely in a cycle of two not worth breaking
This commit is contained in:
@@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user