34
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2006 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: Implementation for wrapper for a label
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <coecntrl.h>
|
|
21 |
#include <barsread.h>
|
|
22 |
#include <gulcolor.h>
|
|
23 |
#include <utf.h>
|
|
24 |
|
|
25 |
#include <AknsUtils.h>
|
|
26 |
#include <AknPictographInterface.h> // for japanese variants.
|
|
27 |
#include <AknBidiTextUtils.h>
|
|
28 |
#include <AknUtils.h>
|
|
29 |
#include <AknLayoutFont.h>
|
|
30 |
|
|
31 |
#include "xnnodepluginif.h"
|
|
32 |
#include "xndompropertyvalue.h"
|
|
33 |
#include "xndomproperty.h"
|
|
34 |
#include "xndomlist.h"
|
|
35 |
#include "xnproperty.h"
|
|
36 |
#include "xncomponent.h"
|
|
37 |
#include "xnuienginepluginif.h"
|
|
38 |
#include "xncomponent.h"
|
|
39 |
#include "xncontroladapter.h"
|
|
40 |
#include "c_xnutils.h"
|
|
41 |
#include "xntype.h"
|
|
42 |
#include "xntextadapter.h"
|
|
43 |
#include "xncomponentnodeimpl.h"
|
|
44 |
#include "xnviewnodeimpl.h"
|
|
45 |
#include "xneditmode.h"
|
|
46 |
|
|
47 |
namespace XnText
|
|
48 |
{
|
|
49 |
const TUint8 KClip = 0x01;
|
|
50 |
const TUint8 KEllipse = 0x02;
|
|
51 |
const TUint8 KWrap = 0x04;
|
|
52 |
const TUint8 KOverflowVisible = 0x08;
|
|
53 |
const TUint8 KLtr = 0x10;
|
|
54 |
const TUint8 KConstructText = 0x20;
|
|
55 |
|
|
56 |
_LIT8( tooltip, "tooltip" );
|
|
57 |
_LIT8( clock, "clock" );
|
|
58 |
}
|
|
59 |
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
// IsBitSet
|
|
62 |
// Test whether bit is set in a flag
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
static TBool IsBitSet(TUint8 aBit,TUint8 aFlag)
|
|
65 |
{
|
|
66 |
return ( aFlag & aBit );
|
|
67 |
}
|
|
68 |
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
// SetLabelTextL
|
|
71 |
// Prepares text to label, wraps or clips if needed
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
static void SetLabelTextL( CEikLabel& aLabel, const TDesC& aSource, TInt aMaxLineWidth,
|
|
74 |
TInt aMaxLines, TUint8 aFlags, TBool aMeasureOnly = EFalse )
|
|
75 |
{
|
|
76 |
// By default, let the label do the logical to visual conversion
|
|
77 |
TBool conversion( ETrue );
|
|
78 |
|
|
79 |
if( IsBitSet( XnText::KOverflowVisible, aFlags ) || aSource == KNullDesC )
|
|
80 |
{
|
|
81 |
// no clipping or wrapping needed if,
|
|
82 |
// overflow is visible
|
|
83 |
// no text or no space,
|
|
84 |
// or text fits to given space
|
|
85 |
aLabel.SetTextL( aSource );
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{
|
|
89 |
AknBidiTextUtils::TParagraphDirectionality dir( AknBidiTextUtils::EImplicit );
|
|
90 |
|
|
91 |
const CFont* font( aLabel.Font() );
|
|
92 |
|
|
93 |
HBufC* buffer( NULL );
|
|
94 |
|
|
95 |
if( IsBitSet( XnText::KEllipse, aFlags ) )
|
|
96 |
{
|
|
97 |
buffer = aSource.AllocLC();
|
|
98 |
|
|
99 |
TPtr ptr( buffer->Des() );
|
|
100 |
|
|
101 |
AknBidiTextUtils::ConvertToVisualAndClipL(
|
|
102 |
ptr, *font, aMaxLineWidth, aMaxLineWidth, dir );
|
|
103 |
|
|
104 |
|
|
105 |
// The text is already in visual form, no need for conversion
|
|
106 |
conversion = EFalse;
|
|
107 |
|
|
108 |
aLabel.SetTextL( *buffer );
|
|
109 |
|
|
110 |
CleanupStack::PopAndDestroy( buffer );
|
|
111 |
}
|
|
112 |
else if( IsBitSet( XnText::KWrap, aFlags ) )
|
|
113 |
{
|
|
114 |
if( aMaxLines > 0 )
|
|
115 |
{
|
|
116 |
CArrayFixFlat< TInt >* array = new ( ELeave ) CArrayFixFlat< TInt >( 8 );
|
|
117 |
CleanupStack::PushL( array );
|
|
118 |
|
|
119 |
for( TInt i = 0; i < aMaxLines; i++ )
|
|
120 |
{
|
|
121 |
array->AppendL( aMaxLineWidth );
|
|
122 |
}
|
|
123 |
|
|
124 |
buffer = HBufC::NewLC( aSource.Length() + aMaxLines *
|
|
125 |
( KAknBidiExtraSpacePerLine + 1 ) );
|
|
126 |
|
|
127 |
TPtr ptr( buffer->Des() );
|
|
128 |
|
|
129 |
AknBidiTextUtils::ConvertToVisualAndWrapToStringL(
|
|
130 |
aSource, *array, *font, ptr, ETrue, dir );
|
|
131 |
}
|
|
132 |
else
|
|
133 |
{
|
|
134 |
CArrayFixFlat< TPtrC >* array = new ( ELeave ) CArrayFixFlat< TPtrC >( 8 );
|
|
135 |
CleanupStack::PushL( array );
|
|
136 |
|
|
137 |
HBufC* temp = AknBidiTextUtils::ConvertToVisualAndWrapToArrayL(
|
|
138 |
aSource, aMaxLineWidth, *font, *array, dir );
|
|
139 |
|
|
140 |
CleanupStack::PushL( temp );
|
|
141 |
|
|
142 |
TInt lineCount( array->Count() );
|
|
143 |
|
|
144 |
TInt bufLen = temp->Length() + ( lineCount - 1 );
|
|
145 |
if ( bufLen > 0 )
|
|
146 |
{
|
|
147 |
buffer = HBufC::NewLC( bufLen );
|
|
148 |
|
|
149 |
TPtr ptr( buffer->Des() );
|
|
150 |
|
|
151 |
for( TInt i = 0; i < lineCount; i++ )
|
|
152 |
{
|
|
153 |
TPtrC line( array->At( i ) );
|
|
154 |
|
|
155 |
ptr.Append( line );
|
|
156 |
|
|
157 |
if( i + 1 < lineCount )
|
|
158 |
{
|
|
159 |
ptr.Append( '\n' );
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
|
163 |
CleanupStack::Pop();
|
|
164 |
CleanupStack::PopAndDestroy( temp );
|
|
165 |
CleanupStack::PushL( buffer );
|
|
166 |
}
|
|
167 |
else
|
|
168 |
{
|
|
169 |
CleanupStack::PopAndDestroy( temp );
|
|
170 |
}
|
|
171 |
}
|
|
172 |
|
|
173 |
// The text is already in visual form, no need for conversion
|
|
174 |
conversion = EFalse;
|
|
175 |
|
|
176 |
if ( buffer )
|
|
177 |
{
|
|
178 |
aLabel.SetTextL( *buffer );
|
|
179 |
CleanupStack::PopAndDestroy( buffer );
|
|
180 |
}
|
|
181 |
|
|
182 |
CleanupStack::PopAndDestroy(); // array
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
aLabel.SetTextL( aSource );
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
if( !aMeasureOnly )
|
|
191 |
{
|
|
192 |
// Text is truly set, set conversion and defer draw
|
|
193 |
aLabel.UseLogicalToVisualConversion( conversion );
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
// -----------------------------------------------------------------------------
|
|
198 |
// CopyBitmapData
|
|
199 |
// Copies a data from source bitmap to target bitmap.
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
static TInt CopyBitmapData(
|
|
203 |
CFbsBitmap& aTarget,
|
|
204 |
const CFbsBitmap& aSource,
|
|
205 |
TPoint aSourcePoint)
|
|
206 |
{
|
|
207 |
TSize targetSize(aTarget.SizeInPixels());
|
|
208 |
TSize sourceSize(aSource.SizeInPixels());
|
|
209 |
TInt lineLength(targetSize.iWidth);
|
|
210 |
TInt maxSourceLineLength(sourceSize.iWidth - aSourcePoint.iX);
|
|
211 |
if(lineLength > maxSourceLineLength)
|
|
212 |
{
|
|
213 |
lineLength = maxSourceLineLength;
|
|
214 |
}
|
|
215 |
TInt rowCount(targetSize.iHeight);
|
|
216 |
TInt maxSourceRowCount(sourceSize.iHeight - aSourcePoint.iY);
|
|
217 |
if(rowCount > maxSourceRowCount)
|
|
218 |
{
|
|
219 |
rowCount = maxSourceRowCount;
|
|
220 |
}
|
|
221 |
|
|
222 |
// Get bitmap display mode
|
|
223 |
TDisplayMode displayMode(aSource.DisplayMode());
|
|
224 |
|
|
225 |
// Create buffer for a scan line
|
|
226 |
HBufC8* scanLine = HBufC8::New(
|
|
227 |
aSource.ScanLineLength(lineLength, displayMode));
|
|
228 |
if(!scanLine)
|
|
229 |
{
|
|
230 |
return KErrNoMemory;
|
|
231 |
}
|
|
232 |
|
|
233 |
TPtr8 scanPtr(scanLine->Des());
|
|
234 |
|
|
235 |
// Copy all rows to destination bitmap
|
|
236 |
for(TInt row(0); row < rowCount; row++)
|
|
237 |
{
|
|
238 |
aSource.GetScanLine(scanPtr,
|
|
239 |
TPoint(aSourcePoint.iX, aSourcePoint.iY + row),
|
|
240 |
lineLength, displayMode);
|
|
241 |
aTarget.SetScanLine(scanPtr, row);
|
|
242 |
}
|
|
243 |
delete scanLine;
|
|
244 |
return KErrNone;
|
|
245 |
}
|
|
246 |
|
|
247 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
248 |
|
|
249 |
// -----------------------------------------------------------------------------
|
|
250 |
// CXnTextAdapter::NewL
|
|
251 |
// Symbian static 1st phase constructor
|
|
252 |
// -----------------------------------------------------------------------------
|
|
253 |
//
|
|
254 |
CXnTextAdapter* CXnTextAdapter::NewL(CXnControlAdapter* aParent, CXnNodePluginIf& aNode)
|
|
255 |
{
|
|
256 |
CXnTextAdapter* self = new( ELeave ) CXnTextAdapter( aParent, aNode );
|
|
257 |
|
|
258 |
CleanupStack::PushL( self );
|
|
259 |
self->ConstructL();
|
|
260 |
CleanupStack::Pop();
|
|
261 |
|
|
262 |
return self;
|
|
263 |
}
|
|
264 |
|
|
265 |
// -----------------------------------------------------------------------------
|
|
266 |
// CXnTextAdapter::CXnTextAdapter
|
|
267 |
// C++ default constructor
|
|
268 |
// -----------------------------------------------------------------------------
|
|
269 |
//
|
|
270 |
CXnTextAdapter::CXnTextAdapter(CXnControlAdapter* aParent, CXnNodePluginIf& aNode)
|
|
271 |
: iParent( aParent ), iNode( aNode )
|
|
272 |
{
|
|
273 |
}
|
|
274 |
|
|
275 |
// -----------------------------------------------------------------------------
|
|
276 |
// CXnTextAdapter::~CXnTextAdapter
|
|
277 |
// C++ destructor
|
|
278 |
// -----------------------------------------------------------------------------
|
|
279 |
//
|
|
280 |
CXnTextAdapter::~CXnTextAdapter()
|
|
281 |
{
|
|
282 |
delete iLabel;
|
|
283 |
|
|
284 |
delete iText;
|
|
285 |
|
|
286 |
if( iFont && iReleaseFont )
|
|
287 |
{
|
|
288 |
CWsScreenDevice* dev = iCoeEnv->ScreenDevice();
|
|
289 |
dev->ReleaseFont( iFont );
|
|
290 |
}
|
|
291 |
|
|
292 |
if( iPictographInterface )
|
|
293 |
{
|
|
294 |
delete iPictographInterface;
|
|
295 |
}
|
|
296 |
|
|
297 |
delete iBackgroundBitmap;
|
|
298 |
}
|
|
299 |
|
|
300 |
// -----------------------------------------------------------------------------
|
|
301 |
// CXnTextAdapter::ConstructL
|
|
302 |
// Symbian 2nd phase constructor can leave.
|
|
303 |
// -----------------------------------------------------------------------------
|
|
304 |
//
|
|
305 |
void CXnTextAdapter::ConstructL()
|
|
306 |
{
|
|
307 |
iGc = &SystemGc();
|
|
308 |
|
|
309 |
iLabel = new ( ELeave ) CEikLabel;
|
|
310 |
iLabel->SetContainerWindowL( *iParent );
|
|
311 |
iLabel->SetTextL( KNullDesC );
|
|
312 |
|
|
313 |
CXnControlAdapter::ConstructL( iNode );
|
|
314 |
|
|
315 |
iPictographInterface = CAknPictographInterface::NewL( *iLabel, *this );
|
|
316 |
iLabel->EnablePictographsL( *iPictographInterface );
|
|
317 |
|
|
318 |
SetTextPropertiesL( iNode );
|
|
319 |
UpdateTextL( iNode.GetPCData() );
|
|
320 |
}
|
|
321 |
|
|
322 |
// -----------------------------------------------------------------------------
|
|
323 |
// CXnTextAdapter::ConstructTextL
|
|
324 |
// Construct the text component according to properties.
|
|
325 |
// -----------------------------------------------------------------------------
|
|
326 |
//
|
|
327 |
void CXnTextAdapter::ConstructTextL()
|
|
328 |
{
|
|
329 |
if( !iText )
|
|
330 |
{
|
|
331 |
// CEikLabel will panic in ::Draw if text is not set
|
|
332 |
SetLabelTextL( *iLabel, KNullDesC, 0, 0, 0 );
|
|
333 |
return;
|
|
334 |
}
|
|
335 |
|
|
336 |
if( !( iFlags & XnText::KConstructText ) )
|
|
337 |
{
|
|
338 |
return;
|
|
339 |
}
|
|
340 |
|
|
341 |
TRect rect( iNode.Rect() );
|
|
342 |
|
|
343 |
SetLineSpacingL( rect.Height() );
|
|
344 |
|
|
345 |
TInt flags( iFlags );
|
|
346 |
|
|
347 |
// Now we must restrict side into parent
|
|
348 |
flags = RestrictSizeL();
|
|
349 |
|
|
350 |
SetLabelTextL( *iLabel, *iText, iLabel->Rect().Width(), iMaxLines, flags );
|
|
351 |
}
|
|
352 |
|
|
353 |
// -----------------------------------------------------------------------------
|
|
354 |
// CXnTextAdapter::SetTextPropertiesL
|
|
355 |
// Sets text properties, such as color, font, etc.
|
|
356 |
// (other items were commented in a header).
|
|
357 |
// -----------------------------------------------------------------------------
|
|
358 |
//
|
|
359 |
TBool CXnTextAdapter::SetTextPropertiesL( CXnNodePluginIf& aNode )
|
|
360 |
{
|
|
361 |
// Store current state
|
|
362 |
const CFont* font( iFont );
|
|
363 |
TInt flags( iFlags );
|
|
364 |
TInt maxLines( iMaxLines );
|
|
365 |
|
|
366 |
if( iFont && iReleaseFont )
|
|
367 |
{
|
|
368 |
CWsScreenDevice* dev = iCoeEnv->ScreenDevice();
|
|
369 |
dev->ReleaseFont( iFont );
|
|
370 |
iFont = NULL;
|
|
371 |
}
|
|
372 |
|
|
373 |
// Find out the font and set it
|
|
374 |
CXnUtils::CreateFontL( aNode, iFont, iReleaseFont );
|
|
375 |
iLabel->SetFont( iFont );
|
|
376 |
|
|
377 |
// Turn off all graphic context effects
|
|
378 |
iLabel->SetUnderlining( EFalse );
|
|
379 |
iLabel->SetStrikethrough( EFalse );
|
|
380 |
|
|
381 |
//following data types are used due to we are handling text via CEikLabel instead of direct
|
|
382 |
//font color and effects manipulation via graphics context.
|
|
383 |
//We manipulate pen and brush colors indirectly via
|
|
384 |
//Label's OverrideColorL method applying EColorControlBackground and EColorLabelText parameters
|
|
385 |
//with corresponding RGB value.
|
|
386 |
TRgb textColor;
|
|
387 |
TRgb effectsColor;
|
|
388 |
TBool textColorSet( EFalse );
|
|
389 |
TBool effectsColorSet( EFalse );
|
|
390 |
TBool effectsDevColorSet( EFalse );
|
|
391 |
|
|
392 |
CXnProperty* colorProperty = aNode.GetPropertyL( XnPropertyNames::appearance::common::KColor );
|
|
393 |
|
|
394 |
if( colorProperty != NULL )
|
|
395 |
{
|
|
396 |
CXnDomProperty* domProperty = colorProperty->Property();
|
|
397 |
|
|
398 |
if( domProperty )
|
|
399 |
{
|
|
400 |
TInt error( KErrNotSupported );
|
|
401 |
|
|
402 |
CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >
|
|
403 |
( domProperty->PropertyValueList().Item( 0 ) );
|
|
404 |
|
|
405 |
if( value->IsAutoIdent() )
|
|
406 |
{
|
|
407 |
MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
|
|
408 |
error = AknsUtils::GetCachedColor(skinInstance, textColor, KAknsIIDQsnTextColors,
|
|
409 |
EAknsCIQsnTextColorsCG6);
|
|
410 |
}
|
|
411 |
else if( value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor )
|
|
412 |
{
|
|
413 |
textColor = value->RgbColorValueL();
|
|
414 |
error = KErrNone;
|
|
415 |
}
|
|
416 |
else
|
|
417 |
{
|
|
418 |
HBufC* colorString = colorProperty->StringValueL();
|
|
419 |
CleanupStack::PushL( colorString );
|
|
420 |
|
|
421 |
CXnUtils::StripQuotes( colorString );
|
|
422 |
|
|
423 |
TInt index = 0;
|
|
424 |
TAknsItemID skinID;
|
|
425 |
|
|
426 |
TBool idResolved = CXnUtils::ResolveSkinItemIDL( colorString->Des(), skinID, index );
|
|
427 |
|
|
428 |
if( idResolved )
|
|
429 |
{
|
|
430 |
MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
|
|
431 |
error = AknsUtils::GetCachedColor( skinInstance, textColor, skinID, index );
|
|
432 |
}
|
|
433 |
else // use auto value if skin id is invalid.
|
|
434 |
{
|
|
435 |
MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
|
|
436 |
error = AknsUtils::GetCachedColor(skinInstance, textColor, KAknsIIDQsnTextColors,
|
|
437 |
EAknsCIQsnTextColorsCG6);
|
|
438 |
}
|
|
439 |
CleanupStack::PopAndDestroy( colorString );
|
|
440 |
}
|
|
441 |
if (error == KErrNone)
|
|
442 |
{
|
|
443 |
textColorSet = ETrue;
|
|
444 |
}
|
|
445 |
}
|
|
446 |
}
|
|
447 |
|
|
448 |
CXnProperty* effectsProperty = aNode.GetPropertyL(XnPropertyNames::appearance::common::KTextEffects);
|
|
449 |
if ( effectsProperty )
|
|
450 |
{
|
|
451 |
TInt error(KErrNotSupported);
|
|
452 |
effectsDevColorSet = ETrue; //some color needed, device color by default
|
|
453 |
CXnProperty* effectsColorProperty = aNode.GetPropertyL(XnPropertyNames::appearance::common::KEffectsColor);
|
|
454 |
if (effectsColorProperty)
|
|
455 |
{
|
|
456 |
CXnDomProperty* domProperty = effectsColorProperty->Property();
|
|
457 |
if( domProperty )
|
|
458 |
{
|
|
459 |
CXnDomPropertyValue* value = static_cast<CXnDomPropertyValue*>(domProperty->PropertyValueList().Item(0));
|
|
460 |
if (value->IsAutoIdent())
|
|
461 |
{
|
|
462 |
MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
|
|
463 |
error = AknsUtils::GetCachedColor(skinInstance, effectsColor, KAknsIIDQsnTextColors,
|
|
464 |
EAknsCIQsnTextColorsCG6);
|
|
465 |
}
|
|
466 |
else if (value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor)
|
|
467 |
{
|
|
468 |
effectsColor = value->RgbColorValueL();
|
|
469 |
error = KErrNone;
|
|
470 |
}
|
|
471 |
else
|
|
472 |
{
|
|
473 |
HBufC* colorString = effectsColorProperty->StringValueL();
|
|
474 |
CleanupStack::PushL( colorString );
|
|
475 |
CXnUtils::StripQuotes( colorString );
|
|
476 |
|
|
477 |
TInt index = 0;
|
|
478 |
TAknsItemID skinID;
|
|
479 |
|
|
480 |
TBool idResolved = CXnUtils::ResolveSkinItemIDL( colorString->Des(), skinID, index );
|
|
481 |
if( idResolved )
|
|
482 |
{
|
|
483 |
MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
|
|
484 |
error = AknsUtils::GetCachedColor( skinInstance, effectsColor, skinID, index );
|
|
485 |
}
|
|
486 |
else // use auto value if skin id is invalid.
|
|
487 |
{
|
|
488 |
MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
|
|
489 |
error = AknsUtils::GetCachedColor(skinInstance, effectsColor, KAknsIIDQsnTextColors,
|
|
490 |
EAknsCIQsnTextColorsCG6);
|
|
491 |
}
|
|
492 |
CleanupStack::PopAndDestroy( colorString );
|
|
493 |
}
|
|
494 |
if ( error == KErrNone )
|
|
495 |
{
|
|
496 |
effectsColorSet = ETrue; //theme color found
|
|
497 |
effectsDevColorSet = EFalse;//device color not needed
|
|
498 |
}
|
|
499 |
}
|
|
500 |
}
|
|
501 |
}
|
|
502 |
|
|
503 |
if ( textColorSet )
|
|
504 |
{
|
|
505 |
if ( effectsColorSet )
|
|
506 |
{//theme font color and theme effects color
|
|
507 |
iLabel->OverrideColorL(EColorControlBackground, textColor);
|
|
508 |
iLabel->OverrideColorL(EColorLabelText, effectsColor);
|
|
509 |
}
|
|
510 |
else if ( effectsDevColorSet )
|
|
511 |
{//theme font color and device effects color
|
|
512 |
iLabel->OverrideColorL(EColorControlBackground, textColor);
|
|
513 |
}
|
|
514 |
else
|
|
515 |
{//theme font color, but no effects defined
|
|
516 |
iLabel->OverrideColorL(EColorLabelText, textColor);
|
|
517 |
}
|
|
518 |
}
|
|
519 |
else if ( effectsColorSet )
|
|
520 |
{//device font color and theme effects color
|
|
521 |
iLabel->OverrideColorL(EColorLabelText, effectsColor);
|
|
522 |
}//else device font color and device effects color (default)
|
|
523 |
|
|
524 |
CXnProperty* textDecorationProp = aNode.GetPropertyL( XnPropertyNames::appearance::common::KTextDecoration );
|
|
525 |
|
|
526 |
if( textDecorationProp )
|
|
527 |
{
|
|
528 |
CXnDomList& propertyValueList = textDecorationProp->Property()->PropertyValueList();
|
|
529 |
|
|
530 |
TInt valueCount = propertyValueList.Length();
|
|
531 |
|
|
532 |
for( TInt i = 0; i < valueCount; ++i )
|
|
533 |
{
|
|
534 |
CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >( propertyValueList.Item( i ) );
|
|
535 |
|
|
536 |
if( value->StringValueL() == XnPropertyNames::appearance::common::textdecoration::KUnderline )
|
|
537 |
{
|
|
538 |
iLabel->SetUnderlining( ETrue );
|
|
539 |
}
|
|
540 |
|
|
541 |
if( value->StringValueL() == XnPropertyNames::appearance::common::textdecoration::KLinethrough )
|
|
542 |
{
|
|
543 |
iLabel->SetStrikethrough( ETrue );
|
|
544 |
}
|
|
545 |
}
|
|
546 |
}
|
|
547 |
|
|
548 |
iFlags = 0;
|
|
549 |
iFlags |= XnText::KEllipse; //default
|
|
550 |
iFlags |= XnText::KLtr;
|
|
551 |
iMaxLines = 0;
|
|
552 |
|
|
553 |
TGulAlignmentValue alignment = CXnUtils::TextAlignment( aNode );
|
|
554 |
|
|
555 |
TInt labelAlignment( ELayoutAlignLeft ); // all are vertically top aligned by default (avkon)
|
|
556 |
|
|
557 |
switch( alignment )
|
|
558 |
{
|
|
559 |
case EHCenterVCenter:
|
|
560 |
labelAlignment = ELayoutAlignCenter;
|
|
561 |
break;
|
|
562 |
case EHRightVCenter:
|
|
563 |
labelAlignment = ELayoutAlignRight;
|
|
564 |
break;
|
|
565 |
default:
|
|
566 |
break;
|
|
567 |
}
|
|
568 |
|
|
569 |
iLabel->SetLabelAlignment( labelAlignment ); // avkon extension needs this, it modifys horizontal alignment
|
|
570 |
iLabel->SetAlignment( alignment ); // call to have vertical alignment
|
|
571 |
|
|
572 |
CXnProperty* direction = iNode.GetPropertyL( XnPropertyNames::style::common::KDirection );
|
|
573 |
const TDesC8* directionValue = &XnPropertyNames::style::common::direction::KLTR;
|
|
574 |
|
|
575 |
if( direction )
|
|
576 |
{
|
|
577 |
directionValue = &direction->StringValue();
|
|
578 |
}
|
|
579 |
|
|
580 |
if( *directionValue == XnPropertyNames::style::common::direction::KRTL )
|
|
581 |
{
|
|
582 |
iLabel->SetLabelAlignment( ELayoutAlignBidi );
|
|
583 |
iFlags &= ~XnText::KLtr;
|
|
584 |
}
|
|
585 |
|
|
586 |
CXnProperty* overflowProp = aNode.GetPropertyL( XnPropertyNames::appearance::common::KTextOverflowMode );
|
|
587 |
|
|
588 |
if( overflowProp )
|
|
589 |
{
|
|
590 |
CXnDomList& propertyValueList = overflowProp->Property()->PropertyValueList();
|
|
591 |
|
|
592 |
TInt valueCount = propertyValueList.Length();
|
|
593 |
|
|
594 |
for( TInt i = 0; i < valueCount; ++i )
|
|
595 |
{
|
|
596 |
CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >( propertyValueList.Item( i ) );
|
|
597 |
|
|
598 |
if( value->StringValueL() == XnPropertyNames::appearance::common::textoverflow::KClipMode )
|
|
599 |
{
|
|
600 |
iFlags |= XnText::KClip;
|
|
601 |
iFlags &= ~XnText::KWrap;
|
|
602 |
iFlags &= ~XnText::KEllipse;
|
|
603 |
}
|
|
604 |
else if( value->StringValueL() == XnPropertyNames::appearance::common::textoverflow::KWrapMode )
|
|
605 |
{
|
|
606 |
iFlags |= XnText::KWrap;
|
|
607 |
iFlags &= ~XnText::KClip;
|
|
608 |
iFlags &= ~XnText::KEllipse;
|
|
609 |
}
|
|
610 |
}
|
|
611 |
|
|
612 |
//Get max lines amount for wrap
|
|
613 |
if( iFlags & XnText::KWrap )
|
|
614 |
{
|
|
615 |
CXnProperty* maxlinesProp = aNode.GetPropertyL( XnPropertyNames::appearance::common::textoverflow::KMaxLineAmount );
|
|
616 |
|
|
617 |
if( maxlinesProp )
|
|
618 |
{
|
|
619 |
iMaxLines = static_cast< TInt >( maxlinesProp->FloatValueL() );
|
|
620 |
}
|
|
621 |
}
|
|
622 |
}
|
|
623 |
|
|
624 |
CXnProperty* overflowProperty = iNode.GetPropertyL( XnPropertyNames::style::common::KOverflow );
|
|
625 |
|
|
626 |
if( overflowProperty )
|
|
627 |
{
|
|
628 |
const TDesC8& overflowValue = overflowProperty->StringValue();
|
|
629 |
|
|
630 |
if( overflowValue == XnPropertyNames::style::common::visibility::KVisible )
|
|
631 |
{
|
|
632 |
iFlags |= XnText::KOverflowVisible;
|
|
633 |
}
|
|
634 |
}
|
|
635 |
|
|
636 |
if( flags & XnText::KConstructText )
|
|
637 |
{
|
|
638 |
iFlags |= XnText::KConstructText;
|
|
639 |
}
|
|
640 |
|
|
641 |
if( font != iFont || flags != iFlags || maxLines != iMaxLines )
|
|
642 |
{
|
|
643 |
return ETrue;
|
|
644 |
}
|
|
645 |
|
|
646 |
return EFalse;
|
|
647 |
}
|
|
648 |
|
|
649 |
// -----------------------------------------------------------------------------
|
|
650 |
// CXnTextAdapter::SetTextL
|
|
651 |
// Sets the new content to the underlying CEikLabel
|
|
652 |
// -----------------------------------------------------------------------------
|
|
653 |
//
|
|
654 |
void CXnTextAdapter::SetTextL( const TDesC& aText )
|
|
655 |
{
|
|
656 |
UpdateTextL( &aText );
|
|
657 |
}
|
|
658 |
|
|
659 |
// -----------------------------------------------------------------------------
|
|
660 |
// CXnTextAdapter::Text
|
|
661 |
// Returns the text contained in the underlying CEikLabel
|
|
662 |
// -----------------------------------------------------------------------------
|
|
663 |
//
|
|
664 |
const TDesC* CXnTextAdapter::Text() const
|
|
665 |
{
|
|
666 |
if( iFlags & XnText::KConstructText )
|
|
667 |
{
|
|
668 |
return iText;
|
|
669 |
}
|
|
670 |
else
|
|
671 |
{
|
|
672 |
return iLabel->Text();
|
|
673 |
}
|
|
674 |
}
|
|
675 |
|
|
676 |
// -----------------------------------------------------------------------------
|
|
677 |
// CXnTextAdapter::CountComponentControls
|
|
678 |
// Returns the number of component controls.
|
|
679 |
// -----------------------------------------------------------------------------
|
|
680 |
//
|
|
681 |
TInt CXnTextAdapter::CountComponentControls() const
|
|
682 |
{
|
|
683 |
return 1;
|
|
684 |
}
|
|
685 |
|
|
686 |
// -----------------------------------------------------------------------------
|
|
687 |
// CXnTextAdapter::ComponentControl
|
|
688 |
// Returns the component control of the given index
|
|
689 |
// -----------------------------------------------------------------------------
|
|
690 |
//
|
|
691 |
CCoeControl* CXnTextAdapter::ComponentControl(TInt aIndex) const
|
|
692 |
{
|
|
693 |
if( aIndex == 0 )
|
|
694 |
{
|
|
695 |
return iLabel;
|
|
696 |
}
|
|
697 |
|
|
698 |
return NULL;
|
|
699 |
}
|
|
700 |
|
|
701 |
// -----------------------------------------------------------------------------
|
|
702 |
// CXnTextAdapter::DoHandlePropertyChangeL
|
|
703 |
// -----------------------------------------------------------------------------
|
|
704 |
//
|
|
705 |
void CXnTextAdapter::DoHandlePropertyChangeL(CXnProperty* aProperty)
|
|
706 |
{
|
|
707 |
if( aProperty )
|
|
708 |
{
|
|
709 |
const TDesC8& name( aProperty->Property()->Name() );
|
|
710 |
|
|
711 |
if( name == XnPropertyNames::style::common::KDisplay ||
|
|
712 |
name == XnPropertyNames::style::common::KVisibility ||
|
|
713 |
name == XnPropertyNames::style::common::KWidth ||
|
|
714 |
name == XnPropertyNames::style::common::KHeight )
|
|
715 |
{
|
|
716 |
return;
|
|
717 |
}
|
|
718 |
|
|
719 |
if( name == XnPropertyNames::common::KPCData )
|
|
720 |
{
|
|
721 |
UpdateTextL( iNode.GetPCData() );
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
if( SetTextPropertiesL( iNode ) )
|
|
726 |
{
|
|
727 |
iFlags |= XnText::KConstructText;
|
|
728 |
}
|
|
729 |
}
|
|
730 |
|
|
731 |
// -----------------------------------------------------------------------------
|
|
732 |
// CXnTextAdapter::HandleResourceChange
|
|
733 |
// -----------------------------------------------------------------------------
|
|
734 |
//
|
|
735 |
void CXnTextAdapter::HandleScreenDeviceChangedL()
|
|
736 |
{
|
|
737 |
if( SetTextPropertiesL( iNode ) )
|
|
738 |
{
|
|
739 |
iFlags |= XnText::KConstructText;
|
|
740 |
}
|
|
741 |
|
|
742 |
CXnControlAdapter::HandleScreenDeviceChangedL();
|
|
743 |
}
|
|
744 |
|
|
745 |
// -----------------------------------------------------------------------------
|
|
746 |
// CXnTextAdapter::HandlePointerEventL
|
|
747 |
// (other items were commented in a header).
|
|
748 |
// -----------------------------------------------------------------------------
|
|
749 |
//
|
|
750 |
void CXnTextAdapter::HandlePointerEventL( const TPointerEvent& aPointerEvent )
|
|
751 |
{
|
|
752 |
if( AknLayoutUtils::PenEnabled() )
|
|
753 |
{
|
|
754 |
CXnControlAdapter::HandlePointerEventL( aPointerEvent );
|
|
755 |
}
|
|
756 |
}
|
|
757 |
|
|
758 |
// ---------------------------------------------------------
|
|
759 |
// CXnTextAdapter::SizeChanged()
|
|
760 |
// Called by framework when the view size is changed
|
|
761 |
// (other items were commented in a header).
|
|
762 |
// ---------------------------------------------------------
|
|
763 |
//
|
|
764 |
void CXnTextAdapter::SizeChanged()
|
|
765 |
{
|
|
766 |
TRAP_IGNORE( SizeChangedL() );
|
|
767 |
}
|
|
768 |
|
|
769 |
// ---------------------------------------------------------
|
|
770 |
// CXnTextAdapter::SizeChangedL()
|
|
771 |
// ---------------------------------------------------------
|
|
772 |
//
|
|
773 |
void CXnTextAdapter::SizeChangedL()
|
|
774 |
{
|
|
775 |
if( SetTextPropertiesL( iNode ) )
|
|
776 |
{
|
|
777 |
iFlags |= XnText::KConstructText;
|
|
778 |
}
|
|
779 |
|
|
780 |
TRect rect( iNode.Rect() );
|
|
781 |
|
|
782 |
TRect labelRect( iLabel->Rect() );
|
|
783 |
iLabel->SetRect( rect );
|
|
784 |
|
|
785 |
if( iText )
|
|
786 |
{
|
|
787 |
TInt textWidth( iLabel->Font()->TextWidthInPixels( *iText ) );
|
|
788 |
|
|
789 |
TInt rectWidth( rect.Width() );
|
|
790 |
|
|
791 |
if( iFlags & XnText::KOverflowVisible )
|
|
792 |
{
|
|
793 |
TBool isTooltip( iNode.ParentL()->Type()->Type() == XnText::tooltip );
|
|
794 |
|
|
795 |
// Tooltip can grow and shrink, others just grow
|
|
796 |
if( isTooltip || textWidth > rectWidth )
|
|
797 |
{
|
|
798 |
rect = Rect();
|
|
799 |
|
|
800 |
TInt dx( textWidth - rectWidth );
|
|
801 |
|
|
802 |
if( dx != 0 )
|
|
803 |
{
|
|
804 |
rect.Resize( dx, 0 );
|
|
805 |
SetSizeWithoutNotification( rect.Size() );
|
|
806 |
|
|
807 |
// Update
|
|
808 |
iLabel->SetRect( rect );
|
|
809 |
}
|
|
810 |
}
|
|
811 |
}
|
|
812 |
}
|
|
813 |
if( labelRect != iLabel->Rect() )
|
|
814 |
{
|
|
815 |
iFlags |= XnText::KConstructText;
|
|
816 |
}
|
|
817 |
}
|
|
818 |
|
|
819 |
// ---------------------------------------------------------
|
|
820 |
// CXnTextAdapter::SkinChanged()
|
|
821 |
// Called by framework when the skin is changed
|
|
822 |
// (other items were commented in a header).
|
|
823 |
// ---------------------------------------------------------
|
|
824 |
//
|
|
825 |
void CXnTextAdapter::SkinChanged()
|
|
826 |
{
|
|
827 |
TRAP_IGNORE
|
|
828 |
(
|
|
829 |
if( SetTextPropertiesL( iNode ) )
|
|
830 |
{
|
|
831 |
iFlags |= XnText::KConstructText;
|
|
832 |
}
|
|
833 |
);
|
|
834 |
}
|
|
835 |
|
|
836 |
// -----------------------------------------------------------------------------
|
|
837 |
// CXnTextAdapter::Draw
|
|
838 |
// Draws the text component
|
|
839 |
// -----------------------------------------------------------------------------
|
|
840 |
//
|
|
841 |
void CXnTextAdapter::Draw(const TRect& aRect) const
|
|
842 |
{
|
|
843 |
CXnTextAdapter* adapter = const_cast< CXnTextAdapter* >( this );
|
|
844 |
|
|
845 |
if( iFlags & XnText::KConstructText )
|
|
846 |
{
|
|
847 |
TRAPD( err, adapter->ConstructTextL() );
|
|
848 |
|
|
849 |
adapter->iFlags &= ~XnText::KConstructText;
|
|
850 |
|
|
851 |
if( err )
|
|
852 |
{
|
|
853 |
return;
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
CXnControlAdapter::Draw( aRect );
|
|
858 |
|
|
859 |
if( iPictographInterface )
|
|
860 |
{
|
|
861 |
TRAP_IGNORE( UpdateBackgroundL() );
|
|
862 |
iGc->BitBlt( iNode.Rect().iTl, iBackgroundBitmap );
|
|
863 |
}
|
|
864 |
}
|
|
865 |
|
|
866 |
// -----------------------------------------------------------------------------
|
|
867 |
// CXnTextAdapter::DrawPictographArea
|
|
868 |
// Draws the text component
|
|
869 |
// -----------------------------------------------------------------------------
|
|
870 |
//
|
|
871 |
void CXnTextAdapter::DrawPictographArea()
|
|
872 |
{
|
|
873 |
DrawNow();
|
|
874 |
}
|
|
875 |
|
|
876 |
// -----------------------------------------------------------------------------
|
|
877 |
// CXnTextAdapter::UpdateBackgroundL
|
|
878 |
// -----------------------------------------------------------------------------
|
|
879 |
//
|
|
880 |
void CXnTextAdapter::UpdateBackgroundL() const
|
|
881 |
{
|
|
882 |
CGraphicsDevice* gdevice = iGc->Device();
|
|
883 |
TDisplayMode displayMode = gdevice->DisplayMode();
|
|
884 |
|
|
885 |
// create "screenshot" from the background appearance
|
|
886 |
if( iBackgroundBitmap )
|
|
887 |
{
|
|
888 |
delete iBackgroundBitmap;
|
|
889 |
iBackgroundBitmap = NULL;
|
|
890 |
}
|
|
891 |
|
|
892 |
iBackgroundBitmap = new (ELeave) CFbsBitmap();
|
|
893 |
iBackgroundBitmap->Create( iNode.Rect().Size(), displayMode );
|
|
894 |
CFbsBitmap* tmpBitmap = new (ELeave) CFbsBitmap;
|
|
895 |
CleanupStack::PushL( tmpBitmap );
|
|
896 |
|
|
897 |
CWsScreenDevice* scrDevice = static_cast<CWsScreenDevice*>( iGc->Device() );
|
|
898 |
TSize tmpSize = scrDevice->SizeInPixels();
|
|
899 |
tmpBitmap->Create( tmpSize, displayMode );
|
|
900 |
|
|
901 |
CFbsBitmapDevice* tmpDevice = CFbsBitmapDevice::NewL( tmpBitmap );
|
|
902 |
CleanupStack::PushL( tmpDevice );
|
|
903 |
CBitmapContext* bc( NULL );
|
|
904 |
tmpDevice->CreateBitmapContext( bc );
|
|
905 |
CleanupStack::PushL( bc );
|
|
906 |
DrawBackground( iNode.Rect(), reinterpret_cast<CWindowGc&>( *bc ) );
|
|
907 |
CopyBitmapData( *iBackgroundBitmap, *tmpBitmap, iNode.Rect().iTl );
|
|
908 |
CleanupStack::PopAndDestroy( 3 );
|
|
909 |
}
|
|
910 |
|
|
911 |
// -----------------------------------------------------------------------------
|
|
912 |
// CXnTextAdapter::DrawBackground
|
|
913 |
// -----------------------------------------------------------------------------
|
|
914 |
//
|
|
915 |
void CXnTextAdapter::DrawBackground(const TRect& aRect, CWindowGc& aGc) const
|
|
916 |
{
|
|
917 |
RPointerArray<CXnControlAdapter> adapters;
|
|
918 |
|
|
919 |
for( CXnNodePluginIf* node = &iNode; node; )
|
|
920 |
{
|
|
921 |
TRAP_IGNORE(
|
|
922 |
CXnControlAdapter* adapter( node->Control() );
|
|
923 |
|
|
924 |
if ( adapter )
|
|
925 |
{
|
|
926 |
adapters.AppendL( adapter );
|
|
927 |
}
|
|
928 |
|
|
929 |
node = node->ParentL()
|
|
930 |
);
|
|
931 |
}
|
|
932 |
|
|
933 |
for( TInt i = adapters.Count() - 1; i >= 0; --i )
|
|
934 |
{
|
|
935 |
adapters[i]->Draw( aRect, aGc );
|
|
936 |
}
|
|
937 |
|
|
938 |
adapters.Reset();
|
|
939 |
}
|
|
940 |
|
|
941 |
// -----------------------------------------------------------------------------
|
|
942 |
// CXnTextAdapter::MeasureAdaptiveContentL
|
|
943 |
// -----------------------------------------------------------------------------
|
|
944 |
//
|
|
945 |
TSize CXnTextAdapter::MeasureAdaptiveContentL( const TSize& aAvailableSize )
|
|
946 |
{
|
|
947 |
TSize size;
|
|
948 |
|
|
949 |
if( ( aAvailableSize.iWidth > 0 ) && ( aAvailableSize.iHeight > 0 ) )
|
|
950 |
{
|
|
951 |
size = MeasureTextL( aAvailableSize );
|
|
952 |
}
|
|
953 |
|
|
954 |
return size;
|
|
955 |
}
|
|
956 |
|
|
957 |
// -----------------------------------------------------------------------------
|
|
958 |
// CXnTextAdapter::RestrictSizeL
|
|
959 |
// -----------------------------------------------------------------------------
|
|
960 |
//
|
|
961 |
TInt CXnTextAdapter::RestrictSizeL()
|
|
962 |
{
|
|
963 |
CXnNodePluginIf* parent( iNode.ParentL() );
|
|
964 |
|
|
965 |
if( !parent )
|
|
966 |
{
|
|
967 |
// No parent where to restrict own size
|
|
968 |
return iFlags;
|
|
969 |
}
|
|
970 |
|
|
971 |
TRect parentRect( parent->Rect() );
|
|
972 |
|
|
973 |
if( parentRect.IsEmpty() )
|
|
974 |
{
|
|
975 |
return iFlags;
|
|
976 |
}
|
|
977 |
|
|
978 |
TRect rect( Rect() );
|
|
979 |
|
|
980 |
TInt dx( 0 );
|
|
981 |
TInt dy( 0 );
|
|
982 |
|
|
983 |
// Restrict own size inside parent rect to prevent flowing outside parent's rect
|
|
984 |
if( rect.iBr.iX > parentRect.iBr.iX )
|
|
985 |
{
|
|
986 |
dx = rect.iBr.iX - parentRect.iBr.iX;
|
|
987 |
}
|
|
988 |
|
|
989 |
if( rect.iBr.iY > parentRect.iBr.iY )
|
|
990 |
{
|
|
991 |
dy = rect.iBr.iY - parentRect.iBr.iY;
|
|
992 |
}
|
|
993 |
|
|
994 |
if( dx == 0 && dy == 0 )
|
|
995 |
{
|
|
996 |
// No need to change sizes
|
|
997 |
return iFlags;
|
|
998 |
}
|
|
999 |
|
|
1000 |
TInt flags( iFlags );
|
|
1001 |
|
|
1002 |
if( parent->Type()->Type() == XnText::tooltip )
|
|
1003 |
{
|
|
1004 |
// Remove temporarily to allow tooltip truncation
|
|
1005 |
flags &= ~XnText::KOverflowVisible;
|
|
1006 |
}
|
|
1007 |
|
|
1008 |
// Clip text again, parent size restriction may result in re-clipping
|
|
1009 |
if( !IsBitSet( XnText::KOverflowVisible, flags ) )
|
|
1010 |
{
|
|
1011 |
TSize size( rect.Size() );
|
|
1012 |
|
|
1013 |
size.iWidth -= dx;
|
|
1014 |
size.iHeight -= dy;
|
|
1015 |
|
|
1016 |
// Update own size ...
|
|
1017 |
SetSizeWithoutNotification( size );
|
|
1018 |
|
|
1019 |
// ... and label
|
|
1020 |
rect = iLabel->Rect();
|
|
1021 |
|
|
1022 |
rect.Resize( -dx, -dy );
|
|
1023 |
|
|
1024 |
iLabel->SetRect( rect );
|
|
1025 |
}
|
|
1026 |
|
|
1027 |
return flags;
|
|
1028 |
}
|
|
1029 |
|
|
1030 |
// -----------------------------------------------------------------------------
|
|
1031 |
// CXnTextAdapter::SetLineSpacingL
|
|
1032 |
// -----------------------------------------------------------------------------
|
|
1033 |
//
|
|
1034 |
void CXnTextAdapter::SetLineSpacingL( TInt aReference )
|
|
1035 |
{
|
|
1036 |
// Set linespacing, one pixel is the default
|
|
1037 |
TInt lineSpace( 1 );
|
|
1038 |
|
|
1039 |
CXnProperty* lineSpaceProp(
|
|
1040 |
iNode.GetPropertyL( XnPropertyNames::appearance::common::KFontLineSpace ) );
|
|
1041 |
|
|
1042 |
if( lineSpaceProp )
|
|
1043 |
{
|
|
1044 |
lineSpace = iNode.UiEngineL()->VerticalPixelValueL( lineSpaceProp, aReference );
|
|
1045 |
}
|
|
1046 |
|
|
1047 |
if( lineSpace < 1 )
|
|
1048 |
{
|
|
1049 |
// Must be at least 1
|
|
1050 |
lineSpace = 1;
|
|
1051 |
}
|
|
1052 |
|
|
1053 |
const CAknLayoutFont* layoutFont( CAknLayoutFont::AsCAknLayoutFontOrNull( iFont ) );
|
|
1054 |
|
|
1055 |
if( layoutFont )
|
|
1056 |
{
|
|
1057 |
TInt textPaneHeight = layoutFont->TextPaneHeight();
|
|
1058 |
|
|
1059 |
lineSpace += ( textPaneHeight - iFont->HeightInPixels() );
|
|
1060 |
}
|
|
1061 |
/* end of CEikLabel fix */
|
|
1062 |
|
|
1063 |
iLabel->SetPixelGapBetweenLines( lineSpace );
|
|
1064 |
}
|
|
1065 |
|
|
1066 |
// -----------------------------------------------------------------------------
|
|
1067 |
// MeasureTextL
|
|
1068 |
// Measures the text dimensions fitted to available size
|
|
1069 |
// -----------------------------------------------------------------------------
|
|
1070 |
//
|
|
1071 |
TSize CXnTextAdapter::MeasureTextL( const TSize& aAvailableSize )
|
|
1072 |
{
|
|
1073 |
TSize size;
|
|
1074 |
|
|
1075 |
if( !iText || *iText == KNullDesC )
|
|
1076 |
{
|
|
1077 |
return size;
|
|
1078 |
}
|
|
1079 |
|
|
1080 |
// Save the current text before measure
|
|
1081 |
HBufC* original( iLabel->Text()->AllocLC() );
|
|
1082 |
|
|
1083 |
SetLineSpacingL( 0 );
|
|
1084 |
|
|
1085 |
SetLabelTextL( *iLabel, *iText, aAvailableSize.iWidth, iMaxLines, iFlags, ETrue );
|
|
1086 |
|
|
1087 |
TPtrC text( *iLabel->Text() );
|
|
1088 |
|
|
1089 |
// help CEikLabel to calculate its content size more precisely
|
|
1090 |
iLabel->iMargin.iBottom = iLabel->Font()->DescentInPixels();
|
|
1091 |
|
|
1092 |
// Get the size needed for the text
|
|
1093 |
size = iLabel->CalcMinimumSize( text );
|
|
1094 |
|
|
1095 |
// Restore original text
|
|
1096 |
iLabel->SetTextL( *original );
|
|
1097 |
CleanupStack::PopAndDestroy( original );
|
|
1098 |
|
|
1099 |
return size;
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
// -----------------------------------------------------------------------------
|
|
1103 |
// UpdateTextL
|
|
1104 |
// -----------------------------------------------------------------------------
|
|
1105 |
//
|
|
1106 |
void CXnTextAdapter::UpdateTextL( const TDesC8& aText )
|
|
1107 |
{
|
|
1108 |
HBufC* text( CnvUtfConverter::ConvertToUnicodeFromUtf8L( aText ) );
|
|
1109 |
|
|
1110 |
CleanupStack::PushL( text );
|
|
1111 |
|
|
1112 |
UpdateTextL( text );
|
|
1113 |
|
|
1114 |
CleanupStack::PopAndDestroy( text );
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
// -----------------------------------------------------------------------------
|
|
1118 |
// UpdateTextL
|
|
1119 |
// -----------------------------------------------------------------------------
|
|
1120 |
//
|
|
1121 |
void CXnTextAdapter::UpdateTextL( const TDesC* aText )
|
|
1122 |
{
|
|
1123 |
if( aText )
|
|
1124 |
{
|
|
1125 |
if( iText && *iText == *aText )
|
|
1126 |
{
|
|
1127 |
// New text is same as current
|
|
1128 |
return;
|
|
1129 |
}
|
|
1130 |
|
|
1131 |
if( iText && iText->Des().MaxLength() >= aText->Length() )
|
|
1132 |
{
|
|
1133 |
// New text fits to earlier allocated space
|
|
1134 |
*iText = *aText;
|
|
1135 |
}
|
|
1136 |
else
|
|
1137 |
{
|
|
1138 |
// Need to reserve space for new text
|
|
1139 |
delete iText;
|
|
1140 |
iText = NULL;
|
|
1141 |
iText = aText->AllocL();
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
TPtr ptr( iText->Des() );
|
|
1145 |
|
|
1146 |
CXnUtils::CollapseWhiteSpace( iNode, ptr );
|
|
1147 |
|
|
1148 |
iFlags |= XnText::KConstructText;
|
|
1149 |
|
|
1150 |
iNode.SetDirtyL();
|
|
1151 |
|
|
1152 |
const TDesC8& parentType( iNode.ParentL()->Type()->Type() );
|
|
1153 |
|
|
1154 |
if( parentType == XnText::tooltip )
|
|
1155 |
{
|
|
1156 |
// Force tooltip text size to be recalculted by layout algorithm
|
|
1157 |
SetSizeWithoutNotification( TSize() );
|
|
1158 |
}
|
|
1159 |
else if( parentType == XnText::clock )
|
|
1160 |
{
|
|
1161 |
iNode.ParentL()->SetDirtyL();
|
|
1162 |
}
|
|
1163 |
}
|
|
1164 |
}
|
|
1165 |
|
|
1166 |
// End of file
|
|
1167 |
|