1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-08 08:30:02 +02:00

Rewrite popup menu code to user registry visitors...

... but there are not yet any items moved out as plug-ins
This commit is contained in:
Paul Licameli 2020-02-06 00:54:08 -05:00
commit 54ba4e9b8a
14 changed files with 450 additions and 286 deletions

View File

@ -37,7 +37,9 @@ std::vector<UIHandlePtr> LabelTrackControls::HitTest
class LabelTrackMenuTable : public PopupMenuTable
{
LabelTrackMenuTable() : mpData(NULL) {}
LabelTrackMenuTable()
: PopupMenuTable{ "LabelTrack" }
{}
DECLARE_POPUP_MENU(LabelTrackMenuTable);
public:
@ -53,7 +55,7 @@ public:
mpData = nullptr;
}
CommonTrackControls::InitMenuData *mpData;
CommonTrackControls::InitMenuData *mpData{};
void OnSetFont(wxCommandEvent &);
};
@ -70,8 +72,9 @@ enum
};
BEGIN_POPUP_MENU(LabelTrackMenuTable)
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnSetFontID, XO("&Font..."), OnSetFont)
BEGIN_POPUP_MENU_SECTION( "Basic" )
POPUP_MENU_ITEM( "Font", OnSetFontID, XO("&Font..."), OnSetFont)
END_POPUP_MENU_SECTION()
END_POPUP_MENU()
void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)

View File

@ -78,7 +78,9 @@ std::vector<UIHandlePtr> NoteTrackControls::HitTest
class NoteTrackMenuTable : public PopupMenuTable
{
NoteTrackMenuTable() : mpData(NULL) {}
NoteTrackMenuTable()
: PopupMenuTable{ "NoteTrack" }
{}
DECLARE_POPUP_MENU(NoteTrackMenuTable);
public:
@ -95,7 +97,7 @@ private:
mpData = nullptr;
}
NoteTrackControlsBase::InitMenuData *mpData;
NoteTrackControlsBase::InitMenuData *mpData{};
void OnChangeOctave(wxCommandEvent &);
};
@ -129,9 +131,10 @@ void NoteTrackMenuTable::OnChangeOctave(wxCommandEvent &event)
}
BEGIN_POPUP_MENU(NoteTrackMenuTable)
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnUpOctaveID, XO("Up &Octave"), OnChangeOctave)
POPUP_MENU_ITEM(OnDownOctaveID, XO("Down Octa&ve"), OnChangeOctave)
BEGIN_POPUP_MENU_SECTION( "Basic" )
POPUP_MENU_ITEM( "Up", OnUpOctaveID, XO("Up &Octave"), OnChangeOctave)
POPUP_MENU_ITEM( "Down", OnDownOctaveID, XO("Down Octa&ve"), OnChangeOctave)
END_POPUP_MENU_SECTION()
END_POPUP_MENU()
PopupMenuTable *NoteTrackControls::GetMenuExtension(Track *)

View File

@ -167,7 +167,9 @@ enum {
class NoteTrackVRulerMenuTable : public PopupMenuTable
{
NoteTrackVRulerMenuTable(){};
NoteTrackVRulerMenuTable()
: PopupMenuTable{ "NoteTrackVRuler" }
{};
virtual ~NoteTrackVRulerMenuTable() {}
DECLARE_POPUP_MENU(NoteTrackVRulerMenuTable);
@ -254,16 +256,24 @@ void NoteTrackVRulerMenuTable::OnZoom( int iZoomCode ){
BEGIN_POPUP_MENU(NoteTrackVRulerMenuTable)
POPUP_MENU_ITEM(OnZoomResetID, XO("Zoom Reset\tShift-Right-Click"), OnZoomReset)
POPUP_MENU_ITEM(OnZoomMaxID, XO("Max Zoom"), OnZoomMax)
BEGIN_POPUP_MENU_SECTION( "Zoom" )
BEGIN_POPUP_MENU_SECTION( "Basic" )
POPUP_MENU_ITEM( "Reset", OnZoomResetID, XO("Zoom Reset\tShift-Right-Click"), OnZoomReset)
POPUP_MENU_ITEM( "Max", OnZoomMaxID, XO("Max Zoom"), OnZoomMax)
END_POPUP_MENU_SECTION()
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnZoomInVerticalID, XO("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
POPUP_MENU_ITEM(OnZoomOutVerticalID, XO("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
BEGIN_POPUP_MENU_SECTION( "InOut" )
POPUP_MENU_ITEM( "In", OnZoomInVerticalID, XO("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
POPUP_MENU_ITEM( "Out", OnZoomOutVerticalID, XO("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
END_POPUP_MENU_SECTION()
END_POPUP_MENU_SECTION()
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnUpOctaveID, XO("Up &Octave"), OnUpOctave)
POPUP_MENU_ITEM(OnDownOctaveID, XO("Down Octa&ve"), OnDownOctave)
BEGIN_POPUP_MENU_SECTION( "Pan" )
BEGIN_POPUP_MENU_SECTION( "Octaves" )
POPUP_MENU_ITEM( "Up", OnUpOctaveID, XO("Up &Octave"), OnUpOctave)
POPUP_MENU_ITEM( "Down", OnDownOctaveID, XO("Down Octa&ve"), OnDownOctave)
END_POPUP_MENU_SECTION()
END_POPUP_MENU_SECTION()
END_POPUP_MENU()
@ -297,8 +307,7 @@ UIHandle::Result NoteTrackVZoomHandle::Release
PopupMenuTable *const pTable =
(PopupMenuTable *) &NoteTrackVRulerMenuTable::Instance();
std::unique_ptr<PopupMenuTable::Menu>
pMenu(PopupMenuTable::BuildMenu(pParent, pTable, &data));
auto pMenu = PopupMenuTable::BuildMenu(pParent, pTable, &data);
// Accelerators only if zooming enabled.
if( !bVZoom )

View File

@ -265,7 +265,7 @@ PopupMenuTable &SpectrumVRulerMenuTable::Instance()
return instance;
}
void SpectrumVRulerMenuTable::InitMenu(Menu *pMenu)
void SpectrumVRulerMenuTable::InitMenu(wxMenu *pMenu)
{
WaveTrackVRulerMenuTable::InitMenu(pMenu);
@ -277,19 +277,25 @@ void SpectrumVRulerMenuTable::InitMenu(Menu *pMenu)
BEGIN_POPUP_MENU(SpectrumVRulerMenuTable)
BEGIN_POPUP_MENU_SECTION( "Scales" )
{
const auto & names = SpectrogramSettings::GetScaleNames();
for (int ii = 0, nn = names.size(); ii < nn; ++ii) {
POPUP_MENU_RADIO_ITEM(OnFirstSpectrumScaleID + ii, names[ii].Msgid(),
POPUP_MENU_RADIO_ITEM( names[ii].Internal(),
OnFirstSpectrumScaleID + ii, names[ii].Msgid(),
OnSpectrumScaleType);
}
}
END_POPUP_MENU_SECTION()
BEGIN_POPUP_MENU_SECTION( "Zoom" )
POPUP_MENU_ITEM( "Reset", OnZoomResetID, XO("Zoom Reset"), OnZoomReset)
POPUP_MENU_ITEM( "Fit", OnZoomFitVerticalID, XO("Zoom to Fit\tShift-Right-Click"), OnZoomFitVertical)
POPUP_MENU_ITEM( "In", OnZoomInVerticalID, XO("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
POPUP_MENU_ITEM( "Out", OnZoomOutVerticalID, XO("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
END_POPUP_MENU_SECTION()
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnZoomResetID, XO("Zoom Reset"), OnZoomReset)
POPUP_MENU_ITEM(OnZoomFitVerticalID, XO("Zoom to Fit\tShift-Right-Click"), OnZoomFitVertical)
POPUP_MENU_ITEM(OnZoomInVerticalID, XO("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
POPUP_MENU_ITEM(OnZoomOutVerticalID, XO("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
END_POPUP_MENU()
void SpectrumVRulerMenuTable::OnSpectrumScaleType(wxCommandEvent &evt)

View File

@ -75,7 +75,9 @@ private:
class SpectrumVRulerMenuTable : public WaveTrackVRulerMenuTable
{
SpectrumVRulerMenuTable() : WaveTrackVRulerMenuTable() {}
SpectrumVRulerMenuTable()
: WaveTrackVRulerMenuTable{ "SpectrumVRuler" }
{}
virtual ~SpectrumVRulerMenuTable() {}
DECLARE_POPUP_MENU(SpectrumVRulerMenuTable);
@ -83,7 +85,7 @@ public:
static PopupMenuTable &Instance();
private:
void InitMenu(Menu *pMenu) override;
void InitMenu(wxMenu *pMenu) override;
void OnSpectrumScaleType(wxCommandEvent &evt);
};

View File

@ -135,7 +135,6 @@ enum {
OnChannelMonoID,
OnMergeStereoID,
OnWaveColorID,
OnInstrument1ID,
OnInstrument2ID,
OnInstrument3ID,
@ -153,7 +152,9 @@ enum {
// Table class for a sub-menu
class WaveColorMenuTable : public PopupMenuTable
{
WaveColorMenuTable() : mpData(NULL) {}
WaveColorMenuTable()
: PopupMenuTable( "WaveColor", XO("&Wave Color") )
{}
DECLARE_POPUP_MENU(WaveColorMenuTable);
public:
@ -161,14 +162,14 @@ public:
private:
void InitUserData(void *pUserData) override;
void InitMenu(Menu *pMenu) override;
void InitMenu(wxMenu *pMenu) override;
void DestroyMenu() override
{
mpData = NULL;
}
PlayableTrackControls::InitMenuData *mpData;
PlayableTrackControls::InitMenuData *mpData{};
int IdOfWaveColor(int WaveColor);
void OnWaveColorChange(wxCommandEvent & event);
@ -185,7 +186,7 @@ void WaveColorMenuTable::InitUserData(void *pUserData)
mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
}
void WaveColorMenuTable::InitMenu(Menu *pMenu)
void WaveColorMenuTable::InitMenu(wxMenu *pMenu)
{
WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
auto WaveColorId = IdOfWaveColor( pTrack->GetWaveColorIndex());
@ -205,13 +206,13 @@ const TranslatableString GetWaveColorStr(int colorIndex)
BEGIN_POPUP_MENU(WaveColorMenuTable)
POPUP_MENU_RADIO_ITEM(OnInstrument1ID,
POPUP_MENU_RADIO_ITEM( "Instrument1", OnInstrument1ID,
GetWaveColorStr(0), OnWaveColorChange)
POPUP_MENU_RADIO_ITEM(OnInstrument2ID,
POPUP_MENU_RADIO_ITEM( "Instrument2", OnInstrument2ID,
GetWaveColorStr(1), OnWaveColorChange)
POPUP_MENU_RADIO_ITEM(OnInstrument3ID,
POPUP_MENU_RADIO_ITEM( "Instrument3", OnInstrument3ID,
GetWaveColorStr(2), OnWaveColorChange)
POPUP_MENU_RADIO_ITEM(OnInstrument4ID,
POPUP_MENU_RADIO_ITEM( "Instrument4", OnInstrument4ID,
GetWaveColorStr(3), OnWaveColorChange)
END_POPUP_MENU()
@ -250,7 +251,9 @@ void WaveColorMenuTable::OnWaveColorChange(wxCommandEvent & event)
// Table class for a sub-menu
class FormatMenuTable : public PopupMenuTable
{
FormatMenuTable() : mpData(NULL) {}
FormatMenuTable()
: PopupMenuTable{ "SampleFormat", XO("&Format") }
{}
DECLARE_POPUP_MENU(FormatMenuTable);
public:
@ -258,14 +261,14 @@ public:
private:
void InitUserData(void *pUserData) override;
void InitMenu(Menu *pMenu) override;
void InitMenu(wxMenu *pMenu) override;
void DestroyMenu() override
{
mpData = NULL;
}
PlayableTrackControls::InitMenuData *mpData;
PlayableTrackControls::InitMenuData *mpData{};
int IdOfFormat(int format);
@ -283,7 +286,7 @@ void FormatMenuTable::InitUserData(void *pUserData)
mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
}
void FormatMenuTable::InitMenu(Menu *pMenu)
void FormatMenuTable::InitMenu(wxMenu *pMenu)
{
WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
auto formatId = IdOfFormat(pTrack->GetSampleFormat());
@ -297,11 +300,11 @@ void FormatMenuTable::InitMenu(Menu *pMenu)
}
BEGIN_POPUP_MENU(FormatMenuTable)
POPUP_MENU_RADIO_ITEM(On16BitID,
POPUP_MENU_RADIO_ITEM( "16Bit", On16BitID,
GetSampleFormatStr(int16Sample), OnFormatChange)
POPUP_MENU_RADIO_ITEM(On24BitID,
GetSampleFormatStr(int24Sample), OnFormatChange)
POPUP_MENU_RADIO_ITEM(OnFloatID,
POPUP_MENU_RADIO_ITEM("24Bit", On24BitID,
GetSampleFormatStr( int24Sample), OnFormatChange)
POPUP_MENU_RADIO_ITEM( "Float", OnFloatID,
GetSampleFormatStr(floatSample), OnFormatChange)
END_POPUP_MENU()
@ -371,7 +374,9 @@ void FormatMenuTable::OnFormatChange(wxCommandEvent & event)
// Table class for a sub-menu
class RateMenuTable : public PopupMenuTable
{
RateMenuTable() : mpData(NULL) {}
RateMenuTable()
: PopupMenuTable{ "SampleRate", XO("Rat&e") }
{}
DECLARE_POPUP_MENU(RateMenuTable);
public:
@ -379,14 +384,14 @@ public:
private:
void InitUserData(void *pUserData) override;
void InitMenu(Menu *pMenu) override;
void InitMenu(wxMenu *pMenu) override;
void DestroyMenu() override
{
mpData = NULL;
}
PlayableTrackControls::InitMenuData *mpData;
PlayableTrackControls::InitMenuData *mpData{};
int IdOfRate(int rate);
void SetRate(WaveTrack * pTrack, double rate);
@ -406,7 +411,7 @@ void RateMenuTable::InitUserData(void *pUserData)
mpData = static_cast<PlayableTrackControls::InitMenuData*>(pUserData);
}
void RateMenuTable::InitMenu(Menu *pMenu)
void RateMenuTable::InitMenu(wxMenu *pMenu)
{
WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
const auto rateId = IdOfRate((int)pTrack->GetRate());
@ -423,19 +428,19 @@ void RateMenuTable::InitMenu(Menu *pMenu)
// If we did, we'd get no message when clicking on Other...
// when it is already selected.
BEGIN_POPUP_MENU(RateMenuTable)
POPUP_MENU_CHECK_ITEM(OnRate8ID, XO("8000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate11ID, XO("11025 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate16ID, XO("16000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate22ID, XO("22050 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate44ID, XO("44100 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate48ID, XO("48000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate88ID, XO("88200 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate96ID, XO("96000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate176ID, XO("176400 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate192ID, XO("192000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate352ID, XO("352800 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRate384ID, XO("384000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM(OnRateOtherID, XO("&Other..."), OnRateOther)
POPUP_MENU_CHECK_ITEM( "8000", OnRate8ID, XO("8000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "11025", OnRate11ID, XO("11025 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "16000", OnRate16ID, XO("16000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "22050", OnRate22ID, XO("22050 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "44100", OnRate44ID, XO("44100 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "48000", OnRate48ID, XO("48000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "88200", OnRate88ID, XO("88200 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "96000", OnRate96ID, XO("96000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "176400", OnRate176ID, XO("176400 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "192000", OnRate192ID, XO("192000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "352800", OnRate352ID, XO("352800 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "384000", OnRate384ID, XO("384000 Hz"), OnRateChange)
POPUP_MENU_CHECK_ITEM( "Other", OnRateOtherID, XO("&Other..."), OnRateOther)
END_POPUP_MENU()
const int nRates = 12;
@ -572,13 +577,15 @@ class WaveTrackMenuTable : public PopupMenuTable
{
public:
static WaveTrackMenuTable &Instance( Track * pTrack);
Track * mpTrack;
Track * mpTrack{};
protected:
WaveTrackMenuTable() : mpData(NULL) {mpTrack=NULL;}
WaveTrackMenuTable()
: PopupMenuTable{ "WaveTrack" }
{}
void InitUserData(void *pUserData) override;
void InitMenu(Menu *pMenu) override;
void InitMenu(wxMenu *pMenu) override;
void DestroyMenu() override
{
@ -587,7 +594,7 @@ protected:
DECLARE_POPUP_MENU(WaveTrackMenuTable);
PlayableTrackControls::InitMenuData *mpData;
PlayableTrackControls::InitMenuData *mpData{};
void OnMultiView(wxCommandEvent & event);
void OnSetDisplay(wxCommandEvent & event);
@ -632,7 +639,7 @@ static std::vector<WaveTrackSubViewType> AllTypes()
return result;
}
void WaveTrackMenuTable::InitMenu(Menu *pMenu)
void WaveTrackMenuTable::InitMenu(wxMenu *pMenu)
{
WaveTrack *const pTrack = static_cast<WaveTrack*>(mpData->pTrack);
@ -761,37 +768,39 @@ BEGIN_POPUP_MENU(WaveTrackMenuTable)
WaveTrack *const pTrack = static_cast<WaveTrack*>(mpTrack);
const auto &view = WaveTrackView::Get( *pTrack );
POPUP_MENU_SEPARATOR()
BEGIN_POPUP_MENU_SECTION( "SubViews" )
if ( WaveTrackSubViews::slots() > 1 )
POPUP_MENU_CHECK_ITEM(OnMultiViewID, XO("&Multi-view"), OnMultiView)
POPUP_MENU_CHECK_ITEM( "MultiView", OnMultiViewID, XO("&Multi-view"), OnMultiView)
int id = OnSetDisplayId;
for ( const auto &type : AllTypes() ) {
if ( view.GetMultiView() ) {
POPUP_MENU_CHECK_ITEM(id++, type.name.Msgid(), OnSetDisplay)
POPUP_MENU_CHECK_ITEM( type.name.Internal(), id++, type.name.Msgid(), OnSetDisplay)
}
else {
POPUP_MENU_RADIO_ITEM(id++, type.name.Msgid(), OnSetDisplay)
POPUP_MENU_RADIO_ITEM( type.name.Internal(), id++, type.name.Msgid(), OnSetDisplay)
}
}
POPUP_MENU_ITEM(OnSpectrogramSettingsID, XO("S&pectrogram Settings..."), OnSpectrogramSettings)
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM( "SpectrogramSettings", OnSpectrogramSettingsID, XO("S&pectrogram Settings..."), OnSpectrogramSettings)
END_POPUP_MENU_SECTION()
// If these are enabled again, choose a hot key for Mono that does not conflict
// with Multi View
// POPUP_MENU_RADIO_ITEM(OnChannelMonoID, XO("&Mono"), OnChannelChange)
// POPUP_MENU_RADIO_ITEM(OnChannelLeftID, XO("&Left Channel"), OnChannelChange)
// POPUP_MENU_RADIO_ITEM(OnChannelRightID, XO("R&ight Channel"), OnChannelChange)
POPUP_MENU_ITEM(OnMergeStereoID, XO("Ma&ke Stereo Track"), OnMergeStereo)
BEGIN_POPUP_MENU_SECTION( "Channels" )
// If these are enabled again, choose a hot key for Mono that does not conflict
// with Multi View
// POPUP_MENU_RADIO_ITEM(OnChannelMonoID, XO("&Mono"), OnChannelChange)
// POPUP_MENU_RADIO_ITEM(OnChannelLeftID, XO("&Left Channel"), OnChannelChange)
// POPUP_MENU_RADIO_ITEM(OnChannelRightID, XO("R&ight Channel"), OnChannelChange)
POPUP_MENU_ITEM( "MakeStereo", OnMergeStereoID, XO("Ma&ke Stereo Track"), OnMergeStereo)
POPUP_MENU_ITEM(OnSwapChannelsID, XO("Swap Stereo &Channels"), OnSwapChannels)
POPUP_MENU_ITEM(OnSplitStereoID, XO("Spl&it Stereo Track"), OnSplitStereo)
// DA: Uses split stereo track and then drag pan sliders for split-stereo-to-mono
#ifndef EXPERIMENTAL_DA
POPUP_MENU_ITEM(OnSplitStereoMonoID, XO("Split Stereo to Mo&no"), OnSplitStereoMono)
#endif
POPUP_MENU_ITEM( "Swap", OnSwapChannelsID, XO("Swap Stereo &Channels"), OnSwapChannels)
POPUP_MENU_ITEM( "Split", OnSplitStereoID, XO("Spl&it Stereo Track"), OnSplitStereo)
// DA: Uses split stereo track and then drag pan sliders for split-stereo-to-mono
#ifndef EXPERIMENTAL_DA
POPUP_MENU_ITEM( "SplitToMono", OnSplitStereoMonoID, XO("Split Stereo to Mo&no"), OnSplitStereoMono)
#endif
END_POPUP_MENU_SECTION()
if ( pTrack ) {
const auto displays = view.GetDisplays();
@ -800,15 +809,19 @@ BEGIN_POPUP_MENU(WaveTrackMenuTable)
WaveTrackSubView::Type{ WaveTrackViewConstants::Waveform, {} }
) );
if( hasWaveform ){
POPUP_MENU_SEPARATOR()
POPUP_MENU_SUB_MENU(OnWaveColorID, XO("&Wave Color"), WaveColorMenuTable)
BEGIN_POPUP_MENU_SECTION( "WaveColor" )
POPUP_MENU_SUB_MENU( "WaveColor", WaveColorMenuTable)
END_POPUP_MENU_SECTION()
}
}
POPUP_MENU_SEPARATOR()
POPUP_MENU_SUB_MENU(0, XO("&Format"), FormatMenuTable)
POPUP_MENU_SEPARATOR()
POPUP_MENU_SUB_MENU(0, XO("Rat&e"), RateMenuTable)
BEGIN_POPUP_MENU_SECTION( "Format" )
POPUP_MENU_SUB_MENU( "Format", FormatMenuTable)
END_POPUP_MENU_SECTION()
BEGIN_POPUP_MENU_SECTION( "Rate" )
POPUP_MENU_SUB_MENU( "Rate", RateMenuTable)
END_POPUP_MENU_SECTION()
END_POPUP_MENU()

View File

@ -118,8 +118,7 @@ UIHandle::Result WaveTrackVZoomHandle::DoRelease(
*pProject,
pTrack, rect, RefreshCode::RefreshNone, event.m_y, doZoom };
std::unique_ptr<PopupMenuTable::Menu>
pMenu(PopupMenuTable::BuildMenu(pParent, &table, &data));
auto pMenu = PopupMenuTable::BuildMenu(pParent, &table, &data);
// Accelerators only if zooming enabled.
if( !bVZoom )

View File

@ -68,7 +68,9 @@ public:
};
protected:
WaveTrackVRulerMenuTable() {}
WaveTrackVRulerMenuTable( const Identifier &id )
: PopupMenuTable{ id }
{}
void InitUserData(void *pUserData) override;

View File

@ -266,7 +266,7 @@ PopupMenuTable &WaveformVRulerMenuTable::Instance()
return instance;
}
void WaveformVRulerMenuTable::InitMenu(Menu *pMenu)
void WaveformVRulerMenuTable::InitMenu(wxMenu *pMenu)
{
WaveTrackVRulerMenuTable::InitMenu(pMenu);
@ -279,28 +279,33 @@ void WaveformVRulerMenuTable::InitMenu(Menu *pMenu)
BEGIN_POPUP_MENU(WaveformVRulerMenuTable)
BEGIN_POPUP_MENU_SECTION( "Scales" )
{
const auto & names = WaveformSettings::GetScaleNames();
for (int ii = 0, nn = names.size(); ii < nn; ++ii) {
POPUP_MENU_RADIO_ITEM(OnFirstWaveformScaleID + ii, names[ii].Msgid(),
POPUP_MENU_RADIO_ITEM( names[ii].Internal(),
OnFirstWaveformScaleID + ii, names[ii].Msgid(),
OnWaveformScaleType);
}
}
END_POPUP_MENU_SECTION()
POPUP_MENU_SEPARATOR()
BEGIN_POPUP_MENU_SECTION( "Zoom" )
BEGIN_POPUP_MENU_SECTION( "Basic" )
POPUP_MENU_ITEM( "Reset", OnZoomFitVerticalID, XO("Zoom Reset\tShift-Right-Click"), OnZoomReset)
POPUP_MENU_ITEM( "TimesHalf", OnZoomDiv2ID, XO("Zoom x1/2"), OnZoomDiv2Vertical)
POPUP_MENU_ITEM( "TimesTwo", OnZoomTimes2ID, XO("Zoom x2"), OnZoomTimes2Vertical)
POPUP_MENU_ITEM(OnZoomFitVerticalID, XO("Zoom Reset\tShift-Right-Click"), OnZoomReset)
POPUP_MENU_ITEM(OnZoomDiv2ID, XO("Zoom x1/2"), OnZoomDiv2Vertical)
POPUP_MENU_ITEM(OnZoomTimes2ID, XO("Zoom x2"), OnZoomTimes2Vertical)
#ifdef EXPERIMENTAL_HALF_WAVE
POPUP_MENU_ITEM(OnZoomHalfWaveID, XO("Half Wave"), OnZoomHalfWave)
#endif
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnZoomInVerticalID, XO("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
POPUP_MENU_ITEM(OnZoomOutVerticalID, XO("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
#ifdef EXPERIMENTAL_HALF_WAVE
POPUP_MENU_ITEM( "HalfWave", OnZoomHalfWaveID, XO("Half Wave"), OnZoomHalfWave)
#endif
END_POPUP_MENU_SECTION()
BEGIN_POPUP_MENU_SECTION( "InOut" )
POPUP_MENU_ITEM( "In", OnZoomInVerticalID, XO("Zoom In\tLeft-Click/Left-Drag"), OnZoomInVertical)
POPUP_MENU_ITEM( "Out", OnZoomOutVerticalID, XO("Zoom Out\tShift-Left-Click"), OnZoomOutVertical)
END_POPUP_MENU_SECTION()
END_POPUP_MENU_SECTION()
END_POPUP_MENU()

View File

@ -75,7 +75,9 @@ private:
class WaveformVRulerMenuTable : public WaveTrackVRulerMenuTable
{
WaveformVRulerMenuTable() : WaveTrackVRulerMenuTable() {}
WaveformVRulerMenuTable()
: WaveTrackVRulerMenuTable{ "WaveFormVRuler" }
{}
virtual ~WaveformVRulerMenuTable() {}
DECLARE_POPUP_MENU(WaveformVRulerMenuTable);
@ -83,7 +85,7 @@ public:
static PopupMenuTable &Instance();
private:
virtual void InitMenu(Menu *pMenu) override;
virtual void InitMenu(wxMenu *pMenu) override;
void OnWaveformScaleType(wxCommandEvent &evt);
};

View File

@ -40,7 +40,9 @@ enum
class TimeTrackMenuTable : public PopupMenuTable
{
TimeTrackMenuTable() : mpData(NULL) {}
TimeTrackMenuTable()
: PopupMenuTable{ "TimeTrack" }
{}
DECLARE_POPUP_MENU(TimeTrackMenuTable);
public:
@ -52,7 +54,7 @@ private:
mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
}
void InitMenu(Menu *pMenu) override
void InitMenu(wxMenu *pMenu) override
{
TimeTrack *const pTrack = static_cast<TimeTrack*>(mpData->pTrack);
@ -68,7 +70,7 @@ private:
mpData = nullptr;
}
CommonTrackControls::InitMenuData *mpData;
CommonTrackControls::InitMenuData *mpData{};
void OnSetTimeTrackRange(wxCommandEvent & /*event*/);
void OnTimeTrackLin(wxCommandEvent & /*event*/);
@ -160,12 +162,15 @@ void TimeTrackMenuTable::OnTimeTrackLogInt(wxCommandEvent & /*event*/)
}
BEGIN_POPUP_MENU(TimeTrackMenuTable)
POPUP_MENU_SEPARATOR()
POPUP_MENU_RADIO_ITEM(OnTimeTrackLinID, XO("&Linear scale"), OnTimeTrackLin)
POPUP_MENU_RADIO_ITEM(OnTimeTrackLogID, XO("L&ogarithmic scale"), OnTimeTrackLog)
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(OnSetTimeTrackRangeID, XO("&Range..."), OnSetTimeTrackRange)
POPUP_MENU_CHECK_ITEM(OnTimeTrackLogIntID, XO("Logarithmic &Interpolation"), OnTimeTrackLogInt)
BEGIN_POPUP_MENU_SECTION( "Scales" )
POPUP_MENU_RADIO_ITEM( "Linear", OnTimeTrackLinID, XO("&Linear scale"), OnTimeTrackLin)
POPUP_MENU_RADIO_ITEM( "Log", OnTimeTrackLogID, XO("L&ogarithmic scale"), OnTimeTrackLog)
END_POPUP_MENU_SECTION()
BEGIN_POPUP_MENU_SECTION( "Other" )
POPUP_MENU_ITEM( "Range", OnSetTimeTrackRangeID, XO("&Range..."), OnSetTimeTrackRange)
POPUP_MENU_CHECK_ITEM( "LogInterp", OnTimeTrackLogIntID, XO("Logarithmic &Interpolation"), OnTimeTrackLogInt)
END_POPUP_MENU_SECTION()
END_POPUP_MENU()
PopupMenuTable *TimeTrackControls::GetMenuExtension(Track *)

View File

@ -80,7 +80,9 @@ enum
class TrackMenuTable : public PopupMenuTable
{
TrackMenuTable() : mpData(NULL) {}
TrackMenuTable()
: PopupMenuTable{ "Track" }
{}
DECLARE_POPUP_MENU(TrackMenuTable);
public:
@ -91,14 +93,14 @@ private:
void OnMoveTrack(wxCommandEvent &event);
void InitUserData(void *pUserData) override;
void InitMenu(Menu *pMenu) override;
void InitMenu(wxMenu *pMenu) override;
void DestroyMenu() override
{
mpData = nullptr;
}
CommonTrackControls::InitMenuData *mpData;
CommonTrackControls::InitMenuData *mpData{};
};
TrackMenuTable &TrackMenuTable::Instance()
@ -112,7 +114,7 @@ void TrackMenuTable::InitUserData(void *pUserData)
mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
}
void TrackMenuTable::InitMenu(Menu *pMenu)
void TrackMenuTable::InitMenu(wxMenu *pMenu)
{
Track *const pTrack = mpData->pTrack;
@ -125,51 +127,54 @@ void TrackMenuTable::InitMenu(Menu *pMenu)
}
BEGIN_POPUP_MENU(TrackMenuTable)
POPUP_MENU_ITEM(OnSetNameID, XO("&Name..."), OnSetName)
POPUP_MENU_SEPARATOR()
POPUP_MENU_ITEM(
// It is not correct to use NormalizedKeyString::Display here --
// wxWidgets will apply its equivalent to the key names passed to menu
// functions.
OnMoveUpID,
XO("Move Track &Up").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveUp")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM(
OnMoveDownID,
XO("Move Track &Down").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveDown")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM(
OnMoveTopID,
XO("Move Track to &Top").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveTop")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM(
OnMoveBottomID,
XO("Move Track to &Bottom").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveBottom")).GET() ),
wxT("\t")
),
OnMoveTrack)
BEGIN_POPUP_MENU_SECTION( "Basic" )
POPUP_MENU_ITEM( "Name", OnSetNameID, XO("&Name..."), OnSetName)
END_POPUP_MENU_SECTION()
BEGIN_POPUP_MENU_SECTION( "Move" )
POPUP_MENU_ITEM( "Up",
// It is not correct to use NormalizedKeyString::Display here --
// wxWidgets will apply its equivalent to the key names passed to menu
// functions.
OnMoveUpID,
XO("Move Track &Up").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveUp")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM( "Down",
OnMoveDownID,
XO("Move Track &Down").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveDown")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM( "Top",
OnMoveTopID,
XO("Move Track to &Top").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveTop")).GET() ),
wxT("\t")
),
OnMoveTrack)
POPUP_MENU_ITEM( "Bottom",
OnMoveBottomID,
XO("Move Track to &Bottom").Join(
Verbatim(
CommandManager::Get( mpData->project ).
// using GET to compose menu item name for wxWidgets
GetKeyFromName(wxT("TrackMoveBottom")).GET() ),
wxT("\t")
),
OnMoveTrack)
END_POPUP_MENU_SECTION()
END_POPUP_MENU()
@ -282,7 +287,7 @@ unsigned CommonTrackControls::DoContextMenu(
PopupMenuTable *const pExtension = GetMenuExtension(track.get());
if (pExtension)
pMenu->Extend(pExtension);
PopupMenuTable::ExtendMenu( *pMenu, *pExtension );
pParent->PopupMenu
(pMenu.get(), buttonRect.x + 1, buttonRect.y + buttonRect.height + 1);

View File

@ -11,93 +11,186 @@ Paul Licameli split from TrackPanel.cpp
#include "../Audacity.h"
#include "PopupMenuTable.h"
PopupMenuTable::Menu::~Menu()
PopupMenuTableEntry::~PopupMenuTableEntry()
{}
PopupSubMenu::~PopupSubMenu()
{}
PopupSubMenu::PopupSubMenu( const Identifier &stringId,
const TranslatableString &caption_, PopupMenuTable &table )
: ConcreteGroupItem< false >{ stringId }
, caption{ caption_ }
{
// Event connections between the parent window and the singleton table
// object must be broken when this menu is destroyed.
Disconnect();
}
void PopupMenuTable::Menu::Extend(PopupMenuTable *pTable)
namespace {
struct PopupMenu : public wxMenu
{
pTable->InitUserData(pUserData);
PopupMenu(wxEvtHandler *pParent_, void *pUserData_)
: pParent{ pParent_ }, tables{}, pUserData{ pUserData_ } {}
auto connect = [&]( const PopupMenuTable::Entry *pEntry ) {
this->pParent->Bind
~PopupMenu() override;
void Extend(PopupMenuTable *pTable);
void DisconnectTable(PopupMenuTable *pTable);
void Disconnect();
wxEvtHandler *pParent;
std::vector<PopupMenuTable*> tables;
void *pUserData;
};
class PopupMenuBuilder : public MenuVisitor {
public:
explicit
PopupMenuBuilder( PopupMenuTable &table, PopupMenu &menu, void *pUserData )
: mTable{ table }
, mMenu{ &menu }
, mRoot{ mMenu }
, mpUserData{ pUserData }
{}
void DoBeginGroup( Registry::GroupItem &item, const Path &path ) override;
void DoEndGroup( Registry::GroupItem &item, const Path &path ) override;
void DoVisit( Registry::SingleItem &item, const Path &path ) override;
void DoSeparator() override;
PopupMenuTable &mTable;
std::vector< std::unique_ptr<PopupMenu> > mMenus;
PopupMenu *mMenu, *mRoot;
void *const mpUserData;
};
void PopupMenuBuilder::DoBeginGroup( Registry::GroupItem &item, const Path &path )
{
if ( auto pItem = dynamic_cast<PopupSubMenu*>(&item) ) {
if ( !pItem->caption.empty() ) {
auto newMenu =
std::make_unique<PopupMenu>( mMenu->pParent, mMenu->pUserData );
mMenu = newMenu.get();
mMenus.push_back( std::move( newMenu ) );
}
}
}
void PopupMenuBuilder::DoEndGroup( Registry::GroupItem &item, const Path &path )
{
if ( auto pItem = dynamic_cast<PopupSubMenu*>(&item) ) {
if ( !pItem->caption.empty() ) {
auto subMenu = std::move( mMenus.back() );
mMenus.pop_back();
mMenu = mMenus.empty() ? mRoot : mMenus.back().get();
mMenu->AppendSubMenu( subMenu.release(), pItem->caption.Translation());
}
}
}
void PopupMenuBuilder::DoVisit( Registry::SingleItem &item, const Path &path )
{
auto connect = [this]( const PopupMenuTable::Entry *pEntry ) {
mMenu->pParent->Bind
(wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, pTable, pEntry->id);
pEntry->func, &mTable, pEntry->id);
};
for (const PopupMenuTable::Entry *pEntry = &*pTable->Get().begin();
pEntry->IsValid(); ++pEntry) {
switch (pEntry->type) {
auto pEntry = static_cast<PopupMenuTableEntry*>( &item );
switch (pEntry->type) {
case PopupMenuTable::Entry::Item:
{
this->Append(pEntry->id, pEntry->caption.Translation());
mMenu->Append(pEntry->id, pEntry->caption.Translation());
connect( pEntry );
break;
}
case PopupMenuTable::Entry::RadioItem:
{
this->AppendRadioItem(pEntry->id, pEntry->caption.Translation());
mMenu->AppendRadioItem(pEntry->id, pEntry->caption.Translation());
connect( pEntry );
break;
}
case PopupMenuTable::Entry::CheckItem:
{
this->AppendCheckItem(pEntry->id, pEntry->caption.Translation());
mMenu->AppendCheckItem(pEntry->id, pEntry->caption.Translation());
connect( pEntry );
break;
}
case PopupMenuTable::Entry::Separator:
this->AppendSeparator();
break;
case PopupMenuTable::Entry::SubMenu:
{
const auto subTable = pEntry->subTable;
auto subMenu = BuildMenu( this->pParent, subTable, pUserData );
this->AppendSubMenu( subMenu.release(), pEntry->caption.Translation());
}
default:
break;
}
}
pTable->InitMenu(this);
tables.push_back( pTable );
}
void PopupMenuTable::Menu::DisconnectTable(PopupMenuTable *pTable)
void PopupMenuBuilder::DoSeparator()
{
for (const PopupMenuTable::Entry *pEntry = &*pTable->Get().begin();
pEntry->IsValid(); ++pEntry) {
if ( pEntry->IsItem() )
pParent->Unbind( wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, pTable, pEntry->id );
else if ( pEntry->IsSubMenu() )
// recur
DisconnectTable(pEntry->subTable);
}
mMenu->AppendSeparator();
}
PopupMenu::~PopupMenu()
{
// Event connections between the parent window and the singleton table
// object must be broken when this menu is destroyed.
Disconnect();
}
}
void PopupMenuTable::ExtendMenu( wxMenu &menu, PopupMenuTable &table )
{
auto &theMenu = dynamic_cast<PopupMenu&>(menu);
table.InitUserData(theMenu.pUserData);
PopupMenuBuilder visitor{ table, theMenu, theMenu.pUserData };
Registry::Visit( visitor, table.Get().get() );
table.InitMenu( &menu );
theMenu.tables.push_back( &table );
}
namespace{
void PopupMenu::DisconnectTable(PopupMenuTable *pTable)
{
class PopupMenuDestroyer : public MenuVisitor {
public:
explicit
PopupMenuDestroyer( PopupMenuTable &table, PopupMenu &menu )
: mTable{ table }
, mMenu{ menu }
{}
void DoVisit( Registry::SingleItem &item, const Path &path ) override
{
auto pEntry = static_cast<PopupMenuTableEntry*>( &item );
mMenu.pParent->Unbind( wxEVT_COMMAND_MENU_SELECTED,
pEntry->func, &mTable, pEntry->id );
}
PopupMenuTable &mTable;
PopupMenu &mMenu;
};
PopupMenuDestroyer visitor{ *pTable, *this };
Registry::Visit( visitor, pTable->Get().get() );
pTable->DestroyMenu();
}
void PopupMenuTable::Menu::Disconnect()
void PopupMenu::Disconnect()
{
for ( auto pTable : tables )
DisconnectTable(pTable);
}
}
void PopupMenuTable::InitMenu(Menu *)
void PopupMenuTable::InitMenu(wxMenu *)
{
}
// static
std::unique_ptr<PopupMenuTable::Menu> PopupMenuTable::BuildMenu
std::unique_ptr<wxMenu> PopupMenuTable::BuildMenu
( wxEvtHandler *pParent, PopupMenuTable *pTable, void *pUserData )
{
// Rebuild as needed each time. That makes it safe in case of language change.
std::unique_ptr<Menu> theMenu{ safenew Menu( pParent, pUserData ) };
theMenu->Extend(pTable);
auto theMenu = std::make_unique<PopupMenu>( pParent, pUserData );
ExtendMenu( *theMenu, *pTable );
return theMenu;
}

View File

@ -25,12 +25,13 @@ class wxString;
#include "../MemoryX.h"
#include "../Internat.h"
#include "../commands/CommandManager.h"
class PopupMenuTable;
struct PopupMenuTableEntry
struct PopupMenuTableEntry : Registry::SingleItem
{
enum Type { Item, RadioItem, CheckItem, Separator, SubMenu, Invalid };
enum Type { Item, RadioItem, CheckItem };
Type type;
int id;
@ -38,45 +39,45 @@ struct PopupMenuTableEntry
wxCommandEventFunction func;
PopupMenuTable *subTable;
PopupMenuTableEntry(Type type_, int id_, TranslatableString caption_,
wxCommandEventFunction func_, PopupMenuTable *subTable_)
: type(type_)
PopupMenuTableEntry( const Identifier &stringId,
Type type_, int id_, const TranslatableString &caption_,
wxCommandEventFunction func_)
: SingleItem{ stringId }
, type(type_)
, id(id_)
, caption(caption_)
, func(func_)
, subTable(subTable_)
{}
bool IsItem() const { return type == Item || type == RadioItem || type == CheckItem; }
bool IsSubMenu() const { return type == SubMenu; }
bool IsValid() const { return type != Invalid; }
~PopupMenuTableEntry() override;
};
struct PopupSubMenu : Registry::ConcreteGroupItem< false >
{
TranslatableString caption;
PopupSubMenu( const Identifier &stringId,
const TranslatableString &caption_, PopupMenuTable &table );
~PopupSubMenu() override;
};
struct PopupMenuSection
: Registry::ConcreteGroupItem< false >
, MenuTable::MenuSection {
using ConcreteGroupItem< false >::ConcreteGroupItem;
};
class PopupMenuTable : public wxEvtHandler
{
public:
typedef PopupMenuTableEntry Entry;
using Entry = PopupMenuTableEntry;
class Menu
: public wxMenu
{
friend class PopupMenuTable;
Menu(wxEvtHandler *pParent_, void *pUserData_)
: pParent{ pParent_ }, tables{}, pUserData{ pUserData_ } {}
public:
virtual ~Menu();
void Extend(PopupMenuTable *pTable);
void DisconnectTable(PopupMenuTable *pTable);
void Disconnect();
private:
wxEvtHandler *pParent;
std::vector<PopupMenuTable*> tables;
void *pUserData;
};
// Supply a nonempty caption for sub-menu tables
PopupMenuTable( const Identifier &id, const TranslatableString &caption = {} )
: mId{ id }
, mCaption{ caption }
{}
// Called before the menu items are appended.
// Store user data, if needed.
@ -85,29 +86,39 @@ public:
// Called when the menu is about to pop up.
// Your chance to enable and disable items.
// Default implementation does nothing.
virtual void InitMenu(Menu *pMenu);
virtual void InitMenu(wxMenu *pMenu);
// Called when menu is destroyed.
virtual void DestroyMenu() = 0;
// Optional pUserData gets passed to the InitUserData routines of tables.
// No memory management responsibility is assumed by this function.
static std::unique_ptr<Menu> BuildMenu
static std::unique_ptr<wxMenu> BuildMenu
(wxEvtHandler *pParent, PopupMenuTable *pTable, void *pUserData = NULL);
const Identifier &Id() const { return mId; }
const TranslatableString &Caption() const { return mCaption; }
// menu must have been built by BuildMenu
// More items get added to the end of it
static void ExtendMenu( wxMenu &menu, PopupMenuTable &otherTable );
using Entries = std::vector<PopupMenuTableEntry>;
const std::shared_ptr< PopupSubMenu > &Get()
{
if (!mTop)
Populate();
return mTop;
}
protected:
virtual void Populate() = 0;
void Clear() { mContents.clear(); }
void Clear() { mTop.reset(); }
using Entries = std::vector<PopupMenuTableEntry>;
const Entries& Get()
{
if (mContents.empty())
Populate();
return mContents;
}
Entries mContents;
std::shared_ptr< PopupSubMenu > mTop;
std::vector< Registry::GroupItem* > mStack;
Identifier mId;
TranslatableString mCaption;
};
/*
@ -120,7 +131,7 @@ which inherits from PopupMenuTable,
DECLARE_POPUP_MENU(MyTable);
virtual void InitUserData(void *pUserData);
virtual void InitMenu(Menu *pMenu);
virtual void InitMenu(wxMenu *pMenu);
virtual void DestroyMenu();
Then in MyTable.cpp,
@ -131,7 +142,7 @@ void MyTable::InitUserData(void *pUserData)
auto pData = static_cast<MyData*>(pUserData);
}
void MyTable::InitMenu(Menu *pMenu)
void MyTable::InitMenu(wxMenu *pMenu)
{
// enable or disable menu items
}
@ -145,7 +156,7 @@ BEGIN_POPUP_MENU(MyTable)
// This is inside a function and can contain arbitrary code. But usually
// you only need a sequence of macro calls:
POPUP_MENU_ITEM(OnCutSelectedTextID, XO("Cu&t"), OnCutSelectedText)
POPUP_MENU_ITEM("Cut", OnCutSelectedTextID, XO("Cu&t"), OnCutSelectedText)
// etc.
END_POPUP_MENU()
@ -160,7 +171,7 @@ auto pMenu = PopupMenuTable::BuildMenu(pParent, &myTable, &data);
// Optionally:
OtherTable otherTable;
pMenu->Extend(&otherTable);
PopupMenuTable::ExtendMenu( *pMenu, otherTable );
pParent->PopupMenu(pMenu.get(), event.m_x, event.m_y);
@ -173,47 +184,53 @@ That's all!
// begins function
#define BEGIN_POPUP_MENU(HandlerClass) \
void HandlerClass::Populate() { \
typedef HandlerClass My;
using My = HandlerClass; \
mTop = std::make_shared< PopupSubMenu >( \
Id(), Caption(), *this ); \
mStack.clear(); \
mStack.push_back( mTop.get() );
#define POPUP_MENU_APPEND(type, id, string, memFn, subTable) \
mContents.push_back( Entry { \
#define POPUP_MENU_APPEND(stringId, type, id, string, memFn) \
mStack.back()->items.push_back( std::make_unique<Entry>( \
Identifier{ stringId }, \
type, \
id, \
string, \
memFn, \
subTable \
} );
memFn \
) );
#define POPUP_MENU_APPEND_ITEM(type, id, string, memFn) \
POPUP_MENU_APPEND( \
#define POPUP_MENU_APPEND_ITEM(stringId, type, id, string, memFn) \
POPUP_MENU_APPEND( stringId, \
type, \
id, \
string, \
(wxCommandEventFunction) (&My::memFn), \
nullptr )
(wxCommandEventFunction) (&My::memFn) )
#define POPUP_MENU_ITEM(id, string, memFn) \
POPUP_MENU_APPEND_ITEM(Entry::Item, id, string, memFn);
#define POPUP_MENU_ITEM(stringId, id, string, memFn) \
POPUP_MENU_APPEND_ITEM(stringId, Entry::Item, id, string, memFn);
#define POPUP_MENU_RADIO_ITEM(id, string, memFn) \
POPUP_MENU_APPEND_ITEM(Entry::RadioItem, id, string, memFn);
#define POPUP_MENU_RADIO_ITEM(stringId, id, string, memFn) \
POPUP_MENU_APPEND_ITEM(stringId, Entry::RadioItem, id, string, memFn);
#define POPUP_MENU_CHECK_ITEM(id, string, memFn) \
POPUP_MENU_APPEND_ITEM(Entry::CheckItem, id, string, memFn);
#define POPUP_MENU_CHECK_ITEM(stringId, id, string, memFn) \
POPUP_MENU_APPEND_ITEM(stringId, Entry::CheckItem, id, string, memFn);
// classname names a class that derives from MenuTable and defines Instance()
#define POPUP_MENU_SUB_MENU(id, string, classname) \
POPUP_MENU_APPEND( \
Entry::SubMenu, id, string, nullptr, &classname::Instance() );
#define POPUP_MENU_SUB_MENU(stringId, classname) \
mStack.back()->items.push_back( \
Registry::Shared( classname::Instance().Get() ) );
#define POPUP_MENU_SEPARATOR() \
POPUP_MENU_APPEND( \
Entry::Separator, -1, {}, nullptr, nullptr );
// ends function
#define END_POPUP_MENU() \
POPUP_MENU_APPEND( \
Entry::Invalid, -1, {}, nullptr, nullptr ) \
#define BEGIN_POPUP_MENU_SECTION( name ) \
{ auto uSection = std::make_unique< PopupMenuSection >( \
Identifier{ name } ); \
auto section = uSection.get(); \
mStack.back()->items.push_back( std::move( uSection ) ); \
mStack.push_back( section ); \
}
#define END_POPUP_MENU_SECTION() mStack.pop_back();
// ends function
#define END_POPUP_MENU() }
#endif