66
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: This is the source file for the CClockMarqueeLabel class.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <AknsSkinInstance.h>
|
|
20 |
#include <AknsDrawUtils.h>
|
|
21 |
#include <AknsUtils.h>
|
|
22 |
#include <AknMarqueeControl.h>
|
|
23 |
#include <AknUtils.h>
|
|
24 |
#include <AknLayoutFont.h>
|
|
25 |
#include <AknBidiTextUtils.h>
|
|
26 |
|
|
27 |
// User includes
|
|
28 |
#include "clockmarqueelabel.h"
|
|
29 |
#include "clock_debug.h"
|
|
30 |
|
|
31 |
// Constants
|
|
32 |
const TInt KNumLoops( 1 );
|
|
33 |
|
|
34 |
// ---------------------------------------------------------
|
|
35 |
// CClockMarqueeLabel::CClockMarqueeLabel
|
|
36 |
// rest of the details are commented in the header
|
|
37 |
// ---------------------------------------------------------
|
|
38 |
//
|
|
39 |
CClockMarqueeLabel::CClockMarqueeLabel()
|
|
40 |
{
|
|
41 |
__PRINTS( "CClockMarqueeLabel::NewL - Entry" );
|
|
42 |
|
|
43 |
// No implementation yet.
|
|
44 |
|
|
45 |
__PRINTS( "CClockMarqueeLabel::NewL - Exit" );
|
|
46 |
}
|
|
47 |
|
|
48 |
// ---------------------------------------------------------
|
|
49 |
// CClockMarqueeLabel::ConstructL
|
|
50 |
// rest of the details are commented in the header
|
|
51 |
// ---------------------------------------------------------
|
|
52 |
//
|
|
53 |
void CClockMarqueeLabel::ConstructL( TBool aEnableMarquee )
|
|
54 |
{
|
|
55 |
__PRINTS( "CClockMarqueeLabel::ConstructL - Entry" );
|
|
56 |
|
|
57 |
// Check if marquee has to be enabled.
|
|
58 |
if ( aEnableMarquee )
|
|
59 |
{
|
|
60 |
// Contruct the marquee control.
|
|
61 |
iMarqueeControl = CAknMarqueeControl::NewL();
|
|
62 |
// Set the redraw callback for the marquee control
|
|
63 |
TCallBack callback( RedrawCallback, this );
|
|
64 |
iMarqueeControl->SetRedrawCallBack( callback );
|
|
65 |
// Set the number of loops.
|
|
66 |
iMarqueeControl->SetLoops( KNumLoops );
|
|
67 |
iMarqueeControl->SetContainerWindowL( *this );
|
|
68 |
}
|
|
69 |
|
|
70 |
__PRINTS( "CClockMarqueeLabel::ConstructL - Exit" );
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------
|
|
74 |
// CClockMarqueeLabel::~CClockMarqueeLabel
|
|
75 |
// rest of the details are commented in the header
|
|
76 |
// ---------------------------------------------------------
|
|
77 |
//
|
|
78 |
CClockMarqueeLabel::~CClockMarqueeLabel()
|
|
79 |
{
|
|
80 |
__PRINTS( "CClockMarqueeLabel::~CClockMarqueeLabel - Entry" );
|
|
81 |
|
|
82 |
if( iLabelText )
|
|
83 |
{
|
|
84 |
delete iLabelText;
|
|
85 |
iLabelText = NULL;
|
|
86 |
}
|
|
87 |
if( iMarqueeControl )
|
|
88 |
{
|
|
89 |
delete iMarqueeControl;
|
|
90 |
iMarqueeControl = NULL;
|
|
91 |
}
|
|
92 |
iBgContext = NULL;
|
|
93 |
|
|
94 |
__PRINTS( "CClockMarqueeLabel::~CClockMarqueeLabel - Exit" );
|
|
95 |
}
|
|
96 |
|
|
97 |
// ---------------------------------------------------------
|
|
98 |
// CClockMarqueeLabel::SetBackground
|
|
99 |
// rest of the details are commented in the header
|
|
100 |
// ---------------------------------------------------------
|
|
101 |
//
|
|
102 |
void CClockMarqueeLabel::SetBackground( MAknsControlContext* aBgContext )
|
|
103 |
{
|
|
104 |
__PRINTS( "CClockMarqueeLabel::SetBackground - Entry" );
|
|
105 |
|
|
106 |
iBgContext = aBgContext;
|
|
107 |
|
|
108 |
__PRINTS( "CClockMarqueeLabel::SetBackground - Exit" );
|
|
109 |
}
|
|
110 |
|
|
111 |
// ---------------------------------------------------------
|
|
112 |
// CClockMarqueeLabel::RedrawRect
|
|
113 |
// rest of the details are commented in the header
|
|
114 |
// ---------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CClockMarqueeLabel::RedrawRect( const TRect& aRect ) const
|
|
117 |
{
|
|
118 |
__PRINTS( "CClockMarqueeLabel::RedrawRect - Entry" );
|
|
119 |
|
|
120 |
// Check if the rectangle to be redrawn is within the bounds of own rect.
|
|
121 |
if ( aRect.Intersects( Rect() ) )
|
|
122 |
{
|
|
123 |
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
|
|
124 |
|
|
125 |
CWindowGc& gc = SystemGc();
|
|
126 |
if ( iBgContext )
|
|
127 |
{
|
|
128 |
// Set the background skin.
|
|
129 |
AknsDrawUtils::Background( skin, iBgContext, gc, Rect() );
|
|
130 |
}
|
|
131 |
|
|
132 |
CGraphicsContext::TTextAlign align = iAlignment.TextAlign();
|
|
133 |
|
|
134 |
// Get baseline for current font
|
|
135 |
TInt baselineOffset = 0;
|
|
136 |
if ( iMarqueeControl )
|
|
137 |
{
|
|
138 |
const CAknLayoutFont* layoutFont = CAknLayoutFont::AsCAknLayoutFontOrNull( Font() );
|
|
139 |
if ( layoutFont )
|
|
140 |
{
|
|
141 |
baselineOffset= layoutFont->TextPaneTopToBaseline();
|
|
142 |
}
|
|
143 |
}
|
|
144 |
|
|
145 |
// Set the font and the pen color.
|
|
146 |
gc.UseFont( Font() );
|
|
147 |
|
|
148 |
TRgb cachedColor;
|
|
149 |
// Get the cached color.
|
|
150 |
AknsUtils::GetCachedColor( skin, cachedColor, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6 );
|
|
151 |
gc.SetPenColor( cachedColor );
|
|
152 |
|
|
153 |
// Draw marquee, if supported and necessary.
|
|
154 |
if ( !iMarqueeControl || !iMarqueeControl->IsMarqueeOn() ||
|
|
155 |
iMarqueeControl->DrawText( gc,
|
|
156 |
Rect(),
|
|
157 |
FullText(),
|
|
158 |
baselineOffset,
|
|
159 |
align,
|
|
160 |
*Font() ) )
|
|
161 |
{
|
|
162 |
// Marquee is not enabled or all the loops have been executed
|
|
163 |
// The text needs to be drawn here.
|
|
164 |
// iMarqueeControl->Stop();
|
|
165 |
__PRINTS( "Marquee has finished executing all loops" );
|
|
166 |
if(AknLayoutUtils::LayoutMirrored())
|
|
167 |
{
|
|
168 |
gc.DrawText( *Text(), aRect, baselineOffset,CGraphicsContext::ERight );
|
|
169 |
}
|
|
170 |
else
|
|
171 |
{
|
|
172 |
gc.DrawText( *Text(), aRect, baselineOffset,CGraphicsContext::ELeft );
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
|
176 |
}
|
|
177 |
|
|
178 |
__PRINTS( "CClockMarqueeLabel::RedrawRect - Exit" );
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------
|
|
182 |
// CClockMarqueeLabel::StartMarquee
|
|
183 |
// rest of the details are commented in the header
|
|
184 |
// ---------------------------------------------------------
|
|
185 |
//
|
|
186 |
void CClockMarqueeLabel::StartMarquee()
|
|
187 |
{
|
|
188 |
__PRINTS( "CClockMarqueeLabel::StartMarquee - Entry" );
|
|
189 |
|
|
190 |
if ( iMarqueeControl )
|
|
191 |
{
|
|
192 |
// Check if scrolling is required.
|
|
193 |
TBool needToScroll = NeedToScroll();
|
|
194 |
if ( needToScroll && !iMarqueeControl->IsMarqueeOn() )
|
|
195 |
{
|
|
196 |
__PRINTS( "Scrolling required" );
|
|
197 |
// Reset the marquee control.
|
|
198 |
iMarqueeControl->Reset();
|
|
199 |
}
|
|
200 |
// Enable the marquee.
|
|
201 |
iMarqueeControl->EnableMarquee( needToScroll );
|
|
202 |
if ( needToScroll )
|
|
203 |
{
|
|
204 |
// Start marquee.
|
|
205 |
iMarqueeControl->Start();
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
__PRINTS( "Scrolling not required" );
|
|
210 |
RedrawRect( Rect() );
|
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
__PRINTS( "CClockMarqueeLabel::StartMarquee - Exit" );
|
|
215 |
}
|
|
216 |
|
|
217 |
// ---------------------------------------------------------
|
|
218 |
// CClockMarqueeLabel::StopMarquee
|
|
219 |
// rest of the details are commented in the header
|
|
220 |
// ---------------------------------------------------------
|
|
221 |
//
|
|
222 |
void CClockMarqueeLabel::StopMarquee()
|
|
223 |
{
|
|
224 |
__PRINTS( "CClockMarqueeLabel::StopMarquee - Entry" );
|
|
225 |
|
|
226 |
if ( iMarqueeControl )
|
|
227 |
{
|
|
228 |
iMarqueeControl->EnableMarquee( EFalse );
|
|
229 |
iMarqueeControl->Stop();
|
|
230 |
}
|
|
231 |
|
|
232 |
__PRINTS( "CClockMarqueeLabel::StopMarquee - Exit" );
|
|
233 |
}
|
|
234 |
|
|
235 |
// ---------------------------------------------------------
|
|
236 |
// CClockMarqueeLabel::FullText
|
|
237 |
// rest of the details are commented in the header
|
|
238 |
// ---------------------------------------------------------
|
|
239 |
//
|
|
240 |
const TDesC& CClockMarqueeLabel::FullText() const
|
|
241 |
{
|
|
242 |
__PRINTS( "CClockMarqueeLabel::FullText - Entry" );
|
|
243 |
|
|
244 |
if ( iLabelText )
|
|
245 |
{
|
|
246 |
__PRINTS( "CClockMarqueeLabel::FullText - Exit" );
|
|
247 |
|
|
248 |
return *iLabelText;
|
|
249 |
}
|
|
250 |
else
|
|
251 |
{
|
|
252 |
__PRINTS( "CClockMarqueeLabel::FullText - Exit" );
|
|
253 |
|
|
254 |
return *Text();
|
|
255 |
}
|
|
256 |
}
|
|
257 |
|
|
258 |
// ---------------------------------------------------------
|
|
259 |
// CClockMarqueeLabel::SetLabelTextL
|
|
260 |
// rest of the details are commented in the header
|
|
261 |
// ---------------------------------------------------------
|
|
262 |
//
|
|
263 |
void CClockMarqueeLabel::SetLabelTextL( const TDesC& aText )
|
|
264 |
{
|
|
265 |
__PRINTS( "CClockMarqueeLabel::SetLabelTextL - Entry" );
|
|
266 |
|
|
267 |
// Clear the previuosly set text.
|
|
268 |
if ( iMarqueeControl )
|
|
269 |
{
|
|
270 |
delete iLabelText;
|
|
271 |
iLabelText = NULL;
|
|
272 |
iLabelText = aText.AllocL();
|
|
273 |
}
|
|
274 |
|
|
275 |
// Allocate 3 chars more ( make sure "..." fits ).
|
|
276 |
HBufC* buf = HBufC::NewLC( aText.Length() + 3 );
|
|
277 |
*buf = aText;
|
|
278 |
TPtr ptr( buf->Des() );
|
|
279 |
AknBidiTextUtils::ConvertToVisualAndClipL( ptr, *Font(), Rect().Width(), Rect().Width() );
|
|
280 |
SetTextL( *buf );
|
|
281 |
CleanupStack::PopAndDestroy( buf );
|
|
282 |
|
|
283 |
__PRINTS( "CClockMarqueeLabel::SetLabelTextL - Exit" );
|
|
284 |
}
|
|
285 |
|
|
286 |
// ---------------------------------------------------------
|
|
287 |
// CClockMarqueeLabel::ResetMarquee
|
|
288 |
// rest of the details are commented in the header
|
|
289 |
// ---------------------------------------------------------
|
|
290 |
//
|
|
291 |
void CClockMarqueeLabel::ResetMarquee()
|
|
292 |
{
|
|
293 |
__PRINTS( "CClockMarqueeLabel::ResetMarquee - Entry" );
|
|
294 |
|
|
295 |
iMarqueeControl->Reset();
|
|
296 |
|
|
297 |
__PRINTS( "CClockMarqueeLabel::ResetMarquee - Exit" );
|
|
298 |
}
|
|
299 |
|
|
300 |
// ---------------------------------------------------------
|
|
301 |
// CClockMarqueeLabel::Draw
|
|
302 |
// rest of the details are commented in the header
|
|
303 |
// ---------------------------------------------------------
|
|
304 |
//
|
|
305 |
void CClockMarqueeLabel::Draw( const TRect& aRect ) const
|
|
306 |
{
|
|
307 |
__PRINTS( "CClockMarqueeLabel::Draw - Entry" );
|
|
308 |
|
|
309 |
RedrawRect( aRect );
|
|
310 |
|
|
311 |
__PRINTS( "CClockMarqueeLabel::Draw - Exit" );
|
|
312 |
}
|
|
313 |
|
|
314 |
// ---------------------------------------------------------
|
|
315 |
// CClockMarqueeLabel::CountComponentControls
|
|
316 |
// rest of the details are commented in the header
|
|
317 |
// ---------------------------------------------------------
|
|
318 |
//
|
|
319 |
TInt CClockMarqueeLabel::CountComponentControls() const
|
|
320 |
{
|
|
321 |
__PRINTS( "CClockMarqueeLabel::CountComponentControls - Entry" );
|
|
322 |
|
|
323 |
TInt componentCount = 0;
|
|
324 |
if ( iMarqueeControl )
|
|
325 |
{
|
|
326 |
componentCount++;
|
|
327 |
}
|
|
328 |
|
|
329 |
__PRINTS( "CClockMarqueeLabel::CountComponentControls - Exit" );
|
|
330 |
|
|
331 |
return componentCount;
|
|
332 |
}
|
|
333 |
|
|
334 |
// ---------------------------------------------------------
|
|
335 |
// CClockMarqueeLabel::ComponentControl
|
|
336 |
// rest of the details are commented in the header
|
|
337 |
// ---------------------------------------------------------
|
|
338 |
//
|
|
339 |
CCoeControl* CClockMarqueeLabel::ComponentControl( TInt aIndex ) const
|
|
340 |
{
|
|
341 |
__PRINTS( "CClockMarqueeLabel::ComponentControl - Entry" );
|
|
342 |
|
|
343 |
ASSERT( aIndex == 0 );
|
|
344 |
|
|
345 |
__PRINTS( "CClockMarqueeLabel::ComponentControl - Exit" );
|
|
346 |
|
|
347 |
return iMarqueeControl;
|
|
348 |
}
|
|
349 |
|
|
350 |
// ---------------------------------------------------------
|
|
351 |
// CClockMarqueeLabel::NeedToScroll
|
|
352 |
// rest of the details are commented in the header
|
|
353 |
// ---------------------------------------------------------
|
|
354 |
//
|
|
355 |
TBool CClockMarqueeLabel::NeedToScroll() const
|
|
356 |
{
|
|
357 |
__PRINTS( "CClockMarqueeLabel::NeedToScroll - Entry" );
|
|
358 |
|
|
359 |
TBool needToScroll( EFalse );
|
|
360 |
// Check if the text fits in the width of the label
|
|
361 |
if ( iLabelText && iFont->TextWidthInPixels( *iLabelText ) > Size().iWidth )
|
|
362 |
{
|
|
363 |
needToScroll = ETrue;
|
|
364 |
}
|
|
365 |
|
|
366 |
__PRINTS( "CClockMarqueeLabel::NeedToScroll - Exit" );
|
|
367 |
|
|
368 |
return needToScroll;
|
|
369 |
}
|
|
370 |
|
|
371 |
// ---------------------------------------------------------
|
|
372 |
// CClockMarqueeLabel::RedrawCallback
|
|
373 |
// rest of the details are commented in the header
|
|
374 |
// ---------------------------------------------------------
|
|
375 |
//
|
|
376 |
TInt CClockMarqueeLabel::RedrawCallback( TAny* aPtr )
|
|
377 |
{
|
|
378 |
__PRINTS( "CClockMarqueeLabel::RedrawCallback - Entry" );
|
|
379 |
|
|
380 |
CClockMarqueeLabel* self = static_cast< CClockMarqueeLabel* >( aPtr );
|
|
381 |
CWindowGc& gc = self->SystemGc();
|
|
382 |
gc.Activate( *self->DrawableWindow() );
|
|
383 |
self->Draw( self->Rect() );
|
|
384 |
gc.Deactivate();
|
|
385 |
|
|
386 |
__PRINTS( "CClockMarqueeLabel::RedrawCallback - Exit" );
|
|
387 |
|
|
388 |
// Redraw again.
|
|
389 |
return TRUE;
|
|
390 |
}
|
|
391 |
|
|
392 |
// End of file
|