Audacity  3.0.3
SplashDialog.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  SplashDialog.cpp
6 
7  James Crook
8 
9 ********************************************************************//********************************************************************/
21 
22 
23 
24 #include "SplashDialog.h"
25 
26 
27 
28 #include <wx/dialog.h>
29 #include <wx/frame.h>
30 #include <wx/html/htmlwin.h>
31 #include <wx/button.h>
32 #include <wx/sizer.h>
33 #include <wx/statbmp.h>
34 #include <wx/intl.h>
35 #include <wx/image.h>
36 
37 #include "FileNames.h"
38 #include "Project.h"
39 #include "ProjectWindows.h"
40 #include "ShuttleGui.h"
42 #include "widgets/HelpSystem.h"
43 
44 #include "AllThemeResources.h"
45 #include "Prefs.h"
46 #include "HelpText.h"
47 
48 // DA: Logo for Splash Dialog (welcome dialog)
49 #ifdef EXPERIMENTAL_DA
50 #include "../images/DarkAudacityLogoWithName.xpm"
51 #else
52 #include "../images/AudacityLogoWithName.xpm"
53 #endif
54 
55 #ifdef HAS_WHATS_NEW
56 
57 #include "MemoryX.h"
58 #include <wx/fs_mem.h>
59 
60 namespace
61 {
62 const char* WhatsNewURL = "https://youtube.com";
63 
64 # include "../images/WhatsNewBtn.png.h"
65 
66 struct FSHelper final
67 {
68  FSHelper()
69  : mMemoryFSHandler(std::make_unique<wxMemoryFSHandler>())
70  {
71  wxFileSystem::AddHandler(mMemoryFSHandler.get());
72 
73  wxMemoryFSHandler::AddFile(
74  "whats_new_btn.png", bin2c_whats_new_btn_png,
75  sizeof(bin2c_whats_new_btn_png));
76  }
77 
78  ~FSHelper()
79  {
80  wxMemoryFSHandler::RemoveFile("whats_new_btn.png");
81  wxFileSystem::RemoveHandler(mMemoryFSHandler.get());
82  }
83 
84 private:
85  std::unique_ptr<wxMemoryFSHandler> mMemoryFSHandler;
86 };
87 
88 } // namespace
89 #endif
90 
92 
93 enum
94 {
95  DontShowID=1000,
96 };
97 
98 BEGIN_EVENT_TABLE(SplashDialog, wxDialogWrapper)
100  EVT_CHECKBOX( DontShowID, SplashDialog::OnDontShow )
102 
104 
105 void SplashDialog::DoHelpWelcome( AudacityProject &project )
106 {
107  Show2( &GetProjectFrame( project ) );
108 }
109 
110 SplashDialog::SplashDialog(wxWindow * parent)
111  : wxDialogWrapper(parent, -1, XO("Welcome to Audacity!"),
112  wxPoint( -1, 60 ), // default x position, y position 60 pixels from top of screen.
113  wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
114 {
115  SetName();
116  m_pLogo = NULL; //v
117  ShuttleGui S( this, eIsCreating );
118  Populate( S );
119  Fit();
120  this->Centre();
121  int x,y;
122  GetPosition( &x, &y );
123  Move( x, 60 );
124 }
125 
126 void SplashDialog::OnChar(wxMouseEvent &event)
127 {
128  if ( event.ShiftDown() && event.ControlDown() )
129  wxLaunchDefaultBrowser("https://www.audacityteam.org");
130 }
131 
133 {
134  bool bShow;
135  gPrefs->Read(wxT("/GUI/ShowSplashScreen"), &bShow, true );
136  S.StartVerticalLay(1);
137 
138  //v For now, change to AudacityLogoWithName via old-fashioned ways, not Theme.
139  m_pLogo = std::make_unique<wxBitmap>((const char **) AudacityLogoWithName_xpm); //v
140 
141 
142  // JKC: Resize to 50% of size. Later we may use a smaller xpm as
143  // our source, but this allows us to tweak the size - if we want to.
144  // It also makes it easier to revert to full size if we decide to.
145  const float fScale=0.5f;// smaller size.
146  wxImage RescaledImage( m_pLogo->ConvertToImage() );
147  wxColour MainColour(
148  RescaledImage.GetRed(1,1),
149  RescaledImage.GetGreen(1,1),
150  RescaledImage.GetBlue(1,1));
151  this->SetBackgroundColour(MainColour);
152 
153  // wxIMAGE_QUALITY_HIGH not supported by wxWidgets 2.6.1, or we would use it here.
154  RescaledImage.Rescale( (int)(LOGOWITHNAME_WIDTH * fScale), (int)(LOGOWITHNAME_HEIGHT *fScale) );
155  wxBitmap RescaledBitmap( RescaledImage );
156  wxStaticBitmap *const icon =
157  safenew wxStaticBitmap(S.GetParent(), -1,
158  //*m_pLogo, //v theTheme.Bitmap(bmpAudacityLogoWithName),
159  RescaledBitmap,
160  wxDefaultPosition,
161  wxSize((int)(LOGOWITHNAME_WIDTH*fScale), (int)(LOGOWITHNAME_HEIGHT*fScale)));
162 
163  S.Prop(0)
164 #if (0)
165  .ConnectRoot( wxEVT_LEFT_DOWN, &SplashDialog::OnChar)
166 #endif
167  .AddWindow( icon );
168 
170  wxDefaultPosition,
171  wxSize(506, 280),
172  wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER );
173  mpHtml->SetPage(HelpText( wxT("welcome") ));
174  S.Prop(1)
175  .Position( wxEXPAND )
176  .AddWindow( mpHtml );
177  S.Prop(0).StartMultiColumn(2, wxEXPAND);
178  S.SetStretchyCol( 1 );// Column 1 is stretchy...
179  {
180  S.SetBorder( 5 );
181  S.Id( DontShowID).AddCheckBox( XXO("Don't show this again at start up"), !bShow );
182  S.SetBorder( 5 );
183 
184  S.Id(wxID_OK)
185  .Prop(0)
186  .AddButton(XXO("OK"), wxALIGN_RIGHT| wxALL, true);
187  }
188  S.EndVerticalLay();
189 }
190 
191 SplashDialog::~SplashDialog()
192 {
193 }
194 
195 void SplashDialog::OnDontShow( wxCommandEvent & Evt )
196 {
197  bool bShow = !Evt.IsChecked();
198  gPrefs->Write(wxT("/GUI/ShowSplashScreen"), bShow );
199  gPrefs->Flush();
200 }
201 
202 void SplashDialog::OnOK(wxCommandEvent & WXUNUSED(event))
203 {
204  Show( false );
205 
206 }
207 
208 void SplashDialog::Show2( wxWindow * pParent )
209 {
210 #ifdef HAS_WHATS_NEW
211  FSHelper helper;
212 #endif // HAS_WHATS_NEW
213 
214  if( pSelf == NULL )
215  {
216  // pParent owns it
217  wxASSERT(pParent);
218  pSelf = safenew SplashDialog( pParent );
219  }
220  pSelf->mpHtml->SetPage(HelpText( wxT("welcome") ));
221  pSelf->Show( true );
222 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
ShuttleGuiBase::AddCheckBox
wxCheckBox * AddCheckBox(const TranslatableString &Prompt, bool Selected)
Definition: ShuttleGui.cpp:309
SplashDialog::Populate
void Populate(ShuttleGui &S)
Definition: SplashDialog.cpp:132
DontShowID
@ DontShowID
Definition: SplashDialog.cpp:95
HelpSystem.h
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
AllThemeResources.h
Project.h
SplashDialog::m_pLogo
std::unique_ptr< wxBitmap > m_pLogo
Definition: SplashDialog.h:41
SplashDialog
The SplashDialog shows help information for Audacity when Audacity starts up.
Definition: SplashDialog.h:21
SplashDialog.h
SplashDialog::Show2
static void Show2(wxWindow *pParent)
Definition: SplashDialog.cpp:208
XO
#define XO(s)
Definition: Internat.h:31
LOGOWITHNAME_WIDTH
#define LOGOWITHNAME_WIDTH
Definition: AllThemeResources.h:237
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
HelpText.h
XXO
#define XXO(s)
Definition: Internat.h:44
SplashDialog::OnChar
void OnChar(wxMouseEvent &event)
Definition: SplashDialog.cpp:126
SplashDialog::pSelf
static SplashDialog * pSelf
Definition: SplashDialog.h:42
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
LinkingHtmlWindow
An HtmlWindow that handles linked clicked - usually the link will go to our own local copy of the man...
Definition: HelpSystem.h:126
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
ShuttleGui.h
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:725
ProjectWindows.h
accessors for certain important windows associated with each project
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
SplashDialog::OnDontShow
void OnDontShow(wxCommandEvent &Evt)
Definition: SplashDialog.cpp:195
wxDialogWrapper
Definition: wxPanelWrapper.h:81
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
ShuttleGui::Position
ShuttleGui & Position(int flags)
Definition: ShuttleGui.h:712
MemoryX.h
ShuttleGui::ConnectRoot
auto ConnectRoot(wxEventTypeTag< Tag > eventType, void(Handler::*func)(Argument &)) -> typename std::enable_if< std::is_base_of< Argument, Tag >::value, ShuttleGui & >::type
Definition: ShuttleGui.h:699
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
SplashDialog::mpHtml
HtmlWindow * mpHtml
Definition: SplashDialog.h:40
FileNames.h
AudacityMessageBox.h
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: ProjectWindows.cpp:72
IMPLEMENT_CLASS
IMPLEMENT_CLASS(ControlToolBar, ToolBar)
SplashDialog::SplashDialog
SplashDialog(wxWindow *parent)
Definition: SplashDialog.cpp:110
Prefs.h
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
wxDialogWrapper::SetName
void SetName()
Definition: wxPanelWrapper.cpp:81
SplashDialog::OnOK
void OnOK(wxCommandEvent &event)
Definition: SplashDialog.cpp:202
HelpText
AUDACITY_DLL_API wxString HelpText(const wxString &Key)
safenew
#define safenew
Definition: MemoryX.h:10
ShuttleGuiBase::SetStretchyCol
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:202
END_EVENT_TABLE
END_EVENT_TABLE()
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
LOGOWITHNAME_HEIGHT
#define LOGOWITHNAME_HEIGHT
Definition: AllThemeResources.h:240