11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
12 <concept id="GUID-1A26BD9E-5B8E-4E6D-904E-B8354B14E111" xml:lang="en"><title>Constructing |
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> |
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 |
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> |
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 |
16 <p>The following are the methods that you need to derive for the view derived |
17 view are as follows:</p> |
17 from <xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita"><apiname>CCoeControl</apiname></xref> :</p> |
18 <ul> |
18 <ul> |
19 <li><p>C++ default constructor, which cannot contain code that leaves. |
19 <li><p>Default constructor, which cannot contain code that leaves. |
20 A common implementation is:</p> |
20 A common implementation is:</p> |
21 <itemgroup> |
21 <itemgroup> |
22 <codeblock id="GUID-7A108F7C-AD2E-4CDA-9758-5FD6ED477917" xml:space="preserve"> |
22 <codeblock id="GUID-7A108F7C-AD2E-4CDA-9758-5FD6ED477917" xml:space="preserve"> |
23 CMyAppView* CMyAppView::NewL( const TRect& aRect ) |
23 CMyAppView* CMyAppView::NewL( const TRect& aRect ) |
24 { |
24 { |
37 |
37 |
38 CMyAppView::CMyAppView() |
38 CMyAppView::CMyAppView() |
39 { |
39 { |
40 // No implementation required |
40 // No implementation required |
41 }</codeblock> |
41 }</codeblock> |
42 <p>The declarations for <parmname>CMyAppView::NewL</parmname> and <parmname>CMyAppView::NewLC</parmname> in |
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 |
43 the class header file needs to be public to support the construction method |
44 required.</p> |
44 required.</p> |
45 <p>In this approach, <parmname>CMyAppView::NewL</parmname> is called from |
45 <p>In this approach, <parmname>CMyAppView::NewL()</parmname> is called |
46 the UI controller. It creates a view object by calling <parmname>CMyAppView::NewLC</parmname>. <parmname>CMyAppView::NewLC</parmname> calls |
46 from the UI controller. It creates a view object by calling <parmname>CMyAppView::NewLC()</parmname> to |
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 |
47 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. |
48 leaves, and then calls the second phase construction method of the object. |
50 When it returns to <parmname>CMyAppView::NewL</parmname>, the pointer pushed |
49 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> |
50 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> |
51 </itemgroup> |
53 </li> |
52 </li> |
54 <li><p>Symbian 2nd phase constructor with code that might leave. |
53 <li><p>Symbian second phase constructor with code that might leave. |
55 A common implementation is:</p> |
54 A common implementation is:</p> |
56 <itemgroup> |
55 <itemgroup> |
57 <codeblock id="GUID-32125111-6ACB-4539-8CD0-39ED5629789F" xml:space="preserve"> |
56 <codeblock id="GUID-32125111-6ACB-4539-8CD0-39ED5629789F" xml:space="preserve"> |
58 void CMyAppView::ConstructL( const TRect& aRect ) |
57 void CMyAppView::ConstructL( const TRect& aRect ) |
59 { |
58 { |
66 SetRect( aRect ); |
65 SetRect( aRect ); |
67 |
66 |
68 // Activate the window, which makes it ready to be drawn |
67 // Activate the window, which makes it ready to be drawn |
69 ActivateL(); |
68 ActivateL(); |
70 }</codeblock> |
69 }</codeblock> |
71 <p><parmname>CMyAppView::ConstructL</parmname> is a private class providing |
70 <p><parmname>CMyAppView</parmname> is a private class providing the second |
72 the second phase construction that accepts the rectangle the view is drawn |
71 phase construction that accepts the rectangle the view is drawn to.</p> |
73 to.</p> |
72 <p><xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-03CC715F-11D8-39B1-875D-F4589BC9681E"><apiname>CCoeControl::CreateWindowL()</apiname></xref> creates a window for |
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 |
73 the control. Note that this window is a child of the UI controller. This method |
75 for the control. Note that this window is a child of the UI controller. This |
74 makes the control a <xref href="GUID-352850A9-227F-45DB-8DCD-C6268954B4ED.dita">window-owning |
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 |
75 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 |
76 prevent the taxing of run-time resources, this is the top-level window for |
79 the UI controller.</p> |
77 the UI controller.</p> |
80 <p>While this is a simple control that does not contain other controls, |
78 <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, |
79 other controls could be added to the control between <xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-03CC715F-11D8-39B1-875D-F4589BC9681E"><apiname>CCoeControl::CreateWindowL()</apiname></xref> and <xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-AC806401-86C7-308A-9D18-39085CB8D877"><apiname>CCoeControl::SetRect(aRect)</apiname></xref>. For more information, see <xref href="GUID-57CA8A13-05C6-4AFE-9804-E2EA2453143A.dita">Compound |
82 see <xref href="GUID-57CA8A13-05C6-4AFE-9804-E2EA2453143A.dita">Compound |
|
83 controls in the view architecture</xref>.</p> |
80 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 |
81 <p><xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-AC806401-86C7-308A-9D18-39085CB8D877"><apiname>CCoeControl::SetRect(aRect)</apiname></xref> sets the window size |
85 size according to the requirements of the mobile device. The top-level control |
82 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. |
83 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 |
84 Calling <xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-AC806401-86C7-308A-9D18-39085CB8D877"><apiname>CCoeControl::SetRect(aRect)</apiname></xref> calls the <xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-9D6A2C52-DCE0-3490-BDA1-323406B7FBCF"><apiname>CCoeControl::SizeChanged()</apiname></xref> method, |
88 for any child controls and thus adjust the control layout to the UI.</p> |
85 where the control should set the position and size for any child controls |
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 |
86 and thus adjust the control layout to the UI.</p> |
90 as ready to be drawn.</p> |
87 <p><xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-C79D0B6F-C2D7-3F22-A62B-88762092E869"><apiname>CCoeControl::ActivateL()</apiname></xref> sets the control as ready |
|
88 to be drawn.</p> |
91 </itemgroup> |
89 </itemgroup> |
92 </li> |
90 </li> |
93 </ul> |
91 </ul> |
94 <p>If required for your application, you may need to implement other methods |
92 <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 |
93 for your control. For top-level windows, you would need to implement <xref href="GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160.dita#GUID-B06F99BD-F032-3B87-AB26-5DD6EBE8C160/GUID-9D6A2C52-DCE0-3490-BDA1-323406B7FBCF"><apiname>CCoeControl::SizeChanged()</apiname></xref> to |
96 changes to the size and position of the contents of this control. This is |
94 respond to changes to the size and position of the contents of this control. |
97 called by the Symbian platform when a change occurs. A typical implementation |
95 This is called by the Symbian platform when a change occurs. A typical implementation |
98 for a compound control is:</p> |
96 for a compound control is:</p> |
99 <codeblock id="GUID-6F100E69-F0BB-4637-A1AA-57024AF20CF4" xml:space="preserve">void CMyAppView::SizeChanged() |
97 <codeblock id="GUID-6F100E69-F0BB-4637-A1AA-57024AF20CF4" xml:space="preserve">void CMyAppView::SizeChanged() |
100 { |
98 { |
101 // Control resize code |
99 // Control resize code |
102 iControl->SetExtent( const TPoint &aPosition, const TSize &aSize); |
100 iControl->SetExtent( const TPoint &aPosition, const TSize &aSize); |