Symbian3/PDK/Source/GUID-57CA8A13-05C6-4AFE-9804-E2EA2453143A.dita
changeset 1 25a17d01db0c
child 3 46218c8b8afa
equal deleted inserted replaced
0:89d6a7a84779 1:25a17d01db0c
       
     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-57CA8A13-05C6-4AFE-9804-E2EA2453143A" xml:lang="en"><title>Compound
       
    13 controls in the view architecture</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p><xref href="GUID-352850A9-227F-45DB-8DCD-C6268954B4ED.dita">Compound controls</xref> are
       
    15 controls that contain other controls. To create a compound control, you must
       
    16 do the following:</p>
       
    17 <ul>
       
    18 <li><p>construct the control in the parent control, which is the
       
    19 control that owns the window in which the control appears. The control should
       
    20 be constructed in the constructor for the window. An example of an implementation
       
    21 is as follows:</p>
       
    22 <itemgroup>
       
    23 <codeblock id="GUID-87D5DA2C-DF12-40CA-8F39-CA9B61500F8F" xml:space="preserve">void CMyViewContainer::ConstructL(const TRect&amp; aRect)
       
    24     {
       
    25     CreateWindowL();
       
    26 
       
    27     iLabel = new (ELeave) CEikLabel;
       
    28     iLabel-&gt;SetContainerWindowL( *this );
       
    29     iLabel-&gt;SetTextL( _L("MyView 1\n\nSelect local view\nswitching from menu") );
       
    30 
       
    31     SetRect(aRect);
       
    32     ActivateL();
       
    33     }</codeblock>
       
    34 <p>, where</p>
       
    35 <p><parmname>iLabel = new (ELeave) CEikLabel;</parmname> creates a <xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCEikLabel.html" format="application/java-archive"><parmname>CEikLabel</parmname></xref> object,
       
    36 which is a class that supports the display of text in the parent window.</p>
       
    37 <p><xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aSetContainerWindowL%28const%20CCoeControl%20%26amp%3b%29" format="application/java-archive"><parmname>CCoeControl::SetContainerWindowL</parmname></xref> assigns
       
    38 the non-window-owning control to the window-owning control</p>
       
    39 <p><xref href="jar:GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6.jar!/html/classCEikLabel.html#bcf1d51ebf4177465387f76584078f0c" format="application/java-archive"><parmname>CEikLabel::SetTextL</parmname></xref> sets a text for the label.</p>
       
    40 <p>The other methods are the standard methods for creating a window for
       
    41 the window-owning control.</p>
       
    42 </itemgroup>
       
    43 </li>
       
    44 <li><p>add a method to the owning control that returns the number
       
    45 of controls in the compound control. An example of an implementation is as
       
    46 follows:</p>
       
    47 <itemgroup>
       
    48 <codeblock id="GUID-048B5DCE-124A-4530-89AD-842DCA2F3FFC" xml:space="preserve">TInt CMyViewAppContainer::CountComponentControls() const
       
    49     {
       
    50     return KNumberOfControls; // return nbr of controls inside this compound control
       
    51     }</codeblock>
       
    52 <p>, where</p>
       
    53 <p><parmname>CMyViewAppContainer::CountComponentControls()</parmname> overrides <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aCountComponentControls%28%29const" format="application/java-archive"><parmname>CCoeControl::CountComponentControls</parmname></xref> to
       
    54 return the number of controls in the compound control.</p>
       
    55 <p><parmname>KNumberOfControls</parmname> is a <parmname>TInt</parmname> constant
       
    56 for the number of controls in the application. Other approaches could be used.</p>
       
    57 </itemgroup>
       
    58 </li>
       
    59 <li><p>Add a method to the owning control that returns each of the
       
    60 controls by a zero-based index. An example of an implementation is as follows:</p>
       
    61 <itemgroup>
       
    62 <codeblock id="GUID-3A8A5312-117E-466F-A5BC-6B7AF0A75B9C" xml:space="preserve">CCoeControl* CContainerContainer::ComponentControl(
       
    63     TInt aIndex)  const
       
    64     {
       
    65         switch ( aIndex )
       
    66         {
       
    67         case 0:
       
    68             return iLabel; // return a pointer to the 
       
    69                              //iLabel
       
    70         default:
       
    71             return NULL;
       
    72         }
       
    73     }
       
    74 </codeblock>
       
    75 <p>, where</p>
       
    76 <p><parmname>CCoeControl* CContainerContainer::ComponentControl(TInt aIndex)</parmname> gets
       
    77 an indexed component of a compound control.  There are 2 ways to implement
       
    78 a compound control. One way is to override this function. The other way is
       
    79 to use the <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlArrayClass.html#_top%20title=" format="application/java-archive"><parmname>CCoeControlArray</parmname></xref> functionality (see the <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aInitComponentArrayL%28%29" format="application/java-archive"><parmname>CCoeControl::InitComponentArrayL</parmname></xref> method).
       
    80  Note: within a compound control, each component control is identified by
       
    81 an index, where the index depends on the order the controls were added: the
       
    82 first is given an index of <parmname>0</parmname>, the next an index of <parmname>1</parmname>,
       
    83 and so on. </p>
       
    84 <p>All child controls should be accessible by <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aComponentControl%28TInt%29const" format="application/java-archive"><parmname>CCoeControl::ComponentControl</parmname></xref> at any time, regardless
       
    85 of whether they are visible or not. The visibility of a control should be
       
    86 adjusted using the <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aMakeVisible%28TBool%29" format="application/java-archive"><parmname>CCoeControl::MakeVisible</parmname></xref> method.</p>
       
    87 </itemgroup>
       
    88 </li>
       
    89 </ul>
       
    90 <p><parmname>CCoeControl* CContainerContainer::ComponentControl(TInt aIndex)</parmname> and <xref href="jar:GUID-35228542-8C95-4849-A73F-2B4F082F0C44.jar!/sdk/doc_source/reference/reference-cpp/Control_Environment/CCoeControlClass.html#%3a%3aCCoeControl%3a%3aCountComponentControls%28%29const" format="application/java-archive"><parmname>CCoeControl::CountComponentControls</parmname></xref> work
       
    91 in conjunction with each other. The Symbian platform can query the control
       
    92 as to how many components it has and then request a pointer to each of the
       
    93 component's controls. Controls can be added or removed at run time using these
       
    94 two methods. The framework uses this information to draw the container. </p>
       
    95 <p>The compound control usually owns the child controls and therefore it
       
    96 is responsible of their construction and destruction. The compound control
       
    97 should also set the positions and sizes of its child controls; it must ensure
       
    98 that all child controls are inside the compound control rectangle and visible
       
    99 child rectangles do not overlap each other.</p>
       
   100 </conbody></concept>