]> git.saurik.com Git - wxWidgets.git/commitdiff
add wxScrollHelper::ShowScrollbars() (implemented for GTK only right now, generic...
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Dec 2008 15:58:37 +0000 (15:58 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 24 Dec 2008 15:58:37 +0000 (15:58 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57529 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/gtk/scrolwin.h
include/wx/scrolwin.h
interface/wx/scrolwin.h
samples/scroll/scroll.cpp
src/generic/scrlwing.cpp
src/gtk/scrolwin.cpp

index ecd68c800d911144b655466ad5794a9f28fdfd52..45835577772c07fd9c0bd4aff326a4c4a185f19e 100644 (file)
@@ -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).
index facf1d2b49fff5f7450eb013558f7e4b120e8b01..7b4d75c00e71a9b5d6fce5922b55da5242a71557 100644 (file)
@@ -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)
index 4ef5499dac9de9685a80063e9f8a4345b0011d35..d85a167eb65211c72d87e3565ed5172caf65d128 100644 (file)
@@ -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())
index b3664bee2ef805e7cbd96d48507486aaaeb8f90d..3c55bd704a3e1e99c163d3dd4b407e11491c032c 100644 (file)
@@ -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
index 2186f19bbcbd0b96bf6c1e6cb054e44509b57c6c..efbfb37479600cb51f590956b09dbd4b90a055d4 100644 (file)
@@ -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);
index c393f20e6ddd8cbbc68a9a4b54eacaf58d5d719c..19cb186145e1d2422dc580431d77eba0cdb6cfd7 100644 (file)
@@ -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
 {
index 0447f58d42ed14f9abb5add5e78fb14fcca4416c..e7de2bf53da0f2b054bdbec551ddf126f50d4d80 100644 (file)
@@ -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));
+}
+