|
1 // Copyright (c) 1997-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 #include <gulalign.h> |
|
17 #include <gulpanic.h> |
|
18 #include "GULSTD.H" |
|
19 |
|
20 #if No_Compiler_Bug |
|
21 #if (EHLeft!=ELeft || EHCenter!=ECenter || EHRight!=ERight) |
|
22 #error "GDI enum values have changed" |
|
23 #endif |
|
24 #endif |
|
25 |
|
26 |
|
27 /** Gets the (absolute) alignment value as @c TGulAlignmentValue. |
|
28 |
|
29 Note that this has the absolute horizontal alignment. I.e. left and right |
|
30 horizontal alignment will not be swapped depending on language directionality. |
|
31 */ |
|
32 EXPORT_C TGulAlignment::operator TGulAlignmentValue() const |
|
33 {return static_cast<TGulAlignmentValue>(iValue&(EHMask|EVMask));} |
|
34 |
|
35 |
|
36 /** |
|
37 Return whether horizontal alignment will be treated as an absolute value, |
|
38 or relative the specified language directionality. In the latter case, |
|
39 left and right will be swapped (by @c TGulAlignment methods for which a |
|
40 @c TBidiText::TDirectionality is provided) for languages with RightToLeft |
|
41 directionality. |
|
42 */ |
|
43 EXPORT_C TBool TGulAlignment::HasAbsoluteHAlignment() const |
|
44 { |
|
45 return (iValue&EHAbsoluteFlag); |
|
46 } |
|
47 |
|
48 /** |
|
49 Set the current horizontal alignment to be used as an absolute value. |
|
50 If set to true, this means that the alignment will NOT be swapped depending |
|
51 on language directionality when calling e.g. @c HAlignment(TBidiText::TDirectionality). |
|
52 |
|
53 Note that the default is false (i.e. relative alignment), and calling any |
|
54 of the setters on the @c TGulAlignment object will reset it to relative alignment |
|
55 (i.e. always call this method after the horizontal alignment has been set). |
|
56 |
|
57 Also note that support for absolute horizontal alignment was added to TGulAlignment |
|
58 late in Symbian OS release 9.1. Hence if this method is called on an object that is |
|
59 passed to a client compiled against an earlier release (or if the client does not yet |
|
60 support absolute alignment) then the resulting alignment may be incorrect. |
|
61 */ |
|
62 EXPORT_C void TGulAlignment::SetAbsoluteHAlignment(TBool aAbsoluteHAlignment) |
|
63 { |
|
64 if(aAbsoluteHAlignment) |
|
65 iValue |= EHAbsoluteFlag; |
|
66 else |
|
67 iValue &= ~EHAbsoluteFlag; |
|
68 } |
|
69 |
|
70 /** |
|
71 Return the horizontal alignment, relative to the language directionality specified. |
|
72 Calling this method will return a horizontal alignment where left and right has |
|
73 been swapped for any language with RightToLeft directionality, UNLESS the |
|
74 alignment has been set as being absolute, by calling @c SetAbsoluteHAlignment(). |
|
75 |
|
76 @param aLanguageDirectionality The language directionality to consider when swapping left and right. |
|
77 @return The horizontal alignment, taking language directionality into account. |
|
78 */ |
|
79 EXPORT_C TGulHAlignment TGulAlignment::HAlignment(TBidiText::TDirectionality aApplicationLanguageDirectionality) const |
|
80 { |
|
81 if((aApplicationLanguageDirectionality == TBidiText::ERightToLeft) && !(iValue&EHAbsoluteFlag) && ((iValue&EHMask) != EHCenter)) |
|
82 return ((iValue&EHMask) == EHLeft ? EHRight : EHLeft); |
|
83 else |
|
84 return static_cast<TGulHAlignment>(iValue&EHMask); |
|
85 } |
|
86 |
|
87 /** |
|
88 Return the horizontal alignment, relative to the language directionality specified. |
|
89 Calling this method will return a horizontal alignment where left and right has |
|
90 been swapped for any language with RightToLeft directionality, UNLESS the |
|
91 alignment has been set as being absolute, by calling @c SetAbsoluteHAlignment(). |
|
92 |
|
93 @param aLanguageDirectionality The language directionality to consider when swapping left and right. |
|
94 @return The horizontal alignment, taking language directionlity into account. |
|
95 */ |
|
96 EXPORT_C CGraphicsContext::TTextAlign TGulAlignment::TextAlign(TBidiText::TDirectionality aLanguageDirectionality) const |
|
97 { |
|
98 return static_cast<CGraphicsContext::TTextAlign>(HAlignment(aLanguageDirectionality)); |
|
99 } |
|
100 |
|
101 /** |
|
102 Return the horizontal alignment as a @c CParaFormat::TAlignment object. Note that the |
|
103 @c CParaFormat::TAlignment class supports the concept of horizontal absolute alignment, |
|
104 so left and right alignment will not be swapped. |
|
105 |
|
106 @return The horizontal alignment, including whether it's absolute or not. |
|
107 */ |
|
108 EXPORT_C CParaFormat::TAlignment TGulAlignment::ParaAlign() const |
|
109 { |
|
110 if(HAlignment() == EHLeft) |
|
111 return (HasAbsoluteHAlignment() ? CParaFormat::EAbsoluteLeftAlign : CParaFormat::ELeftAlign); |
|
112 else if(HAlignment() == EHRight) |
|
113 return (HasAbsoluteHAlignment() ? CParaFormat::EAbsoluteRightAlign : CParaFormat::ERightAlign); |
|
114 else |
|
115 return CParaFormat::ECenterAlign; |
|
116 } |
|
117 |
|
118 /** Sets the vertical alignment. |
|
119 |
|
120 @param aVAlign The vertical alignment. */ |
|
121 EXPORT_C void TGulAlignment::SetVAlignment(TGulVAlignment aVAlign) |
|
122 { |
|
123 const TInt allButVAlign = iValue&(~EVMask); |
|
124 iValue = (allButVAlign|aVAlign); |
|
125 } |
|
126 |
|
127 /** Sets the horizontal alignment. Alignment will be reset to relative. I.e. when calling |
|
128 @c HAlignment() with a @c TBidiText::ERightToLeft argument, left and right will be swapped. |
|
129 Calling @c HAlignment() without argument will always return the alignment in absolute terms. |
|
130 |
|
131 @param aHAlign The horizontal alignment. */ |
|
132 EXPORT_C void TGulAlignment::SetHAlignment(TGulHAlignment aHAlign) |
|
133 { |
|
134 const TInt allButHAlign = iValue&(~EHMask); |
|
135 iValue = (allButHAlign|aHAlign); |
|
136 SetAbsoluteHAlignment(EFalse); // Reset the horizintal alignment to relative app language |
|
137 } |
|
138 |
|
139 /** Sets the horizontal alignment. Alignment will be reset to relative. I.e. when calling |
|
140 @c HAlignment() with a @c TBidiText::ERightToLeft argument, left and right will be swapped. |
|
141 Calling @c HAlignment() without argument will always return the alignment in absolute terms. |
|
142 |
|
143 @param aHAlign The horizontal alignment. */ |
|
144 EXPORT_C void TGulAlignment::SetHAlignment(CGraphicsContext::TTextAlign aHAlign) |
|
145 { |
|
146 SetHAlignment(static_cast<TGulHAlignment>(aHAlign)); // CGraphicsContext::TTextAlign has the same values as TGulHAlignment |
|
147 // Abosolute alignment flag set to false by the call above. |
|
148 } |
|
149 |
|
150 /** Sets the horizontal alignment. Alignment will be set to absolute for @c EAbsoluteLeftAlign |
|
151 and @c EAbsoluteRightAlign, otherwise relative the language directionality (if specified). |
|
152 |
|
153 @param aHAlign The horizontal alignment. */ |
|
154 EXPORT_C void TGulAlignment::SetHAlignment(CParaFormat::TAlignment aHAlign) |
|
155 { |
|
156 const TInt allButHAlign = iValue&(~EHMask); |
|
157 |
|
158 switch(aHAlign) |
|
159 { |
|
160 case CParaFormat::ELeftAlign: |
|
161 iValue = (allButHAlign|EHLeft); |
|
162 SetAbsoluteHAlignment(EFalse); |
|
163 break; |
|
164 case CParaFormat::ERightAlign: |
|
165 iValue = (allButHAlign|EHRight); |
|
166 SetAbsoluteHAlignment(EFalse); |
|
167 break; |
|
168 case CParaFormat::EAbsoluteLeftAlign: |
|
169 iValue = (allButHAlign|EHLeft); |
|
170 SetAbsoluteHAlignment(ETrue); |
|
171 break; |
|
172 case CParaFormat::EAbsoluteRightAlign: |
|
173 iValue = (allButHAlign|EHRight); |
|
174 SetAbsoluteHAlignment(ETrue); |
|
175 break; |
|
176 default: |
|
177 __ASSERT_DEBUG(0, Panic(EEgulPanicCParaFormatAlignementValueNotSupported)); |
|
178 } |
|
179 } |
|
180 |
|
181 |
|
182 /** Gets the co-ordinates of the top left corner of an object of size @c aInnerSize, |
|
183 which is placed in the area of the rectangle @c aOuter according to the current |
|
184 alignment. |
|
185 |
|
186 Note that horizontal alignment is always treated as being in absolute terms. |
|
187 |
|
188 @param aOuter The outer rectangle. |
|
189 @param aInnerSize The size of the inner rectangle. |
|
190 @return The inner top left point. */ |
|
191 EXPORT_C TPoint TGulAlignment::InnerTopLeft(const TRect& aOuter,const TSize& aInnerSize) const |
|
192 { |
|
193 return InnerTopLeft(aOuter, aInnerSize, TBidiText::ELeftToRight); |
|
194 } |
|
195 |
|
196 /** Gets the co-ordinates of the top left corner of an object of size @c aInnerSize, |
|
197 which is placed in the area of the rectangle @c aOuter according to the current |
|
198 alignment. |
|
199 |
|
200 Note that if RightToLeft language directionality is specified, left and right horizontal |
|
201 alignment for the inner object will be swapped. |
|
202 |
|
203 @param aOuter The outer rectangle. |
|
204 @param aInnerSize The size of the inner rectangle. |
|
205 @param aLanguageDirectionality The language directionality to consider when swapping left and right. |
|
206 @return The inner top left point. */ |
|
207 EXPORT_C TPoint TGulAlignment::InnerTopLeft(const TRect& aOuter, const TSize& aInnerSize, TBidiText::TDirectionality aLanguageDirectionality) const |
|
208 { |
|
209 TSize delta = aOuter.Size()-aInnerSize; |
|
210 switch (HAlignment(aLanguageDirectionality)) |
|
211 { |
|
212 case EHLeft: |
|
213 delta.iWidth=0; |
|
214 break; |
|
215 case EHCenter: |
|
216 delta.iWidth>>=1; // div 2 |
|
217 break; |
|
218 default: |
|
219 break; |
|
220 } |
|
221 |
|
222 switch (VAlignment()) |
|
223 { |
|
224 case EVTop: |
|
225 delta.iHeight=0; |
|
226 break; |
|
227 case EVCenter: |
|
228 delta.iHeight>>=1; // div 2 |
|
229 break; |
|
230 default: |
|
231 break; |
|
232 } |
|
233 |
|
234 return(aOuter.iTl+delta); |
|
235 } |
|
236 |
|
237 /** Gets the rectangle occupied by an object of size @c aInnerSize, which is placed |
|
238 in the area of the rectangle @c aOuter according to the current alignment. |
|
239 |
|
240 Note that horizontal alignment is always treated as being in absolute terms. |
|
241 |
|
242 @param aOuter The outer rectangle. |
|
243 @param aInnerSize The size of the inner rectangle. |
|
244 @return The rectangle. */ |
|
245 EXPORT_C TRect TGulAlignment::InnerRect(const TRect& aOuter, const TSize& aInnerSize) const |
|
246 { |
|
247 return InnerRect(aOuter, aInnerSize, TBidiText::ELeftToRight); |
|
248 } |
|
249 |
|
250 /** Gets the rectangle occupied by an object of size @c aInnerSize, which is placed |
|
251 in the area of the rectangle @c aOuter according to the current alignment. |
|
252 |
|
253 Note that if RightToLeft language directionality is specified, left and right horizontal |
|
254 alignment for the inner object will be swapped. |
|
255 |
|
256 @param aOuter The outer rectangle. |
|
257 @param aInnerSize The size of the inner rectangle. |
|
258 @param aLanguageDirectionality The language directionality to consider when swapping left and right. |
|
259 @return The rectangle. */ |
|
260 EXPORT_C TRect TGulAlignment::InnerRect(const TRect& aOuter, const TSize& aInnerSize, TBidiText::TDirectionality aLanguageDirectionality) const |
|
261 { |
|
262 const TSize outerSize = aOuter.Size(); |
|
263 TSize clippedInner = aInnerSize; |
|
264 if (clippedInner.iWidth > outerSize.iWidth) |
|
265 clippedInner.iWidth = outerSize.iWidth; |
|
266 |
|
267 if (clippedInner.iHeight > outerSize.iHeight) |
|
268 clippedInner.iHeight = outerSize.iHeight; |
|
269 |
|
270 return(TRect(InnerTopLeft(aOuter,clippedInner,aLanguageDirectionality), clippedInner)); |
|
271 } |
|
272 |
|
273 |