S60 3rd Edition SDK for Symbian OS
Example Applications Guide

IMOpenAPIExampleGrid.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : IMOpenAPIExampleGrid.cpp
00004 *  Part of     : IMOpenAPIExample
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2005-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include "IMOpenAPIExampleGrid.h"
00018 #include <akniconarray.h> 
00019 #include <aknlists.h> 
00020 #include <barsread.h> 
00021 #include <stringloader.h> 
00022 #include <e32des16.h> 
00023 
00024 // CONSTANTS
00025 const TInt KNumberOfIcons(7);
00026 
00027 // ----------------------------------------------------------
00028 // CIMOpenAPIExampleGrid::ConstructL(TInt aGridResource, const TDesC& aImageFile)
00029 // Construct a grid with an image file and grid resource
00030 // ----------------------------------------------------------
00031 //
00032 void CIMOpenAPIExampleGrid::ConstructL(TInt aGridResource, const TDesC& aImageFile)
00033         {
00034     // Construct the grid from resource
00035         TResourceReader reader;
00036         CEikonEnv::Static()->CreateResourceReaderLC(reader, aGridResource);
00037         ConstructFromResourceL(reader);
00038         CleanupStack::PopAndDestroy(); // reader
00039 
00040         // Set up the icons
00041         SetupGridIconsL (aImageFile);
00042 
00043         // set up text and icons in array
00044     iArray = static_cast<CDesCArray*>(this->Model()->ItemTextArray());
00045     ResetGrid();
00046 
00047         // Draw the grid
00048         SizeChanged();
00049     
00050         }
00051 
00052 // ----------------------------------------------------------
00053 // CIMOpenAPIExampleGrid::~CIMOpenAPIExampleGrid()
00054 // Destructor
00055 // ----------------------------------------------------------
00056 //
00057 CIMOpenAPIExampleGrid::~CIMOpenAPIExampleGrid()
00058     {
00059     }
00060 
00061 // ----------------------------------------------------------
00062 // CIMOpenAPIExampleGrid::SetupGridIconsL(const TDesC& aImageFile)
00063 // setup grid icons reading from an mbm file
00064 // ----------------------------------------------------------
00065 //
00066 void CIMOpenAPIExampleGrid::SetupGridIconsL(const TDesC& aImageFile)
00067         {
00068 
00069         // Create an array of icons, reading them from the file
00070         CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(KNumberOfIcons);
00071         CleanupStack::PushL(icons);
00072 
00073         icons->AppendL( iEikonEnv->CreateIconL( aImageFile, 0, 3 ) );
00074         icons->AppendL( iEikonEnv->CreateIconL( aImageFile, 1, 3 ) );
00075         icons->AppendL( iEikonEnv->CreateIconL( aImageFile, 2, 3 ) );
00076 
00077         
00078         
00079         CleanupStack::Pop(icons);
00080         // passing ownership of icons
00081         ItemDrawer()->FormattedCellData()->SetIconArray(icons);
00082         
00083         }
00084 
00085 // ----------------------------------------------------------
00086 // CIMOpenAPIExampleGrid::SetupGrid()
00087 // setup the grid layout
00088 // ----------------------------------------------------------
00089 //
00090 void CIMOpenAPIExampleGrid::SetupGrid()
00091         {
00092         // Setup text foreground and background colours to default
00093         AknListBoxLayouts::SetupStandardGrid(*this);
00094 
00095 
00096         // Get local copies of data we will need        
00097         CFormattedCellListBoxItemDrawer* itemDrawer = this->ItemDrawer();
00098         TInt cellWidth = ColumnWidth();
00099         TInt cellHeight = ItemHeight();
00100 
00101                 
00102         // Set up graphics subcells
00103         AknListBoxLayouts::SetupFormGfxCell(*this,  //the grid
00104                                                                                 itemDrawer, // the grid's drawer
00105                                                                                 0, // index of the graphic within item strings
00106                                                                                 1, // left position
00107                                                                                 1, // top position
00108                                                                                 0, // right - unused
00109                                                                                 0, // bottom - unused
00110                                                                                 cellWidth-4, // width of graphic
00111                                                                                 cellHeight-4, // height of graphic
00112                                                                                 TPoint (0, 0), // start position
00113                                                                                 TPoint (cellWidth , cellHeight)); // end position
00114     CEikScrollBarFrame* frame = ScrollBarFrame();
00115 
00116         if (frame)
00117                 {
00118                 frame->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff);
00119                 }
00120 
00121         }
00122 
00123 // ----------------------------------------------------------
00124 // CIMOpenAPIExampleGrid::SizeChanged()
00125 // Called by framework when the view size is changed and by ConstructL to intialise the grid
00126 // ----------------------------------------------------------
00127 //
00128 void CIMOpenAPIExampleGrid::SizeChanged()
00129         {
00130     CAknGrid::SizeChanged();
00131         SetupGrid();
00132         }
00133 
00134 // ----------------------------------------------------------
00135 // CIMOpenAPIExampleGrid::SetCellSign(TGameSign aCellValue, TInt aCellIndex)
00136 // sets up a single cell sign
00137 // ----------------------------------------------------------
00138 //
00139 void CIMOpenAPIExampleGrid::SetCellSign(TGameSign aCellValue, TInt aCellIndex)
00140         {
00141     _LIT(KFormatString, "%d");
00142         TBuf<1> cellValueString;
00143         cellValueString.Format(KFormatString, aCellValue);
00144 
00145     // return if index is out of bound
00146     if ( (aCellIndex>8) || (aCellIndex<0) )
00147         return;
00148     iArray->Delete(aCellIndex);
00149         iArray->InsertL(aCellIndex,cellValueString);
00150     HandleItemAdditionL();
00151         }
00152 
00153 // ----------------------------------------------------------
00154 // CIMOpenAPIExampleGrid::ResetGrid()
00155 // resets all cell signs to empty
00156 // ----------------------------------------------------------
00157 //
00158 void CIMOpenAPIExampleGrid::ResetGrid()
00159         {
00160     _LIT(KFormatString, "%d");
00161         TBuf<2> cellValueString;
00162 
00163     for (TInt i=0; i<9 ; i++)
00164         {
00165         cellValueString.Format(KFormatString, EEmptySign);
00166         iArray->Delete(i);
00167             iArray->InsertL(i,cellValueString);
00168         }
00169     HandleItemAdditionL();
00170         }
00171 
00172 // End of File  
00173 

© Nokia 2006

Back to top