You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

491 lines
19 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010 Rafael Sokolowski <Rafael.Sokolowski@web.de>
  5. * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <config.h>
  25. #include <string>
  26. #include <wx/clipbrd.h>
  27. #include <wx/msgdlg.h>
  28. #include <wx/hyperlink.h>
  29. /* All KiCad icons are linked into shared library 'libbitmaps.a'.
  30. * Icons:
  31. * preference_xpm; // Icon for 'Developers' tab
  32. * editor_xpm; // Icon for 'Doc Writers' tab
  33. * color_materials_xpm; // Icon for 'Artists' tab
  34. * language_xpm; // Icon for 'Translators' tab
  35. * right_xpm; // Right arrow icon for list items
  36. * info_xpm; // Bulb for description tab
  37. * tools_xpm; // Sheet of paper icon for license info tab
  38. */
  39. #include <bitmaps.h>
  40. #include <build_version.h>
  41. #include <dialogs/html_message_box.h>
  42. #include <tool/tool_manager.h>
  43. #include "dialog_about.h"
  44. DIALOG_ABOUT::DIALOG_ABOUT( EDA_BASE_FRAME *aParent, ABOUT_APP_INFO& aAppInfo )
  45. : DIALOG_ABOUT_BASE( aParent ), m_info( aAppInfo )
  46. {
  47. wxASSERT( aParent != nullptr );
  48. // TODO: Change these to 16x16 versions when available
  49. m_images = new wxImageList( 24, 24, false, 9 );
  50. m_images->Add( KiBitmap( BITMAPS::info ) ); // INFORMATION
  51. m_images->Add( KiBitmap( BITMAPS::recent ) ); // VERSION
  52. m_images->Add( KiBitmap( BITMAPS::preference ) ); // DEVELOPERS
  53. m_images->Add( KiBitmap( BITMAPS::editor ) ); // DOCWRITERS
  54. m_images->Add( KiBitmap( BITMAPS::library ) ); // LIBRARIANS
  55. m_images->Add( KiBitmap( BITMAPS::color_materials ) ); // ARTISTS
  56. m_images->Add( KiBitmap( BITMAPS::language ) ); // TRANSLATORS
  57. m_images->Add( KiBitmap( BITMAPS::zip ) ); // PACKAGERS
  58. m_images->Add( KiBitmap( BITMAPS::tools ) ); // LICENSE
  59. m_notebook->SetImageList( m_images );
  60. if( m_info.GetAppIcon().IsOk() )
  61. {
  62. SetIcon( m_info.GetAppIcon() );
  63. m_bitmapApp->SetBitmap( m_info.GetAppIcon() );
  64. }
  65. else
  66. {
  67. wxIcon icon;
  68. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_kicad ) );
  69. SetIcon( icon );
  70. m_bitmapApp->SetBitmap( icon );
  71. }
  72. m_titleName = aParent->GetAboutTitle();
  73. m_staticTextAppTitle->SetLabel( m_titleName );
  74. m_staticTextCopyright->SetLabel( m_info.GetCopyright() );
  75. m_staticTextBuildVersion->SetLabel( "Version: " + m_info.GetBuildVersion() );
  76. m_staticTextLibVersion->SetLabel( m_info.GetLibVersion() );
  77. SetTitle( wxString::Format( _( "About %s" ), m_titleName ) );
  78. createNotebooks();
  79. GetSizer()->SetSizeHints( this );
  80. SetFocus();
  81. Centre();
  82. }
  83. DIALOG_ABOUT::~DIALOG_ABOUT()
  84. {
  85. delete m_images;
  86. }
  87. wxFlexGridSizer* DIALOG_ABOUT::createFlexGridSizer()
  88. {
  89. // three columns with vertical and horizontal extra space of two pixels
  90. wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 3, 2, 2 );
  91. fgSizer->SetFlexibleDirection( wxHORIZONTAL );
  92. fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
  93. return fgSizer;
  94. }
  95. void DIALOG_ABOUT::createNotebooks()
  96. {
  97. createNotebookHtmlPage( m_notebook, _( "About" ), IMAGES::INFORMATION,
  98. m_info.GetDescription() );
  99. wxString version = GetVersionInfoData( m_titleName, true );
  100. createNotebookHtmlPage( m_notebook, _( "Version" ), IMAGES::VERSION, version, true );
  101. createNotebookPageByCategory( m_notebook, _( "Developers" ) , IMAGES::DEVELOPERS,
  102. m_info.GetDevelopers() );
  103. createNotebookPage( m_notebook, _( "Doc Writers" ), IMAGES::DOCWRITERS,
  104. m_info.GetDocWriters() );
  105. createNotebookPageByCategory( m_notebook, _( "Librarians" ), IMAGES::LIBRARIANS,
  106. m_info.GetLibrarians() );
  107. createNotebookPageByCategory( m_notebook, _( "Artists" ), IMAGES::ARTISTS,
  108. m_info.GetArtists() );
  109. createNotebookPageByCategory( m_notebook, _( "Translators" ), IMAGES::TRANSLATORS,
  110. m_info.GetTranslators() );
  111. createNotebookPageByCategory( m_notebook, _( "Packagers" ), IMAGES::PACKAGERS,
  112. m_info.GetPackagers() );
  113. createNotebookHtmlPage( m_notebook, _( "License" ), IMAGES::LICENSE, m_info.GetLicense() );
  114. }
  115. void DIALOG_ABOUT::createNotebookPage( wxNotebook* aParent, const wxString& aCaption,
  116. IMAGES aIconIndex, const CONTRIBUTORS& aContributors )
  117. {
  118. wxPanel* outerPanel = new wxPanel( aParent );
  119. wxBoxSizer* outerSizer = new wxBoxSizer( wxVERTICAL );
  120. wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );
  121. wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( outerPanel, wxID_ANY,
  122. wxDefaultPosition,
  123. wxDefaultSize,
  124. wxHSCROLL|wxVSCROLL );
  125. m_scrolledWindow1->SetScrollRate( 5, 5 );
  126. /* Panel for additional space at the left,
  127. * but can also be used to show an additional bitmap.
  128. */
  129. wxPanel* panel1 = new wxPanel( m_scrolledWindow1 );
  130. wxFlexGridSizer* fgSizer1 = createFlexGridSizer();
  131. for( size_t i=0; i<aContributors.GetCount(); ++i )
  132. {
  133. CONTRIBUTOR* contributor = &aContributors.Item( i );
  134. // Icon at first column
  135. wxStaticBitmap* m_bitmap1 = createStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
  136. fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
  137. // Name of contributor at second column
  138. if ( contributor->GetName() != wxEmptyString )
  139. {
  140. wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY,
  141. contributor->GetName(),
  142. wxDefaultPosition, wxDefaultSize, 0 );
  143. m_staticText1->Wrap( -1 );
  144. fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  145. }
  146. else
  147. {
  148. fgSizer1->AddSpacer( 5 );
  149. }
  150. // Email address of contributor at third column
  151. if ( contributor->GetExtra() != wxEmptyString )
  152. {
  153. wxStaticText* hyperlink = wxStaticTextRef( m_scrolledWindow1,
  154. contributor->GetExtra() );
  155. fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  156. }
  157. else
  158. {
  159. fgSizer1->AddSpacer( 5 );
  160. }
  161. }
  162. bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
  163. bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
  164. m_scrolledWindow1->SetSizer( bSizer );
  165. m_scrolledWindow1->Layout();
  166. bSizer->Fit( m_scrolledWindow1 );
  167. outerSizer->Add( m_scrolledWindow1, 1, wxEXPAND, 0 );
  168. outerPanel->SetSizer( outerSizer );
  169. aParent->AddPage( outerPanel, aCaption, false, static_cast<int>( aIconIndex ) );
  170. }
  171. void DIALOG_ABOUT::createNotebookPageByCategory( wxNotebook* aParent, const wxString& aCaption,
  172. IMAGES aIconIndex,
  173. const CONTRIBUTORS& aContributors )
  174. {
  175. // The left justification between wxStaticText and wxHyperlinkCtrl is different so
  176. // we must pad to make the alignment look decent.
  177. //
  178. // @todo Just make all of the contributor lists HTML so the alignment is consistent.
  179. wxString padding;
  180. // Of course the padding is different depending on the platform so we adjust the
  181. // padding accordingly.
  182. #if defined( __WXGTK__ )
  183. padding += " ";
  184. #endif
  185. wxPanel* outerPanel = new wxPanel( aParent );
  186. wxBoxSizer* outerSizer = new wxBoxSizer( wxVERTICAL );
  187. wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );
  188. wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( outerPanel, wxID_ANY,
  189. wxDefaultPosition,
  190. wxDefaultSize,
  191. wxHSCROLL|wxVSCROLL );
  192. m_scrolledWindow1->SetScrollRate( 5, 5 );
  193. /* Panel for additional space at the left,
  194. * but can also be used to show an additional bitmap.
  195. */
  196. wxPanel* panel1 = new wxPanel( m_scrolledWindow1 );
  197. wxFlexGridSizer* fgSizer1 = createFlexGridSizer();
  198. for( size_t i=0; i < aContributors.GetCount(); ++i )
  199. {
  200. CONTRIBUTOR* contributor = &aContributors.Item( i );
  201. wxBitmap* icon = contributor->GetIcon();
  202. wxString category = contributor->GetCategory();
  203. /* to construct the next row we expect to have
  204. * a category and a contributor that was not considered up to now
  205. */
  206. if( ( category != wxEmptyString ) && !( contributor->IsChecked() ) )
  207. {
  208. // Icon at first column
  209. wxStaticBitmap* m_bitmap1 = createStaticBitmap( m_scrolledWindow1, icon );
  210. fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
  211. // Category name at second column
  212. wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY,
  213. contributor->GetCategory() + wxT( ":" ),
  214. wxDefaultPosition, wxDefaultSize, 0 );
  215. m_staticText1->SetFont( m_staticText1->GetFont().Bold() );
  216. m_staticText1->Wrap( -1 );
  217. fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM|wxEXPAND, 2 );
  218. // Nothing at third column
  219. fgSizer1->AddSpacer( 5 );
  220. // Now, all contributors of the same category will follow
  221. for( size_t j=0; j < aContributors.GetCount(); ++j )
  222. {
  223. CONTRIBUTOR* sub_contributor = &aContributors.Item( j );
  224. if ( sub_contributor->GetCategory() == category )
  225. {
  226. // First column is empty
  227. fgSizer1->AddSpacer( 5 );
  228. wxControl* ctrl;
  229. // No URL supplied, display normal text control
  230. if( sub_contributor->GetUrl().IsEmpty() )
  231. {
  232. ctrl = new wxStaticText( m_scrolledWindow1, wxID_ANY,
  233. padding + wxT( "" ) + sub_contributor->GetName(),
  234. wxDefaultPosition,
  235. wxDefaultSize, 0 );
  236. }
  237. else
  238. {
  239. // Display a hyperlink control instead
  240. ctrl = new wxHyperlinkCtrl( m_scrolledWindow1, wxID_ANY,
  241. wxT( "" ) + sub_contributor->GetName(),
  242. sub_contributor->GetUrl(),
  243. wxDefaultPosition,
  244. wxDefaultSize,
  245. wxBORDER_NONE | wxHL_CONTEXTMENU | wxHL_ALIGN_LEFT );
  246. }
  247. m_staticText1->Wrap( -1 );
  248. fgSizer1->Add( ctrl, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  249. // Email address of contributor at third column
  250. if( sub_contributor->GetExtra() != wxEmptyString )
  251. {
  252. wxStaticText* mail = wxStaticTextRef( m_scrolledWindow1,
  253. sub_contributor->GetExtra() );
  254. fgSizer1->Add( mail, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  255. }
  256. else
  257. {
  258. fgSizer1->AddSpacer( 5 );
  259. }
  260. /* this contributor was added to the GUI,
  261. * thus can be ignored next time
  262. */
  263. sub_contributor->SetChecked( true );
  264. }
  265. }
  266. }
  267. else
  268. {
  269. continue;
  270. }
  271. }
  272. /* Now, lets list the remaining contributors that have not been considered
  273. * because they were not assigned to any category.
  274. */
  275. for ( size_t k=0; k < aContributors.GetCount(); ++k )
  276. {
  277. CONTRIBUTOR* contributor = &aContributors.Item( k );
  278. if ( contributor->IsChecked() )
  279. continue;
  280. // Icon at first column
  281. wxStaticBitmap* m_bitmap1 = createStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
  282. fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
  283. // Name of contributor at second column
  284. if( contributor->GetName() != wxEmptyString )
  285. {
  286. wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY,
  287. contributor->GetName(),
  288. wxDefaultPosition, wxDefaultSize, 0 );
  289. m_staticText1->Wrap( -1 );
  290. fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  291. }
  292. else
  293. {
  294. fgSizer1->AddSpacer( 5 );
  295. }
  296. // Email address of contributor at third column
  297. if ( contributor->GetExtra() != wxEmptyString )
  298. {
  299. wxStaticText* mail = wxStaticTextRef( m_scrolledWindow1, contributor->GetExtra() );
  300. fgSizer1->Add( mail, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  301. }
  302. else
  303. {
  304. fgSizer1->AddSpacer( 5 );
  305. }
  306. }
  307. bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
  308. bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
  309. m_scrolledWindow1->SetSizer( bSizer );
  310. m_scrolledWindow1->Layout();
  311. bSizer->Fit( m_scrolledWindow1 );
  312. outerSizer->Add( m_scrolledWindow1, 1, wxEXPAND, 0 );
  313. outerPanel->SetSizer( outerSizer );
  314. aParent->AddPage( outerPanel, aCaption, false, static_cast<int>( aIconIndex ) );
  315. }
  316. void DIALOG_ABOUT::createNotebookHtmlPage( wxNotebook* aParent, const wxString& aCaption,
  317. IMAGES aIconIndex, const wxString& html,
  318. bool aSelection )
  319. {
  320. wxPanel* panel = new wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  321. wxTAB_TRAVERSAL );
  322. wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
  323. int flags = aSelection ? wxHW_SCROLLBAR_AUTO : ( wxHW_SCROLLBAR_AUTO | wxHW_NO_SELECTION );
  324. // the HTML page is going to be created with previously created HTML content
  325. HTML_WINDOW* htmlWindow = new HTML_WINDOW( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  326. flags );
  327. // HTML font set to font properties as they are used for widgets to have an unique look
  328. // under different platforms with HTML
  329. wxFont font = GetFont();
  330. htmlWindow->SetStandardFonts( font.GetPointSize(), font.GetFaceName(), font.GetFaceName() );
  331. htmlWindow->SetPage( html );
  332. // the HTML window shall not be used to open external links, thus this task is delegated
  333. // to users default browser
  334. htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED,
  335. wxHtmlLinkEventHandler( DIALOG_ABOUT::onHtmlLinkClicked ), NULL, this );
  336. // no additional space around the HTML window as it is also the case by the other notebook pages
  337. bSizer->Add( htmlWindow, 1, wxEXPAND, 0 );
  338. panel->SetSizer( bSizer );
  339. aParent->AddPage( panel, aCaption, false, static_cast<int>( aIconIndex ) );
  340. }
  341. wxStaticText* DIALOG_ABOUT::wxStaticTextRef( wxScrolledWindow* aParent, const wxString& aReference )
  342. {
  343. wxStaticText* text = new wxStaticText( aParent, wxID_ANY,
  344. wxT( "(" ) + aReference + wxT( ")" ) );
  345. return text;
  346. }
  347. wxStaticBitmap* DIALOG_ABOUT::createStaticBitmap( wxScrolledWindow* aParent, wxBitmap* aIcon )
  348. {
  349. wxStaticBitmap* bitmap = new wxStaticBitmap( aParent, wxID_ANY, wxNullBitmap,
  350. wxDefaultPosition, wxDefaultSize, 0 );
  351. if( aIcon )
  352. bitmap->SetBitmap( *aIcon );
  353. else
  354. bitmap->SetBitmap( KiBitmap( BITMAPS::right ) );
  355. return bitmap;
  356. }
  357. void DIALOG_ABOUT::onHtmlLinkClicked( wxHtmlLinkEvent& event )
  358. {
  359. ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );
  360. }
  361. void DIALOG_ABOUT::onCopyVersionInfo( wxCommandEvent& event )
  362. {
  363. wxLogNull doNotLog; // disable logging of failed clipboard actions
  364. if( !wxTheClipboard->Open() )
  365. {
  366. wxMessageBox( _( "Could not open clipboard to write version information." ),
  367. _( "Clipboard Error" ), wxOK | wxICON_EXCLAMATION, this );
  368. return;
  369. }
  370. wxString msg_version = GetVersionInfoData( m_titleName );
  371. wxTheClipboard->SetData( new wxTextDataObject( msg_version ) );
  372. wxTheClipboard->Flush(); // Allow clipboard data to be available after KiCad closes
  373. wxTheClipboard->Close();
  374. m_btCopyVersionInfo->SetLabel( _( "Copied..." ) );
  375. }
  376. void DIALOG_ABOUT::onDonateClick( wxCommandEvent& event )
  377. {
  378. if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
  379. mgr->RunAction( "common.SuiteControl.donate", true );
  380. }
  381. void DIALOG_ABOUT::onReportBug( wxCommandEvent& event )
  382. {
  383. if( TOOL_MANAGER* mgr = static_cast<EDA_BASE_FRAME*>( GetParent() )->GetToolManager() )
  384. mgr->RunAction( "common.SuiteControl.reportBug", true );
  385. }
  386. void DIALOG_ABOUT::OnNotebookPageChanged( wxNotebookEvent& aEvent )
  387. {
  388. // Work around wxMac issue where the notebook pages are blank
  389. #ifdef __WXMAC__
  390. int page = aEvent.GetSelection();
  391. if( page >= 0 )
  392. m_notebook->ChangeSelection( static_cast<unsigned>( page ) );
  393. #endif
  394. }