📄 searchresults.cpp
字号:
/*
========================================================================
Name : SearchResults.cpp
Author :
Copyright : Copyright 2006 Nokia Corporation
Description :
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <barsread.h>
#include <stringloader.h>
#include <aknlists.h>
#include <eikenv.h>
#include <akniconarray.h>
#include <eikclbd.h>
#include <aknviewappui.h>
#include <eikappui.h>
#include <Yahoo.rsg>
#include <Yahoo_mbm.mbg>
// ]]] end generated region [Generated System Includes]
// [[[ begin generated region: do not modify [Generated User Includes]
#include "SearchResults.h"
#include "Yahoo.hrh"
#include "SearchResults.hrh"
// ]]] end generated region [Generated User Includes]
#include "SearchResultsView.h"
// [[[ begin generated region: do not modify [Generated Constants]
_LIT( KYahoo_mbmFile, "\\resource\\apps\\Yahoo_mbm.mbm" );
// ]]] end generated region [Generated Constants]
/**
* First phase of Symbian two-phase construction. Should not
* contain any code that could leave.
*/
CSearchResults::CSearchResults()
{
// [[[ begin generated region: do not modify [Generated Contents]
iListBox = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* Destroy child controls.
*/
CSearchResults::~CSearchResults()
{
// [[[ begin generated region: do not modify [Generated Contents]
delete iListBox;
iListBoxEventDispatch.Close();
// ]]] end generated region [Generated Contents]
}
/**
* Construct the control (first phase).
* Creates an instance and initializes it.
* Instance is not left on cleanup stack.
* @param aRect bounding rectangle
* @param aParent owning parent, or NULL
* @param aCommandObserver command observer
* @return initialized instance of CSearchResults
*/
CSearchResults* CSearchResults::NewL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
CSearchResults* self = CSearchResults::NewLC( aRect, aParent, aCommandObserver );
CleanupStack::Pop( self );
return self;
}
/**
* Construct the control (first phase).
* Creates an instance and initializes it.
* Instance is left on cleanup stack.
* @param aRect The rectangle for this window
* @param aParent owning parent, or NULL
* @param aCommandObserver command observer
* @return new instance of CSearchResults
*/
CSearchResults* CSearchResults::NewLC(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
CSearchResults* self = new (ELeave) CSearchResults();
CleanupStack::PushL( self );
self->ConstructL( aRect, aParent, aCommandObserver );
return self;
}
/**
* Construct the control (second phase).
* Creates a window to contain the controls and activates it.
* @param aRect bounding rectangle
* @param aCommandObserver command observer
* @param aParent owning parent, or NULL
*/
void CSearchResults::ConstructL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
if ( !aParent )
{
CreateWindowL();
}
else
{
SetContainerWindowL( *aParent );
}
iFocusControl = NULL;
iCommandObserver = aCommandObserver;
InitializeControlsL();
HBufC *prompt = StringLoader::LoadLC(R_SEARCH_LIST_EMPTY_PROMPT);
iListBox->View()->SetListEmptyTextL(*prompt);
CleanupStack::PopAndDestroy(prompt);
SetRect( aRect );
ActivateL();
// [[[ begin generated region: do not modify [Post-ActivateL initializations]
// ]]] end generated region [Post-ActivateL initializations]
}
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CSearchResults::CountComponentControls() const
{
return (int) ELastControl;
}
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CSearchResults::ComponentControl( TInt aIndex ) const
{
// [[[ begin generated region: do not modify [Generated Contents]
switch ( aIndex )
{
case EListBox:
return iListBox;
}
// ]]] end generated region [Generated Contents]
// handle any user controls here...
return NULL;
}
/**
* Handle resizing of the container. This implementation will lay out
* full-sized controls like list boxes for any screen size, and will layout
* labels, editors, etc. to the size they were given in the UI designer.
* This code will need to be modified to adjust arbitrary controls to
* any screen size.
*/
void CSearchResults::SizeChanged()
{
CCoeControl::SizeChanged();
LayoutControls();
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
}
// [[[ begin generated function: do not modify
/**
* Layout components as specified in the UI Designer
*/
void CSearchResults::LayoutControls()
{
iListBox->SetExtent( TPoint( 0, 0 ), iListBox->MinimumSize() );
}
// ]]] end generated function
/**
* Handle key events.
*/
TKeyResponse CSearchResults::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
{
// [[[ begin generated region: do not modify [Generated Contents]
if ( ( aKeyEvent.iCode == EKeyLeftArrow ) || ( aKeyEvent.iCode == EKeyRightArrow ) )
{
// Listbox takes all events even if it doesn't use them
return EKeyWasNotConsumed;
}
// ]]] end generated region [Generated Contents]
if ( iFocusControl &&
iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
return EKeyWasConsumed;
return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
}
// [[[ begin generated function: do not modify
/**
* Initialize each control upon creation.
*/
void CSearchResults::InitializeControlsL()
{
iListBox = new (ELeave) CAknDoubleStyleListBox;
iListBox->SetContainerWindowL( *this );
{
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_SEARCH_RESULTS_LIST_BOX );
iListBox->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // reader internal state
}
// the listbox owns the items in the list and will free them
iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
// setup the icon array so graphics-style boxes work
SetupListBoxIconsL();
iListBox->SetListBoxObserver( this );
AddListBoxEventHandlerL( iListBox, EEventEnterKeyPressed, &CSearchResults::HandleListBoxEnterKeyPressedL );
// add list items
iListBox->SetFocus( ETrue );
iFocusControl = iListBox;
}
// ]]] end generated function
/**
* Handle global resource changes, such as scalable UI or skin events (override)
*/
void CSearchResults::HandleResourceChange( TInt aType )
{
CCoeControl::HandleResourceChange( aType );
SetRect( iAvkonViewAppUi->View( TUid::Uid( ESearchResultsViewId ) )->ClientRect() );
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
}
/**
* Draw container contents.
*/
void CSearchResults::Draw( const TRect& aRect ) const
{
// [[[ begin generated region: do not modify [Generated Contents]
CWindowGc& gc = SystemGc();
gc.Clear( aRect );
// ]]] end generated region [Generated Contents]
}
/**
* Add a list box item to a list.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -