First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
22 #ifndef _DISPLAYCONFIGURATION_INL__INCLUDED_
23 #define _DISPLAYCONFIGURATION_INL__INCLUDED_
27 // Complete implementation of Base class
30 inline TInt TDisplayConfigurationBase::Version() const
35 inline void TDisplayConfigurationBase::Clear(TAttribute aAttribute)
37 iDefined.Clear(+aAttribute);
40 inline void TDisplayConfigurationBase::ClearAll()
45 inline void TDisplayConfigurationBase::Panic(TInt aPanicCode)
47 _LIT(KCategory,"DISPLAYCONFIG");
48 User::Panic(KCategory,aPanicCode);
51 inline TBool TDisplayConfigurationBase::IsDefined(TAttribute aAttribute) const
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);
58 inline TDisplayConfigurationBase::TDisplayConfigurationBase(TInt aVersion)
60 if (aVersion < sizeof(*this))
62 Panic(EPanicConfigInvalid);
65 //default constructor for iDefined sets all-zero.
66 //Members do not need zapping to zero because they are disabled in iDefined
70 inline TBool TDisplayConfigurationBase::operator == (const TDisplayConfigurationBase& aRhs) const
72 return (aRhs.Version()== Version()) && (const_cast<TBitFlags32&>(aRhs.iDefined) == iDefined );
76 // Complete implementation of V1 class
79 inline TDisplayConfiguration1::TDisplayConfiguration1():TDisplayConfigurationBase(sizeof(*this))
80 ,iResolution(TSize::EUninitialized)
83 inline TDisplayConfiguration1::TDisplayConfiguration1(TInt aVersion):TDisplayConfigurationBase(aVersion)
84 ,iResolution(TSize::EUninitialized)
86 if (aVersion > sizeof(TDisplayConfigurationBase) &&
87 aVersion < sizeof(*this))
89 Panic(EPanicConfigInvalid);
93 inline void TDisplayConfiguration1::SetResolution(const TSize& aSize)
95 if (MemberAccessible(iResolution))
97 if (aSize.iWidth<0 || aSize.iHeight<0)
99 Panic(EPanicNegResolution);
101 if ((aSize.iWidth>0 && aSize.iHeight==0)||
102 (aSize.iWidth==0 && aSize.iHeight>0))
104 Panic(EPanicSemiZeroResolution);
106 iDefined.Set(+EResolution);
111 inline TBool TDisplayConfiguration1::GetResolution(TSize& aSize) const
113 if (MemberAccessible(iResolution) && IsDefined(EResolution))
121 //Accessor for rotation member (index)
122 inline void TDisplayConfiguration1::SetRotation(TRotation aOrientation)
124 if (MemberAccessible(iRotation))
126 if ((TUint)aOrientation>=(TUint)ERotationIllegal)
128 Panic(EPanicIllegalRotation);
130 iDefined.Set(+ERotation);
131 iRotation=aOrientation;
135 //Accessor for rotation member (index)
136 inline TBool TDisplayConfiguration1::GetRotation(TRotation& aOrientation)const
138 if (MemberAccessible(iRotation) && IsDefined(ERotation))
140 aOrientation=static_cast<TRotation>(iRotation);
145 //Accessor for resolution value
146 inline void TDisplayConfiguration1::SetResolutionTwips(const TSize& aSize)
148 if (MemberAccessible(iTwipsSize))
150 if (aSize.iWidth<0 || aSize.iHeight<0)
152 Panic(EPanicNegTwips);
154 if ((aSize.iWidth>0 && aSize.iHeight==0)||
155 (aSize.iWidth==0 && aSize.iHeight>0))
157 Panic(EPanicSemiZeroTwips);
159 iDefined.Set(+EResolutionTwips);
163 //Accessor for resolution value
164 inline TBool TDisplayConfiguration1::GetResolutionTwips(TSize& aSize) const
166 if (MemberAccessible(iTwipsSize) && IsDefined(EResolutionTwips))
174 inline TBool TDisplayConfiguration1::operator == (const TDisplayConfiguration1& aRhs)const
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
181 TBool isAttrEqual = ETrue;
182 if(IsDefined(EResolution))
184 isAttrEqual = isAttrEqual&(aRhs.iResolution == iResolution);
186 if(IsDefined(ERotation))
188 isAttrEqual = isAttrEqual&(aRhs.iRotation == iRotation);
190 if(IsDefined(EResolutionTwips))
192 isAttrEqual = isAttrEqual&(aRhs.iTwipsSize == iTwipsSize);
200 // Complete implementation of v2 class (goes here)
207 // Complete implementation of Wrapper class
210 inline TDisplayConfiguration::TDisplayConfiguration(const TDisplayConfiguration& aDisplayConfiguration):
211 TDisplayConfigurationTop(TDisplayConfiguration().Version())
213 TInt tempSize = aDisplayConfiguration.Version();
214 if (tempSize > TDisplayConfiguration().Version())
216 tempSize = TDisplayConfiguration().Version();
218 Mem::Copy(this, &aDisplayConfiguration, tempSize);
219 //This has copied size for higher version features...
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);
229 inline TDisplayConfiguration::TDisplayConfiguration(TInt aVersion):
230 TDisplayConfigurationTop(aVersion)
232 if (TDisplayConfiguration().Version() > aVersion)
238 #endif // _DISPLAYCONFIGURATION__INCLUDED_