|
1 /* |
|
2 * Copyright (c) 1997-2009 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 <s32file.h> |
|
20 |
|
21 #include <f32file.h> |
|
22 |
|
23 #include <txtrich.h> |
|
24 |
|
25 #include <frmprint.h> |
|
26 |
|
27 #include <coeutils.h> |
|
28 |
|
29 #include <clock.h> // RMessageWindow::EMaxTextLength |
|
30 |
|
31 #include <barsread.h> |
|
32 |
|
33 #include <prnsetup.h> |
|
34 |
|
35 #include <eikenv.h> |
|
36 #include <techview/eikrted.h> |
|
37 #include <eikfutil.h> |
|
38 #include <techview/eikcfdlg.h> |
|
39 #include <techview/eikon.rsg> |
|
40 |
|
41 #include "WPAPPUI.H" |
|
42 #include "WPDIALGS.H" |
|
43 #include "WPDOC.H" |
|
44 #include "WPPANIC.H" |
|
45 #include "wpresources.h" |
|
46 #include <word.rsg> |
|
47 #include "WORD.HRH" |
|
48 |
|
49 const TInt KExportTextWrapWidth=78; |
|
50 const TInt KMaxTemplateMsgLen = KMaxFileName+32*2; // file name and a pre + post string |
|
51 |
|
52 |
|
53 void CWordAppUi::CreateFileL(const TDesC& aFileName) |
|
54 { |
|
55 TFileName templateFileName=NormalTemplateFileNameL(); |
|
56 CreateFileL(aFileName, templateFileName); |
|
57 } |
|
58 |
|
59 void CWordAppUi::CreateFileL(const TDesC& aFileName, const TDesC& aTemplateFileName) |
|
60 // Support a *switch file* create message from the shell |
|
61 // |
|
62 { |
|
63 DoFileSaveL(EFalse); // do not echo any file save info message |
|
64 Document()->DoFileNewL(aFileName, aTemplateFileName); |
|
65 iEikonEnv->UpdateTaskNameL(); |
|
66 HandleModelChangeL(); |
|
67 iRichEd->ResetUndo(); |
|
68 iRichEd->SetBookmark(); |
|
69 } |
|
70 |
|
71 |
|
72 void CWordAppUi::CmdFileNewL() |
|
73 // Get a filename and create that file |
|
74 // |
|
75 { |
|
76 TFileName fileName; |
|
77 SetInitialPathL(fileName); |
|
78 TFileName templateFileName; |
|
79 CEikDialog* dialog=new(ELeave) CWordTemplateNewFileDialog(&fileName, templateFileName, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue)); |
|
80 if (dialog->ExecuteLD(R_WORD_TEMPLATE_FILE_NEW)) // confirms action if file already exists |
|
81 CreateFileL(fileName, templateFileName); |
|
82 } |
|
83 |
|
84 |
|
85 void CWordAppUi::OpenFileL(const TDesC& aFileName) |
|
86 // Supporta a *switch file* open message from the shell |
|
87 // |
|
88 { |
|
89 DoFileSaveL(EFalse); // do not echo any file save info message |
|
90 DoFileOpenL(aFileName); |
|
91 Document()->SetChanged(EFalse); |
|
92 iRichEd->ResetUndo(); |
|
93 iRichEd->SetBookmark(); |
|
94 } |
|
95 |
|
96 |
|
97 void CWordAppUi::CmdFileOpenL() |
|
98 // Get a filename from and open that file |
|
99 // |
|
100 { |
|
101 TFileName filename; |
|
102 SetInitialPathL(filename); |
|
103 CEikFileOpenDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename); |
|
104 dialog->RestrictToNativeDocumentFiles(); |
|
105 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN)) |
|
106 OpenFileL(filename); |
|
107 } |
|
108 |
|
109 |
|
110 TFileName CWordAppUi::CurrentFilePath()const |
|
111 { |
|
112 TParsePtrC parser(Document()->Process()->MainDocFileName()); |
|
113 return parser.DriveAndPath(); |
|
114 } |
|
115 |
|
116 |
|
117 void CWordAppUi::SetInitialPathL(TFileName& aFileName)const |
|
118 // checks that the initial path exists, creating it if not |
|
119 // if the path was read-only a default is used instead |
|
120 { |
|
121 aFileName=CurrentFilePath(); |
|
122 TRAPD(ret,ConeUtils::EnsurePathExistsL(aFileName) ); |
|
123 if (ret!=KErrNone) |
|
124 {// if the path is eg read-only default to C: |
|
125 TWordFilePath::GetWordDefaultFilePath(aFileName); |
|
126 ConeUtils::EnsurePathExistsL(aFileName); |
|
127 } |
|
128 } |
|
129 |
|
130 TFileName CWordAppUi::NormalTemplateFileNameL()const |
|
131 // Returns the name of the normal template |
|
132 // |
|
133 { |
|
134 TFindFile ff(iEikonEnv->FsSession()); |
|
135 TFileName templateFileName; |
|
136 TWordFilePath::GetNormalTemplateFolderName(templateFileName); |
|
137 TFileName tempFileName; |
|
138 iEikonEnv->ReadResource(tempFileName, R_WORD_NORMAL_TEMPLATE_FILE_NAME); |
|
139 templateFileName.Append(tempFileName); |
|
140 TParsePtr parse(templateFileName); |
|
141 templateFileName[0] = 'Y'; |
|
142 TInt err = ff.FindByDir(parse.NameAndExt(),parse.DriveAndPath()); |
|
143 if(err) |
|
144 { |
|
145 // no normal template, search ROM for blank |
|
146 TWordFilePath::GetNormalTemplateFolderName(templateFileName); |
|
147 iEikonEnv->ReadResource(tempFileName, R_WORD_BLANK_TEMPLATE_FILE_NAME); |
|
148 templateFileName.Append(tempFileName); |
|
149 templateFileName[0] = 'Z'; |
|
150 TParsePtr blankParse(templateFileName); |
|
151 User::LeaveIfError(ff.FindByDir(blankParse.NameAndExt(),blankParse.DriveAndPath())); |
|
152 } |
|
153 return ff.File(); |
|
154 } |
|
155 |
|
156 void CWordAppUi::DoFileOpenL(const TFileName& aFileName) |
|
157 { |
|
158 Document()->DoFileOpenL(aFileName,EFileWrite); |
|
159 iRichEd->ResetUndo(); |
|
160 iRichEd->SetBookmark(); |
|
161 iEikonEnv->UpdateTaskNameL(); |
|
162 HandleModelChangeL(); |
|
163 } |
|
164 |
|
165 |
|
166 void CWordAppUi::CmdFileSaveL() |
|
167 // Ascertain whether the document should be saved. |
|
168 // If so, then save; otherwise do nothing. |
|
169 // |
|
170 {DoFileSaveL(ETrue);} |
|
171 |
|
172 |
|
173 void CWordAppUi::DoFileSaveL(TBool aEchoFileSaved) |
|
174 // If the current document has changed, then save it. |
|
175 // An info message confirmation is only required when not running as embedded. |
|
176 // |
|
177 { |
|
178 if (iRichEd->IsReadOnly()) |
|
179 return; // all changes are lost - allow print model etc.. to be changed. |
|
180 if (DocHasChanged()) |
|
181 { |
|
182 __ASSERT_DEBUG(iDocument->AppFileMode()&EFileWrite,Panic(EWordSaveReadOnlyFile)); |
|
183 SaveL(); |
|
184 iRichEd->SetBookmark(); |
|
185 if (!iContainerAppUi && aEchoFileSaved) |
|
186 iEikonEnv->InfoMsg(R_EIK_TBUF_FILE_SAVED); |
|
187 } |
|
188 else |
|
189 { |
|
190 if (aEchoFileSaved) |
|
191 iEikonEnv->InfoMsg(R_WORD_DOCUMENT_UNCHANGED); |
|
192 } |
|
193 } |
|
194 |
|
195 |
|
196 void CWordAppUi::CmdFileSaveAsL() |
|
197 { |
|
198 TFileName fileName; |
|
199 SetInitialPathL(fileName); |
|
200 CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&fileName,NULL,NULL); |
|
201 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS)) |
|
202 { |
|
203 if (Document()->FileNameExists(fileName)) |
|
204 { |
|
205 CmdFileSaveL(); |
|
206 return; |
|
207 } |
|
208 TEntry entry; |
|
209 if (!iEikonEnv->FsSession().Entry(fileName,entry)) |
|
210 User::LeaveIfError(iEikonEnv->FsSession().Delete(fileName)); |
|
211 Document()->DoFileSaveToNewL(fileName); |
|
212 iEikonEnv->InfoMsg(R_EIK_TBUF_FILE_SAVED); |
|
213 // set the filename label to read correctly |
|
214 iEikonEnv->UpdateTaskNameL(); |
|
215 UpdateFileNameLabelL(); |
|
216 SetReadOnly(EFalse); |
|
217 iRichEd->SetBookmark(); |
|
218 } |
|
219 } |
|
220 |
|
221 |
|
222 void CWordAppUi::CmdFileRevertL() |
|
223 { |
|
224 if (DocHasChanged()) |
|
225 { |
|
226 if (ConfirmationDialogL(ERevertTitle,ERevertText)) |
|
227 { |
|
228 Document()->DoFileRevertL(); |
|
229 TRAPD(ret, |
|
230 HandleModelChangeL()); // resets document to not saved yet. |
|
231 if (ret!=KErrNone) |
|
232 {// Just clear the screen cos we have new content but cannot draw it. |
|
233 CWindowGc& gc=iEikonEnv->SystemGc(); |
|
234 gc.Activate(*iRichEd->DrawableWindow()); |
|
235 gc.Clear(iRichEd->TextView()->ViewRect()); |
|
236 gc.Deactivate(); |
|
237 User::Leave(ret); |
|
238 } |
|
239 Document()->SetChanged(EFalse); |
|
240 iRichEd->ResetUndo(); |
|
241 iRichEd->SetBookmark(); |
|
242 } |
|
243 } |
|
244 else |
|
245 iEikonEnv->InfoMsg(R_WORD_DOCUMENT_UNCHANGED); |
|
246 } |
|
247 |
|
248 void CWordAppUi::CmdFileSaveAsTemplateL() |
|
249 { |
|
250 TFileName filename; |
|
251 CEikDialog* dialog=new(ELeave) CWordSaveAsTemplateDialog(filename, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue)); |
|
252 if (dialog->ExecuteLD(R_WORD_TEMPLATE_SAVE_AS)) |
|
253 { |
|
254 iEikonEnv->BusyMsgL(R_WORD_TEMPLATE_SAVING_FILE,KFileBusyInitialDelayInMicroSeconds); |
|
255 TParse parse; |
|
256 parse.Set(filename,NULL,NULL); |
|
257 if (!EikFileUtils::FolderExists(parse.DriveAndPath())) |
|
258 iEikonEnv->FsSession().MkDirAll(parse.DriveAndPath()); |
|
259 if(ConeUtils::FileExists(filename)) |
|
260 iEikonEnv->FsSession().Delete(filename); |
|
261 Document()->DoFileSaveToNewNoSwitchL(filename); |
|
262 iEikonEnv->BusyMsgCancel(); |
|
263 TFileName file = parse.Name(); // can CEikUnifiedFileNameSelector has guaranteed the extra will fit |
|
264 TBuf<32> msg; |
|
265 iEikonEnv->ReadResource(msg,R_EIK_TBUF_UNIFIED_PRE_DRIVE); |
|
266 file.Append(msg); |
|
267 file.Append(parse.Drive()[0]); |
|
268 iEikonEnv->ReadResource(msg,R_EIK_TBUF_UNIFIED_POST_DRIVE); |
|
269 file.Append(msg); |
|
270 iEikonEnv->ReadResource(msg,R_WORD_TEMPLATE_SAVED_MESSAGE); |
|
271 TBuf<KMaxTemplateMsgLen> fullmsg; |
|
272 fullmsg.Format(msg,&file); |
|
273 iEikonEnv->InfoMsg(fullmsg); |
|
274 } |
|
275 } |
|
276 |
|
277 void CWordAppUi::CmdFileDeleteTemplateL() |
|
278 { |
|
279 TFileName filename=NormalTemplateFileNameL(); |
|
280 CEikDialog* dialog=new(ELeave) CWordDeleteTemplateDialog(filename, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue)); |
|
281 if (dialog->ExecuteLD(R_WORD_TEMPLATE_DELETE)) |
|
282 { |
|
283 if (filename.Length()) |
|
284 iEikonEnv->FsSession().Delete(filename); |
|
285 } |
|
286 } |
|
287 |
|
288 void CWordAppUi::CmdFileTextImportL() |
|
289 { |
|
290 TFileName filename=CurrentFilePath(); |
|
291 CEikDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename,R_WORD_TEXT_IMPORT_DIALOG_TITLE); |
|
292 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN)) |
|
293 { |
|
294 iCoeEnv->WsSession().Flush(); // !! check this out |
|
295 iEikonEnv->BusyMsgL(R_EIK_TBUF_IMPORTING,KFileBusyInitialDelayInMicroSeconds); |
|
296 iRichEd->InsertFromTextFileL(filename,CPlainText::EOrganiseByParagraph); |
|
297 SetPaginationOutOfDate(ETrue); |
|
298 SetDocChanged(); |
|
299 iEikonEnv->BusyMsgCancel(); |
|
300 } |
|
301 } |
|
302 |
|
303 |
|
304 void CWordAppUi::CmdFileTextExportL()const |
|
305 { |
|
306 TFileName filename=CurrentFilePath(); |
|
307 filename.Append(_L(".txt")); |
|
308 ConeUtils::EnsurePathExistsL(filename); |
|
309 CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&filename,NULL,R_WORD_TEXT_EXPORT_DIALOG_TITLE); |
|
310 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS)) |
|
311 { |
|
312 iEikonEnv->BusyMsgL(R_EIK_TBUF_EXPORTING,KFileBusyInitialDelayInMicroSeconds); |
|
313 Text()->ExportAsTextL(filename,CPlainText::EOrganiseByParagraph,KExportTextWrapWidth); |
|
314 iEikonEnv->BusyMsgCancel(); |
|
315 } |
|
316 } |
|
317 |
|
318 void CWordAppUi::CmdFileHtmlImportL() |
|
319 { |
|
320 TFileName filename=CurrentFilePath(); |
|
321 CEikDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename,R_WORD_HTML_IMPORT_DIALOG_TITLE); |
|
322 if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN)) |
|
323 { |
|
324 iCoeEnv->WsSession().Flush(); |
|
325 iEikonEnv->BusyMsgL(R_EIK_TBUF_IMPORTING,KFileBusyInitialDelayInMicroSeconds); |
|
326 iRichEd->InsertFromHtmlFileL(filename); |
|
327 SetPaginationOutOfDate(ETrue); |
|
328 SetDocChanged(); |
|
329 iEikonEnv->BusyMsgCancel(); |
|
330 } |
|
331 } |