OpenCPN Partial API docs
Loading...
Searching...
No Matches
AboutFrameImpl.cpp
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 "gui_lib.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
39extern OCPNPlatform* g_Platform;
40
41AboutFrameImpl::AboutFrameImpl(wxWindow* parent, wxWindowID id,
42 const wxString& title, const wxPoint& pos,
43 const wxSize& size, long style)
44 : AboutFrame(parent, id, title, pos, size, style) {
45 m_staticTextVersion->SetLabel(VERSION_FULL);
46 m_staticTextCopyYears->SetLabel("\u00A9 2000-2021");
47 m_hyperlinkIniFile->SetLabel(g_Platform->GetConfigFileName());
48 m_hyperlinkIniFile->SetURL(g_Platform->GetConfigFileName());
49 m_hyperlinkLogFile->SetLabel(g_Platform->GetLogFileName());
50 m_hyperlinkLogFile->SetURL(g_Platform->GetLogFileName());
51 m_htmlWinAuthors->Hide();
52 m_htmlWinLicense->Hide();
53 m_htmlWinHelp->Hide();
54 m_btnBack->Hide();
55 m_htmlWinLicense->LoadFile(wxString::Format(
56 "%s/license.html", g_Platform->GetSharedDataDir().c_str()));
57 m_htmlWinAuthors->LoadFile(wxString::Format(
58 "%s/authors.html", g_Platform->GetSharedDataDir().c_str()));
59 wxBitmap logo(wxString::Format("%s/opencpn.png",
60 g_Platform->GetSharedDataDir().c_str()),
61 wxBITMAP_TYPE_ANY);
62
63 m_hyperlinkHelp->SetURL(wxString::Format(
64 "file://%sdoc/help_en_US.html", g_Platform->GetSharedDataDir().c_str()));
65#if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
66 m_htmlWinHelp->LoadURL(wxString::Format(
67 "file://%sdoc/help_en_US.html", g_Platform->GetSharedDataDir().c_str()));
68#else
69 m_htmlWinHelp->LoadFile(wxString::Format(
70 "%s/doc/help_en_US.html", g_Platform->GetSharedDataDir().c_str()));
71#endif
72 m_bitmapLogo->SetBitmap(logo);
73
74 int width = m_scrolledWindowAbout->GetSizer()->GetSize().GetWidth() +
75 m_bitmapLogo->GetSize().GetWidth() + EXTEND_WIDTH;
76 int height = m_scrolledWindowAbout->GetSizer()->GetSize().GetHeight() +
77 m_panelMainLinks->GetSizer()->GetSize().GetHeight() +
78 EXTEND_HEIGHT;
79
80 SetMinSize(wxSize(width, height));
81 RecalculateSize();
82}
83
84void AboutFrameImpl::OnLinkHelp(wxHyperlinkEvent& event) {
85#ifdef __WXGTK__
86 wxString testFile = wxString::Format("/%s/doc/help_en_US.html",
87 g_Platform->GetSharedDataDir().c_str());
88 if (!::wxFileExists(testFile)) {
89 wxString msg = _("OpenCPN Help documentation is not available locally.");
90 msg += _T("\n");
91 msg +=
92 _("Would you like to visit the opencpn.org website for more "
93 "information?");
94
95 if (wxID_YES ==
96 OCPNMessageBox(NULL, msg, _("OpenCPN Info"), wxYES_NO | wxCENTER, 60)) {
97 wxLaunchDefaultBrowser(_T("https://opencpn.org"));
98 }
99 } else
100#endif
101 {
102 m_htmlWinAuthors->Hide();
103 m_htmlWinLicense->Hide();
104 m_htmlWinHelp->Show();
105 m_scrolledWindowAbout->Hide();
106 m_btnBack->Show();
107#if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
108 m_btnBack->Enable(m_htmlWinHelp->CanGoBack());
109#else
110 m_btnBack->Enable(m_htmlWinHelp->HistoryCanBack());
111#endif
112 wxSize parentSize = m_parent->GetSize();
113 SetSize(wxSize(parentSize.x * 9 / 10, parentSize.y * 9 / 10));
114 Centre();
115 }
116}
117
118void AboutFrameImpl::OnLinkLicense(wxHyperlinkEvent& event) {
119 m_htmlWinAuthors->Hide();
120 m_htmlWinLicense->Show();
121 m_htmlWinHelp->Hide();
122 m_btnBack->Hide();
123 m_scrolledWindowAbout->Hide();
124 Layout();
125}
126
127void AboutFrameImpl::OnLinkAuthors(wxHyperlinkEvent& event) {
128 m_htmlWinAuthors->Show();
129 m_htmlWinLicense->Hide();
130 m_htmlWinHelp->Hide();
131 m_btnBack->Hide();
132 m_scrolledWindowAbout->Hide();
133 Layout();
134}
135
136void AboutFrameImpl::AboutFrameOnActivate(wxActivateEvent& event) {
137 m_htmlWinAuthors->Hide();
138 m_htmlWinLicense->Hide();
139 m_htmlWinHelp->Hide();
140 m_btnBack->Hide();
141 m_scrolledWindowAbout->Show();
142 Layout();
143 m_scrolledWindowAbout->Refresh();
144 m_panelMainLinks->Refresh();
145}
146
147void AboutFrameImpl::RecalculateSize(void) {
148#ifdef __OCPN__ANDROID__
149 // Make an estimate of the dialog size, without scrollbars showing
150
151 wxSize esize;
152 esize.x = GetCharWidth() * 110;
153 esize.y = GetCharHeight() * 20;
154
155 wxSize dsize = GetParent()->GetClientSize();
156 esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
157 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
158 SetClientSize(esize);
159
160 wxSize fsize = GetSize();
161 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
162 fsize.x = wxMin(fsize.x, dsize.x - (1 * GetCharHeight()));
163
164 SetSize(fsize);
165 Centre();
166
167#else
168 Fit();
169 Centre();
170#endif
171}
Class AboutFrame.
Definition: AboutFrame.h:39