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.

338 lines
13 KiB

  1. /***************************************************************
  2. * Name: dialog_about.cpp
  3. * Purpose: Code for Application Frame
  4. * Author: Rafael Sokolowski (rafael.sokolowski@web.de)
  5. * Created: 2010-08-06
  6. * Copyright: Rafael Sokolowski ()
  7. * License:
  8. **************************************************************/
  9. #include "dialog_about.h"
  10. ///////////////////////////////////////////////////////////////////////////////
  11. /// Class dialog_about methods
  12. ///////////////////////////////////////////////////////////////////////////////
  13. dialog_about::dialog_about(wxWindow *parent, AboutAppInfo& appInfo)
  14. : dialog_about_base(parent), info(appInfo)
  15. {
  16. picInformation = wxBitmap(info_xpm);
  17. picDevelopers = wxBitmap(preference_xpm);
  18. picDocWriters = wxBitmap(editor_xpm);
  19. picArtists = wxBitmap(palette_xpm);
  20. picTranslators = wxBitmap(language_xpm);
  21. picLicense = wxBitmap(tools_xpm);
  22. m_bitmapApp->SetBitmap( info.GetIcon() );
  23. m_staticTextAppTitle->SetLabel( info.GetAppName() );
  24. m_staticTextCopyright->SetLabel( info.GetCopyright() );
  25. m_staticTextBuildVersion->SetLabel( info.GetBuildVersion() );
  26. m_staticTextLibVersion->SetLabel( info.GetLibVersion() );
  27. /* Affects m_titlepanel the parent of some wxStaticText.
  28. * Changing the text afterwards makes it under Windows necessary to call 'Layout()'
  29. * so that the new text gets properly layout.
  30. */
  31. /* m_staticTextCopyright->GetParent()->Layout();
  32. m_staticTextBuildVersion->GetParent()->Layout();
  33. m_staticTextLibVersion->GetParent()->Layout();
  34. */
  35. DeleteNotebooks();
  36. CreateNotebooks();
  37. GetSizer()->SetSizeHints(this);
  38. m_auiNotebook->Update();
  39. Centre();
  40. }
  41. dialog_about::~dialog_about()
  42. {
  43. }
  44. wxFlexGridSizer* dialog_about::CreateFlexGridSizer()
  45. {
  46. // three colums with vertical and horizontal extra space of two pixels
  47. wxFlexGridSizer* fgSizer1 = new wxFlexGridSizer( 3, 2, 2 );
  48. fgSizer1->SetFlexibleDirection( wxHORIZONTAL );
  49. fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
  50. return fgSizer1;
  51. }
  52. void dialog_about::DeleteNotebooks()
  53. {
  54. for( size_t i=0; i<m_auiNotebook->GetPageCount(); ++i )
  55. m_auiNotebook->DeletePage(i);
  56. }
  57. void dialog_about::CreateNotebooks()
  58. {
  59. CreateNotebookHtmlPage( m_auiNotebook, _("Information"), picInformation, info.GetDescription() );
  60. CreateNotebookPage( m_auiNotebook, _("Developers") , picDevelopers, info.GetDevelopers() );
  61. CreateNotebookPage( m_auiNotebook, _("Doc Writers"), picDocWriters, info.GetDocWriters() );
  62. CreateNotebookPageByCategory( m_auiNotebook, _("Artists") , picArtists, info.GetArtists() );
  63. CreateNotebookPageByCategory( m_auiNotebook, _("Translators"), picTranslators, info.GetTranslators() );
  64. CreateNotebookHtmlPage( m_auiNotebook, _("License"), picLicense, info.GetLicense() );
  65. }
  66. void dialog_about::CreateNotebookPage(wxAuiNotebook* parent, const wxString& caption, const wxBitmap& icon, const Contributors& contributors)
  67. {
  68. wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );
  69. wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
  70. m_scrolledWindow1->SetScrollRate( 5, 5 );
  71. /* Panel for additional space at the left,
  72. * but can also be used to show an additional bitmap.
  73. */
  74. wxPanel* panel1 = new wxPanel(m_scrolledWindow1);
  75. wxFlexGridSizer* fgSizer1 = CreateFlexGridSizer();
  76. for ( size_t i=0; i<contributors.GetCount(); ++i)
  77. {
  78. Contributor* contributor = &contributors.Item(i);
  79. // Icon at first column
  80. wxStaticBitmap* m_bitmap1 = CreateStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
  81. fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
  82. // Name of contributor at second column
  83. if ( contributor->GetName() != wxEmptyString )
  84. {
  85. wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY, contributor->GetName(), wxDefaultPosition, wxDefaultSize, 0 );
  86. m_staticText1->Wrap( -1 );
  87. fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  88. }
  89. else {
  90. fgSizer1->AddSpacer(5);
  91. }
  92. // Email address of contributor at third column
  93. if ( contributor->GetEMail() != wxEmptyString )
  94. {
  95. wxHyperlinkCtrl* hyperlink = CreateHyperlink( m_scrolledWindow1, contributor->GetEMail() );
  96. fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  97. }
  98. else {
  99. fgSizer1->AddSpacer(5);
  100. }
  101. }
  102. bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
  103. bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
  104. m_scrolledWindow1->SetSizer( bSizer );
  105. m_scrolledWindow1->Layout();
  106. bSizer->Fit( m_scrolledWindow1 );
  107. parent->AddPage( m_scrolledWindow1, caption, false, icon );
  108. }
  109. void dialog_about::CreateNotebookPageByCategory(wxAuiNotebook* parent, const wxString& caption, const wxBitmap& icon, const Contributors& contributors)
  110. {
  111. wxBoxSizer* bSizer = new wxBoxSizer( wxHORIZONTAL );
  112. wxScrolledWindow* m_scrolledWindow1 = new wxScrolledWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
  113. m_scrolledWindow1->SetScrollRate( 5, 5 );
  114. /* Panel for additional space at the left,
  115. * but can also be used to show an additional bitmap.
  116. */
  117. wxPanel* panel1 = new wxPanel(m_scrolledWindow1);
  118. wxFlexGridSizer* fgSizer1 = CreateFlexGridSizer();
  119. for ( size_t i=0; i<contributors.GetCount(); ++i)
  120. {
  121. Contributor* contributor = &contributors.Item(i);
  122. wxBitmap* icon = contributor->GetIcon();
  123. wxString category = contributor->GetCategory();
  124. /* to construct the next row we expect to have
  125. * a category and a contributor that was not considered up to now
  126. */
  127. if ( ( category != wxEmptyString ) && !( contributor->IsChecked() ) )
  128. {
  129. // Icon at first column
  130. wxStaticBitmap* m_bitmap1 = CreateStaticBitmap( m_scrolledWindow1, icon );
  131. fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
  132. // Category name at second column
  133. wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY, contributor->GetCategory() + wxT(":"), wxDefaultPosition, wxDefaultSize, 0 );
  134. m_staticText1->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) ); // bold font
  135. m_staticText1->Wrap( -1 );
  136. fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  137. // Nothing at third column
  138. fgSizer1->AddSpacer(5);
  139. // Now, all contributors of the same category will follow
  140. for ( size_t j=0; j<contributors.GetCount(); ++j )
  141. {
  142. Contributor* contributor = &contributors.Item(j);
  143. if ( contributor->GetCategory() == category )
  144. {
  145. // First column is empty
  146. fgSizer1->AddSpacer(5);
  147. // Name of contributor at second column
  148. wxStaticText* m_staticText2 = new wxStaticText( m_scrolledWindow1, wxID_ANY, wxT("") + contributor->GetName(), wxDefaultPosition, wxDefaultSize, 0 );
  149. m_staticText1->Wrap( -1 );
  150. fgSizer1->Add( m_staticText2, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  151. // Email address of contributor at third column
  152. if ( contributor->GetEMail() != wxEmptyString )
  153. {
  154. wxHyperlinkCtrl* hyperlink = CreateHyperlink( m_scrolledWindow1, contributor->GetEMail() );
  155. fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  156. }
  157. else {
  158. fgSizer1->AddSpacer(5);
  159. }
  160. /* this contributor was added to the gui,
  161. * thus can be ignored next time
  162. */
  163. contributor->SetChecked( true );
  164. }
  165. }
  166. }
  167. else {
  168. continue;
  169. }
  170. }
  171. /* Now, lets list the remaining contributors that have not been considered
  172. * because they were not assigned to any category.
  173. */
  174. for ( size_t k=0; k<contributors.GetCount(); ++k )
  175. {
  176. Contributor* contributor = &contributors.Item(k);
  177. if ( contributor->IsChecked() )
  178. continue;
  179. // Icon at first column
  180. wxStaticBitmap* m_bitmap1 = CreateStaticBitmap( m_scrolledWindow1, contributor->GetIcon() );
  181. fgSizer1->Add( m_bitmap1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5 );
  182. // Name of contributor at second column
  183. if ( contributor->GetName() != wxEmptyString )
  184. {
  185. wxStaticText* m_staticText1 = new wxStaticText( m_scrolledWindow1, wxID_ANY, contributor->GetName(), wxDefaultPosition, wxDefaultSize, 0 );
  186. m_staticText1->Wrap( -1 );
  187. fgSizer1->Add( m_staticText1, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  188. }
  189. else {
  190. fgSizer1->AddSpacer(5);
  191. }
  192. // Email address of contributor at third column
  193. if ( contributor->GetEMail() != wxEmptyString )
  194. {
  195. wxHyperlinkCtrl* hyperlink = CreateHyperlink( m_scrolledWindow1, contributor->GetEMail() );
  196. fgSizer1->Add( hyperlink, 0, wxALIGN_LEFT|wxBOTTOM, 2 );
  197. }
  198. else {
  199. fgSizer1->AddSpacer(5);
  200. }
  201. }
  202. bSizer->Add( panel1, 1, wxEXPAND|wxALL, 10 );
  203. bSizer->Add( fgSizer1, 7, wxEXPAND|wxALL, 10 ); // adjust width of panel with first int value
  204. m_scrolledWindow1->SetSizer( bSizer );
  205. m_scrolledWindow1->Layout();
  206. bSizer->Fit( m_scrolledWindow1 );
  207. parent->AddPage( m_scrolledWindow1, caption, false, icon );
  208. }
  209. void dialog_about::CreateNotebookHtmlPage(wxAuiNotebook* parent, const wxString& caption, const wxBitmap& icon, const wxString& html)
  210. {
  211. wxPanel* panel = new wxPanel( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
  212. wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL );
  213. wxString htmlPage = wxEmptyString, htmlContent = html;
  214. // to have a unique look background color for HTML pages is set to the default as it is used for all the other widgets
  215. wxString htmlColor = ( this->GetBackgroundColour() ).GetAsString( wxC2S_HTML_SYNTAX );
  216. // beginning of html structure
  217. htmlPage.Append( wxT("<html><body bgcolor='") + htmlColor + wxT("'>") );
  218. htmlPage.Append( htmlContent );
  219. // end of html structure indicated by closing tags
  220. htmlPage.Append( wxT("</body></html>") );
  221. // the html page is going to be created with previously created html content
  222. wxHtmlWindow* htmlWindow = new wxHtmlWindow( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO|wxHW_NO_SELECTION );
  223. // HTML font set to font properties as they are used for widgets to have an unique look under different platforms with HTML
  224. wxFont font = this->GetFont();
  225. htmlWindow->SetStandardFonts( font.GetPointSize(), font.GetFaceName(), font.GetFaceName() );
  226. htmlWindow->SetPage( htmlPage );
  227. // the HTML window shall not be used to open external links, thus this task is delegated to users default browser
  228. htmlWindow->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( dialog_about::OnHtmlLinkClicked ), NULL, this );
  229. // no additional space around the html window as it is also the case by the other notebook pages
  230. bSizer->Add( htmlWindow, 1, wxALL|wxEXPAND, 0 );
  231. panel->SetSizer( bSizer );
  232. panel->Layout();
  233. bSizer->Fit( panel );
  234. parent->AddPage( panel, caption, false, icon );
  235. }
  236. wxHyperlinkCtrl* dialog_about::CreateHyperlink(wxScrolledWindow* parent, const wxString& email)
  237. {
  238. wxHyperlinkCtrl* hyperlink = new wxHyperlinkCtrl(
  239. parent, wxID_ANY,
  240. wxT("<") + email + wxT(">"), /* the label */
  241. wxT("mailto:") + email
  242. + wxT("?subject=KiCad - ")
  243. + info.GetBuildVersion()
  244. + wxT( " , ") + info.GetLibVersion()
  245. ); /* the url */
  246. return hyperlink;
  247. }
  248. wxStaticBitmap* dialog_about::CreateStaticBitmap(wxScrolledWindow* parent, wxBitmap* icon)
  249. {
  250. wxStaticBitmap* bitmap = new wxStaticBitmap( parent, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
  251. if ( icon )
  252. {
  253. bitmap->SetBitmap( *icon );
  254. }
  255. else {
  256. bitmap->SetBitmap( right_xpm );
  257. }
  258. return bitmap;
  259. }
  260. ///////////////////////////////////////////////////////////////////////////////
  261. /// Event handlers
  262. ///////////////////////////////////////////////////////////////////////////////
  263. void dialog_about::OnClose(wxCloseEvent &event)
  264. {
  265. Destroy();
  266. }
  267. void dialog_about::OnOkClick(wxCommandEvent &event)
  268. {
  269. Destroy();
  270. }
  271. void dialog_about::OnHtmlLinkClicked( wxHtmlLinkEvent& event )
  272. {
  273. ::wxLaunchDefaultBrowser( event.GetLinkInfo().GetHref() );
  274. }