X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3f0785de9a320f558b13f9f46b5f6356180578c1..ff2baa25d5dbac5e5181a6f7d49779c399c037a3:/src/generic/listbkg.cpp?ds=sidebyside diff --git a/src/generic/listbkg.cpp b/src/generic/listbkg.cpp index 3fc2953c17..508474d08c 100644 --- a/src/generic/listbkg.cpp +++ b/src/generic/listbkg.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "listbook.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -36,14 +32,6 @@ #include "wx/imaglist.h" #include "wx/settings.h" -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -// margin between the list and the page, should be bigger than wxStaticLine -// size -const wxCoord MARGIN = 5; - // ---------------------------------------------------------------------------- // various wxWidgets macros // ---------------------------------------------------------------------------- @@ -62,7 +50,7 @@ const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING = wxNewEventType(); const wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED = wxNewEventType(); const int wxID_LISTBOOKLISTVIEW = wxNewId(); -BEGIN_EVENT_TABLE(wxListbook, wxBookCtrl) +BEGIN_EVENT_TABLE(wxListbook, wxBookCtrlBase) EVT_SIZE(wxListbook::OnSize) EVT_LIST_ITEM_SELECTED(wxID_LISTBOOKLISTVIEW, wxListbook::OnListSelected) END_EVENT_TABLE() @@ -134,7 +122,7 @@ wxListbook::Create(wxWindow *parent, #ifdef __WXMSW__ // On XP with themes enabled the GetViewRect used in GetListSize 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 wiull be + // (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. @@ -151,7 +139,8 @@ wxListbook::Create(wxWindow *parent, wxSize wxListbook::GetListSize() const { const wxSize sizeClient = GetClientSize(), - sizeList = m_list->GetViewRect().GetSize(); + sizeBorder = m_list->GetSize() - m_list->GetClientSize(), + sizeList = m_list->GetViewRect().GetSize() + sizeBorder; wxSize size; if ( IsVertical() ) @@ -172,7 +161,7 @@ wxRect wxListbook::GetPageRect() const { const wxSize sizeList = m_list->GetSize(); - wxPoint pt(0, 0); + wxPoint pt; wxRect rectPage(pt, GetClientSize()); switch ( GetWindowStyle() & wxLB_ALIGN_MASK ) { @@ -181,19 +170,19 @@ wxRect wxListbook::GetPageRect() const // fall through case wxLB_TOP: - rectPage.y = sizeList.y + MARGIN; + rectPage.y = sizeList.y + GetInternalBorder(); // fall through case wxLB_BOTTOM: - rectPage.height -= sizeList.y + MARGIN; + rectPage.height -= sizeList.y + GetInternalBorder(); break; case wxLB_LEFT: - rectPage.x = sizeList.x + MARGIN; + rectPage.x = sizeList.x + GetInternalBorder(); // fall through case wxLB_RIGHT: - rectPage.width -= sizeList.x + MARGIN; + rectPage.width -= sizeList.x + GetInternalBorder(); break; } @@ -210,10 +199,21 @@ void wxListbook::OnSize(wxSizeEvent& event) return; } + // arrange the icons before calling SetClientSize(), otherwise it wouldn't + // account for the scrollbars the list control might need and, at least + // under MSW, we'd finish with an ugly looking list control with both + // vertical and horizontal scrollbar (with one of them being added because + // the other one is not accounted for in client size computations) + m_list->Arrange(); + // resize the list control and the page area to fit inside our new size const wxSize sizeClient = GetClientSize(), + sizeBorder = m_list->GetSize() - m_list->GetClientSize(), sizeList = GetListSize(); + m_list->SetClientSize( sizeList.x - sizeBorder.x, sizeList.y - sizeBorder.y ); + + const wxSize sizeNew = m_list->GetSize(); wxPoint posList; switch ( GetWindowStyle() & wxLB_ALIGN_MASK ) { @@ -227,16 +227,16 @@ void wxListbook::OnSize(wxSizeEvent& event) break; case wxLB_BOTTOM: - posList.y = sizeClient.y - sizeList.y; + posList.y = sizeClient.y - sizeNew.y; break; case wxLB_RIGHT: - posList.x = sizeClient.x - sizeList.x; + posList.x = sizeClient.x - sizeNew.x; break; } - m_list->Move(posList.x, posList.y); - m_list->SetClientSize(sizeList.x, sizeList.y); + if ( m_list->GetPosition() != posList ) + m_list->Move(posList); #if wxUSE_LINE_IN_LISTBOOK if ( m_line ) @@ -246,23 +246,23 @@ void wxListbook::OnSize(wxSizeEvent& event) switch ( GetWindowStyle() & wxLB_ALIGN_MASK ) { case wxLB_TOP: - rectLine.y = sizeList.y + 1; - rectLine.height = MARGIN - 2; + rectLine.y = sizeNew.y + 1; + rectLine.height = GetInternalBorder() - 2; break; case wxLB_BOTTOM: - rectLine.height = MARGIN - 2; - rectLine.y = sizeClient.y - sizeList.y - rectLine.height; + rectLine.height = GetInternalBorder() - 2; + rectLine.y = sizeClient.y - sizeNew.y - rectLine.height; break; case wxLB_LEFT: - rectLine.x = sizeList.x + 1; - rectLine.width = MARGIN - 2; + rectLine.x = sizeNew.x + 1; + rectLine.width = GetInternalBorder() - 2; break; case wxLB_RIGHT: - rectLine.width = MARGIN - 2; - rectLine.x = sizeClient.x - sizeList.x - rectLine.width; + rectLine.width = GetInternalBorder() - 2; + rectLine.x = sizeClient.x - sizeNew.x - rectLine.width; break; } @@ -276,22 +276,22 @@ void wxListbook::OnSize(wxSizeEvent& event) wxWindow *page = m_pages[m_selection]; wxCHECK_RET( page, _T("NULL page in wxListbook?") ); page->SetSize(GetPageRect()); - } + } } wxSize wxListbook::CalcSizeFromPage(const wxSize& sizePage) const { - // we need to add the size of the list control and the margin + // we need to add the size of the list control and the border between const wxSize sizeList = GetListSize(); wxSize size = sizePage; if ( IsVertical() ) { - size.y += sizeList.y + MARGIN; + size.y += sizeList.y + GetInternalBorder(); } else // left/right aligned { - size.x += sizeList.x + MARGIN; + size.x += sizeList.x + GetInternalBorder(); } return size; @@ -318,7 +318,7 @@ int wxListbook::GetPageImage(size_t WXUNUSED(n)) const { wxFAIL_MSG( _T("wxListbook::GetPageImage() not implemented") ); - return -1; + return wxNOT_FOUND; } bool wxListbook::SetPageImage(size_t n, int imageId) @@ -334,7 +334,7 @@ void wxListbook::SetImageList(wxImageList *imageList) { m_list->SetImageList(imageList, wxIMAGE_LIST_NORMAL); - wxBookCtrl::SetImageList(imageList); + wxBookCtrlBase::SetImageList(imageList); } // ---------------------------------------------------------------------------- @@ -393,7 +393,7 @@ wxListbook::InsertPage(size_t n, bool bSelect, int imageId) { - if ( !wxBookCtrl::InsertPage(n, page, text, bSelect, imageId) ) + if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) ) return false; m_list->InsertItem(n, text, imageId); @@ -423,13 +423,14 @@ wxListbook::InsertPage(size_t n, SetSelection(selNew); InvalidateBestSize(); + m_list->Arrange(); return true; } wxWindow *wxListbook::DoRemovePage(size_t page) { - const int page_count = GetPageCount(); - wxWindow *win = wxBookCtrl::DoRemovePage(page); + const size_t page_count = GetPageCount(); + wxWindow *win = wxBookCtrlBase::DoRemovePage(page); if ( win ) { @@ -450,6 +451,8 @@ wxWindow *wxListbook::DoRemovePage(size_t page) if ((sel != wxNOT_FOUND) && (sel != m_selection)) SetSelection(sel); } + + m_list->Arrange(); } return win; @@ -459,7 +462,7 @@ wxWindow *wxListbook::DoRemovePage(size_t page) bool wxListbook::DeleteAllPages() { m_list->DeleteAllItems(); - return wxBookCtrl::DeleteAllPages(); + return wxBookCtrlBase::DeleteAllPages(); } // ---------------------------------------------------------------------------- @@ -489,4 +492,3 @@ void wxListbook::OnListSelected(wxListEvent& eventList) } #endif // wxUSE_LISTBOOK -