blob: 5dec51f28d4a3fa5de2e596d2942ead355e24a99 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/*
2========================================================================
3 Name : pjsuaContainer.cpp
4 Author : nanang
5 Copyright : Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
6 Description :
7========================================================================
8*/
9// [[[ begin generated region: do not modify [Generated System Includes]
10#include <barsread.h>
11#include <eikimage.h>
12#include <eikenv.h>
13#include <stringloader.h>
14#include <eiklabel.h>
15#include <aknviewappui.h>
16#include <eikappui.h>
17#include <akniconutils.h>
18#include <pjsua.mbg>
19#include <pjsua.rsg>
20// ]]] end generated region [Generated System Includes]
21
22// [[[ begin generated region: do not modify [Generated User Includes]
23#include "pjsuaContainer.h"
24#include "pjsuaContainerView.h"
25#include "pjsua.hrh"
26// ]]] end generated region [Generated User Includes]
27
28#include <eikmenub.h>
29
30// [[[ begin generated region: do not modify [Generated Constants]
31_LIT( KpjsuaFile, "\\resource\\apps\\pjsua.mbm" );
32// ]]] end generated region [Generated Constants]
33
34/**
35 * First phase of Symbian two-phase construction. Should not
36 * contain any code that could leave.
37 */
38CPjsuaContainer::CPjsuaContainer()
39 {
40 // [[[ begin generated region: do not modify [Generated Contents]
41 iImage1 = NULL;
42 iLabel1 = NULL;
43 // ]]] end generated region [Generated Contents]
44
45 }
46/**
47 * Destroy child controls.
48 */
49CPjsuaContainer::~CPjsuaContainer()
50 {
51 // [[[ begin generated region: do not modify [Generated Contents]
52 delete iImage1;
53 iImage1 = NULL;
54 delete iLabel1;
55 iLabel1 = NULL;
56 // ]]] end generated region [Generated Contents]
57
58 }
59
60/**
61 * Construct the control (first phase).
62 * Creates an instance and initializes it.
63 * Instance is not left on cleanup stack.
64 * @param aRect bounding rectangle
65 * @param aParent owning parent, or NULL
66 * @param aCommandObserver command observer
67 * @return initialized instance of CPjsuaContainer
68 */
69CPjsuaContainer* CPjsuaContainer::NewL(
70 const TRect& aRect,
71 const CCoeControl* aParent,
72 MEikCommandObserver* aCommandObserver )
73 {
74 CPjsuaContainer* self = CPjsuaContainer::NewLC(
75 aRect,
76 aParent,
77 aCommandObserver );
78 CleanupStack::Pop( self );
79 return self;
80 }
81
82/**
83 * Construct the control (first phase).
84 * Creates an instance and initializes it.
85 * Instance is left on cleanup stack.
86 * @param aRect The rectangle for this window
87 * @param aParent owning parent, or NULL
88 * @param aCommandObserver command observer
89 * @return new instance of CPjsuaContainer
90 */
91CPjsuaContainer* CPjsuaContainer::NewLC(
92 const TRect& aRect,
93 const CCoeControl* aParent,
94 MEikCommandObserver* aCommandObserver )
95 {
96 CPjsuaContainer* self = new ( ELeave ) CPjsuaContainer();
97 CleanupStack::PushL( self );
98 self->ConstructL( aRect, aParent, aCommandObserver );
99 return self;
100 }
101
102/**
103 * Construct the control (second phase).
104 * Creates a window to contain the controls and activates it.
105 * @param aRect bounding rectangle
106 * @param aCommandObserver command observer
107 * @param aParent owning parent, or NULL
108 */
109void CPjsuaContainer::ConstructL(
110 const TRect& aRect,
111 const CCoeControl* aParent,
112 MEikCommandObserver* aCommandObserver )
113 {
114 if ( aParent == NULL )
115 {
116 CreateWindowL();
117 }
118 else
119 {
120 SetContainerWindowL( *aParent );
121 }
122 iFocusControl = NULL;
123 iCommandObserver = aCommandObserver;
124 InitializeControlsL();
125 SetRect( aRect );
126
127 // Full screen
128 SetExtentToWholeScreen();
129
130 // Set label color
131 //iLabel1->OverrideColorL( EColorLabelText, KRgbWhite );
132 //iLabel1->OverrideColorL(EColorControlBackground, KRgbBlack )
133 iLabel1->SetEmphasis( CEikLabel::EFullEmphasis);
134 iLabel1->OverrideColorL( EColorLabelHighlightFullEmphasis, KRgbBlack );
135 iLabel1->OverrideColorL( EColorLabelTextEmphasis, KRgbWhite );
136
137 // Set label font
138 CFont* fontUsed;
139 _LIT(f,"Arial");
140 TFontSpec* fontSpec = new TFontSpec(f, 105);
141 TFontStyle* fontStyle = new TFontStyle();
142 fontStyle->SetPosture(EPostureUpright);
143 fontStyle->SetStrokeWeight(EStrokeWeightNormal);
144 fontSpec->iFontStyle = *fontStyle;
145 fontUsed = iCoeEnv->CreateScreenFontL(*fontSpec);
146 iLabel1->SetFont(fontUsed);
147 iLabel1->SetAlignment( EHCenterVCenter );
148
149 ActivateL();
150 // [[[ begin generated region: do not modify [Post-ActivateL initializations]
151 // ]]] end generated region [Post-ActivateL initializations]
152
153 }
154
155/**
156* Return the number of controls in the container (override)
157* @return count
158*/
159TInt CPjsuaContainer::CountComponentControls() const
160 {
161 return ( int ) ELastControl;
162 }
163
164/**
165* Get the control with the given index (override)
166* @param aIndex Control index [0...n) (limited by #CountComponentControls)
167* @return Pointer to control
168*/
169CCoeControl* CPjsuaContainer::ComponentControl( TInt aIndex ) const
170 {
171 // [[[ begin generated region: do not modify [Generated Contents]
172 switch ( aIndex )
173 {
174 case EImage1:
175 return iImage1;
176 case ELabel1:
177 return iLabel1;
178 }
179 // ]]] end generated region [Generated Contents]
180
181 // handle any user controls here...
182
183 return NULL;
184 }
185
186/**
187 * Handle resizing of the container. This implementation will lay out
188 * full-sized controls like list boxes for any screen size, and will layout
189 * labels, editors, etc. to the size they were given in the UI designer.
190 * This code will need to be modified to adjust arbitrary controls to
191 * any screen size.
192 */
193void CPjsuaContainer::SizeChanged()
194 {
195 CCoeControl::SizeChanged();
196 LayoutControls();
197
198 // Align the image
199 int x = (Size().iWidth - iImage1->Size().iWidth) / 2;
200 int y = (Size().iHeight - iImage1->Size().iHeight) / 2;
201 iImage1->SetPosition(TPoint(x, y));
202
203 // Align the label
204 iLabel1->SetExtent(TPoint(0, Size().iHeight - iLabel1->Size().iHeight),
205 TSize(Size().iWidth, iLabel1->Size().iHeight));
206
207 // [[[ begin generated region: do not modify [Generated Contents]
208
209 // ]]] end generated region [Generated Contents]
210
211 }
212
213// [[[ begin generated function: do not modify
214/**
215 * Layout components as specified in the UI Designer
216 */
217void CPjsuaContainer::LayoutControls()
218 {
219 iImage1->SetExtent( TPoint( 0, 0 ), TSize( 99, 111 ) );
220 iLabel1->SetExtent( TPoint( 0, 196 ), TSize( 241, 27 ) );
221 }
222// ]]] end generated function
223
224/**
225 * Handle key events.
226 */
227TKeyResponse CPjsuaContainer::OfferKeyEventL(
228 const TKeyEvent& aKeyEvent,
229 TEventCode aType )
230 {
231 // [[[ begin generated region: do not modify [Generated Contents]
232
233 // ]]] end generated region [Generated Contents]
234
235 if ( iFocusControl != NULL
236 && iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
237 {
238 return EKeyWasConsumed;
239 }
240 return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
241 }
242
243// [[[ begin generated function: do not modify
244/**
245 * Initialize each control upon creation.
246 */
247void CPjsuaContainer::InitializeControlsL()
248 {
249 iImage1 = new ( ELeave ) CEikImage;
250 {
251 CFbsBitmap *bitmap, *mask;
252 AknIconUtils::CreateIconL( bitmap, mask,
253 KpjsuaFile, EMbmPjsuaPjsua, -1 );
254 AknIconUtils::SetSize( bitmap, TSize( 99, 111 ), EAspectRatioPreserved );
255 iImage1->SetPicture( bitmap );
256 }
257 iImage1->SetAlignment( EHCenterVTop );
258 iLabel1 = new ( ELeave ) CEikLabel;
259 iLabel1->SetContainerWindowL( *this );
260 {
261 TResourceReader reader;
262 iEikonEnv->CreateResourceReaderLC( reader, R_PJSUA_CONTAINER_LABEL1 );
263 iLabel1->ConstructFromResourceL( reader );
264 CleanupStack::PopAndDestroy(); // reader internal state
265 }
266
267 }
268// ]]] end generated function
269
270/**
271 * Handle global resource changes, such as scalable UI or skin events (override)
272 */
273void CPjsuaContainer::HandleResourceChange( TInt aType )
274 {
275 CCoeControl::HandleResourceChange( aType );
276 SetRect( iAvkonViewAppUi->View( TUid::Uid( EPjsuaContainerViewId ) )->ClientRect() );
277 // [[[ begin generated region: do not modify [Generated Contents]
278 // ]]] end generated region [Generated Contents]
279
280 }
281
282/**
283 * Draw container contents.
284 */
285void CPjsuaContainer::Draw( const TRect& aRect ) const
286 {
287 // [[[ begin generated region: do not modify [Generated Contents]
288 CWindowGc& gc = SystemGc();
289 gc.SetPenStyle( CGraphicsContext::ENullPen );
290 TRgb backColor( 0,0,0 );
291 gc.SetBrushColor( backColor );
292 gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
293 gc.DrawRect( aRect );
294
295 // ]]] end generated region [Generated Contents]
296
297 }
298
299void CPjsuaContainer::PutMessageL( const char * msg )
300{
301 if (!iLabel1)
302 return;
303
304 TPtrC8 ptr(reinterpret_cast<const TUint8*>(msg));
305 HBufC* buffer = HBufC::NewLC(ptr.Length());
306 buffer->Des().Copy(ptr);
307
308 iLabel1->SetTextL(*buffer);
309 iLabel1->DrawNow();
310
311 CleanupStack::PopAndDestroy(buffer);
312}