|
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: Implementation of Notepad Editor mode. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "NpdLib.hrh" |
|
21 #include "NpdExternalTextEditorDialog.h" |
|
22 #include "NpdApi.h" |
|
23 #include "NpdLib.h" |
|
24 #include "NpdUtil.h" |
|
25 #include "NpdEdwin.h" |
|
26 |
|
27 #include <NpdLib.rsg> |
|
28 |
|
29 #include <aknappui.h> |
|
30 #include <avkon.hrh> |
|
31 #include <eikmenup.h> |
|
32 #include <txtetext.h> |
|
33 #include <AknForm.h> |
|
34 #include <aknnotedialog.h> |
|
35 #include <eikapp.h> |
|
36 #include <aknnotewrappers.h> |
|
37 #include <sendui.h> |
|
38 #include <SenduiMtmUids.h> |
|
39 #include <Sendnorm.rsg> |
|
40 #include <barsread.h> |
|
41 #include <featmgr.h> |
|
42 #include <hlplch.h> |
|
43 #include <finditemmenu.h> |
|
44 #include <CommonContentPolicy.h> |
|
45 |
|
46 #include <finditemengine.h> |
|
47 #include <finditemmenu.h> |
|
48 #include <finditemdialog.h> |
|
49 #include <FindItemmenu.rsg> |
|
50 #include <finditem.hrh> |
|
51 |
|
52 #include <csxhelp/nmake.hlp.hrh> |
|
53 #include "NpdLibPanic.h" |
|
54 #include "NpdEdwinLines.h" |
|
55 |
|
56 |
|
57 // ============================ MEMBER FUNCTIONS =============================== |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CNotepadExternalTextDialog::NewL |
|
61 // constructor. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CNotepadExternalTextDialog* CNotepadExternalTextDialog::NewL( |
|
65 HBufC** aText, |
|
66 TInt& aReturnStatus, |
|
67 const TDesC& aInitialText, |
|
68 const TDesC& aTitle, |
|
69 const TDesC& aConfirmText, |
|
70 CEikDialog** aSelfPtr |
|
71 ) |
|
72 { |
|
73 CNotepadExternalTextDialog* self = new(ELeave) CNotepadExternalTextDialog(); |
|
74 self->iSelfPtr = aSelfPtr; |
|
75 CleanupStack::PushL(self); |
|
76 |
|
77 TResourceReader rr; |
|
78 self->iCoeEnv->CreateResourceReaderLC(rr, R_NOTEPAD_TEXT_EDITOR); |
|
79 self->ConstructL( rr, aText, aReturnStatus, aInitialText, aTitle , aConfirmText); |
|
80 CleanupStack::PopAndDestroy(); // rr |
|
81 CleanupStack::Pop(); // rr |
|
82 return self; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CNotepadExternalTextDialog::ConstructL |
|
87 // constructor. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CNotepadExternalTextDialog::ConstructL( |
|
91 TResourceReader &rr, |
|
92 HBufC** aText, |
|
93 TInt& aReturnStatus, |
|
94 const TDesC& aInitialText, |
|
95 const TDesC& aTitle, |
|
96 const TDesC& aConfirmText |
|
97 ) |
|
98 { |
|
99 if ( aTitle.Length() != 0 ) |
|
100 { |
|
101 CNotepadDialogBase::SetTitleL(&aTitle); |
|
102 } |
|
103 iContent.Set( aInitialText ); |
|
104 iContentPointer = aText; |
|
105 |
|
106 if (aConfirmText.Length() != 0) |
|
107 { |
|
108 iDeleteConfirmation.Set( aConfirmText ); |
|
109 } |
|
110 |
|
111 iOKKeyPressed = ETrue; |
|
112 CNotepadDialogBase::ConstructL(rr); |
|
113 iReturnValue = &aReturnStatus; |
|
114 iFindItemMenu = CFindItemMenu::NewL(ENotepadCmdFind); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CNotepadExternalTextDialog::~CNotepadExternalTextDialog |
|
119 // Destructor |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C CNotepadExternalTextDialog::~CNotepadExternalTextDialog() |
|
123 { |
|
124 delete iFindItemMenu; |
|
125 } |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CNotepadExternalTextDialog::OkToExitL |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 TBool CNotepadExternalTextDialog::OkToExitL( TInt aButtonId ) |
|
132 { |
|
133 TBool isOk(ETrue); |
|
134 //MSK |
|
135 if(aButtonId == EAknSoftkeyContextOptions ) |
|
136 { |
|
137 iOKKeyPressed = ETrue; |
|
138 DisplayMenuL(); |
|
139 return EFalse; |
|
140 } |
|
141 else if(aButtonId == EAknSoftkeyOptions ) |
|
142 { |
|
143 iOKKeyPressed = EFalse; |
|
144 } |
|
145 else |
|
146 { |
|
147 } |
|
148 isOk = CAknDialog::OkToExitL(aButtonId); |
|
149 |
|
150 TInt size = iEditor->Text()->DocumentLength(); |
|
151 |
|
152 if(size == 0) |
|
153 { |
|
154 *iReturnValue = CNotepadApi::ENpdDataErased; |
|
155 } |
|
156 else if(size != 0 && (*iReturnValue) != CNotepadApi::ENpdDataDeleted ) |
|
157 { |
|
158 *iContentPointer = HBufC::NewL(size); |
|
159 TPtr desptr = (*iContentPointer)->Des(); |
|
160 iEditor->Text()->Extract(desptr,0,size); |
|
161 if(NotepadUtil::IsEmpty(**iContentPointer)) |
|
162 { |
|
163 *iReturnValue = CNotepadApi::ENpdDataErased; |
|
164 } |
|
165 else |
|
166 { |
|
167 *iReturnValue = CNotepadApi::ENpdDataEdited; |
|
168 } |
|
169 } |
|
170 |
|
171 return isOk; |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CNotepadExternalTextDialog::HandleResourceChange |
|
176 // from CCoeControl |
|
177 // --------------------------------------------------------- |
|
178 // |
|
179 void CNotepadExternalTextDialog::HandleResourceChange(TInt aType) |
|
180 { |
|
181 if (aType == KEikDynamicLayoutVariantSwitch) |
|
182 { |
|
183 TRect mainPane; |
|
184 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPane); |
|
185 SetRect(mainPane); |
|
186 } |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CNotepadExternalTextDialog::SizeChanged |
|
191 // from CCoeControl |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CNotepadExternalTextDialog::SizeChanged() |
|
195 { |
|
196 CNotepadDialogBase::SizeChanged(); |
|
197 if (iEditor && IsActivated()) |
|
198 { |
|
199 TRAP_IGNORE(iEditor->DoEditorLayoutL()); |
|
200 } |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CNotepadExternalTextDialog::PostLayoutDynInitL |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CNotepadExternalTextDialog::PostLayoutDynInitL() |
|
208 { |
|
209 |
|
210 iEditor = STATIC_CAST(CNotepadEdwin*, Control(ENotepadIdEdwin)); |
|
211 iEditor->ConstructBaseL(); |
|
212 __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) ); |
|
213 iEditor->CreatePreAllocatedScrollBarFrameL()->SetScrollBarVisibilityL( |
|
214 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
215 |
|
216 iEditor->Text()->Reset(); |
|
217 iEditor->SetTextL(&iContent); |
|
218 iEditor->HandleTextChangedL(); |
|
219 |
|
220 CEikAppUi* container = iAvkonAppUi->ContainerAppUi(); |
|
221 //cannot find UIDs in SenduiMtmUids.h |
|
222 TUid appuid = KNullUid; |
|
223 if ( container ) |
|
224 { |
|
225 appuid = container->Application()->AppDllUid(); |
|
226 } |
|
227 |
|
228 TRect rect(iEikonEnv->EikAppUi()->ClientRect()); |
|
229 iEditor->SetRect(rect); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CNotepadExternalTextDialog::ActivateL |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CNotepadExternalTextDialog::ActivateL() |
|
237 { |
|
238 __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) ); |
|
239 iEditor->InitNotepadEditorL(this, STATIC_CAST(CNotepadEdwinLines*, Control(ENotepadIdEdwinLines))); |
|
240 iEditor->SetFocus(ETrue, ENoDrawNow); |
|
241 CNotepadDialogBase::ActivateL(); |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CNotepadExternalTextDialog::OfferKeyEventL |
|
246 // from CoeControl |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 TKeyResponse CNotepadExternalTextDialog::OfferKeyEventL( |
|
250 const TKeyEvent& aKeyEvent, |
|
251 TEventCode aType ) |
|
252 { |
|
253 TKeyResponse keyResponse(EKeyWasConsumed); |
|
254 |
|
255 if ( !MenuShowing() && aType == EEventKey && |
|
256 !( aKeyEvent.iModifiers & (EAllStdModifiers|EModifierSpecial) ) && |
|
257 ( aKeyEvent.iCode == EKeyOK ) ) |
|
258 { |
|
259 iOKKeyPressed = ETrue; |
|
260 DisplayMenuL(); |
|
261 } |
|
262 else if( aKeyEvent.iCode == EKeyPhoneEnd ) |
|
263 { |
|
264 TInt size = iEditor->Text()->DocumentLength(); |
|
265 if(size == 0) |
|
266 { |
|
267 *iReturnValue = CNotepadApi::ENpdDataErased; |
|
268 } |
|
269 else if(size != 0 && (*iReturnValue) != CNotepadApi::ENpdDataDeleted ) |
|
270 { |
|
271 *iContentPointer = HBufC::NewL(size); |
|
272 TPtr desptr = (*iContentPointer)->Des(); |
|
273 iEditor->Text()->Extract(desptr,0,size); |
|
274 if(NotepadUtil::IsEmpty(**iContentPointer)) |
|
275 { |
|
276 *iReturnValue = CNotepadApi::ENpdDataErased; |
|
277 } |
|
278 else |
|
279 { |
|
280 *iReturnValue = CNotepadApi::ENpdDataEdited; |
|
281 } |
|
282 } |
|
283 } |
|
284 else |
|
285 { |
|
286 keyResponse = CAknDialog::OfferKeyEventL(aKeyEvent, aType); |
|
287 } |
|
288 return keyResponse; |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CNotepadExternalTextDialog::GetHelpContext |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 void CNotepadExternalTextDialog::GetHelpContext(TCoeHelpContext& aContext) const |
|
296 { |
|
297 aContext.iMajor = KUidNotepad; |
|
298 aContext.iContext = KNMAKE_HLP_MEMO_EDITOR_APPS;//KNMAKE_HLP_MEMO_EDITOR; |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CNotepadExternalTextDialog::ProcessCommandL |
|
303 // from MEikCommandObserver |
|
304 // ----------------------------------------------------------------------------- |
|
305 // |
|
306 void CNotepadExternalTextDialog::ProcessCommandL(TInt aCommandId) |
|
307 { |
|
308 HideMenu(); |
|
309 if ( iFindItemMenu && iFindItemMenu->CommandIsValidL( aCommandId ) ) |
|
310 { |
|
311 TInt ret = DoSearchL( iFindItemMenu->SearchCase(aCommandId) ); |
|
312 if ( ret == EAknSoftkeyExit ) |
|
313 { |
|
314 aCommandId = ret; |
|
315 } |
|
316 } |
|
317 |
|
318 switch (aCommandId) |
|
319 { |
|
320 case ENotepadCmdDelete: |
|
321 { |
|
322 TBool deleted; |
|
323 if(iDeleteConfirmation.Length() != 0) |
|
324 { |
|
325 deleted = CNotepadDialogBase::ExecuteConfirmationQueryL( &iDeleteConfirmation ); |
|
326 } |
|
327 else |
|
328 { |
|
329 deleted =CNotepadDialogBase::ExecuteConfirmationQueryL( R_NOTEPAD_QUERY_DELETE_MEMO ); |
|
330 } |
|
331 if(deleted) |
|
332 { |
|
333 *iReturnValue = CNotepadApi::ENpdDataDeleted; |
|
334 TryExitL(0); |
|
335 } |
|
336 break; |
|
337 } |
|
338 default: |
|
339 CNotepadDialogBase::ProcessCommandL(aCommandId); |
|
340 break; |
|
341 } |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CNotepadExternalTextDialog::DynInitMenuPaneL |
|
346 // from MEikMenuObserver |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CNotepadExternalTextDialog::DynInitMenuPaneL( |
|
350 TInt aResourceId, |
|
351 CEikMenuPane* aMenuPane ) |
|
352 { |
|
353 switch ( aResourceId ) |
|
354 { |
|
355 case R_NOTEPAD_TEXT_EDITOR_MENU: |
|
356 if ( !(NotepadUtil::IsEmpty( iEditor->Text()->Read(0, iEditor->Text()->DocumentLength()) ) ) ) |
|
357 { |
|
358 if ( !(iOKKeyPressed) ) |
|
359 { |
|
360 iFindItemMenu->DisplayFindItemMenuItemL( |
|
361 *aMenuPane, ENotepadCmdDelete); |
|
362 } |
|
363 } |
|
364 if ( iOKKeyPressed ) |
|
365 { |
|
366 aMenuPane->SetItemDimmed(EAknCmdHelp,ETrue); |
|
367 aMenuPane->SetItemDimmed(EAknCmdExit, ETrue); |
|
368 iOKKeyPressed = ETrue; |
|
369 } |
|
370 else |
|
371 { |
|
372 iOKKeyPressed = ETrue; |
|
373 } |
|
374 if(!FeatureManager::FeatureSupported(KFeatureIdHelp)) |
|
375 { |
|
376 aMenuPane->SetItemDimmed(EAknCmdHelp, ETrue); |
|
377 } |
|
378 |
|
379 break; |
|
380 case R_FINDITEMMENU_MENU : |
|
381 { |
|
382 iFindItemMenu->DisplayFindItemCascadeMenuL(*aMenuPane); |
|
383 break; |
|
384 } |
|
385 default: |
|
386 break; |
|
387 } |
|
388 } |
|
389 |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CNotepadExternalTextDialog::DynInitMenuBarL |
|
393 // from MEikMenuObserver |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 void CNotepadExternalTextDialog::DynInitMenuBarL(TInt aResourceId, CEikMenuBar* aMenuBar) |
|
397 { |
|
398 __ASSERT_DEBUG( aResourceId > 0,Panic(ENotepadLibraryPanicNoMenuResource) ); |
|
399 __ASSERT_DEBUG( aMenuBar, Panic(ENotepadLibraryPanicNoMenuResource) ); |
|
400 |
|
401 CEikMenuBar::TMenuType menuType = (iOKKeyPressed) ? CEikMenuBar::EMenuOptionsNoTaskSwapper : |
|
402 CEikMenuBar::EMenuOptions ; |
|
403 aMenuBar->SetMenuType(menuType); |
|
404 |
|
405 } |
|
406 |
|
407 // ----------------------------------------------------------------------------- |
|
408 // CNotepadExternalTextDialog::DoSearchL |
|
409 // ----------------------------------------------------------------------------- |
|
410 // |
|
411 TInt CNotepadExternalTextDialog::DoSearchL(CFindItemEngine::TFindItemSearchCase aCase) |
|
412 { |
|
413 CFindItemDialog* dialog = CFindItemDialog::NewL( iEditor->Text()->Read(0), aCase ); |
|
414 TInt ret = dialog->ExecuteLD(); |
|
415 TBuf<128> test = _L("FI returned: "); |
|
416 test.AppendNum(ret); |
|
417 iEikonEnv->InfoMsg(test); |
|
418 return ret; |
|
419 } |
|
420 |
|
421 // End of File |