|
1 /* |
|
2 * Copyright (c) 1997-1999 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikalert.h> |
|
20 #include <eikon.hrh> |
|
21 #include <eikcdlg.rsg> |
|
22 #include <eikappui.h> |
|
23 |
|
24 #include <aknnotecontrol.h> |
|
25 #include <AknGlobalNote.h> |
|
26 #include <AknCapServerDefs.h> |
|
27 #include <AknSgcc.h> |
|
28 |
|
29 |
|
30 const TInt KEikAlertMaxMsgLength=17; // Maximum characters that fit on Avkon note |
|
31 const TInt KCbaPriorityOffset = 10; |
|
32 const TUint KCombinedBufferMaxLength = 80; // used with notifs |
|
33 |
|
34 _LIT(KENDL,"\n"); |
|
35 |
|
36 |
|
37 void CEikAlert::ConstructL() |
|
38 { |
|
39 ConstructSleepingDialogL(R_EIK_DIALOG_ALERT); |
|
40 |
|
41 // preallocate text, |
|
42 TBuf< KEikAlertMaxMsgLength*2 +1> buffer; |
|
43 buffer.SetLength( KEikAlertMaxMsgLength*2 +1); |
|
44 buffer.Fill( '1' ); |
|
45 |
|
46 buffer.Replace( KEikAlertMaxMsgLength, 1, KENDL); |
|
47 SetTextL( buffer ); |
|
48 |
|
49 Window().SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront-1); |
|
50 } |
|
51 |
|
52 void CEikAlert::RunAlert(const TDesC& aMsg1,const TDesC& aMsg2) |
|
53 { |
|
54 iMsg1=(&aMsg1); |
|
55 iMsg2=(&aMsg2); |
|
56 RouseSleepingDialog(); |
|
57 } |
|
58 |
|
59 void CEikAlert::Release() |
|
60 { |
|
61 delete this; |
|
62 } |
|
63 |
|
64 CEikDialog* CEikAlert::AsEikDialog() |
|
65 { |
|
66 return this; |
|
67 } |
|
68 |
|
69 void CEikAlert::PreLayoutDynInitL() |
|
70 { |
|
71 TBuf< KEikAlertMaxMsgLength*2 + 1 > buffer; |
|
72 |
|
73 if ( iMsg1->Length() > KEikAlertMaxMsgLength ) |
|
74 { |
|
75 buffer.Copy( iMsg1->Left( KEikAlertMaxMsgLength ) ); |
|
76 } |
|
77 else |
|
78 { |
|
79 buffer.Copy( *iMsg1 ); |
|
80 } |
|
81 |
|
82 if ( iMsg2->Length() ) |
|
83 { |
|
84 buffer.Append( '\n' ); |
|
85 } |
|
86 |
|
87 if ( iMsg2->Length() > KEikAlertMaxMsgLength ) |
|
88 { |
|
89 buffer.Append( iMsg2->Left( KEikAlertMaxMsgLength ) ); |
|
90 } |
|
91 else |
|
92 { |
|
93 buffer.Append( *iMsg2 ); |
|
94 } |
|
95 |
|
96 // This cannot leave because long enough text has been preallocated |
|
97 // in ConstructL. |
|
98 SetNoMemoryAllocation(); |
|
99 SetTextL( buffer ); |
|
100 |
|
101 // Update CBA stack priority, to match dialog priority |
|
102 CCoeControl* cba = ButtonGroupContainer().ButtonGroup()->AsControl(); |
|
103 iEikonEnv->RemoveFromStack(cba); |
|
104 iEikonEnv->EikAppUi()->AddToStackL(cba, ECoeStackPriorityAlert+KCbaPriorityOffset, ECoeStackFlagRefusesFocus); // Won't fail since we just removed it (and array will not reallocate) |
|
105 } |
|
106 |
|
107 EXPORT_C void CEikAlert::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
108 { |
|
109 CAknNoteDialog::HandlePointerEventL(aPointerEvent); |
|
110 } |
|
111 |
|
112 EXPORT_C void* CEikAlert::ExtensionInterface( TUid /*aInterface*/ ) |
|
113 { |
|
114 return NULL; |
|
115 } |
|
116 |
|
117 void CEikAlert::CEikDialog_Reserved_1() |
|
118 { |
|
119 } |
|
120 |
|
121 void CEikAlert::CEikDialog_Reserved_2() |
|
122 { |
|
123 } |
|
124 |
|
125 void CEikAlert::CAknNoteDialog_Reserved() |
|
126 { |
|
127 } |
|
128 |
|
129 CEikAlertNotifier::~CEikAlertNotifier() |
|
130 { |
|
131 delete iLocalDialog; |
|
132 delete iNotifierBuffer; |
|
133 } |
|
134 |
|
135 void CEikAlertNotifier::ConstructL() |
|
136 { |
|
137 iNotifierBuffer = CBufFlat::NewL(0); // no need to expand later on |
|
138 iNotifierBuffer->SetReserveL(200); // about 80 chars and control bytes |
|
139 RThread r; |
|
140 if (r.Name().CompareF(KAknCapServerThreadName) == 0) |
|
141 { |
|
142 CreateLocalDialogIfRequired(); |
|
143 } |
|
144 |
|
145 } |
|
146 |
|
147 class RAknUiServer2: public RAknUiServer |
|
148 { |
|
149 public: |
|
150 void DoSendNotifBuf(TPtrC8& aPtr) |
|
151 { |
|
152 TPckgBuf<SAknGlobalNoteReturnParams> retPckg; |
|
153 SendReceive(EStartNotifier,TIpcArgs(KAknGlobalNoteUid.iUid,&aPtr, &retPckg)); |
|
154 } |
|
155 }; |
|
156 |
|
157 |
|
158 void CEikAlertNotifier::RunAlert(const TDesC& aTitle, const TDesC& aMsg) |
|
159 { |
|
160 RAknUiServer2* client = (RAknUiServer2*) CAknSgcClient::AknSrv(); |
|
161 if (!client || client->Handle() == 0) |
|
162 { |
|
163 CreateLocalDialogIfRequired(); |
|
164 if (iLocalDialog) |
|
165 iLocalDialog->RunAlert(aTitle, aMsg); |
|
166 return; |
|
167 } |
|
168 |
|
169 TBuf<KCombinedBufferMaxLength> combinedBuffer; // so sad, too bad |
|
170 combinedBuffer.Append(aTitle.Left(Min(aTitle.Length(), KCombinedBufferMaxLength))); |
|
171 if (combinedBuffer.Length() < KCombinedBufferMaxLength-1 && aMsg.Length()) |
|
172 { |
|
173 combinedBuffer.Append(KENDL); |
|
174 combinedBuffer.Append(aMsg.Left(Min(KCombinedBufferMaxLength-combinedBuffer.Length(),aMsg.Length()))); |
|
175 } |
|
176 CAknGlobalNote::DoGlobaNoteBufferL( |
|
177 EAknGlobalWarningNote, |
|
178 0, |
|
179 R_AVKON_SOFTKEYS_OK_EMPTY, |
|
180 -1, |
|
181 -1, |
|
182 -1, |
|
183 -1, |
|
184 EFalse, |
|
185 ETrue, |
|
186 combinedBuffer, |
|
187 iNotifierBuffer |
|
188 ); |
|
189 |
|
190 TPtrC8 bufferPtr; |
|
191 bufferPtr.Set(iNotifierBuffer->Ptr(0)); |
|
192 |
|
193 client->DoSendNotifBuf(bufferPtr); |
|
194 } |
|
195 |
|
196 void CEikAlertNotifier::Release() |
|
197 { |
|
198 delete this; |
|
199 } |
|
200 |
|
201 CEikDialog* CEikAlertNotifier::AsEikDialog() |
|
202 { |
|
203 CreateLocalDialogIfRequired(); |
|
204 return iLocalDialog; |
|
205 } |
|
206 |
|
207 void CEikAlertNotifier::CreateLocalDialogIfRequired() |
|
208 { |
|
209 if (!iLocalDialog) |
|
210 { |
|
211 iLocalDialog = new CEikAlert; |
|
212 if (iLocalDialog) |
|
213 { |
|
214 TRAPD(err, iLocalDialog->ConstructL()); |
|
215 if (err) |
|
216 { |
|
217 delete iLocalDialog; |
|
218 iLocalDialog = 0; |
|
219 } |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 |