|
1 /* |
|
2 * Copyright (c) 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: CListBoxTestControl test class for STIF Test Framework TestScripter. |
|
15 * |
|
16 */ |
|
17 #include "ListBoxTestControl.h" |
|
18 #include <eikenv.h> |
|
19 #include <aknsutils.h> |
|
20 #include <aknsdrawutils.h> |
|
21 #include <aknutils.h> |
|
22 #include <aknsbasicbackgroundcontrolcontext.h> |
|
23 #include <eiklbi.h> |
|
24 |
|
25 CListBoxTestControl::~CListBoxTestControl() |
|
26 { |
|
27 delete iListBox; |
|
28 iListBox = NULL; |
|
29 delete iBgContext; |
|
30 iBgContext = NULL; |
|
31 } |
|
32 |
|
33 CListBoxTestControl* CListBoxTestControl::NewL(void) |
|
34 { |
|
35 CListBoxTestControl* self = new(ELeave)CListBoxTestControl(); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 void CListBoxTestControl::ConstructL(void) |
|
43 { |
|
44 CreateWindowL(); |
|
45 |
|
46 |
|
47 iListBox = new(ELeave) CEikTextListBox(); |
|
48 iListBox->SetContainerWindowL(*this); |
|
49 iListBox->SetMopParent(this); |
|
50 iListBox->ConstructL( this, EAknListBoxSelectionList ); |
|
51 |
|
52 CDesCArray* items = static_cast<CDesCArray*> (iListBox->Model()->ItemTextArray()); |
|
53 _LIT(KItem1, "MenuItem_1"); |
|
54 items->AppendL(KItem1); |
|
55 _LIT(KItem2, "MenuItem_2"); |
|
56 items->AppendL(KItem2); |
|
57 _LIT(KItem3, "MenuItem_3"); |
|
58 items->AppendL(KItem3); |
|
59 _LIT(KItem4, "MenuItem_4"); |
|
60 items->AppendL(KItem4); |
|
61 _LIT(KItem5, "MenuItem_5"); |
|
62 items->AppendL(KItem5); |
|
63 |
|
64 iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray); |
|
65 |
|
66 iListBox->HandleItemAdditionL(); |
|
67 iListBox->SetFocus(ETrue); |
|
68 |
|
69 |
|
70 iListBox->CreateScrollBarFrameL(); |
|
71 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
72 |
|
73 // make first with no size at all |
|
74 iBgContext = CAknsBasicBackgroundControlContext::NewL(KAknsIIDQsnBgScreen,TRect(0,0,1,1), ETrue); |
|
75 // Setting rect will cause SizeChanged to be called |
|
76 // and iBgContext size & position is updated accordingly. |
|
77 SetRect( CEikonEnv::Static()->EikAppUi()->ClientRect() ); |
|
78 |
|
79 ActivateL(); |
|
80 DrawNow(); |
|
81 } |
|
82 |
|
83 void CListBoxTestControl::SizeChanged() |
|
84 { |
|
85 if ( iBgContext ) |
|
86 { |
|
87 iBgContext->SetRect(Rect()); |
|
88 |
|
89 if ( &Window() ) |
|
90 { |
|
91 iBgContext->SetParentPos( PositionRelativeToScreen() ); |
|
92 } |
|
93 } |
|
94 if ( iListBox ) |
|
95 { |
|
96 iListBox->SetRect(Rect()); |
|
97 } |
|
98 } |
|
99 |
|
100 |
|
101 void CListBoxTestControl::HandleResourceChange(TInt aType) |
|
102 { |
|
103 TRect rect; |
|
104 |
|
105 if ( aType==KEikDynamicLayoutVariantSwitch ) |
|
106 { |
|
107 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect); |
|
108 SetRect(rect); |
|
109 } |
|
110 |
|
111 CCoeControl::HandleResourceChange(aType); |
|
112 } |
|
113 |
|
114 |
|
115 TTypeUid::Ptr CListBoxTestControl::MopSupplyObject(TTypeUid aId) |
|
116 { |
|
117 if (iBgContext) |
|
118 { |
|
119 return MAknsControlContext::SupplyMopObject(aId, iBgContext ); |
|
120 } |
|
121 return CCoeControl::MopSupplyObject(aId); |
|
122 } |
|
123 |
|
124 |
|
125 void CListBoxTestControl::Draw(const TRect& aRect) const |
|
126 { |
|
127 CWindowGc& gc = SystemGc(); |
|
128 |
|
129 // draw background skin first. |
|
130 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
131 AknsDrawUtils::Background( skin, iBgContext, this, gc, aRect ); |
|
132 } |
|
133 |
|
134 TInt CListBoxTestControl::CountComponentControls() const |
|
135 { |
|
136 return 1; |
|
137 } |
|
138 |
|
139 CCoeControl* CListBoxTestControl::ComponentControl(TInt aIndex) const |
|
140 { |
|
141 switch (aIndex) |
|
142 { |
|
143 case 0: |
|
144 return iListBox; |
|
145 default: |
|
146 return 0; |
|
147 } |
|
148 } |
|
149 |
|
150 void CListBoxTestControl::HandleControlEventL( CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/) |
|
151 { |
|
152 // TODO: Add your control event handler code here |
|
153 } |
|
154 |
|
155 TKeyResponse CListBoxTestControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
156 { |
|
157 if( iListBox ) |
|
158 { |
|
159 return iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
160 } |
|
161 else |
|
162 { |
|
163 return EKeyWasNotConsumed; |
|
164 } |
|
165 } |
|
166 |