mmuifw_plat/osn_global_api/inc/osn/osntypes.inl
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Defines all inline functions of the osn types.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef OSNTYPES_INL
       
    20 #define OSNTYPES_INL
       
    21 
       
    22 // ======== GLOBAL FUNCTIONS ========
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CSize operator+
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 inline const CSize operator+( const CSize& aLeftHandSide,
       
    29                               const CSize& aRightHandSide )
       
    30     {
       
    31     return CSize( aLeftHandSide ) += aRightHandSide;
       
    32     }
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CSize operator-
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 inline const CSize operator-( const CSize& aLeftHandSide,
       
    39                               const CSize& aRightHandSide )
       
    40     {
       
    41     return CSize( aLeftHandSide ) -= aRightHandSide;
       
    42     }
       
    43     
       
    44 // -----------------------------------------------------------------------------
       
    45 // CPoint operator+
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 inline const CPoint operator+( const CPoint& aLeftHandSide,
       
    49                                const CPoint& aRightHandSide )
       
    50     {
       
    51     return CPoint( aLeftHandSide ) += aRightHandSide;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSize operator-
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 inline const CPoint operator-( const CPoint& aLeftHandSide,
       
    59                                const CPoint& aRightHandSide )
       
    60     {
       
    61     return CPoint( aLeftHandSide ) -= aRightHandSide;
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CRect + CPoint
       
    66 // Point addition.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 inline const CRect operator+( const CRect& aRect,
       
    70                               const CPoint& aPoint )
       
    71     {
       
    72     return CRect( aRect ) += aPoint;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CRect - CPoint
       
    77 // Point substraction.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 inline const CRect operator-( const CRect& aRect,
       
    81                               const CPoint& aPoint )
       
    82     {
       
    83     return CRect( aRect ) -= aPoint;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CRect + CSize
       
    88 // Size addition.
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 inline const CRect operator+( const CRect& aRect,
       
    92                               const CSize& aSize )
       
    93     {
       
    94     return CRect( aRect ) += aSize;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CRect - CSize
       
    99 // Size substraction.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 inline const CRect operator-( const CRect& aRect,
       
   103                               const CSize& aSize )
       
   104     {
       
   105     return CRect( aRect ) -= aSize;
       
   106     }
       
   107 
       
   108 // ======== MEMBER FUNCTIONS ========
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CSize::CSize
       
   112 // Default Constructor.
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 inline CSize::CSize() :
       
   116     mX( 0 ),
       
   117     mY( 0 )
       
   118     {
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CSize::CSize
       
   123 // Parameterized constructor.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 inline CSize::CSize( int32 aX, int32 aY ) :
       
   127     mX( aX ),
       
   128     mY( aY )
       
   129     {
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CSize::CSize
       
   134 // Copy Constructor.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 inline CSize::CSize( const CSize& aSize ) :
       
   138     mX( aSize.mX ),
       
   139     mY( aSize.mY )
       
   140     {
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSize::AsPoint
       
   145 // Assignment substraction.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 inline CPoint CSize::AsPoint()
       
   149     {
       
   150     return CPoint( mX, mY );
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSize::operator==
       
   155 // Logical comparison.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 inline bool32 CSize::operator==( const CSize& aSize ) const
       
   159     {
       
   160     return ( mX == aSize.mX ) && ( mY == aSize.mY );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CSize::operator!=
       
   165 // Logical comparison.
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 inline bool32 CSize::operator!=( const CSize& aSize ) const
       
   169     {
       
   170     // call operator== and negate it (logically)
       
   171     return !( *this == aSize );
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CSize::operator+=
       
   176 // Assignment addition.
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 inline CSize& CSize::operator+=( const CSize& aSize )
       
   180     {
       
   181     mX += aSize.mX;
       
   182     mY += aSize.mY;
       
   183     return *this;
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CSize::operator-=
       
   188 // Assignment substraction.
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 inline CSize& CSize::operator-=( const CSize& aSize )
       
   192     {
       
   193     mX -= aSize.mX;
       
   194     mY -= aSize.mY;
       
   195     return *this;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CPoint::CPoint
       
   200 // Default Constructor.
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 inline CPoint::CPoint() :
       
   204     mX( 0 ),
       
   205     mY( 0 )
       
   206     {
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CPoint::CPoint
       
   211 // Parameterized Constructor.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 inline CPoint::CPoint( int32 aX, int32 aY ) :
       
   215     mX( aX ),
       
   216     mY( aY )
       
   217     {
       
   218     }
       
   219 
       
   220 // -----------------------------------------------------------------------------
       
   221 // CPoint::CPoint
       
   222 // Copy Constructor.
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 inline CPoint::CPoint( const CPoint& aPoint ) :
       
   226     mX( aPoint.mX ),
       
   227     mY( aPoint.mY )
       
   228     {
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CPoint::AsSize
       
   233 // Assignment substraction.
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 inline CSize CPoint::AsSize()
       
   237     {
       
   238     return CSize( mX, mY );
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CPoint::operator==
       
   243 // Logical comparison.
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 inline bool32 CPoint::operator==( const CPoint& aPoint ) const
       
   247     {
       
   248     return ( mX == aPoint.mX ) && ( mY == aPoint.mY );
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CPoint::operator!=
       
   253 // Logical comparison.
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 inline bool32 CPoint::operator!=( const CPoint& aPoint ) const
       
   257     {
       
   258     // call operator== and negate it (logically)
       
   259     return !( *this == aPoint );
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CPoint::operator+=
       
   264 // Assignment addition.
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 inline CPoint& CPoint::operator+=( const CPoint& aPoint )
       
   268     {
       
   269     mX += aPoint.mX;
       
   270     mY += aPoint.mY;
       
   271     return *this;
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CPoint::operator-=
       
   276 // Assignment substraction.
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 inline CPoint& CPoint::operator-=( const CPoint& aPoint )
       
   280     {
       
   281     mX -= aPoint.mX;
       
   282     mY -= aPoint.mY;
       
   283     return *this;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CRect::CRect
       
   288 // Default Constructor.
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 inline CRect::CRect() :
       
   292     mX( 0 ),
       
   293     mY( 0 ),
       
   294     mWidth( 0 ),
       
   295     mHeight( 0 )
       
   296     {
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CRect::CRect
       
   301 // Parameterized Constructor.
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 inline CRect::CRect( int32 aX, int32 aY, int32 aWidth, int32 aHeight ) :
       
   305     mX( aX ),
       
   306     mY( aY ),
       
   307     mWidth( aWidth ),
       
   308     mHeight( aHeight )
       
   309     {
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CRect::CRect
       
   314 // Parameterized Constructor.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 inline CRect::CRect( const CPoint& aTopLeft, const CSize& aSize ) :
       
   318     mX( aTopLeft.mX ),
       
   319     mY( aTopLeft.mY ),
       
   320     mWidth( aSize.mX ),
       
   321     mHeight( aSize.mY )
       
   322     {
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CRect::CRect
       
   327 // Parameterized Constructor.
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 inline CRect::CRect( const CSize& aSize ) :
       
   331     mX( 0 ),
       
   332     mY( 0 ),
       
   333     mWidth( aSize.mX ),
       
   334     mHeight( aSize.mY )
       
   335     {
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CRect::CRect
       
   340 // Copy Constructor.
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 inline CRect::CRect( const CRect& aRect ) :
       
   344     mX( aRect.mX ),
       
   345     mY( aRect.mY ),
       
   346     mWidth( aRect.mWidth ),
       
   347     mHeight( aRect.mHeight )
       
   348     {
       
   349     }
       
   350     
       
   351 // -----------------------------------------------------------------------------
       
   352 // CRect::IsEmpty
       
   353 // Check for emptyness.
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 inline bool32 CRect::IsEmpty() const
       
   357     {
       
   358     // is empty if either width or heigth are zero
       
   359     return ( !mHeight ) || ( !mWidth );
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // CRect::Intersects
       
   364 // Checks whether two rects are intersecting.
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 inline bool32 CRect::Intersects( CRect aRect ) const
       
   368     {
       
   369     if( IsEmpty() || aRect.IsEmpty() )
       
   370         {
       
   371         return false;
       
   372         }
       
   373     
       
   374     aRect.Normalize();
       
   375     
       
   376     if( ( mWidth >= 0 ) && ( mHeight >= 0 ) )
       
   377         {
       
   378         return FastIntersects( aRect );
       
   379         }
       
   380     else if ( ( mWidth < 0 ) && ( mHeight < 0 ) )
       
   381         {
       
   382         return ( mX > aRect.mX ) &&
       
   383                ( mY > aRect.mY ) &&
       
   384                ( ( mX + mWidth ) < ( aRect.mX + aRect.mWidth ) ) &&
       
   385                ( ( mY + mHeight ) < ( aRect.mY + aRect.mHeight ) );
       
   386         }
       
   387     else if ( ( mWidth >= 0 ) && ( mHeight < 0 ) )
       
   388         {
       
   389         return ( ( mX + mWidth ) > aRect.mX ) &&
       
   390                ( mY > aRect.mY ) &&
       
   391                ( mX < ( aRect.mX + aRect.mWidth ) ) &&
       
   392                ( ( mY + mHeight ) < ( aRect.mY + aRect.mHeight ) );
       
   393         }
       
   394     else // ( mWidth < 0 ) && ( mHeight >= 0 )
       
   395         {
       
   396         return ( mX > aRect.mX ) &&
       
   397                ( ( mY + mHeight ) > aRect.mY ) &&
       
   398                ( ( mX + mWidth ) < ( aRect.mX + aRect.mWidth ) ) &&
       
   399                ( mY < ( aRect.mY + aRect.mHeight ) );
       
   400         }
       
   401     }
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CRect::FastIntersects
       
   405 // Checks whether two normalized rects are intersecting.
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 inline bool32 CRect::FastIntersects( const CRect& aRect ) const
       
   409     {
       
   410     return !( IsEmpty() ||                          // Empty rects do not
       
   411               aRect.IsEmpty() ||                    // intersect.
       
   412               !IsNormalized() ||                    // Non-normalized rects are
       
   413               !aRect.IsNormalized() ||              // ignored.
       
   414               ( mX + mWidth ) <= aRect.mX ||        // Top or left side of aRect
       
   415               ( mY + mHeight ) <= aRect.mY ||       // inside of this rect?
       
   416               mX >= ( aRect.mX + aRect.mWidth ) ||  // Or the other way
       
   417               mY >= ( aRect.mY + aRect.mHeight ) ); // around?
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CRect::Intersection
       
   422 // Changes this rect to become the intersection rect of this rect and aRect.
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 inline void CRect::Intersection( CRect aRect )
       
   426     {
       
   427     Normalize();
       
   428     aRect.Normalize();
       
   429 
       
   430     FastIntersection( aRect );
       
   431     }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // CRect::FastIntersection
       
   435 // Changes this rect to become the intersection rect of this rect and aRect.
       
   436 // Works only for normalized rectangles.
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 inline void CRect::FastIntersection( const CRect& aRect )
       
   440     {
       
   441     // if not intersecting at all, the intersection area is zero.
       
   442     if( !FastIntersects( aRect ) )
       
   443         {
       
   444         mX = 0;
       
   445         mY = 0;
       
   446         mWidth = 0;
       
   447         mHeight = 0;
       
   448         return;
       
   449         }
       
   450     // this rect's left side lies left of aRect's left side
       
   451     if( mX < aRect.mX )
       
   452 	    {
       
   453 		mWidth -= ( aRect.mX - mX ); // adjust this rect's width
       
   454         mX = aRect.mX;               // move this rect's left side
       
   455         }
       
   456     // this rect's top side lies above aRect's top side
       
   457 	if( mY < aRect.mY )
       
   458 	    {
       
   459 		mHeight -= ( aRect.mY - mY ); // adjust this rect's height
       
   460         mY = aRect.mY;                // move this rect's top side
       
   461         }
       
   462     // this rect's right side lies right of aRect's right side
       
   463 	if( ( mX + mWidth ) > ( aRect.mX + aRect.mWidth ) )
       
   464 	    {
       
   465 		mWidth = ( aRect.mX + aRect.mWidth ) - mX; // adjust this rect's width
       
   466         }
       
   467     // this rect's bottom side lies below aRect's bottom side
       
   468 	if( ( mY + mHeight ) > ( aRect.mY + aRect.mHeight ) )
       
   469 	    {
       
   470 		mHeight = ( aRect.mY + aRect.mHeight ) - mY; // adjust this rect's
       
   471                                                      // height
       
   472         }
       
   473     }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CRect::Normalize
       
   477 // Makes sure the rect has positive width and height.
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 inline void CRect::Normalize()
       
   481     {
       
   482 	if( mWidth < 0 )
       
   483 	    {
       
   484 		mX += mWidth;
       
   485 		mWidth = -mWidth;
       
   486 	    }
       
   487 	if( mHeight < 0 )
       
   488 	    {
       
   489 		mY += mHeight;
       
   490 		mHeight = -mHeight;
       
   491 	    }
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CRect::IsNormalized
       
   496 // Tests whether is rectangle is normalized.
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 inline bool32 CRect::IsNormalized() const
       
   500     {
       
   501 	return ( mWidth >= 0 ) && ( mHeight >= 0 );
       
   502     }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CRect::operator==
       
   506 // Logical comparison.
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 inline bool32 CRect::operator==( const CRect& aRect ) const
       
   510     {
       
   511     return ( mY == aRect.mY ) &&
       
   512            ( mX == aRect.mX ) &&
       
   513            ( mHeight == aRect.mHeight ) &&
       
   514            ( mWidth == aRect.mWidth );
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CRect::operator!=
       
   519 // Logical comparison.
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 inline bool32 CRect::operator!=( const CRect& aRect ) const
       
   523     {
       
   524     // is empty, if either width or height are zero
       
   525     return !( *this == aRect );
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CPoint::operator+=
       
   530 // Point addition.
       
   531 // -----------------------------------------------------------------------------
       
   532 //
       
   533 inline CRect& CRect::operator+=( const CPoint& aPoint )
       
   534     {
       
   535     mX += aPoint.mX;
       
   536     mY += aPoint.mY;
       
   537     return *this;
       
   538     }
       
   539 
       
   540 // -----------------------------------------------------------------------------
       
   541 // CPoint::operator-=
       
   542 // Point substraction.
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 inline CRect& CRect::operator-=( const CPoint& aPoint )
       
   546     {
       
   547     mX -= aPoint.mX;
       
   548     mY -= aPoint.mY;
       
   549     return *this;
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // CPoint::operator+=
       
   554 // Size addition.
       
   555 // -----------------------------------------------------------------------------
       
   556 //
       
   557 inline CRect& CRect::operator+=( const CSize& aSize )
       
   558     {
       
   559     mWidth += aSize.mX;
       
   560     mHeight += aSize.mY;
       
   561     return *this;
       
   562     }
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CPoint::operator-=
       
   566 // Size substraction.
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 inline CRect& CRect::operator-=( const CSize& aSize )
       
   570     {
       
   571     mWidth -= aSize.mX;
       
   572     mHeight -= aSize.mY;
       
   573     return *this;
       
   574     }
       
   575 
       
   576 #endif // OSNTYPES_INL__