📄 mmsdemo1form.cpp
字号:
/*
* ============================================================================
* Name : CMMSDemo1Form from CMMSDemo1Form.h
* Part of : MMSDemo1
* Created : 28.10.2002 by Forum Nokia
* Implementation notes:
* Message editor/viewer form.
* Version :
* Copyright: Nokia Corp. 2003
* ============================================================================
*/
// INCLUDE FILES
#include "eikmenup.h" // For Menupane
#include "avkon.hrh" // To disable Add/Delete Menupane
#include "avkon.rsg" // To disable Add/Delete Menupane
#include <aknappui.h> // To call ProcessCommandL()
#include <apgcli.h> // For RApaLsSession
#include <aknglobalnote.h> // For AknGlobalNote
#include "mmsdemo1form.h"
#include <mmsdemo1.rsg>
// FUNCTION PROTOTYPES
// ================= MEMBER FUNCTIONS =========================================
// ----------------------------------------------------------------------------
// CMMSDemo1Form::NewL()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CMMSDemo1Form* CMMSDemo1Form::NewL(TBool aModifyAllowed, TDes& aUrl, TDes& aDescription,
TDes& aTo, TDes& aCc, TBool aForwadMsg, TBool aOpenedMessage)
{
CMMSDemo1Form* self =
new (ELeave) CMMSDemo1Form(aModifyAllowed,aUrl,aDescription,aTo,aCc, aForwadMsg, aOpenedMessage);
CleanupStack::PushL(self);
if(aOpenedMessage)
{
if(aTo.Length() > 0)
self->ConstructL(R_MMSDEMO1_MENUBAR_OPEN);
else
self->ConstructL(R_MMSDEMO1_MENUBAR_OPEN_EMBEDDED);
}
else
self->ConstructL();
CleanupStack::Pop();
return self;
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::~CAknExFormSaveForm()
// Destructor.
// ----------------------------------------------------------------------------
//
CMMSDemo1Form::~CMMSDemo1Form()
{
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::CAknExFormSaveForm()
// Default constructor.
// ----------------------------------------------------------------------------
//
CMMSDemo1Form::CMMSDemo1Form(TBool aModifyAllowed, TDes& aUrl, TDes& aDescription,
TDes& aTo, TDes& aCc, TBool aForwadMsg, TBool aOpenedMessage)
:iUrl(aUrl),
iDesc(aDescription),
iTo(aTo),
iCc(aCc),
iEmergencyExit(EFalse),
iModifyAllowed(aModifyAllowed),
iIsForwardMsg(aForwadMsg),
iIsOpenedMsg(aOpenedMessage)
{
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::ModifyAllowed()
// Second-phase constructor.
// ----------------------------------------------------------------------------
//
void CMMSDemo1Form::SetModifyAllowed(TBool aModifyAllowed)
{
iModifyAllowed=aModifyAllowed;
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::OkToExitL()
// User requests to close the form, check needed issues and either accept
// or decline (close form or ask the user for more information)
// ----------------------------------------------------------------------------
//
TBool CMMSDemo1Form::OkToExitL(TInt aButtonId)
{
CEikButtonGroupContainer * myCbaGroup = CEikButtonGroupContainer::Current();
if (aButtonId==EMMSDemo1SendButton && !myCbaGroup->IsCommandDimmed(aButtonId))
{
// update the values from edwin controls
GetEdwinText(iUrl,EMMSDemo1DlgCtrlIdEdwinUrl);
GetEdwinText(iDesc,EMMSDemo1DlgCtrlIdEdwinDescription);
GetEdwinText(iTo,EMMSDemo1DlgCtrlIdEdwinTo);
GetEdwinText(iCc,EMMSDemo1DlgCtrlIdEdwinCc);
_LIT(KSending,"Sending...");
// Display a Note --> If process take more time change type of the Note according the process need
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalInformationNote , KSending);
CleanupStack::PopAndDestroy();
// launch sending on the AppUi
iAvkonAppUi->ProcessCommandL(EMMSDemo1CmdSend);
//Exit
return ETrue;
}
if (aButtonId==EAknSoftkeyBack)
{
if (IsEditable())
{
ValidateL();
return EFalse;
}
else
return ETrue;
}
return CAknForm::OkToExitL(aButtonId);
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::DynInitMenuPaneL()
// Preparing form.
// ----------------------------------------------------------------------------
//
void CMMSDemo1Form::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
{
CAknForm::DynInitMenuPaneL(aResourceId, aMenuPane);
if (aResourceId == R_AVKON_FORM_MENUPANE)
{
aMenuPane->SetItemDimmed(EAknFormCmdSave, ETrue);
aMenuPane->SetItemDimmed(EAknFormCmdEdit, ETrue);
aMenuPane->SetItemDimmed(EAknFormCmdLabel, ETrue);
aMenuPane->SetItemDimmed(EAknFormCmdAdd, ETrue);
aMenuPane->SetItemDimmed(EAknFormCmdDelete, ETrue);
}
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::ProcessCommandL()
// Processing menu commands, either forwarding, replying or launching the WAP browser
// ----------------------------------------------------------------------------
//
void CMMSDemo1Form::ProcessCommandL(TInt aCommandId)
{
if(aCommandId == EMMSDemo1CmdForwardMessage)
{
// redirect command to appui
HideMenu();
iAvkonAppUi->ProcessCommandL(EMMSDemo1CmdForwardMessage);
} // EMMSDemo1CmdForwardMessage
if(aCommandId == EMMSDemo1CmdReplyMessage)
{
// redirect command to appui
HideMenu();
iAvkonAppUi->ProcessCommandL(EMMSDemo1CmdReplyMessage);
} // EMMSDemo1CmdReplyMessage
if(aCommandId == EMMSDemo1CmdOpenURL)
{
HideMenu();
// Open URL in WAP browser
// Parameters are separated by space
// 1st parameter: type of the further parameters
// 2nd parameter: URL
// Note: Set 4 as the first parameter, specify that second parameter will be an URL
HBufC* param = HBufC::NewLC( 100 );
param->Des().Append('4');
param->Des().Append(' ');
param->Des().Append(iUrl);
// Wap Browser's constants UId
const TInt KWmlBrowserUid = 0x10008D39;
TUid id( TUid::Uid( KWmlBrowserUid ) );
TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
TApaTask task = taskList.FindApp( id );
if ( task.Exists() )
{
HBufC8* param8 = HBufC8::NewLC( param->Length() );
param8->Des().Append( *param );
task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
CleanupStack::PopAndDestroy();
}
else
{
RApaLsSession appArcSession;
User::LeaveIfError(appArcSession.Connect()); // connect to AppArc server
TThreadId id;
appArcSession.StartDocument( *param, TUid::Uid( KWmlBrowserUid ), id );
appArcSession.Close();
}
CleanupStack::PopAndDestroy(); // param
} // EMMSDemo1CmdOpenURL
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::ValidateL()
// Check form contents. Send button will be dimmed until one recipient
// address is entered.
// ----------------------------------------------------------------------------
//
TBool CMMSDemo1Form::ValidateL()
{
GetEdwinText(iTo,EMMSDemo1DlgCtrlIdEdwinTo);
// we can customise the checking by identify which entry we are selecting currently
if(iTo.Length()==0) // To field is empty, can't send yet
{
if( ( IdOfFocusControl()==EMMSDemo1DlgCtrlIdEdwinTo ) )
{
_LIT(KDataNotAccepted,"Please define a recipient");
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalWarningNote , KDataNotAccepted);
CleanupStack::PopAndDestroy();
// Dim "Send" button util the user has typed in at least one To address
CEikButtonGroupContainer * myCbaGroup = CEikButtonGroupContainer::Current();
myCbaGroup->DimCommand(EMMSDemo1SendButton,ETrue);
myCbaGroup->DrawNow();
}
// we may return to View mode, like the below
SetEditableL(EFalse);
return EFalse;
}
else // we accept the data
{
CEikButtonGroupContainer * myCbaGroup = CEikButtonGroupContainer::Current();
myCbaGroup->DimCommand(EMMSDemo1SendButton,EFalse);
myCbaGroup->DrawNow();
SetEditableL(EFalse);
return ETrue;// We accept
}
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::OfferKeyEventL()
// Handle key events.
// ----------------------------------------------------------------------------
//
TKeyResponse CMMSDemo1Form::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
if (IsEditable())
{
switch (aKeyEvent.iCode)
{
case EKeyOK:
// Validate the user input
ValidateL();
// Disable the Up&Down key
case EKeyUpArrow:
case EKeyDownArrow:
return EKeyWasConsumed;
default:
return CAknForm::OfferKeyEventL(aKeyEvent,aType);
}
}
else // Not editable
{
switch (aKeyEvent.iCode)
{
case EKeyOK: // Edit if application logic allow it
if (iModifyAllowed)
{
if(iIsForwardMsg) // message is a forward i.e. can't edit url or descr fields
{
// We may edit 'To' or 'Cc' when 'OK' pressed
if (IdOfFocusControl()==EMMSDemo1DlgCtrlIdEdwinTo
||
IdOfFocusControl()==EMMSDemo1DlgCtrlIdEdwinCc )
{
SetEditableL(ETrue);
return EKeyWasConsumed;
}
}
else // message is either a new one or a reply; can edit all fields
{
SetEditableL(ETrue);
return EKeyWasConsumed;
}
}
else // modify is not allowed = check focus and possibly start wap browser
{
if (IdOfFocusControl()==EMMSDemo1DlgCtrlIdEdwinUrl)
{
// Start browser
ProcessCommandL(EMMSDemo1CmdOpenURL);
}
}
break;
case EKeyLeftArrow:
case EKeyRightArrow:
return EKeyWasNotConsumed;
break;
default:
break;
}
}
return CAknForm::OfferKeyEventL(aKeyEvent,aType);
}
// ----------------------------------------------------------------------------
// CMMSDemo1Form::PostLayoutDynInitL()
// Set default field value to member data.
// ----------------------------------------------------------------------------
//
void CMMSDemo1Form::PostLayoutDynInitL()
{
CAknForm::PostLayoutDynInitL();
SetChangesPending(ETrue);
SetEdwinTextL(EMMSDemo1DlgCtrlIdEdwinUrl, &iUrl);
SetEdwinTextL(EMMSDemo1DlgCtrlIdEdwinDescription, &iDesc);
SetEdwinTextL(EMMSDemo1DlgCtrlIdEdwinTo, &iTo);
SetEdwinTextL(EMMSDemo1DlgCtrlIdEdwinCc, &iCc);
// Dim "Send" button utill the user has typed in at least one To address
if(iTo.Length() <= 0)
{
CEikButtonGroupContainer * myCbaGroup = CEikButtonGroupContainer::Current();
myCbaGroup->DimCommand(EMMSDemo1SendButton,ETrue);
myCbaGroup->DrawNow();
}
}
/// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -