From 6046d33a36f9a42c03592aa878e5ad48c5f45bce Mon Sep 17 00:00:00 2001 From: "james.k.crook@gmail.com" Date: Fri, 25 Nov 2011 20:41:12 +0000 Subject: [PATCH] Updated to demo new method of taking over TrackPanel. --- .../mod-track-panel/ModTrackPanelCallback.cpp | 22 +++++-- lib-src/mod-track-panel/TrackPanel2.cpp | 60 +++++++++++++------ lib-src/mod-track-panel/TrackPanel2.h | 26 +++++++- 3 files changed, 85 insertions(+), 23 deletions(-) diff --git a/lib-src/mod-track-panel/ModTrackPanelCallback.cpp b/lib-src/mod-track-panel/ModTrackPanelCallback.cpp index 8439d213d..3a4e51c24 100644 --- a/lib-src/mod-track-panel/ModTrackPanelCallback.cpp +++ b/lib-src/mod-track-panel/ModTrackPanelCallback.cpp @@ -32,6 +32,7 @@ click from the menu into the actual function to be called. #include "Project.h" #include "LoadModules.h" #include "Registrar.h" +#include "TrackPanel2.h" /* There are several functions that can be used in a GUI module. @@ -67,7 +68,7 @@ class ModTrackPanelCallback { public: void OnFuncShowAudioExplorer(); - void OnFuncShowAnotherExtension(); + void OnFuncReplaceTrackPanel(); }; typedef void (ModTrackPanelCallback::*ModTrackPanelCommandFunction)(); @@ -114,9 +115,17 @@ void ModTrackPanelCallback::OnFuncShowAudioExplorer() Registrar::ShowNewPanel(); } -void ModTrackPanelCallback::OnFuncShowAnotherExtension() +void ModTrackPanelCallback::OnFuncReplaceTrackPanel() { + // Upgrade the factory. Now all TrackPanels will be created as TrackPanel 2's + +#if 0 + AudacityProject *p = GetActiveProject(); + wxASSERT( p!= NULL ); + // Change it's type (No new storage allocated). + TrackPanel2::Upgrade( &p->mTrackPanel ); int k=4; +#endif } // Oooh look, we're using a NULL object, and hence a NULL 'this'. @@ -150,6 +159,8 @@ MOD_TRACK_PANEL_DLL_API int ModuleDispatch(ModuleDispatchTypes type) { case AppInitialized: Registrar::Start(); + // Demand that all track panels be created using the TrackPanel2Factory. + TrackPanel::FactoryFunction = TrackPanel2Factory; break; case AppQuiting: Registrar::Finish(); @@ -168,10 +179,11 @@ MOD_TRACK_PANEL_DLL_API int ModuleDispatch(ModuleDispatchTypes type) c->SetToMenu( pMenu ); c->AddSeparator(); // We add two new commands into the Analyze menu. - c->AddItem( _T("Audio Explorer..."), _T("Experimental GUI for audio analysis"), + c->AddItem( _T("Extra Dialog..."), _T("Experimental Extra Dialog for whatever you want."), ModTrackPanelFN( OnFuncShowAudioExplorer ) ); - c->AddItem( _T("Another Extension..."), _T("Experimental GUI for other things"), - ModTrackPanelFN( OnFuncShowAnotherExtension ) ); + //Second menu tweak no longer needed as we always make TrackPanel2's. + //c->AddItem( _T("Replace TrackPanel..."), _T("Replace Current TrackPanel with TrackPanel2"), + // ModTrackPanelFN( OnFuncReplaceTrackPanel ) ); } break; default: diff --git a/lib-src/mod-track-panel/TrackPanel2.cpp b/lib-src/mod-track-panel/TrackPanel2.cpp index 1dac9ccd8..017c4d49f 100644 --- a/lib-src/mod-track-panel/TrackPanel2.cpp +++ b/lib-src/mod-track-panel/TrackPanel2.cpp @@ -23,28 +23,35 @@ #include "Registrar.h" #include "TrackPanel2.h" +TrackPanel * TrackPanel2Factory(wxWindow * parent, + wxWindowID id, + const wxPoint & pos, + const wxSize & size, + TrackList * tracks, + ViewInfo * viewInfo, + TrackPanelListener * listener, + AdornedRulerPanel * ruler) +{ + return new TrackPanel2( + parent, + id, + pos, + size, + tracks, + viewInfo, + listener, + ruler); +} -void ShowTrackPanel() +void ShowExtraDialog() { int k=42; - wxDialog Dlg(NULL, wxID_ANY, wxString(wxT("Experimental New TrackPanel"))); + wxDialog Dlg(NULL, wxID_ANY, wxString(wxT("Experimental Extra Dialog"))); ShuttleGui S(&Dlg, eIsCreating); -#if 0 - S.StartHorizontalLay(wxCENTER, false); - { - S.StartStatic(wxT(""), false); - { - S.SetBorder(200); - S.AddFixedText(wxT("AAA")); - } - S.EndStatic(); - } - S.EndHorizontalLay(); -#endif S.StartNotebook(); { - S.StartNotebookPage( _("Panel") ); + S.StartNotebookPage( _("Panel 1") ); S.StartVerticalLay(1); { HtmlWindow *html = new LinkingHtmlWindow(S.GetParent(), -1, @@ -52,7 +59,7 @@ void ShowTrackPanel() wxSize(600, 359), wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER); html->SetFocus(); - html->SetPage(wxT("

TrackPanel

This will be replaced with the panel")); + html->SetPage(wxT("

An Html Window

Replace with whatever you like.")); S.Prop(1).AddWindow( html, wxEXPAND ); } S.EndVerticalLay(); @@ -89,7 +96,7 @@ int TrackPanel2Dispatch( Registrar & R, t_RegistrarDispatchType Type ) switch( Type ) { case RegResource: - R.pShowFn = ShowTrackPanel; + R.pShowFn = ShowExtraDialog; break; case RegArtist: break; @@ -105,3 +112,22 @@ int TrackPanel2Dispatch( Registrar & R, t_RegistrarDispatchType Type ) return 1; } +TrackPanel2::TrackPanel2( + wxWindow * parent, wxWindowID id, const wxPoint & pos, const wxSize & size, + TrackList * tracks, ViewInfo * viewInfo, TrackPanelListener * listener, + AdornedRulerPanel * ruler) : + TrackPanel( + parent, id, pos, size, + tracks, viewInfo, listener, ruler) +{ +} + + +// Here is a sample function that shows that TrackPanel2 is being invoked. +void TrackPanel2::OnPaint(wxPaintEvent & event) +{ +// Hmm... Log debug will only show if you open the log window. +// wxLogDebug( wxT("Paint TrackPanel2 requested") ); + TrackPanel::OnPaint( event ); +} + diff --git a/lib-src/mod-track-panel/TrackPanel2.h b/lib-src/mod-track-panel/TrackPanel2.h index 58c40470b..50e703011 100644 --- a/lib-src/mod-track-panel/TrackPanel2.h +++ b/lib-src/mod-track-panel/TrackPanel2.h @@ -11,10 +11,34 @@ #ifndef __AUDACITY_TRACK_PANEL2__ #define __AUDACITY_TRACK_PANEL2__ +#include "TrackPanel.h" -class TrackPanel2 { +class TrackPanel2 : public TrackPanel +{ public: + TrackPanel2( + wxWindow * parent, wxWindowID id, + const wxPoint & pos, + const wxSize & size, + TrackList * tracks, + ViewInfo * viewInfo, + TrackPanelListener * listener, + AdornedRulerPanel * ruler); + // Upgrades an existing TrackPanel to a TrackPanel2 + static void Upgrade( TrackPanel ** ppTrackPanel ); + + virtual void OnPaint(wxPaintEvent & event); }; +// Factory function. +TrackPanel * TrackPanel2Factory(wxWindow * parent, + wxWindowID id, + const wxPoint & pos, + const wxSize & size, + TrackList * tracks, + ViewInfo * viewInfo, + TrackPanelListener * listener, + AdornedRulerPanel * ruler); + #endif