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