DirectPrint/DirectPrintApp/ui/src/directprintlistbox.cpp
changeset 19 2275db202402
parent 11 613a5ff70823
equal deleted inserted replaced
2:acc370d7f2f6 19:2275db202402
       
     1 /*
       
     2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <barsread.h>
       
    19 #include <DirectPrintApp.rsg>
       
    20 
       
    21 #include "DirectPrintListBox.h"
       
    22 
       
    23 CDirectPrintListBox::CDirectPrintListBox()
       
    24 	{
       
    25 	iListObserver = NULL;
       
    26 	}
       
    27 
       
    28 CDirectPrintListBox::~CDirectPrintListBox()
       
    29 	{
       
    30 	delete iListBox;
       
    31 	}
       
    32 
       
    33 CDirectPrintListBox* CDirectPrintListBox::NewL(const TRect& aRect, CDesCArray* aItemArray)
       
    34 	{
       
    35 	CDirectPrintListBox* self = CDirectPrintListBox::NewLC(aRect, aItemArray);
       
    36 	CleanupStack::Pop(self);
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 CDirectPrintListBox* CDirectPrintListBox::NewLC(const TRect& aRect, CDesCArray* aItemArray)
       
    41 	{
       
    42 	CDirectPrintListBox* self = new(ELeave) CDirectPrintListBox();
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL(aRect, aItemArray);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 void CDirectPrintListBox::ConstructL(const TRect& aRect, CDesCArray* aItemArray)
       
    49 	{
       
    50 	CreateWindowL();
       
    51 	SetRect(aRect);
       
    52 
       
    53 	InitializeControlsL();
       
    54 	iListBox->SetRect(Rect());
       
    55 	iListBox->Model()->SetItemTextArray(aItemArray);
       
    56 	iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
    57 	iListBox->HandleItemAdditionL();
       
    58 
       
    59 	ActivateL();
       
    60 	}
       
    61 
       
    62 TInt CDirectPrintListBox::CountComponentControls() const
       
    63 	{
       
    64 	return (int)ELastControl;
       
    65 	}
       
    66 
       
    67 CCoeControl* CDirectPrintListBox::ComponentControl(TInt aIndex) const
       
    68 	{
       
    69 	CCoeControl* ctrl = NULL;
       
    70 
       
    71 	switch ( aIndex )
       
    72 		{
       
    73 		case EListBox:
       
    74 			{
       
    75 			ctrl = iListBox;
       
    76 			}
       
    77 			break;
       
    78 		default:
       
    79 			break;
       
    80 		}
       
    81 
       
    82 	return ctrl;
       
    83 	}
       
    84 
       
    85 void CDirectPrintListBox::InitializeControlsL()
       
    86 	{
       
    87 	TBuf<50> buf;
       
    88 	//_LIT ( KStringHeader, "%S\t%S" );
       
    89 	iListBox = new(ELeave) CAknDoubleStyleListBox;
       
    90 	iListBox->SetContainerWindowL(*this);
       
    91 		{
       
    92 		TResourceReader reader;
       
    93 		iEikonEnv->CreateResourceReaderLC(reader, R_DIRECTPRINT_MAINVIEW_LISTBOX);
       
    94 		iListBox->ConstructFromResourceL(reader);
       
    95 		CleanupStack::PopAndDestroy(); // reader internal state
       
    96 		}
       
    97 
       
    98 	iListBox->CreateScrollBarFrameL(ETrue);
       
    99 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EOn);
       
   100 	iListBox->ScrollBarFrame()->DrawScrollBarsNow();
       
   101 	iListBox->SetFocus( ETrue );
       
   102 	iListBox->SetListBoxObserver(this);
       
   103     iListBox->View()->SetListEmptyTextL( _L("No Data") );
       
   104 	}
       
   105 
       
   106 void CDirectPrintListBox::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aEventType)
       
   107 	{
       
   108 	switch (aEventType)
       
   109 		{
       
   110 		case EEventItemClicked:
       
   111 		case EEventEnterKeyPressed:
       
   112 			{
       
   113 			TInt index = iListBox->CurrentItemIndex();
       
   114 			if (iListObserver)
       
   115 				{
       
   116 				iListObserver->HandleListIndexL(index);
       
   117 				}
       
   118 			}
       
   119 			break;
       
   120 		default:
       
   121 			break;
       
   122 		}
       
   123 	}
       
   124 
       
   125 void CDirectPrintListBox::SetItemL(CDesCArray* aItemArray)
       
   126 	{
       
   127 	iListBox->Model()->SetItemTextArray(aItemArray);
       
   128 	iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   129 	iListBox->HandleItemAdditionL();
       
   130 	}
       
   131 
       
   132 void CDirectPrintListBox::SetListObserver(MDirectPrintListObserver* aObserver)
       
   133 	{
       
   134 	iListObserver = aObserver;
       
   135 	}
       
   136 
       
   137 TInt CDirectPrintListBox::DeleteCurrentItemL()
       
   138 	{
       
   139 	TInt index = -1;
       
   140 	if (iListBox->Model()->NumberOfItems() > 0)
       
   141 		{
       
   142 		index = iListBox->CurrentItemIndex();
       
   143 		CDesCArray* itemArray = static_cast<CDesC16ArrayFlat*>(iListBox->Model()->ItemTextArray());
       
   144 		itemArray->Delete(index);
       
   145 		}
       
   146 	iListBox->HandleItemAdditionL();
       
   147 
       
   148 	return index;
       
   149 	}
       
   150 
       
   151 void CDirectPrintListBox::RedrawListL()
       
   152 	{
       
   153 	iListBox->HandleItemAdditionL();
       
   154 	iListBox->DrawNow();
       
   155 	DrawNow();
       
   156 	}
       
   157 
       
   158 TInt CDirectPrintListBox::CurrentIndex()
       
   159 	{
       
   160 	return iListBox->CurrentItemIndex();
       
   161 	}
       
   162 
       
   163 void CDirectPrintListBox::SetFocusL(TInt aIndex)
       
   164 	{
       
   165 	iListBox->SetCurrentItemIndexAndDraw(aIndex);
       
   166 	}
       
   167