⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendarapiexamplesearchcontainer.cpp

📁 塞班3D游戏
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CCalendarAPIexampleSearchContainer from CalendarAPIexampleSearchContainer.h
*  Part of  : CalendarAPIexample
*  Created  : 12/06/2006 by Forum Nokia
*  Version  : 2.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES
#include <aknlists.h> //CAknSingleStyleListBox
#include <barsread.h> //TResourceReader
#include <CalendarAPIexample.rsg>
#include "CalendarAPIexampleSearchContainer.h"
#include "CalendarAPIexample.pan"

// CONSTANTS
const TInt KPoint = 5;

// ================= MEMBER FUNCTIONS =======================

// constructor
CCalendarAPIexampleSearchContainer::CCalendarAPIexampleSearchContainer(CCalendarAPIexampleSearchView& aView)
	:	iSearchView(aView)
		{
		}
		
// destructor
CCalendarAPIexampleSearchContainer::~CCalendarAPIexampleSearchContainer()
	{
	delete iLabel;
	iLabel = NULL;
	delete iSearchListBox;
	iSearchListBox = NULL;
	}
	
// Two-phased constructor.	
CCalendarAPIexampleSearchContainer* CCalendarAPIexampleSearchContainer::NewL(const TRect& aRect,
																			CCalendarAPIexampleSearchView& aView)
	{
	CCalendarAPIexampleSearchContainer* self = new (ELeave) CCalendarAPIexampleSearchContainer(aView);
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	CleanupStack::Pop(self);
	return self;
	}

// Symbian OS default constructor can leave.	
void CCalendarAPIexampleSearchContainer::ConstructL(const TRect& aRect)
	{
	CreateWindowL();    
	
    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
    HBufC* text = iCoeEnv->AllocReadResourceLC(R_CALENDARAPIEXAMPLE_SEARCH_STRING);
    iLabel->SetTextL(*text);
    CleanupStack::PopAndDestroy(text);
	
	iSearchListBox = new (ELeave) CAknSingleStyleListBox;
	iSearchListBox->SetContainerWindowL(*this);	
	TResourceReader reader; 
	CEikonEnv::Static()->CreateResourceReaderLC(reader, R_CALENDARAPIEXAMPLE_SEARCH_LIST); 
	iSearchListBox->ConstructFromResourceL(reader); 
	CleanupStack::PopAndDestroy(); //reader
	iSearchListBox->SetListBoxObserver(this);
    // set scrolling functionality
	iSearchListBox->CreateScrollBarFrameL(ETrue);
	iSearchListBox->ScrollBarFrame()->SetScrollBarVisibilityL(	CEikScrollBarFrame::EOff,
                                								CEikScrollBarFrame::EAuto);
 
    SetRect(aRect);
    
	ActivateL();
	}

// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::SizeChanged()
// Responds to size changes to set the size and 
// position of the contents of this control. 
// ----------------------------------------------------
//		
void CCalendarAPIexampleSearchContainer::SizeChanged()
	{

	iLabel->SetExtent( TPoint(KPoint,KPoint), iLabel->MinimumSize() );
	iSearchListBox->SetExtent( TPoint(0,iLabel->MinimumSize().iHeight+KPoint),
	                           iSearchListBox->MinimumSize() );
	}

// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::CountComponentControls()
// Gets the number of controls contained in a compound 
// control. 
// ----------------------------------------------------
//			
TInt CCalendarAPIexampleSearchContainer::CountComponentControls() const
	{
	TInt count = 0;
	if (iSearchListBox)
		count++;
	if (iLabel)
		count++;
	return count;
	}
	
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::ComponentControl()
// Gets the specified component of a compound control.
// ----------------------------------------------------
//		
CCoeControl* CCalendarAPIexampleSearchContainer::ComponentControl(TInt aIndex)
                                                                         const
	{
	switch (aIndex)
		{
		case 0:
			return iLabel;
		case 1:
			return iSearchListBox;
		default:
			return NULL;
		}
	}
	
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::OfferKeyEventL()
// When a key event occurs, the control framework calls 
// this function for each control on the control stack, 
// until one of them can process the key event 
// (and returns EKeyWasConsumed).
// ----------------------------------------------------
//		
TKeyResponse CCalendarAPIexampleSearchContainer::OfferKeyEventL(
                                  const TKeyEvent& aKeyEvent,TEventCode aType)
	{
    if(aType != EEventKey)
        {
        return EKeyWasNotConsumed;
        }    
    else if(iSearchListBox)
        {
        return iSearchListBox->OfferKeyEventL( aKeyEvent, aType );
        }
    else
        {
        return EKeyWasNotConsumed;
        }
	}


// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::Draw()
// This function is used for window server-initiated 
// redrawing of controls, and for some 
// application-initiated drawing.
// ----------------------------------------------------
//				
void CCalendarAPIexampleSearchContainer::Draw(const TRect& aRect) const
    {
    
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbWhite );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    
    }
    
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::SearchType()
// Returns the selected search range (week, month,...)
// ----------------------------------------------------
//			
TSearchType CCalendarAPIexampleSearchContainer::SearchType() const
	{
	switch (iSearchListBox->CurrentItemIndex())
		{
		case 0:
			return EWeek;
		case 1:
			return EMonth;
		case 2:
			return ESixMonths;
		case 3:
			return EYear;
		default:
			Panic(EUnSupportedSearchType);
			break;
		}
	return EWeek;
	}    


// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::HandleListBoxEventL()
// Handles listbox events.
// ----------------------------------------------------
//	
void CCalendarAPIexampleSearchContainer::HandleListBoxEventL(	CEikListBox* /*aListBox*/, 
																TListBoxEvent aEventType)
	{
	if (aEventType == EEventEnterKeyPressed)
		{
		iSearchView.HandleCommandL(ECalendarAPIexampleCmdSearch);
		}
	}


// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -