Improve support for TABs in wxListBox under MSW
Always set the LB_USETABSTOPS style flag to achieve behaviour more compatible with other platforms and expand TABs to align them at tab stops positioned at every 8 characters. Also add MSW-specific MSWSetTabStops() method allowing to customize tab stops. Update the documentation and the sample to demonstrate using TABs. Closes https://github.com/wxWidgets/wxWidgets/pull/1789
This commit is contained in:
committed by
Vadim Zeitlin
parent
ebe7816516
commit
d1553c63ed
@@ -128,6 +128,10 @@ public:
|
|||||||
// extent of all strings is used. In any case calls InvalidateBestSize()
|
// extent of all strings is used. In any case calls InvalidateBestSize()
|
||||||
virtual void SetHorizontalExtent(const wxString& s = wxEmptyString);
|
virtual void SetHorizontalExtent(const wxString& s = wxEmptyString);
|
||||||
|
|
||||||
|
// This is a wrapper for LB_SETTABSTOPS message and takes tab stops in
|
||||||
|
// dialog units, with the same conventions as LB_SETTABSTOPS uses.
|
||||||
|
virtual bool MSWSetTabStops(const wxVector<int>& tabStops);
|
||||||
|
|
||||||
// Windows callbacks
|
// Windows callbacks
|
||||||
bool MSWCommand(WXUINT param, WXWORD id) wxOVERRIDE;
|
bool MSWCommand(WXUINT param, WXWORD id) wxOVERRIDE;
|
||||||
WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE;
|
WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE;
|
||||||
|
@@ -24,10 +24,7 @@
|
|||||||
performance nor from user interface point of view, for large number of
|
performance nor from user interface point of view, for large number of
|
||||||
items.
|
items.
|
||||||
|
|
||||||
Notice that currently @c TAB characters in list box items text are not
|
Notice that the list box doesn't support control characters other than @c TAB.
|
||||||
handled consistently under all platforms, so they should be replaced by
|
|
||||||
spaces to display strings properly everywhere. The list box doesn't
|
|
||||||
support any other control characters at all.
|
|
||||||
|
|
||||||
@beginStyleTable
|
@beginStyleTable
|
||||||
@style{wxLB_SINGLE}
|
@style{wxLB_SINGLE}
|
||||||
@@ -321,6 +318,28 @@ public:
|
|||||||
*/
|
*/
|
||||||
int GetTopItem() const;
|
int GetTopItem() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
MSW-specific function for setting custom tab stop distances.
|
||||||
|
|
||||||
|
Tab stops are expressed in dialog unit widths, i.e. "quarters of the
|
||||||
|
average character width for the font that is selected into the list
|
||||||
|
box".
|
||||||
|
|
||||||
|
@param tabStops
|
||||||
|
If this argument is empty, tab stops are reset to their default
|
||||||
|
value (every 32 dialog units). If it contains a single element, tab
|
||||||
|
stops are set at each multiple of the given value. Otherwise tab
|
||||||
|
stops are set at every element of the array, which must be in
|
||||||
|
ascending order.
|
||||||
|
|
||||||
|
@return @true if all specified tabs are set, @false otherwise
|
||||||
|
|
||||||
|
@onlyfor{wxmsw}
|
||||||
|
|
||||||
|
@since 3.1.4
|
||||||
|
*/
|
||||||
|
virtual void MSWSetTabStops(const wxVector<int>& tabStops);
|
||||||
|
|
||||||
// NOTE: Phoenix needs to see the implementation of pure virtuals so it
|
// NOTE: Phoenix needs to see the implementation of pure virtuals so it
|
||||||
// knows that this class is not abstract.
|
// knows that this class is not abstract.
|
||||||
virtual unsigned int GetCount() const;
|
virtual unsigned int GetCount() const;
|
||||||
@@ -328,4 +347,3 @@ public:
|
|||||||
virtual void SetString(unsigned int n, const wxString& s);
|
virtual void SetString(unsigned int n, const wxString& s);
|
||||||
virtual int FindString(const wxString& s, bool bCase = false) const;
|
virtual int FindString(const wxString& s, bool bCase = false) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -337,7 +337,7 @@ void ListboxWidgetsPage::CreateContent()
|
|||||||
|
|
||||||
wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
|
wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL);
|
||||||
btn = new wxButton(this, ListboxPage_Add, "&Add this string");
|
btn = new wxButton(this, ListboxPage_Add, "&Add this string");
|
||||||
m_textAdd = new wxTextCtrl(this, ListboxPage_AddText, "test item 0");
|
m_textAdd = new wxTextCtrl(this, ListboxPage_AddText, "test item \t0");
|
||||||
sizerRow->Add(btn, 0, wxRIGHT, 5);
|
sizerRow->Add(btn, 0, wxRIGHT, 5);
|
||||||
sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
|
sizerRow->Add(m_textAdd, 1, wxLEFT, 5);
|
||||||
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5);
|
||||||
@@ -619,7 +619,7 @@ void ListboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event))
|
|||||||
if ( !m_textAdd->IsModified() )
|
if ( !m_textAdd->IsModified() )
|
||||||
{
|
{
|
||||||
// update the default string
|
// update the default string
|
||||||
m_textAdd->SetValue(wxString::Format("test item %u", ++s_item));
|
m_textAdd->SetValue(wxString::Format("test item \t%u", ++s_item));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lbox->Append(s);
|
m_lbox->Append(s);
|
||||||
|
@@ -187,6 +187,9 @@ WXDWORD wxListBox::MSWGetStyle(long style, WXDWORD *exstyle) const
|
|||||||
}
|
}
|
||||||
#endif // wxUSE_OWNER_DRAWN
|
#endif // wxUSE_OWNER_DRAWN
|
||||||
|
|
||||||
|
// tabs stops are expanded by default on linux/GTK and macOS/Cocoa
|
||||||
|
msStyle |= LBS_USETABSTOPS;
|
||||||
|
|
||||||
return msStyle;
|
return msStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,6 +614,12 @@ void wxListBox::SetHorizontalExtent(const wxString& s)
|
|||||||
//else: it shouldn't change
|
//else: it shouldn't change
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxListBox::MSWSetTabStops(const wxVector<int>& tabStops)
|
||||||
|
{
|
||||||
|
return SendMessage(GetHwnd(), LB_SETTABSTOPS, (WPARAM)tabStops.size(),
|
||||||
|
tabStops.size() ? (LPARAM)tabStops.begin() : NULL);
|
||||||
|
}
|
||||||
|
|
||||||
wxSize wxListBox::DoGetBestClientSize() const
|
wxSize wxListBox::DoGetBestClientSize() const
|
||||||
{
|
{
|
||||||
// find the widest string
|
// find the widest string
|
||||||
|
Reference in New Issue
Block a user