|
1 |
|
2 // Copyright (c) 2004-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: |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "SIPExGameContainer.h" |
|
21 #include "SIPExGameView.h" |
|
22 #include "SIPExApp.h" |
|
23 #include "SIPExGameConstants.h" |
|
24 |
|
25 #include <sipex.rsg> |
|
26 #include <eiklabel.h> |
|
27 #include <eikgted.h> // CGlobalTextEditor |
|
28 #include <eikenv.h> |
|
29 #include <txtglobl.h> // CGlobalText |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KUndefinedControlId( -3000 ); |
|
33 const TInt KComponentCount( 3 ); |
|
34 const TUid KViewUid = { 0x00000001 }; |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CSIPExGameContainer::NewL |
|
38 // Static constructor |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CSIPExGameContainer* CSIPExGameContainer::NewL( |
|
42 const TRect& aRect, |
|
43 CSIPExEngine& aGameData ) |
|
44 { |
|
45 CSIPExGameContainer* self = CSIPExGameContainer::NewLC( aRect, aGameData ); |
|
46 CleanupStack::Pop( self ); |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSIPExGameContainer::NewLC |
|
52 // Static constructor. On return the instance is left to the CleanupStack. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CSIPExGameContainer* CSIPExGameContainer::NewLC( |
|
56 const TRect& aRect, |
|
57 CSIPExEngine& aGameData ) |
|
58 { |
|
59 CSIPExGameContainer* self = new ( ELeave ) CSIPExGameContainer; |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL( aRect, aGameData ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSIPExGameContainer::~CSIPExGameContainer |
|
67 // Destructor |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CSIPExGameContainer::~CSIPExGameContainer() |
|
71 { |
|
72 delete iStatusLbl; |
|
73 delete iGameView; |
|
74 delete iEditor; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CSIPExGameContainer::ConstructL |
|
79 // Symbian 2nd phase constructor that might leave. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CSIPExGameContainer::ConstructL( |
|
83 const TRect& aRect, |
|
84 CSIPExEngine& aGameData ) |
|
85 { |
|
86 iGameEngine = &aGameData; |
|
87 // Create a window for this application view |
|
88 CreateWindowL(); |
|
89 |
|
90 // Set the windows size |
|
91 SetRect( aRect ); |
|
92 // Indicate that the control is blank |
|
93 SetBlank(); |
|
94 // Set the control's border |
|
95 SetBorder( TGulBorder::EFlatContainer ); |
|
96 |
|
97 // Initialize controls |
|
98 CreateGameViewL(); |
|
99 CreateStateViewEditorL(); |
|
100 |
|
101 // Activate the window, which makes it ready to be drawn |
|
102 ActivateL(); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CSIPExGameContainer::CSIPExGameContainer |
|
107 // C++ default constructor |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CSIPExGameContainer::CSIPExGameContainer() |
|
111 { |
|
112 // no implementation required |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CSIPExGameContainer::CountRects |
|
117 // Calculates rectangles for all different areas. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CSIPExGameContainer::CountRects() |
|
121 { |
|
122 iGameAreaRect = TRect( TPoint( 20, 30 ), TSize( 220, 205 ) ); |
|
123 iStatusLblRect = TRect( TPoint( 20, 5 ), TSize( 220, 25 ) ); |
|
124 iEditorRect = TRect( TPoint( 265, 5 ), TSize( 230, 230 ) ); |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CSIPExGameContainer::CreateStateViewEditorL |
|
129 // Creates the state window and status label. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CSIPExGameContainer::CreateStateViewEditorL() |
|
133 { |
|
134 iEditor = new (ELeave) CEikGlobalTextEditor(); |
|
135 TInt flags( EEikEdwinNoAutoSelection | |
|
136 EEikEdwinJustAutoCurEnd | |
|
137 EEikEdwinLineCursor | |
|
138 EEikEdwinNoHorizScrolling ); |
|
139 // The max number of characters in editor 1k |
|
140 iEditor->ConstructL( this, 7, 1024, flags, EGulFontControlAll, EGulAllFonts ); |
|
141 iEditor->SetContainerWindowL( *this ); |
|
142 iEditor->SetRect( iEditorRect ); |
|
143 iEditor->ActivateL(); |
|
144 iEditor->CreateScrollBarFrameL(); |
|
145 iEditor->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
146 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
147 |
|
148 iStatusLbl = new (ELeave) CEikLabel(); |
|
149 iStatusLbl->SetContainerWindowL( *this ); |
|
150 iStatusLbl->SetRect( iStatusLblRect ); |
|
151 iStatusLbl->ActivateL(); |
|
152 iStatusLbl->SetTextL( KNullDesC ); |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CSIPExGameContainer::CreateGameViewL |
|
157 // Creates the game board view. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CSIPExGameContainer::CreateGameViewL() |
|
161 { |
|
162 iGameView = CSIPExGameView::NewL( iGameAreaRect, this, *iGameEngine ); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CSIPExGameContainer::CountComponentControls |
|
167 // From CCoeControl. |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 TInt CSIPExGameContainer::CountComponentControls() const |
|
171 { |
|
172 return KComponentCount; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CSIPExGameContainer::ComponentControl |
|
177 // From CCoeControl. |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 CCoeControl* CSIPExGameContainer::ComponentControl( TInt aIndex ) const |
|
181 { |
|
182 switch( aIndex ) |
|
183 { |
|
184 case 0: |
|
185 return iEditor; |
|
186 case 1: |
|
187 return iGameView; |
|
188 case 2: |
|
189 return iStatusLbl; |
|
190 |
|
191 default: |
|
192 { |
|
193 _LIT( KPanicCntx, "SIP Example" ); |
|
194 __ASSERT_ALWAYS( |
|
195 EFalse, User::Panic( KPanicCntx(), KUndefinedControlId ) ); |
|
196 } |
|
197 } |
|
198 return NULL; |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CSIPExGameContainer::Draw |
|
203 // From CCoeControl. |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CSIPExGameContainer::Draw( const TRect& aRect ) const |
|
207 { |
|
208 CEikBorderedControl::Draw( aRect ); |
|
209 CWindowGc& gc = SystemGc(); |
|
210 |
|
211 // Ensure that the border is not overwritten |
|
212 // by future drawing operations |
|
213 gc.SetClippingRect( Border().InnerRect( Rect() ) ); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CSIPExGameContainer::SizeChanged |
|
218 // From CCoeControl. |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CSIPExGameContainer::SizeChanged() |
|
222 { |
|
223 CountRects(); |
|
224 |
|
225 if( iGameView ) |
|
226 { |
|
227 iGameView->SetRect( iGameAreaRect ); |
|
228 } |
|
229 if( iEditor ) |
|
230 { |
|
231 iEditor->SetRect( iEditorRect ); |
|
232 } |
|
233 if( iStatusLbl ) |
|
234 { |
|
235 iStatusLbl->SetRect( iStatusLblRect ); |
|
236 } |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CSIPExGameContainer::ShowInfoL |
|
241 // From MSIPExStateViewNotifier. |
|
242 // Appends the text to the globaltexteditor. After each line the line break is |
|
243 // added. |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CSIPExGameContainer::ShowInfoL( const TDesC& aText ) |
|
247 { |
|
248 CGlobalText* globalText = iEditor->GlobalText(); |
|
249 globalText->InsertL( globalText->DocumentLength(), aText ); |
|
250 globalText->InsertL( |
|
251 globalText->DocumentLength(), CEditableText::ELineBreak ); |
|
252 |
|
253 TCharFormat charFormat; |
|
254 TCharFormatMask charMask; |
|
255 iEditor->ApplyCharFormatL( charFormat, charMask ); |
|
256 |
|
257 iEditor->MoveCursorL( TCursorPosition::EFPageDown, EFalse ); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CSIPExGameContainer::ShowInfoL |
|
262 // From MSIPExStateViewNotifier. |
|
263 // Converts the 8-bit descriptor to 16-bit desc. and calls the overwritten |
|
264 // ShowInfoL |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CSIPExGameContainer::ShowInfoL( const TDesC8& aText ) |
|
268 { |
|
269 HBufC* buf = HBufC::NewLC( aText.Length() ); |
|
270 buf->Des().Copy( aText ); |
|
271 ShowInfoL( *buf ); |
|
272 CleanupStack::PopAndDestroy( buf ); |
|
273 } |
|
274 |
|
275 // ----------------------------------------------------------------------------- |
|
276 // CSIPExGameContainer::ShowStatusInfoL |
|
277 // From MSIPExStateViewNotifier. Updates the game status label text. |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 void CSIPExGameContainer::ShowStatusInfoL( const TDesC& aText ) |
|
281 { |
|
282 iStatusLbl->SetTextL( aText ); |
|
283 DrawNow(); |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CSIPExGameContainer::OfferKeyEventL |
|
288 // From CCoeControl. Redirect the keyevent to the game view. |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 TKeyResponse CSIPExGameContainer::OfferKeyEventL( |
|
292 const TKeyEvent& aKeyEvent, |
|
293 TEventCode aType ) |
|
294 { |
|
295 return iGameView->OfferKeyEventL( aKeyEvent, aType ); |
|
296 } |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // CSIPProfileListContainer::ViewId |
|
300 // From MCoeView. |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 TVwsViewId CSIPExGameContainer::ViewId() const |
|
304 { |
|
305 TVwsViewId id; |
|
306 id.iAppUid = KUidSIPExApp; |
|
307 id.iViewUid = KViewUid; |
|
308 return id; |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CSIPProfileListContainer::ViewActivatedL |
|
313 // From MCoeView. |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CSIPExGameContainer::ViewActivatedL( |
|
317 const TVwsViewId& /*aPrevViewId*/, |
|
318 TUid /*aCustomMessageId*/,const TDesC8& /*aCustomMessage*/) |
|
319 { |
|
320 // Not used. Implemented to get around the focus disapearing problem. |
|
321 } |
|
322 |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CSIPProfileListContainer::ViewDeactivated |
|
325 // From MCoeView. |
|
326 // ----------------------------------------------------------------------------- |
|
327 // |
|
328 void CSIPExGameContainer::ViewDeactivated() |
|
329 { |
|
330 // Not used. Implemented to get around the focus disapearing problem. |
|
331 } |
|
332 |
|
333 // End of file |
|
334 |