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