Add optional label to wxFileDialogCustomize::AddTextCtrl()

Creating a text with a label is a common operation and can be
implemented to look slightly better than AddStaticText() followed by
AddTextCtrl() without a label when using IFileDialog.
This commit is contained in:
Vadim Zeitlin
2022-05-28 01:26:39 +01:00
parent 095c4dfc94
commit 751a73a2ca
5 changed files with 33 additions and 9 deletions

View File

@@ -130,7 +130,7 @@ class wxFileDialogCustomize
public:
wxFileDialogButton* AddButton(const wxString& label);
wxFileDialogCheckBox* AddCheckBox(const wxString& label);
wxFileDialogTextCtrl* AddTextCtrl();
wxFileDialogTextCtrl* AddTextCtrl(const wxString& label = wxString());
wxFileDialogStaticText* AddStaticText(const wxString& label);
~wxFileDialogCustomize();

View File

@@ -58,7 +58,7 @@ class wxFileDialogCustomizeImpl
public:
virtual wxFileDialogButtonImpl* AddButton(const wxString& label) = 0;
virtual wxFileDialogCheckBoxImpl* AddCheckBox(const wxString& label) = 0;
virtual wxFileDialogTextCtrlImpl* AddTextCtrl() = 0;
virtual wxFileDialogTextCtrlImpl* AddTextCtrl(const wxString& label) = 0;
virtual wxFileDialogStaticTextImpl* AddStaticText(const wxString& label) = 0;
virtual ~wxFileDialogCustomizeImpl();

View File

@@ -1691,8 +1691,7 @@ public:
// Note: all the pointers created here cease to be valid once
// ShowModal() returns, TransferDataFromCustomControls() is the latest
// moment when they can still be used.
customizer.AddStaticText("Just some extra text:");
m_text = customizer.AddTextCtrl();
m_text = customizer.AddTextCtrl("Just some extra text:");
m_cb = customizer.AddCheckBox("Enable Custom Button");
m_cb->Bind(wxEVT_CHECKBOX, &MyCustomizeHook::OnCheckBox, this);
m_btn = customizer.AddButton("Custom Button");

View File

@@ -206,9 +206,9 @@ wxFileDialogCustomize::AddCheckBox(const wxString& label)
}
wxFileDialogTextCtrl*
wxFileDialogCustomize::AddTextCtrl()
wxFileDialogCustomize::AddTextCtrl(const wxString& label)
{
return StoreAndReturn(new wxFileDialogTextCtrl(m_impl->AddTextCtrl()));
return StoreAndReturn(new wxFileDialogTextCtrl(m_impl->AddTextCtrl(label)));
}
wxFileDialogStaticText*

View File

@@ -378,7 +378,8 @@ public:
wxFileDialogCustomizeFDC()
: wxFileDialogCustomize(this)
{
m_lastId = 0;
m_lastId =
m_lastAuxId = 0;
}
bool Initialize(IFileDialog* fileDialog)
@@ -433,15 +434,31 @@ public:
return new wxFileDialogCheckBoxImplFDC(m_fdc, m_lastId);
}
wxFileDialogTextCtrlImpl* AddTextCtrl() wxOVERRIDE
wxFileDialogTextCtrlImpl* AddTextCtrl(const wxString& label) wxOVERRIDE
{
HRESULT hr = m_fdc->AddEditBox(++m_lastId, L"");
HRESULT hr;
if ( !label.empty() )
{
hr = m_fdc->StartVisualGroup(--m_lastAuxId, label.wc_str());
if ( FAILED(hr) )
wxLogApiError(wxS("IFileDialogCustomize::StartVisualGroup"), hr);
}
hr = m_fdc->AddEditBox(++m_lastId, L"");
if ( FAILED(hr) )
{
wxLogApiError(wxS("IFileDialogCustomize::AddEditBox"), hr);
return NULL;
}
if ( !label.empty() )
{
hr = m_fdc->EndVisualGroup();
if ( FAILED(hr) )
wxLogApiError(wxS("IFileDialogCustomize::EndVisualGroup"), hr);
}
return new wxFileDialogTextCtrlImplFDC(m_fdc, m_lastId);
}
@@ -459,7 +476,15 @@ public:
private:
wxCOMPtr<IFileDialogCustomize> m_fdc;
// IDs used for the custom controls returned from the public AddXXX()
// functions: they are positive and must be consecutive in order to allow
// accessing the correspond element of m_controls later, see FindControl().
DWORD m_lastId;
// IDs used for any other controls, they're negative (which means they
// decrement from USHORT_MAX down).
DWORD m_lastAuxId;
};
#endif // wxUSE_IFILEOPENDIALOG