From c5cc7fbd27fb53c36beb0ade36153ae48d9e961e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 10 Aug 2009 11:18:09 +0000 Subject: [PATCH] Made wxWindow::HasScrollbar() do what it says. Added wxWindow::CanScroll() with the old HasScrollbar() meaning but changed HasScrollbar() to check for the scrollbar existence instead of just checking if it might exist. Closes #10897. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ include/wx/window.h | 9 ++++++--- interface/wx/window.h | 18 +++++++++++++++++- src/common/wincmn.cpp | 16 +++++++++++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 6a2a7384a7..a3f2ff23e2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -391,6 +391,8 @@ All (GUI): - Added EVT_DATAVIEW_CACHE_HINT() event (Trigve). - Added wxLB_NO_SB style (implemented for MSW only; Dario Senic). - Added long version field to wxAboutDialogInfo (Jeff Tupper). +- Added wxWindow::CanScroll() behaving like the old HasScrollbar() and made + HasScrollbar() really check for the scrollbar existence. GTK: diff --git a/include/wx/window.h b/include/wx/window.h index b481080beb..9d863ee516 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -377,7 +377,7 @@ public: // acceptable size using which it will still look "nice" in // most situations) wxSize GetBestSize() const; - + void GetBestSize(int *w, int *h) const { wxSize s = GetBestSize(); @@ -1160,13 +1160,16 @@ public: // scrollbars // ---------- - // does the window have the scrollbar for this orientation? - bool HasScrollbar(int orient) const + // can the window have the scrollbar in this orientation? + bool CanScroll(int orient) const { return (m_windowStyle & (orient == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL)) != 0; } + // does the window have the scrollbar in this orientation? + bool HasScrollbar(int orient) const; + // configure the window scrollbars virtual void SetScrollbar( int orient, int pos, diff --git a/interface/wx/window.h b/interface/wx/window.h index 7d1f81473c..f14f24f050 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -513,7 +513,23 @@ public: virtual int GetScrollThumb(int orientation) const; /** - Returns @true if this window has a scroll bar for this orientation. + Returns @true if this window can have a scroll bar in this orientation. + + @param orient + Orientation to check, either wxHORIZONTAL or wxVERTICAL. + + @since 2.9.1 + */ + bool CanScroll(int orient) const; + + /** + Returns @true if this window currently has a scroll bar for this + orientation. + + This method may return @false even when CanScroll() for the same + orientation returns @true, but if CanScroll() returns @false, i.e. + scrolling in this direction is not enabled at all, HasScrollbar() + always returns @false as well. @param orient Orientation to check, either wxHORIZONTAL or wxVERTICAL. diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index b337a659e4..d36b727cf0 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -474,7 +474,7 @@ static bool wxHasRealChildren(const wxWindowBase* win) node = node->GetNext() ) { wxWindow *win = node->GetData(); - if ( !win->IsTopLevel() && win->IsShown() + if ( !win->IsTopLevel() && win->IsShown() #if wxUSE_SCROLLBAR && !win->IsKindOf(CLASSINFO(wxScrollBar)) #endif @@ -896,6 +896,20 @@ void wxWindowBase::SendSizeEventToParent(int flags) parent->SendSizeEvent(flags); } +bool wxWindowBase::HasScrollbar(int orient) const +{ + // if scrolling in the given direction is disabled, we can't have the + // corresponding scrollbar no matter what + if ( !CanScroll(orient) ) + return false; + + const wxSize sizeVirt = GetVirtualSize(); + const wxSize sizeClient = GetClientSize(); + + return orient == wxHORIZONTAL ? sizeVirt.x > sizeClient.x + : sizeVirt.y > sizeClient.y; +} + // ---------------------------------------------------------------------------- // show/hide/enable/disable the window // ---------------------------------------------------------------------------- -- 2.47.2