Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ========================================================================
- Name : GPSDemoContainer.cpp
- Author :
- Copyright : Your copyright notice
- Description :
- ========================================================================
- */
- // [[[ begin generated region: do not modify [Generated System Includes]
- #include <barsread.h>
- #include <stringloader.h>
- #include <aknlists.h>
- #include <eikenv.h>
- #include <akniconarray.h>
- #include <eikclbd.h>
- #include <aknviewappui.h>
- #include <eikappui.h>
- #include <GPSDemo.rsg>
- // ]]] end generated region [Generated System Includes]
- // [[[ begin generated region: do not modify [Generated User Includes]
- #include "GPSDemoContainer.h"
- #include "GPSDemoContainerView.h"
- #include "GPSDemo.hrh"
- // ]]] end generated region [Generated User Includes]
- //#include <lbs.h>
- #pragma comment(lib, "c:\\Symbian\\9.2\\S60_3rd_FP1\\Epoc32\\release\\winscw\\udeb\\lbs.lib")
- //#include "LBSPositionlistener.h"
- #include "LBSPositionRequestor.h"
- _LIT(KFormatListItemText, "\t%s: %f\t");
- _LIT(KLatText, "Lat");
- _LIT(KLonText, "Lon");
- _LIT(KAltText, "Alt");
- // [[[ begin generated region: do not modify [Generated Constants]
- // ]]] end generated region [Generated Constants]
- /**
- * First phase of Symbian two-phase construction. Should not
- * contain any code that could leave.
- */
- CGPSDemoContainer::CGPSDemoContainer()
- {
- // [[[ begin generated region: do not modify [Generated Contents]
- iListBox = NULL;
- // ]]] end generated region [Generated Contents]
- }
- /**
- * Destroy child controls.
- */
- CGPSDemoContainer::~CGPSDemoContainer()
- {
- // [[[ begin generated region: do not modify [Generated Contents]
- delete iListBox;
- iListBox = NULL;
- // ]]] end generated region [Generated Contents]
- delete iPositionRequestor;
- }
- /**
- * 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 CGPSDemoContainer
- */
- CGPSDemoContainer* CGPSDemoContainer::NewL(
- const TRect& aRect,
- const CCoeControl* aParent,
- MEikCommandObserver* aCommandObserver )
- {
- CGPSDemoContainer* self = CGPSDemoContainer::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 CGPSDemoContainer
- */
- CGPSDemoContainer* CGPSDemoContainer::NewLC(
- const TRect& aRect,
- const CCoeControl* aParent,
- MEikCommandObserver* aCommandObserver )
- {
- CGPSDemoContainer* self = new ( ELeave ) CGPSDemoContainer();
- 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 CGPSDemoContainer::ConstructL(
- const TRect& aRect,
- const CCoeControl* aParent,
- MEikCommandObserver* aCommandObserver )
- {
- if ( aParent == NULL )
- {
- CreateWindowL();
- }
- else
- {
- SetContainerWindowL( *aParent );
- }
- iFocusControl = NULL;
- iCommandObserver = aCommandObserver;
- InitializeControlsL();
- SetRect( aRect );
- ActivateL();
- // [[[ begin generated region: do not modify [Post-ActivateL initializations]
- // ]]] end generated region [Post-ActivateL initializations]
- iPositionRequestor = CLbsPositionRequestor::NewL(*this);
- }
- /**
- * Return the number of controls in the container (override)
- * @return count
- */
- TInt CGPSDemoContainer::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* CGPSDemoContainer::ComponentControl( TInt aIndex ) const
- {
- // [[[ begin generated region: do not modify [Generated Contents]
- switch ( aIndex )
- {
- case EListBox:
- return iListBox;
- }
- // ]]] 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 CGPSDemoContainer::SizeChanged()
- {
- CCoeControl::SizeChanged();
- LayoutControls();
- // [[[ 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 CGPSDemoContainer::LayoutControls()
- {
- iListBox->SetExtent( TPoint( 0, 0 ), iListBox->MinimumSize() );
- }
- // ]]] end generated function
- /**
- * Handle key events.
- */
- TKeyResponse CGPSDemoContainer::OfferKeyEventL(
- const TKeyEvent& aKeyEvent,
- TEventCode aType )
- {
- // [[[ begin generated region: do not modify [Generated Contents]
- if ( aKeyEvent.iCode == EKeyLeftArrow
- || aKeyEvent.iCode == EKeyRightArrow )
- {
- // Listbox takes all events even if it doesn't use them
- return EKeyWasNotConsumed;
- }
- // ]]] 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 CGPSDemoContainer::InitializeControlsL()
- {
- iListBox = new ( ELeave ) CAknSingleHeadingStyleListBox;
- iListBox->SetContainerWindowL( *this );
- {
- TResourceReader reader;
- iEikonEnv->CreateResourceReaderLC( reader, R_GPSDEMO_CONTAINER_LIST_BOX );
- iListBox->ConstructFromResourceL( reader );
- CleanupStack::PopAndDestroy(); // reader internal state
- }
- // the listbox owns the items in the list and will free them
- iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
- // setup the icon array so graphics-style boxes work
- SetupListBoxIconsL();
- // add list items
- iListBox->SetFocus( ETrue );
- iFocusControl = iListBox;
- }
- // ]]] end generated function
- /**
- * Handle global resource changes, such as scalable UI or skin events (override)
- */
- void CGPSDemoContainer::HandleResourceChange( TInt aType )
- {
- CCoeControl::HandleResourceChange( aType );
- SetRect( iAvkonViewAppUi->View( TUid::Uid( EGPSDemoContainerViewId ) )->ClientRect() );
- // [[[ begin generated region: do not modify [Generated Contents]
- // ]]] end generated region [Generated Contents]
- }
- /**
- * Draw container contents.
- */
- void CGPSDemoContainer::Draw( const TRect& aRect ) const
- {
- // [[[ begin generated region: do not modify [Generated Contents]
- CWindowGc& gc = SystemGc();
- gc.Clear( aRect );
- // ]]] end generated region [Generated Contents]
- }
- // [[[ begin generated function: do not modify
- /**
- * Add a list box item to a list.
- */
- void CGPSDemoContainer::AddListBoxItemL(
- CEikTextListBox* aListBox,
- const TDesC& aString )
- {
- CTextListBoxModel* model = aListBox->Model();
- CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
- itemArray->AppendL( aString );
- aListBox->HandleItemAdditionL();
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Get the array of selected item indices, with respect to the list model.
- * The array is sorted in ascending order.
- * The array should be destroyed with two calls to CleanupStack::PopAndDestroy(),
- * the first with no argument (referring to the internal resource) and the
- * second with the array pointer.
- * @return newly allocated array, which is left on the cleanup stack;
- * or NULL for empty list.
- */
- RArray< TInt >* CGPSDemoContainer::GetSelectedListBoxItemsLC( CEikTextListBox* aListBox )
- {
- CAknFilteredTextListBoxModel* model =
- static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() );
- if ( model->NumberOfItems() == 0 )
- return NULL;
- // get currently selected indices
- const CListBoxView::CSelectionIndexArray* selectionIndexes =
- aListBox->SelectionIndexes();
- TInt selectedIndexesCount = selectionIndexes->Count();
- if ( selectedIndexesCount == 0 )
- return NULL;
- // copy the indices and sort numerically
- RArray<TInt>* orderedSelectedIndices =
- new (ELeave) RArray< TInt >( selectedIndexesCount );
- // push the allocated array
- CleanupStack::PushL( orderedSelectedIndices );
- // dispose the array resource
- CleanupClosePushL( *orderedSelectedIndices );
- // see if the search field is enabled
- CAknListBoxFilterItems* filter = model->Filter();
- if ( filter != NULL )
- {
- // when filtering enabled, translate indices back to underlying model
- for ( TInt idx = 0; idx < selectedIndexesCount; idx++ )
- {
- TInt filteredItem = ( *selectionIndexes ) [ idx ];
- TInt actualItem = filter->FilteredItemIndex ( filteredItem );
- orderedSelectedIndices->InsertInOrder( actualItem );
- }
- }
- else
- {
- // the selection indices refer directly to the model
- for ( TInt idx = 0; idx < selectedIndexesCount; idx++ )
- orderedSelectedIndices->InsertInOrder( ( *selectionIndexes ) [ idx ] );
- }
- return orderedSelectedIndices;
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Delete the selected item or items from the list box.
- */
- void CGPSDemoContainer::DeleteSelectedListBoxItemsL( CEikTextListBox* aListBox )
- {
- CAknFilteredTextListBoxModel* model =
- static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() );
- if ( model->NumberOfItems() == 0 )
- return;
- RArray< TInt >* orderedSelectedIndices = GetSelectedListBoxItemsLC( aListBox );
- if ( !orderedSelectedIndices )
- return;
- // Delete selected items from bottom up so indices don't change on us
- CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
- TInt currentItem = 0;
- for ( TInt idx = orderedSelectedIndices->Count(); idx-- > 0; )
- {
- currentItem = ( *orderedSelectedIndices )[ idx ];
- itemArray->Delete ( currentItem );
- }
- // dispose the array resources
- CleanupStack::PopAndDestroy();
- // dispose the array pointer
- CleanupStack::PopAndDestroy( orderedSelectedIndices );
- // refresh listbox's cursor now that items are deleted
- AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
- aListBox, currentItem, ETrue );
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Get the listbox.
- */
- CAknSingleHeadingStyleListBox* CGPSDemoContainer::ListBox()
- {
- return iListBox;
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Create a list box item with the given column values.
- */
- void CGPSDemoContainer::CreateListBoxItemL( TDes& aBuffer,
- const TDesC& aHeadingText,
- const TDesC& aMainText )
- {
- _LIT ( KStringHeader, "%S\t%S" );
- aBuffer.Format( KStringHeader(), &aHeadingText, &aMainText );
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Add an item to the list by reading the text items from the array resource
- * and setting a single image property (if available) from an index
- * in the list box's icon array.
- * @param aResourceId id of an ARRAY resource containing the textual
- * items in the columns
- *
- */
- void CGPSDemoContainer::AddListBoxResourceArrayItemL( TInt aResourceId )
- {
- CDesCArray* array = iCoeEnv->ReadDesCArrayResourceL( aResourceId );
- CleanupStack::PushL( array );
- // This is intended to be large enough, but if you get
- // a USER 11 panic, consider reducing string sizes.
- TBuf<512> listString;
- CreateListBoxItemL( listString, ( *array ) [ 0 ], ( *array ) [ 1 ] );
- AddListBoxItemL( iListBox, listString );
- CleanupStack::PopAndDestroy( array );
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Set up the list's icon array.
- */
- void CGPSDemoContainer::SetupListBoxIconsL()
- {
- CArrayPtr< CGulIcon >* icons = NULL;
- if ( icons != NULL )
- {
- iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
- }
- }
- // ]]] end generated function
- // [[[ begin generated function: do not modify
- /**
- * Handle commands relating to markable lists.
- */
- TBool CGPSDemoContainer::HandleMarkableListCommandL( TInt aCommand )
- {
- return EFalse;
- }
- // ]]] end generated function
- /*void CGPSDemoContainer::StartTrackingLC() {
- this.iModuleId = TUid::Uid(270526858); // Internal GPS
- User::LeaveIfError(this.iServer.Connect());
- CleanupClosePushL(this.iPosServer);
- User::LeaveIfError(this.iPositioner.Open(this.iPosServer, this.iModuleId));
- CleanupClosePushL(this.iPositioner);
- this.iUpdateOptions.SetUpdateInterval(1000000);
- this.iUpdateOptions.SetUpdateTimeOut(15000000);
- this.iUpdateOptions.SetMaxUpdateAge(1000000);
- this.iUpdateOptions.SetAcceptPartialUpdates(ETrue);
- this.iPositioner.SetUpdateOptions(this.iUpdateOptions);
- _LIT(KRequestor, "S60 GPS Demo");
- User::LeaveIfError(
- this.iPositioner.SetRequestor(CRequestor::ERequestorService,
- CRequestor::EFormatApplication, KRequestor)
- );
- User::LeaveIfError(this.iPositioner.NotifyPositionUpdate(this.iPosInfo, this.iStatus));
- }*/
- //void CGPSDemoContainer::StopTracking/*L*//* L - ? */() {
- // CleanupStack::PopAndDestroy(2);
- //}
- void CGPSDemoContainer::PositionInfoUpdatedL(TPositionInfoBase& aPosInfo,
- const TDesC& aModulename)
- {
- //TInt count = iItemArray->Count();
- //iItemArray->Reset();
- // Set the module name
- //iModuleName = aModulename;
- //AddItemInListL(KTxtModuleName, iModuleName);
- // Check the type of the updated position information
- // and process that information.
- // Check if position information class type is TPositionSatelliteInfo
- if (aPosInfo.PositionClassType() & EPositionSatelliteInfoClass)
- {
- // Cast the TPositionInfoBase object to TPositionSatelliteInfo
- //TPositionSatelliteInfo* posInfo = static_cast<TPositionSatelliteInfo*>(&aPosInfo);
- // Process the satellite information
- //ProcessSatelliteInfoL( *posInfo );
- }
- // Check if position information class type is TPositionInfo
- else if (aPosInfo.PositionClassType() & EPositionInfoClass)
- {
- //Cast the TPositionInfoBase object to TPositionInfo
- TPositionInfo* posInfo = static_cast<TPositionInfo*>(&aPosInfo);
- TPosition* pos;
- posInfo->GetPosition(*pos);
- //Process the position information
- //ProcessPositionInfoL( *posInfo );
- CDesCArray* iItemArray;
- MDesCArray* itemList = iListBox->Model()->ItemTextArray();
- iItemArray = (CDesCArray*) itemList;
- iItemArray->Reset();
- TBuf<100> buff;
- buff.Zero();
- buff.Format(KFormatListItemText, KLatText, pos->Latitude());
- iItemArray->AppendL(buff);
- buff.Zero();
- buff.Format(KFormatListItemText, KLonText, pos->Longitude());
- iItemArray->AppendL(buff);
- buff.Zero();
- buff.Format(KFormatListItemText, KAltText, pos->Altitude());
- iItemArray->AppendL(buff);
- }
- /*if (count < iItemArray->Count())
- {
- //iListBox->HandleItemAdditionL();
- }
- else if (count > iItemArray->Count())
- {
- //iListBox->HandleItemRemovalL();
- }
- else
- {
- //iListBox->DrawNow();
- }*/
- }
- void CGPSDemoContainer::ShowErrorL(const TDesC& aErrorString) {
- }
- void CGPSDemoContainer::ShowMessageL(const TDesC& aMessage) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement