Constructing the UI controller in the view architecture

The call on the first phase constructor method of the UI controller occurs in the CAknDocument -derived class of application. For more information, see Implementing framework requirements .

The methods you need to implement for your CAknViewAppUI -derived UI controller are as follows:

  • C++ default constructor, which cannot contain any code that might leave. A common implementation is:

            
             
            
            CMyViewAppAppUi::CMyViewAppAppUi()
        {    
        }
           

    The class declaration for this constructor in the class header file needs to be public to support the construction method required.

  • Symbian 2nd phase constructor with code that might leave. A common implementation is:

            
             
            
            void CMyViewAppAppUi::ConstructL()
        {
        
        BaseConstructL(EAknEnableSkin); // Use EAknEnableSkin to make the application support themes.
     
        CMyViewAppView* view1 = CMyViewAppView::NewL();
    
        AddViewL( view1 );        // transfer ownership to CAknViewAppAppUi
    	  iViewId1 = view1->Id();   // view id to get view from CAknViewAppAppUi
        
    
        CMyViewAppView2* view2 = CMyViewAppView2::NewL();
    
        AddViewL( view2 );      // transfer ownership to CAknViewAppAppUi
    	  iViewId2 = view2->Id(); // view id to get view from CAknViewAppAppUi
        
    
        SetDefaultViewL( *view1 );
        }
           

    ConstructL completes the construction of the object. It is a public constructor in the header file.

    CAknViewAppUi::BaseConstructL() initializes the application UI with necessary UI components , including status and control panes. CAknViewAppUi::BaseConstructL() can accept flags enumerated in CEikAppUi and CAknAppUi . In particular, the CAknAppUi::EAknEnableSkin() flag enables themes in the application.

    CMyViewAppView* view1 = CMyViewAppView::NewL() is a two phase constructor for the CAknView -derived view controller.

    CAknViewAppUi::AddViewL() registers and adds the view controller to the UI controller.

    iViewId1 = view1->Id() calls the view controller method that provides the UID of the view controller.

    CCoeAppUi::SetDefaultViewL() registers a view as the default view of the application. The meaning of the default view varies depending on the UI. It is normally the view that is displayed when the application is launched. It may also be the view that is displayed when the application is brought to the foreground.

You must implement other methods to support key event handling , command handling , and other possible events , as well as overriding default control pane and status pane behavior.

Note:

Command, key event, and layout change support handling can take place at least partially in the view controller.

Scalability

If you wish to support scalability in your application, then you need to implement CEikAppUi::HandleResourceChangeL() in the UI controller , and then a HandleClientRectChangeL method in the view controller.

A common implementation is:

       
        
       
       void CMyViewAppAppUi::HandleResourceChangeL( TInt aType )
    {    	    
    CAknAppUi::HandleResourceChangeL( aType );	

    
    if ( aType==KEikDynamicLayoutVariantSwitch )
        {		
		((CMyViewAppView*) View( iViewId1) )->HandleClientRectChange(  );
		((CMyViewAppView2*) View( iViewId2) )->HandleClientRectChange(  );	        
		}	
	
    }
      

, where

CEikAppUi::HandleResourceChangeL() is a layout change event method .

HandleClientRectChangeL is a method in the view controller for passing the change onto to the control