landmarksui/uicontrols/src/CLmkIconSelectorPopup.cpp
branchRCL_3
changeset 18 870918037e16
parent 0 522cd55cc3d7
equal deleted inserted replaced
17:1fc85118c3ae 18:870918037e16
       
     1 /*
       
     2 * Copyright (c) 2002 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:    LandmarksUi Content File -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include <AknPopupHeadingPane.h>
       
    28 #include "CLmkIconSelectorPopup.h"
       
    29 #include "LmkConsts.h"
       
    30 #include "CLmkUiUtils.h"
       
    31 #include <akniconarray.h>
       
    32 #include <gulicon.h>
       
    33 #include <AknLists.h>
       
    34 #include <Lmkui.rsg>
       
    35 #include <aknselectionlist.h>
       
    36 #include <AknIconUtils.h>
       
    37 #include <AknUtils.h>
       
    38 #include <AknLayoutScalable_Avkon.cdl.h>
       
    39 #include <LayoutMetaData.cdl.h>
       
    40 
       
    41 // CONSTANTS
       
    42 /// Unnamed namespace for local definitions
       
    43 namespace {
       
    44     _LIT( KFormat, "%d\t" );
       
    45 //    const TInt KColorIndex( 215 );
       
    46     const TInt KNumOfColumns( 9 );
       
    47     const TInt KNumOfRows( 8 );
       
    48     const TInt KWidth( 18 );
       
    49     const TInt KHeight( 20 );
       
    50     const TInt KTextLength( 50 );
       
    51     const TInt KNumOfIcons( 16 );
       
    52 
       
    53 }  // namespace
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CLmkIconSelectorPopup::CLmkIconSelectorPopup
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CLmkIconSelectorPopup::CLmkIconSelectorPopup() :
       
    63     iNumOfColumns( KNumOfColumns ),
       
    64     iNumOfRows( KNumOfRows ),
       
    65     iSizeOfItems( TSize( KWidth, KHeight ) )
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CLmkIconSelectorPopup::NewL
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CLmkIconSelectorPopup* CLmkIconSelectorPopup::NewL( CAknGrid& aGrid )
       
    75     {
       
    76     CLmkIconSelectorPopup* self =
       
    77         new( ELeave ) CLmkIconSelectorPopup( );
       
    78 
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL( aGrid );
       
    81     CleanupStack::Pop();
       
    82 
       
    83     return self;
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------
       
    87 // CLmkIconSelectorPopup::ConstructL
       
    88 // ----------------------------------------------------
       
    89 //
       
    90 void CLmkIconSelectorPopup::ConstructL( CAknGrid& aGrid )
       
    91 	{
       
    92 	iEnv = CEikonEnv::Static();
       
    93     iGrid = &aGrid;
       
    94 	}
       
    95 
       
    96 // ----------------------------------------------------
       
    97 // CLmkIconSelectorPopup::~CLmkIconSelectorPopup
       
    98 // ----------------------------------------------------
       
    99 //
       
   100 CLmkIconSelectorPopup::~CLmkIconSelectorPopup()
       
   101     {
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------
       
   105 // CLmkIconSelectorPopup::ExecuteLD
       
   106 // ----------------------------------------------------
       
   107 //
       
   108 TBool CLmkIconSelectorPopup::ExecuteLD ()
       
   109 	{
       
   110     CAknPopupList* popupList= CAknPopupList::NewL(
       
   111         iGrid, R_AVKON_SOFTKEYS_SELECT_CANCEL, AknPopupLayouts::EMenuGraphicWindow );
       
   112     CleanupStack::PushL( popupList );
       
   113 
       
   114 	iGrid->ConstructL( popupList, CEikListBox::EPopout);
       
   115 
       
   116 	TRect clientRect;
       
   117 	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, clientRect);
       
   118 
       
   119 	TAknLayoutRect main_pane;
       
   120 	main_pane.LayoutRect(
       
   121 		clientRect, AknLayoutScalable_Avkon::main_pane(2));
       
   122 
       
   123 	TAknLayoutRect popup_grid_graphic_window;
       
   124 	popup_grid_graphic_window.LayoutRect(
       
   125 		clientRect, AknLayoutScalable_Avkon::popup_grid_graphic_window(0));
       
   126 
       
   127 	popupList->SetRect(main_pane.Rect());
       
   128 
       
   129 	// Calculate the size relatively
       
   130 	TRect relativeDialog(TPoint(0,0),popup_grid_graphic_window.Rect().Size());
       
   131 
       
   132 	// Get the layout of the actual character grid with scrollbar
       
   133     TAknLayoutRect listscroll_popup_graphic_pane;
       
   134 
       
   135     listscroll_popup_graphic_pane.LayoutRect(relativeDialog,
       
   136     	AknLayoutScalable_Avkon::listscroll_popup_graphic_pane());
       
   137 
       
   138 	TAknLayoutRect grid_graphic_popup_pane;
       
   139 
       
   140 	grid_graphic_popup_pane.LayoutRect(
       
   141 		listscroll_popup_graphic_pane.Rect(),
       
   142 		AknLayoutScalable_Avkon::grid_graphic_popup_pane(1));
       
   143 
       
   144 	TRect popupGridRect = grid_graphic_popup_pane.Rect();
       
   145 
       
   146     iGrid->SetRect(popupGridRect);
       
   147 
       
   148     iSizeOfItems.iWidth = popupGridRect.Width() / iNumOfColumns;
       
   149     iSizeOfItems.iHeight = popupGridRect.Height() / iNumOfRows;
       
   150 
       
   151 	// adjust the size of cells to the number of columns.
       
   152 	iGrid->SetLayoutL( EFalse, ETrue, ETrue, iNumOfColumns,
       
   153                        iNumOfRows, iSizeOfItems );
       
   154 
       
   155     iGrid->SetPrimaryScrollingType(
       
   156                 CAknGridView::EScrollIncrementLineAndLoops );
       
   157     iGrid->SetSecondaryScrollingType(
       
   158                 CAknGridView::EScrollIncrementLineAndLoops );
       
   159 
       
   160 	LoadGraphicsL();
       
   161     // create data
       
   162     AddDataL( KNumOfIcons );
       
   163 
       
   164     iGrid->CreateScrollBarFrameL(EFalse);
       
   165     iGrid->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   166                                 CEikScrollBarFrame::EOff,
       
   167                                 CEikScrollBarFrame::EOff);
       
   168 
       
   169 
       
   170 	// add title
       
   171     HBufC* title = iEnv->AllocReadResourceL( R_LMK_ICON_SELECTOR_TITLE );
       
   172     CleanupStack::PushL( title );
       
   173     popupList->SetTitleL( *title );
       
   174     CleanupStack::PopAndDestroy( title ); //title
       
   175     title = NULL;
       
   176 
       
   177     CleanupStack::Pop(); //popupList
       
   178 	TInt popupOk = popupList->ExecuteLD();
       
   179     delete this;
       
   180     return popupOk;
       
   181 	}
       
   182 
       
   183 // ----------------------------------------------------
       
   184 // CLmkIconSelectorPopup::LoadGraphicsL
       
   185 // ----------------------------------------------------
       
   186 //
       
   187 void CLmkIconSelectorPopup::LoadGraphicsL()
       
   188     {
       
   189     TFileName iconFile( CLmkUiUtils::LmkUiIconFileL() );
       
   190 
       
   191     CArrayPtr< CGulIcon >* icons = new( ELeave ) CAknIconArray(KNumOfIcons);
       
   192     CleanupStack::PushL( icons );
       
   193 
       
   194     // Create icon bitmap and mask.
       
   195     for ( TInt i(0); i < ( KNumOfIcons*2 ); i++ )
       
   196         {
       
   197 
       
   198 /*******************************************************************/
       
   199 			CFbsBitmap* bitmap = NULL;
       
   200 			CFbsBitmap* bitmapMask = NULL;
       
   201 
       
   202 			AknIconUtils::CreateIconLC(bitmap, bitmapMask, iconFile,
       
   203                              EMbmLmkuiQgn_prop_lm_transport + i, EMbmLmkuiQgn_prop_lm_transport + i + 1);
       
   204 			i++;
       
   205 			AknIconUtils::SetSize(bitmap, iSizeOfItems);  	//fix
       
   206 			AknIconUtils::SetSize(bitmapMask, iSizeOfItems); //fix
       
   207 			CGulIcon* icon = CGulIcon::NewL( bitmap, bitmapMask );
       
   208 	        CleanupStack::PushL( icon );
       
   209 		    icons->AppendL( icon );
       
   210 			CleanupStack::Pop(3); // icon, mask, bitmap
       
   211 /*******************************************************************/
       
   212         }
       
   213 
       
   214     // Set icon array.
       
   215     iGrid->ItemDrawer()->FormattedCellData()->SetIconArrayL( icons );
       
   216     CleanupStack::Pop(); // icons array
       
   217     }
       
   218 
       
   219 // ----------------------------------------------------
       
   220 // CLmkIconSelectorPopup::AddDataL
       
   221 // ----------------------------------------------------
       
   222 //
       
   223 void CLmkIconSelectorPopup::AddDataL( TInt aNum )
       
   224     {
       
   225     MDesCArray* array = iGrid->Model()->ItemTextArray();
       
   226     CDesCArray* cArray = ( CDesCArray* )array;
       
   227 
       
   228     // Makes text which is added to.
       
   229     TBuf< KTextLength > number;
       
   230     TBuf< KTextLength > format( KFormat );
       
   231 
       
   232     // The number of Grids.
       
   233     TInt numberOfData = iGrid->GridModel()->NumberOfData() ;
       
   234 
       
   235     // Add the data to the last
       
   236     for ( TInt i = numberOfData; i < aNum + numberOfData; i++ )
       
   237         {
       
   238         number.Format( format, i );
       
   239         cArray->AppendL( number );
       
   240         }
       
   241 
       
   242     // Inform list box that data added
       
   243     iGrid->HandleItemAdditionL();
       
   244 
       
   245     // If item size changes, need to alter the item style
       
   246     ApplySelGridGraphicStyleL();
       
   247 
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------
       
   251 // CLmkIconSelectorPopup::ApplySelGridGraphicStyleL
       
   252 // ----------------------------------------------------
       
   253 //
       
   254 void CLmkIconSelectorPopup::ApplySelGridGraphicStyleL()
       
   255     {
       
   256 
       
   257     if ( !iGrid )
       
   258         {
       
   259         return;
       
   260         }
       
   261 
       
   262     AknListBoxLayouts::SetupStandardGrid( *iGrid );
       
   263 
       
   264     TInt grWidth( iGrid->ColumnWidth() );
       
   265     TInt grHeight( iGrid->ItemHeight() );
       
   266     // layout of the graphic
       
   267     AknListBoxLayouts::SetupGridFormGfxCell( *iGrid,
       
   268             iGrid->ItemDrawer(),
       
   269             0, 0, 0, 0, 0,
       
   270             grWidth,
       
   271             grHeight,
       
   272             TPoint( 0, 0 ),
       
   273             TPoint( grWidth, grHeight ) );
       
   274     }
       
   275 void CLmkIconSelectorPopup::HandleScreenSizeChange()
       
   276 	{
       
   277 	TRect clientRect;
       
   278 	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, clientRect);
       
   279 	TAknLayoutRect popup_grid_graphic_window;
       
   280 	popup_grid_graphic_window.LayoutRect(
       
   281 		clientRect, AknLayoutScalable_Avkon::popup_grid_graphic_window(0));
       
   282 
       
   283 	// Calculate the size relatively
       
   284 	TRect relativeDialog(TPoint(0,0),popup_grid_graphic_window.Rect().Size());
       
   285 
       
   286 	// Get the layout of the actual character grid with scrollbar
       
   287     TAknLayoutRect listscroll_popup_graphic_pane;
       
   288 
       
   289     listscroll_popup_graphic_pane.LayoutRect(relativeDialog,
       
   290     	AknLayoutScalable_Avkon::listscroll_popup_graphic_pane());
       
   291 
       
   292 	TAknLayoutRect grid_graphic_popup_pane;
       
   293 
       
   294 	grid_graphic_popup_pane.LayoutRect(
       
   295 		listscroll_popup_graphic_pane.Rect(),
       
   296 		AknLayoutScalable_Avkon::grid_graphic_popup_pane(1));
       
   297 
       
   298 	TRect popupGridRect = grid_graphic_popup_pane.Rect();
       
   299 
       
   300 	TSize sizeOfItems(popupGridRect.Width() / KNumOfColumns,
       
   301 					  popupGridRect.Height() / KNumOfRows);
       
   302 
       
   303 	// adjust the size of cells to the number of columns.
       
   304 	TRAP_IGNORE(iGrid->SetLayoutL( EFalse, ETrue, ETrue, KNumOfColumns,
       
   305                        KNumOfRows, sizeOfItems ));
       
   306 
       
   307     CArrayPtr< CGulIcon >* icons =
       
   308     	iGrid->ItemDrawer()->FormattedCellData()->IconArray();
       
   309 
       
   310     for ( TInt i(0); i < icons->Count(); i++ )
       
   311         {
       
   312         	CGulIcon *icon = icons->At(i);
       
   313 			CFbsBitmap* bitmap = icon->Bitmap();
       
   314 			CFbsBitmap* bitmapMask = icon->Mask();
       
   315 			AknIconUtils::SetSize(bitmap, sizeOfItems);  	//fix
       
   316 			AknIconUtils::SetSize(bitmapMask, sizeOfItems); //fix
       
   317         }
       
   318 	TRAP_IGNORE(ApplySelGridGraphicStyleL());
       
   319 	}
       
   320 //  End of File