Symbian3/SDK/Source/GUID-1A26BD9E-5B8E-4E6D-904E-B8354B14E111.dita
changeset 0 89d6a7a84779
equal deleted inserted replaced
-1:000000000000 0:89d6a7a84779
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-1A26BD9E-5B8E-4E6D-904E-B8354B14E111" xml:lang="en"><title>Constructing
       
    13 views in the view architecture</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>The call on the first phase constructor method of the view occurs in <xref href="GUID-FD2CDEB8-0784-4BE5-A775-170F57D71BBC.dita">UI controller</xref>. The
       
    15 view serves as the top-level window under the UI controller.</p>
       
    16 <p>The methods you need to implement for your <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html" format="application/java-archive"><parmname>CCoeControl</parmname></xref>-derived
       
    17 view are as follows:</p>
       
    18 <ul>
       
    19 <li><p>C++ default constructor, which cannot contain code that leaves.
       
    20 A common implementation is:</p>
       
    21 <itemgroup>
       
    22 <codeblock id="GUID-7A108F7C-AD2E-4CDA-9758-5FD6ED477917" xml:space="preserve">
       
    23 CMyAppView* CMyAppView::NewL( const TRect&amp; aRect )
       
    24     {
       
    25     CMyAppView* self = CMyAppView::NewLC( aRect );
       
    26     CleanupStack::Pop( self );
       
    27     return self;
       
    28     }
       
    29 
       
    30 CMyAppView* CMyAppView::NewLC( const TRect&amp; aRect )
       
    31     {
       
    32     CMyAppView* self = new ( ELeave ) CMyAppView;
       
    33     CleanupStack::PushL( self );
       
    34     self-&gt;ConstructL( aRect );
       
    35     return self;
       
    36     }
       
    37 
       
    38 CMyAppView::CMyAppView()
       
    39     {
       
    40     // No implementation required
       
    41     }</codeblock>
       
    42 <p>The declarations for <parmname>CMyAppView::NewL</parmname> and <parmname>CMyAppView::NewLC</parmname> in
       
    43 the class header file needs to be public to support the construction method
       
    44 required.</p>
       
    45 <p>In this approach, <parmname>CMyAppView::NewL</parmname> is called from
       
    46 the UI controller. It creates a view object by calling <parmname>CMyAppView::NewLC</parmname>. <parmname>CMyAppView::NewLC</parmname> calls
       
    47 new (ELeave) on the C++ default constructor <parmname>CMyAppView</parmname> to
       
    48 create the object (and leave if it cannot), <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Kernel_Architecture_2/CCleanupClass.html#%3a%3aCCleanup%3a%3aPushL%28CBase%20%2a%29" format="application/java-archive">pushes</xref> a pointer to the clean-up stack in case the second phase construction method
       
    49 leaves, and then calls the second phase construction method of the object.
       
    50 When it returns to <parmname>CMyAppView::NewL</parmname>, the pointer pushed
       
    51 to the cleanup stack is <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Kernel_Architecture_2/CCleanupClass.html#%3a%3aCCleanup%3a%3aPop%28%29" format="application/java-archive">removed</xref>.</p>
       
    52 </itemgroup>
       
    53 </li>
       
    54 <li><p>Symbian 2nd phase constructor with code that might leave.
       
    55 A common implementation is:</p>
       
    56 <itemgroup>
       
    57 <codeblock id="GUID-32125111-6ACB-4539-8CD0-39ED5629789F" xml:space="preserve">
       
    58 void CMyAppView::ConstructL( const TRect&amp; aRect )
       
    59     {
       
    60     // Create a window for this application view
       
    61     CreateWindowL();
       
    62 
       
    63      //add construction for other controls if required
       
    64 
       
    65 	   // Set the windows size
       
    66     SetRect( aRect );
       
    67 
       
    68     // Activate the window, which makes it ready to be drawn
       
    69     ActivateL();
       
    70     }</codeblock>
       
    71 <p><parmname>CMyAppView::ConstructL</parmname> is a private class providing
       
    72 the second phase construction that accepts the rectangle the view is drawn
       
    73 to.</p>
       
    74 <p><xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aCreateWindowL%28%29" format="application/java-archive"><parmname>CCoeControl::CreateWindowL</parmname></xref> creates a window
       
    75 for the control. Note that this window is a child of the UI controller. This
       
    76 method makes the control a <xref href="GUID-352850A9-227F-45DB-8DCD-C6268954B4ED.dita">window-owning
       
    77 control</xref>. While, the use of window-owning controls is discouraged to
       
    78 prevent the taxing of run-time resources, this is the top-level window for
       
    79 the UI controller.</p>
       
    80 <p>While this is a simple control that does not contain other controls,
       
    81 other controls could be added to the control between <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aCreateWindowL%28%29" format="application/java-archive"><parmname>CCoeControl::CreateWindowL</parmname></xref> and <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aSetRect%28const%20TRect%20%26amp%3b%29" format="application/java-archive"><parmname>CCoeControl::SetRect(aRect)</parmname></xref>. For more information,
       
    82 see <xref href="GUID-57CA8A13-05C6-4AFE-9804-E2EA2453143A.dita">Compound
       
    83 controls in the view architecture</xref>.</p>
       
    84 <p><xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aSetRect%28const%20TRect%20%26amp%3b%29" format="application/java-archive"><parmname>CCoeControl::SetRect(aRect)</parmname></xref> sets the window
       
    85 size according to the requirements of the mobile device. The top-level control
       
    86 rectangle is set to the area that the framework provides for the application.
       
    87 Calling <parmname>SetRect</parmname> calls the <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aSizeChanged%28%29" format="application/java-archive"><parmname>CCoeControl::SizeChanged</parmname></xref> method, where the control should set the position and size
       
    88 for any child controls and thus adjust the control layout to the UI.</p>
       
    89 <p><xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aActivateL%28%29" format="application/java-archive"><parmname>CCoeControl::ActivateL</parmname></xref> sets the control
       
    90 as ready to be drawn.</p>
       
    91 </itemgroup>
       
    92 </li>
       
    93 </ul>
       
    94 <p>If required for your application, you may need to implement other methods
       
    95 for your control. For top-level windows, you would need to implement <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aSizeChanged%28%29" format="application/java-archive"><parmname>CCoeControl::SizeChanged</parmname></xref> to respond to
       
    96 changes to the size and position of the contents of this control. This is
       
    97 called by the Symbian platform when a change occurs. A typical implementation
       
    98 for a compound control is:</p>
       
    99 <codeblock id="GUID-6F100E69-F0BB-4637-A1AA-57024AF20CF4" xml:space="preserve">void CMyAppView::SizeChanged()
       
   100     {
       
   101     // Control resize code
       
   102     iControl-&gt;SetExtent( const TPoint &amp;aPosition, const TSize &amp;aSize);
       
   103     }</codeblock>
       
   104 </conbody></concept>