OpenCPN Partial API docs
Loading...
Searching...
No Matches
about_frame_impl.cpp
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2019 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#include <fstream>
25#include <sstream>
26#include <string>
27
28#include "model/base_platform.h"
29
30#include "about_frame_impl.h"
31#include "config.h"
32#include "gui_lib.h"
33#include "std_filesystem.h"
34
35#ifdef __WXMSW__
36#define EXTEND_WIDTH 70
37#define EXTEND_HEIGHT 70
38#else
39#define EXTEND_WIDTH 50
40#define EXTEND_HEIGHT 50
41#endif
42
44static void LoadAuthors(wxHtmlWindow& hyperlink) {
45 fs::path datadir(g_BasePlatform->GetSharedDataDir().ToStdString());
46 std::ifstream stream(datadir / "Authors.html");
47 std::stringstream ss;
48 ss << stream.rdbuf();
49 hyperlink.SetPage(wxString::FromUTF8(ss.str().c_str()));
50}
51
52AboutFrameImpl::AboutFrameImpl(wxWindow* parent, wxWindowID id,
53 const wxString& title, const wxPoint& pos,
54 const wxSize& size, long style)
55 : AboutFrame(parent, id, title, pos, size, style) {
56 if (strlen(DEBIAN_PPA_VERSION))
57 m_staticTextVersion->SetLabel(wxString(DEBIAN_PPA_VERSION));
58 else
59 m_staticTextVersion->SetLabel(PACKAGE_VERSION);
60
61 m_staticTextCopyYears->SetLabel("\u00A9 2000-2024");
62 m_hyperlinkIniFile->SetLabel(g_BasePlatform->GetConfigFileName());
63 m_hyperlinkIniFile->SetURL(g_BasePlatform->GetConfigFileName());
64 m_hyperlinkLogFile->SetLabel(g_BasePlatform->GetLogFileName());
65 m_hyperlinkLogFile->SetURL(g_BasePlatform->GetLogFileName());
66 m_htmlWinAuthors->Hide();
67 m_htmlWinLicense->Hide();
68 m_htmlWinHelp->Hide();
69 m_btnBack->Hide();
70 m_htmlWinLicense->LoadFile(wxString::Format(
71 "%s/license.html", g_BasePlatform->GetSharedDataDir().c_str()));
72 LoadAuthors(*m_htmlWinAuthors);
73 wxBitmap logo(wxString::Format("%s/opencpn.png",
74 g_BasePlatform->GetSharedDataDir().c_str()),
75 wxBITMAP_TYPE_ANY);
76
77 wxString target = wxString::Format(
78 "%sdoc/local/toc_flat.html", g_BasePlatform->GetSharedDataDir().c_str());
79
80 if (!::wxFileExists(target))
81 target = wxString::Format("%sdoc/help_web.html",
82 g_BasePlatform->GetSharedDataDir().c_str());
83
84 target.Prepend("file://");
85
86 m_hyperlinkHelp->SetURL(target);
87#if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
88 m_htmlWinHelp->LoadURL(target);
89#else
90 m_htmlWinHelp->LoadFile(target);
91#endif
92 m_bitmapLogo->SetBitmap(logo);
93
94 int width = m_scrolledWindowAbout->GetSizer()->GetSize().GetWidth() +
95 m_bitmapLogo->GetSize().GetWidth() + EXTEND_WIDTH;
96 int height = m_scrolledWindowAbout->GetSizer()->GetSize().GetHeight() +
97 m_panelMainLinks->GetSizer()->GetSize().GetHeight() +
98 EXTEND_HEIGHT;
99
100 SetMinSize(wxSize(width, height));
101 RecalculateSize();
102}
103
104void AboutFrameImpl::OnLinkHelp(wxHyperlinkEvent& event) {
105#ifdef __WXGTK__
106 wxString testFile = wxString::Format(
107 "/%s/doc/help_web.html", g_BasePlatform->GetSharedDataDir().c_str());
108 if (!::wxFileExists(testFile)) {
109 wxString msg = _("OpenCPN Help documentation is not available locally.");
110 msg += "\n";
111 msg +=
112 _("Would you like to visit the opencpn.org website for more "
113 "information?");
114
115 if (wxID_YES ==
116 OCPNMessageBox(NULL, msg, _("OpenCPN Info"), wxYES_NO | wxCENTER, 60)) {
117 wxLaunchDefaultBrowser("https://opencpn.org");
118 }
119 } else
120#endif
121 {
122 m_htmlWinAuthors->Hide();
123 m_htmlWinLicense->Hide();
124 m_htmlWinHelp->Show();
125 m_scrolledWindowAbout->Hide();
126 m_btnBack->Show();
127#if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
128 m_btnBack->Enable(m_htmlWinHelp->CanGoBack());
129#else
130 m_btnBack->Enable(m_htmlWinHelp->HistoryCanBack());
131#endif
132 wxSize parentSize = m_parent->GetSize();
133 SetSize(wxSize(parentSize.x * 9 / 10, parentSize.y * 9 / 10));
134 Centre();
135 }
136}
137
138void AboutFrameImpl::OnLinkLicense(wxHyperlinkEvent& event) {
139 m_htmlWinAuthors->Hide();
140 m_htmlWinLicense->Show();
141 m_htmlWinHelp->Hide();
142 m_btnBack->Hide();
143 m_scrolledWindowAbout->Hide();
144 Layout();
145}
146
147void AboutFrameImpl::OnLinkAuthors(wxHyperlinkEvent& event) {
148 m_htmlWinAuthors->Show();
149 m_htmlWinLicense->Hide();
150 m_htmlWinHelp->Hide();
151 m_btnBack->Hide();
152 m_scrolledWindowAbout->Hide();
153 Layout();
154}
155
156void AboutFrameImpl::AboutFrameOnActivate(wxActivateEvent& event) {
157 m_htmlWinAuthors->Hide();
158 m_htmlWinLicense->Hide();
159 m_htmlWinHelp->Hide();
160 m_btnBack->Hide();
161 m_scrolledWindowAbout->Show();
162 Layout();
163 m_scrolledWindowAbout->Refresh();
164 m_panelMainLinks->Refresh();
165}
166
167void AboutFrameImpl::RecalculateSize(void) {
168#ifdef __ANDROID__
169 // Make an estimate of the dialog size, without scrollbars showing
170
171 wxSize esize;
172 esize.x = GetCharWidth() * 110;
173 esize.y = GetCharHeight() * 20;
174
175 wxSize dsize = GetParent()->GetClientSize();
176 esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
177 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
178 SetClientSize(esize);
179
180 wxSize fsize = GetSize();
181 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
182 fsize.x = wxMin(fsize.x, dsize.x - (1 * GetCharHeight()));
183
184 SetSize(fsize);
185 Centre();
186
187#else
188 Fit();
189 Centre();
190#endif
191}
Class AboutFrameImpl.
About dialog main frame, various controls to display information about OpenCPN.
Definition about_frame.h:57
General purpose GUI support.