From: Vadim Zeitlin Date: Wed, 24 Dec 2008 15:58:37 +0000 (+0000) Subject: add wxScrollHelper::ShowScrollbars() (implemented for GTK only right now, generic... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6362d82b3ed82aa6795e4ad03160820f94c9e4d4 add wxScrollHelper::ShowScrollbars() (implemented for GTK only right now, generic implementation coming soon) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57529 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index ecd68c800d..4583557777 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -343,6 +343,7 @@ All (GUI): - Added wxWrapSizer (Arne Steinarson). - Added wxSpinCtrlDouble (John Labenski). - Support custom labels in wxMessageDialog (Gareth Simpson for wxMac version). +- Added wxScrolledWindow::ShowScrollbars(). - Also added wxCANCEL_DEFAULT to wxMessageDialog. - Allow copying text in the log dialogs. - Added multisample (anti-aliasing) support to wxGLCanvas (Olivier Playez). diff --git a/include/wx/gtk/scrolwin.h b/include/wx/gtk/scrolwin.h index facf1d2b49..7b4d75c00e 100644 --- a/include/wx/gtk/scrolwin.h +++ b/include/wx/gtk/scrolwin.h @@ -64,7 +64,10 @@ protected: int pixelsPerLine, int *posOld); + // implement the base class methods virtual void DoScroll(int x, int y); + virtual void DoShowScrollbars(wxScrollbarVisibility horz, + wxScrollbarVisibility vert); private: DECLARE_NO_COPY_CLASS(wxScrollHelperNative) diff --git a/include/wx/scrolwin.h b/include/wx/scrolwin.h index 4ef5499dac..d85a167eb6 100644 --- a/include/wx/scrolwin.h +++ b/include/wx/scrolwin.h @@ -20,6 +20,14 @@ class WXDLLIMPEXP_FWD_BASE wxTimer; // default scrolled window style: scroll in both directions #define wxScrolledWindowStyle (wxHSCROLL | wxVSCROLL) +// values for the second argument of wxScrollHelper::ShowScrollbars() +enum wxScrollbarVisibility +{ + wxSHOW_SB_NEVER = -1, // never show the scrollbar at all + wxSHOW_SB_DEFAULT, // show scrollbar only if it is needed + wxSHOW_SB_ALWAYS // always show scrollbar, even if not needed +}; + // ---------------------------------------------------------------------------- // The hierarchy of scrolling classes is a bit complicated because we want to // put as much functionality as possible in a mix-in class not deriving from @@ -80,6 +88,13 @@ public: virtual void GetScrollPixelsPerUnit(int *pixelsPerUnitX, int *pixelsPerUnitY) const; + // Set scrollbar visibility: it is possible to show scrollbar only if it is + // needed (i.e. if our virtual size is greater than the current size of the + // associated window), always (as wxALWAYS_SHOW_SB style does) or never (in + // which case you should provide some other way to scroll the window as the + // user wouldn't be able to do it at all) + void ShowScrollbars(wxScrollbarVisibility horz, wxScrollbarVisibility vert); + // Enable/disable Windows scrolling in either direction. If true, wxWidgets // scrolls the canvas and only a bit of the canvas is invalidated; no // Clear() is necessary. If false, the whole canvas is invalidated and a @@ -202,6 +217,8 @@ protected: // implementation of public methods with the same name virtual void DoGetViewStart(int *x, int *y) const; virtual void DoScroll(int x, int y); + virtual void DoShowScrollbars(wxScrollbarVisibility horz, + wxScrollbarVisibility vert); // implementations of various wxWindow virtual methods which should be // forwarded to us (this can be done by WX_FORWARD_TO_SCROLL_HELPER()) diff --git a/interface/wx/scrolwin.h b/interface/wx/scrolwin.h index b3664bee2e..3c55bd704a 100644 --- a/interface/wx/scrolwin.h +++ b/interface/wx/scrolwin.h @@ -6,6 +6,16 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +/** + Possible values for the second argument of wxScrolled::ShowScrollbars(). + */ +enum wxScrollbarVisibility +{ + wxSHOW_SB_NEVER = -1, ///< Never show the scrollbar at all. + wxSHOW_SB_DEFAULT, ///< Show scrollbar only if it is needed. + wxSHOW_SB_ALWAYS ///< Always show scrollbar, even if not needed. +}; + /** The wxScrolled class manages scrolling for its client area, transforming @@ -237,6 +247,32 @@ public: */ void EnableScrolling(bool xScrolling, bool yScrolling); + /** + Set the scrollbar visibility. + + By default the scrollbar in the corresponding direction is only shown + if it is needed, i.e. if the virtual size of the scrolled window in + this direction is greater than the current physical window size. Using + this function the scrollbar visibility can be changed to be: + - wxSHOW_SB_ALWAYS: To always show the scrollbar, even if it is + not needed currently (wxALWAYS_SHOW_SB style can be used during + the window creation to achieve the same effect but it applies + in both directions). + - wxSHOW_SB_NEVER: To never show the scrollbar at all. In this case + the program should presumably provide some other way for the + user to scroll the window. + - wxSHOW_SB_DEFAULT: To restore the default behaviour described + above. + + @param horz + The desired visibility for the horizontal scrollbar. + @param vert + The desired visibility for the vertical scrollbar. + + @since 2.9.0 + */ + void ShowScrollbars(wxScrollbarVisibility horz, wxScrollbarVisibility vert); + /** Get the number of pixels per scroll unit (line), in each direction, as set by SetScrollbars(). A value of zero indicates no scrolling in that diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 2186f19bbc..efbfb37479 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -621,6 +621,7 @@ private: void OnTestAuto(wxCommandEvent& WXUNUSED(event)) { new MyAutoFrame(this); } void OnToggleSync(wxCommandEvent& event); + void OnToggleScrollbar(wxCommandEvent& event); MyScrolledWindowBase *m_win1, *m_win2; @@ -834,6 +835,7 @@ const wxWindowID Scroll_Test_Sub = wxWindow::NewControlId(); const wxWindowID Scroll_Test_Auto = wxWindow::NewControlId(); const wxWindowID Scroll_TglBtn_Sync = wxWindow::NewControlId(); +const wxWindowID Scroll_TglBtn_Scrollbar = wxWindow::NewControlId(); BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) @@ -846,6 +848,7 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame) EVT_MENU(Scroll_Test_Auto, MyFrame::OnTestAuto) EVT_TOGGLEBUTTON(Scroll_TglBtn_Sync, MyFrame::OnToggleSync) + EVT_TOGGLEBUTTON(Scroll_TglBtn_Scrollbar, MyFrame::OnToggleScrollbar) END_EVENT_TABLE() MyFrame::MyFrame() @@ -896,8 +899,16 @@ MyFrame::MyFrame() sizerScrollWin->Add(m_win2, flagsExpand); topsizer->Add(sizerScrollWin, flagsExpand); + const wxSizerFlags flagsHBorder(wxSizerFlags().Border(wxLEFT | wxRIGHT)); + wxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL); - sizerBtns->Add(new wxToggleButton(this, Scroll_TglBtn_Sync, "&Synchronize")); + sizerBtns->Add(new wxToggleButton(this, Scroll_TglBtn_Sync, "S&ynchronize"), + flagsHBorder); + + wxToggleButton *btn =new wxToggleButton(this, Scroll_TglBtn_Scrollbar, + "&Show scrollbar"); + btn->SetValue(true); + sizerBtns->Add(btn, flagsHBorder); topsizer->Add(sizerBtns, wxSizerFlags().Centre().Border()); SetSizer(topsizer); @@ -920,6 +931,13 @@ void MyFrame::OnToggleSync(wxCommandEvent& event) } } +void MyFrame::OnToggleScrollbar(wxCommandEvent& event) +{ + m_win1->ShowScrollbars(wxSHOW_SB_NEVER, + event.IsChecked() ? wxSHOW_SB_ALWAYS + : wxSHOW_SB_NEVER); +} + void MyFrame::OnQuit(wxCommandEvent &WXUNUSED(event)) { Close(true); diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index c393f20e6d..19cb186145 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -972,6 +972,18 @@ void wxScrollHelper::EnableScrolling (bool x_scroll, bool y_scroll) m_yScrollingEnabled = y_scroll; } +void wxScrollHelper::ShowScrollbars(wxScrollbarVisibility horz, + wxScrollbarVisibility vert) +{ + DoShowScrollbars(horz, vert); +} + +void wxScrollHelper::DoShowScrollbars(wxScrollbarVisibility horz, + wxScrollbarVisibility vert) +{ + // TODO +} + // Where the current view starts from void wxScrollHelper::DoGetViewStart (int *x, int *y) const { diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index 0447f58d42..e7de2bf53d 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -188,3 +188,45 @@ void wxScrollHelperNative::DoScroll( int x_pos, int y_pos ) DoScrollOneDir(wxHORIZONTAL, x_pos, m_xScrollPixelsPerLine, &m_xScrollPosition); DoScrollOneDir(wxVERTICAL, y_pos, m_yScrollPixelsPerLine, &m_yScrollPosition); } + +// ---------------------------------------------------------------------------- +// scrollbars visibility +// ---------------------------------------------------------------------------- + +namespace +{ + +GtkPolicyType GtkPolicyFromWX(wxScrollbarVisibility visibility) +{ + GtkPolicyType policy; + switch ( visibility ) + { + case wxSHOW_SB_NEVER: + policy = GTK_POLICY_NEVER; + break; + + case wxSHOW_SB_DEFAULT: + policy = GTK_POLICY_AUTOMATIC; + break; + + case wxSHOW_SB_ALWAYS: + policy = GTK_POLICY_ALWAYS; + break; + } + + return policy; +} + +} // anonymous namespace + +void wxScrollHelperNative::DoShowScrollbars(wxScrollbarVisibility horz, + wxScrollbarVisibility vert) +{ + GtkScrolledWindow * const scrolled = GTK_SCROLLED_WINDOW(m_win->m_widget); + wxCHECK_RET( scrolled, "window must be created" ); + + gtk_scrolled_window_set_policy(scrolled, + GtkPolicyFromWX(horz), + GtkPolicyFromWX(vert)); +} +