|
1 /* |
|
2 * Copyright (c) 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: Text label for Playback view |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <AknsSkinInstance.h> |
|
22 #include <AknsDrawUtils.h> |
|
23 #include <AknsUtils.h> |
|
24 #include <AknMarqueeControl.h> |
|
25 #include <AknUtils.h> |
|
26 #include <AknLayoutFont.h> |
|
27 |
|
28 #include "mpxplaybackviewinfolabel.h" |
|
29 |
|
30 // CONSTANTS |
|
31 #ifdef _DEBUG |
|
32 _LIT( KPanicCat, "CMPXPlaybackViewInfoLabel" ); |
|
33 #endif |
|
34 |
|
35 // MODULE DATA STRUCTURES |
|
36 enum TPanicCode |
|
37 { |
|
38 ENoPanic = 0, |
|
39 EAlreadyScrolling, |
|
40 ENoTextSet, |
|
41 EFontNotSet |
|
42 }; |
|
43 |
|
44 |
|
45 // ======== MEMBER FUNCTIONS ======== |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // C++ default constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CMPXPlaybackViewInfoLabel::CMPXPlaybackViewInfoLabel() |
|
53 { |
|
54 // do nothing |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CMPXPlaybackViewInfoLabel::ConstructL(TBool aEnableMarqueeSupport) |
|
62 { |
|
63 if ( aEnableMarqueeSupport ) |
|
64 { |
|
65 iMarquee = CAknMarqueeControl::NewL(); |
|
66 TCallBack callback( RedrawCallback, this ); |
|
67 iMarquee->SetRedrawCallBack( callback ); |
|
68 iMarquee->SetLoops( 1 ); |
|
69 iMarquee->SetContainerWindowL( *this ); |
|
70 } |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Destructor |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CMPXPlaybackViewInfoLabel::~CMPXPlaybackViewInfoLabel() |
|
78 { |
|
79 delete iFullText; |
|
80 delete iMarquee; |
|
81 iBackground = NULL; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Set background bitmap |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void CMPXPlaybackViewInfoLabel::SetBackground( |
|
89 MAknsControlContext* aBackground ) |
|
90 { |
|
91 iBackground = aBackground; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // Redraw rectangle |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CMPXPlaybackViewInfoLabel::RedrawRect( const TRect& aRect ) const |
|
99 { |
|
100 if ( aRect.Intersects( Rect() ) ) |
|
101 { |
|
102 CWindowGc& gc = SystemGc(); |
|
103 if ( iBackground ) |
|
104 { |
|
105 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
106 AknsDrawUtils::Background( skin, iBackground, gc, Rect() ); |
|
107 } |
|
108 |
|
109 CGraphicsContext::TTextAlign align=iAlignment.TextAlign(); |
|
110 |
|
111 // Get baseline for current font |
|
112 TInt baselineOffset = 0; |
|
113 if ( iMarquee ) |
|
114 { |
|
115 const CAknLayoutFont* layoutFont = |
|
116 CAknLayoutFont::AsCAknLayoutFontOrNull( Font() ); |
|
117 if ( layoutFont ) |
|
118 { |
|
119 baselineOffset= layoutFont->TextPaneTopToBaseline(); |
|
120 } |
|
121 } |
|
122 |
|
123 gc.UseFont( Font() ); |
|
124 gc.SetPenColor( iEikonEnv->ControlColor( EColorLabelText,*this ) ); |
|
125 |
|
126 // Draw marquee, if supported and necessary |
|
127 if ( !iMarquee || !iMarquee->IsMarqueeOn() || iMarquee->DrawText( |
|
128 gc, // aGc |
|
129 Rect(), // aTextRect |
|
130 FullText(), // aText |
|
131 baselineOffset, // aBaselineOffset |
|
132 align, // aAlign |
|
133 *Font() ) ) // aFont |
|
134 { |
|
135 // Marquee is not enabled or all the loops have been executed |
|
136 // -> the text needs to be drawn here |
|
137 CEikLabel::Draw( aRect ); |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // Start marquee scrolling if supported and needed. |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CMPXPlaybackViewInfoLabel::StartMarquee() |
|
147 { |
|
148 if ( iMarquee ) |
|
149 { |
|
150 TBool need = NeedToScroll(); |
|
151 if ( need && !iMarquee->IsMarqueeOn() ) |
|
152 { |
|
153 iMarquee->Reset(); |
|
154 } |
|
155 iMarquee->EnableMarquee( need ); |
|
156 if ( need ) |
|
157 { |
|
158 iMarquee->Start(); |
|
159 } |
|
160 } |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // Stop marquee scrolling. |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void CMPXPlaybackViewInfoLabel::StopMarquee() |
|
168 { |
|
169 if ( iMarquee ) |
|
170 { |
|
171 iMarquee->EnableMarquee( EFalse ); |
|
172 iMarquee->Stop(); |
|
173 } |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // Get the full unclipped text for the label |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 const TDesC& CMPXPlaybackViewInfoLabel::FullText() const |
|
181 { |
|
182 if ( iFullText ) |
|
183 { |
|
184 return *iFullText; |
|
185 } |
|
186 else |
|
187 { |
|
188 return *Text(); |
|
189 } |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // Set label text and clip if necessary. |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CMPXPlaybackViewInfoLabel::SetLabelTextL( const TDesC& aText ) |
|
197 { |
|
198 if ( iMarquee ) |
|
199 { |
|
200 delete iFullText; |
|
201 iFullText = NULL; |
|
202 iFullText = aText.AllocL(); |
|
203 } |
|
204 |
|
205 // magic: allocate 3 chars more (make sure "..." fits). |
|
206 HBufC* buf = HBufC::NewLC( aText.Length() + 3 ); |
|
207 *buf = aText; |
|
208 TPtr ptr( buf->Des() ); |
|
209 AknTextUtils::ClipToFit( ptr, |
|
210 *Font(), |
|
211 Rect().Width() ); |
|
212 SetTextL( *buf ); |
|
213 CleanupStack::PopAndDestroy( buf ); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // Check if scrolling is needed. |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 TBool CMPXPlaybackViewInfoLabel::NeedToScroll() const |
|
221 { |
|
222 __ASSERT_DEBUG( iFont, User::Panic( KPanicCat, EFontNotSet ) ); |
|
223 |
|
224 TBool need( EFalse ); |
|
225 if ( iFullText && iFont->TextWidthInPixels( *iFullText ) > Size().iWidth ) |
|
226 { |
|
227 need = ETrue; |
|
228 } |
|
229 return need; |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------------------------- |
|
233 // Redraw callback for marquee control |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 TInt CMPXPlaybackViewInfoLabel::RedrawCallback( TAny* aPtr ) |
|
237 { |
|
238 CMPXPlaybackViewInfoLabel* self = |
|
239 static_cast<CMPXPlaybackViewInfoLabel*>( aPtr ); |
|
240 CWindowGc& gc = self->SystemGc(); |
|
241 gc.Activate( *self->DrawableWindow() ); |
|
242 self->Draw( self->Rect() ); |
|
243 gc.Deactivate(); |
|
244 |
|
245 return static_cast<TBool>( ETrue ); // True -> draw again |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // Draws the control. |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void CMPXPlaybackViewInfoLabel::Draw( const TRect& aRect ) const |
|
253 { |
|
254 RedrawRect( aRect ); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Gets the number of controls contained in a compound control. |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 TInt CMPXPlaybackViewInfoLabel::CountComponentControls() const |
|
262 { |
|
263 TInt childCount = 0; |
|
264 if ( iMarquee ) |
|
265 { |
|
266 childCount++; |
|
267 } |
|
268 return childCount; |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // Gets an indexed component of a compound control. |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 CCoeControl* CMPXPlaybackViewInfoLabel::ComponentControl( |
|
276 TInt aIndex ) const |
|
277 { |
|
278 ASSERT( aIndex == 0 ); // only 1 control |
|
279 return iMarquee; |
|
280 } |
|
281 |
|
282 // End of File |