|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Emergency number dialog |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "lockappecsnote.h" |
|
20 #include "lockapputils.h" |
|
21 #include <AknUtils.h> |
|
22 #include <aknlayoutscalable_avkon.cdl.h> |
|
23 #include <aknappui.h> |
|
24 #include <AknEcs.h> // for KAknEcsMaxMatchingLength |
|
25 |
|
26 #include <aknglobalpopupprioritycontroller.h> |
|
27 #include <GlobalWindowPriorities.h> |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // Standard C++ constructor |
|
31 // --------------------------------------------------------------------------- |
|
32 CLockAppEcsNote::CLockAppEcsNote( ) : |
|
33 iNoteOnScreen(EFalse) |
|
34 { |
|
35 // no implementation required |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Destructor. |
|
40 // --------------------------------------------------------------------------- |
|
41 CLockAppEcsNote::~CLockAppEcsNote( ) |
|
42 { |
|
43 #ifdef _GLOBAL_PRIORITY_SUPPORTED |
|
44 AknGlobalPopupPriorityController::RemovePopupPriority(*this); |
|
45 #endif |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Emergency note is a sleeping note |
|
50 // --------------------------------------------------------------------------- |
|
51 void CLockAppEcsNote::ConstructSleepingNoteL(TInt aResourceId ) |
|
52 { |
|
53 CAknNoteDialog::ConstructSleepingDialogL( aResourceId ); |
|
54 #ifdef _GLOBAL_PRIORITY_SUPPORTED |
|
55 // global ui component order is handled trhoug global popup priority controller |
|
56 AknGlobalPopupPriorityController::SetPopupPriorityL( *this, KGlobalWindowPriority_KeyLock ); |
|
57 #endif |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Show note with time out. |
|
62 // --------------------------------------------------------------------------- |
|
63 TInt CLockAppEcsNote::ShowNote( ) |
|
64 { |
|
65 ReportUserActivity( ); |
|
66 iTimeoutInMicroseconds = CAknNoteDialog::EUndefinedTimeout; |
|
67 iTone = CAknNoteDialog::ENoTone; |
|
68 TInt error = KErrNone; |
|
69 if ( !iNoteOnScreen ) |
|
70 { |
|
71 error = RouseSleepingDialog( ); |
|
72 } |
|
73 iNoteOnScreen = ETrue; |
|
74 // return value not used |
|
75 return error; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Hide note from screen. |
|
80 // --------------------------------------------------------------------------- |
|
81 void CLockAppEcsNote::SleepNote( ) |
|
82 { |
|
83 if ( iNoteOnScreen ) |
|
84 { |
|
85 ExitSleepingDialog( ); // Causes flicker to other notes if called when note is not on screen |
|
86 } |
|
87 iNoteOnScreen = EFalse; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Emergency dialog consumes all key events it receives. |
|
92 // --------------------------------------------------------------------------- |
|
93 TKeyResponse CLockAppEcsNote::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/) |
|
94 { |
|
95 return EKeyWasConsumed; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // Format the emergency number for the dialog text. |
|
100 // --------------------------------------------------------------------------- |
|
101 void CLockAppEcsNote::SetEmergencyNumber( const TDesC& aMatchedNumber ) |
|
102 { |
|
103 TRect mainPaneRect; |
|
104 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect ); |
|
105 TAknLayoutRect popupNoteWindow; |
|
106 AknLayoutUtils::TAknCbaLocation cbaLocation( AknLayoutUtils::CbaLocation( )); |
|
107 TInt variety( 0); |
|
108 if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight ) |
|
109 { |
|
110 variety = 5; |
|
111 } |
|
112 else |
|
113 if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft ) |
|
114 { |
|
115 variety = 8; |
|
116 } |
|
117 else |
|
118 { |
|
119 variety = 2; |
|
120 } |
|
121 |
|
122 popupNoteWindow.LayoutRect( mainPaneRect, AknLayoutScalable_Avkon::popup_note_window( variety ) ); |
|
123 TAknLayoutText textRect; |
|
124 textRect.LayoutText( popupNoteWindow.Rect( ), AknLayoutScalable_Avkon::popup_note_window_t5(2).LayoutLine( ) ); |
|
125 |
|
126 // Size of a temporary buffer that contains new lines, spaces and |
|
127 // emergency number for a note. |
|
128 TBuf16<KAknEcsMaxMatchingLength+80> number; |
|
129 number.Append( '\n' ); |
|
130 number.Append( '\n' ); |
|
131 |
|
132 TInt spaceCharWidthInPixels = textRect.Font()->CharWidthInPixels( ' ' ); |
|
133 if ( spaceCharWidthInPixels < 1 ) |
|
134 { |
|
135 // Avoid divide by zero situation even the space char would have zero length. |
|
136 spaceCharWidthInPixels = 1; |
|
137 } |
|
138 |
|
139 TInt length = (textRect.TextRect().Width() - textRect.Font()->TextWidthInPixels(aMatchedNumber))/ spaceCharWidthInPixels; |
|
140 |
|
141 const TInt matchedNumberLength = aMatchedNumber.Length( ); |
|
142 const TInt numberLength = number.Length( ); |
|
143 const TInt numberMaxLength = number.MaxLength( ); |
|
144 |
|
145 if ( numberLength + length + matchedNumberLength > numberMaxLength ) |
|
146 { |
|
147 // To make sure that buffer overflow does not happen. |
|
148 length = numberMaxLength - numberLength - matchedNumberLength; |
|
149 } |
|
150 for (int i = 0; i < length; i++ ) |
|
151 { |
|
152 number.Append( ' ' ); |
|
153 } |
|
154 |
|
155 number.Append( aMatchedNumber ); |
|
156 TRAP_IGNORE(SetTextL(number)); |
|
157 } |