Specify list control columns and styles all in one call

This commit is contained in:
Paul Licameli 2018-02-02 19:22:07 -05:00
parent 17ee2478bc
commit ae353fe61f
10 changed files with 127 additions and 67 deletions

View File

@ -72,10 +72,9 @@ void AutoRecoveryDialog::PopulateOrExchange(ShuttleGui& S)
S.StartStatic(_("Recoverable projects")); S.StartStatic(_("Recoverable projects"));
{ {
mFileList = S.Id(ID_FILE_LIST).AddListControlReportMode(); mFileList = S.Id(ID_FILE_LIST)
/*i18n-hint: (noun). It's the name of the project to recover.*/ /*i18n-hint: (noun). It's the name of the project to recover.*/
mFileList->InsertColumn(0, _("Name")); .AddListControlReportMode( { _("Name") } );
mFileList->SetColumnWidth(0, wxLIST_AUTOSIZE);
PopulateList(); PopulateList();
} }
S.EndStatic(); S.EndStatic();

View File

@ -137,8 +137,8 @@ void ApplyMacroDialog::PopulateOrExchange(ShuttleGui &S)
{ {
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_SINGLE_SEL); wxLC_SINGLE_SEL);
mMacros = S.Id(MacrosListID).Prop(1).AddListControlReportMode(); mMacros = S.Id(MacrosListID).Prop(1)
mMacros->InsertColumn(0, _("Macro"), wxLIST_FORMAT_LEFT); .AddListControlReportMode( { _("Macro") } );
} }
S.EndStatic(); S.EndStatic();
@ -410,10 +410,10 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_SINGLE_SEL); wxLC_SINGLE_SEL);
fileList = S.Id(CommandsListID).AddListControlReportMode(); fileList = S.Id(CommandsListID)
.AddListControlReportMode( { _("File") } );
// AssignImageList takes ownership // AssignImageList takes ownership
fileList->AssignImageList(imageList.release(), wxIMAGE_LIST_SMALL); fileList->AssignImageList(imageList.release(), wxIMAGE_LIST_SMALL);
fileList->InsertColumn(0, _("File"), wxLIST_FORMAT_LEFT);
} }
S.EndStatic(); S.EndStatic();
@ -618,9 +618,9 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
{ {
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_SINGLE_SEL | S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_SINGLE_SEL |
wxLC_EDIT_LABELS); wxLC_EDIT_LABELS);
mMacros = S.Id(MacrosListID).Prop(1).AddListControlReportMode(); mMacros = S.Id(MacrosListID).Prop(1)
// i18n-hint: This is the heading for a column in the edit macros dialog // i18n-hint: This is the heading for a column in the edit macros dialog
mMacros->InsertColumn(0, _("Macro"), wxLIST_FORMAT_LEFT); .AddListControlReportMode( { _("Macro") } );
S.StartVerticalLay(wxALIGN_TOP, 0); S.StartVerticalLay(wxALIGN_TOP, 0);
{ {
S.Id(AddButtonID).AddButton(_("&New")); S.Id(AddButtonID).AddButton(_("&New"));
@ -646,16 +646,13 @@ void MacrosWindow::PopulateOrExchange(ShuttleGui & S)
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_SINGLE_SEL); wxLC_SINGLE_SEL);
mList = S.Id(CommandsListID).AddListControlReportMode(); mList = S.Id(CommandsListID)
.AddListControlReportMode({
//A dummy first column, which is then deleted, is a workaround - under Windows the first column /* i18n-hint: This is the number of the command in the list */
//can't be right aligned. { _("Num"), wxLIST_FORMAT_RIGHT },
mList->InsertColumn(0, wxT(""), wxLIST_FORMAT_LEFT); { _("Command "), wxLIST_FORMAT_RIGHT },
/* i18n-hint: This is the number of the command in the list */ { _("Parameters"), wxLIST_FORMAT_LEFT }
mList->InsertColumn(ItemNumberColumn + 1, _("Num"), wxLIST_FORMAT_RIGHT); });
mList->InsertColumn(ActionColumn + 1, _("Command "), wxLIST_FORMAT_RIGHT);
mList->InsertColumn(ParamsColumn + 1, _("Parameters"), wxLIST_FORMAT_LEFT);
mList->DeleteColumn(0);
S.StartVerticalLay(wxALIGN_TOP, 0); S.StartVerticalLay(wxALIGN_TOP, 0);
{ {

View File

@ -356,11 +356,10 @@ void DependencyDialog::PopulateOrExchange(ShuttleGui& S)
S.StartStatic(_("Project Dependencies"),1); S.StartStatic(_("Project Dependencies"),1);
{ {
mFileListCtrl = S.Id(FileListID).AddListControlReportMode(); mFileListCtrl = S.Id(FileListID).AddListControlReportMode({
mFileListCtrl->InsertColumn(0, _("Audio File")); { _("Audio File"), wxLIST_FORMAT_LEFT, 220 },
mFileListCtrl->SetColumnWidth(0, 220); { _("Disk Space"), wxLIST_FORMAT_LEFT, 120 }
mFileListCtrl->InsertColumn(1, _("Disk Space")); });
mFileListCtrl->SetColumnWidth(1, 120);
PopulateList(); PopulateList();
mCopySelectedFilesButton = mCopySelectedFilesButton =

View File

@ -83,12 +83,12 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
{ {
S.StartStatic(_("&Manage History"), 1); S.StartStatic(_("&Manage History"), 1);
{ {
mList = S.AddListControlReportMode(); mList = S
// Do this BEFORE inserting the columns. On the Mac at least, the .AddListControlReportMode(
// columns are deleted and later InsertItem()s will cause Audacity to crash. { { _("Action"), wxLIST_FORMAT_LEFT, 260 },
mList->SetSingleStyle(wxLC_SINGLE_SEL); { _("Reclaimable Space"), wxLIST_FORMAT_LEFT, 125 } },
mList->InsertColumn(0, _("Action"), wxLIST_FORMAT_LEFT, 260); wxLC_SINGLE_SEL
mList->InsertColumn(1, _("Reclaimable Space"), wxLIST_FORMAT_LEFT, 125); );
//Assign rather than set the image list, so that it is deleted later. //Assign rather than set the image list, so that it is deleted later.
// AssignImageList takes ownership // AssignImageList takes ownership

View File

@ -565,16 +565,14 @@ void PluginRegistrationDialog::PopulateOrExchange(ShuttleGui &S)
S.EndHorizontalLay(); S.EndHorizontalLay();
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES ); S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES );
mEffects = S.Id(ID_List).AddListControlReportMode(); mEffects = S.Id(ID_List)
.AddListControlReportMode({ _("Name"), _("State"), _("Path") });
mEffects->Bind(wxEVT_KEY_DOWN, mEffects->Bind(wxEVT_KEY_DOWN,
&PluginRegistrationDialog::OnListChar, &PluginRegistrationDialog::OnListChar,
this); this);
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
mEffects->SetAccessible(mAx = safenew CheckListAx(mEffects)); mEffects->SetAccessible(mAx = safenew CheckListAx(mEffects));
#endif #endif
mEffects->InsertColumn(COL_Name, _("Name"));
mEffects->InsertColumn(COL_State, _("State"));
mEffects->InsertColumn(COL_Path, _("Path"));
S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, 0); S.StartHorizontalLay(wxALIGN_LEFT | wxEXPAND, 0);
{ {

View File

@ -699,20 +699,6 @@ wxListBox * ShuttleGuiBase::AddListBox(const wxArrayStringEx &choices, long styl
} }
wxListCtrl * ShuttleGuiBase::AddListControl()
{
UseUpId();
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxListCtrl);
wxListCtrl * pListCtrl;
SetProportions( 1 );
mpWind = pListCtrl = safenew wxListCtrl(GetParent(), miId,
wxDefaultPosition, wxDefaultSize, Style( wxLC_ICON ));
pListCtrl->SetMinSize( wxSize( 120,150 ));
UpdateSizers();
return pListCtrl;
}
wxGrid * ShuttleGuiBase::AddGrid() wxGrid * ShuttleGuiBase::AddGrid()
{ {
UseUpId(); UseUpId();
@ -727,7 +713,30 @@ wxGrid * ShuttleGuiBase::AddGrid()
return pGrid; return pGrid;
} }
wxListCtrl * ShuttleGuiBase::AddListControlReportMode() wxListCtrl * ShuttleGuiBase::AddListControl(
std::initializer_list<const ListControlColumn> columns,
long listControlStyles
)
{
UseUpId();
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxListCtrl);
wxListCtrl * pListCtrl;
SetProportions( 1 );
mpWind = pListCtrl = safenew wxListCtrl(GetParent(), miId,
wxDefaultPosition, wxDefaultSize, Style( wxLC_ICON ));
pListCtrl->SetMinSize( wxSize( 120,150 ));
UpdateSizers();
DoInsertListColumns( pListCtrl, listControlStyles, columns );
return pListCtrl;
}
wxListCtrl * ShuttleGuiBase::AddListControlReportMode(
std::initializer_list<const ListControlColumn> columns,
long listControlStyles
)
{ {
UseUpId(); UseUpId();
if( mShuttleMode != eIsCreating ) if( mShuttleMode != eIsCreating )
@ -739,9 +748,43 @@ wxListCtrl * ShuttleGuiBase::AddListControlReportMode()
Style( wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxSUNKEN_BORDER )); Style( wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxSUNKEN_BORDER ));
// pListCtrl->SetMinSize( wxSize( 120,150 )); // pListCtrl->SetMinSize( wxSize( 120,150 ));
UpdateSizers(); UpdateSizers();
DoInsertListColumns( pListCtrl, listControlStyles, columns );
return pListCtrl; return pListCtrl;
} }
void ShuttleGuiBase::DoInsertListColumns(
wxListCtrl *pListCtrl,
long listControlStyles,
std::initializer_list<const ListControlColumn> columns )
{
// Old comment from HistoryWindow.cpp follows
// -- is it still correct for wxWidgets 3?
// Do this BEFORE inserting the columns. On the Mac at least, the
// columns are deleted and later InsertItem()s will cause Audacity to crash.
for ( auto style = 1l; style <= listControlStyles; style <<= 1 )
if ( (style & listControlStyles) )
pListCtrl->SetSingleStyle(style, true);
long iCol = 0;
bool dummyColumn =
columns.size() > 0 && begin(columns)->format == wxLIST_FORMAT_RIGHT;
//A dummy first column, which is then deleted, is a workaround -
// under Windows the first column can't be right aligned.
if (dummyColumn)
pListCtrl->InsertColumn( iCol++, wxString{} );
for (auto &column : columns)
pListCtrl->InsertColumn(
iCol++, column.heading, column.format, column.width );
if (dummyColumn)
pListCtrl->DeleteColumn( 0 );
}
wxTreeCtrl * ShuttleGuiBase::AddTree() wxTreeCtrl * ShuttleGuiBase::AddTree()
{ {
UseUpId(); UseUpId();

View File

@ -20,6 +20,7 @@
#include <vector> #include <vector>
#include <wx/slider.h> // to inherit #include <wx/slider.h> // to inherit
#include "MemoryX.h" #include "MemoryX.h"
#include <wx/listbase.h> // for wxLIST_FORMAT_LEFT
#include "WrappedType.h" #include "WrappedType.h"
@ -163,8 +164,26 @@ public:
wxTextCtrl * AddNumericTextBox(const wxString &Caption, const wxString &Value, const int nChars); wxTextCtrl * AddNumericTextBox(const wxString &Caption, const wxString &Value, const int nChars);
wxTextCtrl * AddTextWindow(const wxString &Value); wxTextCtrl * AddTextWindow(const wxString &Value);
wxListBox * AddListBox(const wxArrayStringEx &choices, long style = 0); wxListBox * AddListBox(const wxArrayStringEx &choices, long style = 0);
wxListCtrl * AddListControl();
wxListCtrl * AddListControlReportMode(); struct ListControlColumn{
ListControlColumn(
wxString h, int f = wxLIST_FORMAT_LEFT, int w = wxLIST_AUTOSIZE)
: heading(h), format(f), width(w)
{}
wxString heading;
int format;
int width;
};
wxListCtrl * AddListControl(
std::initializer_list<const ListControlColumn> columns = {},
long listControlStyles = 0
);
wxListCtrl * AddListControlReportMode(
std::initializer_list<const ListControlColumn> columns = {},
long listControlStyles = 0
);
wxGrid * AddGrid(); wxGrid * AddGrid();
wxCheckBox * AddCheckBox( const wxString &Prompt, bool Selected); wxCheckBox * AddCheckBox( const wxString &Prompt, bool Selected);
wxCheckBox * AddCheckBoxOnRight( const wxString &Prompt, bool Selected); wxCheckBox * AddCheckBoxOnRight( const wxString &Prompt, bool Selected);
@ -334,6 +353,12 @@ protected:
private: private:
void SetSizeHints( const wxArrayStringEx & items ); void SetSizeHints( const wxArrayStringEx & items );
void DoInsertListColumns(
wxListCtrl *pListCtrl,
long listControlStyles,
std::initializer_list<const ListControlColumn> columns );
public: public:
static void SetSizeHints( wxWindow *window, const wxArrayStringEx & items ); static void SetSizeHints( wxWindow *window, const wxArrayStringEx & items );

View File

@ -3334,8 +3334,10 @@ void EditCurvesDialog::PopulateOrExchange(ShuttleGui & S)
S.StartStatic(_("&Curves"), 1); S.StartStatic(_("&Curves"), 1);
{ {
S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES ); S.SetStyle(wxSUNKEN_BORDER | wxLC_REPORT | wxLC_HRULES | wxLC_VRULES );
mList = S.Id(CurvesListID).AddListControlReportMode(); mList = S.Id(CurvesListID)
mList->InsertColumn(0, _("Curve Name"), wxLIST_FORMAT_RIGHT); .AddListControlReportMode({
{ _("Curve Name"), wxLIST_FORMAT_RIGHT }
});
} }
S.EndStatic(); S.EndStatic();
S.StartVerticalLay(0); S.StartVerticalLay(0);

View File

@ -511,8 +511,8 @@ void AudioUnitEffectExportDialog::PopulateOrExchange(ShuttleGui & S)
{ {
S.SetStyle(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | S.SetStyle(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_NO_SORT_HEADER); wxLC_NO_SORT_HEADER);
mList = S.AddListControlReportMode(); mList = S
mList->InsertColumn(0, _("Preset"), wxLIST_FORMAT_LEFT); .AddListControlReportMode( { _("Preset") } );
} }
S.EndStatic(); S.EndStatic();
} }
@ -684,9 +684,8 @@ void AudioUnitEffectImportDialog::PopulateOrExchange(ShuttleGui & S)
{ {
S.SetStyle(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | S.SetStyle(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
wxLC_NO_SORT_HEADER); wxLC_NO_SORT_HEADER);
mList = S.AddListControlReportMode(); mList = S
mList->InsertColumn(0, _("Preset"), wxLIST_FORMAT_LEFT); .AddListControlReportMode( { _("Preset"), _("Location") } );
mList->InsertColumn(1, _("Location"), wxLIST_FORMAT_LEFT);
} }
S.EndStatic(); S.EndStatic();
} }

View File

@ -148,14 +148,14 @@ void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
} }
S.AddWindow(RuleTable, wxEXPAND | wxALL); S.AddWindow(RuleTable, wxEXPAND | wxALL);
PluginList = S.Id(EIPPluginList).AddListControl (); PluginList = S.Id(EIPPluginList).AddListControl(
{ { _("Importer order"), wxLIST_FORMAT_LEFT,
wxLIST_AUTOSIZE_USEHEADER } },
wxLC_REPORT | wxLC_SINGLE_SEL
);
if (fillRuleTable) if (fillRuleTable)
{ {
PluginList->SetSingleStyle (wxLC_REPORT, true);
PluginList->SetSingleStyle (wxLC_SINGLE_SEL, true);
PluginList->InsertColumn (0, _("Importer order"));
ExtImportPrefsDropTarget *dragtarget2 {}; ExtImportPrefsDropTarget *dragtarget2 {};
PluginList->SetDropTarget ( PluginList->SetDropTarget (
dragtarget2 = safenew ExtImportPrefsDropTarget( dragtarget2 = safenew ExtImportPrefsDropTarget(
@ -164,8 +164,6 @@ void ExtImportPrefs::PopulateOrExchange(ShuttleGui & S)
); );
dragtarget2->SetPrefs (this); dragtarget2->SetPrefs (this);
PluginList->SetColumnWidth (0, wxLIST_AUTOSIZE_USEHEADER);
auto &items = Importer::Get().GetImportItems(); auto &items = Importer::Get().GetImportItems();
{ {
int i = -1; int i = -1;