📄 shoppinglistappui.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <AknQueryDialog.h>
#include <ShoppingList.rsg>
#include "ShoppingItem.h"
#include "ShoppingList.pan"
#include "ShoppingListAppUi.h"
#include "ShoppingListAppView.h"
#include "ShoppingList.hrh"
#include "ShoppingListDocument.h"
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CShoppingListAppUi::ConstructL()
// 2nd phase constructor.
// ---------------------------------------------------------
//
void CShoppingListAppUi::ConstructL()
{
BaseConstructL();
iAppView = CShoppingListAppView::NewL( ClientRect(), GetDocument() );
iAppView->SetMopParent( this );
AddToStackL( iAppView );
}
// ---------------------------------------------------------
// CShoppingListAppUi::CShoppingListAppUi()
// Constructor.
// ---------------------------------------------------------
//
CShoppingListAppUi::CShoppingListAppUi()
{
// No implementation required
}
// ---------------------------------------------------------
// CShoppingListAppUi::~CShoppingListAppUi()
// Constructor.
// ---------------------------------------------------------
//
CShoppingListAppUi::~CShoppingListAppUi()
{
if ( iAppView )
{
iEikonEnv->RemoveFromStack( iAppView );
delete iAppView;
iAppView = NULL;
}
}
// ---------------------------------------------------------
// CShoppingListAppUi::HandleCommandL()
// ---------------------------------------------------------
//
void CShoppingListAppUi::HandleCommandL( TInt aCommand )
{
TInt selectedItemIndex = 0;
CShoppingItem* item;
switch( aCommand )
{
case EEikCmdExit:
case EAknSoftkeyExit:
TRAPD( Err, SaveL() ); // Ignore any errors
Exit();
break;
case EShoppingListNewItem:
{
if( GetDocument()->ItemCount() > 0 )
{
selectedItemIndex = iAppView->CurrentItemIndex();
}
item = CShoppingItem::NewLC();
item->SetNameL( KNewitem().AllocL() );
GetDocument()->InsertItemL( item, selectedItemIndex );
CleanupStack::Pop( item );
HandleModelChangeL();
TBuf<KTextBufferLength> name;
CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL( name );
if ( dlg->ExecuteLD( R_DIALOG_TEXT_ITEM_NAME ) )
{
GetDocument()->Item( iAppView->CurrentItemIndex() )->
SetNameL( name.AllocL() );
}
HandleModelChangeL();
break;
}
case EShoppingListMarkUnmark:
if( GetDocument()->ItemCount() > 0 )
{
item = GetDocument()->Item( iAppView->CurrentItemIndex() );
item->SetFlags( item->Flags() ^ CShoppingItem::EMarked );
HandleModelChangeL();
}
break;
case EShoppingListRemove:
if( GetDocument()->ItemCount() > 0 )
{
selectedItemIndex = iAppView->CurrentItemIndex();
GetDocument()->RemoveItem( selectedItemIndex );
TInt count = GetDocument()->ItemCount();
if( count > 0 && iAppView->CurrentItemIndex() == count )
{
iAppView->SetCurrentItemIndex( iAppView->CurrentItemIndex() - 1 );
}
HandleModelChangeL();
}
break;
default:
Panic( EShoppingListUi );
break;
}
}
// ---------------------------------------------------------
// CShoppingListAppUi::GetDocument()
// ---------------------------------------------------------
//
CShoppingListDocument* CShoppingListAppUi::GetDocument()
{
return static_cast<CShoppingListDocument*>( Document() );
}
// ---------------------------------------------------------
// CShoppingListAppUi::HandleModelChangeL()
// ---------------------------------------------------------
//
void CShoppingListAppUi::HandleModelChangeL()
{
iAppView->UpdateL();
iAppView->DrawNow();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -