From: Peter Cawley Date: Sat, 6 Nov 2010 23:46:25 +0000 (+0000) Subject: Improve behaviour of scrolling through a ribbon gallery. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/32eb560338fa702c61544c8c1a01d8ca9812b2f3 Improve behaviour of scrolling through a ribbon gallery. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/ribbon/gallery.h b/include/wx/ribbon/gallery.h index 6916be51fc..01d89841e5 100644 --- a/include/wx/ribbon/gallery.h +++ b/include/wx/ribbon/gallery.h @@ -69,6 +69,7 @@ public: virtual bool Layout(); virtual bool ScrollLines(int lines); + bool ScrollPixels(int pixels); void EnsureVisible(const wxRibbonGalleryItem* item); protected: @@ -84,8 +85,10 @@ protected: void OnMouseLeave(wxMouseEvent& evt); void OnMouseDown(wxMouseEvent& evt); void OnMouseUp(wxMouseEvent& evt); + void OnMouseDClick(wxMouseEvent& evt); void OnPaint(wxPaintEvent& evt); void OnSize(wxSizeEvent& evt); + int GetScrollLineSize() const; virtual wxSize DoGetBestSize() const; virtual wxSize DoGetNextSmallerSize(wxOrientation direction, diff --git a/interface/wx/ribbon/gallery.h b/interface/wx/ribbon/gallery.h index eb2b01938f..51edca8784 100644 --- a/interface/wx/ribbon/gallery.h +++ b/interface/wx/ribbon/gallery.h @@ -239,6 +239,18 @@ public: direction, @false if it did not scroll. */ virtual bool ScrollLines(int lines); + + /** + Scroll the gallery contents by some fine-grained amount. + + @param pixels + Positive values scroll toward the end of the gallery, while negative + values scroll toward the start. + + @return @true if the gallery scrolled at least one pixel in the given + direction, @false if it did not scroll. + */ + bool ScrollPixels(int pixels); /** Scroll the gallery to ensure that the given item is visible. diff --git a/src/ribbon/gallery.cpp b/src/ribbon/gallery.cpp index 6d7c300e92..a671a3a880 100644 --- a/src/ribbon/gallery.cpp +++ b/src/ribbon/gallery.cpp @@ -76,6 +76,7 @@ BEGIN_EVENT_TABLE(wxRibbonGallery, wxRibbonControl) EVT_LEAVE_WINDOW(wxRibbonGallery::OnMouseLeave) EVT_LEFT_DOWN(wxRibbonGallery::OnMouseDown) EVT_LEFT_UP(wxRibbonGallery::OnMouseUp) + EVT_LEFT_DCLICK(wxRibbonGallery::OnMouseDClick) EVT_MOTION(wxRibbonGallery::OnMouseMove) EVT_PAINT(wxRibbonGallery::OnPaint) EVT_SIZE(wxRibbonGallery::OnSize) @@ -372,6 +373,15 @@ void wxRibbonGallery::OnMouseUp(wxMouseEvent& evt) } } +void wxRibbonGallery::OnMouseDClick(wxMouseEvent& evt) +{ + // The 2nd click of a double-click should be handled as a click in the + // same way as the 1st click of the double-click. This is useful for + // scrolling through the gallery. + OnMouseDown(evt); + OnMouseUp(evt); +} + void wxRibbonGallery::SetItemClientObject(wxRibbonGalleryItem* itm, wxClientData* data) { @@ -398,14 +408,31 @@ bool wxRibbonGallery::ScrollLines(int lines) if(m_scroll_limit == 0 || m_art == NULL) return false; + return ScrollPixels(lines * GetScrollLineSize()); +} + +int wxRibbonGallery::GetScrollLineSize() const +{ + if(m_art == NULL) + return 32; + int line_size = m_bitmap_padded_size.GetHeight(); if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL) line_size = m_bitmap_padded_size.GetWidth(); - if(lines < 0) + + return line_size; +} + +bool wxRibbonGallery::ScrollPixels(int pixels) +{ + if(m_scroll_limit == 0 || m_art == NULL) + return false; + + if(pixels < 0) { if(m_scroll_amount > 0) { - m_scroll_amount += lines * line_size; + m_scroll_amount += pixels; if(m_scroll_amount <= 0) { m_scroll_amount = 0; @@ -418,11 +445,11 @@ bool wxRibbonGallery::ScrollLines(int lines) return true; } } - else if(lines > 0) + else if(pixels > 0) { if(m_scroll_amount < m_scroll_limit) { - m_scroll_amount += lines * line_size; + m_scroll_amount += pixels; if(m_scroll_amount >= m_scroll_limit) { m_scroll_amount = m_scroll_limit;