00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DeviceListContainer.h"
00010 #include "SharedIntermediator.h"
00011 #include <aknnotewrappers.h>
00012 #include "ThreadAOAppUi.h"
00013 #include "BTDiscoverer.h"
00014
00015
00016 #include <aknlists.h>
00017 #include <barsread.h>
00018 #include <eikclbd.h>
00019 #include <eikmenub.h>
00020 #include <ThreadAO.rsg>
00021 #include <stringloader.h>
00022 #include <uikon.hrh>
00023
00024
00025 const TInt KAknExListAddItemBufLength(256);
00026 #define KListBoxPosition TPoint(0,0)
00027
00028 _LIT( KListBoxHeader, "Bluetooth devices:");
00029
00030
00031
00032
00033
00034
00035 CDeviceListContainer::CDeviceListContainer() : iSMediator(NULL)
00036 {
00037 }
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 void CDeviceListContainer::ConstructL(const TRect& aRect)
00048 {
00049 CreateWindowL();
00050
00051
00052 iDeviceListBox = new (ELeave) CAknSingleStyleListBox;
00053 iDeviceListBox->SetContainerWindowL(*this);
00054
00055
00056 TResourceReader reader;
00057 CEikonEnv::Static()->CreateResourceReaderLC(reader, R_DEVICE_LIST_LISTBOX);
00058 iDeviceListBox->ConstructFromResourceL(reader);
00059
00060 CleanupStack::PopAndDestroy();
00061
00062
00063 iDeviceListBox->SetListBoxObserver(this);
00064
00065
00066 CreateScrollBarsL();
00067 SetRect(aRect);
00068 ActivateL();
00069
00070
00071 AddItemL(KListBoxHeader);
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 void CDeviceListContainer::CreateScrollBarsL()
00081 {
00082 iDeviceListBox->CreateScrollBarFrameL();
00083 iDeviceListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
00084 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EOn);
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 CDeviceListContainer* CDeviceListContainer::NewL(const TRect& aRect)
00096 {
00097 CDeviceListContainer* self = CDeviceListContainer::NewLC(aRect);
00098 CleanupStack::Pop(self);
00099 return self;
00100 }
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 CDeviceListContainer* CDeviceListContainer::NewLC(const TRect& aRect)
00111 {
00112 CDeviceListContainer* self = new (ELeave) CDeviceListContainer;
00113 CleanupStack::PushL(self);
00114 self->ConstructL(aRect);
00115 return self;
00116 }
00117
00118
00119
00120
00121 CDeviceListContainer::~CDeviceListContainer()
00122 {
00123 delete iDeviceListBox;
00124 }
00125
00126
00127
00128
00129
00130
00131
00132 void CDeviceListContainer::SizeChanged()
00133 {
00134 iDeviceListBox->SetExtent( KListBoxPosition,
00135 iDeviceListBox->MinimumSize() );
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145 TInt CDeviceListContainer::CountComponentControls() const
00146 {
00147 return 1;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156 CCoeControl* CDeviceListContainer::ComponentControl(TInt aIndex) const
00157 {
00158 switch (aIndex)
00159 {
00160 case 0:
00161 return iDeviceListBox;
00162 default:
00163 return NULL;
00164 }
00165 }
00166
00167
00168
00169
00170
00171
00172 void CDeviceListContainer::Draw(const TRect& aRect) const
00173 {
00174 CWindowGc& gc = SystemGc();
00175 gc.Clear(aRect);
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 TKeyResponse CDeviceListContainer::OfferKeyEventL(
00187 const TKeyEvent& aKeyEvent,TEventCode aType )
00188 {
00189 if (iDeviceListBox)
00190 return iDeviceListBox->OfferKeyEventL (aKeyEvent, aType);
00191 else
00192 return EKeyWasNotConsumed;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202 void CDeviceListContainer::HandleListBoxEventL( CEikListBox* ,
00203 TListBoxEvent aEvent )
00204 {
00205
00206 if ((aEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
00207 (aEvent == MEikListBoxObserver::EEventItemClicked))
00208 {
00209 ShowSelectedAddressL();
00210 }
00211 }
00212
00213
00214
00215
00216
00217
00218
00219 void CDeviceListContainer::AddItemL(const TDesC& aNewItem)
00220 {
00221
00222 CTextListBoxModel* model = iDeviceListBox->Model();
00223 CDesCArray* deviceArray = static_cast<CDesCArray*>(model->ItemTextArray());
00224
00225 TBuf <KAknExListAddItemBufLength> addedItem( 0 );
00226
00227
00228
00229 _LIT( beginning, " \t");
00230 addedItem.Append( beginning );
00231 addedItem.Append( aNewItem );
00232
00233
00234 deviceArray->InsertL(deviceArray->Count(), addedItem);
00235 }
00236
00237
00238
00239
00240
00241
00242 void CDeviceListContainer::HandleChangedL()
00243 {
00244 iDeviceListBox->HandleItemAdditionL();
00245 }
00246
00247
00248
00249
00250
00251
00252 void CDeviceListContainer::ShowSelectedAddressL()
00253 {
00254 if (iDeviceListBox)
00255 {
00256 CTextListBoxModel* model = iDeviceListBox->Model();
00257
00258
00259 if (model->NumberOfItems() > 0)
00260 {
00261
00262
00263 TInt itemIndex = iDeviceListBox->CurrentItemIndex();
00264
00265
00266 if (itemIndex > 0)
00267 {
00268 TBuf <KBTDeviceAddress> address;
00269 iSMediator->GetAddress(address, itemIndex -1);
00270
00271
00272 CAknInformationNote* addressNote =
00273 new (ELeave) CAknInformationNote;
00274 addressNote->ExecuteLD(address);
00275 }
00276 }
00277 }
00278
00279 }
00280
00281
00282
00283
00284
00285
00286 void CDeviceListContainer::SetSMediator(CSharedIntermediator* aSMediator)
00287 {
00288 iSMediator = aSMediator;
00289 }
00290
00291
00292
00293
00294
00295
00296
00297 void CDeviceListContainer::ClearListBox()
00298 {
00299 CTextListBoxModel* model = iDeviceListBox->Model();
00300 CDesCArray* deviceArray = static_cast <CDesCArray*>(model->ItemTextArray());
00301 deviceArray->Reset();
00302 }
00303
00304 void CDeviceListContainer::HandleResourceChange(TInt aType)
00305 {
00306 CCoeControl::HandleResourceChange(aType);
00307 if ( aType==KEikDynamicLayoutVariantSwitch )
00308 {
00309 TRect rect;
00310 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00311 SetRect(rect);
00312 }
00313 }
00314