~ubuntu-branches/ubuntu/wily/sflphone/wily

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
========================================================================
 Name        : pjsuaContainer.cpp
 Author      : nanang
 Copyright   : Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <barsread.h>
#include <eikimage.h>
#include <eikenv.h>
#include <stringloader.h>
#include <eiklabel.h>
#include <aknviewappui.h>
#include <eikappui.h>
#include <akniconutils.h>
#include <pjsua.mbg>
#include <pjsua.rsg>
// ]]] end generated region [Generated System Includes]

// [[[ begin generated region: do not modify [Generated User Includes]
#include "pjsuaContainer.h"
#include "pjsuaContainerView.h"
#include "pjsua.hrh"
// ]]] end generated region [Generated User Includes]

#include <eikmenub.h>

// [[[ begin generated region: do not modify [Generated Constants]
_LIT( KpjsuaFile, "\\resource\\apps\\pjsua.mbm" );
// ]]] end generated region [Generated Constants]

/**
 * First phase of Symbian two-phase construction. Should not 
 * contain any code that could leave.
 */
CPjsuaContainer::CPjsuaContainer()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iImage1 = NULL;
	iLabel1 = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
/** 
 * Destroy child controls.
 */
CPjsuaContainer::~CPjsuaContainer()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iImage1;
	iImage1 = NULL;
	delete iLabel1;
	iLabel1 = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
				
/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is not left on cleanup stack.
 * @param aRect bounding rectangle
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return initialized instance of CPjsuaContainer
 */
CPjsuaContainer* CPjsuaContainer::NewL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	CPjsuaContainer* self = CPjsuaContainer::NewLC( 
			aRect, 
			aParent, 
			aCommandObserver );
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is left on cleanup stack.
 * @param aRect The rectangle for this window
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return new instance of CPjsuaContainer
 */
CPjsuaContainer* CPjsuaContainer::NewLC( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	CPjsuaContainer* self = new ( ELeave ) CPjsuaContainer();
	CleanupStack::PushL( self );
	self->ConstructL( aRect, aParent, aCommandObserver );
	return self;
	}
			
/**
 * Construct the control (second phase).
 *  Creates a window to contain the controls and activates it.
 * @param aRect bounding rectangle
 * @param aCommandObserver command observer
 * @param aParent owning parent, or NULL
 */ 
void CPjsuaContainer::ConstructL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	if ( aParent == NULL )
	    {
		CreateWindowL();
	    }
	else
	    {
	    SetContainerWindowL( *aParent );
	    }
	iFocusControl = NULL;
	iCommandObserver = aCommandObserver;
	InitializeControlsL();
	SetRect( aRect );

	// Full screen
	SetExtentToWholeScreen();
	
	// Set label color
	//iLabel1->OverrideColorL( EColorLabelText, KRgbWhite );
	//iLabel1->OverrideColorL(EColorControlBackground, KRgbBlack )
	iLabel1->SetEmphasis( CEikLabel::EFullEmphasis);
	iLabel1->OverrideColorL( EColorLabelHighlightFullEmphasis, KRgbBlack );
	iLabel1->OverrideColorL( EColorLabelTextEmphasis, KRgbWhite );

	// Set label font
	 CFont* fontUsed;
	_LIT(f,"Arial");
	TFontSpec* fontSpec = new TFontSpec(f, 105);
	TFontStyle* fontStyle = new TFontStyle();
	fontStyle->SetPosture(EPostureUpright);
	fontStyle->SetStrokeWeight(EStrokeWeightNormal);
	fontSpec->iFontStyle = *fontStyle;
	fontUsed = iCoeEnv->CreateScreenFontL(*fontSpec);
	iLabel1->SetFont(fontUsed);
	iLabel1->SetAlignment( EHCenterVCenter );
	
	ActivateL();
	// [[[ begin generated region: do not modify [Post-ActivateL initializations]
	// ]]] end generated region [Post-ActivateL initializations]
	
	}
			
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CPjsuaContainer::CountComponentControls() const
	{
	return ( int ) ELastControl;
	}
				
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CPjsuaContainer::ComponentControl( TInt aIndex ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	switch ( aIndex )
		{
		case EImage1:
			return iImage1;
		case ELabel1:
			return iLabel1;
		}
	// ]]] end generated region [Generated Contents]
	
	// handle any user controls here...
	
	return NULL;
	}
				
/**
 *	Handle resizing of the container. This implementation will lay out
 *  full-sized controls like list boxes for any screen size, and will layout
 *  labels, editors, etc. to the size they were given in the UI designer.
 *  This code will need to be modified to adjust arbitrary controls to
 *  any screen size.
 */				
void CPjsuaContainer::SizeChanged()
	{
	CCoeControl::SizeChanged();
	LayoutControls();

	// Align the image
	int x = (Size().iWidth - iImage1->Size().iWidth) / 2;
	int y = (Size().iHeight - iImage1->Size().iHeight) / 2;
	iImage1->SetPosition(TPoint(x, y));
	
	// Align the label
	iLabel1->SetExtent(TPoint(0, Size().iHeight - iLabel1->Size().iHeight),
			   TSize(Size().iWidth, iLabel1->Size().iHeight));
	
	// [[[ begin generated region: do not modify [Generated Contents]
			
	// ]]] end generated region [Generated Contents]
	
	}
				
// [[[ begin generated function: do not modify
/**
 * Layout components as specified in the UI Designer
 */
void CPjsuaContainer::LayoutControls()
	{
	iImage1->SetExtent( TPoint( 0, 0 ), TSize( 99, 111 ) );
	iLabel1->SetExtent( TPoint( 0, 196 ), TSize( 241, 27 ) );
	}
// ]]] end generated function

/**
 *	Handle key events.
 */				
TKeyResponse CPjsuaContainer::OfferKeyEventL( 
		const TKeyEvent& aKeyEvent, 
		TEventCode aType )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	
	// ]]] end generated region [Generated Contents]
	
	if ( iFocusControl != NULL
		&& iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
		{
		return EKeyWasConsumed;
		}
	return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
	}
				
// [[[ begin generated function: do not modify
/**
 *	Initialize each control upon creation.
 */				
void CPjsuaContainer::InitializeControlsL()
	{
	iImage1 = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KpjsuaFile, EMbmPjsuaPjsua, -1 );
		AknIconUtils::SetSize( bitmap, TSize( 99, 111 ), EAspectRatioPreserved );
		iImage1->SetPicture( bitmap );
		}
	iImage1->SetAlignment( EHCenterVTop );
	iLabel1 = new ( ELeave ) CEikLabel;
	iLabel1->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_PJSUA_CONTAINER_LABEL1 );
		iLabel1->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	
	}
// ]]] end generated function

/** 
 * Handle global resource changes, such as scalable UI or skin events (override)
 */
void CPjsuaContainer::HandleResourceChange( TInt aType )
	{
	CCoeControl::HandleResourceChange( aType );
	SetRect( iAvkonViewAppUi->View( TUid::Uid( EPjsuaContainerViewId ) )->ClientRect() );
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}
				
/**
 *	Draw container contents.
 */				
void CPjsuaContainer::Draw( const TRect& aRect ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CWindowGc& gc = SystemGc();
	gc.SetPenStyle( CGraphicsContext::ENullPen );
	TRgb backColor( 0,0,0 );
	gc.SetBrushColor( backColor );
	gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
	gc.DrawRect( aRect );
	
	// ]]] end generated region [Generated Contents]
	
	}

void CPjsuaContainer::PutMessageL( const char * msg )
{
    if (!iLabel1)
	return;
    
    TPtrC8 ptr(reinterpret_cast<const TUint8*>(msg));
    HBufC* buffer = HBufC::NewLC(ptr.Length());
    buffer->Des().Copy(ptr);

    iLabel1->SetTextL(*buffer);
    iLabel1->DrawNow();

    CleanupStack::PopAndDestroy(buffer);
}