symbian中自定义控件

来源:互联网 发布:桃谷绘里香推荐 知乎 编辑:程序博客网 时间:2024/04/30 03:24

大多数Symbian OS UI控件派生自CCoeControl类,CCoeControl类提供了一个控件框架并同时提供丰富的功能。CcoeControl通过将窗口服务器及其事件封装为公共Symbian OS应用框架的―部分,即控件环境,而隐藏了相关的复杂性。

下面是CCoeControl类提供的方法:

1.Construction and destruction
2.Creating compound controls
Description:A compound control is one which contains one or more simple or compound controls. Compound controls are also known as container controls, and may be window-owning or non-window-owning.

3.Creating window owning controls

 

4.Setting and querying size, position and extent

Description:A control's origin is its top-left corner. The position of a control is specified relative to the origin of its associated window.

5.Activating a control
6.Drawing
7.Graphics contexts
8.Control contexts
Description:Control contexts allow a group of controls to share a common set of graphics context settings, and hence a common appearance.
9.Making controls invisible
10.Making controls dimmed
11.Keyboard focus
12.Handling key and pointer events
Description:The functions grouped below handle key and pointer events and sending events to another control.
 
在symbian os中自定义控件的步骤:
step1.创建复合控件:
复合控件实现的函数允许控件框架在初始化和绘制控件时访问子控件。
CCoeControl::CountComponentControls可以返回子控件的数目(This function should be implemented by all compound controls),在递归遍历控件树时,需要子控件数;例如,当初始化应用时、在顶层控件调用ActivateL 方法后、或在进行绘制操作时均需要子控件数。
CCoeControl::ComponentControl方法可以返回一个指向子控件的指针。(This function should be implemented by all compound controls.)控件框架使用ComponentControl方法访问子控件,
 
step2.窗口
RWindow类代表设备屏幕上窗口服务器支持的区域。控件能够被绘制到窗口中,并且在窗口具有焦点时从窗口服务器接收事件。所有控件都通过使用一个窗口访问屏幕很重要。控件可以拥有它们自己的窗口或使用其它控件的窗口。一种常用的设计方法是顶层复合控件创建一个窗口,然后它的所有子控件共享该窗口。
控件窗口通过CCoeControl::CreateWindowL方法创建。它有一些重载方法,但最常用的是没有参数的重载方法,它基于控件的内存地址创建主窗口及其句柄。另一个有用的重载方法是使用CCoeControl作为参数,从而为控件的窗口创建子窗口例如控件使用窗口滚动或剪切时需要操作子窗口——作为一些特例,为子控件创建窗口而不是使用父控件的窗口是需要的。
如果一个控件没有自己的窗口,则应该通过调用CCoeControl::SetContainerWindowL方法设置它需要使用的窗口。该方法有一些重载,但对于复合控件,使用CCoeControl作为参数的重载最为有用。该参数可以是拥有窗口的控件,也可以是与其它控件共享窗口的控件。
 
step3.输入事件
控件可以接收按键或指针事件。窗口服务器产生事件,应用框架使用活动调度器循环侦听事件。当发生事件时,它将被发送到具有焦点的控件,框架然后根据事件类型调用控件的处理方法;例如,为按键事件调用CCoeControl::OfferKeyEventL ,为指针事件调用CCoeControl::HandlePointerEventL。
应用框架仅向压入事件堆栈中的控件提供按键输入事件。通过CCoeAppUi::AddToStackL方法向事件堆栈压入输入接收控件。事件堆栈中可以有多个控件。在发生事件时,按照压入到堆栈中的顺序为控件调用CCoeControl::OfferKeyEventL方法,即首先提供事件给最后压入的控件。事件被依次传给堆栈中的各个控件,直到控件返回。
TKeyResponse::EKeyWasConsumed。TKeyResponse的一种常用策略是,如果控件使用事件执行某些内容,则该事件将被消耗掉。通常一个顶层复合控件被压入到堆栈中,顶层控件将事件分配给它的子控件。然而,无论父控件是否在事件堆栈中,事件都不会自动提供给子控件。如果子控件需要事件,复合控件应执行OfferKeyEventL,将按键事件传递给子控件
原创粉丝点击