S60 sample project 之 Helloworldbasic

 
1. Brief Introduction
Helloworldbasic project实现了一个比较简单的S60 GUI 应用程序的。通过实现App类,Doc类,View类,Ui类,Dialog类,实现了S60应用程序的框架。
我们应该重点了解各个Class之间的调用关系,如何用资源文件来描述一个UI,以及如何添加菜单的响应代码。

2. Design
不要被类图的繁冗的继承结构所吓倒,我们只需要研究他的很小的一部分。
序列图把调用关系基本阐述清楚了,虽然画的还是不够规范。
a. Class Diagram

b. Sequence Diagram



3. Key Concept


将App,Doc, Ui, View类的基类的官方mi摘录如下。

CAknApplication

Base class for a Series 60 application. S60的官方介绍真够简单的

CEikApplication

The base of all Uikon applications.

CEikApplication builds on CApaApplication, providing a basis for applications working within the framework provided by Uikon. It also contains an interface to the resource file and the document object belonging to the application.

Each Uikon  class is derived from CEikApplication. Application writers must provide at least an implementation of the pure virtual function CreateDocumentL().

The application's resource file can be changed from the default by overriding ResourceFileName().



CreateDocumentL()

Creates a new document.

This function is called by the application DLL framework during application startup to create a new instance of the document associated with this application. This implementation of the function makes a record of the CApaProcess argument, and returns a document created by the un-parameterised, private, overload.

这个函数在CHelloworldBasicApp中实现了。这个函数创建并返回了一个指向CHelloworldbasic对象的指针。但是当时我不明白,这个虚函数在何时会被调用?这段解释说地也不是很清楚,application DLL framework是什么概念,可以理解为是application server 吗?


ResourceFileName()

Gets the localized name of the resource file used by this application.

By default, this file has an extension of .rsc and uses the same name as the application file located in the same directory. Language variants are supported through BaflUtils::NearestLanguageFile().

每一个application都户默认的与其同名的rss文件相关联,在rss文件中定义了application的UI。


CAknDocument

Base class for a Series 60 application document. 等于没说


CEikDocument

In file-based applications, the document represents the data that relates to a
particular instance of the application, and should handle storing and restoring
it. In all applications, whether file-based or not, the document is used to create
the application UI.

A class derived from CEikDocument must be defined by each GUI application, and minimally
it must implement CreateAppUiL(). Note that UIs may implement their own document base class,
derived from CEikDocument, which applications may need to derive from instead.

The document is created by the application's CreateDocumentL() function.


CEikDocument负责两件事情1.应用程序相关的文件操作 2.实现CreateAppUiL()函数



CreateAppUiL()

Constructs the application UI.

This function is called by the UI framework during application start-up. It should only carry out first phase construction of the app UI, in other words, using new(ELeave). It should not call the app UI's ConstructL(), because the UI framework is responsible for this. Note also that the UI framework takes ownership of the app UI, so the document does not need to destroy it.

这个函数什么时候调用,被谁调用?文中提到在应用程序启动时被UI framework调用,这也是一个比较模糊的回答。

另外提到CreateAppUiL不负责进行Ui的construct,这个ConstructL函数被谁调用呢?估计也是UI framework


CAknAppUi

Abstract Avkon application UI class. 简单


CAknAppUiBase

Abstract Avkon application UI base class



CEikAppUi

Handles application-wide aspects of the application's user interface such
as the menu bar, toolbar pop-up menus, opening and closing files and exiting the
application cleanly.

Every GUI application should use its own class derived from CEikAppUi.

An app UI's main role is to handle commands, in its HandleCommandL() function.
These may be invoked using the menu bar, toolbar, or hotkeys; the commands
that an app UI handles are specified in the application's resource file.

In addition, the app UI normally needs to respond to other kinds of events, by
providing suitable implementations of the following virtual functions, all
inherited from CCoeAppUi:

- HandleKeyEventL(): Key events.

- HandleForegroundEventL(): Application switched to foreground.

- HandleSwitchOnEventL(): Machine switched on.

- HandleSystemEventL(): System events.

- HandleApplicationSpecificEventL(): Application-specific events.


说得比较明白了,虽然对于底层的消息调用机制仍然是透明的。



CCoeControl

Control base class from which all other controls are derived.




4. Implementation
4.1 main
  1. GLDEF_C TInt E32Main()
  2.     {
  3.     return EikStart::RunApplication( NewApplication );
  4.     }
  5. LOCAL_C CApaApplication* NewApplication()
  6.     {
  7.     return new CHelloWorldBasicApplication;
  8.     }

惯用的开局套路,以后依葫芦画瓢就可以了。
4.2 CHelloworldBasicApp
  1. CApaDocument* CHelloWorldBasicApplication::CreateDocumentL()
  2.     {
  3.     // Create an HelloWorldBasic document, and return a pointer to it
  4.     return (static_cast<CApaDocument*>
  5.                     ( CHelloWorldBasicDocument::NewL( *this ) ) );
  6.     }
标准化的调用,无须赘述。
  1. TUid CHelloWorldBasicApplication::AppDllUid() const
  2.     {
  3.     // Return the UID for the HelloWorldBasic application
  4.     return KUidHelloWorldBasicApp;
  5.     }
这个函数好像会被系统多次调用,不知为何。
4.3 CHelloworldBasicDoc
这个类的NewL,NewLC,ConstructL都是常规实现,无须赘述。
  1. CHelloWorldBasicDocument::CHelloWorldBasicDocument( CEikApplication& aApp )
  2.     : CAknDocument( aApp )
  3.     {
  4.     // No implementation required
  5.     }
注意aApp传给了基类的构造函数,说明Doc类中必定保留了只想App类的指针或引用。
  1. CEikAppUi* CHelloWorldBasicDocument::CreateAppUiL()
  2.     {
  3.     // Create the application user interface, and return a pointer to it;
  4.     // the framework takes ownership of this object
  5.     return ( static_cast <CEikAppUi*> ( new ( ELeave )
  6.                                         CHelloWorldBasicAppUi ) );
  7.     }
  4.4 CHelloworldBasicUi
CHelloworldBasicUi中重点实现了两个函数ConstructL以及HandleCommand
ConstructL首先调用了BasicConstructL函数,然后创建了一个hello.txt文件。
HandleCommand 和Windows的消息处理函数类似,一堆的switch case

5. Notes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值