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