|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Base class for bio controls |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <msvapi.h> // MTM server API |
|
24 #include <AknQueryDialog.h> |
|
25 #include <eikmenup.h> |
|
26 #include <bautils.h> // for BaflUtils |
|
27 #include <MsgEditorUtils.rsg> // resouce identifiers |
|
28 #include <StringLoader.h> // StringLoader |
|
29 #include <msgbiocontrolObserver.h> |
|
30 #include "msgbiocontrol.h" // for CMsgBioControl |
|
31 #include "MMsgBioControlExtension.h" // MMsgBioControlExtension |
|
32 #include "MsgEditorUtils.pan" // for MsgEditorUtils panics |
|
33 #include <data_caging_path_literals.hrh> |
|
34 |
|
35 // CONSTANTS |
|
36 _LIT(KMsgEditorUtilsResource, "msgeditorutils.rsc"); |
|
37 enum TStatusFlags |
|
38 { |
|
39 EFileBased = KBit0 |
|
40 }; |
|
41 |
|
42 // ================= MEMBER FUNCTIONS ======================= |
|
43 |
|
44 EXPORT_C CMsgBioControl::CMsgBioControl(MMsgBioControlObserver& aObserver, |
|
45 CMsvSession* aSession, //no ownership |
|
46 TMsvId aId, |
|
47 TMsgBioMode aEditorOrViewerMode, |
|
48 const RFile* aFile): |
|
49 iBioControlObserver(aObserver), |
|
50 iId(aId), |
|
51 iMsvSession(aSession), |
|
52 iMode(aEditorOrViewerMode), |
|
53 iFile(aFile), |
|
54 iBCStatusFlags(0) |
|
55 { |
|
56 // If aFile presents real file, subsession handle > 0 |
|
57 // If aFile is dummy file handle ==> subsession handle == 0 |
|
58 if (aFile) |
|
59 { |
|
60 if( aFile->SubSessionHandle() == 0) |
|
61 { |
|
62 iFile = NULL; |
|
63 } |
|
64 else |
|
65 { |
|
66 iFile = aFile; |
|
67 iBCStatusFlags |= EFileBased; |
|
68 } |
|
69 } |
|
70 __ASSERT_ALWAYS( |
|
71 ( ( (aEditorOrViewerMode==EMsgBioEditorMode) || |
|
72 (aEditorOrViewerMode==EMsgBioViewerMode) ) |
|
73 && |
|
74 ( (aSession && aId) ^ (IsFileBased()) ) |
|
75 ), |
|
76 Panic( EMEUErrArgument ) ); |
|
77 } |
|
78 |
|
79 EXPORT_C CMsgBioControl::~CMsgBioControl() |
|
80 { |
|
81 if (iResourceOffsets) |
|
82 { |
|
83 for (TInt n(0); n < iResourceOffsets->Count(); n++) |
|
84 { |
|
85 iCoeEnv->DeleteResourceFile(iResourceOffsets->At(n)); |
|
86 } |
|
87 delete iResourceOffsets; |
|
88 } |
|
89 } |
|
90 |
|
91 EXPORT_C TBool CMsgBioControl::ConfirmationQueryL(const TDesC& aText) |
|
92 { |
|
93 //This temporary descriptor is needed because the query wants a non const |
|
94 HBufC* text = aText.AllocL(); |
|
95 CleanupStack::PushL(text); |
|
96 CAknQueryDialog* qDlg = new (ELeave) CAknQueryDialog(*text); |
|
97 TInt response = |
|
98 qDlg->ExecuteLD(R_MSGEDITORUTILS_GENERAL_CONFIRMATION_QUERY); |
|
99 CleanupStack::PopAndDestroy(text); // text |
|
100 if (response) |
|
101 { |
|
102 return ETrue; |
|
103 } |
|
104 return EFalse; |
|
105 } |
|
106 |
|
107 EXPORT_C TBool CMsgBioControl::ConfirmationQueryL(TInt aStringResource) |
|
108 { |
|
109 HBufC* buf = StringLoader::LoadLC(aStringResource); |
|
110 TBool result(ConfirmationQueryL(*buf)); |
|
111 CleanupStack::PopAndDestroy(buf); //buf |
|
112 return result; |
|
113 } |
|
114 |
|
115 EXPORT_C void CMsgBioControl::LoadResourceL(const TDesC& aFile) |
|
116 { |
|
117 |
|
118 TDriveList driveList; |
|
119 |
|
120 TFileName searchPath(NULL); |
|
121 |
|
122 // get a list of available drives |
|
123 TInt ret = iCoeEnv->FsSession().DriveList(driveList); |
|
124 if (ret != KErrNone) |
|
125 { |
|
126 // cannot continue |
|
127 Panic( EMEUResourceFileNotFound ); |
|
128 } |
|
129 |
|
130 // scan all drives |
|
131 for ( TInt n=0 ; n < KMaxDrives ; n++ ) |
|
132 { |
|
133 // does the drive exis |
|
134 if (driveList[n] != 0) |
|
135 { |
|
136 TDriveInfo driveInfo; |
|
137 |
|
138 ret = iCoeEnv->FsSession().Drive(driveInfo,n); |
|
139 if ((ret == KErrNone) |
|
140 && (driveInfo.iType != EMediaNotPresent) |
|
141 && (driveInfo.iType != EMediaRemote)) |
|
142 { |
|
143 // drive exists.. |
|
144 TDriveUnit drive(n); |
|
145 |
|
146 // append the data. |
|
147 searchPath.CopyF(drive.Name()); |
|
148 searchPath.Append(KDC_RESOURCE_FILES_DIR()); |
|
149 searchPath.Append(aFile); |
|
150 |
|
151 // check does the non-localized file exist |
|
152 TBool res = BaflUtils::FileExists( iCoeEnv->FsSession(), searchPath ); |
|
153 if (res) //found |
|
154 { |
|
155 // Complete searchpath without filename. |
|
156 searchPath.CopyF( drive.Name() ); |
|
157 searchPath.Append( KDC_RESOURCE_FILES_DIR() ); |
|
158 // no need to scan other drives: |
|
159 break; |
|
160 } |
|
161 else |
|
162 { |
|
163 HBufC* originalPath = searchPath.AllocLC(); |
|
164 // check is there localized version of resource file |
|
165 BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(), searchPath ); |
|
166 |
|
167 // if the original path differs from search path, the |
|
168 // localized resource file is found |
|
169 res = originalPath->Compare(searchPath); |
|
170 |
|
171 CleanupStack::PopAndDestroy(originalPath); |
|
172 if ( res != KErrNone ) // found |
|
173 { |
|
174 // Complete searchpath without filename. |
|
175 searchPath.CopyF(drive.Name()); |
|
176 searchPath.Append( KDC_RESOURCE_FILES_DIR() ); |
|
177 // no need to scan other drives: |
|
178 break; |
|
179 } |
|
180 } |
|
181 } |
|
182 } |
|
183 } |
|
184 |
|
185 // load the resource file from scanned path. |
|
186 LoadResourceL(aFile, searchPath); |
|
187 } |
|
188 |
|
189 EXPORT_C void CMsgBioControl::LoadResourceL(const TDesC& aFile, const TDesC& aSearchPath) |
|
190 { |
|
191 if (!iResourceOffsets) |
|
192 { |
|
193 iResourceOffsets = new (ELeave) CArrayFixFlat<TInt>(1); // granularity |
|
194 } |
|
195 |
|
196 // Find the resource file for the nearest language |
|
197 TFileName fileName(aSearchPath); |
|
198 fileName.Append(aFile); |
|
199 BaflUtils::NearestLanguageFile(iCoeEnv->FsSession(), fileName); |
|
200 |
|
201 // Check does the resource file exist in given path. |
|
202 TBool fileExists( BaflUtils::FileExists(iCoeEnv->FsSession(), fileName) ); |
|
203 if (fileExists) |
|
204 { |
|
205 // Add the resource file to the CONE environment, and keep the offset |
|
206 iResourceOffsets->SetReserveL(iResourceOffsets->Count() + 1); |
|
207 const TInt offset = iCoeEnv->AddResourceFileL(fileName); |
|
208 iResourceOffsets->AppendL(offset); |
|
209 } |
|
210 else |
|
211 { |
|
212 TParse* fp = new(ELeave) TParse(); |
|
213 fp->Set(aFile, &KDC_RESOURCE_FILES_DIR, NULL); |
|
214 |
|
215 TFileName fileName(fp->FullName()); |
|
216 delete fp; |
|
217 |
|
218 iResourceOffsets->SetReserveL(iResourceOffsets->Count() + 1); |
|
219 const TInt offset = iCoeEnv->AddResourceFileL(fileName); |
|
220 User::LeaveIfError( offset); |
|
221 iResourceOffsets->AppendL(offset); |
|
222 } |
|
223 } |
|
224 |
|
225 EXPORT_C void CMsgBioControl::LoadStandardBioResourceL() |
|
226 { |
|
227 LoadResourceL(KMsgEditorUtilsResource); |
|
228 } |
|
229 |
|
230 EXPORT_C TBool CMsgBioControl::IsEditor() const |
|
231 { |
|
232 return (iMode == EMsgBioEditorMode); |
|
233 } |
|
234 |
|
235 EXPORT_C TBool CMsgBioControl::IsFileBased() const |
|
236 { |
|
237 return (iBCStatusFlags & EFileBased); |
|
238 } |
|
239 |
|
240 EXPORT_C CMsvSession& CMsgBioControl::MsvSession() const |
|
241 { |
|
242 __ASSERT_ALWAYS(iMsvSession, Panic(EMEUMsvSessionIsNull)); |
|
243 return *iMsvSession; |
|
244 } |
|
245 |
|
246 EXPORT_C const TFileName& CMsgBioControl::FileName() const |
|
247 { |
|
248 // deprecated |
|
249 __ASSERT_ALWAYS(/*IsFileBased()*/ 0, Panic(EMEUNotFileBase)); |
|
250 return TFileName(); // should never ever come to this point |
|
251 } |
|
252 |
|
253 EXPORT_C const RFile& CMsgBioControl::FileHandle() const |
|
254 { |
|
255 __ASSERT_ALWAYS(IsFileBased(), Panic(EMEUNotFileBase)); |
|
256 return *iFile; |
|
257 } |
|
258 |
|
259 EXPORT_C TUint32 CMsgBioControl::OptionMenuPermissionsL() const |
|
260 { |
|
261 // This is the default because most of the Bio Controls need these. |
|
262 return EMsgBioCallBack |
|
263 | EMsgBioDelete |
|
264 | EMsgBioMessInfo |
|
265 | EMsgBioMove |
|
266 | EMsgBioCreateCC |
|
267 | EMsgBioSend |
|
268 | EMsgBioAddRecipient |
|
269 | EMsgBioSave |
|
270 | EMsgBioSendingOpt |
|
271 | EMsgBioHelp |
|
272 | EMsgBioExit; |
|
273 } |
|
274 |
|
275 |
|
276 // default implementation returns height of the control. |
|
277 EXPORT_C TInt CMsgBioControl::VirtualHeight() |
|
278 { |
|
279 return iSize.iHeight; |
|
280 } |
|
281 |
|
282 // default implementation returns 0. |
|
283 EXPORT_C TInt CMsgBioControl::VirtualVisibleTop() |
|
284 { |
|
285 return 0; |
|
286 } |
|
287 |
|
288 // default implementation returns EFalse. |
|
289 EXPORT_C TBool CMsgBioControl::IsCursorLocation(TMsgCursorLocation /*aLocation*/) const |
|
290 { |
|
291 return EFalse; |
|
292 } |
|
293 |
|
294 EXPORT_C void CMsgBioControl::AddMenuItemL(CEikMenuPane& aMenuPane, |
|
295 TInt aStringRes, TInt aCommandOffset, TInt aPosition) |
|
296 { |
|
297 CEikMenuPaneItem::SData menuItem; |
|
298 menuItem.iCascadeId = NULL; |
|
299 menuItem.iFlags = NULL; |
|
300 menuItem.iText.Format(*StringLoader::LoadLC(aStringRes)); |
|
301 CleanupStack::PopAndDestroy(); // (string) |
|
302 menuItem.iCommandId = iBioControlObserver.FirstFreeCommand() |
|
303 + aCommandOffset; |
|
304 aMenuPane.InsertMenuItemL(menuItem, aPosition); |
|
305 } |
|
306 |
|
307 void CMsgBioControl::SetBioBodyControl( MMsgBioBodyControl* aBioBodyControl ) |
|
308 { |
|
309 iBioBodyControl = aBioBodyControl; |
|
310 } |
|
311 |
|
312 EXPORT_C TBool CMsgBioControl::NotifyEditorViewL( |
|
313 TMsgBioControlEventRequest aRequest, |
|
314 TInt aDelta) |
|
315 { |
|
316 if (iBioBodyControl) |
|
317 { |
|
318 return iBioBodyControl->HandleBaseControlEventRequestL( |
|
319 aRequest, aDelta); |
|
320 } |
|
321 return ETrue; |
|
322 } |
|
323 |
|
324 EXPORT_C void CMsgBioControl::SetExtension(MMsgBioControlExtension* aExt) |
|
325 { |
|
326 iExt = aExt; |
|
327 } |
|
328 |
|
329 #ifdef RD_SCALABLE_UI_V2 |
|
330 EXPORT_C TInt CMsgBioControl::ScrollL( TInt aPixelsToScroll, |
|
331 TMsgScrollDirection aDirection ) |
|
332 { |
|
333 TInt retval(0); |
|
334 |
|
335 if(!iExt) |
|
336 { |
|
337 return retval; |
|
338 } |
|
339 |
|
340 MMsgBioControlScrollExtension* extension = |
|
341 static_cast<MMsgBioControlScrollExtension*> |
|
342 ( iExt->BioControlExtension( KMsgBioControlScrollExtension ) ); |
|
343 |
|
344 if(extension != NULL) |
|
345 { |
|
346 //call the extension method |
|
347 retval = extension->ExtScrollL( aPixelsToScroll, aDirection ); |
|
348 } |
|
349 |
|
350 return retval; |
|
351 } |
|
352 |
|
353 EXPORT_C void CMsgBioControl::NotifyViewEvent( TMsgViewEvent aEvent, TInt aParam ) |
|
354 { |
|
355 if(!iExt) |
|
356 { |
|
357 return; |
|
358 } |
|
359 |
|
360 MMsgBioControlScrollExtension* extension = |
|
361 static_cast<MMsgBioControlScrollExtension*> |
|
362 ( iExt->BioControlExtension( KMsgBioControlScrollExtension ) ); |
|
363 |
|
364 if(extension != NULL) |
|
365 { |
|
366 extension->ExtNotifyViewEvent( aEvent, aParam ); |
|
367 } |
|
368 } |
|
369 #else |
|
370 EXPORT_C TInt CMsgBioControl::ScrollL( TInt /*aPixelsToScroll*/, |
|
371 TMsgScrollDirection /*aDirection*/ ) |
|
372 { |
|
373 //no op |
|
374 return 0; |
|
375 } |
|
376 |
|
377 EXPORT_C void CMsgBioControl::NotifyViewEvent( TMsgViewEvent /*aEvent*/, TInt /*aParam*/ ) |
|
378 { |
|
379 //no op |
|
380 } |
|
381 #endif |
|
382 |
|
383 //end of file |