Use list mode in wxListbook list control instead of report.

Use wxLC_LIST instead of wxLC_REPORT when we don't have any icons. This makes
the code simpler as wxLC_LIST is more similar to wxLC_ICON which we used, and
continue to use, when we do have icons, because we don't need to add and
remove any columns on the fly.

And it fixes the appearance of wxListbook without images with wxBK_TOP or
wxBK_BOTTOM styles as it now lays out its items horizontally and not
vertically as before.

It also fixes the best size calculation of wxListbook control since the
changes to wxListCtrl best size calculations in r71733 as a nice side effect.

Closes #14451.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71965 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-07-04 17:09:53 +00:00
parent d68a2a24d1
commit 0f79c83f89
2 changed files with 23 additions and 67 deletions

View File

@@ -88,10 +88,6 @@ protected:
wxBookCtrlEvent* CreatePageChangingEvent() const; wxBookCtrlEvent* CreatePageChangingEvent() const;
void MakeChangedEvent(wxBookCtrlEvent &event); void MakeChangedEvent(wxBookCtrlEvent &event);
// get flags for different list control modes
long GetListCtrlIconViewFlags() const;
long GetListCtrlReportViewFlags() const;
// event handlers // event handlers
void OnListSelected(wxListEvent& event); void OnListSelected(wxListEvent& event);
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);

View File

@@ -38,24 +38,6 @@
#include "wx/sysopt.h" #include "wx/sysopt.h"
namespace
{
// FIXME: This function exists because native OS X wxListCtrl seems to have
// problems with report view, either imperfect display or reported hanging, so
// disable it for now (but it should be fixed, and this function removed).
bool CanUseReportView()
{
#if defined(__WXMAC__) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
if (wxSystemOptions::GetOptionInt(wxMAC_ALWAYS_USE_GENERIC_LISTCTRL) == 0)
return false;
else
#endif
return true;
}
} // anonymous namespace
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// various wxWidgets macros // various wxWidgets macros
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -118,13 +100,10 @@ wxListbook::Create(wxWindow *parent,
wxDefaultPosition, wxDefaultPosition,
wxDefaultSize, wxDefaultSize,
wxLC_SINGLE_SEL | wxLC_SINGLE_SEL |
(CanUseReportView() ? GetListCtrlReportViewFlags() (IsVertical() ? wxLC_ALIGN_LEFT : wxLC_ALIGN_TOP) |
: GetListCtrlIconViewFlags()) wxLC_LIST
); );
if ( CanUseReportView() )
GetListView()->InsertColumn(0, wxT("Pages"));
#ifdef __WXMSW__ #ifdef __WXMSW__
// On XP with themes enabled the GetViewRect used in GetControllerSize() to // On XP with themes enabled the GetViewRect used in GetControllerSize() to
// determine the space needed for the list view will incorrectly return // determine the space needed for the list view will incorrectly return
@@ -138,20 +117,6 @@ wxListbook::Create(wxWindow *parent,
return true; return true;
} }
// ----------------------------------------------------------------------------
// wxListCtrl flags
// ----------------------------------------------------------------------------
long wxListbook::GetListCtrlIconViewFlags() const
{
return (IsVertical() ? wxLC_ALIGN_LEFT : wxLC_ALIGN_TOP) | wxLC_ICON;
}
long wxListbook::GetListCtrlReportViewFlags() const
{
return wxLC_REPORT | wxLC_NO_HEADER;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxListbook geometry management // wxListbook geometry management
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -259,39 +224,34 @@ bool wxListbook::SetPageImage(size_t n, int imageId)
void wxListbook::SetImageList(wxImageList *imageList) void wxListbook::SetImageList(wxImageList *imageList)
{ {
if ( CanUseReportView() ) wxListView * const list = GetListView();
// If imageList presence has changed, we update the list control style
if ( (imageList != NULL) != (GetImageList() != NULL) )
{ {
wxListView * const list = GetListView(); // Preserve the selection which is lost when changing the mode
const int oldSel = GetSelection();
// If imageList presence has changed, we update the list control view // Update the style to use icon view for images, list view otherwise
if ( (imageList != NULL) != (GetImageList() != NULL) ) long style = list->GetWindowStyle() & ~wxLC_MASK_TYPE;
if ( imageList )
{ {
// Preserve the selection which is lost when changing the mode style |= wxLC_ICON;
const int oldSel = GetSelection(); }
else // no image list
// Update the style to use icon view for images, report view otherwise {
long style = wxLC_SINGLE_SEL; style |= wxLC_LIST;
if ( imageList )
{
style |= GetListCtrlIconViewFlags();
}
else // no image list
{
style |= GetListCtrlReportViewFlags();
}
list->SetWindowStyleFlag(style);
if ( !imageList )
list->InsertColumn(0, wxT("Pages"));
// Restore selection
if ( oldSel != wxNOT_FOUND )
SetSelection(oldSel);
} }
list->SetImageList(imageList, wxIMAGE_LIST_NORMAL); list->SetWindowStyleFlag(style);
// Restore selection
if ( oldSel != wxNOT_FOUND )
SetSelection(oldSel);
} }
list->SetImageList(imageList, wxIMAGE_LIST_NORMAL);
wxBookCtrlBase::SetImageList(imageList); wxBookCtrlBase::SetImageList(imageList);
} }