|
1 // GuiConsAppView.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <coemain.h> |
|
14 #include <eikedwin.h> |
|
15 #include <eiklabel.h> |
|
16 #include <eikenv.h> |
|
17 #include <barsread.h> |
|
18 #include <coeaui.h> |
|
19 #include <ImageConversion.h> |
|
20 #include "GuiConsAppView.h" |
|
21 #include "guicons.rsg" |
|
22 |
|
23 |
|
24 class CEdwinThatDoesntConsumeEnter : public CEikEdwin |
|
25 { |
|
26 TKeyResponse OfferKeyEventL(const TKeyEvent& aEvent, TEventCode aType); |
|
27 }; |
|
28 |
|
29 TKeyResponse CEdwinThatDoesntConsumeEnter::OfferKeyEventL(const TKeyEvent& aEvent, TEventCode aType) |
|
30 { |
|
31 if (aEvent.iCode == EKeyEnter) |
|
32 { |
|
33 return EKeyWasNotConsumed; |
|
34 } |
|
35 return CEikEdwin::OfferKeyEventL(aEvent, aType); |
|
36 } |
|
37 |
|
38 _LIT(KGuiConsViewPanic, "GuiConsView"); |
|
39 |
|
40 void Panic(TGuiConsViewPanic aReason) |
|
41 { |
|
42 User::Panic(KGuiConsViewPanic, aReason); |
|
43 } |
|
44 |
|
45 CGuiConsAppView* CGuiConsAppView::NewL(const TRect& aRect) |
|
46 { |
|
47 CGuiConsAppView* self = CGuiConsAppView::NewLC(aRect); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 CGuiConsAppView* CGuiConsAppView::NewLC(const TRect& aRect) |
|
53 { |
|
54 CGuiConsAppView* self = new(ELeave)CGuiConsAppView; |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL(aRect); |
|
57 return self; |
|
58 } |
|
59 |
|
60 _LIT(KBgImage, "\\resource\\guiconsbg.png"); |
|
61 |
|
62 void CGuiConsAppView::ConstructL(const TRect& aRect) |
|
63 { |
|
64 CreateWindowL(); |
|
65 |
|
66 iEditor = new(ELeave) CEdwinThatDoesntConsumeEnter; |
|
67 |
|
68 iEditor->ConstructL( |
|
69 CEikEdwin::EAvkonEditor | CEikEdwin::ENoWrap | CEikEdwin::ELineCursor | CEikEdwin::ENoLineOrParaBreaks, |
|
70 20, // width in chars |
|
71 0, |
|
72 1); // number of lines |
|
73 /* TResourceReader reader; |
|
74 CCoeEnv::Static()->CreateResourceReaderLC(reader, R_GUICONS_LINEEDITOR_EDWIN); |
|
75 |
|
76 iEditor->ConstructFromResourceL(reader); |
|
77 CleanupStack::PopAndDestroy();*/ |
|
78 |
|
79 iEditor->SetBorder(TGulBorder::ESingleDotted); |
|
80 iEditor->SetContainerWindowL(*this); |
|
81 |
|
82 iLabel = new(ELeave)CEikLabel(); |
|
83 iLabel->SetContainerWindowL(*this); |
|
84 iLabel->SetFont(CEikonEnv::Static()->DenseFont()); |
|
85 iLabel->SetAlignment(EHCenterVCenter); |
|
86 iLabel->OverrideColorL(EColorLabelText, 0x808080); |
|
87 |
|
88 TRAP_IGNORE(iBgImage = CImageDecodeAo::NewL(*this, KBgImage)); |
|
89 |
|
90 SetRect(aRect); |
|
91 } |
|
92 |
|
93 void CGuiConsAppView::SetLargeControlL(CCoeControl* aControl) |
|
94 { |
|
95 __ASSERT_ALWAYS(!iLargeControl, Panic(EGuiConsControlAlreadyExists)); |
|
96 if (!aControl->DrawableWindow()) |
|
97 { |
|
98 aControl->SetContainerWindowL(*this); |
|
99 } |
|
100 iLargeControl = aControl; |
|
101 Layout(); |
|
102 //DrawNow(); |
|
103 DrawDeferred(); |
|
104 } |
|
105 |
|
106 void CGuiConsAppView::ClearLargeControl() |
|
107 { |
|
108 iLargeControl = NULL; |
|
109 //DrawNow(); |
|
110 DrawDeferred(); |
|
111 } |
|
112 |
|
113 void CGuiConsAppView::ShowLabelL(const TDesC& aText) |
|
114 { |
|
115 iLabel->SetTextL(aText); |
|
116 iLabel->MakeVisible(ETrue); |
|
117 iEditor->MakeVisible(EFalse); |
|
118 DrawNow(); |
|
119 } |
|
120 |
|
121 void CGuiConsAppView::ShowEditor() |
|
122 { |
|
123 iLabel->MakeVisible(EFalse); |
|
124 iEditor->MakeVisible(ETrue); |
|
125 DrawNow(); |
|
126 } |
|
127 |
|
128 void CGuiConsAppView::FocusEditor(TBool aFocus) |
|
129 { |
|
130 iEditor->SetDimmed(!aFocus); |
|
131 iEditor->SetFocusing(aFocus); |
|
132 iEditor->SetFocus(aFocus); |
|
133 iEditor->SetReadOnly(!aFocus); |
|
134 } |
|
135 |
|
136 void CGuiConsAppView::AddEditorToStackL(CCoeAppUi* aAppUi) |
|
137 { |
|
138 aAppUi->AddToStackL(iEditor); |
|
139 } |
|
140 |
|
141 void CGuiConsAppView::RemoveEditorFromStack(CCoeAppUi* aAppUi) |
|
142 { |
|
143 aAppUi->RemoveFromStack(iEditor); |
|
144 } |
|
145 |
|
146 HBufC* CGuiConsAppView::GetEditorTextL() |
|
147 { |
|
148 return iEditor->GetTextInHBufL(); |
|
149 } |
|
150 |
|
151 void CGuiConsAppView::SetEditorTextL(const TDesC* aText) |
|
152 { |
|
153 iEditor->SetTextL(aText); |
|
154 } |
|
155 |
|
156 CGuiConsAppView::CGuiConsAppView() |
|
157 { |
|
158 } |
|
159 |
|
160 CGuiConsAppView::~CGuiConsAppView() |
|
161 { |
|
162 delete iEditor; |
|
163 delete iLabel; |
|
164 delete iBgImage; |
|
165 } |
|
166 |
|
167 void CGuiConsAppView::Draw(const TRect& aRect) const |
|
168 { |
|
169 CWindowGc& gc = SystemGc(); |
|
170 gc.Clear( aRect ); |
|
171 |
|
172 // JB - This doesn't seem to work reliably and it messes up scrolling. |
|
173 /* TGulBorder border = iEditor->Border(); |
|
174 TRect editorRect = iEditor->Rect(); |
|
175 border.Draw(gc, border.OuterRect(editorRect)); |
|
176 */ |
|
177 if ((!iLargeControl) && (iBgImage) && (iBgImage->Bitmap())) |
|
178 { |
|
179 CFbsBitmap* bg = iBgImage->Bitmap(); |
|
180 TSize bgSize = bg->SizeInPixels(); |
|
181 TPoint myCentre = Rect().iTl + TPoint(Size().iWidth / 2, Size().iHeight/2); |
|
182 TPoint imgTl = myCentre - TPoint(bgSize.iWidth / 2, bgSize.iHeight / 2); |
|
183 iBgImage->Bitblt(gc, imgTl); |
|
184 } |
|
185 } |
|
186 |
|
187 void CGuiConsAppView::BgImageReady() |
|
188 { |
|
189 if (!iLargeControl) DrawNow(); |
|
190 } |
|
191 |
|
192 void CGuiConsAppView::SizeChanged() |
|
193 { |
|
194 Layout(); |
|
195 DrawNow(); |
|
196 } |
|
197 |
|
198 TInt CGuiConsAppView::CountComponentControls() const |
|
199 { |
|
200 TInt count = 2; |
|
201 if (iLargeControl) count++; |
|
202 return count; |
|
203 } |
|
204 |
|
205 CCoeControl* CGuiConsAppView::ComponentControl(TInt aIndex) const |
|
206 { |
|
207 switch (aIndex) |
|
208 { |
|
209 case 0: |
|
210 return iLabel; |
|
211 case 1: |
|
212 return iEditor; |
|
213 case 2: |
|
214 if (iLargeControl) |
|
215 { |
|
216 return iLargeControl; |
|
217 } |
|
218 // fallthrough |
|
219 default: |
|
220 Panic(EGuiConsBadControlIndex); |
|
221 return NULL; // keep compiler quiet |
|
222 } |
|
223 } |
|
224 |
|
225 void CGuiConsAppView::Layout() |
|
226 { |
|
227 TRect myRect = Rect(); |
|
228 TSize largeSize(myRect.Size()); |
|
229 |
|
230 |
|
231 TSize editorSize(myRect.Width(), iEditor->MinimumSize().iHeight); |
|
232 TRect editorRect(myRect.iBr - editorSize.AsPoint(), editorSize); |
|
233 iEditor->SetRect(editorRect); |
|
234 iLabel->SetRect(editorRect); |
|
235 |
|
236 |
|
237 largeSize.iHeight -= editorSize.iHeight; |
|
238 |
|
239 if (iLargeControl) |
|
240 { |
|
241 TRect largeRect(myRect.iTl, largeSize); |
|
242 iLargeControl->SetRect(largeRect); |
|
243 } |
|
244 } |
|
245 |
|
246 //______________________________________________________________________________ |
|
247 // CImageDecodeAo |
|
248 CImageDecodeAo* CImageDecodeAo::NewL(CGuiConsAppView& aOwner, const TDesC& aFileName) |
|
249 { |
|
250 CImageDecodeAo* self = new(ELeave)CImageDecodeAo(aOwner); |
|
251 CleanupStack::PushL(self); |
|
252 self->ConstructL(aFileName); |
|
253 CleanupStack::Pop(self); |
|
254 return self; |
|
255 } |
|
256 |
|
257 CImageDecodeAo::~CImageDecodeAo() |
|
258 { |
|
259 Cancel(); |
|
260 delete iDecoder; |
|
261 delete iBitmap; |
|
262 delete iMask; |
|
263 iFs.Close(); |
|
264 } |
|
265 |
|
266 CFbsBitmap* CImageDecodeAo::Bitmap() |
|
267 { |
|
268 return iBitmapReady ? iBitmap : NULL; |
|
269 } |
|
270 |
|
271 void CImageDecodeAo::Bitblt(CWindowGc& aGc, TPoint aPosition) |
|
272 { |
|
273 if (!Bitmap()) return; |
|
274 aGc.BitBltMasked(aPosition, iBitmap, iBitmap->SizeInPixels(), iMask, EFalse); |
|
275 } |
|
276 |
|
277 CImageDecodeAo::CImageDecodeAo(CGuiConsAppView& aOwner) |
|
278 : CActive(CActive::EPriorityLow), iOwner(aOwner) |
|
279 { |
|
280 CActiveScheduler::Add(this); |
|
281 } |
|
282 |
|
283 void CImageDecodeAo::ConstructL(const TDesC& aFileName) |
|
284 { |
|
285 User::LeaveIfError(iFs.Connect()); |
|
286 User::LeaveIfError(iFs.ShareAuto()); |
|
287 TFindFile ff(iFs); |
|
288 User::LeaveIfError(ff.FindByDir(aFileName, KNullDesC)); |
|
289 |
|
290 iDecoder = CImageDecoder::FileNewL(iFs, ff.File()); |
|
291 iBitmap = new(ELeave)CFbsBitmap; |
|
292 iMask = new(ELeave)CFbsBitmap; |
|
293 User::LeaveIfError(iBitmap->Create(iDecoder->FrameInfo().iOverallSizeInPixels, iDecoder->FrameInfo().iFrameDisplayMode)); |
|
294 User::LeaveIfError(iMask->Create(iDecoder->FrameInfo().iOverallSizeInPixels, EGray2)); |
|
295 iDecoder->Convert(&iStatus, *iBitmap, *iMask); |
|
296 SetActive(); |
|
297 } |
|
298 |
|
299 void CImageDecodeAo::RunL() |
|
300 { |
|
301 if (iStatus.Int()==0) |
|
302 { |
|
303 iBitmapReady = ETrue; |
|
304 iOwner.BgImageReady(); |
|
305 } |
|
306 } |
|
307 |
|
308 void CImageDecodeAo::DoCancel() |
|
309 { |
|
310 iDecoder->Cancel(); |
|
311 } |