1 / 39

基于 S60 的 UI 组件编程

基于 S60 的 UI 组件编程. 主要内容. UI 组件概述 标签的使用 编辑器的使用 列表的使用 设置列表的使用 自定义组件的开发 对话框. UI 组件概述. 使用 CONE 支持组件技术 标签组件 编辑器 列表 对话框 自定义组件. 标签的使用. 标签类 CEikLabel 使用 在 Container 类的声明中 ,声明标签成员 CEikLabel* iLabel; 创建控件 iLabel = new (ELeave) CEikLabel; iLabel->SetContainerWindowL( *this );

nasya
Download Presentation

基于 S60 的 UI 组件编程

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 基于S60的UI组件编程

  2. 主要内容 • UI组件概述 • 标签的使用 • 编辑器的使用 • 列表的使用 • 设置列表的使用 • 自定义组件的开发 • 对话框

  3. UI组件概述 • 使用CONE支持组件技术 • 标签组件 • 编辑器 • 列表 • 对话框 • 自定义组件

  4. 标签的使用 • 标签类CEikLabel • 使用 • 在Container类的声明中 ,声明标签成员 CEikLabel* iLabel; • 创建控件 iLabel = new (ELeave) CEikLabel; iLabel->SetContainerWindowL( *this ); iLabel->SetTextL( _L("Example View") ); • 重载父类CoeControl的如下方法: TInt CountComponentControls() const; CCoeControl* ComponentControl(TInt aIndex) const;

  5. 标签的使用 • 使用 • 在SizeChanged()方法中,设置控件在容器中的位置和大小 void CControlExamContainer::SizeChanged() { iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() ); }

  6. 编辑器的使用 • 编辑器类别 • 文本编辑器 • 数值编辑器 • 密码编辑器 • 多字段数值编辑器

  7. 编辑器的使用 • 文本编辑器 • 类型 • 无格式文本编辑器 • 全局文本编辑器 • 多格式文本编辑器

  8. 编辑器的使用 • 文本编辑器 • 编辑器资源及控件类

  9. 编辑器的使用 • 文本编辑器 • 无格式文本编辑器CEikEdwin的控件资源结构 STRUCT EDWIN { LONG flags=0; WORD width=0; WORD lines=1; WORD maxlength=0; AKN_EDITOR_EXTENSIONS }

  10. 编辑器的使用 • 文本编辑器 • 创建和使用编辑器控件——静态方式 • 1)在程序资源文件定义资源 RESOURCE EDWIN r_aknexeditor_view1_edwin { flags = EAknEditorFlagDefault; width = qnn_aknexeditor_view1_edwin_width; lines= qnn_aknexeditor_view1_edwin_height; maxlength = qnn_aknexeditor_view1_edwin_maxlength; }

  11. 编辑器的使用 • 2)在Container类中定义表示文本编辑器控件的成员变量指针 CEikEdwin* iEdwin;

  12. 编辑器的使用 • 3)创建文本编辑器控件,从资源初始化控件 TResourceReader reader; iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_VIEW1_EDWIN ); iEdwin = new ( ELeave ) CEikEdwin; iEdwin->SetContainerWindowL( *this ); iEdwin->ConstructFromResourceL( reader ); CleanupStack::PopAndDestroy(); // Resource reader iEdwin->SetExtent( EDWIN_POS, iEdwin->MinimumSize() );

  13. 编辑器的使用 • 4)实现下面的方法 TInt CountComponentControls() const; CCoeControl* ComponentControl(TInt aIndex) const; Void SizeChanged();

  14. 编辑器的使用 • 文本编辑器 • 创建和使用编辑器控件——动态方式 • 创建控件和初始化控件的方式不同 iEdwinDynamic = new ( ELeave ) CEikEdwin; iEdwinDynamic->ConstructL(0,8,15,1); iEdwinDynamic->SetContainerWindowL( *this ); iEdwinDynamic->SetExtent( TPoint( 10, 100 ), iEdwinDynamic->MinimumSize() );

  15. 编辑器的使用 • 文本编辑器 • 操作文本及属性 • 给编辑器设置初值 TBuf<20> buf; buf.Append(_L("this is example")); iGTextEd->SetTextL(&buf); iEdwinDynamic->SetTextL(&buf); • 获取编辑控件的内容 TBuf<30> bufContent; iEdwinDynamic->GetText(&bufContent); iEdwin->SetTextL(&bufContent);

  16. 编辑器的使用 • 文本编辑器 • 操作文本及属性 • 选择文本 // 得到选择的内容 TCursorSelection pos = iEditor->Selection(); // 取得选中的文本 CPlainText* text = iEditor->Text(); // 删除选中的文本 text->DeleteL(pos.LowerPos(), pos.Length());

  17. 编辑器的使用 • 文本编辑器 • 操作文本及属性 • 格式化文本 // 创建段落格式对象 CParaFormat* pf = new (ELeave) CParaFormat(); CleanupStack::PushL(pf); // 设置段落的对齐方式 pf->iHorizontalAlignment = CParaFormat::ECenterAlign; // 创建段落格式掩码对象 TParaFormatMask mask; // 设置 段落对齐属性将被改变 mask.SetAttrib(EAttAlignment); // 应用段落格式到全局文本编辑器对象 iEditor->ApplyParaFormatL(pf, mask); CleanupStack::Pop();

  18. 编辑器的使用 • 数值编辑器 • 类型 • 整数编辑器 • 浮点数编辑器 • 定点数编辑器

  19. 编辑器的使用 • 密码编辑器 • 类型 • 数字式密码编辑器 • 字母数字式密码编辑器

  20. 编辑器的使用 • 多字段数值编辑器

  21. 列表的使用 • 列表架构

  22. 列表的使用 • 列表类型 • 选择列表 • 多选列表 • 可标记列表 • 菜单列表

  23. 列表的使用 • 列表资源 STRUCT LISTBOX { BYTE version; WORD flags; WORD height; WORD width; LLINK array_id; }

  24. 列表的使用 • 创建和使用列表 • 定义资源 RESOURCE LISTBOX r_demo_listbox { flags = EAknListBoxSelectionList; array_id = r_demo_listbox_items; } RESOURCE ARRAY r_demo_listbox_items { items = { LBUF { txt = "Item1"; }, LBUF { txt = "Item2"; }, LBUF { txt = "Item3"; } }; }

  25. 列表的使用 • 创建和使用列表 • 创建列表 // 创建一个列表实例 CEikTextListBox* list = new (ELeave) CAknSingleStyleListBox(); // 给列表实例设置一个容器窗口 list->SetContainerWindow(*this); // 使用列表资源初始化资源读取器 TResourceReader rr; iEikonEnv->CreateResourceReaderLC(rr, R_DEMO_LISTBOX); // 从资源构建列表,初始化列表 list->ConstructFromResourceL(rr); CleanupStack::PopAndDestroy(); // rr

  26. 列表的使用 • 操作列表项 • 添加列表项 // 从列表的数据模型获取列表项数组指针 MDesCArray* textArray = list->Model()->ItemTextArray(); CDesCArray* itemList = static_cast<CDesCArray*>(textArray); // 构建一个新的列表项 _LIT(KNewItem, "New item.."); TBuf<32> item; item.Format(_L("\t%S\t\t"), &KNewItem); // 添加新的列表项值到列表项数组中 itemList->AppendL(item); // 通知列表,列表项数据被改变了 list->HandleItemAdditionL();

  27. 列表的使用 • 操作列表项 • 删除列表项 // 取得当前被选择列表项的索引 TInt currentItem = list->Model()->CurrentItemIndex(); // 从列表的数据模型取得列表项数据数组 MDesCArray* textArray = list->Model()->ItemTextArray(); CDesCArray* itemList = static_cast<CDesCArray*>(textArray); // 删除当前被选择的列表项 itemList->Delete(currentItem, 1); // 通知列表有列表项被删除,重新选择当前列表项 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(list, currentItem, ETrue); // 重新绘制列表 list->DrawNow();

  28. 设置列表的使用 • 设置列表是把应用的用户配置设置集中到一个列表中 • 可用的设置列表项 • 音量控件 • 文本编辑器 • 滑块控件 • 枚举文本 • 时间编辑器 • 日期编辑器 • IP字段编辑器 • 二元开关 • 字母数字口令编辑器 • 数字口令编辑器

  29. 自定义控件的开发 • 开发过程 • 从CCoeControl类派生一个类作为控件类。 • 实现派生类的二阶段构造函数ConstructL()。 • 实现虚函数Draw(),提供绘制控件的代码。 • 实现虚函数SizeChanged(),在控件大小改变时,重新布置、绘制控件。 • 实现虚函数OffkeyEventL(),提供处理键盘事件

  30. 对话框 • 对话框的分类 • 标准对话框 • 窗体 • 通知 • 查询

  31. 对话框 • 标准对话框的使用 • 1. 定义对话框资源 RESOURCE DIALOG r_input_name_dialog { flags=EEikDialogFlagNoDrag | EEikDialogFlagCbaButtons | EEikDialogFlagWait; buttons=R_AVKON_SOFTKEYS_OK_CANCEL; items= { DLG_LINE //该行定义显示标签 { id=EDialogInputNameLabel; //程序中使用此ID引用控件 type=EEikCtLabel; //控件类型 control= LABEL //定义控件 { }; }, }

  32. 对话框 • 标准对话框的使用 • 2. 从CAknDialog类派生一个对话框类 class CInputNameDlg : public CAknDialog { public: static TBool RunDlgLD (TDes& aName); protected: TBool OkToExitL(TInt aButtonId); void PreLayoutDynInitL(); private: CInputNameDlg(TDes& aName); private: //对话框数据 TDes& iName; };

  33. 对话框 • 标准对话框的使用 • 3. 从CAknDialog类派生一个对话框类 class CInputNameDlg : public CAknDialog { public: static TBool RunDlgLD (TDes& aName); protected: TBool OkToExitL(TInt aButtonId); void PreLayoutDynInitL(); private: CInputNameDlg(TDes& aName); private: //对话框数据 TDes& iName; };

  34. 对话框 • 标准对话框的使用 • 4. 实现对话框类 的静态方法 TBool CInputNameDlg::RunDlgLD (TDes& aPlayerName) { CInputNameDlg* inputNameDialog = new (ELeave) CInputNameDlg(aPlayerName); return inputNameDialog->ExecuteLD(R_INPUT_NAME_DIALOG); }

  35. 对话框 • 标准对话框的使用 • 5.动态初始化对话框显示的数据 void CInputNameDlg::PreLayoutDynInitL() { //取得对话框中标签控件的指针,设置标签显示的提示信息 CEikLabel* label = static_cast<CEikLabel*> (ControlOrNull(EDialogInputNameLabel)); if (label) { TBuf<30> labelText; labelText.Append(_L("Input contact name")); label->SetTextL(labelText); } }

  36. 对话框 • 标准对话框的使用 • 6.保存和验证对话框数据 if(CInputNameDlg::RunDlgLD(iContactName)) { CAknInformationNote* informationNote; informationNote = new ( ELeave ) CAknInformationNote; informationNote->ExecuteLD( iContactName); }

  37. 对话框 • 通知的使用 • 简单的包装式通知

  38. 对话框 • 通知的使用 TBuf<50> noteContent; noteContent.Append("Information Note"); CAknInformationNote* informationNote; informationNote = new ( ELeave ) CAknInformationNote; informationNote->ExecuteLD(noteContent);

  39. 对话框 • 查询的使用

More Related