void wxListbook::SetImageList(wxImageList *imageList) { wxListView * const list = GetListView(); #ifdef CAN_USE_REPORT_VIEW // If imageList presence has changed, we update the list control view if ( (imageList != NULL) != (GetImageList() != NULL) ) { wxArrayString labels; labels.Alloc(GetPageCount()); wxArrayInt imageIds; imageIds.Alloc(GetPageCount()); const int oldSel = GetSelection(); size_t i; // Grab snapshot of all list control items before changing the window // style (which deletes the items) for ( i = 0; i < GetPageCount(); i++ ) { labels.Add(GetPageText(i)); imageIds.Add(GetPageImage(i)); } // Update the style to use icon view for images, report view otherwise long style = wxLC_SINGLE_SEL; if ( imageList ) { style |= GetListCtrlIconViewFlags(); } else // no image list { style |= GetListCtrlReportViewFlags(); } list->SetWindowStyleFlag(style); if ( !imageList ) list->InsertColumn(0, wxT("Pages")); // Add back the list control items for ( i = 0; i < GetPageCount(); i++ ) { list->InsertItem(i, labels[i], imageIds[i]); } // Restore selection if ( oldSel != wxNOT_FOUND ) SetSelection(oldSel); } list->SetImageList(imageList, wxIMAGE_LIST_NORMAL); #endif // CAN_USE_REPORT_VIEW wxBookCtrlBase::SetImageList(imageList); }
bool wxListbook::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) { #ifdef __WXMAC__ style |= wxBK_TOP; #else // !__WXMAC__ style |= wxBK_LEFT; #endif // __WXMAC__/!__WXMAC__ } // no border for this control, it doesn't look nice together with // wxListCtrl border style &= ~wxBORDER_MASK; style |= wxBORDER_NONE; if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; m_bookctrl = new wxListView ( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_SINGLE_SEL | #ifdef CAN_USE_REPORT_VIEW GetListCtrlReportViewFlags() #else // !CAN_USE_REPORT_VIEW GetListCtrlIconViewFlags() #endif // CAN_USE_REPORT_VIEW/!CAN_USE_REPORT_VIEW ); #ifdef CAN_USE_REPORT_VIEW GetListView()->InsertColumn(0, wxT("Pages")); #endif // CAN_USE_REPORT_VIEW #ifdef __WXMSW__ // On XP with themes enabled the GetViewRect used in GetControllerSize() to // determine the space needed for the list view will incorrectly return // (0,0,0,0) the first time. So send a pending event so OnSize will be // called again after the window is ready to go. Technically we don't // need to do this on non-XP windows, but if things are already sized // correctly then nothing changes and so there is no harm. wxSizeEvent evt; GetEventHandler()->AddPendingEvent(evt); #endif return true; }
void wxListbook::SetImageList(wxImageList *imageList) { #ifdef CAN_USE_REPORT_VIEW wxListView * const list = GetListView(); // If imageList presence has changed, we update the list control view if ( (imageList != NULL) != (GetImageList() != NULL) ) { // Preserve the selection which is lost when changing the mode const int oldSel = GetSelection(); // Update the style to use icon view for images, report view otherwise long style = wxLC_SINGLE_SEL; 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); #endif // CAN_USE_REPORT_VIEW wxBookCtrlBase::SetImageList(imageList); }