|
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 * |
|
16 */ |
|
17 |
|
18 // AknForm.cpp |
|
19 // |
|
20 // Copyright (c) 2001 Symbian Ltd. All rights reserved. |
|
21 // |
|
22 |
|
23 |
|
24 #include <AknForm.h> |
|
25 #include <AknQueryDialog.h> |
|
26 #include <eikdialg.h> |
|
27 #include <eikmenub.h> |
|
28 #include <eikenv.h> |
|
29 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
30 #include <uikon/eikenvinterface.h> |
|
31 #endif |
|
32 #include <eikappui.h> |
|
33 #include <eiklabel.h> |
|
34 #include <eikedwin.h> |
|
35 #include <barsread.h> |
|
36 |
|
37 #include <avkon.hrh> |
|
38 #include <avkon.rsg> |
|
39 #include <aknnotedialog.h> |
|
40 #include <eikcapc.h> |
|
41 #include "aknenv.h" |
|
42 #include <eikedwin.h> |
|
43 |
|
44 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS |
|
45 #include <gfxtranseffect/gfxtranseffect.h> |
|
46 #endif |
|
47 |
|
48 /** |
|
49 * Local Panic Function and Panic Codes (Shared by AknDialog & AknForm) |
|
50 */ |
|
51 enum TPanicCodes |
|
52 { |
|
53 EGeneralFormPanic, |
|
54 ENoMenuBar, |
|
55 EMenuCommandUnknown |
|
56 }; |
|
57 |
|
58 void Panic(TPanicCodes aPanic) |
|
59 { |
|
60 _LIT(kForm, "AVKON-FORM"); |
|
61 User::Panic(kForm, aPanic); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Constructor |
|
66 */ |
|
67 EXPORT_C CAknForm::CAknForm() |
|
68 { |
|
69 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS |
|
70 GfxTransEffect::Deregister( this ); |
|
71 #endif |
|
72 iWsBufferRequestID = iAvkonEnv->RequestWsBuffer( 16000 ); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Creates a default Form menu using default form menu resource. |
|
77 * (note that the parameter, a new menu bar resource, is saved for later. |
|
78 */ |
|
79 EXPORT_C void CAknForm::ConstructL(TInt aMenuBarId) |
|
80 { |
|
81 iMenuBarId = aMenuBarId; |
|
82 CAknDialog::ConstructL(R_AVKON_FORM_MENUBAR); |
|
83 } |
|
84 |
|
85 /** |
|
86 * |
|
87 */ |
|
88 EXPORT_C CAknForm::~CAknForm() |
|
89 { |
|
90 // cancels large WS client buffer required by form |
|
91 iAvkonEnv->CancelWsBufferRequest( iWsBufferRequestID ); |
|
92 } |
|
93 |
|
94 /** |
|
95 * This function intialises the items on the menu. It's used to disable and enable menu items and may be |
|
96 * over riden to add new ones. |
|
97 * In addition it adds menu items which have been provided in the ContsructL in the form of a Menu Bar resource. |
|
98 * Instead of using the Menu Bar directly it extracts the menu panes and adds them to it's own menu pane. |
|
99 * It must be called in the DynInitMenuPaneL() function of any derived class before anything else!! |
|
100 * |
|
101 */ |
|
102 EXPORT_C void CAknForm::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane) |
|
103 { |
|
104 if (aResourceId == R_AVKON_FORM_MENUPANE) |
|
105 { |
|
106 if (iMenuBarId) |
|
107 { |
|
108 |
|
109 TResourceReader reader; |
|
110 iCoeEnv->CreateResourceReaderLC(reader, iMenuBarId); |
|
111 |
|
112 TInt count = reader.ReadInt16(); // Number of menu panes |
|
113 while (count--) |
|
114 { |
|
115 TInt menuPaneResourceId = reader.ReadInt32(); |
|
116 reader.ReadTPtrC(); // read and ignore the rest... |
|
117 reader.ReadInt32(); |
|
118 reader.ReadTPtrC(); |
|
119 reader.ReadInt16(); |
|
120 reader.ReadInt16(); |
|
121 reader.ReadInt32(); |
|
122 aMenuPane->AddMenuItemsL(menuPaneResourceId, 0, ETrue); // at the top, with a separator |
|
123 } |
|
124 CleanupStack::PopAndDestroy(); // Resource Reader |
|
125 } |
|
126 |
|
127 TBool editOptionDimmed = IsEditable(); |
|
128 aMenuPane->SetItemDimmed(EAknFormCmdEdit, editOptionDimmed); |
|
129 aMenuPane->SetItemDimmed(EAknFormCmdSave, !editOptionDimmed); |
|
130 aMenuPane->SetItemDimmed(EAknFormCmdLabel, !editOptionDimmed); |
|
131 aMenuPane->SetItemDimmed(EAknFormCmdAdd, !editOptionDimmed); |
|
132 aMenuPane->SetItemDimmed(EAknFormCmdDelete, !editOptionDimmed); |
|
133 } |
|
134 } |
|
135 |
|
136 /** |
|
137 *From MEikCommandObserver (act on the menu selection if menu is showing - pass on to client if not processed here) |
|
138 */ |
|
139 EXPORT_C void CAknForm::ProcessCommandL(TInt aCommandId) |
|
140 { |
|
141 CAknDialog::ProcessCommandL(aCommandId); |
|
142 |
|
143 switch (aCommandId) |
|
144 { |
|
145 case EAknFormCmdEdit : // Change into edit state |
|
146 if (!IsEditable()) |
|
147 SetEditableL(ETrue); |
|
148 break; |
|
149 case EAknFormCmdAdd : // Add Field to Form (display dialog) |
|
150 AddItemL(); |
|
151 break; |
|
152 case EAknFormCmdSave : // Save form data (must be implemented by Child) and revert to View Mode |
|
153 if (SaveFormDataL()) |
|
154 { |
|
155 SetChangesPending( EFalse ); |
|
156 TBool hasEditModeOnly = FormFlagsFromActivePage()&EEikFormEditModeOnly; |
|
157 if (!hasEditModeOnly) |
|
158 SetEditableL(EFalse); |
|
159 } |
|
160 break; |
|
161 case EAknFormCmdLabel : // Edit selected label (display dialog) |
|
162 EditCurrentLabelL(); |
|
163 break; |
|
164 case EAknFormCmdDelete : // Delete selected item (control) |
|
165 DeleteCurrentItemL(); |
|
166 break; |
|
167 default : |
|
168 // Default action is to do nothing. |
|
169 // Mustn't panic as this function might be called by a child which has already |
|
170 // acted upon an action which it has added to the menu. |
|
171 break; |
|
172 } |
|
173 } |
|
174 |
|
175 |
|
176 /** |
|
177 * From CEikDialog (thence MEikDialogPageObserver) |
|
178 * If deleting then this routine must not do anything (the default tries to access the control |
|
179 * which has just been deleted!) |
|
180 */ |
|
181 EXPORT_C void CAknForm::PrepareForFocusTransitionL() |
|
182 { |
|
183 if (!Deleting()) |
|
184 CAknDialog::PrepareForFocusTransitionL(); |
|
185 } |
|
186 |
|
187 |
|
188 |
|
189 /** |
|
190 * |
|
191 * From CEikDialog - Use this to pop up the options menu or close the dialog. |
|
192 * Will call SaveFormDataL() before closing if data has been edited. |
|
193 * Will NOT permit exit if attempt to save data fails. |
|
194 */ |
|
195 EXPORT_C TBool CAknForm::OkToExitL(TInt aButtonId) |
|
196 { |
|
197 TBool hasEditModeOnly = FormFlagsFromActivePage()&EEikFormEditModeOnly; |
|
198 |
|
199 if (iMenuBar) |
|
200 HideMenu(); |
|
201 |
|
202 if (aButtonId == EAknSoftkeyOptions) |
|
203 { |
|
204 DisplayMenuL(); |
|
205 return EFalse; |
|
206 } |
|
207 else if ( aButtonId == EAknSoftkeyBack) |
|
208 { |
|
209 if (IsEditable()) |
|
210 { |
|
211 TBool mayExitEditMode = ETrue; |
|
212 if (UnsavedEdit()) |
|
213 { |
|
214 if ( QuerySaveChangesL() ) |
|
215 { |
|
216 // User has chosen to save. Attempt to save. Implementation of this |
|
217 // may in some situations return EFalse. This will prevent leaving edit |
|
218 // mode |
|
219 mayExitEditMode = SaveFormDataL(); |
|
220 if ( mayExitEditMode ) |
|
221 SetChangesPending( EFalse ); |
|
222 } |
|
223 else // introduced to allow users to re-set data when a save is undesired. |
|
224 DoNotSaveFormDataL(); |
|
225 } |
|
226 if (hasEditModeOnly) |
|
227 { |
|
228 if ( !mayExitEditMode ) |
|
229 return EFalse; // stay in Form because save failed |
|
230 } |
|
231 else |
|
232 { |
|
233 if ( mayExitEditMode ) |
|
234 SetEditableL(EFalse); // go out of edit mode of Form |
|
235 return EFalse; // remain in form ( but in view mode if save was OK). |
|
236 } |
|
237 |
|
238 } // end of if (IsEditable()) |
|
239 |
|
240 return ETrue; |
|
241 } |
|
242 else if (aButtonId == EAknSoftkeyChange) |
|
243 { |
|
244 if (ControlOrNull(IdOfFocusControl())) |
|
245 { |
|
246 // we need to inform popup field about MSK event |
|
247 TKeyEvent event = { EKeyOK, EKeyOK, EModifierPureKeycode, 0 }; |
|
248 Line(IdOfFocusControl())->OfferKeyEventL(event, EEventKey ); |
|
249 } |
|
250 } |
|
251 return EFalse; |
|
252 } |
|
253 |
|
254 EXPORT_C void CAknForm::HandleResourceChange(TInt aType) |
|
255 { |
|
256 CEikDialog::HandleResourceChange(aType); |
|
257 } |
|
258 |
|
259 |
|
260 |
|
261 /** |
|
262 * This routine should be re-implemented by the client to save the contents of the form. |
|
263 * The re-implementation can call this function to display the 'Saved' dialog. |
|
264 * (CAknForm::SaveFormDataL()) |
|
265 * |
|
266 * This should return ETrue unless there was a problem saving that the user can circumvent |
|
267 * If it is a serious system problem, then a Leave should be generated |
|
268 * |
|
269 * Note that the changes pending flag is not cleared here ( but you could if you want to ); |
|
270 * it is the responsibility of the caller to clear iff return is ETrue. |
|
271 */ |
|
272 EXPORT_C TBool CAknForm::SaveFormDataL() |
|
273 { |
|
274 return (ETrue); |
|
275 } |
|
276 |
|
277 /** |
|
278 * This routine may be overridden. Default displays 'Save Changes Dialog Yes/No' |
|
279 * Returns ETrue if Changes are requested to be saved and then are successfully saved |
|
280 * |
|
281 * Re-implementation may put data validation here (as an alternative to over-riding |
|
282 * OkToExit - which is a more complicated method ) |
|
283 * |
|
284 * Note that this routine does not perform the changes itself. |
|
285 */ |
|
286 EXPORT_C TBool CAknForm::QuerySaveChangesL() |
|
287 { |
|
288 CAknQueryDialog* saveChangesDialog = CAknQueryDialog::NewL(); |
|
289 TInt option = saveChangesDialog->ExecuteLD(R_AVKON_FORM_DEFAULT_SAVE_CHANGES_DIALOG); |
|
290 return ( option ); |
|
291 } |
|
292 |
|
293 EXPORT_C void CAknForm::SetChangesPending(TBool aChangesPending) |
|
294 { |
|
295 SetFormFlag( EUnsavedEdit, aChangesPending ); |
|
296 } |
|
297 |
|
298 |
|
299 /** |
|
300 * This routine may be overridden. Default displays old label as caption and editor for new one |
|
301 * Uses customised dialog |
|
302 */ |
|
303 EXPORT_C void CAknForm::EditCurrentLabelL() |
|
304 { |
|
305 const TInt KFurtherTextIrrelevant=30; |
|
306 if (!ControlOrNull(IdOfFocusControl())) |
|
307 return; |
|
308 TPtrC originalLabel = Line(IdOfFocusControl())->GetFullCaptionText(); |
|
309 TBuf<KFurtherTextIrrelevant> buf= originalLabel.Left(KFurtherTextIrrelevant); |
|
310 TResourceReader reader ; |
|
311 iCoeEnv->CreateResourceReaderLC( reader, R_AVKON_TEXT_EDIT_LABEL_QUERY_TEXT ) ; |
|
312 HBufC* editLabelQueryPrompt = reader.ReadHBufCL(); |
|
313 CleanupStack::PushL(editLabelQueryPrompt); |
|
314 CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(buf); |
|
315 dlg->PrepareLC(R_AVKON_DEFAULT_EDIT_LABEL_QUERY); |
|
316 dlg->SetPromptL(*editLabelQueryPrompt); |
|
317 TInt queryOk = dlg->RunLD(); |
|
318 CleanupStack::PopAndDestroy(); // editLabelQueryPrompt |
|
319 CleanupStack::PopAndDestroy(); // reader |
|
320 if(queryOk == EAknSoftkeyOk) |
|
321 { |
|
322 SetFormFlag( EUnsavedEdit, ETrue ); |
|
323 TRAP_IGNORE(Line(IdOfFocusControl())->SetCaptionL(buf)); |
|
324 } |
|
325 DrawNow(); |
|
326 } |
|
327 |
|
328 /** |
|
329 * This routine may be overridden. Default displays delete item? Yes/No |
|
330 * Deletes Item on return from Dialog before returning |
|
331 */ |
|
332 EXPORT_C void CAknForm::DeleteCurrentItemL() |
|
333 { |
|
334 CAknQueryDialog* deleteItemDialog = CAknQueryDialog::NewL(); |
|
335 TInt option = deleteItemDialog->ExecuteLD(R_AVKON_FORM_DEFAULT_DELETE_ITEM_DIALOG); |
|
336 if (option == EAknSoftkeyYes) |
|
337 { |
|
338 SetFormFlag( EDeleting, ETrue ); |
|
339 |
|
340 TInt LineForDeletion = IdOfFocusControl(); |
|
341 |
|
342 if (LineForDeletion) |
|
343 { |
|
344 DeleteLine(LineForDeletion); |
|
345 SetFormFlag( EUnsavedEdit, ETrue ); |
|
346 } |
|
347 DrawNow(); |
|
348 SetFormFlag( EDeleting, EFalse ); |
|
349 } |
|
350 } |
|
351 |
|
352 /** |
|
353 * This routine may be overridden. Default displays Add Item |
|
354 * Uses customised dialog |
|
355 */ |
|
356 EXPORT_C void CAknForm::AddItemL() |
|
357 { |
|
358 } |
|
359 |
|
360 |
|
361 /** |
|
362 * |
|
363 */ |
|
364 EXPORT_C TBool CAknForm::UnsavedEdit() const |
|
365 { |
|
366 return (iFlags & EUnsavedEdit); |
|
367 } |
|
368 |
|
369 EXPORT_C TBool CAknForm::Deleting() const |
|
370 { |
|
371 return (iFlags & EDeleting); |
|
372 } |
|
373 |
|
374 |
|
375 EXPORT_C void CAknForm::PostLayoutDynInitL() |
|
376 { |
|
377 if (FormFlagsFromActivePage()&EEikFormEditModeOnly) |
|
378 SetEditableL(ETrue); |
|
379 else |
|
380 SetEditableL(EFalse); |
|
381 } |
|
382 |
|
383 /* |
|
384 Overridden, so that the form can tell if a line's state has changed. |
|
385 This is used to decide when to save changes. |
|
386 */ |
|
387 |
|
388 EXPORT_C void CAknForm::HandleControlStateChangeL(TInt aControlId) |
|
389 { |
|
390 SetChangesPending(ETrue); |
|
391 CAknDialog::HandleControlStateChangeL(aControlId); |
|
392 } |
|
393 |
|
394 /* |
|
395 This is added, so that anyone adding lines either in PreLayoutDynInit or SetInitialCurrentLine |
|
396 should have the lines in a consistent state. |
|
397 */ |
|
398 EXPORT_C void CAknForm::SetInitialCurrentLine() |
|
399 { |
|
400 // call SetEditableL again to put controls in consistent state. |
|
401 |
|
402 TRAP_IGNORE(SetEditableL(IsEditable())); // re-run the seteditable to ensure any added lines are in consistent state. |
|
403 // ignore e. |
|
404 CAknDialog::SetInitialCurrentLine(); |
|
405 } |
|
406 |
|
407 EXPORT_C void CAknForm::SetFormFlag(enum CAknForm::TFlags aFlagPattern, TBool aSetTheFlag ) |
|
408 { |
|
409 if ( aSetTheFlag ) |
|
410 iFlags |= aFlagPattern; |
|
411 else |
|
412 iFlags &= (~aFlagPattern); |
|
413 } |
|
414 |
|
415 EXPORT_C void CAknForm::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
416 { |
|
417 CAknDialog::HandlePointerEventL(aPointerEvent); |
|
418 } |
|
419 |
|
420 EXPORT_C void* CAknForm::ExtensionInterface( TUid /*aInterface*/ ) |
|
421 { |
|
422 return NULL; |
|
423 } |
|
424 |
|
425 |
|
426 EXPORT_C void CAknForm::DoNotSaveFormDataL() |
|
427 { |
|
428 |
|
429 }; |
|
430 |
|
431 EXPORT_C void CAknForm::CEikDialog_Reserved_1() |
|
432 { |
|
433 |
|
434 } |
|
435 |
|
436 EXPORT_C void CAknForm::CEikDialog_Reserved_2() |
|
437 { |
|
438 |
|
439 } |
|
440 |
|
441 EXPORT_C void CAknForm::CAknDialog_Reserved() |
|
442 { |
|
443 |
|
444 } |
|
445 |
|
446 EXPORT_C void CAknForm::CAknForm_Reserved() |
|
447 { |
|
448 |
|
449 } |
|
450 |
|
451 void CAknForm::DoLayout() |
|
452 { |
|
453 Layout(); |
|
454 } |