diff --git a/include/wx/msw/listbox.h b/include/wx/msw/listbox.h index 3c910e325e..78e310b306 100644 --- a/include/wx/msw/listbox.h +++ b/include/wx/msw/listbox.h @@ -128,6 +128,10 @@ public: // extent of all strings is used. In any case calls InvalidateBestSize() 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& tabStops); + // Windows callbacks bool MSWCommand(WXUINT param, WXWORD id) wxOVERRIDE; WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE; diff --git a/interface/wx/listbox.h b/interface/wx/listbox.h index 53c07ddab1..5239107ff9 100644 --- a/interface/wx/listbox.h +++ b/interface/wx/listbox.h @@ -24,10 +24,7 @@ performance nor from user interface point of view, for large number of items. - Notice that currently @c TAB characters in list box items text are not - 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. + Notice that the list box doesn't support control characters other than @c TAB. @beginStyleTable @style{wxLB_SINGLE} @@ -321,6 +318,28 @@ public: */ 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& tabStops); + // NOTE: Phoenix needs to see the implementation of pure virtuals so it // knows that this class is not abstract. virtual unsigned int GetCount() const; @@ -328,4 +347,3 @@ public: virtual void SetString(unsigned int n, const wxString& s); virtual int FindString(const wxString& s, bool bCase = false) const; }; - diff --git a/samples/widgets/listbox.cpp b/samples/widgets/listbox.cpp index 2ab069a397..8e87f5c3cd 100644 --- a/samples/widgets/listbox.cpp +++ b/samples/widgets/listbox.cpp @@ -337,7 +337,7 @@ void ListboxWidgetsPage::CreateContent() wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL); 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(m_textAdd, 1, wxLEFT, 5); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); @@ -619,7 +619,7 @@ void ListboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event)) if ( !m_textAdd->IsModified() ) { // 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); diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 128f679d2c..f8b0d19a95 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -187,6 +187,9 @@ WXDWORD wxListBox::MSWGetStyle(long style, WXDWORD *exstyle) const } #endif // wxUSE_OWNER_DRAWN + // tabs stops are expanded by default on linux/GTK and macOS/Cocoa + msStyle |= LBS_USETABSTOPS; + return msStyle; } @@ -611,6 +614,12 @@ void wxListBox::SetHorizontalExtent(const wxString& s) //else: it shouldn't change } +bool wxListBox::MSWSetTabStops(const wxVector& tabStops) +{ + return SendMessage(GetHwnd(), LB_SETTABSTOPS, (WPARAM)tabStops.size(), + tabStops.size() ? (LPARAM)tabStops.begin() : NULL); +} + wxSize wxListBox::DoGetBestClientSize() const { // find the widest string