Tuesday, May 02, 2006

Multiple Views

One of the most fundamental kind of apps is the one which supports multiple views. Here we discuss the multipleviews example which comes as a part of Series60 Examples.

The general idea is explained in the previous post. Here is the gist of it. For supporting multiple views, the view class must derive from CAknView as it contains methods for switching as well as activating/decativing other views. However to draw to a view as well as have a view contain other controls, the view needs to be an instance of CCoeControl. These 2 approaches cannot be mixed aka we cannot have a view inheriting from both CCoeControl as well as CAknView as this leads to a diamond kinda hierarchy. So we have the concept of a view and a container.

A container is simply a holder for other controls which also knows how to draw itself. Note that this container is just like a view for normal(Single View) applications. Every view is inherited from CAknView while every container is derived from CCoeControl. A view holds a container.

Here is an overview of the classes used with intersting bits as comments...

1. The main class -- Multiviews.cpp

Class creates an instance of CMultiviewsApplication and returns it by casting to CApaApplication.


2. Document Class -- MultiViewsDocument.cpp

Derives from CAknDocument, which derives from UIKON root document class CEikDocument which itself derives from CApaDocument. Ditto as application.

3. UI Class -- MultiViewsUI

Derives from CAknViewAppUI, instead of CAknAppUI. Actually CAknAppUI is used in single paned applications while CAknViewAppUI, which inherits from CAknAppUI, is used for multiple views. The view class maintains a reference to views. In ConstructL(), the views are created, added to base class using AddViewL() and a default view is set via SetDefaultViewL().

4. View Classes -- CMultiViewsView*

Derives from CAknView

5. Container Classes -- CMultiViewsContainer*

Derives from CCoeControl...

=====================

TitBits:
An interesting titbit is the hierarchy of classes. An application class derives from CAknApplication, which further derives from CEikApplication. CEikApplication is the root application class for all UIKON applications. It provides interface to resource file and document. CEikApplication class is derived from CApaApplication which defines basic behavious for all applications. This model is followed verbatim for Documents also. The hierarchy for UI and Views is a bit different.

An interesting titbit about the 2 phase constructions:-
a) Ctor is the first phase of construction. IT CANNOT LEAVE
b) ConstructL() is the second phase. IT CAN LEAVE.

Another one...
We don't need to include complete headers. A forward reference is sufficient incase we need only one class.

Yet Another...
NewL DOES NOT PUTS the object on CLEANUP STACK
NewLC PUTS object on CLEANUP STACK
Also the ConstructL() func called in the second phase construction is private..

===============================

Adding one more view to the application


  1. Create new container header and src

  2. Create new view header and src

  3. Include view construction & initialization code in UI

  4. Fill in menu event handler

0 Comments:

Post a Comment

<< Home