Symbian3/SDK/Source/GUID-97486385-88F7-4AF1-B880-D9A8AA4D7094.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-97486385-88F7-4AF1-B880-D9A8AA4D7094" xml:lang="en"><title>Compound
       
    13 controls in traditional 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-F5320B9F-2CC1-4190-B75A-AF303DC5EB8B" 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> makes
       
    38 the <xref href="GUID-352850A9-227F-45DB-8DCD-C6268954B4ED.dita">non-window-owning
       
    39 control</xref> a child of the window-owning control.</p>
       
    40 <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>
       
    41 <p>The other methods are the standard methods for creating a window for
       
    42 the window-owning control.</p>
       
    43 </itemgroup>
       
    44 </li>
       
    45 <li><p>add a method to the owning control that returns the number
       
    46 of controls in the compound control. An example of an implementation is as
       
    47 follows:</p>
       
    48 <itemgroup>
       
    49 <codeblock id="GUID-73DD2770-41FC-4B29-AA8A-4B9010654B64" xml:space="preserve">TInt CMyViewAppContainer::CountComponentControls() const
       
    50     {
       
    51     return KNumberOfControls; // return nbr of controls inside this compound control
       
    52     }</codeblock>
       
    53 <p>, where</p>
       
    54 <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
       
    55 return the number of controls in the compound control</p>
       
    56 <p><parmname>KNumberOfControls</parmname> is a <parmname>TInt</parmname> constant
       
    57 for the number of controls in the application. Other approaches could be used.</p>
       
    58 </itemgroup>
       
    59 </li>
       
    60 <li><p>Add a method to the owning control that returns each of the
       
    61 controls by a zero-based index. An example of an implementation is as follows:</p>
       
    62 <itemgroup>
       
    63 <codeblock id="GUID-14C8180C-9A7E-4CA8-A631-EB2A0179352C" xml:space="preserve">CCoeControl* CContainerContainer::ComponentControl(
       
    64     TInt aIndex)  const
       
    65     {
       
    66         switch ( aIndex )
       
    67         {
       
    68         case 0:
       
    69             return iLabel; // return a pointer to the 
       
    70                              //iLabel
       
    71         default:
       
    72             return NULL;
       
    73         }
       
    74     }
       
    75 </codeblock>
       
    76 <p>, where</p>
       
    77 <p><parmname>CCoeControl* CContainerContainer::ComponentControl(TInt aIndex)</parmname> gets
       
    78 an indexed component of a compound control.  There are two ways to implement
       
    79 a compound control. One way is to override this function. The other way is
       
    80 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).
       
    81  </p>
       
    82 <note>
       
    83 <p>Within a compound control, each component control is identified by an
       
    84 index. </p>
       
    85 </note>
       
    86 <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
       
    87 of whether they are visible or not. You can adjust the visibility of a control
       
    88 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>
       
    89 </itemgroup>
       
    90 </li>
       
    91 </ul>
       
    92 <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
       
    93 in conjunction with each other. The Symbian platform can query the control
       
    94 as to how many components it has and then request a pointer to each of the
       
    95 component's controls. Controls can be added or removed at run time using these
       
    96 two methods. The framework uses this information to draw the container. </p>
       
    97 <p>The compound control usually owns the child controls and therefore it
       
    98 is responsible of their construction and destruction. The compound control
       
    99 should also set the positions and sizes of its child controls; it must ensure
       
   100 that all child controls are inside the compound control rectangle and visible
       
   101 child rectangles do not overlap each other.</p>
       
   102 </conbody></concept>