]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/sound/sound.cpp
fixing length param, see #10846
[wxWidgets.git] / samples / sound / sound.cpp
index 8273867d7c9f8fc172978b66b90f58221345fd45..c82d84be909dc5aad35d32c9ecea9126c1eb24de 100644 (file)
@@ -73,11 +73,12 @@ public:
     void OnPlayAsyncOnStack(wxCommandEvent& event);
     void OnPlayLoop(wxCommandEvent& event);
     void OnStop(wxCommandEvent& event);
+    void OnPlayBell(wxCommandEvent& event);
 
     void OnAbout(wxCommandEvent& event);
 
     void NotifyUsingFile(const wxString& name);
-    
+
 
 private:
     bool CreateSound(wxSound& snd) const;
@@ -90,7 +91,7 @@ private:
     bool        m_useMemory;
 
     wxTextCtrl* m_tc;
-    
+
     // any class wishing to process wxWidgets events must use this macro
     DECLARE_EVENT_TABLE()
 };
@@ -114,6 +115,7 @@ enum
     Sound_PlayAsyncOnStack,
     Sound_PlayLoop,
     Sound_Stop,
+    Sound_PlayBell,
 
     Sound_Quit = wxID_EXIT,
     Sound_About = wxID_ABOUT
@@ -139,6 +141,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(Sound_PlayAsyncOnStack, MyFrame::OnPlayAsyncOnStack)
     EVT_MENU(Sound_PlayLoop,         MyFrame::OnPlayLoop)
     EVT_MENU(Sound_Stop,             MyFrame::OnStop)
+    EVT_MENU(Sound_PlayBell,         MyFrame::OnPlayBell)
 END_EVENT_TABLE()
 
 // Create a new application object: this macro will allow wxWidgets to create
@@ -159,6 +162,9 @@ IMPLEMENT_APP(MyApp)
 // 'Main program' equivalent: the program execution "starts" here
 bool MyApp::OnInit()
 {
+    if ( !wxApp::OnInit() )
+        return false;
+
     // create the main application window
     MyFrame *frame = new MyFrame(_T("wxWidgets Sound Sample"));
 
@@ -191,8 +197,9 @@ MyFrame::MyFrame(const wxString& title)
     menuFile->Append(Sound_SelectFile, _T("Select WAV &file...\tCtrl-O"), _T("Select a new wav file to play"));
 #ifdef __WXMSW__
     menuFile->Append(Sound_SelectResource, _T("Select WAV &resource...\tCtrl-R"), _T("Select a new resource to play"));
-#endif // __WXMSW__
     menuFile->Append(Sound_SelectMemory, _T("Select WAV &data\tCtrl-M"), _T("Choose to play from memory buffer"));
+#endif // __WXMSW__
+
     menuFile->Append(Sound_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
 
     wxMenu *playMenu = new wxMenu;
@@ -202,6 +209,8 @@ MyFrame::MyFrame(const wxString& title)
     playMenu->Append(Sound_PlayLoop, _T("&Loop sound\tCtrl-L"));
     playMenu->AppendSeparator();
     playMenu->Append(Sound_Stop, _T("&Stop playing\tCtrl-T"));
+    playMenu->AppendSeparator();
+    playMenu->Append(Sound_PlayBell, _T("Play system bell"));
 
     wxMenu *helpMenu = new wxMenu;
     helpMenu->Append(Sound_About, _T("&About...\tF1"), _T("Show about dialog"));
@@ -224,6 +233,7 @@ MyFrame::MyFrame(const wxString& title)
 
 bool MyFrame::CreateSound(wxSound& snd) const
 {
+#ifdef __WXMSW__
     if ( m_useMemory )
     {
         // this is the dump of cuckoo.wav
@@ -957,7 +967,6 @@ bool MyFrame::CreateSound(wxSound& snd) const
         return snd.Create(sizeof(data), data);
     }
 
-#ifdef __WXMSW__
     if ( !m_soundRes.empty() )
     {
         return snd.Create(m_soundRes, true);
@@ -981,9 +990,10 @@ void MyFrame::NotifyUsingFile(const wxString& name)
 
 void MyFrame::OnSelectFile(wxCommandEvent& WXUNUSED(event))
 {
+#if wxUSE_FILEDLG
     wxFileDialog dlg(this, _T("Choose a sound file"),
                      wxEmptyString, wxEmptyString,
-                     _T("WAV files (*.wav)|*.wav"), wxOPEN|wxCHANGE_DIR);
+                     _T("WAV files (*.wav)|*.wav"), wxFD_OPEN|wxFD_CHANGE_DIR);
     if ( dlg.ShowModal() == wxID_OK )
     {
         m_soundFile = dlg.GetPath();
@@ -996,6 +1006,7 @@ void MyFrame::OnSelectFile(wxCommandEvent& WXUNUSED(event))
         m_sound = NULL;
         NotifyUsingFile(m_soundFile);
     }
+#endif // wxUSE_FILEDLG
 }
 
 #ifdef __WXMSW__
@@ -1084,6 +1095,11 @@ void MyFrame::OnPlayLoop(wxCommandEvent& WXUNUSED(event))
         m_sound->Play(wxSOUND_ASYNC | wxSOUND_LOOP);
 }
 
+void MyFrame::OnPlayBell(wxCommandEvent& WXUNUSED(event))
+{
+    wxBell();
+}
+
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
     wxString msg;