[haiku-commits] r41179 - haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview

  • From: superstippi@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 4 Apr 2011 11:25:08 +0200 (CEST)

Author: stippi
Date: 2011-04-04 11:25:07 +0200 (Mon, 04 Apr 2011)
New Revision: 41179
Changeset: https://dev.haiku-os.org/changeset/41179

Modified:
   haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.cpp
   haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.h
Log:
 * Exposed ValidScrollOffsetFor() as public method.
 * Make validating the scroll offset in SetDataRect() optional.
 * Introduced SetDataRectAndScrollOffset() to set both atomically.
   This avoids some unwanted feedback when having to set them
   both anyway, but hook methods are called and re-enter back into
   the client code.


Modified: 
haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.cpp
===================================================================
--- haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.cpp     
2011-04-04 09:21:43 UTC (rev 41178)
+++ haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.cpp     
2011-04-04 09:25:07 UTC (rev 41179)
@@ -1,9 +1,6 @@
 /*
- * Copyright 2006, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- *             Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
+ * Copyright 2001-2009, Ingo Weinhold <ingo_weinhold@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT license.
  */
 
 #include "Scrollable.h"
@@ -13,8 +10,6 @@
 
 #include "Scroller.h"
 
-using namespace std;
-
 // constructor
 Scrollable::Scrollable()
        : fDataRect(0.0, 0.0, 0.0, 0.0),
@@ -67,7 +62,7 @@
 //
 // Sets the data rect.
 void
-Scrollable::SetDataRect(BRect dataRect)
+Scrollable::SetDataRect(BRect dataRect, bool validateScrollOffset)
 {
        if (fDataRect != dataRect && dataRect.IsValid()) {
                BRect oldDataRect = fDataRect;
@@ -78,9 +73,11 @@
                if (fScrollSource)
                        fScrollSource->DataRectChanged(oldDataRect, fDataRect);
                // adjust the scroll offset, if necessary
-               BPoint offset = _ValidScrollOffsetFor(fScrollOffset);
-               if (offset != fScrollOffset)
-                       SetScrollOffset(offset);
+               if (validateScrollOffset) {
+                       BPoint offset = ValidScrollOffsetFor(fScrollOffset);
+                       if (offset != fScrollOffset)
+                               SetScrollOffset(offset);
+               }
        }
 }
 
@@ -100,7 +97,7 @@
 Scrollable::SetScrollOffset(BPoint offset)
 {
        // adjust the supplied offset to be valid
-       offset = _ValidScrollOffsetFor(offset);
+       offset = ValidScrollOffsetFor(offset);
        if (fScrollOffset != offset) {
                BPoint oldOffset = fScrollOffset;
                fScrollOffset = offset;
@@ -121,6 +118,62 @@
        return fScrollOffset;
 }
 
+// SetDataRect
+//
+// Sets the data rect.
+void
+Scrollable::SetDataRectAndScrollOffset(BRect dataRect, BPoint offset)
+{
+       if (fDataRect != dataRect && dataRect.IsValid()) {
+
+               BRect oldDataRect = fDataRect;
+               fDataRect = dataRect;
+               // notify ourselves
+               DataRectChanged(oldDataRect, fDataRect);
+               // notify scroller
+               if (fScrollSource) {
+                       fScrollSource->SetScrollingEnabled(false);
+                       fScrollSource->DataRectChanged(oldDataRect, fDataRect);
+               }
+               // adjust the scroll offset, if necessary
+               offset = ValidScrollOffsetFor(offset);
+               if (offset != fScrollOffset)
+                       SetScrollOffset(offset);
+
+               if (fScrollSource)
+                       fScrollSource->SetScrollingEnabled(true);
+       }
+}
+
+// ValidScrollOffsetFor
+//
+// Returns the valid scroll offset next to the supplied offset.
+BPoint
+Scrollable::ValidScrollOffsetFor(BPoint offset) const
+{
+       return ValidScrollOffsetFor(offset, fDataRect);
+}
+
+// ValidScrollOffsetFor
+//
+// Returns the valid scroll offset next to the supplied offset.
+BPoint
+Scrollable::ValidScrollOffsetFor(BPoint offset, const BRect& dataRect) const
+{
+       float maxX = max_c(dataRect.left, dataRect.right - fVisibleWidth);
+       float maxY = max_c(dataRect.top, dataRect.bottom - fVisibleHeight);
+       // adjust the offset to be valid
+       if (offset.x < dataRect.left)
+               offset.x = dataRect.left;
+       else if (offset.x > maxX)
+               offset.x = maxX;
+       if (offset.y < dataRect.top)
+               offset.y = dataRect.top;
+       else if (offset.y > maxY)
+               offset.y = maxY;
+       return offset;
+}
+
 // SetVisibleSize
 //
 // Sets the visible size.
@@ -141,7 +194,7 @@
                                                                                
          fVisibleWidth, fVisibleHeight);
                }
                // adjust the scroll offset, if necessary
-               BPoint offset = _ValidScrollOffsetFor(fScrollOffset);
+               BPoint offset = ValidScrollOffsetFor(fScrollOffset);
                if (offset != fScrollOffset)
                        SetScrollOffset(offset);
        }
@@ -207,23 +260,4 @@
 {
 }
 
-// _ValidScrollOffsetFor
-//
-// Returns the valid scroll offset next to the supplied offset.
-BPoint
-Scrollable::_ValidScrollOffsetFor(BPoint offset) const
-{
-       float maxX = max(fDataRect.left, fDataRect.right - fVisibleWidth);
-       float maxY = max(fDataRect.top, fDataRect.bottom - fVisibleHeight);
-       // adjust the offset to be valid
-       if (offset.x < fDataRect.left)
-               offset.x = fDataRect.left;
-       else if (offset.x > maxX)
-               offset.x = maxX;
-       if (offset.y < fDataRect.top)
-               offset.y = fDataRect.top;
-       else if (offset.y > maxY)
-               offset.y = maxY;
-       return offset;
-}
 

Modified: haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.h
===================================================================
--- haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.h       
2011-04-04 09:21:43 UTC (rev 41178)
+++ haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview/Scrollable.h       
2011-04-04 09:25:07 UTC (rev 41179)
@@ -1,11 +1,7 @@
 /*
- * Copyright 2006, Haiku.
- * Distributed under the terms of the MIT License.
- *
- * Authors:
- *             Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
+ * Copyright 2001-2009, Ingo Weinhold <ingo_weinhold@xxxxxx>
+ * All rights reserved. Distributed under the terms of the MIT license.
  */
-
 #ifndef SCROLLABLE_H
 #define SCROLLABLE_H
 
@@ -22,12 +18,20 @@
                        void                            
SetScrollSource(Scroller* source);
                        Scroller*                       ScrollSource() const;
 
-                       void                            SetDataRect(BRect 
dataRect);
+                       void                            SetDataRect(BRect 
dataRect,
+                                                                       bool 
validateScrollOffset = true);
                        BRect                           DataRect() const;
 
-                       void                            SetScrollOffset(BPoint 
offset);
+       virtual void                            SetScrollOffset(BPoint offset);
                        BPoint                          ScrollOffset() const;
 
+                       void                            
SetDataRectAndScrollOffset(BRect dataRect,
+                                                                       BPoint 
offset);
+
+                       BPoint                          
ValidScrollOffsetFor(BPoint offset) const;
+                       BPoint                          
ValidScrollOffsetFor(BPoint offset,
+                                                                       const 
BRect& dataRect) const;
+
                        void                            SetVisibleSize(float 
width, float height);
                        BRect                           VisibleBounds() const;
                        BRect                           VisibleRect() const;
@@ -50,8 +54,6 @@
                        float                           fVisibleWidth;
                        float                           fVisibleHeight;
                        Scroller*                       fScrollSource;
-
-                       BPoint                          
_ValidScrollOffsetFor(BPoint offset) const;
 };
 
 


Other related posts:

  • » [haiku-commits] r41179 - haiku/trunk/src/apps/icon-o-matic/generic/gui/scrollview - superstippi