|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Methods for Common control container class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <CPbkControlContainer.h> |
|
22 #include <MPbkKeyEventHandler.h> |
|
23 |
|
24 |
|
25 /// Unnamed namespace for local definitions |
|
26 namespace { |
|
27 |
|
28 // MODULE DATA STRUCTURES |
|
29 |
|
30 #ifdef _DEBUG |
|
31 enum TPanicCode |
|
32 { |
|
33 EPanicPostCond_Constructor = 1, |
|
34 EPanicPreCond_ConstructL, |
|
35 EPanicPostCond_ConstructL, |
|
36 EPanicPostCond_DestroyControl, |
|
37 EPanicPreCond_SetCoeControlL, |
|
38 EPanicPostCond_SetCoeControlL, |
|
39 EPanicPreCond_ComponentControl, |
|
40 }; |
|
41 |
|
42 void Panic(TPanicCode aReason) |
|
43 { |
|
44 _LIT(KPanicText, "CPbkControlContainerImpl"); |
|
45 User::Panic(KPanicText,aReason); |
|
46 } |
|
47 #endif // _DEBUG |
|
48 |
|
49 } // namespace |
|
50 |
|
51 |
|
52 // ================= MEMBER FUNCTIONS ======================= |
|
53 |
|
54 EXPORT_C CPbkControlContainerImpl::CPbkControlContainerImpl |
|
55 (MPbkKeyEventHandler* aKeyEventHandler) : |
|
56 iKeyEventHandler(aKeyEventHandler) |
|
57 { |
|
58 SetComponentsToInheritVisibility(ETrue); |
|
59 __ASSERT_DEBUG(!iControl, Panic(EPanicPostCond_Constructor)); |
|
60 } |
|
61 |
|
62 EXPORT_C void CPbkControlContainerImpl::ConstructL(MObjectProvider& aProvider) |
|
63 { |
|
64 // PreCond |
|
65 __ASSERT_DEBUG(!iControl, Panic(EPanicPreCond_ConstructL)); |
|
66 |
|
67 SetMopParent(&aProvider); |
|
68 |
|
69 // Create a window, this is the top-level container control |
|
70 CreateWindowL(); |
|
71 |
|
72 // PostCond |
|
73 __ASSERT_DEBUG(!iControl && OwnsWindow(), Panic(EPanicPostCond_ConstructL)); |
|
74 } |
|
75 |
|
76 EXPORT_C void CPbkControlContainerImpl::DestroyControl() |
|
77 { |
|
78 if (iOwnsControl) |
|
79 { |
|
80 delete iControl; |
|
81 iControl = NULL; |
|
82 __ASSERT_DEBUG(!CoeControl(), Panic(EPanicPostCond_DestroyControl)); |
|
83 } |
|
84 } |
|
85 |
|
86 EXPORT_C CPbkControlContainerImpl::~CPbkControlContainerImpl() |
|
87 { |
|
88 if (iOwnsControl) |
|
89 { |
|
90 delete iControl; |
|
91 } |
|
92 } |
|
93 |
|
94 EXPORT_C CCoeControl* CPbkControlContainerImpl::CoeControl() const |
|
95 { |
|
96 return iControl; |
|
97 } |
|
98 |
|
99 EXPORT_C MPbkKeyEventHandler* CPbkControlContainerImpl::KeyEventHandler() const |
|
100 { |
|
101 return iKeyEventHandler; |
|
102 } |
|
103 |
|
104 EXPORT_C void CPbkControlContainerImpl::SetKeyEventHandler |
|
105 (MPbkKeyEventHandler* aKeyEventHandler) |
|
106 { |
|
107 iKeyEventHandler = aKeyEventHandler; |
|
108 } |
|
109 |
|
110 EXPORT_C void CPbkControlContainerImpl::SetHelpContext |
|
111 (const TCoeHelpContext& aContext) |
|
112 { |
|
113 iHelpContext = aContext; |
|
114 } |
|
115 |
|
116 EXPORT_C void CPbkControlContainerImpl::GetHelpContext |
|
117 (TCoeHelpContext& aContext) const |
|
118 { |
|
119 aContext = iHelpContext; |
|
120 } |
|
121 |
|
122 EXPORT_C void CPbkControlContainerImpl::SetCoeControl( |
|
123 CCoeControl* aControl, |
|
124 const TRect& aRect, |
|
125 TBool aOwnsControl/*=ETrue*/) |
|
126 { |
|
127 __ASSERT_DEBUG(OwnsWindow(), Panic(EPanicPreCond_SetCoeControlL)); |
|
128 |
|
129 // Set the control |
|
130 if (aControl != iControl) |
|
131 { |
|
132 if (iOwnsControl) |
|
133 { |
|
134 delete iControl; |
|
135 } |
|
136 iControl = aControl; |
|
137 } |
|
138 |
|
139 // Store ownership request |
|
140 iOwnsControl = aOwnsControl; |
|
141 |
|
142 // Set rectangle |
|
143 SetRect(aRect); |
|
144 |
|
145 __ASSERT_DEBUG(CoeControl()==aControl, Panic(EPanicPostCond_SetCoeControlL)); |
|
146 } |
|
147 |
|
148 EXPORT_C TKeyResponse CPbkControlContainerImpl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
149 { |
|
150 // Offer key event first to the key event handler |
|
151 if (iKeyEventHandler && iKeyEventHandler->PbkProcessKeyEventL(aKeyEvent,aType)) |
|
152 { |
|
153 return EKeyWasConsumed; |
|
154 } |
|
155 // Not consumed by the key handler, offer to the control next |
|
156 if (iControl) |
|
157 { |
|
158 return iControl->OfferKeyEventL(aKeyEvent, aType); |
|
159 } |
|
160 return EKeyWasNotConsumed; |
|
161 } |
|
162 |
|
163 EXPORT_C TInt CPbkControlContainerImpl::CountComponentControls() const |
|
164 { |
|
165 // iControl is the only subcontrol |
|
166 return iControl ? 1 : 0; |
|
167 } |
|
168 |
|
169 EXPORT_C CCoeControl* CPbkControlContainerImpl::ComponentControl(TInt aIndex) const |
|
170 { |
|
171 // PreCond: Assert that the control is assigned and aIndex is sensible |
|
172 __ASSERT_DEBUG(iControl && aIndex==0, Panic(EPanicPreCond_ComponentControl)); |
|
173 |
|
174 // Suppress the unreferenced variable warning |
|
175 (void) aIndex; |
|
176 |
|
177 // iControl is the only subcontrol |
|
178 return iControl; |
|
179 } |
|
180 |
|
181 EXPORT_C void CPbkControlContainerImpl::SizeChanged() |
|
182 { |
|
183 if (iControl) |
|
184 { |
|
185 // Set the control's rectangle to fill this container's rectangle |
|
186 iControl->SetRect(Rect()); |
|
187 } |
|
188 } |
|
189 |
|
190 EXPORT_C void CPbkControlContainerImpl::FocusChanged(TDrawNow aDrawNow) |
|
191 { |
|
192 if (iControl && !IsNonFocusing()) |
|
193 { |
|
194 iControl->SetFocus(IsFocused(), aDrawNow); |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 // End of File |