/*
========================================================================
Name : SimpleDlgContainerView.cpp
Author : liut
Copyright : neusoft
Description :
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <akncontext.h>
#include <akntitle.h>
#include <stringloader.h>
#include <barsread.h>
#include <eikbtgpc.h>
#include <SimpleDlg.rsg>
// ]]] end generated region [Generated System Includes]
// [[[ begin generated region: do not modify [Generated User Includes]
#include "SimpleDlg.hrh"
#include "SimpleDlgContainer.h"
#include "SimpleDlgContainerView.h"
#include "SimpleDlgPlayerNameDialog.h"
#include "TextDialog.h"
// ]]] end generated region [Generated User Includes]
// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]
/**
* First phase of Symbian two-phase construction. Should not contain any
* code that could leave.
*/
CSimpleDlgContainerView::CSimpleDlgContainerView()
{
// [[[ begin generated region: do not modify [Generated Contents]
iSimpleDlgContainer = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* The view's destructor removes the container from the control
* stack and destroys it.
*/
CSimpleDlgContainerView::~CSimpleDlgContainerView()
{
// [[[ begin generated region: do not modify [Generated Contents]
delete iSimpleDlgContainer;
iSimpleDlgContainer = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* Symbian two-phase constructor.
* This creates an instance then calls the second-phase constructor
* without leaving the instance on the cleanup stack.
* @return new instance of CSimpleDlgContainerView
*/
CSimpleDlgContainerView* CSimpleDlgContainerView::NewL()
{
CSimpleDlgContainerView* self = CSimpleDlgContainerView::NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian two-phase constructor.
* This creates an instance, pushes it on the cleanup stack,
* then calls the second-phase constructor.
* @return new instance of CSimpleDlgContainerView
*/
CSimpleDlgContainerView* CSimpleDlgContainerView::NewLC()
{
CSimpleDlgContainerView* self = new ( ELeave ) CSimpleDlgContainerView();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Second-phase constructor for view.
* Initialize contents from resource.
*/
void CSimpleDlgContainerView::ConstructL()
{
// [[[ begin generated region: do not modify [Generated Code]
BaseConstructL( R_SIMPLE_DLG_CONTAINER_SIMPLE_DLG_CONTAINER_VIEW);
// ]]] end generated region [Generated Code]
// add your own initialization code here
}
/**
* @return The UID for this view
*/
TUid CSimpleDlgContainerView::Id() const
{
return TUid::Uid(ESimpleDlgContainerViewId);
}
/**
* Handle a command for this view (override)
* @param aCommand command id to be handled
*/
void CSimpleDlgContainerView::HandleCommandL(TInt aCommand)
{
// [[[ begin generated region: do not modify [Generated Code]
TBool commandHandled = EFalse;
switch (aCommand)
{ // code to dispatch to the AknView's menu and CBA commands is generated here
case ECmdSimpleDlg:
CSimpleDlgPlayerNameDialog::RunDlgLD(iPlayerName) ;
break;
case ECmdQeuryTextDlg:
CTextDialog *dialog = new (ELeave)CTextDialog(iProblem);
if (dialog->ExecuteLD(R_QUESTION_DATA_QUERY_DIALOG) )
{
}
break;
case EEikCmdExit:
{
AppUi()->HandleCommandL( EEikCmdExit);
break;
}
default:
break;
}
if ( !commandHandled)
{
if (aCommand == EAknSoftkeyExit)
{
AppUi()->HandleCommandL( EEikCmdExit);
}
}
// ]]] end generated region [Generated Code]
}
/**
* Handles user actions during activation of the view,
* such as initializing the content.
*/
void CSimpleDlgContainerView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
{
// [[[ begin generated region: do not modify [Generated Contents]
SetupStatusPaneL();
if (iSimpleDlgContainer == NULL)
{
iSimpleDlgContainer = CreateContainerL();
iSimpleDlgContainer->SetMopParent( this);
AppUi()->AddToStackL( *this, iSimpleDlgContainer);
}
// ]]] end generated region [Generated Contents]
}
/**
*/
void CSimpleDlgContainerView::DoDeactivate()
{
// [[[ begin generated region: do not modify [Generated Contents]
CleanupStatusPane();
if (iSimpleDlgContainer != NULL)
{
AppUi()->RemoveFromViewStack( *this, iSimpleDlgContainer);
delete iSimpleDlgContainer;
iSimpleDlgContainer = NULL;
}
// ]]] end generated region [Generated Contents]
}
/**
* Handle status pane size change for this view (override)
*/
void CSimpleDlgContainerView::HandleStatusPaneSizeChange()
{
CAknView::HandleStatusPaneSizeChange();
// this may fail, but we're not able to propagate exceptions here
TInt result;
TRAP( result, SetupStatusPaneL() );
// [[[ begin generated region: do not modify [Generated Code]
// ]]] end generated region [Generated Code]
}
// [[[ begin generated function: do not modify
void CSimpleDlgContainerView::SetupStatusPaneL()
{
// reset the context pane
TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext);
CEikStatusPaneBase::TPaneCapabilities subPaneContext = StatusPane()->PaneCapabilities(contextPaneUid);
if (subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
{
CAknContextPane* context = static_cast< CAknContextPane* > (StatusPane()->ControlL(contextPaneUid) );
context->SetPictureToDefaultL();
}
// setup the title pane
TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle);
CEikStatusPaneBase::TPaneCapabilities subPaneTitle = StatusPane()->PaneCapabilities(titlePaneUid);
if (subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
{
CAknTitlePane* title = static_cast< CAknTitlePane* >(StatusPane()->ControlL(titlePaneUid) );
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_SIMPLE_DLG_CONTAINER_TITLE_RESOURCE );
title->SetFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader internal state
}
}
// ]]] end generated function
// [[[ begin generated function: do not modify
void CSimpleDlgContainerView::CleanupStatusPane()
{
}
// ]]] end generated function
/**
* Creates the top-level container for the view. You may modify this method's
* contents and the CSimpleDlgContainer::NewL() signature as needed to initialize the
* container, but the signature for this method is fixed.
* @return new initialized instance of CSimpleDlgContainer
*/
CSimpleDlgContainer* CSimpleDlgContainerView::CreateContainerL()
{
return CSimpleDlgContainer::NewL(ClientRect(), NULL, this);
}
Symbian自定义对话框类SimpleDlg
2星 需积分: 0 173 浏览量
更新于2008-12-03
收藏 25KB RAR 举报
在Symbian操作系统中,创建自定义对话框是应用程序中常见的需求,这使得用户界面能够更加灵活和符合特定的应用场景。本篇文章将深入探讨如何在Symbian平台上使用`SimpleDlg`类来实现一个自定义对话框,以及涉及到的相关技术如`CAknDialog`和`CAknTextQueryDialog`。
`SimpleDlg`类可以视为一个基于Symbian SDK的自定义对话框模板。在Symbian中,通常使用`CAknDialog`作为对话框的基础类,它是S60 UI框架的一部分,提供了基本的对话框管理功能。开发者可以通过继承`CAknDialog`并覆盖其方法,来定制对话框的外观和行为。
`CAknDialog`类提供了添加和管理对话框元素(如按钮、文本字段等)的能力。例如,你可以通过`AddControlL`函数添加一个新的控件,并使用`SetCancelCommandL`和`SetOkCommandL`设置对话框的确认和取消命令。同时,`CAknDialog`还处理了对话框的显示和隐藏逻辑,以及响应用户交互。
接下来,我们提到的`CAknTextQueryDialog`是S60 UI框架中的另一个重要类,它专门用于创建包含文本输入字段的对话框。如果你的`SimpleDlg`需要用户输入信息,那么可能需要集成这个类。`CAknTextQueryDialog`提供了简单的文本输入功能,可以方便地创建一个带有标题、提示文本和输入字段的对话框。你可以通过设置`CAknTextQueryDialog`的属性来定制它的外观和行为,例如输入字段的大小、字体样式等。
在实际的项目中,使用`SimpleDlg`类时,你需要先在C++源代码中定义这个类,继承自`CAknDialog`,并实现必要的成员函数。这些函数可能包括构造函数、初始化对话框布局的`ConstructL`函数,以及处理用户输入和命令的事件处理函数。为了在Symbian系统上编译和运行代码,你将需要用到像`ActivePerl5.6.1`这样的工具来处理Makefile,以及`carbide.C++`这样的IDE来进行开发和调试。
在`SimpleDlg`类中,你可能还会用到其他Symbian和S60特定的类,比如`CEikLabel`、`CEikEditField`等,它们分别用于显示静态文本和获取用户输入。同时,别忘了处理资源文件,如`.resc`和`.rsg`,它们定义了对话框的视觉样式。
`SimpleDlg`类的实现可能包括以下几个步骤:
1. 创建`SimpleDlg`类,继承自`CAknDialog`。
2. 在`SimpleDlg`的构造函数中调用`CAknDialog`的构造函数,并在`ConstructL`中初始化对话框元素。
3. 添加和配置所需的控件,如文本输入框、按钮等。
4. 实现事件处理函数,如`DoCancel`和`DoOk`,以响应用户的操作。
5. 在主程序中实例化`SimpleDlg`对象,并调用`ExecuteLD`显示对话框。
通过这种方式,你可以根据具体需求构建出功能丰富的自定义对话框,增强Symbian应用程序的用户体验。记住,Symbian平台的UI设计需要遵循其特定的编程规范和最佳实践,以确保软件的稳定性和兼容性。