First public contribution.
1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\us_regn.cpp
21 NONSHARABLE_CLASS(TRectKey) : public TKey
24 TRectKey(const TRect *aRectList,const TPoint &aOffset);
25 virtual TInt Compare(TInt aLeft,TInt aRight) const;
27 const TRect *iRectList;
32 NONSHARABLE_CLASS(TRectSwap) : public TSwap
35 inline TRectSwap(TRect *aRectList);
36 virtual void Swap(TInt aLeft,TInt aRight) const;
41 inline TRectSwap::TRectSwap(TRect *aRectList)
42 {iRectList=aRectList;}
44 enum {ERegionBufSize=8};
46 EXPORT_C TRegion::TRegion(TInt aAllocedRects)
50 : iCount(0),iError(EFalse),iAllocedRects(aAllocedRects)
56 EXPORT_C TBool TRegion::IsEmpty() const
58 Tests whether the region is empty.
60 @return True, if the region is empty and its error flag is unset;
65 return(iCount==0 && !iError);
71 #ifndef __REGIONS_MACHINE_CODED__
72 EXPORT_C TRect TRegion::BoundingRect() const
74 Gets the minimal rectangle that bounds the entire region.
76 @return The region's minimal bounding rectangle.
85 pRect=RectangleList();
87 for (pEnd=pRect+(iCount-1);pRect<pEnd;pRect++)
89 if (pRect->iTl.iX<bounds.iTl.iX)
90 bounds.iTl.iX=pRect->iTl.iX;
91 if (pRect->iTl.iY<bounds.iTl.iY)
92 bounds.iTl.iY=pRect->iTl.iY;
93 if (pRect->iBr.iX>bounds.iBr.iX)
94 bounds.iBr.iX=pRect->iBr.iX;
95 if (pRect->iBr.iY>bounds.iBr.iY)
96 bounds.iBr.iY=pRect->iBr.iY;
106 EXPORT_C const TRect &TRegion::operator[](TInt aIndex) const
108 Gets a rectangle from the region.
110 @param aIndex The index of a rectangle within the region's array of rectangles.
111 Indexes are relative to zero.
113 @return The specified rectangle.
115 @panic USER 81, if aIndex is greater than or equal to the number
116 of rectangles in the region.
120 __ASSERT_ALWAYS((TUint)aIndex<(TUint)iCount,Panic(ETRegionOutOfRange));
121 return(*(RectangleList()+aIndex));
127 #ifndef __REGIONS_MACHINE_CODED__
128 EXPORT_C TBool TRegion::IsContainedBy(const TRect &aRect) const
130 Tests whether the region is fully enclosed within the specified rectangle.
132 @param aRect The specified rectangle.
134 @return True, if the region is fully enclosed within the rectangle (their sides
135 may touch); false, otherwise.
141 for (pRect1=RectangleList(),pEnd1=pRect1+iCount;pRect1<pEnd1;pRect1++)
143 if (pRect1->iTl.iX<aRect.iTl.iX || pRect1->iBr.iX>aRect.iBr.iX || pRect1->iTl.iY<aRect.iTl.iY || pRect1->iBr.iY>aRect.iBr.iY)
152 EXPORT_C TBool TRegion::Intersects(const TRect &aRect) const
154 Tests whether where there is any intersection between this region and the specified rectangle.
156 @param aRect The specified rectangle.
158 @return True, if there is an intersection; false, otherwise.
164 for (pRect1=RectangleList(),pEnd1=pRect1+iCount;pRect1<pEnd1;pRect1++)
166 if (aRect.Intersects(*pRect1))
175 EXPORT_C void TRegion::Copy(const TRegion &aRegion)
177 Copies another region to this region.
179 The state of the specified region's error flag is also copied.
181 @param aRegion The region to be copied.
190 const TInt count = aRegion.iCount;
202 if (SetListSize(count))
205 Mem::Copy(RectangleListW(), aRegion.RectangleList(), sizeof(TRect)*count);
214 EXPORT_C void TRegion::Offset(const TPoint &aOffset)
216 Moves the region by adding a TPoint offset to the co-ordinates of its corners.
218 The size of the region is not changed.
220 @param aOffset The offset by which the region is moved. The region is moved
221 horizontally by aOffset.iX pixels and vertically by aOffset.iY pixels.
225 TRect *pR=RectangleListW();
226 const TRect *pE=pR+iCount;
237 EXPORT_C void TRegion::Offset(TInt aXoffset,TInt aYoffset)
239 Moves the region by adding X and Y offsets to the co-ordinates of its corners.
241 The size of the region is not changed.
243 @param aXoffset The number of pixels by which to move the region horizontally.
244 If negative, the region moves leftwards.
245 @param aYoffset The number of pixels by which to move the region vertically.
246 If negative, the region moves upwards.
250 Offset(TPoint(aXoffset,aYoffset));
256 EXPORT_C TBool TRegion::Contains(const TPoint &aPoint) const
258 Tests whether a point is located within the region.
260 If the point is located on the top or left hand side of any rectangle in the
261 region, it is considered to be within that rectangle and within the region.
263 If the point is located on the right hand side or bottom of a rectangle, it
264 is considered to be outside that rectangle, and may be outside the region.
266 @param aPoint The specified point.
268 @return True, if the point is within the region; false, otherwise.
271 const TRect *pR=RectangleList();
272 const TRect *pE=pR+iCount;
275 if (pR->Contains(aPoint))
285 EXPORT_C void TRegion::SubRect(const TRect &aRect,TRegion *aSubtractedRegion)
287 Removes a rectangle from this region.
289 If there is no intersection between the rectangle and this region, then this
290 region is unaffected.
292 @param aRect The rectangular area to be removed from this region.
293 @param aSubtractedRegion A pointer to a region. If this is supplied, the
294 removed rectangle is added to it. By default this
300 TRect *prect=RectangleListW();
302 for (TInt index=0;index<limit;)
304 if (prect->iBr.iX>aRect.iTl.iX && prect->iBr.iY>aRect.iTl.iY && prect->iTl.iX<aRect.iBr.iX && prect->iTl.iY<aRect.iBr.iY)
308 inter.Intersection(*prect);
310 if (inter.iBr.iY!=rect.iBr.iY)
311 AppendRect(TRect(rect.iTl.iX,inter.iBr.iY,rect.iBr.iX,rect.iBr.iY));
312 if (inter.iTl.iY!=rect.iTl.iY)
313 AppendRect(TRect(rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,inter.iTl.iY));
314 if (inter.iBr.iX!=rect.iBr.iX)
315 AppendRect(TRect(inter.iBr.iX,inter.iTl.iY,rect.iBr.iX,inter.iBr.iY));
316 if (inter.iTl.iX!=rect.iTl.iX)
317 AppendRect(TRect(rect.iTl.iX,inter.iTl.iY,inter.iTl.iX,inter.iBr.iY));
320 if (aSubtractedRegion!=NULL)
321 aSubtractedRegion->AddRect(inter);
322 prect=RectangleListW()+index; // List might have been re-allocated so re-get the pointer
339 Merges a rectangle with this region.
341 If requested it looks for a rectangle in the region that covers the new rectangle, if found method returns immediately.
342 Otherwise, or if an enclosing rectangle is not found, the new aRect is subtracted from all intersecting rectangles,
343 and then aRect is appended to the region.
345 @param aRect The rectangular area to be added to this region.
346 @param aCovered Whether to look for a rectangle in the region that covers the new aRect.
348 void TRegion::MergeRect(const TRect &aRect, TBool aCovered)
350 TRect *prect=RectangleListW();
354 while (aCovered && (index < limit) )
356 if (prect->iBr.iX<=aRect.iTl.iX || prect->iBr.iY<=aRect.iTl.iY || prect->iTl.iX>=aRect.iBr.iX || prect->iTl.iY>=aRect.iBr.iY)
363 if (prect->iBr.iX>=aRect.iBr.iX && prect->iBr.iY>=aRect.iBr.iY && prect->iTl.iX<=aRect.iTl.iX && prect->iTl.iY<=aRect.iTl.iY)
364 { // region rectangle covers new aRect
367 break; // let the 2nd loop deal with this intersection
371 while (index < limit)
373 if (prect->iBr.iX<=aRect.iTl.iX || prect->iBr.iY<=aRect.iTl.iY || prect->iTl.iX>=aRect.iBr.iX || prect->iTl.iY>=aRect.iBr.iY)
382 inter.Intersection(*prect);
384 if (inter.iBr.iY!=rect.iBr.iY)
385 AppendRect(TRect(rect.iTl.iX,inter.iBr.iY,rect.iBr.iX,rect.iBr.iY));
386 if (inter.iTl.iY!=rect.iTl.iY)
387 AppendRect(TRect(rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,inter.iTl.iY));
388 if (inter.iBr.iX!=rect.iBr.iX)
389 AppendRect(TRect(inter.iBr.iX,inter.iTl.iY,rect.iBr.iX,inter.iBr.iY));
390 if (inter.iTl.iX!=rect.iTl.iX)
391 AppendRect(TRect(rect.iTl.iX,inter.iTl.iY,inter.iTl.iX,inter.iBr.iY));
394 prect=RectangleListW()+index; // List might have been re-allocated so re-get the pointer
403 EXPORT_C void TRegion::Union(const TRegion &aRegion)
405 Replaces this region with the union of it and the specified region.
407 Note that if the error flag of either this region or the specified region is
408 set, then this region is cleared and its error flag is set. This frees up
411 @param aRegion The region to be joined to this region.
418 else if (!iError && (aRegion.iCount != 0))
426 RRegionBuf<ERegionBufSize> temp;
428 if (temp.iCount>iCount)
430 temp.AppendRegion(*this);
445 #ifndef __REGIONS_MACHINE_CODED__
446 EXPORT_C void TRegion::Intersection(const TRegion &aRegion1,const TRegion &aRegion2)
448 Replaces this region with the area of intersection between two specified regions.
452 1. If the error flag of either of the two specified regions is set, then this
453 region is cleared and its error flag is set. This frees up allocated memory.
455 2. If this region's error flag is already set, then the function has no effect.
457 @param aRegion1 The first region.
458 @param aRegion2 The second region.
461 if (aRegion1.iError || aRegion2.iError)
466 const TRect *pRect1,*pEnd1;
467 const TRect *pRect2,*pEnd2;
468 for (pRect1=aRegion1.RectangleList(),pEnd1=pRect1+aRegion1.iCount;pRect1<pEnd1;pRect1++)
470 for (pRect2=aRegion2.RectangleList(),pEnd2=pRect2+aRegion2.iCount;pRect2<pEnd2;pRect2++)
472 if (pRect1->iBr.iX>pRect2->iTl.iX && pRect1->iBr.iY>pRect2->iTl.iY && pRect1->iTl.iX<pRect2->iBr.iX && pRect1->iTl.iY<pRect2->iBr.iY)
475 rect.Intersection(*pRect1);
487 EXPORT_C void TRegion::Intersect(const TRegion &aRegion)
489 Replaces this region with the area of intersection between it and the specified
492 Note that if the error flag of either this region or the specified region is
493 set, then this region is cleared and its error flag is set. This frees up
496 @param aRegion The region to be intersected with this region.
503 else if (!iError && (iCount != 0))
505 if (aRegion.iCount == 0)
511 RRegionBuf<ERegionBufSize> temp;
513 Intersection(temp,aRegion);
522 EXPORT_C void TRegion::AddRect(const TRect &aRect)
524 Adds a rectangle to this region.
528 1. If this region's error flag is already set, this function has no effect.
530 2. If the operation causes the capacity of this region to be exceeded, or if
531 memory allocation fails, the region is cleared, freeing up any memory which
532 has been allocated; its error flag is also set.
534 @param aRect The rectangle to be added to this region.
537 if (!aRect.IsEmpty() && !iError)
539 TBool doAppend = ETrue;
542 TRect regRect = BoundingRect();
544 inter.Intersection(regRect);
546 if (!inter.IsEmpty())
548 if ( inter == regRect )
549 { // equivalent to IsContainedBy(aRect)
554 TBool coversRect = (inter == aRect); // bounding rect of region includes all of aRect?
555 MergeRect(aRect, coversRect);
565 // RRegion could have unneeded memory that can be freed
566 if (!iError && (iAllocedRects > iCount))
576 EXPORT_C void TRegion::SubRegion(const TRegion &aRegion,TRegion *aSubtractedRegion)
580 If there is no area of intersection between the two regions, this region is
583 @param aRegion The region to be removed from this region.
584 If aRegion's error flag is set, then this region is
585 cleared, freeing up any allocated memory, and the
587 @param aSubtractedRegion If specified, then on return contains the area removed
591 SubtractRegion(aRegion, aSubtractedRegion);
593 // RRegion could have unneeded memory that can be freed
594 if (!iError && (iAllocedRects > iCount))
604 If there is no area of intersection between the two regions, this region is
607 @param aRegion The region to be removed from this region.
608 If aRegion's error flag is set, then this region is
609 cleared, freeing up any allocated memory, and the
611 @param aSubtractedRegion If specified, then on return contains the area removed
614 void TRegion::SubtractRegion(const TRegion &aRegion,TRegion *aSubtractedRegion)
622 else if (iCount != 0)
624 const TRect *pR=aRegion.RectangleList();
625 const TRect *pE=pR+aRegion.iCount;
626 while (pR<pE && !iError)
628 SubRect(*pR++, aSubtractedRegion);
630 if (iError && aSubtractedRegion)
632 aSubtractedRegion->ForceError();
641 #ifndef __REGIONS_MACHINE_CODED__
642 EXPORT_C void TRegion::ClipRect(const TRect &aRect)
644 Clips the region to the specified rectangle.
646 The resulting region is the area of overlap between the region and the rectangle.
647 If there is no overlap, all rectangles within this region are deleted and
648 the resulting region is empty.
650 @param aRect The rectangle to which this region is to be clipped.
654 for (TInt index=0;index<iCount;)
656 TRect *r2=RectangleListW()+index;
657 if (r2->iTl.iX<aRect.iTl.iX)
658 r2->iTl.iX=aRect.iTl.iX;
659 if (r2->iTl.iY<aRect.iTl.iY)
660 r2->iTl.iY=aRect.iTl.iY;
661 if (r2->iBr.iX>aRect.iBr.iX)
662 r2->iBr.iX=aRect.iBr.iX;
663 if (r2->iBr.iY>aRect.iBr.iY)
664 r2->iBr.iY=aRect.iBr.iY;
676 EXPORT_C void TRegion::Clear()
680 This frees up any memory which has been allocated and unsets the error flag.
684 if (iAllocedRects>=0)
686 User::Free(((RRegion *)this)->iRectangleList);
687 ((RRegion *)this)->iRectangleList=NULL;
698 EXPORT_C void TRegion::Tidy()
700 Merges all rectangles within this region which share an adjacent edge of the
703 The function subsequently checks for allocated but unused memory, if this memory is
704 at least as large as the granularity it is released to the system.
707 TUint doMore = 2; // need 1 pass each of merging vertical & horizontal edges
709 while ( (iCount > 1) && doMore )
714 TRect* pFirst = RectangleListW();
715 TRect* pLast = RectangleListW()+iCount-1;
716 TRect *pRect1 = pLast;
717 for (;pRect1 > pFirst; pRect1--)
719 TRect *pRect2 = pRect1-1;
720 const TInt top = pRect1->iTl.iY;
721 const TInt bottom = pRect1->iBr.iY;
722 for (;pRect2 >= pFirst; pRect2--)
724 if ( (top == pRect2->iTl.iY) && (bottom == pRect2->iBr.iY) )
726 if (pRect1->iBr.iX == pRect2->iTl.iX)
728 pRect2->iTl.iX = pRect1->iTl.iX;
730 else if (pRect1->iTl.iX == pRect2->iBr.iX)
732 pRect2->iBr.iX = pRect1->iBr.iX;
743 // remove merged and move last
760 TRect* pFirst = RectangleListW();
761 TRect* pLast = RectangleListW()+iCount-1;
762 TRect *pRect1 = pLast;
763 for (;pRect1 > pFirst; pRect1--)
765 TRect *pRect2 = pRect1-1;
766 const TInt left = pRect1->iTl.iX;
767 const TInt right = pRect1->iBr.iX;
769 for (;pRect2 >= pFirst; pRect2--)
771 if ( (left == pRect2->iTl.iX) && (right == pRect2->iBr.iX) )
773 if (pRect1->iBr.iY == pRect2->iTl.iY)
775 pRect2->iTl.iY = pRect1->iTl.iY;
777 else if (pRect1->iTl.iY == pRect2->iBr.iY)
779 pRect2->iBr.iY = pRect1->iBr.iY;
805 if (iAllocedRects>iCount)
813 EXPORT_C TInt TRegion::Sort()
815 Sorts the region's array of rectangles according to their vertical position
818 The sort uses the bottom right hand corner co-ordinates of the rectangles.
819 The co-ordinates of the top and left hand sides are irrelevant
820 to the sort operation.
822 Higher rectangles take precedence over lower ones. For rectangles at the same
823 vertical position, the leftmost takes priority.
825 Note that the sort order may need to be different from the default if, for example,
826 a region is moved downwards so that lower non-overlapping rectangles need
827 to be redrawn (and sorted) before higher ones. In this case, use the second
828 overload of this function.
830 @return KErrNone, if the operation is successful; KErrGeneral, otherwise.
834 return Sort(TPoint(-1,-1));
840 EXPORT_C TInt TRegion::Sort(const TPoint &aOffset)
842 // Sort the region for copying to the same display.
845 Sorts the region's array of rectangles according to a specified sort order.
847 The sort uses the bottom right hand co-ordinates of the rectangles.
848 The co-ordinates of the top and left hand sides are irrelevant
849 to the sort operation
851 The order of the sort is determined by whether the iX and iY members of aOffset
852 are positive, or zero or less. If aOffset.iY is greater than zero,
853 lower rectangles take precedence over higher rectangles in the list order.
854 Otherwise, higher rectangles take precedence. For rectangles of equal height,
855 aOffset.iX becomes relevant to the sort.
856 If is greater than zero, rightmost rectangles
857 take precedence. Otherwise, leftmost rectangles take precedence.
859 Note that the sort order may need to be different from the default if,
860 for example, a region is moved downwards so that lower non-overlapping
861 rectangles need to be redrawn (and sorted) before higher ones.
863 @param aOffset A point whose iX and iY members determine the order of the
866 @return KErrNone, if the operation is successful; KErrGeneral, otherwise.
869 TRectKey key(RectangleList(),aOffset);
870 TRectSwap swap(RectangleListW());
871 return(User::QuickSort(iCount,key,swap));
877 EXPORT_C TRect *TRegion::RectangleListW()
879 // Return a writeable rectangle list.
882 if (iAllocedRects>=0)
883 return(((RRegion *)this)->iRectangleList);
884 else if (iAllocedRects&ERRegionBuf)
885 return((TRect *)(this+1));
886 return((TRect *)(((RRegion *)this)+1));
890 /** Ensure that the region is big enough to hold aCount rectangles.
892 @param aCount number of rectangles the region is expected to hold
893 @return ETrue if region is big enough, EFalse if fixed size region is too small or alloc failed.
895 TBool TRegion::SetListSize(TInt aCount)
898 if (iAllocedRects < 0)
900 if (aCount > (-(iAllocedRects|ERRegionBuf)))
902 if (iAllocedRects & ERRegionBuf)
907 // successful alloc will change RRegionBuf into RRegion
908 newAlloc = Max(aCount, ((RRegion *)this)->iGranularity);
911 else if (aCount > iAllocedRects)
913 newAlloc = Max(aCount, iAllocedRects + ((RRegion *)this)->iGranularity);
918 TRect *newList = (TRect *)User::ReAlloc(((RRegion *)this)->iRectangleList, newAlloc*sizeof(TRect));
924 ((RRegion *)this)->iRectangleList = newList;
925 iAllocedRects = newAlloc;
930 /** Ensure that the region is big enough to hold aCount rectangles.
931 Any allocation increase is for at least the granularity count of rectangles.
932 Similar to SetListSize, but always preserves existing iCount rectangles.
934 @param aCount number of rectangles the region is expected to hold
935 @return NULL if region is not big enough, otherwise pointer to the Rect array.
937 TRect* TRegion::ExpandRegion(TInt aCount)
942 if (iAllocedRects & ERRegionBuf)
944 if (aCount > -iAllocedRects)
945 { // Can't expand a TRegionFix
949 prects=(TRect *)(this+1);
951 else if (iAllocedRects < 0)
953 prects = (TRect *)(((RRegion *)this)+1);
954 if (aCount > (-(iAllocedRects|ERRegionBuf)))
956 RRegion *pr = (RRegion *)this;
957 TUint newCount = Max(aCount, iCount + pr->iGranularity);
958 TRect *newList = (TRect *)User::Alloc(newCount * sizeof(TRect));
964 iAllocedRects = newCount;
965 pr->iRectangleList = newList;
968 Mem::Copy(pr->iRectangleList, prects, sizeof(TRect)*iCount);
970 prects = pr->iRectangleList;
975 RRegion *pr = (RRegion *)this;
976 prects = pr->iRectangleList;
977 if (iAllocedRects < aCount)
979 TUint newCount = Max(aCount, iAllocedRects + pr->iGranularity);
980 prects=(TRect *)User::ReAlloc(prects, newCount*sizeof(TRect));
986 iAllocedRects = newCount;
987 pr->iRectangleList = prects;
997 After an RRegion's iCount has reduced try to release some memory.
998 Hysteresis rule: reduce allocated memory to iCount, but only if
999 the released memory will also be at least the granularity.
1001 void TRegion::ShrinkRegion()
1003 ASSERT(iAllocedRects > iCount);
1004 // must be an RRegion
1005 RRegion *pr=(RRegion *)this;
1006 if (iAllocedRects >= (iCount + pr->iGranularity) )
1008 TRect *newList = NULL;
1011 User::Free(pr->iRectangleList);
1015 newList = (TRect *)User::ReAlloc(pr->iRectangleList, iCount*sizeof(TRect));
1016 if (newList == NULL)
1022 iAllocedRects = iCount;
1023 pr->iRectangleList = newList;
1028 void TRegion::AppendRect(const TRect &aRect)
1030 // Add a rectangle to the list.
1033 TRect *prects = ExpandRegion(iCount+1);
1036 *(prects+iCount)=aRect;
1042 #ifndef __REGIONS_MACHINE_CODED__
1045 EXPORT_C void TRegion::ForceError()
1047 Sets the error flag, and clears the region.
1049 This frees up memory allocated to the region.
1057 void TRegion::DeleteRect(TRect *aRect)
1059 // Delete a specific rectangle in the list.
1064 Mem::Copy(aRect,aRect+1,((TUint8 *)(RectangleList()+iCount))-((TUint8 *)aRect));
1068 void TRegion::AppendRegion(TRegion &aRegion)
1070 // Append all the rectangles from aRegion to this.
1073 aRegion.SubtractRegion(*this);
1078 else if (aRegion.iCount > 0)
1080 // alloc enough memory, then memcpy
1081 const TInt newCount = iCount + aRegion.iCount;
1082 if (ExpandRegion(newCount))
1084 TRect* pDest = RectangleListW() + iCount;
1085 const TRect* pSource = aRegion.RectangleList();
1086 Mem::Copy(pDest, pSource, aRegion.iCount * sizeof(TRect));
1094 EXPORT_C RRegion::RRegion()
1095 : TRegion(0), iGranularity(EDefaultGranularity), iRectangleList(NULL)
1097 Default constructor.
1099 Initialises its granularity to five.
1106 EXPORT_C RRegion::RRegion(TInt aGran)
1107 : TRegion(0), iGranularity(aGran), iRectangleList(NULL)
1109 Constructs the object with the specified granularity.
1111 @param aGran The initial value for the region's granularity.
1112 This value must not be negative.
1119 EXPORT_C RRegion::RRegion(const TRect &aRect, TInt aGran)
1120 : TRegion(0), iGranularity(aGran), iRectangleList(NULL)
1122 Constructs the object with the specified rectangle and granularity.
1124 The resulting region consists of the specified single rectangle.
1126 @param aRect The single rectangle with which to initialise the region
1127 @param aGran The initial value for the region's granularity. By default,
1132 if (!aRect.IsEmpty())
1139 EXPORT_C RRegion::RRegion(const RRegion &aRegion)
1143 Constructs a new region from an existing one by performing a bit-wise copy. Both the new and
1144 existing regions are left containing pointers to the same data, so Close() must only be called on
1147 Use of this method is not recommended.
1149 @param aRegion The region to be copied.
1158 EXPORT_C RRegion::RRegion(TInt aBuf, TInt aGran)
1162 : TRegion(aBuf), iGranularity(aGran), iRectangleList(NULL)
1168 EXPORT_C RRegion::RRegion(TInt aCount,TRect* aRectangleList,TInt aGran/*=EDefaultGranularity*/)
1170 Constructor that takes ownership of an already created rectangle list.
1172 @param aCount The number of rectangles in the region.
1173 @param aRectangleList A pointer to the set of rectangles.
1174 @param aGran The region's granularity.
1176 : TRegion(aCount), iGranularity(aGran), iRectangleList(aRectangleList)
1184 EXPORT_C void RRegion::Close()
1188 Frees up any memory which has been allocated, and unsets the error flag, if
1191 The region can be re-used after calling this method. Its granularity is preserved.
1201 EXPORT_C void RRegion::Destroy()
1210 Note this method will delete the RRegion object and therefore it should not be
1211 invoked on RRegion objects that are not allocated on the heap. RRegion::Close()
1212 should be used for RRegion objects stored on the stack.
1214 @panic USER 42 if the RRegion object is stored on the stack.
1225 TInt TRectKey::Compare(TInt aLeft,TInt aRight) const
1227 // Compares two rectangles for partial ordering.
1233 const TRect *r1=&iRectList[aLeft];
1234 const TRect *r2=&iRectList[aRight];
1235 if (r2->iBr.iY<=r1->iTl.iY)
1236 return(iDown ? -1 : 1);
1237 if (r1->iBr.iY<=r2->iTl.iY)
1238 return(iDown ? 1 : -1);
1239 if (r2->iBr.iX<=r1->iTl.iX)
1240 return(iRight ? -1 : 1);
1241 __ASSERT_DEBUG(r1->iBr.iX<=r2->iTl.iX,Panic(ETRegionInvalidRegionInSort));
1242 return(iRight ? 1 : -1);
1245 void TRectSwap::Swap(TInt aLeft,TInt aRight) const
1247 // Swap two rectangles.
1251 TRect tmp(iRectList[aLeft]);
1252 iRectList[aLeft]=iRectList[aRight];
1253 iRectList[aRight]=tmp;
1256 TRectKey::TRectKey(const TRect *aRectList,const TPoint &aOffset)
1258 // Rectangle key constructor
1262 iRectList=aRectList;