|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Start date field for viewers |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "cesmrviewerstartdatefield.h" |
|
19 |
|
20 #include "cesmreditor.h" |
|
21 #include "mesmrlistobserver.h" |
|
22 #include "nmrlayoutmanager.h" |
|
23 #include "nmrbitmapmanager.h" |
|
24 #include "cmrlabel.h" |
|
25 #include "cmrimage.h" |
|
26 #include <esmrgui.rsg> |
|
27 |
|
28 #include <eiklabel.h> |
|
29 #include <caluser.h> |
|
30 #include <calalarm.h> |
|
31 #include <avkon.rsg> |
|
32 #include <calentry.h> |
|
33 #include <eikenv.h> |
|
34 #include <eikedwin.h> |
|
35 #include <StringLoader.h> |
|
36 #include <AknsConstants.h> |
|
37 #include <AknUtils.h> |
|
38 #include <AknLayout2ScalableDef.h> |
|
39 |
|
40 // ======== LOCAL FUNCTIONS ======== |
|
41 namespace // codescanner::namespace |
|
42 { |
|
43 const TInt KComponentCount( 2 ); // icon and label |
|
44 const TInt KMaxTimeBuffer( 32 ); // buffer for date formatting |
|
45 } // unnamed namespace |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CESMRViewerStartDateField::NewL() |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CESMRViewerStartDateField* CESMRViewerStartDateField::NewL() |
|
54 { |
|
55 CESMRViewerStartDateField* self = new (ELeave) CESMRViewerStartDateField(); |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL(); |
|
58 CleanupStack::Pop( self ); |
|
59 return self; |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CESMRViewerStartDateField::~CESMRViewerStartDateField() |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CESMRViewerStartDateField::~CESMRViewerStartDateField() |
|
67 { |
|
68 delete iLabel; |
|
69 delete iIcon; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CESMRViewerStartDateField::CESMRViewerStartDateField() |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CESMRViewerStartDateField::CESMRViewerStartDateField() |
|
77 { |
|
78 SetFieldId ( EESMRFieldStartDate ); |
|
79 SetFocusType( EESMRHighlightFocus ); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CESMRViewerStartDateField::ConstructL() |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CESMRViewerStartDateField::ConstructL() |
|
87 { |
|
88 iLabel = CMRLabel::NewL(); |
|
89 iLabel->SetParent( this ); |
|
90 iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapDateStart ); |
|
91 iIcon->SetParent( this ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CESMRViewerStartDateField::InitializeL() |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CESMRViewerStartDateField::InitializeL() |
|
99 { |
|
100 TAknLayoutText text = NMRLayoutManager::GetLayoutText( |
|
101 Rect(), |
|
102 NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
103 |
|
104 iLabel->SetFont( text.Font() ); |
|
105 // This is called so that theme changes will apply when changing theme "on the fly" |
|
106 if ( IsFocused() ) |
|
107 { |
|
108 iLabel->FocusChanged( EDrawNow ); |
|
109 } |
|
110 |
|
111 AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText, |
|
112 KRgbBlack ); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CESMRViewerStartDateField::InternalizeL() |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CESMRViewerStartDateField::InternalizeL( MESMRCalEntry& aEntry ) |
|
120 { |
|
121 // Read format string from AVKON resource |
|
122 HBufC* dateFormatString = iEikonEnv->AllocReadResourceLC |
|
123 (R_QTN_DATE_USUAL_WITH_ZERO); |
|
124 TBuf<KMaxTimeBuffer> buf; |
|
125 CCalEntry& entry = aEntry.Entry(); |
|
126 TTime startTime = entry.StartTimeL().TimeLocalL(); |
|
127 |
|
128 startTime.FormatL(buf,*dateFormatString); |
|
129 |
|
130 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( buf ); |
|
131 iLabel->SetTextL( buf ); |
|
132 CleanupStack::PopAndDestroy( dateFormatString ); |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CESMRViewerStartDateField::SizeChanged() |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CESMRViewerStartDateField::SizeChanged() |
|
140 { |
|
141 TRect rect = Rect(); |
|
142 TAknLayoutRect rowLayoutRect = |
|
143 NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ); |
|
144 rect = rowLayoutRect.Rect(); |
|
145 |
|
146 TAknWindowComponentLayout iconLayout = |
|
147 NMRLayoutManager::GetWindowComponentLayout( |
|
148 NMRLayoutManager::EMRLayoutTextEditorIcon ); |
|
149 AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout ); |
|
150 |
|
151 TAknLayoutRect bgLayoutRect = |
|
152 NMRLayoutManager::GetLayoutRect( |
|
153 rect, NMRLayoutManager::EMRLayoutTextEditorBg ); |
|
154 TRect bgRect( bgLayoutRect.Rect() ); |
|
155 bgRect.SetHeight( bgRect.Height() + 1 ); |
|
156 // Move focus rect so that it's relative to field's position. |
|
157 bgRect.Move( -Position() ); |
|
158 SetFocusRect( bgRect ); |
|
159 |
|
160 TAknLayoutText labelLayout = |
|
161 NMRLayoutManager::GetLayoutText( |
|
162 rect, NMRLayoutManager::EMRTextLayoutTextEditor ); |
|
163 iLabel->SetRect( labelLayout.TextRect() ); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CESMRViewerStartDateField::CountComponentControls() |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CESMRViewerStartDateField::CountComponentControls() const |
|
171 { |
|
172 TInt count( KComponentCount ); |
|
173 return count; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CESMRViewerStartDateField::ComponentControl() |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 CCoeControl* CESMRViewerStartDateField::ComponentControl( TInt aIndex ) const |
|
181 { |
|
182 switch ( aIndex ) |
|
183 { |
|
184 case 0: |
|
185 return iIcon; |
|
186 case 1: |
|
187 return iLabel; |
|
188 default: |
|
189 return NULL; |
|
190 } |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // CESMRViewerStartDateField::SetOutlineFocusL() |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CESMRViewerStartDateField::SetOutlineFocusL( TBool aFocus ) |
|
198 { |
|
199 CESMRField::SetOutlineFocusL ( aFocus ); |
|
200 |
|
201 iLabel->SetFocus( aFocus ); |
|
202 |
|
203 if ( !aFocus ) |
|
204 { |
|
205 AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText, |
|
206 KRgbBlack ); |
|
207 } |
|
208 } |
|
209 // EOF |