SetMopParent的使用

Symbian - CEikRichTextEditor 陷阱(关于SetMopParent()的探究)

有 SetMopParent()。看如下的一个实例, : ?& `: S3 X# Y' w  k
      现在有三个层次嵌套起来的复合控件(compound contol),我们姑且称之为 grandfather control, father control,child control,并且一个 CEikRichTextEditor 对象 iRtEd 是 child control 的子控件, 如果这三层控件都拥有自己的窗口,也就是 owning a window,那么就没有任何问题了,无论如何,iRtEd 都可以被正确创建。 dev.mmarket.com6 B2 ?1 N- t8 [' z3 J5 `. D& v
中国移动开发者社区: ~* M! g3 n; v0 f
      但是,如果只有 grandfather control 拥有自己的窗口,father control 和 child control 都没有自己的窗口,而是通过 SetContainerWindowL() 来共享 grandfather control 的窗口,那么问题就来了。
9 {* w& B" F" V
3 ]' H- d6 s6 e8 J+ I开发者社区论坛      按照惯例,在 new CEikRichTextEditor 以后,调用 SetParent() 和 SetContainerWindowL() 即可,但是 CEikRichTextEditor 比较特殊,如果仅仅做了这两个步骤,你肯定会得到一个 KERN-EXEC 3 的 Panic。是因为 child control 从 grandfather control 层层传递过来的 window 并没有交给 CEikRichTextEditor,所以你在调用 CEikRichTextEditor::ConstructL(const CCoeControl* aParent, TInt aNumberOfLines, TInt aTextLimit, TInt aEdwinFlags, TInt aFontControlFlags=EGulFontControlAll, TInt aFontNameFlags=EGulNoSymbolFonts) 的时候,会出现 KERN-EXEC 3 Panic,原因是  aParent(也就是 child control)的 window 环境并没有传递给这个CEikRichTextEditor 对象(iRtEd),它认为用没有 window 的父控件构造自己是非法的,所以有这个错误。那么如何让这个 CEikRichTextEditor 对象(iRtEd)得到 child control 的 window 环境呢?就是调用 CCoeControl::SetMopParent(MObjectProvider *aParent)。下面是 SetMopParent 的说明, # ~0 k& t$ H* ~# V$ R* H; ?9 [
IMPORT_C void SetMopParent(MObjectProvider *aParent);中国移动开发者社区- T, d) w  Y7 q$ |
Description. D6 o0 i" [$ X! E5 w
      Sets the context - that is, the enclosing parent control - for this control.开发者社区论坛& B% T' u1 i5 ]+ _. j3 P0 Y0 E6 A
开发者社区论坛" X6 B5 y4 C5 Z: /6 y8 ]. d5 x
所以,做如下的调用之后, 中国移动开发者社区4 _2 j/ /# M% /: L
     iRtEd = new (ELeave) CEikRichTextEditor; ' |% {# O0 @: e8 M* y
     iRtEd->SetAknEditorCase( EAknEditorLowerCase );
! t: G, F* ]; Z8 T! u+ }; Y% k     iRtEd->SetAknEditorFlags( EAknEditorFlagFixedCase ); + m$ ~+ I( u. {! ^7 O
     iRtEd->SetParent( this ); 4 R2 x- B' ~: R; }: W
     iRtEd->SetContainerWindowL( *this );
' F9 B* F1 L: P9 E( e- R1 `# h' `中国移动开发者社区      iRtEd->SetMopParent( this ); 开发者社区论坛; O" q! x( s  B; J
     iRtEd->ConstructL( this, 0, 0, 0 ); - m/ D/ u0 R. ?7 H
开发者社区论坛$ S3 Z% f4 {! [& ]
CEikRichTextEditor 对象即可在你构造的多层次复合控件环境中被正确创建,并且被 ActivateL(),所以千万不要忽视了 SetMopParent()。这个问题浪费了我不少时间,我查过 Symbian 和 S60 的资料,并且看过数个例子,包括“S60_Platform_Rich_Text_Editor_Example_v2_0_en.zip”,但是,这只是 CEikRichTextEditor 对象在一个单层复合控件环境中的示例,也就是说,CEikRichTextEditor 的父控件拥有 window,所以你不会碰到这个问题。
7 d5 U3 n& s( p. j/ f0 P# G7 S4 y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值