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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 **************************************************************************/
19
25#include <fstream>
26#include <sstream>
27#include <string>
28
29#include "about_frame_impl.h"
30#include "config.h"
31#include "OCPNPlatform.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
43extern OCPNPlatform* g_Platform;
44
46static void LoadAuthors(wxHtmlWindow& hyperlink) {
47 fs::path datadir(g_Platform->GetSharedDataDir().ToStdString());
48 std::ifstream stream(datadir / "Authors.html");
49 std::stringstream ss;
50 ss << stream.rdbuf();
51 hyperlink.SetPage(wxString::FromUTF8(ss.str().c_str()));
52}
53
54AboutFrameImpl::AboutFrameImpl(wxWindow* parent, wxWindowID id,
55 const wxString& title, const wxPoint& pos,
56 const wxSize& size, long style)
57 : AboutFrame(parent, id, title, pos, size, style) {
58 if (strlen(DEBIAN_PPA_VERSION))
59 m_staticTextVersion->SetLabel(wxString(DEBIAN_PPA_VERSION));
60 else
61 m_staticTextVersion->SetLabel(PACKAGE_VERSION);
62
63 m_staticTextCopyYears->SetLabel("\u00A9 2000-2024");
64 m_hyperlinkIniFile->SetLabel(g_Platform->GetConfigFileName());
65 m_hyperlinkIniFile->SetURL(g_Platform->GetConfigFileName());
66 m_hyperlinkLogFile->SetLabel(g_Platform->GetLogFileName());
67 m_hyperlinkLogFile->SetURL(g_Platform->GetLogFileName());
68 m_htmlWinAuthors->Hide();
69 m_htmlWinLicense->Hide();
70 m_htmlWinHelp->Hide();
71 m_btnBack->Hide();
72 m_htmlWinLicense->LoadFile(wxString::Format(
73 "%s/license.html", g_Platform->GetSharedDataDir().c_str()));
74 LoadAuthors(*m_htmlWinAuthors);
75 wxBitmap logo(wxString::Format("%s/opencpn.png",
76 g_Platform->GetSharedDataDir().c_str()),
77 wxBITMAP_TYPE_ANY);
78
79 wxString target = wxString::Format("%sdoc/local/toc_flat.html",
80 g_Platform->GetSharedDataDir().c_str());
81
82 if (!::wxFileExists(target))
83 target = wxString::Format("%sdoc/help_web.html",
84 g_Platform->GetSharedDataDir().c_str());
85
86 target.Prepend("file://");
87
88 m_hyperlinkHelp->SetURL(target);
89#if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
90 m_htmlWinHelp->LoadURL(target);
91#else
92 m_htmlWinHelp->LoadFile(target);
93#endif
94 m_bitmapLogo->SetBitmap(logo);
95
96 int width = m_scrolledWindowAbout->GetSizer()->GetSize().GetWidth() +
97 m_bitmapLogo->GetSize().GetWidth() + EXTEND_WIDTH;
98 int height = m_scrolledWindowAbout->GetSizer()->GetSize().GetHeight() +
99 m_panelMainLinks->GetSizer()->GetSize().GetHeight() +
100 EXTEND_HEIGHT;
101
102 SetMinSize(wxSize(width, height));
103 RecalculateSize();
104}
105
106void AboutFrameImpl::OnLinkHelp(wxHyperlinkEvent& event) {
107#ifdef __WXGTK__
108 wxString testFile = wxString::Format("/%s/doc/help_web.html",
109 g_Platform->GetSharedDataDir().c_str());
110 if (!::wxFileExists(testFile)) {
111 wxString msg = _("OpenCPN Help documentation is not available locally.");
112 msg += _T("\n");
113 msg +=
114 _("Would you like to visit the opencpn.org website for more "
115 "information?");
116
117 if (wxID_YES ==
118 OCPNMessageBox(NULL, msg, _("OpenCPN Info"), wxYES_NO | wxCENTER, 60)) {
119 wxLaunchDefaultBrowser(_T("https://opencpn.org"));
120 }
121 } else
122#endif
123 {
124 m_htmlWinAuthors->Hide();
125 m_htmlWinLicense->Hide();
126 m_htmlWinHelp->Show();
127 m_scrolledWindowAbout->Hide();
128 m_btnBack->Show();
129#if wxUSE_WEBVIEW && defined(HAVE_WEBVIEW)
130 m_btnBack->Enable(m_htmlWinHelp->CanGoBack());
131#else
132 m_btnBack->Enable(m_htmlWinHelp->HistoryCanBack());
133#endif
134 wxSize parentSize = m_parent->GetSize();
135 SetSize(wxSize(parentSize.x * 9 / 10, parentSize.y * 9 / 10));
136 Centre();
137 }
138}
139
140void AboutFrameImpl::OnLinkLicense(wxHyperlinkEvent& event) {
141 m_htmlWinAuthors->Hide();
142 m_htmlWinLicense->Show();
143 m_htmlWinHelp->Hide();
144 m_btnBack->Hide();
145 m_scrolledWindowAbout->Hide();
146 Layout();
147}
148
149void AboutFrameImpl::OnLinkAuthors(wxHyperlinkEvent& event) {
150 m_htmlWinAuthors->Show();
151 m_htmlWinLicense->Hide();
152 m_htmlWinHelp->Hide();
153 m_btnBack->Hide();
154 m_scrolledWindowAbout->Hide();
155 Layout();
156}
157
158void AboutFrameImpl::AboutFrameOnActivate(wxActivateEvent& event) {
159 m_htmlWinAuthors->Hide();
160 m_htmlWinLicense->Hide();
161 m_htmlWinHelp->Hide();
162 m_btnBack->Hide();
163 m_scrolledWindowAbout->Show();
164 Layout();
165 m_scrolledWindowAbout->Refresh();
166 m_panelMainLinks->Refresh();
167}
168
169void AboutFrameImpl::RecalculateSize(void) {
170#ifdef __OCPN__ANDROID__
171 // Make an estimate of the dialog size, without scrollbars showing
172
173 wxSize esize;
174 esize.x = GetCharWidth() * 110;
175 esize.y = GetCharHeight() * 20;
176
177 wxSize dsize = GetParent()->GetClientSize();
178 esize.y = wxMin(esize.y, dsize.y - (2 * GetCharHeight()));
179 esize.x = wxMin(esize.x, dsize.x - (1 * GetCharHeight()));
180 SetClientSize(esize);
181
182 wxSize fsize = GetSize();
183 fsize.y = wxMin(fsize.y, dsize.y - (2 * GetCharHeight()));
184 fsize.x = wxMin(fsize.x, dsize.x - (1 * GetCharHeight()));
185
186 SetSize(fsize);
187 Centre();
188
189#else
190 Fit();
191 Centre();
192#endif
193}
Class AboutFrameImpl.
About dialog main frame, various controls to display information about OpenCPN.
Definition about_frame.h:57
Provides platform-specific support utilities for OpenCPN.
General purpose GUI support.