graphicsutils/commongraphicsheaders/inc/displayconfiguration.inl
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-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 "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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedPartner
       
    19  @prototype
       
    20 */
       
    21 
       
    22 #ifndef _DISPLAYCONFIGURATION_INL__INCLUDED_
       
    23 #define _DISPLAYCONFIGURATION_INL__INCLUDED_
       
    24 
       
    25 //
       
    26 //
       
    27 // Complete implementation of Base class
       
    28 //
       
    29 //
       
    30 inline TInt TDisplayConfigurationBase::Version() const
       
    31 	{
       
    32 	return iVersion;
       
    33 	}
       
    34 
       
    35 inline void TDisplayConfigurationBase::Clear(TAttribute aAttribute)
       
    36 	{
       
    37 	iDefined.Clear(+aAttribute);
       
    38 	}
       
    39 
       
    40 inline void TDisplayConfigurationBase::ClearAll()
       
    41 	{
       
    42 	iDefined.ClearAll();
       
    43 	}
       
    44 
       
    45 inline void TDisplayConfigurationBase::Panic(TInt aPanicCode)
       
    46 	{
       
    47 	_LIT(KCategory,"DISPLAYCONFIG");
       
    48 	User::Panic(KCategory,aPanicCode);
       
    49 	}
       
    50 
       
    51 inline TBool TDisplayConfigurationBase::IsDefined(TAttribute aAttribute) const
       
    52 	{
       
    53 	//If we have more than 32 attributes then this code may need a rewrite.
       
    54 	__ASSERT_COMPILE(EAttributeMax<=32);
       
    55 	return  iDefined.IsSet(+aAttribute);
       
    56 	}
       
    57 
       
    58 inline TDisplayConfigurationBase::TDisplayConfigurationBase(TInt aVersion)
       
    59 	{
       
    60 	if (aVersion < sizeof(*this))
       
    61 		{
       
    62 		Panic(EPanicConfigInvalid);
       
    63 		}
       
    64 	iVersion=aVersion;
       
    65 	//default constructor for iDefined sets all-zero.
       
    66 	//Members do not need zapping to zero because they are disabled in iDefined
       
    67 	}
       
    68 
       
    69 
       
    70 inline TBool TDisplayConfigurationBase::operator == (const TDisplayConfigurationBase& aRhs) const
       
    71 	{
       
    72 	return (aRhs.Version()== Version()) && (const_cast<TBitFlags32&>(aRhs.iDefined) == iDefined );
       
    73 	}
       
    74 //
       
    75 //
       
    76 // Complete implementation of V1 class
       
    77 //
       
    78 //
       
    79 inline TDisplayConfiguration1::TDisplayConfiguration1():TDisplayConfigurationBase(sizeof(*this))
       
    80 		,iResolution(TSize::EUninitialized)
       
    81 	{}
       
    82 
       
    83 inline TDisplayConfiguration1::TDisplayConfiguration1(TInt aVersion):TDisplayConfigurationBase(aVersion)
       
    84 		,iResolution(TSize::EUninitialized)
       
    85 	{
       
    86 	if (aVersion > sizeof(TDisplayConfigurationBase) &&
       
    87 			aVersion < sizeof(*this))
       
    88 		{
       
    89 		Panic(EPanicConfigInvalid);
       
    90 		}
       
    91 	}
       
    92 
       
    93 inline void TDisplayConfiguration1::SetResolution(const TSize& aSize)
       
    94 	{
       
    95 	if (MemberAccessible(iResolution))
       
    96 		{
       
    97 		if (aSize.iWidth<0 || aSize.iHeight<0)
       
    98 			{
       
    99 			Panic(EPanicNegResolution);
       
   100 			}
       
   101 		if ((aSize.iWidth>0 && aSize.iHeight==0)||
       
   102 				(aSize.iWidth==0 && aSize.iHeight>0))
       
   103 			{
       
   104 			Panic(EPanicSemiZeroResolution);
       
   105 			}
       
   106 		iDefined.Set(+EResolution);
       
   107 		iResolution=aSize;
       
   108 		}
       
   109 	}
       
   110 
       
   111 inline TBool TDisplayConfiguration1::GetResolution(TSize& aSize) const
       
   112 	{
       
   113 	if (MemberAccessible(iResolution) && IsDefined(EResolution))
       
   114 		{
       
   115 		aSize=iResolution;
       
   116 		return ETrue;
       
   117 		}		
       
   118 	return  EFalse;
       
   119 	}
       
   120 
       
   121 //Accessor for rotation member (index)
       
   122 inline void TDisplayConfiguration1::SetRotation(TRotation aOrientation)
       
   123 	{
       
   124 	if (MemberAccessible(iRotation))
       
   125 		{
       
   126 		if ((TUint)aOrientation>=(TUint)ERotationIllegal)
       
   127 			{
       
   128 			Panic(EPanicIllegalRotation);
       
   129 			}
       
   130 		iDefined.Set(+ERotation);
       
   131 		iRotation=aOrientation;
       
   132 		}
       
   133 	
       
   134 	}
       
   135 //Accessor for rotation member (index)
       
   136 inline TBool TDisplayConfiguration1::GetRotation(TRotation& aOrientation)const
       
   137 	{
       
   138 	if (MemberAccessible(iRotation) && IsDefined(ERotation))
       
   139 		{
       
   140 		aOrientation=static_cast<TRotation>(iRotation);
       
   141 		return ETrue;
       
   142 		}
       
   143 	return EFalse;
       
   144 	}
       
   145 //Accessor for resolution value
       
   146 inline void TDisplayConfiguration1::SetResolutionTwips(const TSize& aSize)
       
   147 	{
       
   148 	if (MemberAccessible(iTwipsSize))
       
   149 		{
       
   150 		if (aSize.iWidth<0 || aSize.iHeight<0)
       
   151 			{
       
   152 			Panic(EPanicNegTwips);
       
   153 			}
       
   154 		if ((aSize.iWidth>0 && aSize.iHeight==0)||
       
   155 				(aSize.iWidth==0 && aSize.iHeight>0))
       
   156 			{
       
   157 			Panic(EPanicSemiZeroTwips);
       
   158 			}
       
   159 		iDefined.Set(+EResolutionTwips);
       
   160 		iTwipsSize=aSize;
       
   161 		}
       
   162 	}
       
   163 //Accessor for resolution value
       
   164 inline TBool TDisplayConfiguration1::GetResolutionTwips(TSize& aSize) const
       
   165 	{
       
   166 	if (MemberAccessible(iTwipsSize) && IsDefined(EResolutionTwips))
       
   167 		{
       
   168 		aSize=iTwipsSize;
       
   169 		return ETrue;
       
   170 		}
       
   171 	return EFalse;
       
   172 	}
       
   173 
       
   174 inline TBool TDisplayConfiguration1::operator == (const TDisplayConfiguration1& aRhs)const
       
   175 	{
       
   176 	if (!TDisplayConfigurationBase::operator ==(aRhs))
       
   177 		return EFalse;	//Check for earlier version compatability
       
   178 	if (Version()<sizeof(*this))
       
   179 		return ETrue;	//If the objects are smaller than this then the check is complete
       
   180 	
       
   181 	TBool isAttrEqual = ETrue;
       
   182 	if(IsDefined(EResolution))
       
   183 		{
       
   184 		isAttrEqual = isAttrEqual&(aRhs.iResolution == iResolution);
       
   185 		}
       
   186 	if(IsDefined(ERotation))
       
   187 		{
       
   188 		isAttrEqual = isAttrEqual&(aRhs.iRotation == iRotation);
       
   189 		}
       
   190 	if(IsDefined(EResolutionTwips))
       
   191 		{
       
   192 		isAttrEqual = isAttrEqual&(aRhs.iTwipsSize == iTwipsSize);
       
   193 		}
       
   194 	
       
   195 	return isAttrEqual;
       
   196 	}
       
   197 
       
   198 //
       
   199 //
       
   200 // Complete implementation of v2 class (goes here)
       
   201 //
       
   202 //
       
   203 
       
   204 
       
   205 //
       
   206 //
       
   207 // Complete implementation of Wrapper class
       
   208 //
       
   209 //
       
   210 inline TDisplayConfiguration::TDisplayConfiguration(const TDisplayConfiguration& aDisplayConfiguration):
       
   211 	TDisplayConfigurationTop(TDisplayConfiguration().Version())
       
   212 	{
       
   213 	TInt tempSize = aDisplayConfiguration.Version();
       
   214 	if (tempSize > TDisplayConfiguration().Version())
       
   215 		{
       
   216 		tempSize = TDisplayConfiguration().Version();
       
   217 		}
       
   218 	Mem::Copy(this, &aDisplayConfiguration, tempSize);
       
   219 	//This has copied size for higher version features...
       
   220 	iVersion = tempSize;
       
   221 	//This has copied set flags for higher version features...
       
   222 	TInt flags=iDefined.Value();
       
   223 	//If we have more than 32 attributes then this code will need a rewrite.
       
   224 	__ASSERT_COMPILE(EAttributeMax<=32);
       
   225 	flags&=(1<<EAttributeMax)-1;
       
   226 	iDefined.SetValue(flags);
       
   227 	}
       
   228 
       
   229 inline TDisplayConfiguration::TDisplayConfiguration(TInt aVersion):
       
   230 	TDisplayConfigurationTop(aVersion)
       
   231 	{
       
   232 	if (TDisplayConfiguration().Version() > aVersion)
       
   233 		{
       
   234 		iVersion = aVersion;
       
   235 		}
       
   236 	}
       
   237 
       
   238 #endif // _DISPLAYCONFIGURATION__INCLUDED_