X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0591bcfdfa1dd68067340bcde7c1b945c3020ccb..c6aabd1ca9a5590d5dd8e89d83a5fba74c69c931:/samples/sound/sound.cpp diff --git a/samples/sound/sound.cpp b/samples/sound/sound.cpp index 8273867d7c..d41c7a2a80 100644 --- a/samples/sound/sound.cpp +++ b/samples/sound/sound.cpp @@ -40,7 +40,7 @@ #include "../sample.xpm" #endif -#define WAV_FILE _T("doggrowl.wav") +#define WAV_FILE wxT("doggrowl.wav") // ---------------------------------------------------------------------------- // private classes @@ -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,8 +162,11 @@ 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")); + MyFrame *frame = new MyFrame(wxT("wxWidgets Sound Sample")); // and show it (the frames, unlike simple controls, are not shown when // created initially) @@ -188,29 +194,32 @@ MyFrame::MyFrame(const wxString& title) SetIcon(wxICON(sample)); wxMenu *menuFile = new wxMenu; - menuFile->Append(Sound_SelectFile, _T("Select WAV &file...\tCtrl-O"), _T("Select a new wav file to play")); + menuFile->Append(Sound_SelectFile, wxT("Select WAV &file...\tCtrl-O"), wxT("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")); + menuFile->Append(Sound_SelectResource, wxT("Select WAV &resource...\tCtrl-R"), wxT("Select a new resource to play")); + menuFile->Append(Sound_SelectMemory, wxT("Select WAV &data\tCtrl-M"), wxT("Choose to play from memory buffer")); #endif // __WXMSW__ - menuFile->Append(Sound_SelectMemory, _T("Select WAV &data\tCtrl-M"), _T("Choose to play from memory buffer")); - menuFile->Append(Sound_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); + + menuFile->Append(Sound_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program")); wxMenu *playMenu = new wxMenu; - playMenu->Append(Sound_PlaySync, _T("Play sound &synchronously\tCtrl-S")); - playMenu->Append(Sound_PlayAsync, _T("Play sound &asynchronously\tCtrl-A")); - playMenu->Append(Sound_PlayAsyncOnStack, _T("Play sound asynchronously (&object on stack)\tCtrl-K")); - playMenu->Append(Sound_PlayLoop, _T("&Loop sound\tCtrl-L")); + playMenu->Append(Sound_PlaySync, wxT("Play sound &synchronously\tCtrl-S")); + playMenu->Append(Sound_PlayAsync, wxT("Play sound &asynchronously\tCtrl-A")); + playMenu->Append(Sound_PlayAsyncOnStack, wxT("Play sound asynchronously (&object on stack)\tCtrl-K")); + playMenu->Append(Sound_PlayLoop, wxT("&Loop sound\tCtrl-L")); + playMenu->AppendSeparator(); + playMenu->Append(Sound_Stop, wxT("&Stop playing\tCtrl-T")); playMenu->AppendSeparator(); - playMenu->Append(Sound_Stop, _T("&Stop playing\tCtrl-T")); + playMenu->Append(Sound_PlayBell, wxT("Play system bell")); wxMenu *helpMenu = new wxMenu; - helpMenu->Append(Sound_About, _T("&About...\tF1"), _T("Show about dialog")); + helpMenu->Append(Sound_About, wxT("&About...\tF1"), wxT("Show about dialog")); // now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar(); - menuBar->Append(menuFile, _T("&File")); - menuBar->Append(playMenu, _T("&Play")); - menuBar->Append(helpMenu, _T("&Help")); + menuBar->Append(menuFile, wxT("&File")); + menuBar->Append(playMenu, wxT("&Play")); + menuBar->Append(helpMenu, wxT("&Help")); // ... and attach this menu bar to the frame SetMenuBar(menuBar); @@ -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); @@ -971,7 +980,7 @@ bool MyFrame::CreateSound(wxSound& snd) const void MyFrame::NotifyUsingFile(const wxString& name) { wxString msg; - msg << _T("Using sound file: ") << name << _T("\n"); + msg << wxT("Using sound file: ") << name << wxT("\n"); m_tc->AppendText(msg); } @@ -981,9 +990,10 @@ void MyFrame::NotifyUsingFile(const wxString& name) void MyFrame::OnSelectFile(wxCommandEvent& WXUNUSED(event)) { - wxFileDialog dlg(this, _T("Choose a sound file"), +#if wxUSE_FILEDLG + wxFileDialog dlg(this, wxT("Choose a sound file"), wxEmptyString, wxEmptyString, - _T("WAV files (*.wav)|*.wav"), wxOPEN|wxCHANGE_DIR); + wxT("WAV files (*.wav)|*.wav"), wxFD_OPEN|wxFD_CHANGE_DIR); if ( dlg.ShowModal() == wxID_OK ) { m_soundFile = dlg.GetPath(); @@ -992,10 +1002,10 @@ void MyFrame::OnSelectFile(wxCommandEvent& WXUNUSED(event)) #endif // __WXMSW__ m_useMemory = false; - delete m_sound; - m_sound = NULL; + wxDELETE(m_sound); NotifyUsingFile(m_soundFile); } +#endif // wxUSE_FILEDLG } #ifdef __WXMSW__ @@ -1004,9 +1014,9 @@ void MyFrame::OnSelectResource(wxCommandEvent& WXUNUSED(event)) { m_soundRes = wxGetTextFromUser ( - _T("Enter resource name:"), - _T("wxWidgets Sound Sample"), - _T("FromResource"), + wxT("Enter resource name:"), + wxT("wxWidgets Sound Sample"), + wxT("FromResource"), this ); if ( m_soundRes.empty() ) @@ -1015,10 +1025,9 @@ void MyFrame::OnSelectResource(wxCommandEvent& WXUNUSED(event)) m_soundFile.clear(); m_useMemory = false; - delete m_sound; - m_sound = NULL; + wxDELETE(m_sound); - NotifyUsingFile(_T("Windows WAV resource")); + NotifyUsingFile(wxT("Windows WAV resource")); } #endif // __WXMSW__ @@ -1027,7 +1036,7 @@ void MyFrame::OnSelectMemory(wxCommandEvent& WXUNUSED(event)) { m_useMemory = true; - NotifyUsingFile(_T("embedded sound fragment")); + NotifyUsingFile(wxT("embedded sound fragment")); } void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) @@ -1084,13 +1093,18 @@ 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; - msg.Printf( _T("This is the About dialog of the sound sample.\n") - _T("Welcome to %s"), wxVERSION_STRING); + msg.Printf( wxT("This is the About dialog of the sound sample.\n") + wxT("Welcome to %s"), wxVERSION_STRING); - wxMessageBox(msg, _T("About"), wxOK | wxICON_INFORMATION, this); + wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this); } void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))