1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  About Dialog
5  * Author:   David Register
6  *
7  ***************************************************************************
8  *   Copyright (C) 2019 by David S. Register                               *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program; if not, write to the                         *
22  *   Free Software Foundation, Inc.,                                       *
23  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
24  **************************************************************************/
25 
26 #include "AboutFrameImpl.h"
27 #include "config.h"
28 #include "OCPNPlatform.h"
29 #include "chart1.h"
30 
31 #ifdef __WXMSW__
32 #define EXTEND_WIDTH 70
33 #define EXTEND_HEIGHT 70
34 #else
35 #define EXTEND_WIDTH 50
36 #define EXTEND_HEIGHT 50
37 #endif
38 
39 extern OCPNPlatform  *g_Platform;
40 
AboutFrameImpl(wxWindow * parent,wxWindowID id,const wxString & title,const wxPoint & pos,const wxSize & size,long style)41 AboutFrameImpl::AboutFrameImpl( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : AboutFrame( parent, id, title, pos, size, style )
42 {
43     m_staticTextVersion->SetLabel(VERSION_FULL);
44     m_staticTextCopyYears->SetLabel("\u00A9 2000-2019");
45     m_hyperlinkIniFile->SetLabel(g_Platform->GetConfigFileName());
46     m_hyperlinkIniFile->SetURL(g_Platform->GetConfigFileName());
47     m_hyperlinkLogFile->SetLabel(g_Platform->GetLogFileName());
48     m_hyperlinkLogFile->SetURL(g_Platform->GetLogFileName());
49     m_htmlWinAuthors->Hide();
50     m_htmlWinLicense->Hide();
51     m_htmlWinHelp->Hide();
52     m_btnBack->Hide();
53     m_htmlWinLicense->LoadFile(wxString::Format("%s/license.html", g_Platform->GetSharedDataDir().c_str()));
54     m_htmlWinAuthors->LoadFile(wxString::Format("%s/authors.html", g_Platform->GetSharedDataDir().c_str()));
55     wxBitmap logo(wxString::Format("%s/opencpn.png", g_Platform->GetSharedDataDir().c_str()), wxBITMAP_TYPE_ANY);
56 
57     m_hyperlinkHelp->SetURL(wxString::Format("file://%sdoc/help_en_US.html", g_Platform->GetSharedDataDir().c_str()));
58 #if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
59     m_htmlWinHelp->LoadURL(wxString::Format("file://%sdoc/help_en_US.html", g_Platform->GetSharedDataDir().c_str()));
60 #else
61     m_htmlWinHelp->LoadFile(wxString::Format("%s/doc/help_en_US.html", g_Platform->GetSharedDataDir().c_str()));
62 #endif
63     m_bitmapLogo->SetBitmap(logo);
64 
65     int width = m_scrolledWindowAbout->GetSizer()->GetSize().GetWidth() + m_bitmapLogo->GetSize().GetWidth() + EXTEND_WIDTH;
66     int height = m_scrolledWindowAbout->GetSizer()->GetSize().GetHeight() + m_panelMainLinks->GetSizer()->GetSize().GetHeight() + EXTEND_HEIGHT;
67 
68     SetMinSize(wxSize(width, height));
69     RecalculateSize();
70 }
71 
72 
OnLinkHelp(wxHyperlinkEvent & event)73 void AboutFrameImpl::OnLinkHelp( wxHyperlinkEvent& event )
74 {
75 #ifdef __WXGTK__
76     wxString testFile = wxString::Format("/%s/doc/help_en_US.html", g_Platform->GetSharedDataDir().c_str());
77     if( !::wxFileExists(testFile)){
78         wxString msg = _("OpenCPN Help documentation is not available locally.");  msg += _T("\n");
79         msg += _("Would you like to visit the opencpn.org website for more information?");
80 
81         if( wxID_YES == OCPNMessageBox(NULL, msg, _("OpenCPN Info"), wxYES_NO | wxCENTER, 60 ) )
82         {
83             wxLaunchDefaultBrowser(_T("https://opencpn.org"));
84         }
85     }
86     else
87 #endif
88     {
89         m_htmlWinAuthors->Hide();
90         m_htmlWinLicense->Hide();
91         m_htmlWinHelp->Show();
92         m_scrolledWindowAbout->Hide();
93         m_btnBack->Show();
94 #if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
95         m_btnBack->Enable(m_htmlWinHelp->CanGoBack());
96 #else
97         m_btnBack->Enable(m_htmlWinHelp->HistoryCanBack());
98 #endif
99         wxSize parentSize = m_parent->GetSize();
100         SetSize(wxSize(parentSize.x * 9 / 10, parentSize.y * 9 / 10));
101         Centre();
102     }
103 }
104 
OnLinkLicense(wxHyperlinkEvent & event)105 void AboutFrameImpl::OnLinkLicense( wxHyperlinkEvent& event )
106 {
107     m_htmlWinAuthors->Hide();
108     m_htmlWinLicense->Show();
109     m_htmlWinHelp->Hide();
110     m_btnBack->Hide();
111     m_scrolledWindowAbout->Hide();
112     Layout();
113 }
114 
OnLinkAuthors(wxHyperlinkEvent & event)115 void AboutFrameImpl::OnLinkAuthors( wxHyperlinkEvent& event )
116 {
117     m_htmlWinAuthors->Show();
118     m_htmlWinLicense->Hide();
119     m_htmlWinHelp->Hide();
120     m_btnBack->Hide();
121     m_scrolledWindowAbout->Hide();
122     Layout();
123 }
124 
AboutFrameOnActivate(wxActivateEvent & event)125 void AboutFrameImpl::AboutFrameOnActivate( wxActivateEvent& event )
126 {
127     m_htmlWinAuthors->Hide();
128     m_htmlWinLicense->Hide();
129     m_htmlWinHelp->Hide();
130     m_btnBack->Hide();
131     m_scrolledWindowAbout->Show();
132     Layout();
133     m_scrolledWindowAbout->Refresh();
134     m_panelMainLinks->Refresh();
135 }
136 
RecalculateSize(void)137 void AboutFrameImpl::RecalculateSize( void )
138 {
139 #ifdef __OCPN__ANDROID__
140     //  Make an estimate of the dialog size, without scrollbars showing
141 
142     wxSize esize;
143     esize.x = GetCharWidth() * 110;
144     esize.y = GetCharHeight() * 20;
145 
146     wxSize dsize = GetParent()->GetClientSize();
147     esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
148     esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
149     SetClientSize(esize);
150 
151     wxSize fsize = GetSize();
152     fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
153     fsize.x = wxMin(fsize.x, dsize.x - (1 * GetCharHeight()));
154 
155     SetSize(fsize);
156     Centre();
157 
158 #else
159     Fit();
160     Centre();
161 #endif
162 
163 }
164