Advertisement
Artem78

GPSDemoContainer.cpp

Sep 24th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.58 KB | None | 0 0
  1. /*
  2. ========================================================================
  3.  Name        : GPSDemoContainer.cpp
  4.  Author      :
  5.  Copyright   : Your copyright notice
  6.  Description :
  7. ========================================================================
  8. */
  9. // [[[ begin generated region: do not modify [Generated System Includes]
  10. #include <barsread.h>
  11. #include <stringloader.h>
  12. #include <aknlists.h>
  13. #include <eikenv.h>
  14. #include <akniconarray.h>
  15. #include <eikclbd.h>
  16. #include <aknviewappui.h>
  17. #include <eikappui.h>
  18. #include <GPSDemo.rsg>
  19. // ]]] end generated region [Generated System Includes]
  20.  
  21. // [[[ begin generated region: do not modify [Generated User Includes]
  22. #include "GPSDemoContainer.h"
  23. #include "GPSDemoContainerView.h"
  24. #include "GPSDemo.hrh"
  25. // ]]] end generated region [Generated User Includes]
  26.  
  27.  
  28. //#include <lbs.h>
  29. #pragma comment(lib, "c:\\Symbian\\9.2\\S60_3rd_FP1\\Epoc32\\release\\winscw\\udeb\\lbs.lib")
  30.  
  31. //#include "LBSPositionlistener.h"
  32. #include "LBSPositionRequestor.h"
  33.  
  34.  
  35. _LIT(KFormatListItemText, "\t%s: %f\t");
  36. _LIT(KLatText, "Lat");
  37. _LIT(KLonText, "Lon");
  38. _LIT(KAltText, "Alt");
  39.  
  40.  
  41. // [[[ begin generated region: do not modify [Generated Constants]
  42. // ]]] end generated region [Generated Constants]
  43.  
  44. /**
  45.  * First phase of Symbian two-phase construction. Should not
  46.  * contain any code that could leave.
  47.  */
  48. CGPSDemoContainer::CGPSDemoContainer()
  49.     {
  50.     // [[[ begin generated region: do not modify [Generated Contents]
  51.     iListBox = NULL;
  52.     // ]]] end generated region [Generated Contents]
  53.    
  54.    
  55.     }
  56. /**
  57.  * Destroy child controls.
  58.  */
  59. CGPSDemoContainer::~CGPSDemoContainer()
  60.     {
  61.     // [[[ begin generated region: do not modify [Generated Contents]
  62.     delete iListBox;
  63.     iListBox = NULL;
  64.     // ]]] end generated region [Generated Contents]
  65.    
  66.    
  67.     delete iPositionRequestor;
  68.    
  69.     }
  70.                
  71. /**
  72.  * Construct the control (first phase).
  73.  *  Creates an instance and initializes it.
  74.  *  Instance is not left on cleanup stack.
  75.  * @param aRect bounding rectangle
  76.  * @param aParent owning parent, or NULL
  77.  * @param aCommandObserver command observer
  78.  * @return initialized instance of CGPSDemoContainer
  79.  */
  80. CGPSDemoContainer* CGPSDemoContainer::NewL(
  81.         const TRect& aRect,
  82.         const CCoeControl* aParent,
  83.         MEikCommandObserver* aCommandObserver )
  84.     {
  85.     CGPSDemoContainer* self = CGPSDemoContainer::NewLC(
  86.             aRect,
  87.             aParent,
  88.             aCommandObserver );
  89.     CleanupStack::Pop( self );
  90.     return self;
  91.     }
  92.  
  93. /**
  94.  * Construct the control (first phase).
  95.  *  Creates an instance and initializes it.
  96.  *  Instance is left on cleanup stack.
  97.  * @param aRect The rectangle for this window
  98.  * @param aParent owning parent, or NULL
  99.  * @param aCommandObserver command observer
  100.  * @return new instance of CGPSDemoContainer
  101.  */
  102. CGPSDemoContainer* CGPSDemoContainer::NewLC(
  103.         const TRect& aRect,
  104.         const CCoeControl* aParent,
  105.         MEikCommandObserver* aCommandObserver )
  106.     {
  107.     CGPSDemoContainer* self = new ( ELeave ) CGPSDemoContainer();
  108.     CleanupStack::PushL( self );
  109.     self->ConstructL( aRect, aParent, aCommandObserver );
  110.     return self;
  111.     }
  112.            
  113. /**
  114.  * Construct the control (second phase).
  115.  *  Creates a window to contain the controls and activates it.
  116.  * @param aRect bounding rectangle
  117.  * @param aCommandObserver command observer
  118.  * @param aParent owning parent, or NULL
  119.  */
  120. void CGPSDemoContainer::ConstructL(
  121.         const TRect& aRect,
  122.         const CCoeControl* aParent,
  123.         MEikCommandObserver* aCommandObserver )
  124.     {
  125.     if ( aParent == NULL )
  126.         {
  127.         CreateWindowL();
  128.         }
  129.     else
  130.         {
  131.         SetContainerWindowL( *aParent );
  132.         }
  133.     iFocusControl = NULL;
  134.     iCommandObserver = aCommandObserver;
  135.     InitializeControlsL();
  136.     SetRect( aRect );
  137.     ActivateL();
  138.     // [[[ begin generated region: do not modify [Post-ActivateL initializations]
  139.     // ]]] end generated region [Post-ActivateL initializations]
  140.    
  141.    
  142.     iPositionRequestor = CLbsPositionRequestor::NewL(*this);
  143.    
  144.     }
  145.            
  146. /**
  147. * Return the number of controls in the container (override)
  148. * @return count
  149. */
  150. TInt CGPSDemoContainer::CountComponentControls() const
  151.     {
  152.     return ( int ) ELastControl;
  153.     }
  154.                
  155. /**
  156. * Get the control with the given index (override)
  157. * @param aIndex Control index [0...n) (limited by #CountComponentControls)
  158. * @return Pointer to control
  159. */
  160. CCoeControl* CGPSDemoContainer::ComponentControl( TInt aIndex ) const
  161.     {
  162.     // [[[ begin generated region: do not modify [Generated Contents]
  163.     switch ( aIndex )
  164.         {
  165.     case EListBox:
  166.         return iListBox;
  167.         }
  168.     // ]]] end generated region [Generated Contents]
  169.    
  170.     // handle any user controls here...
  171.    
  172.     return NULL;
  173.     }
  174.                
  175. /**
  176.  *  Handle resizing of the container. This implementation will lay out
  177.  *  full-sized controls like list boxes for any screen size, and will layout
  178.  *  labels, editors, etc. to the size they were given in the UI designer.
  179.  *  This code will need to be modified to adjust arbitrary controls to
  180.  *  any screen size.
  181.  */            
  182. void CGPSDemoContainer::SizeChanged()
  183.     {
  184.     CCoeControl::SizeChanged();
  185.     LayoutControls();
  186.     // [[[ begin generated region: do not modify [Generated Contents]
  187.            
  188.     // ]]] end generated region [Generated Contents]
  189.    
  190.     }
  191.                
  192. // [[[ begin generated function: do not modify
  193. /**
  194.  * Layout components as specified in the UI Designer
  195.  */
  196. void CGPSDemoContainer::LayoutControls()
  197.     {
  198.     iListBox->SetExtent( TPoint( 0, 0 ), iListBox->MinimumSize() );
  199.     }
  200. // ]]] end generated function
  201.  
  202. /**
  203.  *  Handle key events.
  204.  */            
  205. TKeyResponse CGPSDemoContainer::OfferKeyEventL(
  206.         const TKeyEvent& aKeyEvent,
  207.         TEventCode aType )
  208.     {
  209.     // [[[ begin generated region: do not modify [Generated Contents]
  210.     if ( aKeyEvent.iCode == EKeyLeftArrow
  211.         || aKeyEvent.iCode == EKeyRightArrow )
  212.         {
  213.         // Listbox takes all events even if it doesn't use them
  214.         return EKeyWasNotConsumed;
  215.         }
  216.    
  217.     // ]]] end generated region [Generated Contents]
  218.    
  219.     if ( iFocusControl != NULL
  220.         && iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
  221.         {
  222.         return EKeyWasConsumed;
  223.         }
  224.     return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
  225.     }
  226.                
  227. // [[[ begin generated function: do not modify
  228. /**
  229.  *  Initialize each control upon creation.
  230.  */            
  231. void CGPSDemoContainer::InitializeControlsL()
  232.     {
  233.     iListBox = new ( ELeave ) CAknSingleHeadingStyleListBox;
  234.     iListBox->SetContainerWindowL( *this );
  235.         {
  236.         TResourceReader reader;
  237.         iEikonEnv->CreateResourceReaderLC( reader, R_GPSDEMO_CONTAINER_LIST_BOX );
  238.         iListBox->ConstructFromResourceL( reader );
  239.         CleanupStack::PopAndDestroy(); // reader internal state
  240.         }
  241.     // the listbox owns the items in the list and will free them
  242.     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
  243.    
  244.     // setup the icon array so graphics-style boxes work
  245.     SetupListBoxIconsL();
  246.    
  247.    
  248.     // add list items
  249.    
  250.     iListBox->SetFocus( ETrue );
  251.     iFocusControl = iListBox;
  252.    
  253.     }
  254. // ]]] end generated function
  255.  
  256. /**
  257.  * Handle global resource changes, such as scalable UI or skin events (override)
  258.  */
  259. void CGPSDemoContainer::HandleResourceChange( TInt aType )
  260.     {
  261.     CCoeControl::HandleResourceChange( aType );
  262.     SetRect( iAvkonViewAppUi->View( TUid::Uid( EGPSDemoContainerViewId ) )->ClientRect() );
  263.     // [[[ begin generated region: do not modify [Generated Contents]
  264.     // ]]] end generated region [Generated Contents]
  265.    
  266.     }
  267.                
  268. /**
  269.  *  Draw container contents.
  270.  */            
  271. void CGPSDemoContainer::Draw( const TRect& aRect ) const
  272.     {
  273.     // [[[ begin generated region: do not modify [Generated Contents]
  274.     CWindowGc& gc = SystemGc();
  275.     gc.Clear( aRect );
  276.    
  277.     // ]]] end generated region [Generated Contents]
  278.    
  279.     }
  280.                
  281. // [[[ begin generated function: do not modify
  282. /**
  283.  *  Add a list box item to a list.
  284.  */
  285. void CGPSDemoContainer::AddListBoxItemL(
  286.         CEikTextListBox* aListBox,
  287.         const TDesC& aString )
  288.     {
  289.     CTextListBoxModel* model = aListBox->Model();
  290.     CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
  291.     itemArray->AppendL( aString );
  292.     aListBox->HandleItemAdditionL();
  293.     }
  294.  
  295. // ]]] end generated function
  296.  
  297. // [[[ begin generated function: do not modify
  298. /**
  299.  * Get the array of selected item indices, with respect to the list model.
  300.  * The array is sorted in ascending order.
  301.  * The array should be destroyed with two calls to CleanupStack::PopAndDestroy(),
  302.  * the first with no argument (referring to the internal resource) and the
  303.  * second with the array pointer.
  304.  * @return newly allocated array, which is left on the cleanup stack;
  305.  *  or NULL for empty list.
  306.  */
  307. RArray< TInt >* CGPSDemoContainer::GetSelectedListBoxItemsLC( CEikTextListBox* aListBox )
  308.     {
  309.     CAknFilteredTextListBoxModel* model =
  310.         static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() );
  311.     if ( model->NumberOfItems() == 0 )
  312.         return NULL;
  313.        
  314.     // get currently selected indices
  315.     const CListBoxView::CSelectionIndexArray* selectionIndexes =
  316.         aListBox->SelectionIndexes();
  317.     TInt selectedIndexesCount = selectionIndexes->Count();
  318.     if ( selectedIndexesCount == 0 )
  319.         return NULL;
  320.        
  321.     // copy the indices and sort numerically
  322.     RArray<TInt>* orderedSelectedIndices =
  323.         new (ELeave) RArray< TInt >( selectedIndexesCount );
  324.    
  325.     // push the allocated array
  326.     CleanupStack::PushL( orderedSelectedIndices );
  327.    
  328.     // dispose the array resource
  329.     CleanupClosePushL( *orderedSelectedIndices );
  330.    
  331.     // see if the search field is enabled
  332.     CAknListBoxFilterItems* filter = model->Filter();
  333.     if ( filter != NULL )
  334.         {
  335.         // when filtering enabled, translate indices back to underlying model
  336.         for ( TInt idx = 0; idx < selectedIndexesCount; idx++ )
  337.             {
  338.             TInt filteredItem = ( *selectionIndexes ) [ idx ];
  339.             TInt actualItem = filter->FilteredItemIndex ( filteredItem );
  340.             orderedSelectedIndices->InsertInOrder( actualItem );
  341.             }
  342.         }
  343.     else
  344.         {
  345.         // the selection indices refer directly to the model
  346.         for ( TInt idx = 0; idx < selectedIndexesCount; idx++ )
  347.             orderedSelectedIndices->InsertInOrder( ( *selectionIndexes ) [ idx ] );
  348.         }  
  349.        
  350.     return orderedSelectedIndices;
  351.     }
  352.  
  353. // ]]] end generated function
  354.  
  355. // [[[ begin generated function: do not modify
  356. /**
  357.  * Delete the selected item or items from the list box.
  358.  */
  359. void CGPSDemoContainer::DeleteSelectedListBoxItemsL( CEikTextListBox* aListBox )
  360.     {
  361.     CAknFilteredTextListBoxModel* model =
  362.         static_cast< CAknFilteredTextListBoxModel *> ( aListBox->Model() );
  363.     if ( model->NumberOfItems() == 0 )
  364.         return;
  365.    
  366.     RArray< TInt >* orderedSelectedIndices = GetSelectedListBoxItemsLC( aListBox );    
  367.     if ( !orderedSelectedIndices )
  368.         return;
  369.        
  370.     // Delete selected items from bottom up so indices don't change on us
  371.     CDesCArray* itemArray = static_cast< CDesCArray* > ( model->ItemTextArray() );
  372.     TInt currentItem = 0;
  373.    
  374.     for ( TInt idx = orderedSelectedIndices->Count(); idx-- > 0; )
  375.         {
  376.         currentItem = ( *orderedSelectedIndices )[ idx ];
  377.         itemArray->Delete ( currentItem );
  378.         }
  379.    
  380.     // dispose the array resources
  381.     CleanupStack::PopAndDestroy();
  382.    
  383.     // dispose the array pointer
  384.     CleanupStack::PopAndDestroy( orderedSelectedIndices );
  385.    
  386.     // refresh listbox's cursor now that items are deleted
  387.     AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
  388.         aListBox, currentItem, ETrue );
  389.     }
  390.  
  391. // ]]] end generated function
  392.  
  393. // [[[ begin generated function: do not modify
  394. /**
  395.  *  Get the listbox.
  396.  */
  397. CAknSingleHeadingStyleListBox* CGPSDemoContainer::ListBox()
  398.     {
  399.     return iListBox;
  400.     }
  401.  
  402. // ]]] end generated function
  403.  
  404. // [[[ begin generated function: do not modify
  405. /**
  406.  *  Create a list box item with the given column values.
  407.  */
  408. void CGPSDemoContainer::CreateListBoxItemL( TDes& aBuffer,
  409.         const TDesC& aHeadingText,
  410.         const TDesC& aMainText )
  411.     {
  412.     _LIT ( KStringHeader, "%S\t%S" );
  413.    
  414.     aBuffer.Format( KStringHeader(), &aHeadingText, &aMainText );
  415.     }
  416.                
  417. // ]]] end generated function
  418.  
  419. // [[[ begin generated function: do not modify
  420. /**
  421.  *  Add an item to the list by reading the text items from the array resource
  422.  *  and setting a single image property (if available) from an index
  423.  *  in the list box's icon array.
  424.  *  @param aResourceId id of an ARRAY resource containing the textual
  425.  *  items in the columns
  426.  *  
  427.  */
  428. void CGPSDemoContainer::AddListBoxResourceArrayItemL( TInt aResourceId )
  429.     {
  430.     CDesCArray* array = iCoeEnv->ReadDesCArrayResourceL( aResourceId );
  431.     CleanupStack::PushL( array );
  432.     // This is intended to be large enough, but if you get
  433.     // a USER 11 panic, consider reducing string sizes.
  434.     TBuf<512> listString;
  435.     CreateListBoxItemL( listString, ( *array ) [ 0 ], ( *array ) [ 1 ] );
  436.     AddListBoxItemL( iListBox, listString );
  437.     CleanupStack::PopAndDestroy( array );
  438.     }
  439.                
  440. // ]]] end generated function
  441.  
  442. // [[[ begin generated function: do not modify
  443. /**
  444.  *  Set up the list's icon array.
  445.  */
  446. void CGPSDemoContainer::SetupListBoxIconsL()
  447.     {
  448.     CArrayPtr< CGulIcon >* icons = NULL;        
  449.    
  450.     if ( icons != NULL )
  451.         {
  452.         iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
  453.         }
  454.     }
  455.  
  456. // ]]] end generated function
  457.  
  458. // [[[ begin generated function: do not modify
  459. /**
  460.  *  Handle commands relating to markable lists.
  461.  */
  462. TBool CGPSDemoContainer::HandleMarkableListCommandL( TInt aCommand )
  463.     {
  464.     return EFalse;
  465.     }
  466.  
  467. // ]]] end generated function
  468.  
  469.  
  470. /*void CGPSDemoContainer::StartTrackingLC() {
  471.     this.iModuleId = TUid::Uid(270526858); // Internal GPS
  472.    
  473.     User::LeaveIfError(this.iServer.Connect());
  474.     CleanupClosePushL(this.iPosServer);
  475.    
  476.     User::LeaveIfError(this.iPositioner.Open(this.iPosServer, this.iModuleId));
  477.     CleanupClosePushL(this.iPositioner);
  478.    
  479.     this.iUpdateOptions.SetUpdateInterval(1000000);
  480.     this.iUpdateOptions.SetUpdateTimeOut(15000000);
  481.     this.iUpdateOptions.SetMaxUpdateAge(1000000);
  482.     this.iUpdateOptions.SetAcceptPartialUpdates(ETrue);
  483.     this.iPositioner.SetUpdateOptions(this.iUpdateOptions);
  484.    
  485.     _LIT(KRequestor, "S60 GPS Demo");
  486.     User::LeaveIfError(
  487.             this.iPositioner.SetRequestor(CRequestor::ERequestorService,
  488.             CRequestor::EFormatApplication, KRequestor)
  489.     );
  490.    
  491.     User::LeaveIfError(this.iPositioner.NotifyPositionUpdate(this.iPosInfo, this.iStatus));
  492.    
  493.    
  494.    
  495.    
  496. }*/
  497.  
  498. //void CGPSDemoContainer::StopTracking/*L*//* L - ? */() {
  499. //  CleanupStack::PopAndDestroy(2);
  500. //}
  501.  
  502.  
  503. void CGPSDemoContainer::PositionInfoUpdatedL(TPositionInfoBase& aPosInfo,
  504.     const TDesC& aModulename)
  505.     {
  506.     //TInt count = iItemArray->Count();
  507.     //iItemArray->Reset();
  508.  
  509.     // Set the module name
  510.     //iModuleName = aModulename;
  511.     //AddItemInListL(KTxtModuleName, iModuleName);
  512.    
  513.     // Check the type of the updated position information
  514.     // and process that information.
  515.    
  516.     // Check if position information class type is TPositionSatelliteInfo
  517.     if (aPosInfo.PositionClassType() & EPositionSatelliteInfoClass)
  518.         {
  519.         // Cast the TPositionInfoBase object to TPositionSatelliteInfo
  520.         //TPositionSatelliteInfo* posInfo = static_cast<TPositionSatelliteInfo*>(&aPosInfo);
  521.  
  522.         // Process the satellite information
  523.         //ProcessSatelliteInfoL( *posInfo );
  524.  
  525.         }
  526.     // Check if position information class type is TPositionInfo
  527.     else if (aPosInfo.PositionClassType() & EPositionInfoClass)
  528.         {
  529.  
  530.         //Cast the TPositionInfoBase object to TPositionInfo
  531.         TPositionInfo* posInfo = static_cast<TPositionInfo*>(&aPosInfo);
  532.         TPosition* pos;
  533.         posInfo->GetPosition(*pos);
  534.  
  535.         //Process the position information
  536.         //ProcessPositionInfoL( *posInfo );
  537.        
  538.        
  539.         CDesCArray* iItemArray;
  540.         MDesCArray* itemList = iListBox->Model()->ItemTextArray();
  541.         iItemArray = (CDesCArray*) itemList;
  542.        
  543.         iItemArray->Reset();
  544.        
  545.         TBuf<100> buff;
  546.         buff.Zero();
  547.         buff.Format(KFormatListItemText, KLatText, pos->Latitude());
  548.         iItemArray->AppendL(buff);
  549.        
  550.         buff.Zero();
  551.         buff.Format(KFormatListItemText, KLonText, pos->Longitude());
  552.         iItemArray->AppendL(buff);
  553.        
  554.         buff.Zero();
  555.         buff.Format(KFormatListItemText, KAltText, pos->Altitude());
  556.         iItemArray->AppendL(buff);
  557.        
  558.  
  559.         }
  560.     /*if (count < iItemArray->Count())
  561.         {
  562.         //iListBox->HandleItemAdditionL();
  563.         }
  564.     else if (count > iItemArray->Count())
  565.         {
  566.         //iListBox->HandleItemRemovalL();
  567.         }
  568.     else
  569.         {
  570.         //iListBox->DrawNow();
  571.         }*/
  572.     }
  573.  
  574. void CGPSDemoContainer::ShowErrorL(const TDesC& aErrorString) {
  575.    
  576. }
  577.  
  578. void CGPSDemoContainer::ShowMessageL(const TDesC& aMessage) {
  579.    
  580. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement