现在的位置: 首页 > 综合 > 正文

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

2013年02月07日 ⁄ 综合 ⁄ 共 1882字 ⁄ 字号 评论关闭

转自:http://hi.baidu.com/%B9%ED%C8%CB%CD%F5/blog/item/c47e5410a2e226fbc2ce7989.html/cmtid/4bea523446061541241f1475

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

2009-02-20 10:17

     哈哈,看来不是这样的,因为有 SetMopParent()。看如下的一个实例,

      现在有三个层次嵌套起来的复合控件(compound contol),我们姑且称之为 grandfather control, father control,child control,并且一个 CEikRichTextEditor 对象 iRtEd 是 child control 的子控件, 如果这三层控件都拥有自己的窗口,也就是 owning a window,那么就没有任何问题了,无论如何,iRtEd 都可以被正确创建。

      但是,如果只有 grandfather control 拥有自己的窗口,father control 和 child control 都没有自己的窗口,而是通过 SetContainerWindowL() 来共享 grandfather control 的窗口,那么问题就来了。

      按照惯例,在 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 的说明,

IMPORT_C void SetMopParent(MObjectProvider *aParent);
Description
      Sets the context - that is, the enclosing parent control - for this control.

所以,做如下的调用之后,

     iRtEd = new (ELeave) CEikRichTextEditor;
     iRtEd->SetAknEditorCase( EAknEditorLowerCase );
     iRtEd->SetAknEditorFlags( EAknEditorFlagFixedCase );
     iRtEd->SetParent( this );
     iRtEd->SetContainerWindowL( *this );
iRtEd->SetMopParent( this );
     iRtEd->ConstructL( this, 0, 0, 0 );

CEikRichTextEditor 对象即可在你构造的多层次复合控件环境中被正确创建,并且被 ActivateL(),所以千万不要忽视了 SetMopParent()。这个问题浪费了我不少时间,我查过 Symbian 和 S60 的资料,并且看过数个例子,包括“S60_Platform_Rich_Text_Editor_Example_v2_0_en.zip”,但是,这只 是 CEikRichTextEditor 对象在一个单层复合控件环境中的示例,也就是说,CEikRichTextEditor 的父控件拥有 window,所以你不会碰到这个问题。

抱歉!评论已关闭.