www.pudn.com > UIQ_Code1.rar > CommandsHandlerPage3.cpp
// CommandsHandlerPage3.cpp // // © Symbian Software Ltd 2005. All rights reserved. // #include "CommandsHandlerPage3.h" #include "CommandsView.h" #include "Commands.hrh" #include#include #include /** Indicate application's default bitmap file. */ _LIT(KIconBitmapFile, "*"); /** Creates and constructs the command handler for page 3. @param aCommandView Reference to the CCommandsView @return Pointer to a CCommandsHandlerPage3 object */ CCommandsHandlerPage3* CCommandsHandlerPage3::NewL(CCommandsView& aCommandsView, CQikCommandManager& aCommandManager) { CCommandsHandlerPage3* self = new(ELeave) CCommandsHandlerPage3(aCommandsView, aCommandManager); CleanupStack::PushL(self); self->ConstructL(); CleanupStack::Pop(self); return self; } /** Constructor for the model. Adds the references to the command manager and command view. @param aCommandsView Reference to the CCommandsView */ CCommandsHandlerPage3::CCommandsHandlerPage3(CCommandsView& aCommandsView, CQikCommandManager& aCommandManager) : iCommandManager(aCommandManager), iCommandsView(aCommandsView) { } /** 2nd stage construction of the model. Creates the command state monitor that initialized all states to 0. Changes the values for the state properties for applicationState1 and applicationState2. */ void CCommandsHandlerPage3::ConstructL() { } /** Destructor for the model. Deletes the command state monitor. */ CCommandsHandlerPage3::~CCommandsHandlerPage3() { } /** The purpose of page3 commands is to show how different command types interact with each other and the usage of command icons. For more information about the commands and there placement look into the resource file for the command, CommandsPenStyle.ra and CommandsSoftkeyStyle.ra @param aCommand The command to be executed */ void CCommandsHandlerPage3::HandleCommandL(CQikCommand& aCommand) { // Launch an infoprint with the command text iCommandsView.InfoprintCmdL(aCommand); switch(aCommand.Id()) { case ECommandsPage3YesVisibleCmd: case ECommandsPage3NoVisibleCmd: case ECommandsPage3DoneVisibleCmd: case ECommandsPage3ItemVisibleCmd: case ECommandsPage3PreferVisibleCmd: case ECommandsPage3DeleteVisibleCmd: { // Get the visibility state from the checkbox for the specific command const TBool checked = aCommand.Checked(); // Get command id for command to change visibility on const TInt commandIdToChangeInvisibility = aCommand.Id()-ECommandsPage3VisibleStart+ECommandsPage3TypeStart; // Set the command visibility state according to the state of the // checkbox iCommandManager.SetInvisible(iCommandsView, commandIdToChangeInvisibility, !checked); break; } case ECommandsPage3ShowYesIconCmd: case ECommandsPage3ShowNoIconCmd: case ECommandsPage3ShowDoneIconCmd: case ECommandsPage3ShowItemIconCmd: case ECommandsPage3ShowPreferIconCmd: case ECommandsPage3ShowDeleteIconCmd: { // Get the icon state from the checkbox for the specific command const TBool checked = aCommand.Checked(); // Get command id for command to add/remove icon on const TInt commandIdToSetIcon = aCommand.Id()-ECommandsPage3ShowIconStart+ECommandsPage3TypeStart; // Add or remove command icon according to the state of the checkbox SetIconL(commandIdToSetIcon, checked); break; } case ECommandsPage3TypeYesCmd: case ECommandsPage3TypeNoCmd: case ECommandsPage3TypeDoneCmd: case ECommandsPage3PreferToBePlacedInButtonbarCmd: case ECommandsPage3TypeItemCmd: case ECommandsPage3TypeDeleteCmd: { // Do nothing. In a normal application something should happen // here when the command has been activated. // If commands are not handle by the view they will be propageted // to the appUi. break; } default: { iCommandsView.HandleCommandL(aCommand); break; } } } /** Adds or remove icon for a specific command. @param aCommandId The commandId for the command to add or remove the icon @param aValue Indicates if icon should be added or removed from the command */ void CCommandsHandlerPage3::SetIconL(TInt aCommandId, TBool aAddIcon) const { // Retrieves the command with aCommandId from the currently active // command list CQikCommand* cmd = iCommandManager.Command(iCommandsView, aCommandId); CQikContent* icon = NULL; if(aAddIcon) { // Creates a CQikContent that loads the bitmap from the mbm file (CFbsBitmap). switch(aCommandId) { case ECommandsPage3TypeYesCmd: { icon = CQikContent::NewL(&iCommandsView, KIconBitmapFile, EMbmCommandsTypeyes, EMbmCommandsTypeyes_mask); break; } case ECommandsPage3TypeNoCmd: { icon = CQikContent::NewL(&iCommandsView, KIconBitmapFile, EMbmCommandsTypeno, EMbmCommandsTypeno_mask); break; } case ECommandsPage3TypeDoneCmd: { icon = CQikContent::NewL(&iCommandsView, KIconBitmapFile, EMbmCommandsTypedone, EMbmCommandsTypedone_mask); break; } case ECommandsPage3TypeItemCmd: { icon = CQikContent::NewL(&iCommandsView, KIconBitmapFile, EMbmCommandsTypeitem, EMbmCommandsTypeitem_mask); break; } case ECommandsPage3PreferToBePlacedInButtonbarCmd: { icon = CQikContent::NewL(&iCommandsView, KIconBitmapFile, EMbmCommandsTypeprefer, EMbmCommandsTypeprefer_mask); break; } case ECommandsPage3TypeDeleteCmd: { icon = CQikContent::NewL(&iCommandsView, KIconBitmapFile, EMbmCommandsTypedelete, EMbmCommandsTypedelete_mask); break; } default: { #ifdef _DEBUG _LIT(KErrNoSupportedCommandId ,"No supported command id"); __ASSERT_DEBUG(EFalse, User::Panic(KErrNoSupportedCommandId,0)); #endif // _DEBUG } } // Adds the icon and lets the command be the owner of the CQikContent. // Which mean that the CQikContent will be deleted by the command, // no further responsibility for that object. cmd->SetIcon(icon, ETakeOwnership); } else { // Removes the icon by setting the icon to NULL cmd->SetIcon(icon, ETakeOwnership); } }