|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <coecntrl.h> |
|
17 #include <coecntss.h> |
|
18 #include <coeccntx.h> |
|
19 #include <coemain.h> |
|
20 #include <coeaui.h> |
|
21 #include "COETLS.H" |
|
22 #include "coepanic.h" |
|
23 #include <coeinput.h> |
|
24 #include <coedef.h> |
|
25 #include <coefontprovider.h> |
|
26 #include <coefont.h> |
|
27 #include <coelayoutman.h> |
|
28 #include <hal.h> |
|
29 #include "CoeDynamicStorage.inl" |
|
30 #include "coedefkeys.h" |
|
31 |
|
32 |
|
33 // |
|
34 // class CCoeControl |
|
35 // |
|
36 |
|
37 enum |
|
38 { |
|
39 ECoeCntrlUnused1 =0x00000001, |
|
40 EWindowIsSemiTransparent =0x00000002, // Indicated that the window has been set to make use of the alpha channel |
|
41 EOwnsWindow =0x00000004, // Signals that the control is window-owning |
|
42 EFocused =0x00000008, // Control has focus |
|
43 EActivated =0x00000010, // Control has been activated (thus ready to draw if visible) |
|
44 EInvisible =0x00000020, // Control is currently invisible |
|
45 EDimmed =0x00000040, // Control is currently dimmed (unavailable to the user) |
|
46 ESpareEnumReUseMe =0x00000080, // Was EGrabbed, now available for re-use |
|
47 EBackedUpWindow =0x00000100, // |
|
48 ENonFocusing =0x00000200, // |
|
49 EAllowStrayPointers =0x00000400, // Unless set, pointer up and drag events will be ignored unless |
|
50 // there's been a pointer down event in the control previously |
|
51 ECanDrawOutsideRect =0x00000800, // |
|
52 EBlank =0x00001000, // |
|
53 ECapturesPointer =0x00002000, // |
|
54 EIgnoresFirstExternalPointerUp =0x00004000, // For resolving problem with new windows being created on pointer down |
|
55 EIgnoresEventsUntilNextPointerUp =0x00008000, // For ignoring drag and up events after the user has pressed Esc |
|
56 EComponentsInheritVisibility =0x00010000, // |
|
57 EGloballyCapturing =0x00020000, // |
|
58 EIsBeingDestroyed =0x00040000, // |
|
59 EMemoryAllocationFailed =0x00080000, // |
|
60 ENotifyFocusObserversOnDestruction =0x00100000, // This flag is needed as if CCoeControl::SetFocus needs to call |
|
61 // CCoeControlExtension::SetFocusObserverNotificationIdentifier |
|
62 // but can't because it can't create the CCoeControlExtension object |
|
63 EReportControlStateChange =0x00200000 // This flag is used to control the ReportControlStateChange |
|
64 }; |
|
65 |
|
66 class CCoeControlStorage |
|
67 { |
|
68 public: |
|
69 inline CCoeControlStorage(); |
|
70 inline RCoeDynamicDataStorage& DynamicDataStorage(); |
|
71 inline const RCoeDynamicDataStorage& DynamicDataStorage() const; |
|
72 inline void Open(); |
|
73 inline void Close(); |
|
74 inline void AttemptCompress(); |
|
75 void SetPointerGrab(TUint aSet, TUint aClear); |
|
76 TUint8& PointerGrab(); |
|
77 |
|
78 private: |
|
79 RCoeDynamicDataStorage iDynamicDataStorage; |
|
80 TUint8 iPointerGrabFlags; // The grab-status of each of the supported pointers |
|
81 }; |
|
82 |
|
83 void CCoeControlStorage::SetPointerGrab(TUint aSet, TUint aClear) |
|
84 { |
|
85 ASSERT(aSet != aClear); |
|
86 |
|
87 iPointerGrabFlags &= ~aClear; |
|
88 iPointerGrabFlags |= aSet; |
|
89 } |
|
90 |
|
91 TUint8& CCoeControlStorage::PointerGrab() |
|
92 { |
|
93 return iPointerGrabFlags; |
|
94 } |
|
95 |
|
96 inline CCoeControlStorage::CCoeControlStorage() |
|
97 : iDynamicDataStorage(), iPointerGrabFlags(0) |
|
98 {} |
|
99 |
|
100 inline RCoeDynamicDataStorage& CCoeControlStorage::DynamicDataStorage() |
|
101 { return iDynamicDataStorage; } |
|
102 |
|
103 inline const RCoeDynamicDataStorage& CCoeControlStorage::DynamicDataStorage() const |
|
104 { return iDynamicDataStorage; } |
|
105 |
|
106 inline void CCoeControlStorage::Open() |
|
107 { iDynamicDataStorage.Open(); } |
|
108 |
|
109 inline void CCoeControlStorage::Close() |
|
110 { iDynamicDataStorage.Close(); } |
|
111 |
|
112 inline void CCoeControlStorage::AttemptCompress() |
|
113 { iDynamicDataStorage.AttemptCompress(); } |
|
114 |
|
115 EXPORT_C CCoeControl::CCoeControl() |
|
116 /** Default C++ constructor. |
|
117 |
|
118 Initialises the CCoeControl base class. |
|
119 |
|
120 Note: CCoeControl is normally used as a base class from which concrete |
|
121 control classes are derived. However, it can also be instantiated as a concrete |
|
122 class. */ |
|
123 { |
|
124 iCoeEnv = TheCoe(); |
|
125 |
|
126 iData = new CCoeControlStorage; // Non-leaving allocation |
|
127 if (iData) |
|
128 { |
|
129 iData->Open(); |
|
130 } |
|
131 else |
|
132 { |
|
133 iFlags |= EMemoryAllocationFailed; // Handle OOM later |
|
134 } |
|
135 |
|
136 SetFocusing(CCoeControlStaticSettings::FocusedByDefault(iCoeEnv)); |
|
137 } |
|
138 |
|
139 EXPORT_C CCoeControl::CCoeControl(CCoeEnv* aCoeEnv) |
|
140 /** C++ constructor. |
|
141 |
|
142 Initialises the CCoeControl base class. |
|
143 |
|
144 Note: CCoeControl is normally used as a base class from which concrete |
|
145 control classes are derived. However, it can also be instantiated as a concrete |
|
146 class. |
|
147 |
|
148 @param aCoeEnv The control environment.*/ |
|
149 { |
|
150 iCoeEnv = aCoeEnv; |
|
151 |
|
152 iData = new CCoeControlStorage; // Non-leaving allocation |
|
153 if(iData) |
|
154 iData->Open(); |
|
155 else |
|
156 iFlags |= EMemoryAllocationFailed; // Handle OOM later |
|
157 |
|
158 SetFocusing(CCoeControlStaticSettings::FocusedByDefault(iCoeEnv)); |
|
159 } |
|
160 |
|
161 EXPORT_C CCoeControl::~CCoeControl() |
|
162 /** Destructor. |
|
163 |
|
164 It destroys the window owned by the control, if it is a window-owning control. |
|
165 |
|
166 In debug builds, this checks if the control still exists |
|
167 on the control stack and raises a CONE 44 panic if it is. An application |
|
168 must remove every control that it has added to the stack. */ |
|
169 { |
|
170 #if defined(_DEBUG) |
|
171 CCoeAppUi* appUi=static_cast<CCoeAppUi*>(iCoeEnv->AppUi()); |
|
172 if (appUi && appUi->IsControlOnStack(this)) |
|
173 Panic(ECoePanicControlNotRemovedFromStack); |
|
174 #endif |
|
175 iFlags |= EIsBeingDestroyed; |
|
176 if ((iFlags&EFocused) || (iFlags&ENotifyFocusObserversOnDestruction) && iCoeEnv->FocusObserverNotificationIsStillPending(DoGetFocusObserverNotificationIdentifier(iData->DynamicDataStorage()))) |
|
177 iCoeEnv->NotifyFocusObserversOfDestructionOfFocusedItem(); |
|
178 |
|
179 // The CCoeControlArray d'tor calls delete on components |
|
180 // which are not owned externally. |
|
181 delete DoGetComponentArray(iData->DynamicDataStorage()); |
|
182 |
|
183 if (OwnsWindow()) |
|
184 CloseWindow(); |
|
185 |
|
186 MCoeLayoutManager* layoutMan = LayoutManager(); |
|
187 if (layoutMan) |
|
188 layoutMan->Detach(*this); |
|
189 |
|
190 delete DoGetColorOverrides(iData->DynamicDataStorage()); |
|
191 delete DoGetZoomWithType(iData->DynamicDataStorage()); |
|
192 |
|
193 if(iData) |
|
194 iData->Close(); |
|
195 delete iData; |
|
196 } |
|
197 |
|
198 /**@return ETrue if the component array exists, EFalse otherwise |
|
199 */ |
|
200 EXPORT_C TBool CCoeControl::ComponentArrayExists() const |
|
201 { |
|
202 CCoeControlArray* array = DoGetComponentArray(iData->DynamicDataStorage()); |
|
203 return (array != NULL); |
|
204 } |
|
205 |
|
206 |
|
207 |
|
208 EXPORT_C TBool CCoeControl::IsFocused() const |
|
209 /** Tests if the control has focus. |
|
210 |
|
211 Focus is set and unset using SetFocus(). |
|
212 |
|
213 @return ETrue if the control has focus, EFalse if it doesn't. */ |
|
214 { |
|
215 return (iFlags&EFocused); |
|
216 } |
|
217 |
|
218 EXPORT_C TBool CCoeControl::IsVisible() const |
|
219 /** Tests if the control is visible. |
|
220 |
|
221 Unless MakeVisible() has been called with argument EFalse, the control is |
|
222 visible. |
|
223 |
|
224 @return ETrue if the control is visible, EFalse if it is invisible. */ |
|
225 { |
|
226 return (!(iFlags&EInvisible)); |
|
227 } |
|
228 |
|
229 EXPORT_C TBool CCoeControl::IsDimmed() const |
|
230 /** Tests if the control is dimmed. |
|
231 |
|
232 This function returns the value of a flag within the control which is set |
|
233 and unset using SetDimmed(). |
|
234 |
|
235 @return ETrue if the control is dimmed, EFalse if it is not dimmed. */ |
|
236 { |
|
237 return (iFlags&EDimmed); |
|
238 } |
|
239 |
|
240 EXPORT_C RDrawableWindow* CCoeControl::DrawableWindow() const |
|
241 /** Gets the control's associated drawable window. |
|
242 |
|
243 The control must be a window-owning control. |
|
244 |
|
245 This function should be called if it is not known whether the window is of |
|
246 type RWindow or RBackedUpWindow. RDrawableWindow is an abstract base class |
|
247 from which RWindow and RBackedUpWindow are derived. |
|
248 |
|
249 @return The control's associated window. |
|
250 @see Window() */ |
|
251 { |
|
252 return iWin; |
|
253 } |
|
254 |
|
255 EXPORT_C TSize CCoeControl::Size() const |
|
256 /** Gets the control's size. |
|
257 |
|
258 @return The control's size, in pixels. */ |
|
259 { |
|
260 return iSize; |
|
261 } |
|
262 |
|
263 |
|
264 EXPORT_C TInt CCoeControl::MaximumWidth() const |
|
265 /** Gets the control's maximum width |
|
266 |
|
267 @return The controls maximum width. (0 if no value set). */ |
|
268 { |
|
269 // Try to retrieve a maximum width value if one has been set, otherwise return zero. |
|
270 return DoGetMaximumWidth(iData->DynamicDataStorage()); |
|
271 } |
|
272 |
|
273 |
|
274 EXPORT_C TPoint CCoeControl::Position() const |
|
275 /** Gets the control's position. |
|
276 |
|
277 @return The position of the control, relative to its associated window. */ |
|
278 { |
|
279 return iPosition; |
|
280 } |
|
281 |
|
282 EXPORT_C TPoint CCoeControl::PositionRelativeToScreen() const |
|
283 /** Gets the control's position relative to screen origin. |
|
284 |
|
285 The screen origin is its top-left corner. |
|
286 |
|
287 @return The position of the control, measured in pixels, relative to the screen |
|
288 origin. */ |
|
289 { |
|
290 TPoint ret=iWin->InquireOffset(iCoeEnv->RootWin()); |
|
291 if (!OwnsWindow()) |
|
292 ret+=iPosition; |
|
293 |
|
294 return ret; |
|
295 } |
|
296 |
|
297 EXPORT_C void CCoeControl::SetObserver(MCoeControlObserver* aObserver) |
|
298 /** Sets the control's observer. |
|
299 |
|
300 @param aObserver The observer. */ |
|
301 { |
|
302 if(DoSetObserver(iData->DynamicDataStorage(), aObserver) == KErrNoMemory) |
|
303 iFlags |= EMemoryAllocationFailed; |
|
304 } |
|
305 |
|
306 EXPORT_C MCoeControlObserver* CCoeControl::Observer() const |
|
307 /** Gets the control's observer. |
|
308 |
|
309 @return The control's observer. */ |
|
310 { |
|
311 return DoGetObserver(iData->DynamicDataStorage()); |
|
312 } |
|
313 |
|
314 EXPORT_C TBool CCoeControl::IsReadyToDraw() const |
|
315 /** Tests if the control is ready for drawing. |
|
316 |
|
317 This returns true if the control has been activated and is visible. |
|
318 |
|
319 @return ETrue if the control is ready for drawing, EFalse if it is not ready |
|
320 for drawing. */ |
|
321 { |
|
322 return ((iFlags&(EInvisible|EActivated))==(EActivated)) || (iFlags&EBackedUpWindow); |
|
323 } |
|
324 |
|
325 EXPORT_C TBool CCoeControl::OwnsWindow() const |
|
326 /** Tests if the control is window-owning. |
|
327 |
|
328 @return ETrue if the control is window-owning. EFalse if the control is non-window-owning. */ |
|
329 { |
|
330 return (iFlags&EOwnsWindow); |
|
331 } |
|
332 |
|
333 EXPORT_C TBool CCoeControl::IsBackedUp() const |
|
334 /** Tests if the window owned by the control is a backed-up window. |
|
335 |
|
336 @return ETrue if the window owned by this control is a backed-up window. EFalse |
|
337 if it is not a backed-up window. |
|
338 @deprecated |
|
339 */ |
|
340 { |
|
341 return (iFlags&EBackedUpWindow); |
|
342 } |
|
343 |
|
344 EXPORT_C TBool CCoeControl::IsActivated() const |
|
345 /** Tests if the control has been activated. |
|
346 |
|
347 A control is not ready to draw until it is activated. |
|
348 |
|
349 @return ETrue if the control is activated, EFalse if it is not activated. */ |
|
350 { |
|
351 return (iFlags&EActivated); |
|
352 } |
|
353 |
|
354 EXPORT_C TBool CCoeControl::IsBlank() const |
|
355 /** Tests if the control is blank. |
|
356 |
|
357 This simply gets the value of the flag set by SetBlank(). |
|
358 |
|
359 @return ETrue if SetBlank() has been called on the control. EFalse if SetBank() |
|
360 has not been called on the control. */ |
|
361 { |
|
362 return (iFlags&EBlank); |
|
363 } |
|
364 |
|
365 EXPORT_C TBool CCoeControl::IsBeingDestroyed() const |
|
366 /** Tests if the control is being destroyed. |
|
367 |
|
368 @return ETrue if the control is being destroyed, otherwise EFalse. */ |
|
369 { |
|
370 return (iFlags&EIsBeingDestroyed); |
|
371 } |
|
372 |
|
373 /** |
|
374 @param aPointerNumber The pointer number. Defaulted to zero in the declaration. |
|
375 */ |
|
376 TBool CCoeControl::IsGrabbed(TInt aPointerNumber) const |
|
377 { |
|
378 ASSERT( ((aPointerNumber < KConeMaxSupportedPointers) && (aPointerNumber >= 0)) ); |
|
379 |
|
380 return ( iData->PointerGrab() & (1 << aPointerNumber) ); |
|
381 } |
|
382 |
|
383 EXPORT_C TKeyResponse CCoeControl::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/) |
|
384 /** Handles key events. |
|
385 |
|
386 If a control wishes to process key events, it should implement this function. |
|
387 The implementation must ensure that the function returns EKeyWasNotConsumed |
|
388 if it does not do anything in response to a key event, otherwise, other |
|
389 controls or dialogs may be prevented from receiving the key event. If it is |
|
390 able to process the event it should return EKeyWasConsumed. |
|
391 |
|
392 When a key event occurs, the control framework calls this function for each |
|
393 control on the control stack, until one of them can process the key event |
|
394 (and returns EKeyWasConsumed). |
|
395 |
|
396 Each keyboard key press results in three separate events: EEventKeyDown, EEventKey, |
|
397 and EEventKeyUp, in that order. |
|
398 |
|
399 To receive key events, which can be processed by this function, the application |
|
400 should call CCoeAppUi::AddToStackL() to add the control to the stack. This |
|
401 only applies, however, to controls which are not components of a compound |
|
402 control. Compound controls should pass key events to their components as necessary: |
|
403 the components themselves do not go on the stack. |
|
404 |
|
405 Classes that override CCoeControl::OfferKeyEventL() should also override the |
|
406 InputCapabilities() virtual function, returning a TCoeInputCapabilities object |
|
407 whose attributes correspond to the behaviour of the OfferKeyEventL() function. |
|
408 Note that it is not necessary to call InputCapabilities() on any component |
|
409 controls from inside a class' InputCapabilities() function. This is done |
|
410 automatically by the UI Control Framework. |
|
411 |
|
412 If overriding OfferKeyEventL(), the implementation must include a base call to CCoeControl's |
|
413 OfferKeyEventL(). |
|
414 |
|
415 @param aKeyEvent The key event. |
|
416 @param aType The type of key event: EEventKey, EEventKeyUp or EEventKeyDown. |
|
417 @return Indicates whether or not the key event was used by this control. */ |
|
418 { |
|
419 return(EKeyWasNotConsumed); |
|
420 } |
|
421 |
|
422 void CCoeControl::ProcessPointerBufferReadyL() |
|
423 { |
|
424 CCoeControl* destination=NULL; |
|
425 for (TInt i=0; i<CountComponentControls(); i++) |
|
426 { |
|
427 CCoeControl* ctrl=ComponentControl(i); |
|
428 if (ctrl->IsGrabbed() && !(ctrl->OwnsWindow())) |
|
429 destination=ctrl; |
|
430 } |
|
431 if (destination) |
|
432 destination->ProcessPointerBufferReadyL(); |
|
433 else |
|
434 HandlePointerBufferReadyL(); |
|
435 } |
|
436 |
|
437 EXPORT_C void CCoeControl::HandlePointerBufferReadyL() |
|
438 /** Handles pointer buffer ready events. |
|
439 |
|
440 This function is called whenever the control receives an event of type EEventPointerBufferReady, |
|
441 unless one of its component controls has grabbed the pointer, in which case |
|
442 the function is called on that control. An event of type EEventPointerBufferReady |
|
443 will only be received if the pointer move buffer has been set up using window |
|
444 server functions. |
|
445 |
|
446 The pointer move buffer is typically used when the application requires a |
|
447 continuous stream of pointer drag events, such as in a drawing application. |
|
448 |
|
449 @see RWindowBase::AllocPointerMoveBuffer() */ |
|
450 { |
|
451 } |
|
452 |
|
453 EXPORT_C void CCoeControl::ClaimPointerGrab(TBool aSendUpEvent) |
|
454 /** Claims the pointer-grab from another control. |
|
455 |
|
456 This ensures that all subsequent pointer events are delivered to it and not |
|
457 to the control that originally owned the grab. |
|
458 |
|
459 The function allows a control to claim the pointer grab only if the pointer |
|
460 is already grabbed by another control. |
|
461 |
|
462 This method is to be used in systems implementing single-pointer events. Or in systems |
|
463 implementing multiple-pointer events but where this control's window has single-pointer |
|
464 emulation enabled. |
|
465 |
|
466 @param aSendUpEvent Passed as the argument to RWindowBase::ClaimPointerGrab(). |
|
467 @see RWindowBase::ClaimPointerGrab() */ |
|
468 { |
|
469 iFlags |= EAllowStrayPointers|EIgnoresFirstExternalPointerUp; // EIgnoresFirstExternalPointerUp reset in ProcessPointerEventL() |
|
470 iWin->SetPointerGrab(ETrue); |
|
471 iWin->ClaimPointerGrab(aSendUpEvent); |
|
472 |
|
473 ControlClaimPointerGrab(TAdvancedPointerEvent::EDefaultPointerNumber); |
|
474 } |
|
475 |
|
476 EXPORT_C TInt CCoeControl::ClaimPointerGrab( TInt aPointerNumber, TBool aSendUpEvent ) |
|
477 /** Claims pointer grab from another control. |
|
478 |
|
479 This ensures that all subsequent pointer events of the specified pointer are delivered |
|
480 to it and not to the control that originally owned the grab. |
|
481 |
|
482 The function allows a control to claim the pointer grab only if the pointer |
|
483 is already grabbed by another control. |
|
484 |
|
485 This method is intended to be called on a control who's window implements multi-pointer events. |
|
486 If called on a window without multiple pointers enabled, wserv will ignore the pointer |
|
487 number and grab the emulated pointer. |
|
488 |
|
489 @param aSendUpEvent Passed as the argument to RWindowBase::ClaimPointerGrab(). |
|
490 @param aPointerNumber The number of the pointer for which to claim the grab. |
|
491 @return KErrNone if successful, KErrNotFound if pointer number out of range (Panics in debug build), or KErrNotSupported if incorrect pointer grab claimed for window in emulation mode. |
|
492 @see RWindowBase::ClaimPointerGrab() |
|
493 @see RWindowBase::EnableMMultiplePointers() */ |
|
494 { |
|
495 __ASSERT_DEBUG( ((aPointerNumber < ControlEnv()->SupportedPointers()) && (aPointerNumber >= 0)), Panic(ECoePanicNoSuchNumberedPointer) ); |
|
496 |
|
497 iFlags |= EAllowStrayPointers|EIgnoresFirstExternalPointerUp; // EIgnoresFirstExternalPointerUp reset in ProcessPointerEventL() |
|
498 iWin->SetPointerGrab(ETrue); |
|
499 TInt errNo = iWin->ClaimPointerGrab(aPointerNumber, aSendUpEvent); |
|
500 if(KErrNone == errNo) |
|
501 { |
|
502 ControlClaimPointerGrab(aPointerNumber); |
|
503 } |
|
504 return errNo; |
|
505 } |
|
506 |
|
507 void CCoeControl::ControlClaimPointerGrab(TInt aPointerNumber) |
|
508 { |
|
509 // Without this code, claiming pointer grab only work between |
|
510 // window owning controls, not between controls in the same window |
|
511 const CCoeControl* parent = WindowOwningParent(); |
|
512 |
|
513 if(parent) |
|
514 { |
|
515 CCoeControl* ctrl = parent->GrabbingComponent( aPointerNumber ); |
|
516 |
|
517 if(ctrl) |
|
518 { |
|
519 ctrl->SetGrabbed(EFalse, aPointerNumber); |
|
520 } |
|
521 } |
|
522 |
|
523 SetGrabbed(ETrue, aPointerNumber); |
|
524 } |
|
525 |
|
526 EXPORT_C void CCoeControl::IgnoreEventsUntilNextPointerUp() |
|
527 /** Sets the control to ignore pointer events until the next pointer up. |
|
528 |
|
529 This means that all events until and including the next pointer up event are |
|
530 discarded and are not processed. |
|
531 |
|
532 This can be used for example if the user presses the Esc key while selecting |
|
533 text by dragging the pointer device to ensure that further dragging does not |
|
534 result in continued selection. |
|
535 */ |
|
536 { |
|
537 iFlags|=EIgnoresEventsUntilNextPointerUp; |
|
538 } |
|
539 |
|
540 void CCoeControl::ProcessPointerEventL(const TPointerEvent& aPointerEvent) |
|
541 { |
|
542 TBool requiresFocus = EFalse; |
|
543 TInt pointerNumber = TAdvancedPointerEvent::EDefaultPointerNumber; |
|
544 |
|
545 if (aPointerEvent.IsAdvancedPointerEvent()) |
|
546 { |
|
547 User::LeaveIfError(ValidateAdvancedPointerNumber(aPointerEvent)); |
|
548 pointerNumber = aPointerEvent.AdvancedPointerEvent()->PointerNumber(); |
|
549 } |
|
550 |
|
551 if (aPointerEvent.iType==TPointerEvent::EButton1Down) |
|
552 { |
|
553 // If this is a window owning control with a hit-test object attached.... |
|
554 if(OwnsWindow()) |
|
555 { |
|
556 // ...then if the hit-test fails, try passing the event up to the next level... |
|
557 const MCoeControlHitTest* hitTest = HitTest(); |
|
558 if(hitTest && !hitTest->HitRegionContains(aPointerEvent.iPosition, *this)) |
|
559 { |
|
560 // ...i.e. up to the next window owning parent, thus allowing even window owning controls |
|
561 // to be transparent to pointer events. |
|
562 CCoeControl* windowOwningParent = Parent()->WindowOwningParent(); // safe even if not parent exists |
|
563 if(windowOwningParent) |
|
564 { |
|
565 windowOwningParent->ProcessPointerEventL(aPointerEvent); |
|
566 return; // Don't continue in this part of the control tree |
|
567 } |
|
568 } |
|
569 } |
|
570 |
|
571 SetGrabbed(EFalse, pointerNumber); // Reset the grabbing |
|
572 if (!IsVisible()) |
|
573 return; |
|
574 |
|
575 if (IsDimmed()) |
|
576 { |
|
577 ReportEventL(MCoeControlObserver::EEventInteractionRefused); |
|
578 return; |
|
579 } |
|
580 |
|
581 // If the control does not aleady have focus (but can take focus) |
|
582 // then generate a prepare-focus-transition event now, and a |
|
583 // request-focus event once the pointer event has been handled |
|
584 // (see end of this function) |
|
585 if (!IsFocused() && !IsNonFocusing()) |
|
586 { |
|
587 ReportEventL(MCoeControlObserver::EEventPrepareFocusTransition); |
|
588 requiresFocus = ETrue; |
|
589 } |
|
590 |
|
591 SetGrabbed(ETrue, pointerNumber); // Set the control grabbing any further pointer events. |
|
592 // This ensures that the control that got the pointer down also gets the |
|
593 // pointer up event (and any drag events). |
|
594 } |
|
595 else // Mainly EButton1Up or EDrag. Other events will be ignored unless stray events are allowed (see below) |
|
596 { |
|
597 if ( IsGrabbed(pointerNumber) ) // If there's been a EButton1Down event... |
|
598 { |
|
599 if (aPointerEvent.iType==TPointerEvent::EButton1Up) // ...and this is the matching EButton1Up event... |
|
600 SetGrabbed(EFalse, pointerNumber); // ...then terminate the grabbing state. |
|
601 } |
|
602 else // If no EButton1Down event has been recorded; then either this is it, or it's a stray event. |
|
603 { |
|
604 if ( !(iFlags&EAllowStrayPointers) && !(aPointerEvent.iModifiers & EModifierAdvancedPointerEvent) ) |
|
605 return; // Ignore stray events unless explicitly allowed |
|
606 |
|
607 //mm something's fishy here... |
|
608 // The code that follows intends to resolve the problem that occurs when a pointer tap |
|
609 // (down-up event) on a menu item results in a sub-menu being opened and that sub-menu |
|
610 // appears "under" the pointer. In these cases the up-event must not invoke the menu item |
|
611 // in the sub-menu that happens to be located at the coordinate of the event. |
|
612 |
|
613 // If the pointer grab has been claimed (by calling ClaimPointerGrab()) |
|
614 if (iFlags&EIgnoresFirstExternalPointerUp) |
|
615 { |
|
616 // If the pointer event occured inside this control (and not in the "sub-menu")... |
|
617 if (Rect().Contains(aPointerEvent.iPosition)) |
|
618 iFlags &= ~EIgnoresFirstExternalPointerUp; // ...then no need to ignore the pointer up event. |
|
619 else |
|
620 { |
|
621 if (aPointerEvent.iType==TPointerEvent::EButton1Up) // If the event was the pointer-up... |
|
622 iFlags &= ~EIgnoresFirstExternalPointerUp; // ...then reset the flag... |
|
623 |
|
624 return; // ...and ignore the event. |
|
625 } |
|
626 } |
|
627 } |
|
628 } |
|
629 |
|
630 // If flag is set, ignore all pointer events until the next pointer up. |
|
631 // See doxygen comments for IgnoreEventsUntilNextPointerUp(). |
|
632 if (iFlags&EIgnoresEventsUntilNextPointerUp) |
|
633 { |
|
634 if (aPointerEvent.iType==TPointerEvent::EButton1Up) // Reset the flag on the first pointer up |
|
635 iFlags&=(~EIgnoresEventsUntilNextPointerUp); |
|
636 |
|
637 return; // Ignore the event |
|
638 } |
|
639 |
|
640 HandlePointerEventL(aPointerEvent); |
|
641 |
|
642 // If there was a pointer down event on a non-focused control, then generate a request-focus event. |
|
643 if (requiresFocus) |
|
644 ReportEventL(MCoeControlObserver::EEventRequestFocus); |
|
645 } |
|
646 |
|
647 |
|
648 /** Handles pointer events. |
|
649 |
|
650 This function gets called whenever a pointer event occurs in the control, |
|
651 i.e. when the pointer is within the control's extent, or when the control has |
|
652 grabbed the pointer. The control should implement this function to handle |
|
653 pointer events. |
|
654 |
|
655 Note: events of type EButton1Down are processed before HandlePointerEventL() is |
|
656 called, in order to transfer keyboard focus to the control in which the EButton1Down |
|
657 event occurred. |
|
658 |
|
659 If overriding HandlePointerEventL(), the implementation must include a base call to CCoeControl's |
|
660 HandlePointerEventL(). |
|
661 |
|
662 The TPointerEvent& parameter aPointerEvent can be safely transformed into a TAdvancedPointerEvent |
|
663 at all times by deploying the following code:- |
|
664 |
|
665 const TAdvancedPointerEvent* advancedPointerEvent = aPointerEvent.AdvancedPointerEvent(); |
|
666 @see TPointerEvent |
|
667 @see TAdvancedPointerEvent |
|
668 |
|
669 The TAdvancedPointerEvent methods supply safe and meaningful values even in systems not |
|
670 implementing advanced pointers. |
|
671 |
|
672 @param aPointerEvent The pointer event. */ |
|
673 EXPORT_C void CCoeControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
674 { |
|
675 // The code below will traverse down the control hierarchy, effectively offer the pointer |
|
676 // event to all controls intersecting the pointer event coordinate, from the window-owning |
|
677 // parent down to the furthest child node. |
|
678 |
|
679 // Offers the pointer down (and move) events to component controls in the order from the window-owning |
|
680 // parent and down throught the control tree. Other events always go the the control that got the down event. |
|
681 CCoeControl* pointerRecipient = NULL; |
|
682 if (aPointerEvent.iType==TPointerEvent::EButton1Down |
|
683 || aPointerEvent.iType==TPointerEvent::EMove |
|
684 || aPointerEvent.iType==TPointerEvent::EEnterCloseProximity |
|
685 || aPointerEvent.iType==TPointerEvent::EExitCloseProximity |
|
686 || aPointerEvent.iType==TPointerEvent::EOutOfRange) |
|
687 { |
|
688 // For all children... |
|
689 const TInt count = CountComponentControls(); |
|
690 for (TInt ii=count-1; ii>=0; ii--) |
|
691 { |
|
692 CCoeControl* ctrl = ComponentControl(ii); |
|
693 // ...ignoring any window-owning children (as they would have got the event directly from the WServ |
|
694 // if they intersect the pointer coordinate) and any invisible children... |
|
695 if (ctrl->OwnsWindow() || !(ctrl->IsVisible())) |
|
696 continue; |
|
697 |
|
698 // ...if the child intersects the pointer coordinate... |
|
699 if(ctrl->Rect().Contains(aPointerEvent.iPosition)) |
|
700 { |
|
701 // ...check if the child has a hit-test object attached, and if it has then only progress down |
|
702 // its branch if the test succeeded (this way controls that are partly transparent won't react |
|
703 // to pointer events outside their visible area)... |
|
704 const MCoeControlHitTest* childHitTest = ctrl->HitTest(); |
|
705 if(childHitTest && !childHitTest->HitRegionContains(aPointerEvent.iPosition, *ctrl)) // If the test failed... |
|
706 continue; // ...then offer the event to next sibling (two partly transparent siblings may overlap!) |
|
707 |
|
708 pointerRecipient = ctrl; |
|
709 break; |
|
710 } |
|
711 } |
|
712 } |
|
713 else |
|
714 { |
|
715 // Always offer all events except down- and move-events to the grabbing control (that got the original down event) |
|
716 TInt pointerNum = aPointerEvent.IsAdvancedPointerEvent() ? aPointerEvent.AdvancedPointerEvent()->PointerNumber() : TAdvancedPointerEvent::EDefaultPointerNumber; |
|
717 pointerRecipient = GrabbingComponent(pointerNum); |
|
718 } |
|
719 |
|
720 // Pass the pointer event on to the child found to intersect the pointer event coordintate |
|
721 // (or that got the original pointer down event) |
|
722 if (pointerRecipient) |
|
723 pointerRecipient->ProcessPointerEventL(aPointerEvent); |
|
724 } |
|
725 |
|
726 EXPORT_C void CCoeControl::ReportEventL(MCoeControlObserver::TCoeEvent aEvent) |
|
727 /** Sends an event to the control's observer (if the control has one). |
|
728 |
|
729 @param aEvent The event type. */ |
|
730 { |
|
731 MCoeControlObserver* observer = DoGetObserver(iData->DynamicDataStorage()); |
|
732 if (observer) |
|
733 observer->HandleControlEventL(this,aEvent); |
|
734 } |
|
735 |
|
736 EXPORT_C void CCoeControl::PrepareForFocusLossL() |
|
737 /** Prepares the control for loss of focus. |
|
738 |
|
739 A control which is displayed within a dialog should implement this function |
|
740 if it wishes to validate data entered into the control. |
|
741 |
|
742 This function is called by the dialog framework immediately before it removes |
|
743 keyboard focus from a control within a dialog. It is intended to be used for |
|
744 validating the state of the control: for example, if the control allows the |
|
745 user to enter a date, PrepareForFocusLossL() would normally check to make |
|
746 sure the user did not enter an invalid date such as February 31st. If an invalid |
|
747 state is detected, PrepareForFocusLossL() should leave and issue a message |
|
748 to the user if appropriate. If it does leave, the framework does not perform |
|
749 the action that would have resulted in the control losing focus, and focus |
|
750 remains with the control to allow valid data to be entered. |
|
751 |
|
752 In standard GUI dialogs, various actions can result in a control losing focus, |
|
753 for instance if the user presses the OK button or the Enter key to close the dialog |
|
754 and enter the information, or if the user navigates away from |
|
755 the focussed control. These actions result in PrepareForFocusLossL() being |
|
756 called on the control that currently has keyboard focus. |
|
757 |
|
758 The default implementation of this function is empty, and it is not called |
|
759 from within the UI control framework. The function exists only to provide |
|
760 an interface to the control, for the GUI and any other UI library. */ |
|
761 { |
|
762 } |
|
763 |
|
764 EXPORT_C void CCoeControl::PrepareForFocusGainL() |
|
765 /** Prepares the control for gaining focus. |
|
766 |
|
767 Implementations may by taking any action required, such as updating control |
|
768 information. The default implementation is empty. */ |
|
769 { |
|
770 } |
|
771 |
|
772 EXPORT_C void CCoeControl::SetAdjacent(TInt /*aAdjacent*/) |
|
773 /** Sets the control's appearance when it is next to other controls. |
|
774 |
|
775 Its intended use is to remove the double border that may occur if two controls, |
|
776 both with borders, are adjacent within a container control. |
|
777 |
|
778 This function has an empty default implementation, and is not used within |
|
779 the UI control framework. However, it may be implemented and used by derived |
|
780 control classes. |
|
781 |
|
782 @param aAdjacent Typically a value defined in TGulAdjacent. */ |
|
783 { |
|
784 } |
|
785 |
|
786 EXPORT_C void CCoeControl::SetNeighbor(CCoeControl* /*aNeighbor*/) |
|
787 /** Sets an associated control. |
|
788 |
|
789 This can be used to establish co-ordinated groups of controls for instance in dialogs |
|
790 without specific application co-operation. |
|
791 |
|
792 This function has an empty default implementation, and is not used within |
|
793 the UI control framework. However, it may be implemented and used by derived |
|
794 control classes. |
|
795 |
|
796 @param aNeighbor A control to be used by this function. */ |
|
797 { |
|
798 } |
|
799 |
|
800 EXPORT_C TBool CCoeControl::HasBorder() const |
|
801 /** Tests if the control has a border. |
|
802 |
|
803 When component controls are arranged in a container, the container control |
|
804 may need to know whether or not the components have borders, as this may affect |
|
805 the way the components are laid out within the container. |
|
806 |
|
807 The default implementation of this function returns EFalse, but can |
|
808 be overridden to provide the required functionality. |
|
809 |
|
810 @return ETrue if the control has a border, EFalse if the control does not |
|
811 have a border. The default implementation of this function returns |
|
812 EFalse. */ |
|
813 { |
|
814 return EFalse; |
|
815 } |
|
816 |
|
817 EXPORT_C TSize CCoeControl::MinimumSize() |
|
818 /** Sets the control's minimum required size. |
|
819 |
|
820 This function should be overridden by the concrete control class if the control |
|
821 is to be displayed inside a dialog. Standard GUI dialogs set the size and |
|
822 position of their components automatically, and use this function to enquire |
|
823 the minimum size that a control requires. |
|
824 |
|
825 Other container controls that automatically calculate the layout of their |
|
826 components may also use this function. |
|
827 |
|
828 @return The minimum size required by the control. */ |
|
829 { |
|
830 // designed to be overridden |
|
831 MCoeLayoutManager* layoutManager = LayoutManager(); |
|
832 if (layoutManager) |
|
833 { |
|
834 return layoutManager->CalcMinimumSize(*this); |
|
835 } |
|
836 |
|
837 return(iSize); |
|
838 } |
|
839 |
|
840 |
|
841 EXPORT_C void CCoeControl::HandleComponentControlsResourceChange(TInt aType) |
|
842 /** Handles a change to the resources in the components of a compound control. |
|
843 |
|
844 @param aType A message UID value. |
|
845 @see HandleResourceChange() */ |
|
846 { |
|
847 const TInt count=CountComponentControls(); |
|
848 for(TInt ii=0;ii<count;ii++) |
|
849 { |
|
850 CCoeControl* control = ComponentControl(ii); |
|
851 if (control && control->iWin) |
|
852 { |
|
853 control->HandleResourceChange(aType); |
|
854 } |
|
855 } |
|
856 } |
|
857 |
|
858 /** Sets a pointer to a MCoeControlBackground object that is responsible for |
|
859 drawing the control's background |
|
860 |
|
861 @param aBackground Pointer to an object that implements MCoeControlBackground |
|
862 @see CCoeControl::EnableWindowTransparency() |
|
863 @publishedAll |
|
864 @released |
|
865 */ |
|
866 EXPORT_C void CCoeControl::SetBackground(const MCoeControlBackground* aBackground) |
|
867 { |
|
868 if(DoSetBackground(iData->DynamicDataStorage(), aBackground) == KErrNoMemory) |
|
869 iFlags |= EMemoryAllocationFailed; |
|
870 } |
|
871 |
|
872 /** |
|
873 By default, all windows are opaque. This means that semi-transparent drawing |
|
874 performed into the window will blend with other content of that window, but not |
|
875 with the content of the window(s) behind. This acts as an important performance |
|
876 optimization, limiting the amount of drawing needed to update the screen. |
|
877 |
|
878 Call this method to allow semi-transparent drawing into the window to be blended |
|
879 with the content of the windows behind. (Because of the performance implications, |
|
880 be careful not to enable window transparency unless really required.) |
|
881 |
|
882 This will set the window to use the alpha channel information of the drawing |
|
883 performed into it, and set the initialize window background to fully transparent |
|
884 (before any drawing is made into it). |
|
885 |
|
886 Note that although the same effect can be achieved by calling the RWindow methods |
|
887 directly, calling this method instead will allow correct drawing of semi-transparent |
|
888 control backgrounds (see MCoeControlBackground). |
|
889 |
|
890 This method must only be called on (non-BackedUp) window owning controls. |
|
891 |
|
892 @see MCoeControlBackground |
|
893 @publishedAll |
|
894 */ |
|
895 |
|
896 EXPORT_C void CCoeControl::EnableWindowTransparency() |
|
897 { |
|
898 __ASSERT_DEBUG(OwnsWindow(), Panic(ECoePanicControlNotWindowOwning)); |
|
899 __ASSERT_DEBUG(!(iFlags&EBackedUpWindow), Panic(ECoePanicControlWindowIsBackedUp)); |
|
900 |
|
901 RWindow& win = Window(); |
|
902 win.SetTransparencyAlphaChannel(); |
|
903 win.SetBackgroundColor(~0); |
|
904 iFlags |= EWindowIsSemiTransparent; |
|
905 } |
|
906 |
|
907 |
|
908 /** Set the zoom factor for this control. |
|
909 |
|
910 @param aZoomFactor Amount of zoom (multiplied by 1000) |
|
911 @param aZoomType Absolute or relative (EAbsoluteZoom or ERelativeZoom) |
|
912 @publishedAll |
|
913 @released |
|
914 */ |
|
915 EXPORT_C void CCoeControl::SetZoomFactorL(TInt aZoomFactor, TZoomType aZoomType) |
|
916 { |
|
917 TCoeZoomWithType* zoom = GetZoomWithType(); |
|
918 if(!zoom) |
|
919 { |
|
920 zoom = new (ELeave) TCoeZoomWithType; |
|
921 CleanupStack::PushL(zoom); |
|
922 User::LeaveIfError(SetZoomWithType(zoom)); |
|
923 CleanupStack::Pop(); |
|
924 } |
|
925 |
|
926 zoom->iZoomFactor = aZoomFactor; |
|
927 zoom->iZoomType = aZoomType; |
|
928 |
|
929 HandleResourceChange(KUidValueCoeZoomChangeEvent); |
|
930 RequestRelayout(this); |
|
931 } |
|
932 |
|
933 /** Set the font provider. This is an external object that takes the responsibililty |
|
934 for finding an appropriate font away from the control. |
|
935 |
|
936 @param aFontProvider The provider to use. |
|
937 @publishedAll |
|
938 @released |
|
939 */ |
|
940 EXPORT_C void CCoeControl::SetFontProviderL(const CCoeFontProvider& aFontProvider) |
|
941 { |
|
942 User::LeaveIfError(SetFontProvider(&aFontProvider)); |
|
943 |
|
944 HandleResourceChange(KUidValueCoeFontChangeEvent); |
|
945 RequestRelayout(this); |
|
946 } |
|
947 |
|
948 /** Return the zoom factor for this control. Takes account of zoom factors in parent controls |
|
949 to calculate accumulated zoom factor. |
|
950 |
|
951 |
|
952 @return Accumulated zoom factor. |
|
953 @publishedAll |
|
954 @released |
|
955 */ |
|
956 EXPORT_C TZoomFactor CCoeControl::AccumulatedZoom() const |
|
957 { |
|
958 TZoomFactor accZoomFactor(iCoeEnv->ScreenDevice()); |
|
959 |
|
960 const TCoeZoomWithType* zoomWithType = NULL; |
|
961 const CCoeControl* parent = this; |
|
962 |
|
963 #ifdef _DEBUG |
|
964 TInt safetyCount = 100; |
|
965 #endif |
|
966 while(parent) // Look for all zoom factors, all the way up. Don't stop at the first parent with one set. |
|
967 { |
|
968 zoomWithType = parent->GetZoomWithType(); |
|
969 |
|
970 if(zoomWithType) |
|
971 { |
|
972 if(zoomWithType->iZoomType == ERelativeZoom) |
|
973 { |
|
974 accZoomFactor.SetZoomFactor(accZoomFactor.ZoomFactor() * zoomWithType->iZoomFactor / 1000); |
|
975 } |
|
976 else |
|
977 { |
|
978 accZoomFactor.SetZoomFactor(zoomWithType->iZoomFactor * accZoomFactor.ZoomFactor() /1000); |
|
979 break; |
|
980 } |
|
981 } |
|
982 |
|
983 parent = parent->Parent(); |
|
984 #ifdef _DEBUG |
|
985 safetyCount--; |
|
986 __ASSERT_DEBUG(safetyCount, Panic(ECoePanicCyclicParentChildRelationship)); |
|
987 #endif |
|
988 } |
|
989 |
|
990 if(zoomWithType && (zoomWithType->iZoomType == ERelativeZoom)) |
|
991 { |
|
992 accZoomFactor.SetZoomFactor(accZoomFactor.ZoomFactor() * iCoeEnv->ZoomFactor().ZoomFactor() / 1000); |
|
993 } |
|
994 |
|
995 return accZoomFactor; |
|
996 } |
|
997 |
|
998 /** Return the zoom factor but without taking into account the |
|
999 zoom factor of the parent. Use of AccumulatedZoom() is recommended as it takes |
|
1000 into account the zoom factor of the parent. |
|
1001 |
|
1002 @publishedAll |
|
1003 @released |
|
1004 */ |
|
1005 EXPORT_C const TCoeZoomWithType* CCoeControl::ZoomWithType() const |
|
1006 { |
|
1007 return DoGetZoomWithType(iData->DynamicDataStorage()); |
|
1008 } |
|
1009 |
|
1010 /** Return the font provider used by this control |
|
1011 |
|
1012 @return The font provider used by this control |
|
1013 */ |
|
1014 EXPORT_C const CCoeFontProvider& CCoeControl::FindFontProvider() const |
|
1015 { |
|
1016 const CCoeFontProvider* fontProvider = GetFontProvider(); |
|
1017 const CCoeControl* parent = Parent(); |
|
1018 |
|
1019 #ifdef _DEBUG |
|
1020 TInt safetyCount = 100; |
|
1021 while(!fontProvider && parent) |
|
1022 { |
|
1023 fontProvider = parent->GetFontProvider(); |
|
1024 parent = parent->Parent(); |
|
1025 safetyCount--; |
|
1026 __ASSERT_DEBUG(safetyCount, Panic(ECoePanicCyclicParentChildRelationship)); |
|
1027 } |
|
1028 #else |
|
1029 while(!fontProvider && parent) |
|
1030 { |
|
1031 fontProvider = DoGetFontProvider(parent->iData->DynamicDataStorage()); |
|
1032 parent = parent->Parent(); |
|
1033 } |
|
1034 #endif |
|
1035 |
|
1036 return (!fontProvider ? CCoeEnv::Static()->DefaultFontProvider() : *fontProvider); |
|
1037 } |
|
1038 |
|
1039 /** Returns the closest matching font from the control's current font provider to the |
|
1040 requested logical font, taking into account the control's zoom factor. |
|
1041 |
|
1042 This function should be used in preference to legacy functions like |
|
1043 CEikonEnv::LegendFont(), CCoeEnv::NormalFont() or CCoeEnv::CreateScreenFontL(). |
|
1044 |
|
1045 Example 1: |
|
1046 Instead of the control using a CFont class member, or calling NormalFont(), |
|
1047 LegendFont() etc, it is recommended the control (e.g. in its Draw() method) call the |
|
1048 new ScreenFont() method to temporarily access a CFont object owned by the font provider. |
|
1049 This is a lot more efficient than repeatedly e.g. calling GetNearestFontInPixels(), |
|
1050 and allows the CFont object used for text drawing to vary depending on the current |
|
1051 zoom factor. Thus the CFont reference must not be kept as class member data, as it |
|
1052 may be changed by the font provider at any time. |
|
1053 |
|
1054 @code |
|
1055 CSomeControl::Draw(const TRect& aRect) |
|
1056 { |
|
1057 XCoeTextDrawer textDrawer(TextDrawer()); |
|
1058 textDrawer.SetAlignment(EHCenterVCenter); |
|
1059 textDrawer.DrawText(gc, iText, aRect, ScreenFont(TCoeFont::LegendFont()); |
|
1060 } |
|
1061 @endcode |
|
1062 |
|
1063 Example 2: |
|
1064 Although efficiently implemented, try not to call ScreenFont() or CCoeFontProvider::Font() |
|
1065 repeatedly unnecessarily. Instead, create and use a local const CFont& on the stack, |
|
1066 as shown below. |
|
1067 |
|
1068 Note that the ScreenFont() call above is provided as short-hand for the code on |
|
1069 the first two lines below. Also note that font providers and zoom factors apply |
|
1070 hieratically to the control tree (i.e. setting the zoom factor or font provider on |
|
1071 a container control affects the child controls too). |
|
1072 |
|
1073 @code |
|
1074 CSomeControl::Draw(const TRect& aRect) |
|
1075 { |
|
1076 const CCoeFontProvider& fontProvider = FindFontProvider(); |
|
1077 const CFont& font = fontProvider.Font(TCoeFont::LegendFont(), AccumulatedZoom()); |
|
1078 XCoeTextDrawer textDrawer(TextDrawer()); |
|
1079 textDrawer.SetAlignment(EHCenterVCenter); |
|
1080 textDrawer.DrawText(gc, iText, aRect, font); |
|
1081 textDrawer.DrawText(gc, iText2, aRect, font); |
|
1082 } |
|
1083 @endcode |
|
1084 |
|
1085 @param aFont Logical font to use. |
|
1086 @see CCoeFontProvider |
|
1087 @see TCoeFont |
|
1088 */ |
|
1089 EXPORT_C const CFont& CCoeControl::ScreenFont(const TCoeFont& aFont) const |
|
1090 { |
|
1091 TZoomFactor zoomFactor = AccumulatedZoom(); |
|
1092 return FindFontProvider().Font(aFont, zoomFactor); |
|
1093 } |
|
1094 |
|
1095 /** Notify controls that the font has changed |
|
1096 */ |
|
1097 void CCoeControl::NotifyFontChange(const CCoeFontProvider* aFontProvider) |
|
1098 { |
|
1099 if(!IsActivated() || Rect().IsEmpty()) |
|
1100 return; |
|
1101 |
|
1102 if(!aFontProvider) // Notify on highest possible level |
|
1103 { |
|
1104 HandleResourceChange(KUidValueCoeFontChangeEvent); |
|
1105 RequestRelayout(NULL); |
|
1106 } |
|
1107 else if(aFontProvider == GetFontProvider()) // Look for use of the font provider that changed |
|
1108 { |
|
1109 HandleResourceChange(KUidValueCoeFontChangeEvent); |
|
1110 RequestRelayout(NULL); |
|
1111 } |
|
1112 else // As long as we didn't find the right font provider, keep looking down the control tree |
|
1113 { |
|
1114 const TInt numControls = CountComponentControls(); |
|
1115 for(TInt i = 0; i < numControls; i++) |
|
1116 { |
|
1117 CCoeControl* control = ComponentControl(i); |
|
1118 control->NotifyFontChange(aFontProvider); |
|
1119 } |
|
1120 } |
|
1121 } |
|
1122 |
|
1123 |
|
1124 /** Force all CCoeFontProviders to update their logical-to-pixel mapping from CCoeControlStaticSettings |
|
1125 |
|
1126 @internalTechnology |
|
1127 */ |
|
1128 void CCoeControl::RefetchPixelMappingL() |
|
1129 { |
|
1130 CCoeFontProvider* fontProvider = const_cast<CCoeFontProvider*>(GetFontProvider()); |
|
1131 if(fontProvider) |
|
1132 { |
|
1133 fontProvider->RefetchPixelMappingL(); |
|
1134 } |
|
1135 |
|
1136 // and search for CCoeFontProvider's down the control tree |
|
1137 const TInt numControls = CountComponentControls(); |
|
1138 for(TInt i = 0; i < numControls; i++) |
|
1139 { |
|
1140 CCoeControl* control = ComponentControl(i); |
|
1141 control->RefetchPixelMappingL(); |
|
1142 } |
|
1143 } |
|
1144 |
|
1145 |
|
1146 EXPORT_C void CCoeControl::HandleResourceChange(TInt aType) |
|
1147 /** Handles a change to the control's resources. |
|
1148 |
|
1149 The types of resources handled are those which are shared across the environment, |
|
1150 e.g. colours or fonts. For colour scheme changes, DrawDeferred() is called in |
|
1151 order to redraw the control. |
|
1152 |
|
1153 If overriding HandleResourceChange(), the implementation must include a base call to CCoeControl's |
|
1154 HandleResourceChange(). |
|
1155 |
|
1156 @param aType A message UID value. |
|
1157 @see HandleComponentControlsResourceChange() */ |
|
1158 { |
|
1159 HandleComponentControlsResourceChange(aType); |
|
1160 if ((aType == KUidValueCoeColorSchemeChangeEvent) || (aType == KUidValueCoeZoomChangeEvent)) |
|
1161 { |
|
1162 DrawDeferred(); |
|
1163 } |
|
1164 } |
|
1165 |
|
1166 EXPORT_C void CCoeControl::GetColorUseListL(CArrayFix<TCoeColorUse>& /*aColorUseList*/) const |
|
1167 /** Gets the list of logical colours used to draw the control. |
|
1168 |
|
1169 The list includes an explanation of how each colour is used. |
|
1170 The default implementation is empty. |
|
1171 |
|
1172 If overriding GetColorUseListL(), the implementation must include a base call to CCoeControl's |
|
1173 GetColorUseListL(). |
|
1174 |
|
1175 @param aColorUseList The colour list. */ |
|
1176 { |
|
1177 } |
|
1178 |
|
1179 EXPORT_C void CCoeControl::GetHelpContext(TCoeHelpContext& /*aContext*/) const |
|
1180 /** Gets the control's help context. |
|
1181 |
|
1182 The default implementation is empty. The function must be implemented in |
|
1183 derived classes to associate the control with a particular Help file and |
|
1184 topic in a context sensitive application. The implementation should set |
|
1185 the public data members of TCoeHelpContext to the required Help file UID |
|
1186 and context descriptor, as created using the Context-Sensitive Help Compiler. |
|
1187 |
|
1188 @param aContext The control's help context */ |
|
1189 { |
|
1190 } |
|
1191 |
|
1192 EXPORT_C void CCoeControl::ConstructFromResourceL(TResourceReader& /*aSource*/) |
|
1193 /** Constructs the control from a resource file. |
|
1194 |
|
1195 This function has an empty default implementation. It should be implemented |
|
1196 if the control is to be displayed within a dialog. It should initialise the |
|
1197 control, reading in resource values from the resource file. |
|
1198 |
|
1199 Note: if a control is not displayed in a dialog, it is necessary to set the control's |
|
1200 associated window using SetContainerWindowL(). Since this may leave, the control |
|
1201 should be constructed using ConstructL(). |
|
1202 |
|
1203 @param aSource The resource reader with which to access the control's resource |
|
1204 values. */ |
|
1205 { |
|
1206 } |
|
1207 |
|
1208 EXPORT_C RWindow& CCoeControl::Window() const |
|
1209 /** Gets the control's associated window. |
|
1210 |
|
1211 The control must be window owning, and the window must be of type RWindow. |
|
1212 If you don't know whether the window is of type RWindow or RBackedUpWindow, |
|
1213 you should use DrawableWindow(). |
|
1214 |
|
1215 @return The control's associated window, cast to an RWindow. */ |
|
1216 { |
|
1217 return(STATIC_CAST(RWindow&,*iWin)); |
|
1218 } |
|
1219 |
|
1220 EXPORT_C RBackedUpWindow& CCoeControl::BackedUpWindow() const |
|
1221 /** Gets the backed-up window owned by the control. |
|
1222 |
|
1223 The window must be of type RBackedUpWindow. If you don't know whether the |
|
1224 window is of type RWindow or RBackedUpWindow, you should use DrawableWindow(). |
|
1225 |
|
1226 @return The control's associated window, cast to an RBackedUpWindow. |
|
1227 @deprecated |
|
1228 */ |
|
1229 { |
|
1230 return(STATIC_CAST(RBackedUpWindow&,*iWin)); |
|
1231 } |
|
1232 |
|
1233 EXPORT_C void CCoeControl::CloseWindow() |
|
1234 /** Closes the window owned by this control. |
|
1235 |
|
1236 It is called from CCoeControl's destructor for window-owning controls. */ |
|
1237 { |
|
1238 __ASSERT_DEBUG(OwnsWindow(),Panic(ECoePanicNoWindow)); |
|
1239 if (iWin) |
|
1240 { |
|
1241 iWin->Close(); |
|
1242 delete(iWin); |
|
1243 iWin=NULL; |
|
1244 } |
|
1245 iFlags&=(~(EOwnsWindow|EBackedUpWindow|EActivated)); |
|
1246 } |
|
1247 |
|
1248 EXPORT_C void CCoeControl::CreateBackedUpWindowL(RWindowTreeNode& aParent) |
|
1249 /** Creates a control's window as a backed-up window. |
|
1250 |
|
1251 The new window is the child of aParent and the display mode of the control |
|
1252 becomes the same as that of aParent. |
|
1253 |
|
1254 @param aParent The window to be the parent of this control's window. Does |
|
1255 not have to be a backed-up window. |
|
1256 @deprecated |
|
1257 */ |
|
1258 { |
|
1259 if(iFlags&EMemoryAllocationFailed) |
|
1260 User::LeaveNoMemory(); |
|
1261 |
|
1262 TInt colors=0; |
|
1263 TInt grays=0; |
|
1264 TDisplayMode defaultMode=iCoeEnv->WsSession().GetDefModeMaxNumColors(colors,grays); |
|
1265 CreateBackedUpWindowL(aParent,defaultMode); |
|
1266 } |
|
1267 |
|
1268 EXPORT_C void CCoeControl::CreateBackedUpWindowL(RWindowTreeNode& aParent,TDisplayMode aDisplayMode) |
|
1269 /** Creates a control's window as a backed-up window. |
|
1270 |
|
1271 The new window is the child of aParent. Furthermore, the window's extent is set to that of the control. |
|
1272 |
|
1273 The window will have the same display mode as the system display mode (the provided aDisplayMode is ignored). |
|
1274 |
|
1275 @param aParent The window of the control to be the parent of this control. |
|
1276 Does not have to be a backed-up window. |
|
1277 @param aDisplayMode Ignored. The window will always be created with the system display mode. |
|
1278 @deprecated |
|
1279 */ |
|
1280 { |
|
1281 if(iFlags&EMemoryAllocationFailed) |
|
1282 User::LeaveNoMemory(); |
|
1283 |
|
1284 __ASSERT_DEBUG(!OwnsWindow(), Panic(ECoePanicWindowAlreadyCreated)); |
|
1285 iWin=new(ELeave) RBackedUpWindow(iCoeEnv->WsSession()); |
|
1286 iFlags|=EOwnsWindow|EBackedUpWindow; |
|
1287 User::LeaveIfError(((RBackedUpWindow*)iWin)->Construct(aParent,aDisplayMode,(TUint32)this)); |
|
1288 const TInt err = (static_cast<RBackedUpWindow*>(iWin))->SetExtentErr(iPosition,iSize); |
|
1289 if (err!=KErrNone) |
|
1290 iFlags|=EMemoryAllocationFailed; |
|
1291 } |
|
1292 |
|
1293 EXPORT_C void CCoeControl::CreateWindowL(RWindowTreeNode& aParent) |
|
1294 /** Creates a control's window, specifying its parent window and its extent. |
|
1295 |
|
1296 This function makes the specified control a window-owning control, and would |
|
1297 typically be called in the control's ConstructL() function. It also sets the window's extent to that of the control. |
|
1298 |
|
1299 Note: |
|
1300 |
|
1301 The use of window owning controls is discouraged, as these tax run-time resources. |
|
1302 Ideally only the top level control in an appUi would be window owning. There |
|
1303 are some exceptions to this rule, e.g. floating controls like menus, dialogs |
|
1304 and scroll bars. |
|
1305 |
|
1306 In general, the overload with no parameters should be used. |
|
1307 |
|
1308 @param aParent The window of the control to be the parent of this control. */ |
|
1309 { |
|
1310 if(iFlags&EMemoryAllocationFailed) |
|
1311 User::LeaveNoMemory(); |
|
1312 |
|
1313 __ASSERT_DEBUG(!OwnsWindow(), Panic(ECoePanicWindowAlreadyCreated)); |
|
1314 iWin=new(ELeave) RWindow(iCoeEnv->WsSession()); |
|
1315 iFlags|=EOwnsWindow; |
|
1316 User::LeaveIfError(((RWindow*)iWin)->Construct(aParent,(TUint32)this)); |
|
1317 (static_cast<RWindow*>(iWin))->SetExtent(iPosition,iSize); |
|
1318 } |
|
1319 |
|
1320 // |
|
1321 // Overloaded member function which creates a containing window for the control to own. The window |
|
1322 // containing the control aParent is used as the window's parent if the control pointer is not NULL. |
|
1323 // Otherwise the root window will be used as parent. |
|
1324 // |
|
1325 EXPORT_C void CCoeControl::CreateWindowL(const CCoeControl* aParent) |
|
1326 /** Creates a control's window, specifying the parent control. |
|
1327 |
|
1328 The control's window is created as a child of the parent control's window. |
|
1329 |
|
1330 This function makes the specified control a window-owning control, and would |
|
1331 typically be called in the control's ConstructL() function. |
|
1332 |
|
1333 Note: |
|
1334 |
|
1335 The use of window owning controls is discouraged, as these tax run-time resources. |
|
1336 Ideally only the top level control in an appUi would be window owning. There |
|
1337 are some exceptions to this rule, e.g. floating controls like menus, dialogs |
|
1338 and scroll bars. |
|
1339 |
|
1340 In general, the overload with no parameters should be used. |
|
1341 |
|
1342 @param aParent The control to be the parent of this control. */ |
|
1343 { |
|
1344 SetMopParent(const_cast<CCoeControl*>(aParent)); |
|
1345 User::LeaveIfError(SetParent(const_cast<CCoeControl*>(aParent))); |
|
1346 |
|
1347 CreateWindowL(aParent? (RWindowTreeNode&)(*aParent->iWin): (RWindowTreeNode&)iCoeEnv->RootWin()); |
|
1348 } |
|
1349 |
|
1350 // |
|
1351 // Overloaded member function which creates a containing window for the control to own. The window |
|
1352 // group aParent is used as the window's parent if it is not NULL. Otherwise the root window will be |
|
1353 // used as the parent. |
|
1354 // |
|
1355 EXPORT_C void CCoeControl::CreateWindowL(RWindowGroup* aParent) |
|
1356 /** Creates a control's window, specifying its parent window group. |
|
1357 |
|
1358 This function makes the specified control a window-owning control, and would |
|
1359 typically be called in the control's ConstructL() function. |
|
1360 |
|
1361 Note: |
|
1362 |
|
1363 The use of window owning controls is discouraged, as these tax run-time resources. |
|
1364 Ideally only the top level control in an appUi would be window owning. There |
|
1365 are some exceptions to this rule, e.g. floating controls like menus, dialogs |
|
1366 and scroll bars. |
|
1367 |
|
1368 In general, the overload with no parameters should be used. |
|
1369 |
|
1370 @param aParent The window group of the control to be the parent of this control */ |
|
1371 { |
|
1372 CreateWindowL(aParent? (RWindowTreeNode&)(*aParent): (RWindowTreeNode&)iCoeEnv->RootWin()); |
|
1373 } |
|
1374 |
|
1375 // |
|
1376 // Overloaded member function which creates a containing window for the control to own. The root window is |
|
1377 // used as a parent. |
|
1378 // |
|
1379 EXPORT_C void CCoeControl::CreateWindowL() |
|
1380 /** Creates a control's window. |
|
1381 |
|
1382 The created window is the child of the application's window group. |
|
1383 |
|
1384 This function makes the specified control a window-owning control, and would |
|
1385 typically be called in the control's ConstructL() function. |
|
1386 |
|
1387 Note: |
|
1388 |
|
1389 The use of window owning controls is discouraged, as these tax run-time resources. |
|
1390 Ideally only the top level control in an appUi would be window owning. There |
|
1391 are some exceptions to this rule, e.g. floating controls like menus, dialogs |
|
1392 and scroll bars. */ |
|
1393 { |
|
1394 CreateWindowL(iCoeEnv->RootWin()); |
|
1395 } |
|
1396 |
|
1397 EXPORT_C void CCoeControl::HandleRedrawEvent(const TRect& aRect) const |
|
1398 /** Handles redraw events. |
|
1399 |
|
1400 In normal circumstances this function should not be used or overridden by |
|
1401 the derived control class. |
|
1402 |
|
1403 @param aRect The rectangle to be redrawn. */ |
|
1404 { |
|
1405 Window().BeginRedraw(aRect); |
|
1406 |
|
1407 if (IsReadyToDraw()) |
|
1408 { |
|
1409 ActivateGc(); |
|
1410 // Draw the background if found, but not if this is a semi-transparent window-owning control |
|
1411 // without its own background attached (or we risk drawing a semi-transparent skin multiple times) |
|
1412 if ((OwnsWindow() || Background()) && !(iFlags&EWindowIsSemiTransparent && !Background())) |
|
1413 { |
|
1414 const MCoeControlBackground* background = FindBackground(); |
|
1415 if (background) |
|
1416 background->Draw(SystemGc(), *this, aRect); |
|
1417 } |
|
1418 |
|
1419 Draw(aRect); |
|
1420 DrawComponents(aRect); |
|
1421 DeactivateGc(); |
|
1422 } |
|
1423 Window().EndRedraw(); |
|
1424 } |
|
1425 |
|
1426 void CCoeControl::DrawComponents(const TRect& aRect) const |
|
1427 { |
|
1428 CWindowGc* containerGc = CustomGc(); |
|
1429 CWindowGc* gc = (containerGc ? containerGc : &SystemGc()); |
|
1430 |
|
1431 const TInt count=CountComponentControls(); |
|
1432 for (TInt ii=0; ii<count; ii++) |
|
1433 { |
|
1434 const CCoeControl* ctrl=ComponentControl(ii); |
|
1435 |
|
1436 if (!(ctrl->OwnsWindow()) && ctrl->IsVisible()) |
|
1437 { |
|
1438 TRect rect; |
|
1439 const TRect* pRect=(&aRect); |
|
1440 if (!((ctrl->iFlags)&ECanDrawOutsideRect)) |
|
1441 { |
|
1442 rect=ctrl->Rect(); |
|
1443 rect.Intersection(aRect); |
|
1444 if (rect.IsEmpty()) |
|
1445 continue; |
|
1446 pRect=(&rect); |
|
1447 } |
|
1448 |
|
1449 const MCoeControlBackground* background = ctrl->Background(); |
|
1450 if(background) // ctrl is always non-window owning. Draw if it itself has background attached |
|
1451 background->Draw(*gc, *ctrl, *pRect); |
|
1452 |
|
1453 if (iContext) |
|
1454 iContext->ResetContext(*gc); |
|
1455 else |
|
1456 gc->Reset(); |
|
1457 |
|
1458 ctrl->Draw(*pRect); |
|
1459 ctrl->DrawComponents(*pRect); |
|
1460 } |
|
1461 } |
|
1462 } |
|
1463 |
|
1464 |
|
1465 |
|
1466 EXPORT_C void CCoeControl::Draw(const TRect& aRect) const |
|
1467 /** Draws the control. |
|
1468 |
|
1469 All controls, except blank controls, should implement this function. The default |
|
1470 implementation draws a blank control. |
|
1471 |
|
1472 This function is called by window server. It is used for window server-initiated |
|
1473 redrawing of controls, and for some application-initiated drawing. It should be |
|
1474 implemented by each control, but is only called from within CCoeControl's member |
|
1475 functions, and not from the derived class. For this reason it is a private member |
|
1476 function of CCoeControl. |
|
1477 |
|
1478 The rectangle aRect indicates the region of the control that needs to be redrawn. |
|
1479 The implementation of Draw() must always draw to every pixel within this rectangle. |
|
1480 |
|
1481 Notes: |
|
1482 |
|
1483 For non-window-owning controls, care must be taken not to draw outside the |
|
1484 control, as drawing will not be clipped to the control. Drawing is clipped |
|
1485 to window-owning-controls, but not to non-window-owning controls. |
|
1486 |
|
1487 Drawing outside aRect may cause flicker. |
|
1488 |
|
1489 Drawing should be done using a graphics context (CWindowGc), which can be |
|
1490 obtained using SystemGc(). |
|
1491 |
|
1492 @param aRect The region of the control to be redrawn. Co-ordinates are relative |
|
1493 to the control's origin (top left corner). */ |
|
1494 { |
|
1495 if (iFlags&EBlank) |
|
1496 { // else do nothing |
|
1497 // If there is a background then it will be used |
|
1498 // to draw the background so don't blank the window |
|
1499 if(!FindBackground()) |
|
1500 { |
|
1501 CGraphicsContext& gc=SystemGc(); |
|
1502 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
1503 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
1504 gc.DrawRect(aRect); |
|
1505 } |
|
1506 } |
|
1507 } |
|
1508 |
|
1509 EXPORT_C void CCoeControl::DrawNow() const |
|
1510 /** Draws the entire control |
|
1511 |
|
1512 This function is called by an application or other code. |
|
1513 The application should call this function when the control is first created |
|
1514 and is ready for drawing, or if a change in application data or the control's |
|
1515 internal state means that entire control's appearance is no longer up-to-date. |
|
1516 |
|
1517 Partial redrawing of a control is sometimes more appropriate than drawing |
|
1518 the entire control, and in this case, use DrawNow(const TRect &aRect) instead. |
|
1519 |
|
1520 DrawNow() is implemented by CCoeControl and MAY NOT be overridden. It calls |
|
1521 Draw() on the control itself, and also on all its component controls, if it |
|
1522 is a compound control. (To do this it uses CountComponentControls() and ComponentControl(), |
|
1523 which should be implemented by the derived control class.) If the control |
|
1524 is a window-owning control, it also calls Draw() for its child windows (if |
|
1525 any). */ |
|
1526 { |
|
1527 DrawNow(Rect()); |
|
1528 } |
|
1529 |
|
1530 /** Draws the control, its components and child windows, within the bounds defined by the given rectangle. |
|
1531 @param aRect The rectangular region of the control to be drawn. */ |
|
1532 EXPORT_C void CCoeControl::DrawNow(const TRect &aRect) const |
|
1533 { |
|
1534 if (!IsReadyToDraw()) |
|
1535 return; |
|
1536 |
|
1537 TBool backedUp=IsBackedUp(); |
|
1538 if (!backedUp) |
|
1539 { |
|
1540 Window().Invalidate(aRect); |
|
1541 Window().BeginRedraw(aRect); |
|
1542 } |
|
1543 |
|
1544 const CCoeControl* parent = WindowOwningParent(); |
|
1545 if (parent && parent->IsReadyToDraw()) // Parents should always be ready to draw, but there are flaky code out there... |
|
1546 { |
|
1547 __ASSERT_DEBUG(parent->OwnsWindow(), User::Invariant()); |
|
1548 parent->ActivateGc(); |
|
1549 const MCoeControlBackground* background = parent->FindBackground(); |
|
1550 // Draw the background if found, but not if this is a semi-transparent window-owning control |
|
1551 // without its own background attached (or we risk drawing a semi-transparent skin multiple times) |
|
1552 if (background && !(iFlags&EWindowIsSemiTransparent && !Background())) |
|
1553 background->Draw(parent->SystemGc(), *parent, aRect); |
|
1554 |
|
1555 parent->Draw(aRect); |
|
1556 parent->DrawComponents(aRect); |
|
1557 parent->DeactivateGc(); |
|
1558 if (!backedUp) |
|
1559 Window().EndRedraw(); |
|
1560 parent->DrawWindowOwningComponentsNow(aRect); |
|
1561 } |
|
1562 else |
|
1563 { |
|
1564 ActivateGc(); |
|
1565 Draw(aRect); |
|
1566 DrawComponents(aRect); |
|
1567 DeactivateGc(); |
|
1568 if (!backedUp) |
|
1569 Window().EndRedraw(); |
|
1570 |
|
1571 DrawWindowOwningComponentsNow(aRect); |
|
1572 } |
|
1573 } |
|
1574 |
|
1575 void CCoeControl::DrawWindowOwningComponentsNow(const TRect &aRect) const |
|
1576 { |
|
1577 const TInt count=CountComponentControls(); |
|
1578 for (TInt ii=0; ii<count; ii++) |
|
1579 { |
|
1580 CCoeControl* ctrl=ComponentControl(ii); |
|
1581 |
|
1582 if (!ctrl->OwnsWindow()) |
|
1583 { |
|
1584 ctrl->DrawWindowOwningComponentsNow(aRect); |
|
1585 } |
|
1586 else |
|
1587 { |
|
1588 TRect adjustedRect(aRect); |
|
1589 const RWindow& parentWindow = Window(); |
|
1590 const RDrawableWindow& childWindow = *(ctrl->DrawableWindow()); |
|
1591 if (parentWindow.WsHandle() != childWindow.WsHandle()) |
|
1592 { |
|
1593 const TPoint childRelativePos = childWindow.InquireOffset(parentWindow); |
|
1594 // Adjust the parent referenced rectangle to the child window co-ordinates |
|
1595 adjustedRect.Move(-childRelativePos); |
|
1596 } |
|
1597 else |
|
1598 { |
|
1599 // As the child owns the window, the parent is a lodger of the child, so allow for the parent position |
|
1600 adjustedRect.Move(-iPosition); |
|
1601 } |
|
1602 adjustedRect.Intersection(ctrl->Rect()); |
|
1603 if (!adjustedRect.IsEmpty()) |
|
1604 { |
|
1605 ctrl->DrawNow(adjustedRect); |
|
1606 } |
|
1607 |
|
1608 } |
|
1609 } |
|
1610 } |
|
1611 |
|
1612 |
|
1613 |
|
1614 EXPORT_C void CCoeControl::DrawDeferred() const |
|
1615 /** Draws the control, with low priority. |
|
1616 |
|
1617 This function is called by an application or other code. |
|
1618 |
|
1619 It causes the control area to be marked as invalid, which will |
|
1620 eventually cause a redraw initiated by the window server. The control framework |
|
1621 handles redraw events at a lower priority than user input events, which means |
|
1622 that any pending user input events will be processed before the redraw event. |
|
1623 DrawDeferred() therefore allows a control to do drawing at a lower priority |
|
1624 than drawing performed by DrawNow(). |
|
1625 |
|
1626 An advantage of using DrawDeferred() is that if you make multiple calls to |
|
1627 DrawDeferred() on the same area of a control, the window server will not generate |
|
1628 a redraw event to do drawing that has already been superceded. If you make |
|
1629 multiple calls to DrawNow(), however, all of them get processed, even if they |
|
1630 have already been superceded by the time they are processed. */ |
|
1631 { |
|
1632 if (!IsReadyToDraw()) |
|
1633 return; |
|
1634 if (IsBackedUp()) |
|
1635 DrawNow(); |
|
1636 else |
|
1637 Window().Invalidate(Rect()); |
|
1638 const TInt count=CountComponentControls(); |
|
1639 for (TInt ii=0; ii<count; ii++) |
|
1640 { |
|
1641 const CCoeControl* ctrl=ComponentControl(ii); |
|
1642 if (ctrl->OwnsWindow()) |
|
1643 ctrl->DrawDeferred(); |
|
1644 } |
|
1645 } |
|
1646 |
|
1647 /** Find a control in the parent chain (including this) that owns a window |
|
1648 */ |
|
1649 CCoeControl* CCoeControl::WindowOwningParent() |
|
1650 { |
|
1651 CCoeControl* parent = this; // start with this, in case it is window owning |
|
1652 |
|
1653 #ifdef _DEBUG |
|
1654 TInt safetyCount = 100; |
|
1655 #endif |
|
1656 while(parent && !parent->OwnsWindow()) |
|
1657 { |
|
1658 parent = parent->Parent(); |
|
1659 #ifdef _DEBUG |
|
1660 --safetyCount; |
|
1661 ASSERT(safetyCount); |
|
1662 #endif |
|
1663 } |
|
1664 return parent; |
|
1665 } |
|
1666 |
|
1667 /** Returns the background drawer object associated with this object, if any. |
|
1668 Null is returned if there is no such object. Compare with FindBackground(), which looks up the parent chain |
|
1669 to find a background drawer. |
|
1670 |
|
1671 @return The background drawer object associated with this object. */ |
|
1672 EXPORT_C const MCoeControlBackground* CCoeControl::Background() const |
|
1673 { |
|
1674 return DoGetBackground(iData->DynamicDataStorage()); |
|
1675 } |
|
1676 |
|
1677 /** Return an MCoeControlBackground object, if there is one - looking up |
|
1678 the parent chain as necessary. Compare to Background(), which does not |
|
1679 go up the parent chain. |
|
1680 */ |
|
1681 EXPORT_C const MCoeControlBackground* CCoeControl::FindBackground() const |
|
1682 { |
|
1683 const MCoeControlBackground* background = Background(); |
|
1684 const CCoeControl* parent = Parent(); |
|
1685 |
|
1686 #ifdef _DEBUG |
|
1687 TInt safetyCount = 100; |
|
1688 #endif |
|
1689 while(!background && parent) |
|
1690 { |
|
1691 background = parent->Background(); |
|
1692 parent = parent->Parent(); |
|
1693 #ifdef _DEBUG |
|
1694 safetyCount--; |
|
1695 ASSERT(safetyCount); |
|
1696 #endif |
|
1697 } |
|
1698 return background; |
|
1699 } |
|
1700 |
|
1701 /** Sets aParent as the parent of this control. |
|
1702 If setting aParent as parent of this control will create a cyclic relationship, |
|
1703 this method does nothing. |
|
1704 |
|
1705 @param aParent The control to set as this control's parent. |
|
1706 @return KErrNone if successful, otherwise another of the system error codes. |
|
1707 */ |
|
1708 EXPORT_C TInt CCoeControl::SetParent(CCoeControl* aParent) |
|
1709 { |
|
1710 if(aParent) // Check for cyclic relationships only if parent is not being set to NULL |
|
1711 { |
|
1712 const CCoeControl* parent = aParent->SearchParent(this); |
|
1713 // If "parent" is non-NULL, it means that "this" is already a parent of aParent. |
|
1714 // Such circularity should not occur... |
|
1715 if(parent) // ...but because there are bad controls out there (like CEikButtonGroupContainer)... |
|
1716 return KErrNone; // ...do nothing, to avoid creating a cyclic parent-child relationship. |
|
1717 } |
|
1718 |
|
1719 const TInt err = DoSetParent(iData->DynamicDataStorage(), aParent); |
|
1720 if(err) |
|
1721 iFlags |= EMemoryAllocationFailed; // Doom the control |
|
1722 return err; |
|
1723 } |
|
1724 |
|
1725 /** Safety check to avoid loops in the parent chain. |
|
1726 */ |
|
1727 const CCoeControl* CCoeControl::SearchParent(const CCoeControl* aParentToFind) const |
|
1728 { |
|
1729 const CCoeControl* parent = this; |
|
1730 #ifdef _DEBUG |
|
1731 TInt safetyCount = 100; |
|
1732 #endif |
|
1733 while (parent && parent != aParentToFind) |
|
1734 { |
|
1735 parent = parent->Parent(); |
|
1736 #ifdef _DEBUG |
|
1737 --safetyCount; |
|
1738 ASSERT(safetyCount); |
|
1739 #endif |
|
1740 } |
|
1741 |
|
1742 return parent; |
|
1743 } |
|
1744 |
|
1745 /** |
|
1746 Sets the control's custom graphics context. This value overrides the system context for |
|
1747 this control and any children. |
|
1748 |
|
1749 If aGraphicsContext is null, the control's graphics context is reset to the one it inherited |
|
1750 from its parent, or to the default system graphics context (iCoeEnv->SystemGc()) if none of |
|
1751 its parents have set their own graphics context. |
|
1752 |
|
1753 This value is retrieved by CCoeControl::SystemGc(). |
|
1754 @param aGraphContext The new graphics context for this class and its children. |
|
1755 The caller keeps ownership. |
|
1756 */ |
|
1757 EXPORT_C TInt CCoeControl::SetCustomGc(CWindowGc* aGraphicsContext) |
|
1758 { |
|
1759 return DoSetCustomGc(iData->DynamicDataStorage(), aGraphicsContext); |
|
1760 } |
|
1761 |
|
1762 |
|
1763 /** |
|
1764 Returns the custom graphics context set for this control (if any). Note that unlike |
|
1765 CCoeControl::SystemGc(), this function ignores the parent window's state and |
|
1766 returns the context set explicitly for this control instance, or NULL if none has been set. |
|
1767 |
|
1768 @return The current graphics context. |
|
1769 */ |
|
1770 EXPORT_C CWindowGc* CCoeControl::CustomGc() const |
|
1771 { |
|
1772 return DoGetCustomGc(iData->DynamicDataStorage()); |
|
1773 } |
|
1774 |
|
1775 /** Draws the control's background using its graphics context. |
|
1776 Unlike DrawNow() and DrawDeferred(), this function does not propagate |
|
1777 the draw to component controls. |
|
1778 |
|
1779 @param aRect The area to be redrawn. This can be the control's entire rectangle, or a |
|
1780 sub-rectangle within it. |
|
1781 */ |
|
1782 EXPORT_C void CCoeControl::DrawBackground(const TRect& aRect) const |
|
1783 { |
|
1784 CWindowGc& gc=SystemGc(); |
|
1785 const MCoeControlBackground* theBackground = Background(); |
|
1786 if(theBackground) |
|
1787 { |
|
1788 theBackground->Draw(gc, *this, aRect); |
|
1789 } |
|
1790 } |
|
1791 |
|
1792 /** Draws the control's foreground using the control's graphics context. |
|
1793 Unlike DrawNow() and DrawDeferred(), this function does not propagate the draw to component controls. |
|
1794 |
|
1795 @param aRect The area to be redrawn. This can be the control's entire rectangle, or a |
|
1796 sub-rectangle within it. |
|
1797 */ |
|
1798 EXPORT_C void CCoeControl::DrawForeground(const TRect& aRect) const |
|
1799 { |
|
1800 Draw(aRect); |
|
1801 } |
|
1802 |
|
1803 /** Installs a hit tester for this control. The tester defines the hit region, |
|
1804 which is the area within the control that accepts pointer events. If no hit region is set, |
|
1805 pointer events are accepted in the control's entire rectangle. |
|
1806 |
|
1807 @param aHitTestControl Object which defines the hit region. |
|
1808 @return KErrNone if successful, or another system error code. |
|
1809 */ |
|
1810 EXPORT_C TInt CCoeControl::SetHitTest(const MCoeControlHitTest* aHitTestControl) |
|
1811 { |
|
1812 return DoSetHitTest(iData->DynamicDataStorage(), aHitTestControl); |
|
1813 } |
|
1814 |
|
1815 /** Gets the object that defines the hit region inside the control's rectangle. |
|
1816 The object is set by calling SetHitTest(). |
|
1817 |
|
1818 @return The hit region tester. |
|
1819 */ |
|
1820 EXPORT_C const MCoeControlHitTest* CCoeControl::HitTest() const |
|
1821 { |
|
1822 return DoGetHitTest(iData->DynamicDataStorage()); |
|
1823 } |
|
1824 |
|
1825 TCoeZoomWithType* CCoeControl::GetZoomWithType() const |
|
1826 { |
|
1827 return DoGetZoomWithType(iData->DynamicDataStorage()); |
|
1828 } |
|
1829 |
|
1830 TInt CCoeControl::SetZoomWithType(TCoeZoomWithType* aZoomWithType) |
|
1831 { |
|
1832 return DoSetZoomWithType(iData->DynamicDataStorage(), aZoomWithType); |
|
1833 } |
|
1834 |
|
1835 const CCoeFontProvider* CCoeControl::GetFontProvider() const |
|
1836 { |
|
1837 return DoGetFontProvider(iData->DynamicDataStorage()); |
|
1838 } |
|
1839 |
|
1840 TInt CCoeControl::SetFontProvider(const CCoeFontProvider* aFontProvider) |
|
1841 { |
|
1842 return DoSetFontProvider(iData->DynamicDataStorage(), aFontProvider); |
|
1843 } |
|
1844 |
|
1845 EXPORT_C CWindowGc& CCoeControl::SystemGc() const |
|
1846 /** Gets the graphics context that is used when drawing the control. |
|
1847 |
|
1848 This function walks the CCoeControl hierarchy upwards from child to parent until a context |
|
1849 is found. If no control in the hierarchy has defined its own graphics context, the default system |
|
1850 graphics context (iCoeEnv->SystemGc()) is returned. |
|
1851 |
|
1852 All drawing is carried out through a graphics context. A graphics context |
|
1853 must be activated before it can be drawn to, and deactivated |
|
1854 when it is no longer needed. When drawing is done using Draw(), DrawNow() |
|
1855 or DrawDeferred(), the application does not have to do this, as it is done |
|
1856 within the control framework. However, for application-initiated drawing which |
|
1857 is not done using DrawNow() or DrawDeferred(), the application should activate |
|
1858 and deactivate the graphics context using ActivateGc() and DeactivateGc() |
|
1859 (or CWindowGc::Activate() and CWindowGc::Deactivate()). |
|
1860 |
|
1861 @return The system graphics context. */ |
|
1862 { |
|
1863 const CCoeControl* theControl = this; |
|
1864 do |
|
1865 { |
|
1866 CWindowGc* customGc = DoGetCustomGc(theControl->iData->DynamicDataStorage()); |
|
1867 if(customGc) |
|
1868 return *customGc; |
|
1869 } |
|
1870 while((theControl=theControl->Parent()) != NULL); |
|
1871 |
|
1872 return(iCoeEnv->SystemGc()); |
|
1873 } |
|
1874 |
|
1875 EXPORT_C void CCoeControl::ActivateGc() const |
|
1876 /** Activates the standard graphics context. |
|
1877 |
|
1878 This is the graphics context owned by the control environment (CCoeEnv). |
|
1879 |
|
1880 Applications do not normally need to call this function, as it is called |
|
1881 by the control framework whenever it is about to call Draw(). */ |
|
1882 { |
|
1883 CWindowGc& gc=SystemGc(); |
|
1884 if (iContext) |
|
1885 iContext->ActivateContext(gc,*iWin); |
|
1886 else |
|
1887 gc.Activate(*iWin); |
|
1888 ActivateGcRecursive(); |
|
1889 } |
|
1890 |
|
1891 void CCoeControl::ActivateGcRecursive() const |
|
1892 { |
|
1893 const TInt numComponentControls = CountComponentControls(); |
|
1894 |
|
1895 for(TInt i = numComponentControls - 1; i >= 0; i--) |
|
1896 { |
|
1897 const CCoeControl* control = ComponentControl(i); |
|
1898 |
|
1899 if(control) |
|
1900 { |
|
1901 CWindowGc* redirectedgc = control->CustomGc(); |
|
1902 CWindowGc* containerGc = CustomGc(); |
|
1903 const TBool swapGc = (redirectedgc && (redirectedgc != containerGc)); |
|
1904 |
|
1905 if(swapGc) |
|
1906 { |
|
1907 if(iContext) |
|
1908 { |
|
1909 iContext->ActivateContext(*redirectedgc,*DrawableWindow()); |
|
1910 } |
|
1911 else |
|
1912 { |
|
1913 redirectedgc->Activate(*DrawableWindow()); |
|
1914 } |
|
1915 } |
|
1916 |
|
1917 control->ActivateGcRecursive(); |
|
1918 } |
|
1919 } |
|
1920 } |
|
1921 |
|
1922 EXPORT_C void CCoeControl::ResetGc() const |
|
1923 /** Resets the standard graphics context. |
|
1924 |
|
1925 The function resets the graphics context owned by the control environment |
|
1926 to its default settings. */ |
|
1927 { |
|
1928 CWindowGc& gc=SystemGc(); |
|
1929 if (iContext) |
|
1930 iContext->ResetContext(gc); |
|
1931 else |
|
1932 gc.Reset(); |
|
1933 } |
|
1934 |
|
1935 EXPORT_C void CCoeControl::DeactivateGc() const |
|
1936 /** Deactivates the standard graphics context owned by the UI control framework. |
|
1937 |
|
1938 Applications do not normally need to call this function, as it is called |
|
1939 by the control framework whenever it has called Draw() and drawing is completed. */ |
|
1940 { // no harm done if Gc other than system one used |
|
1941 SystemGc().Deactivate(); |
|
1942 |
|
1943 DeactivateGcRecursive(); |
|
1944 } |
|
1945 |
|
1946 void CCoeControl::DeactivateGcRecursive() const |
|
1947 { |
|
1948 TInt numComponentControls = CountComponentControls(); |
|
1949 |
|
1950 for(TInt i = numComponentControls - 1; i >= 0; i--) |
|
1951 { |
|
1952 const CCoeControl* control = ComponentControl(i); |
|
1953 |
|
1954 if(control) |
|
1955 { |
|
1956 CWindowGc* redirectedgc = control->CustomGc(); |
|
1957 CWindowGc* containerGc = CustomGc(); |
|
1958 const TBool swapGc = (redirectedgc && (redirectedgc != containerGc)); |
|
1959 |
|
1960 if(swapGc) |
|
1961 { |
|
1962 redirectedgc->Deactivate(); |
|
1963 } |
|
1964 |
|
1965 control->DeactivateGcRecursive(); |
|
1966 } |
|
1967 } |
|
1968 } |
|
1969 |
|
1970 EXPORT_C void CCoeControl::SetFocus(TBool aFocus,TDrawNow aDrawNow) |
|
1971 /** Sets this control to have the keyboard focus. |
|
1972 |
|
1973 It sets the value of a focus flag within the control to the value |
|
1974 given by aFocus. This flag indicates whether or not the control has keyboard |
|
1975 focus, and its value can be enquired using IsFocused(). It then calls FocusChanged(), |
|
1976 passing it the value given by aDrawNow, unless the control is invisible or |
|
1977 not activated, in which case it passes ENoDrawNow. |
|
1978 |
|
1979 Note that setting focus does not initiate a redraw. The control's implementation |
|
1980 of FocusChanged() should do this if required. The control's Draw() function, |
|
1981 or that of its container, should normally change the appearance of the control |
|
1982 to indicate whether or not it currently has focus. |
|
1983 |
|
1984 @param aFocus ETrue sets the control as having keyboard focus, EFalse sets |
|
1985 it as not having keyboard focus. |
|
1986 @param aDrawNow Flag to pass to FocusChanged(). */ |
|
1987 { |
|
1988 iCoeEnv->QueueNotificationToFocusObserversOfChangeInFocus(); |
|
1989 if (aFocus) |
|
1990 { |
|
1991 iFlags|=EFocused; |
|
1992 iFlags&=(~ENotifyFocusObserversOnDestruction); |
|
1993 } |
|
1994 else |
|
1995 { |
|
1996 if (iFlags&EFocused) |
|
1997 { |
|
1998 iFlags&=(~EFocused); |
|
1999 |
|
2000 if(DoSetFocusObserverNotificationIdentifier(iData->DynamicDataStorage(), iCoeEnv->FocusObserverNotificationIdentifier()) == KErrNoMemory) |
|
2001 iFlags|=ENotifyFocusObserversOnDestruction; |
|
2002 else |
|
2003 iFlags&=(~ENotifyFocusObserversOnDestruction); |
|
2004 } |
|
2005 } |
|
2006 |
|
2007 if (aDrawNow && !IsReadyToDraw()) |
|
2008 aDrawNow=ENoDrawNow; |
|
2009 |
|
2010 FocusChanged(aDrawNow); |
|
2011 } |
|
2012 |
|
2013 EXPORT_C void CCoeControl::FocusChanged(TDrawNow /*aDrawNow*/) |
|
2014 /** Responds to a change in focus. |
|
2015 |
|
2016 This is called whenever the control gains or loses focus, as a result |
|
2017 of a call to SetFocus(). A typical use of FocusChanged() is to change the |
|
2018 appearance of the control, for example by drawing a focus rectangle around it. |
|
2019 |
|
2020 The default implementation is empty, and should be overridden by the CCoeControl-derived |
|
2021 class. |
|
2022 |
|
2023 @param aDrawNow Contains the value that was passed to it by SetFocus(). */ |
|
2024 { |
|
2025 } |
|
2026 |
|
2027 void CCoeControl::ReportControlStateChange(MCoeControlStateObserver::TCoeState aType) |
|
2028 /** Reports a change in the controls visibility or dimmed state to the Mop Framework |
|
2029 |
|
2030 Looks for an object through the Mop framework both starting at this control and from the |
|
2031 control enviroment. Calls them both if they provide different objects.*/ |
|
2032 { |
|
2033 if(iFlags&EReportControlStateChange && iCoeEnv->ControlStateChange()) //Do control state change only if it is enabled |
|
2034 { |
|
2035 MCoeControlStateObserver* stateObserver1=NULL; |
|
2036 MCoeControlStateObserver* stateObserver2=NULL; |
|
2037 iCoeEnv->MopGetObjectNoChaining(stateObserver1); |
|
2038 MopGetObject(stateObserver2); |
|
2039 if (stateObserver1) |
|
2040 stateObserver1->HandleControlStateChange(this,aType); //Ignore returned error code |
|
2041 if (stateObserver2 && stateObserver1!=stateObserver2) |
|
2042 stateObserver2->HandleControlStateChange(this,aType); //Ignore returned error code |
|
2043 } |
|
2044 } |
|
2045 |
|
2046 TInt CCoeControl::ValidateAdvancedPointerNumber( const TPointerEvent& aPointerEvent ) const |
|
2047 /** Determines that the pointer-number in an advanced-pointer-event is within the supported range. |
|
2048 |
|
2049 @param aPointerEvent the TPointerEvent reference to be validated. |
|
2050 @return KErrArgument if the pointer-number is out of range of the supported number of pointers. |
|
2051 */ |
|
2052 { |
|
2053 TInt err = KErrNone; |
|
2054 |
|
2055 // Called only for advancedpointerevent so AdvancedPointerEvent()->PointerNumber() is safe |
|
2056 if( aPointerEvent.AdvancedPointerEvent()->PointerNumber() >= ControlEnv()->SupportedPointers() ) |
|
2057 { |
|
2058 err = KErrArgument; |
|
2059 } |
|
2060 |
|
2061 return err; |
|
2062 } |
|
2063 |
|
2064 EXPORT_C void CCoeControl::SetDimmed(TBool aDimmed) |
|
2065 /** Sets the control to be dimmed. |
|
2066 |
|
2067 This function sets a flag within the control which indicates whether or not |
|
2068 the control is dimmed (greyed out). This is typically used to show that the |
|
2069 control is temporarily unavailable. |
|
2070 |
|
2071 SetDimmed() does not initiate a redraw of the control. The application should |
|
2072 call DrawNow() or DrawDeferred() if a redraw is required after calling SetDimmed(). |
|
2073 The control's Draw() function should draw the control appropriately according |
|
2074 to whether it is dimmed or not. (This can be enquired using IsDimmed().) |
|
2075 |
|
2076 If overriding SetDimmed(), the implementation must include a base call to CCoeControl's |
|
2077 SetDimmed(). |
|
2078 |
|
2079 @param aDimmed ETrue to dim the control, EFalse to set the control as not |
|
2080 dimmed. */ |
|
2081 { |
|
2082 if (!(iFlags&EDimmed)==!aDimmed) |
|
2083 return; |
|
2084 if (aDimmed) |
|
2085 iFlags|=EDimmed; |
|
2086 else |
|
2087 iFlags&=(~EDimmed); |
|
2088 ReportControlStateChange(MCoeControlStateObserver::EStateDimmed); |
|
2089 } |
|
2090 |
|
2091 void CCoeControl::SetGrabbed(TBool aGrabbed, TInt aPointerNumber) |
|
2092 /** Sets the control to grab pointer events |
|
2093 |
|
2094 */ |
|
2095 { |
|
2096 if (aGrabbed) |
|
2097 { |
|
2098 // sets pointer grab flag for given pointer number |
|
2099 iData->SetPointerGrab( (1 << aPointerNumber), 0 ); |
|
2100 } |
|
2101 else |
|
2102 { |
|
2103 iData->SetPointerGrab( 0, (1 << aPointerNumber) ); |
|
2104 } |
|
2105 } |
|
2106 |
|
2107 EXPORT_C void CCoeControl::MakeVisible(TBool aVisible) |
|
2108 /** Sets this control as visible or invisible. |
|
2109 |
|
2110 This causes the control to disappear or reappear. When a control is created, |
|
2111 it is made visible by default. |
|
2112 |
|
2113 MakeVisible() can be called before or after the control is activated. |
|
2114 |
|
2115 Notes: |
|
2116 |
|
2117 This function may be overridden. |
|
2118 |
|
2119 The visibility of the control can be queried using IsVisible(). |
|
2120 |
|
2121 If MakeVisible() is used to make a component visible, and the control captures |
|
2122 the pointer (see CapturesPointer()), MakeVisible() throws away any pending |
|
2123 pointer events for that control. |
|
2124 |
|
2125 Typical uses are for scrollbars, or for dialogs where some user responses |
|
2126 are not required in certain circumstances. |
|
2127 |
|
2128 @param aVisible ETrue to make the control visible, EFalse to make it invisible. */ |
|
2129 { |
|
2130 DoMakeVisible(aVisible); |
|
2131 if (iFlags&ECapturesPointer) |
|
2132 CheckPointerEventPurge(); |
|
2133 } |
|
2134 |
|
2135 void CCoeControl::DoMakeVisible(TBool aVisible) |
|
2136 { |
|
2137 TBool isVisible=IsVisible(); |
|
2138 if ((isVisible && aVisible) || (!isVisible && !aVisible)) |
|
2139 return; // No change |
|
2140 if (aVisible) |
|
2141 iFlags&=(~EInvisible); |
|
2142 else |
|
2143 iFlags|=EInvisible; |
|
2144 if (OwnsWindow()) |
|
2145 iWin->SetVisible(aVisible); |
|
2146 else if (IsActivated()) |
|
2147 { |
|
2148 if (IsBackedUp()) |
|
2149 DrawNow(); |
|
2150 else |
|
2151 Window().Invalidate(Rect()); |
|
2152 } |
|
2153 if (iFlags&EComponentsInheritVisibility) |
|
2154 { |
|
2155 const TInt count=CountComponentControls(); |
|
2156 for (TInt ii=0; ii<count; ii++) |
|
2157 ComponentControl(ii)->MakeVisible(aVisible); |
|
2158 } |
|
2159 ReportControlStateChange(MCoeControlStateObserver::EStateVisibility); |
|
2160 } |
|
2161 |
|
2162 EXPORT_C void CCoeControl::SetComponentsToInheritVisibility(TBool aInherit) |
|
2163 /** Sets the control's components to inherit the visibility setting of their |
|
2164 container control. |
|
2165 |
|
2166 If set, when MakeVisible() is called on the compound control, the visibility |
|
2167 setting is propagated to all its components. |
|
2168 |
|
2169 @param aInherit If ETrue, the control's components inherit its visibility |
|
2170 setting; if EFalse they do not. */ |
|
2171 { |
|
2172 if (aInherit) |
|
2173 iFlags|=EComponentsInheritVisibility; |
|
2174 else |
|
2175 iFlags&=(~EComponentsInheritVisibility); |
|
2176 } |
|
2177 |
|
2178 EXPORT_C TCoeInputCapabilities CCoeControl::InputCapabilities() const |
|
2179 /** Gets the control's input capabilities. |
|
2180 |
|
2181 Classes that override CCoeControl::OfferKeyEventL() should also override this |
|
2182 function, returning a TCoeInputCapabilities object whose attributes correspond |
|
2183 to the behaviour of the OfferKeyEventL() function. The default implementation |
|
2184 returns TCoeInputCapabilities::ENone. |
|
2185 |
|
2186 It is not necessary to call InputCapabilities() on any component controls |
|
2187 from inside a class's InputCapabilities() function. This is done automatically |
|
2188 by the UI Control Framework. |
|
2189 |
|
2190 @return The control's input capabilities. */ |
|
2191 { |
|
2192 return TCoeInputCapabilities(TCoeInputCapabilities::ENone); |
|
2193 } |
|
2194 |
|
2195 EXPORT_C void CCoeControl::SetGloballyCapturing(TBool aGlobal) |
|
2196 /** Sets the global pointer capture flag. |
|
2197 |
|
2198 This flag indicates whether or not pointer capture should be global. |
|
2199 |
|
2200 The flag is used by SetPointerCapture() to determine what value to pass to |
|
2201 RWindowBase::SetPointerCapture(). The default for the global capture flag, |
|
2202 when a control is created, is EFalse. |
|
2203 |
|
2204 @param aGlobal Value for global capture flag. */ |
|
2205 { |
|
2206 if (aGlobal) |
|
2207 iFlags|=EGloballyCapturing; |
|
2208 else |
|
2209 iFlags&=(~EGloballyCapturing); |
|
2210 } |
|
2211 |
|
2212 EXPORT_C void CCoeControl::SetNonFocusing() |
|
2213 /** Deprecated. Use SetFocusing(). |
|
2214 |
|
2215 Sets the control as unable to receive keyboard focus. The function would typically |
|
2216 be called during construction of the control. */ |
|
2217 { |
|
2218 iFlags|=ENonFocusing; |
|
2219 } |
|
2220 |
|
2221 EXPORT_C void CCoeControl::SetFocusing(TBool aFocusing) |
|
2222 /** Sets the control as able to receive keyboard focus. |
|
2223 |
|
2224 @param aFocusing ETrue if the control can have focus, EFalse if it can't. */ |
|
2225 { |
|
2226 if (aFocusing) |
|
2227 iFlags&=(~ENonFocusing); |
|
2228 else |
|
2229 iFlags|=ENonFocusing; |
|
2230 } |
|
2231 |
|
2232 EXPORT_C TBool CCoeControl::IsNonFocusing() const |
|
2233 /** Tests if the control can receive focus. |
|
2234 |
|
2235 @return ETrue if the control cannot receive focus, EFalse if it can. |
|
2236 @see SetNonFocusing() */ |
|
2237 { |
|
2238 return(iFlags&ENonFocusing); |
|
2239 } |
|
2240 |
|
2241 EXPORT_C void CCoeControl::SetAllowStrayPointers() |
|
2242 /** Sets whether or not to allow stray pointer events. |
|
2243 |
|
2244 This function sets a flag that affects the way the control framework handles |
|
2245 pointer events. By default, the flag is not set, and the control will ignore |
|
2246 any pointer drag events and up events where the matching pointer down event |
|
2247 occurred in a different control. This would happen if a user pressed the pointer |
|
2248 down in a control, but then dragged the pointer into a different control before |
|
2249 releasing it. |
|
2250 |
|
2251 SetAllowStrayPointers() is typically used for menus, where stray pointer events |
|
2252 are required because it is the pointer up event that is used to activate a |
|
2253 menu option even when the pointer down event occured in a different menu pane. |
|
2254 This is not the case in some other components such as command buttons, |
|
2255 where a pointer down event and up event in succession are required to activate |
|
2256 the button. */ |
|
2257 { |
|
2258 iFlags|=EAllowStrayPointers; |
|
2259 } |
|
2260 |
|
2261 EXPORT_C void CCoeControl::SetCanDrawOutsideRect() |
|
2262 /** Allows the control to draw outside its own extent. |
|
2263 |
|
2264 When a compound control is drawn, all its component controls are also drawn. |
|
2265 However, unless this flag is set, they are not drawn if the rectangle they |
|
2266 inhabit on the screen doesn't intersect with the rectangle to be drawn. |
|
2267 |
|
2268 Setting this flag has the effect of allowing a component control to draw outside |
|
2269 its own extent. It should be used with caution! By default, this flag is not |
|
2270 set. */ |
|
2271 { |
|
2272 iFlags|=ECanDrawOutsideRect; |
|
2273 } |
|
2274 |
|
2275 EXPORT_C void CCoeControl::SetBlank() |
|
2276 /** Sets a flag to indicate that the control is blank. |
|
2277 |
|
2278 Once set, this flag cannot be unset for the lifetime of the control. |
|
2279 |
|
2280 @see IsBlank() */ |
|
2281 { |
|
2282 iFlags|=EBlank; |
|
2283 } |
|
2284 |
|
2285 EXPORT_C void CCoeControl::SetRect(const TRect& aRect) |
|
2286 /** Sets the control's extent, specifying a rectangle. |
|
2287 |
|
2288 Note: calling this function results in a call to SizeChanged(). |
|
2289 |
|
2290 @param aRect The rectangle that defines the control's extent. The rectangle's |
|
2291 origin is relative to the origin of its associated window. */ |
|
2292 { |
|
2293 SetExtent(aRect.iTl,aRect.Size()); |
|
2294 } |
|
2295 |
|
2296 EXPORT_C void CCoeControl::SetExtentToWholeScreen() |
|
2297 /** Sets the control's extent to the whole screen. |
|
2298 |
|
2299 Note: calling this function results in a call to SizeChanged(). */ |
|
2300 { |
|
2301 SetExtent(TPoint(0,0),iCoeEnv->ScreenDevice()->SizeInPixels()); |
|
2302 } |
|
2303 |
|
2304 EXPORT_C void CCoeControl::SetExtent(const TPoint& aPosition,const TSize& aSize) |
|
2305 /** Sets the control's extent, specifying a size and a position. |
|
2306 |
|
2307 Note: calling this function results in a call to SizeChanged(). |
|
2308 |
|
2309 @param aPosition The position of the control, relative to its associated window. |
|
2310 @param aSize The size of the control, in pixels. */ |
|
2311 { |
|
2312 if (OwnsWindow()) |
|
2313 { |
|
2314 if (IsBackedUp()) |
|
2315 { |
|
2316 const TInt err=iWin->SetExtentErr(aPosition,aSize); |
|
2317 if (err!=KErrNone) |
|
2318 iFlags|=EMemoryAllocationFailed; // Doom the control |
|
2319 } |
|
2320 else |
|
2321 Window().SetExtent(aPosition,aSize); |
|
2322 } |
|
2323 iPosition=aPosition; |
|
2324 iSize=aSize; |
|
2325 SizeChanged(); |
|
2326 } |
|
2327 |
|
2328 EXPORT_C void CCoeControl::SizeChanged() |
|
2329 /** Responds to changes to the size and position of the contents of this control. |
|
2330 |
|
2331 For a simple control this might include text or graphics. For a compound control |
|
2332 it sets the size and position of the components. |
|
2333 |
|
2334 The function is called whenever SetExtent(), SetSize(), SetRect(), SetCornerAndSize(), |
|
2335 or SetExtentToWholeScreen() are called on the control. Note that the window |
|
2336 server does not generate size-changed events: SizeChanged() gets called only |
|
2337 as a result of calling the functions listed above. Therefore, if a resize |
|
2338 of one control affects the size of other controls, it is up to the application |
|
2339 to ensure that it handles the re-sizing of all affected controls. */ |
|
2340 { |
|
2341 MCoeLayoutManager* layout = LayoutManager(); |
|
2342 if (layout) |
|
2343 { |
|
2344 layout->PerformLayout(); |
|
2345 } |
|
2346 } |
|
2347 |
|
2348 EXPORT_C void CCoeControl::PositionChanged() |
|
2349 /** Responds to changes in the position of a control. |
|
2350 |
|
2351 It has an empty default implementation which may be overridden by the CCoeControl-derived |
|
2352 class. |
|
2353 |
|
2354 This function is called whenever the application calls SetPosition() on |
|
2355 the control. */ |
|
2356 { |
|
2357 } |
|
2358 |
|
2359 EXPORT_C void CCoeControl::SetSize(const TSize& aSize) |
|
2360 /** Sets the control's size. |
|
2361 |
|
2362 If the size, but not the position, of a control is set, then its position |
|
2363 will default to TPoint(0,0). |
|
2364 |
|
2365 Note: calling this function results in a call to SizeChanged(). |
|
2366 |
|
2367 @param aSize The control's size, in pixels. */ |
|
2368 { |
|
2369 SetSizeWithoutNotification(aSize); |
|
2370 SizeChanged(); |
|
2371 } |
|
2372 |
|
2373 EXPORT_C TInt CCoeControl::SetMaximumWidth(TInt aMaxWidth) |
|
2374 /** Sets the controls maximum width. |
|
2375 |
|
2376 @param aMaxWidth The control's maximum width. |
|
2377 @return Error Code. (KErrNone if max width was set successfully) */ |
|
2378 { |
|
2379 // Set the maximum width value |
|
2380 return DoSetMaximumWidth(iData->DynamicDataStorage(), aMaxWidth); |
|
2381 } |
|
2382 |
|
2383 EXPORT_C void CCoeControl::SetPosition(const TPoint& aPosition) |
|
2384 /** Sets the control's position. |
|
2385 |
|
2386 If the control owns its containing window, it achieves this by setting the position of the window. |
|
2387 Otherwise, the position of the control is set relative to its containing window. The |
|
2388 positions of the control's components are adjusted accordingly and PositionChanged() |
|
2389 is called. |
|
2390 |
|
2391 @param aPosition The position of the the top-left of the control, relative to its |
|
2392 associated window. */ |
|
2393 { |
|
2394 if (OwnsWindow()) |
|
2395 { |
|
2396 iPosition=aPosition; |
|
2397 iWin->SetPosition(aPosition); |
|
2398 } |
|
2399 else |
|
2400 { |
|
2401 const TPoint delta=aPosition-iPosition; |
|
2402 iPosition=aPosition; |
|
2403 const TInt count=CountComponentControls(); |
|
2404 for (TInt ii=0;ii<count;ii++) |
|
2405 { |
|
2406 CCoeControl* ctrl=ComponentControl(ii); |
|
2407 const TPoint pos=ctrl->Position(); |
|
2408 ctrl->SetPosition(pos+delta); |
|
2409 } |
|
2410 } |
|
2411 PositionChanged(); |
|
2412 } |
|
2413 |
|
2414 /** Sets a control's size without calling SizeChanged(). |
|
2415 |
|
2416 If the size, but not the position, of a control is set, then its position |
|
2417 will default to TPoint(0,0). |
|
2418 |
|
2419 @param aSize The control's size, in pixels. |
|
2420 @see SetSize() */ |
|
2421 EXPORT_C void CCoeControl::SetSizeWithoutNotification(const TSize& aSize) |
|
2422 { |
|
2423 if (OwnsWindow()) |
|
2424 { |
|
2425 if (IsBackedUp()) |
|
2426 { |
|
2427 const TInt err=iWin->SetSizeErr(aSize); |
|
2428 if (err!=KErrNone) |
|
2429 iFlags|=EMemoryAllocationFailed; // Doom the control |
|
2430 } |
|
2431 else |
|
2432 Window().SetSize(aSize); |
|
2433 } |
|
2434 iSize=aSize; |
|
2435 } |
|
2436 |
|
2437 /** Creates a component array to store child controls. |
|
2438 |
|
2439 This function is useful when the control is a compound control. It creates an array where the |
|
2440 child controls can be stored. The CCoeControl::Components return the created array. The CCoeControlArray class |
|
2441 provides functions to easily add and remove controls. |
|
2442 */ |
|
2443 EXPORT_C void CCoeControl::InitComponentArrayL() |
|
2444 { |
|
2445 CCoeControlArray* array = DoGetComponentArray(iData->DynamicDataStorage()); |
|
2446 if(!array) |
|
2447 { |
|
2448 array = CCoeControlArray::NewL(*this); |
|
2449 if(DoSetComponentArray(iData->DynamicDataStorage(), array) != KErrNone) |
|
2450 { |
|
2451 delete array; |
|
2452 User::LeaveNoMemory(); |
|
2453 } |
|
2454 } |
|
2455 } |
|
2456 |
|
2457 /** Returns a component array to store child controls. |
|
2458 |
|
2459 This function is useful when the control is a compound control. The CCoeControlArray class |
|
2460 provides functions to easily add and remove controls. The array must have been created before |
|
2461 this function can be called. The InitComponentArrayL does this. |
|
2462 |
|
2463 @return The control array |
|
2464 @see CCoeControl::InitComponentArrayL() |
|
2465 */ |
|
2466 EXPORT_C CCoeControlArray& CCoeControl::Components() |
|
2467 { |
|
2468 return *DoGetComponentArray(iData->DynamicDataStorage()); |
|
2469 } |
|
2470 |
|
2471 /** Returns a component array to store child controls. |
|
2472 |
|
2473 This function is useful when the control is a compound control. The CCoeControlArray class |
|
2474 provides functions to easily add and remove controls. The array must have been created before |
|
2475 this function can be called. The InitComponentArrayL does this. |
|
2476 |
|
2477 @return The control array |
|
2478 @see CCoeControl::InitComponentArrayL() |
|
2479 */ |
|
2480 EXPORT_C const CCoeControlArray& CCoeControl::Components() const |
|
2481 { |
|
2482 return *DoGetComponentArray(iData->DynamicDataStorage()); |
|
2483 } |
|
2484 |
|
2485 /** Handles events generated by the CCoeControlArray. |
|
2486 |
|
2487 This function is useful when the control is a compound control and the CCoeControlArray functionality is used. |
|
2488 The CCoeControlArray functions that add and remove controls will use this event handler to notify the |
|
2489 control that child controls have been added or removed. |
|
2490 |
|
2491 The default implementation of this function forwards the events to the layout manager (if there is one). If the |
|
2492 event is EControlAdded it also sets the container window of the new child control unless the child control is a window |
|
2493 owning control. If the event is EControlRemoved it also sets the parent of the removed child control to null. |
|
2494 |
|
2495 @param aEvent The type of the event |
|
2496 @param aArray The array that generated the event |
|
2497 @param aControl The control affected by the event |
|
2498 @param aControlId The id of the control affected by the event |
|
2499 */ |
|
2500 EXPORT_C void CCoeControl::HandleControlArrayEventL(CCoeControlArray::TEvent aEvent, const CCoeControlArray* aArray, |
|
2501 CCoeControl* aControl, TInt /*aControlId*/) |
|
2502 { |
|
2503 if (aArray != &Components()) |
|
2504 return; // some other array |
|
2505 |
|
2506 switch(aEvent) |
|
2507 { |
|
2508 case CCoeControlArray::EControlAdded: |
|
2509 { |
|
2510 __ASSERT_DEBUG(aControl->Parent() == NULL || aControl->Parent() == this, Panic(ECoePanicIncorrectControlParent)); |
|
2511 __ASSERT_DEBUG(DrawableWindow(), Panic(ECoePanicNoWindow)); // Make sure the container window is set |
|
2512 |
|
2513 if(!aControl->OwnsWindow()) |
|
2514 aControl->SetContainerWindowL(*this); |
|
2515 |
|
2516 MCoeLayoutManager* layoutManager = LayoutManager(); |
|
2517 if(layoutManager) |
|
2518 layoutManager->HandleAddedControlL(*this, *aControl); |
|
2519 } |
|
2520 break; |
|
2521 case CCoeControlArray::EControlRemoved: |
|
2522 { |
|
2523 MCoeLayoutManager* layoutManager = LayoutManager(); |
|
2524 if(layoutManager) |
|
2525 layoutManager->HandleRemovedControl(*this, *aControl); |
|
2526 |
|
2527 aControl->SetParent(NULL); |
|
2528 } |
|
2529 break; |
|
2530 default: |
|
2531 ASSERT(0); |
|
2532 } |
|
2533 } |
|
2534 |
|
2535 /** Gets an indexed component of a compound control. |
|
2536 |
|
2537 There are 2 ways to implement a compound control. One way is to override this function. The other way |
|
2538 is to use the CCoeControlArray functionality (see the InitComponentArrayL method). |
|
2539 |
|
2540 Note: within a compound control, each component control is identified by an index, |
|
2541 where the index depends on the order the controls were added: the first is |
|
2542 given an index of 0, the next an index of 1, and so on. |
|
2543 |
|
2544 @param aIndex The index of the control. |
|
2545 @return The component control with an index of aIndex. |
|
2546 */ |
|
2547 EXPORT_C CCoeControl* CCoeControl::ComponentControl(TInt aIndex) const |
|
2548 { |
|
2549 CCoeControlArray* components = DoGetComponentArray(iData->DynamicDataStorage()); |
|
2550 return ( components ? components->At(aIndex).iControl : NULL ); |
|
2551 } |
|
2552 |
|
2553 |
|
2554 EXPORT_C void CCoeControl::ActivateL() |
|
2555 /** Sets the control as ready to be drawn. |
|
2556 |
|
2557 The application should call this function on all controls that are not components |
|
2558 in a compound control. |
|
2559 |
|
2560 The purpose of this function is that controls are not always ready to be drawn |
|
2561 as soon as they have been constructed. For example, it may not be possible |
|
2562 to set the control's extent during construction, but its extent should always |
|
2563 be set before it is drawn. Similarly, if a control is to be made invisible, |
|
2564 this should be done before it is activated. |
|
2565 |
|
2566 The default implementation sets a flag in the control to indicate it is ready |
|
2567 to be drawn. If the control is a compound control, the default implementation |
|
2568 also calls ActivateL() for all the control's components. To get the control's |
|
2569 components it uses CountComponentControls() and ComponentControl(), which |
|
2570 should be implemented by the compound control. |
|
2571 |
|
2572 ActivateL() is typically called from the control's ConstructL() function . |
|
2573 |
|
2574 Notes: |
|
2575 |
|
2576 This function can be overridden. This is useful for doing late initialisation |
|
2577 of the control, using information that was not available at the time the control |
|
2578 was created. For example, a text editor might override ActivateL() and use it |
|
2579 to enquire whether it is focused: if it is, it makes the cursor and any highlighting |
|
2580 visible. At the time when the editor is created, it doesn't know whether or |
|
2581 not it has keyboard focus. |
|
2582 |
|
2583 If overriding ActivateL(), the implementation must include a base call to CCoeControl's |
|
2584 ActivateL().*/ |
|
2585 { |
|
2586 if (iFlags&EMemoryAllocationFailed) |
|
2587 User::LeaveNoMemory(); |
|
2588 |
|
2589 if (!(iFlags&EActivated)) |
|
2590 { |
|
2591 iFlags|=EActivated; |
|
2592 if (OwnsWindow()) |
|
2593 { |
|
2594 iWin->Activate(); |
|
2595 if (iFlags&ECapturesPointer) |
|
2596 CheckPointerEventPurge(); |
|
2597 if (IsBackedUp()) |
|
2598 DrawNow(); |
|
2599 } |
|
2600 |
|
2601 iData->AttemptCompress(); // Purge any unused member data memory |
|
2602 } |
|
2603 |
|
2604 const TInt count=CountComponentControls(); |
|
2605 for (TInt ii=0; ii<count; ii++) |
|
2606 { |
|
2607 CCoeControl* child = ComponentControl(ii); |
|
2608 if(!child->Parent()) |
|
2609 child->SetParent(this); // Set the parent if not already set |
|
2610 child->ActivateL(); |
|
2611 } |
|
2612 } |
|
2613 |
|
2614 EXPORT_C TRect CCoeControl::Rect() const |
|
2615 /** Gets the control's extent. |
|
2616 |
|
2617 The position of the top-left of the rectangle is (0,0) if the control owns its |
|
2618 window. Otherwise, its position is relative to its window. |
|
2619 |
|
2620 @return The control's extent. */ |
|
2621 { |
|
2622 return(TRect(OwnsWindow()? TPoint(0,0): iPosition,iSize)); |
|
2623 } |
|
2624 |
|
2625 EXPORT_C void CCoeControl::SetContainerWindowL(const CCoeControl& aContainer) |
|
2626 /** Sets the control's containing window by copying it from aContainer. |
|
2627 |
|
2628 It also copies the control context from aContainer if one has not previously been set. |
|
2629 |
|
2630 This function can only be called on non-window-owning (or 'lodger') controls. |
|
2631 |
|
2632 If overriding SetContainerWindowL(), the implementation must include a base call to CCoeControl's |
|
2633 SetContainerWindowL(). |
|
2634 |
|
2635 @param aContainer The compound control that is the container for this control. */ |
|
2636 { |
|
2637 if(iFlags&EMemoryAllocationFailed) |
|
2638 User::LeaveNoMemory(); |
|
2639 |
|
2640 if(OwnsWindow()) |
|
2641 CloseWindow(); |
|
2642 |
|
2643 iWin = aContainer.iWin; |
|
2644 if (!iContext) |
|
2645 iContext = aContainer.iContext; |
|
2646 |
|
2647 if (aContainer.IsBackedUp()) |
|
2648 iFlags |= EBackedUpWindow; |
|
2649 |
|
2650 SetMopParent(const_cast<CCoeControl*>(&aContainer)); |
|
2651 User::LeaveIfError(SetParent(const_cast<CCoeControl*>(&aContainer))); |
|
2652 } |
|
2653 |
|
2654 |
|
2655 EXPORT_C void CCoeControl::SetContainerWindowL(RWindow& aWindow) |
|
2656 /** Sets the control's containing window, without transferring ownership |
|
2657 of the window to this control. |
|
2658 |
|
2659 This function can only be called on non-window-owning ('lodger') controls. |
|
2660 |
|
2661 Note: the container's window can be accessed using Window(), DrawableWindow(), or |
|
2662 BackedUpWindow(). |
|
2663 |
|
2664 @param aWindow The window owned by the container control. */ |
|
2665 { |
|
2666 if(iFlags&EMemoryAllocationFailed) |
|
2667 User::LeaveNoMemory(); |
|
2668 |
|
2669 if(OwnsWindow()) |
|
2670 CloseWindow(); |
|
2671 |
|
2672 iWin=&aWindow; |
|
2673 } |
|
2674 |
|
2675 EXPORT_C void CCoeControl::SetContainerWindowL(RBackedUpWindow& aWindow) |
|
2676 /** Sets the control's containing window without transferring ownership |
|
2677 of the window to this control. |
|
2678 |
|
2679 The function can only be called on non-window-owning ('lodger') controls. |
|
2680 |
|
2681 Note: the container's window can be accessed using Window(), DrawableWindow(), or |
|
2682 BackedUpWindow(). |
|
2683 |
|
2684 @param aWindow The backed up window owned by the container control. |
|
2685 @deprecated |
|
2686 */ |
|
2687 { |
|
2688 if(iFlags&EMemoryAllocationFailed) |
|
2689 User::LeaveNoMemory(); |
|
2690 |
|
2691 if(OwnsWindow()) |
|
2692 CloseWindow(); |
|
2693 |
|
2694 iWin=&aWindow; |
|
2695 iFlags|=EBackedUpWindow; |
|
2696 } |
|
2697 |
|
2698 EXPORT_C void CCoeControl::SetCornerAndSize(TGulAlignment aCorner,const TSize& aSize) |
|
2699 /** Sets the control's alignment and size. |
|
2700 |
|
2701 The control's position is calculated, relative to the screen, according to |
|
2702 the requested alignment. |
|
2703 |
|
2704 Note: calling this function results in a call to SizeChanged(). |
|
2705 |
|
2706 @param aCorner The alignment of the control. |
|
2707 @param aSize The control's size. */ |
|
2708 { // the following assumes the window is being positioned wrt the screen |
|
2709 TPoint pos=aCorner.InnerTopLeft(iCoeEnv->ScreenDevice()->SizeInPixels(),aSize); |
|
2710 SetExtent(pos,aSize); |
|
2711 } |
|
2712 |
|
2713 /** Gets the number of controls contained in a compound control. |
|
2714 |
|
2715 There are 2 ways to implement a compound control. One way is to override this function. The other way |
|
2716 is to use the CCoeControlArray functionality (see the InitComponentArrayL method). |
|
2717 |
|
2718 @return The number of component controls contained by this control. */ |
|
2719 EXPORT_C TInt CCoeControl::CountComponentControls() const |
|
2720 { |
|
2721 CCoeControlArray* components = DoGetComponentArray(iData->DynamicDataStorage()); |
|
2722 return ( components ? components->Count() : 0 ); |
|
2723 } |
|
2724 |
|
2725 EXPORT_C void CCoeControl::EnableDragEvents() |
|
2726 /** Requests pointer drag events. |
|
2727 |
|
2728 This function should be called if a control is required to receive pointer |
|
2729 drag and move events. The default behaviour for all controls is that pointer |
|
2730 drag and move events are not delivered. |
|
2731 |
|
2732 The control framework does not provide a function to disable drag events at |
|
2733 a later time, but this can be done via the Window Server API, by calling Window()->PointerFilter(). |
|
2734 |
|
2735 Note: |
|
2736 |
|
2737 By default, pointer move events are not delivered, even after calling EnableDragEvents(), |
|
2738 because they are not normally required in a pen-based system. The window server |
|
2739 can be configured to deliver pointer move events if required, e.g. for a mouse-based |
|
2740 system. |
|
2741 |
|
2742 @see RWindowBase::PointerFilter() */ |
|
2743 { |
|
2744 const TInt KPointerFilterBitsAllClear = 0; |
|
2745 iWin->PointerFilter(EPointerFilterDrag, KPointerFilterBitsAllClear); |
|
2746 } |
|
2747 |
|
2748 EXPORT_C void CCoeControl::SetPointerCapture(TBool aCapture) |
|
2749 /** Sets pointer capture. |
|
2750 |
|
2751 Once set, pointer capture lasts until SetPointerCapture() is called on the |
|
2752 control with aCapture=EFalse. |
|
2753 |
|
2754 This function is typically used by dialogs, to discard any pointer events |
|
2755 that occur outside of the dialog. |
|
2756 |
|
2757 @param aCapture If ETrue, passes the following value as the argument to |
|
2758 RWindowBase::SetPointerCapture(): RWindowBase::TCaptureFlagAllGroups|RWindowBase::TCaptureFlagEnabled, |
|
2759 if the control's global capture flag is set to ETrue (see SetGloballyCapturing()) |
|
2760 or RWindowBase::TCaptureFlagEnabled if the control's global capture flag is |
|
2761 set to EFalse. If EFalse, passes EFalse as the argument to RWindowBase::SetPointerCapture(). |
|
2762 @see RWindowBase::SetPointerCapture() */ |
|
2763 { |
|
2764 TInt captureFlags=0; |
|
2765 iFlags&=(~ECapturesPointer); |
|
2766 if (aCapture) |
|
2767 captureFlags=(iFlags&EGloballyCapturing? RWindowBase::TCaptureFlagAllGroups|RWindowBase::TCaptureFlagEnabled: RWindowBase::TCaptureFlagEnabled); |
|
2768 iWin->SetPointerCapture(captureFlags); |
|
2769 if (aCapture) |
|
2770 { |
|
2771 iFlags|=ECapturesPointer; |
|
2772 CheckPointerEventPurge(); |
|
2773 } |
|
2774 } |
|
2775 |
|
2776 EXPORT_C TBool CCoeControl::CapturesPointer() const |
|
2777 /** Tests whether pointer capture is set for the control. |
|
2778 |
|
2779 This returns true if SetPointerCapture() has been called with aCapture=ETrue. |
|
2780 |
|
2781 @return ETrue if pointer capture is set. EFalse if it isn't. */ |
|
2782 { |
|
2783 return iFlags&ECapturesPointer; |
|
2784 } |
|
2785 |
|
2786 void CCoeControl::CheckPointerEventPurge() const |
|
2787 { |
|
2788 if (IsReadyToDraw()) |
|
2789 iCoeEnv->WsSession().PurgePointerEvents(); |
|
2790 } |
|
2791 |
|
2792 EXPORT_C TInt CCoeControl::Index(const CCoeControl* aControl) const |
|
2793 /** Gets the index of a control that is a component of this control. |
|
2794 |
|
2795 @param aControl The component control. |
|
2796 @return The index of the component control within the compound control, or |
|
2797 KErrNotFound if aControl is not a component of this control. */ |
|
2798 { |
|
2799 TInt count=CountComponentControls(); |
|
2800 for (TInt ii=0; ii<count; ii++) |
|
2801 { |
|
2802 if (aControl==ComponentControl(ii)) |
|
2803 return(ii); |
|
2804 } |
|
2805 return(KErrNotFound); |
|
2806 } |
|
2807 |
|
2808 EXPORT_C void CCoeControl::SetControlContext(MCoeControlContext* aContext) |
|
2809 /** Set the control context for this control. |
|
2810 |
|
2811 @param aContext The context for this control. */ |
|
2812 { |
|
2813 iContext=aContext; |
|
2814 } |
|
2815 |
|
2816 EXPORT_C void CCoeControl::CopyControlContextFrom(const CCoeControl* aControl) |
|
2817 /** Sets the control's context from another control. |
|
2818 |
|
2819 @param aControl The control whose context is copied. */ |
|
2820 { |
|
2821 iContext=aControl->iContext; |
|
2822 } |
|
2823 |
|
2824 EXPORT_C MCoeControlContext* CCoeControl::ControlContext() const |
|
2825 /** Gets the control context being used by this control. |
|
2826 |
|
2827 The function does not transfer ownership to the caller. |
|
2828 |
|
2829 @return The control context. */ |
|
2830 { |
|
2831 return iContext; |
|
2832 } |
|
2833 |
|
2834 EXPORT_C CCoeControl* CCoeControl::GrabbingComponent() const |
|
2835 /** Returns the component of this control which is grabbing the pointer |
|
2836 in systems implementing a single pointer. Or in a multi-pointer system where |
|
2837 single-pointer emulation is enabled on this control's window. |
|
2838 |
|
2839 @return The component control that is currently grabbing the pointer. If no |
|
2840 component of this control is grabbing the pointer, or if this |
|
2841 is not a compound control, the function returns NULL. */ |
|
2842 { |
|
2843 return GrabbingComponent(TAdvancedPointerEvent::EDefaultPointerNumber); |
|
2844 } |
|
2845 |
|
2846 EXPORT_C CCoeControl* CCoeControl::GrabbingComponent(TInt aPointer) const |
|
2847 /** Returns the component of this control which is grabbing the specified pointer. |
|
2848 This method is to be used on controls who's window has multiple-pointer events enabled. |
|
2849 |
|
2850 @return The component control that is currently grabbing the pointer. If no |
|
2851 component of this control is grabbing the pointer, or if this |
|
2852 is not a compound control, the function returns NULL. */ |
|
2853 { |
|
2854 const TInt count=CountComponentControls(); |
|
2855 |
|
2856 for (TInt ii=0; ii<count; ii++) |
|
2857 { |
|
2858 CCoeControl* ctrl=ComponentControl(ii); |
|
2859 if ( ctrl && ctrl->IsGrabbed(aPointer) ) |
|
2860 { |
|
2861 return(ctrl); |
|
2862 } |
|
2863 } |
|
2864 |
|
2865 return(NULL); |
|
2866 } |
|
2867 |
|
2868 TInt CCoeControl::FindColor(TInt aLogicalColor) const |
|
2869 { |
|
2870 CArrayFix<SColorOverride>* colorOverrides = DoGetColorOverrides(iData->DynamicDataStorage()); |
|
2871 if(colorOverrides) |
|
2872 { |
|
2873 TInt pos; |
|
2874 TKeyArrayFix key(4,ECmpTInt); |
|
2875 SColorOverride override; |
|
2876 override.iLogicalColor=aLogicalColor; |
|
2877 override.iColor=TRgb(); // ignore the actual color |
|
2878 if (colorOverrides->Find(override,key,pos)==KErrNone) |
|
2879 return pos; |
|
2880 } |
|
2881 return KErrNotFound; |
|
2882 } |
|
2883 |
|
2884 |
|
2885 EXPORT_C void CCoeControl::OverrideColorL(TInt aLogicalColor,TRgb aColor) |
|
2886 /** Overrides the control's colour setting, as specified in the application's colour |
|
2887 scheme. |
|
2888 |
|
2889 This function does not change the application's colour scheme. It changes |
|
2890 the colour mapping used in this control only. |
|
2891 |
|
2892 @param aLogicalColor The logical colour. Indicates which part of a control |
|
2893 the physical colour maps to. The set of logical colours for a standard application |
|
2894 are defined in TLogicalColor. |
|
2895 @param aColor The new physical colour to which the logical colour should be |
|
2896 mapped. |
|
2897 @see GetColor() */ |
|
2898 { |
|
2899 CArrayFix<SColorOverride>* colorOverrides = DoGetColorOverrides(iData->DynamicDataStorage()); |
|
2900 if (!colorOverrides) |
|
2901 { |
|
2902 colorOverrides=new(ELeave) CArrayFixFlat<SColorOverride>(2); |
|
2903 if(DoSetColorOverrides(iData->DynamicDataStorage(), colorOverrides) == KErrNoMemory) |
|
2904 { |
|
2905 delete colorOverrides; |
|
2906 User::LeaveNoMemory(); |
|
2907 } |
|
2908 } |
|
2909 |
|
2910 SColorOverride override; |
|
2911 override.iLogicalColor=aLogicalColor; |
|
2912 override.iColor=aColor; |
|
2913 const TInt index=FindColor(aLogicalColor); |
|
2914 if (index==KErrNotFound) |
|
2915 colorOverrides->AppendL(override); |
|
2916 else |
|
2917 (*colorOverrides)[index]=override; |
|
2918 |
|
2919 const TInt count=CountComponentControls(); |
|
2920 for (TInt ii=0; ii<count; ii++) |
|
2921 ComponentControl(ii)->OverrideColorL(aLogicalColor,aColor); |
|
2922 } |
|
2923 |
|
2924 EXPORT_C TBool CCoeControl::GetColor(TInt aLogicalColor,TRgb& aColor) const |
|
2925 /** Gets the overridden physical colour. |
|
2926 |
|
2927 This is the colour which has been mapped to the logical colour specified by |
|
2928 a call to OverrideColorL(). If the logical colour specified has not been overridden, |
|
2929 the aColor value is not changed. |
|
2930 |
|
2931 @param aLogicalColor The logical colour for which the corresponding physical |
|
2932 colour will be retrieved. The set of logical colours for a standard GUI application |
|
2933 are defined in TLogicalColor. |
|
2934 @param aColor On return, contains the physical colour which has been mapped |
|
2935 to aLogicalColour by a call to OverrideColorL(). |
|
2936 @return ETrue if aLogicalColour has been overridden, EFalse otherwise. */ |
|
2937 { |
|
2938 CArrayFix<SColorOverride>* colorOverrides = DoGetColorOverrides(iData->DynamicDataStorage()); |
|
2939 if(!colorOverrides) |
|
2940 return EFalse; |
|
2941 |
|
2942 const TInt index=FindColor(aLogicalColor); |
|
2943 if(index==KErrNotFound) |
|
2944 return EFalse; |
|
2945 |
|
2946 aColor=(*colorOverrides)[index].iColor; |
|
2947 return ETrue; |
|
2948 } |
|
2949 |
|
2950 |
|
2951 /** |
|
2952 Gets the input capabilities of the control and all its components. |
|
2953 |
|
2954 @since 6.0 |
|
2955 @return "TCoeInputCapabilities" |
|
2956 The input capabilities of the control. |
|
2957 */ |
|
2958 void CCoeControl::RecursivelyMergeInputCapabilities(TCoeInputCapabilities& aInputCapabilities) const |
|
2959 { |
|
2960 if (!IsBeingDestroyed()) |
|
2961 { |
|
2962 if (IsFocused()) |
|
2963 { |
|
2964 aInputCapabilities.MergeWith(InputCapabilities()); |
|
2965 } |
|
2966 for (TInt i=CountComponentControls()-1; i>=0; --i) |
|
2967 { |
|
2968 ComponentControl(i)->RecursivelyMergeInputCapabilities(aInputCapabilities); |
|
2969 } |
|
2970 } |
|
2971 } |
|
2972 |
|
2973 /** Gets the input capabilities of the control and all its components. |
|
2974 |
|
2975 @return The input capabilities of the control. */ |
|
2976 EXPORT_C TCoeInputCapabilities CCoeControl::RecursivelyMergedInputCapabilities() const |
|
2977 { |
|
2978 TCoeInputCapabilities inputCapabilities(TCoeInputCapabilities::ENone); |
|
2979 RecursivelyMergeInputCapabilities(inputCapabilities); |
|
2980 return inputCapabilities; |
|
2981 } |
|
2982 |
|
2983 |
|
2984 #ifndef _DEBUG |
|
2985 void CCoeControl::WriteInternalStateNowL(RWriteStream&) const |
|
2986 {} |
|
2987 #else |
|
2988 void CCoeControl::WriteInternalStateNowL(RWriteStream& aWriteStream) const |
|
2989 { |
|
2990 WriteInternalStateL(aWriteStream); |
|
2991 } |
|
2992 #endif |
|
2993 |
|
2994 |
|
2995 #ifdef _DEBUG |
|
2996 |
|
2997 |
|
2998 /** Writes the internal state of the control and its components to aWriteStream. |
|
2999 Does nothing in release builds. |
|
3000 This function is designed to be overidden and base called by subclasses |
|
3001 wishing to output state information. |
|
3002 |
|
3003 If overriding WriteInternalStateL(), the implementation must include a base call to CCoeControl's |
|
3004 WriteInternalStateL().*/ |
|
3005 EXPORT_C void CCoeControl::WriteInternalStateL(RWriteStream& aWriteStream) const |
|
3006 { |
|
3007 _LIT8(KCoeLitControlSt,"<CCoeControl>\r\n"); |
|
3008 _LIT8(KCoeLitControlEnd,"</CCoeControl>\r\n"); |
|
3009 TBuf8<100> element; |
|
3010 |
|
3011 aWriteStream.WriteL(KCoeLitControlSt); |
|
3012 |
|
3013 _LIT8(KCoeLitPosition, "<iPosition iX=\"%d\" iY=\"%d\"/>\r\n"); |
|
3014 element.Format(KCoeLitPosition,iPosition.iX,iPosition.iY); |
|
3015 aWriteStream.WriteL(element); |
|
3016 |
|
3017 _LIT8(KCoeLitSize, "<iSize iWidth=\"%d\" iHeight=\"%d\"/>\r\n"); |
|
3018 element.Format(KCoeLitSize,iSize.iWidth,iSize.iHeight); |
|
3019 aWriteStream.WriteL(element); |
|
3020 |
|
3021 // extension stuff |
|
3022 _LIT8(KCoeLitFlags, "<Flags value=\"0x%08x\"/>\r\n"); |
|
3023 element.Format(KCoeLitFlags,iFlags); |
|
3024 aWriteStream.WriteL(element); |
|
3025 |
|
3026 _LIT8(KCoeLitColors, "<ColorOverrides>\r\n"); |
|
3027 _LIT8(KCoeLitColorsEnd, "</ColorOverrides>\r\n"); |
|
3028 aWriteStream.WriteL(KCoeLitColors); |
|
3029 |
|
3030 CArrayFix<SColorOverride>* colorOverrides = DoGetColorOverrides(iData->DynamicDataStorage()); |
|
3031 if (colorOverrides) |
|
3032 { |
|
3033 TBuf8<8> integer; |
|
3034 const TInt count=colorOverrides->Count(); |
|
3035 for(TInt i=0; i<count; i++) |
|
3036 { |
|
3037 const SColorOverride& colOvrride=(*colorOverrides)[i]; |
|
3038 integer.Num(MAKE_TINT64(0,colOvrride.iColor.Color16M())); |
|
3039 aWriteStream.WriteL(integer); |
|
3040 integer.Num(MAKE_TINT64(0,colOvrride.iLogicalColor)); |
|
3041 aWriteStream.WriteL(integer); |
|
3042 } |
|
3043 } |
|
3044 aWriteStream.WriteL(KCoeLitColorsEnd); |
|
3045 |
|
3046 const TInt components=CountComponentControls(); |
|
3047 _LIT8(KCoeLitComponent,"<Component>\r\n"); |
|
3048 _LIT8(KCoeLitComponentEnd,"</Component>\r\n"); |
|
3049 // |
|
3050 for(TInt i=0;i<components;i++) |
|
3051 { |
|
3052 aWriteStream.WriteL(KCoeLitComponent); |
|
3053 // |
|
3054 ComponentControl(i)->WriteInternalStateL(aWriteStream); |
|
3055 // |
|
3056 aWriteStream.WriteL(KCoeLitComponentEnd); |
|
3057 } |
|
3058 aWriteStream.WriteL(KCoeLitControlEnd); |
|
3059 } |
|
3060 #else |
|
3061 EXPORT_C void CCoeControl::WriteInternalStateL(RWriteStream&) const |
|
3062 {} |
|
3063 #endif |
|
3064 |
|
3065 EXPORT_C void CCoeControl::Reserved_2() |
|
3066 { |
|
3067 } |
|
3068 |
|
3069 /** Sets the context - that is, the enclosing parent control - for this control. |
|
3070 If setting aParent as MopParent of this control creates a cyclic relationship, |
|
3071 this method will do nothing. |
|
3072 |
|
3073 @param aParent The parent object which is the context for the control. */ |
|
3074 EXPORT_C void CCoeControl::SetMopParent(MObjectProvider* aParent) |
|
3075 { |
|
3076 if (aParent) |
|
3077 { |
|
3078 const MObjectProvider* mopParent = aParent->FindParent(static_cast<MObjectProvider*>(this)); |
|
3079 if (mopParent) |
|
3080 return; |
|
3081 } |
|
3082 iMopParent = aParent; |
|
3083 } |
|
3084 |
|
3085 /** Retrieves an object of the same type as that encapsulated in aId. |
|
3086 |
|
3087 This function is used to allow controls to ask their owners for access to |
|
3088 other objects that they own. |
|
3089 |
|
3090 Other than in the case where NULL is returned, the object returned must be |
|
3091 of the same object type - that is, the ETypeId member of the object pointed |
|
3092 to by the pointer returned by this function must be equal to the iUid member |
|
3093 of aId. |
|
3094 |
|
3095 @param aId An encapsulated object type ID. |
|
3096 @return Encapsulates the pointer to the object provided. Note that the encapsulated |
|
3097 pointer may be NULL. */ |
|
3098 EXPORT_C TTypeUid::Ptr CCoeControl::MopSupplyObject(TTypeUid /*aId*/) |
|
3099 { |
|
3100 return TTypeUid::Null(); |
|
3101 } |
|
3102 |
|
3103 |
|
3104 /** Retrieves the control's parent. |
|
3105 |
|
3106 This function may be overridden to continue the |
|
3107 chain of object providers which are to be asked to supply an object. |
|
3108 |
|
3109 When overriding this function for any given class of control, it is important |
|
3110 to ensure that the function does not return, either directly or indirectly, |
|
3111 a pointer to the instance of that class on which the function was called. |
|
3112 For example, suppose that bar is an object of class foo. The override for |
|
3113 the class foo could legitimately return a pointer to the object provider in |
|
3114 which bar is contained, but must never return a pointer either to bar or to |
|
3115 an object provider which may return bar. Failure to observe this restriction |
|
3116 may result in an infinite loop. |
|
3117 |
|
3118 @return A pointer to an object provider, or NULL if none is defined. |
|
3119 @publishedAll |
|
3120 @released */ |
|
3121 EXPORT_C MObjectProvider* CCoeControl::MopNext() |
|
3122 { |
|
3123 return iMopParent; |
|
3124 } |
|
3125 |
|
3126 // TEXT DRAWER |
|
3127 |
|
3128 |
|
3129 /** |
|
3130 Gets the text drawer to be used for the control. |
|
3131 This method returns a reference simply because the return value must never be NULL. |
|
3132 The ownership transfer rules of the returned CCoeTextDrawerBase object obey specific rules. |
|
3133 If the CCoeTextDrawerBase::IsReusable() flag is set then the caller must call Reset when the object |
|
3134 is not needed anymore else it should simply delete the object. The XCoeTextDrawer class is a wrapper |
|
3135 around the CCoeTextDrawerBase that will implement this logic automatically. |
|
3136 The method will start with the default text drawer. |
|
3137 It then allows the childs background control to change the text drawer if the child itself is window owning. |
|
3138 Otherwise only the parent control can change the text drawer. |
|
3139 |
|
3140 |
|
3141 @param aKey This parameter can be used by clients that need some custom behaviour. The framework |
|
3142 doesn't use this parameter. |
|
3143 @return reference to a CCoeTextDrawerBase object |
|
3144 */ |
|
3145 EXPORT_C CCoeTextDrawerBase& CCoeControl::TextDrawer(TInt aKey) const |
|
3146 { |
|
3147 // Get the default text drawer |
|
3148 CCoeTextDrawerBase* textDrawer = &iCoeEnv->DefaultTextDrawer(); |
|
3149 |
|
3150 // Retrieve a background object |
|
3151 const MCoeControlBackground* background = FindBackground(); |
|
3152 |
|
3153 // Let the text drawer be updated according to the background object |
|
3154 if(background) |
|
3155 background->GetTextDrawer(textDrawer, this); |
|
3156 |
|
3157 // Let the text drawer be updated according to the text drawers of the |
|
3158 // parent hierarchy. |
|
3159 RecursivelyMergeTextDrawers(textDrawer, this, aKey); |
|
3160 |
|
3161 return *textDrawer; |
|
3162 } |
|
3163 |
|
3164 |
|
3165 /** |
|
3166 This method recursively merges the control's parents' text drawers if it is non-window owning. If a parent control creates |
|
3167 a new text drawer, this method makes sure that the old one is deleted or reset. |
|
3168 |
|
3169 |
|
3170 |
|
3171 @param aTextDrawer reference to the CCoeTextDrawerBase object to be updated |
|
3172 @param aKey TInt |
|
3173 @return void |
|
3174 */ |
|
3175 void CCoeControl::RecursivelyMergeTextDrawers(CCoeTextDrawerBase*& aTextDrawer, |
|
3176 const CCoeControl* aDrawingControl, TInt aKey) const |
|
3177 { |
|
3178 const CCoeControl* parent = Parent(); |
|
3179 if(parent && !OwnsWindow()) |
|
3180 parent->RecursivelyMergeTextDrawers(aTextDrawer, aDrawingControl, aKey); |
|
3181 |
|
3182 CCoeTextDrawerBase* oldTextDrawer = aTextDrawer; |
|
3183 GetTextDrawer(aTextDrawer, aDrawingControl, aKey); |
|
3184 |
|
3185 if(!aTextDrawer) // in case allocation of new text drawer failed |
|
3186 aTextDrawer = oldTextDrawer; |
|
3187 |
|
3188 if(aTextDrawer != oldTextDrawer) // delete or reset the old text drawer |
|
3189 // if a new one was created |
|
3190 { |
|
3191 if(!oldTextDrawer->IsReusable()) |
|
3192 delete oldTextDrawer; |
|
3193 else |
|
3194 oldTextDrawer->Reset(); |
|
3195 } |
|
3196 } |
|
3197 |
|
3198 |
|
3199 /** |
|
3200 Controls that want to change or replace the text drawer that it or its children |
|
3201 controls use shall override this method. The aTextDrawer argument is guaranteed |
|
3202 never to be NULL, and the control can choose to modify it or create a new |
|
3203 text drawer in its place. |
|
3204 */ |
|
3205 EXPORT_C void CCoeControl::GetTextDrawer(CCoeTextDrawerBase*& /*aTextDrawer*/, const CCoeControl* /*aDrawingControl*/, TInt /*aKey*/) const |
|
3206 {} |
|
3207 |
|
3208 |
|
3209 EXPORT_C CCoeControl* CCoeControl::Parent() |
|
3210 { |
|
3211 return DoGetParent(iData->DynamicDataStorage()); |
|
3212 } |
|
3213 |
|
3214 EXPORT_C const CCoeControl* CCoeControl::Parent() const |
|
3215 { |
|
3216 return DoGetParent(iData->DynamicDataStorage()); |
|
3217 } |
|
3218 |
|
3219 /** |
|
3220 Gets the offset to the first text baseline relative to the top of the control. |
|
3221 |
|
3222 The default implementation calls CalcTextBaselineOffset of the layout manager if |
|
3223 one is installed. It returns 0 if no layout manager is installed. |
|
3224 |
|
3225 Derived classes that don't want to use the layout manager and still want to |
|
3226 return a baseline offset should re-implement this function. |
|
3227 |
|
3228 @param aRect The offset of the baseline may depend on the size of the control. This argument specifies the size to use when computing the baseline offset. |
|
3229 @return The offset of the baseline from the top of the control. |
|
3230 */ |
|
3231 EXPORT_C TInt CCoeControl::TextBaselineOffset(const TSize& aSize) const |
|
3232 { |
|
3233 TInt retval = 0; |
|
3234 if(LayoutManager()) |
|
3235 retval = LayoutManager()->CalcTextBaselineOffset(*this, aSize); |
|
3236 return retval; |
|
3237 } |
|
3238 |
|
3239 /** |
|
3240 Sets the spacing between text baselines. |
|
3241 |
|
3242 The default implementation calls SetTextBaselineSpacing of the layout manager if one is installed. It does nothing if there is no layout manager. |
|
3243 |
|
3244 Derived classes that don't want to use the layout manager and still want to do something when the this function is called should re-implement it. |
|
3245 |
|
3246 @param aBaselineSpacing The baseline spacing i.e. the space in pixels between the text baselines. |
|
3247 */ |
|
3248 EXPORT_C void CCoeControl::SetTextBaselineSpacing(TInt aBaselineSpacing) |
|
3249 { |
|
3250 if(LayoutManager()) |
|
3251 LayoutManager()->SetTextBaselineSpacing(aBaselineSpacing); |
|
3252 } |
|
3253 |
|
3254 /** |
|
3255 * Returns a Unique Handle (identifier) previously allocated to the control. |
|
3256 * |
|
3257 * @see SetUniqueHandle |
|
3258 * @return Previously allocated value. |
|
3259 */ |
|
3260 EXPORT_C TInt CCoeControl::UniqueHandle() const |
|
3261 { |
|
3262 return DoGetUniqueHandle(iData->DynamicDataStorage()); |
|
3263 } |
|
3264 |
|
3265 /** |
|
3266 * Sets a Unique Handle (identifier). That the number is unique is the perogative |
|
3267 * of the caller! |
|
3268 * |
|
3269 * @see UniqueHandle() |
|
3270 * @param a number. This number is used to identify this control |
|
3271 * @return Standard error code |
|
3272 */ |
|
3273 EXPORT_C TInt CCoeControl::SetUniqueHandle( TInt aUniqueHandle ) |
|
3274 { |
|
3275 return DoSetUniqueHandle(iData->DynamicDataStorage(), aUniqueHandle); |
|
3276 } |
|
3277 |
|
3278 /** Sets the layout manager |
|
3279 |
|
3280 If the control already has a layout manager, its <code>MCoeLayoutManager::Detatch()</code> is called. |
|
3281 <code>MCoeLayoutManager::Attach()</code> is called on <code>aLayout</code> |
|
3282 |
|
3283 The control doesn't take ownership of the Layout manager. |
|
3284 |
|
3285 @see MCoeLayoutManager::Attach |
|
3286 @param aLayout The new layout manager, <code>NULL</code> if you just want to remove the current |
|
3287 layout manager. |
|
3288 */ |
|
3289 EXPORT_C void CCoeControl::SetLayoutManagerL(MCoeLayoutManager* aLayout) |
|
3290 { |
|
3291 MCoeLayoutManager* layout = LayoutManager(); |
|
3292 if (layout) |
|
3293 layout->Detach(*this); |
|
3294 |
|
3295 User::LeaveIfError(DoSetLayoutManager(iData->DynamicDataStorage(), NULL)); |
|
3296 |
|
3297 if (aLayout) |
|
3298 aLayout->AttachL(*this); |
|
3299 |
|
3300 User::LeaveIfError(DoSetLayoutManager(iData->DynamicDataStorage(), aLayout)); |
|
3301 } |
|
3302 |
|
3303 /** Gets the layout manager |
|
3304 @return The current layout manager, or <code>NULL</code> if the control has no layout manager |
|
3305 */ |
|
3306 EXPORT_C MCoeLayoutManager* CCoeControl::LayoutManager() const |
|
3307 { |
|
3308 // Try to retrieve the layout manager if one has been set, otherwise return NULL. |
|
3309 return DoGetLayoutManager(iData->DynamicDataStorage()); |
|
3310 } |
|
3311 |
|
3312 /** Requests a relayout |
|
3313 |
|
3314 The default implementation is to call the parents <code>RequestRelayout()</code>. |
|
3315 |
|
3316 Should normally be overridden by top-level controls, such as scrollable containers. Classes that |
|
3317 override this function must ensure that they don't cause infinite loops, since a relayout might |
|
3318 cause calls to <code>RequestRelayout()</code> itself, This might be solved like this: |
|
3319 @code |
|
3320 TBool CAnyControl::RequestRelayout(const CCoeControl* aChildControl) |
|
3321 { |
|
3322 if(iRelayoutInProgress) return EFalse; |
|
3323 iRelayoutInProgress = ETrue; |
|
3324 //perform the relayout |
|
3325 iRelayoutInProgress = EFalse; |
|
3326 return ETrue; |
|
3327 } |
|
3328 @endcode |
|
3329 |
|
3330 When the request is addressed the requesting control knows that its <code>SizeChanged()</code> |
|
3331 will be called. |
|
3332 |
|
3333 @param aChildControl The child control that requests the relayout, might be <code>NULL</code> |
|
3334 @return <code>ETrue</code> if the request is addressed, otherwise <code>EFalse</code> |
|
3335 */ |
|
3336 EXPORT_C TBool CCoeControl::RequestRelayout(const CCoeControl* aChildControl) |
|
3337 { |
|
3338 TBool reqComplete = EFalse; |
|
3339 if(aChildControl && !aChildControl->IsActivated()) |
|
3340 { |
|
3341 reqComplete = EFalse; |
|
3342 } |
|
3343 else if(Parent()) |
|
3344 { |
|
3345 reqComplete = Parent()->RequestRelayout(this); |
|
3346 } |
|
3347 return reqComplete; |
|
3348 } |
|
3349 |
|
3350 |
|
3351 void CCoeControl::RemoveFromParent() |
|
3352 { |
|
3353 CCoeControl* parent = Parent(); |
|
3354 if (parent) |
|
3355 { |
|
3356 parent->Components().Remove(this); |
|
3357 } |
|
3358 } |
|
3359 |
|
3360 /** |
|
3361 Set the status of the report control state change. |
|
3362 @param aState Set the state as Enable or Disable to control the report control state change. |
|
3363 @see SetDimmed(), MakeVisible() |
|
3364 */ |
|
3365 EXPORT_C void CCoeControl::EnableReportControlStateChange(TBool aState) |
|
3366 { |
|
3367 if(aState) |
|
3368 { |
|
3369 iFlags |= EReportControlStateChange; |
|
3370 } |
|
3371 else |
|
3372 { |
|
3373 iFlags &= ~EReportControlStateChange; |
|
3374 } |
|
3375 } |
|
3376 |
|
3377 /** @internalComponent */ |
|
3378 EXPORT_C void CCoeControl::Reserved_CCoeControl_8() |
|
3379 { |
|
3380 } |
|
3381 |
|
3382 /** @internalComponent */ |
|
3383 EXPORT_C void CCoeControl::Reserved_CCoeControl_9() |
|
3384 { |
|
3385 } |
|
3386 |
|
3387 /** @internalComponent */ |
|
3388 EXPORT_C void CCoeControl::Reserved_CCoeControl_10() |
|
3389 { |
|
3390 } |
|
3391 |
|
3392 /** @internalComponent */ |
|
3393 EXPORT_C void CCoeControl::Reserved_CCoeControl_11() |
|
3394 { |
|
3395 } |
|
3396 |
|
3397 /** @internalComponent */ |
|
3398 EXPORT_C void CCoeControl::Reserved_CCoeControl_12() |
|
3399 { |
|
3400 } |
|
3401 |
|
3402 /** @internalComponent */ |
|
3403 EXPORT_C void CCoeControl::Reserved_CCoeControl_13() |
|
3404 { |
|
3405 } |
|
3406 |
|
3407 /** |
|
3408 Default empty method. |
|
3409 @param aTextDrawer Not used. |
|
3410 @param aDrawingControl Not used. |
|
3411 */ |
|
3412 EXPORT_C void MCoeControlBackground::GetTextDrawer(CCoeTextDrawerBase*& /*aTextDrawer*/, const CCoeControl* /*aDrawingControl*/) const |
|
3413 {} |
|
3414 |
|
3415 // For future use |
|
3416 EXPORT_C void MCoeControlBackground::MCoeControlBackground_Reserved1() {} |
|
3417 EXPORT_C void MCoeControlBackground::MCoeControlBackground_Reserved2() {} |
|
3418 EXPORT_C void MCoeControlBackground::MCoeControlBackground_Reserved3() {} |
|
3419 EXPORT_C void MCoeControlBackground::MCoeControlBackground_Reserved4() {} |
|
3420 EXPORT_C void MCoeControlBackground::MCoeControlBackground_Reserved5() {} |
|
3421 |
|
3422 |
|
3423 // |
|
3424 // From coecntrl.h (MCoeLayoutManager) |
|
3425 // |
|
3426 |
|
3427 EXPORT_C MCoeLayoutManager::MCoeLayoutManager() : iMCoeLayoutManager_Reserved1(0) {} |
|
3428 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_1() {} |
|
3429 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_2() {} |
|
3430 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_3() {} |
|
3431 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_4() {} |
|
3432 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_5() {} |
|
3433 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_6() {} |
|
3434 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_7() {} |
|
3435 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_8() {} |
|
3436 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_9() {} |
|
3437 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_10() {} |
|
3438 EXPORT_C void MCoeLayoutManager::Reserved_MCoeLayoutManager_11() {} |
|
3439 |
|
3440 // |
|
3441 // From coecntrl.h (MCoeControlBackground) |
|
3442 // |
|
3443 |
|
3444 EXPORT_C MCoeControlBackground::MCoeControlBackground() {} |
|
3445 |
|
3446 // |
|
3447 // From coecntrl.h (MCoeControlHitTest) |
|
3448 // |
|
3449 |
|
3450 EXPORT_C MCoeControlHitTest::MCoeControlHitTest() : iMCoeControlHitTest_Reserved1(0) {} |
|
3451 EXPORT_C void MCoeControlHitTest::MCoeControlHitTest_Reserved1() {} |
|
3452 EXPORT_C void MCoeControlHitTest::MCoeControlHitTest_Reserved2() {} |
|
3453 |
|
3454 |
|
3455 // |
|
3456 // From coecobs.h (MCoeControlObserver) |
|
3457 // |
|
3458 |
|
3459 EXPORT_C MCoeControlObserver::MCoeControlObserver() : iMCoeControlObserver_Reserved1(0) {} |
|
3460 EXPORT_C void MCoeControlObserver::MCoeControlObserver_Reserved1() {} |
|
3461 EXPORT_C void MCoeControlObserver::MCoeControlObserver_Reserved2() {} |