os/textandloc/textrendering/word/SRC/WPAPFILE.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/word/SRC/WPAPFILE.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,331 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <s32file.h>
    1.23 +
    1.24 +#include <f32file.h>
    1.25 +
    1.26 +#include <txtrich.h>
    1.27 +
    1.28 +#include <frmprint.h>
    1.29 +
    1.30 +#include <coeutils.h>
    1.31 +
    1.32 +#include <clock.h>  // RMessageWindow::EMaxTextLength
    1.33 +
    1.34 +#include <barsread.h>
    1.35 +
    1.36 +#include <prnsetup.h>
    1.37 +
    1.38 +#include <eikenv.h>
    1.39 +#include <techview/eikrted.h>
    1.40 +#include <eikfutil.h>
    1.41 +#include <techview/eikcfdlg.h>
    1.42 +#include <techview/eikon.rsg>
    1.43 +
    1.44 +#include "WPAPPUI.H"
    1.45 +#include "WPDIALGS.H"
    1.46 +#include "WPDOC.H"
    1.47 +#include "WPPANIC.H"
    1.48 +#include "wpresources.h"
    1.49 +#include <word.rsg>
    1.50 +#include "WORD.HRH"
    1.51 +
    1.52 +const TInt KExportTextWrapWidth=78;
    1.53 +const TInt KMaxTemplateMsgLen = KMaxFileName+32*2; // file name and a pre + post string
    1.54 +
    1.55 +
    1.56 +void CWordAppUi::CreateFileL(const TDesC& aFileName)
    1.57 +	{
    1.58 +	TFileName templateFileName=NormalTemplateFileNameL();
    1.59 +	CreateFileL(aFileName, templateFileName);
    1.60 +	}
    1.61 +
    1.62 +void CWordAppUi::CreateFileL(const TDesC& aFileName, const TDesC& aTemplateFileName)
    1.63 +// Support a *switch file* create message from the shell
    1.64 +//
    1.65 +	{
    1.66 +	DoFileSaveL(EFalse);  // do not echo any file save info message
    1.67 +	Document()->DoFileNewL(aFileName, aTemplateFileName);
    1.68 +	iEikonEnv->UpdateTaskNameL();
    1.69 +	HandleModelChangeL();
    1.70 +	iRichEd->ResetUndo();
    1.71 +	iRichEd->SetBookmark();
    1.72 +	}
    1.73 +
    1.74 +
    1.75 +void CWordAppUi::CmdFileNewL()
    1.76 +// Get a filename and create that file
    1.77 +//
    1.78 +	{
    1.79 +	TFileName fileName;
    1.80 +	SetInitialPathL(fileName);
    1.81 +	TFileName templateFileName;
    1.82 +	CEikDialog* dialog=new(ELeave) CWordTemplateNewFileDialog(&fileName, templateFileName, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue));
    1.83 +	if (dialog->ExecuteLD(R_WORD_TEMPLATE_FILE_NEW))  // confirms action if file already exists
    1.84 +		CreateFileL(fileName, templateFileName);
    1.85 +	}
    1.86 +
    1.87 +
    1.88 +void CWordAppUi::OpenFileL(const TDesC& aFileName)
    1.89 +// Supporta a *switch file* open message from the shell
    1.90 +//
    1.91 +	{
    1.92 +	DoFileSaveL(EFalse);  // do not echo any file save info message
    1.93 +	DoFileOpenL(aFileName);
    1.94 +	Document()->SetChanged(EFalse);
    1.95 +	iRichEd->ResetUndo();
    1.96 +	iRichEd->SetBookmark();
    1.97 +	}
    1.98 +
    1.99 +
   1.100 +void CWordAppUi::CmdFileOpenL()
   1.101 +// Get a filename from and open that file
   1.102 +//
   1.103 +	{
   1.104 +	TFileName filename;
   1.105 +	SetInitialPathL(filename);
   1.106 +	CEikFileOpenDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename);
   1.107 +	dialog->RestrictToNativeDocumentFiles();
   1.108 +	if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
   1.109 +		OpenFileL(filename);
   1.110 +	}
   1.111 +
   1.112 +
   1.113 +TFileName CWordAppUi::CurrentFilePath()const
   1.114 +	{
   1.115 +	TParsePtrC parser(Document()->Process()->MainDocFileName());
   1.116 +	return parser.DriveAndPath();
   1.117 +	}
   1.118 +
   1.119 +
   1.120 +void CWordAppUi::SetInitialPathL(TFileName& aFileName)const
   1.121 +// checks that the initial path exists, creating it if not
   1.122 +// if the path was read-only a default is used instead
   1.123 +	{
   1.124 +	aFileName=CurrentFilePath();
   1.125 +	TRAPD(ret,ConeUtils::EnsurePathExistsL(aFileName) );
   1.126 +	if (ret!=KErrNone)
   1.127 +		{// if the path is eg read-only default to C:
   1.128 +		TWordFilePath::GetWordDefaultFilePath(aFileName);		
   1.129 +		ConeUtils::EnsurePathExistsL(aFileName);
   1.130 +		}
   1.131 +	}
   1.132 +
   1.133 +TFileName CWordAppUi::NormalTemplateFileNameL()const
   1.134 +// Returns the name of the normal template
   1.135 +//
   1.136 +	{
   1.137 +	TFindFile ff(iEikonEnv->FsSession());
   1.138 +	TFileName templateFileName;
   1.139 +	TWordFilePath::GetNormalTemplateFolderName(templateFileName);
   1.140 +	TFileName tempFileName;
   1.141 +	iEikonEnv->ReadResource(tempFileName, R_WORD_NORMAL_TEMPLATE_FILE_NAME);
   1.142 +	templateFileName.Append(tempFileName);
   1.143 +	TParsePtr parse(templateFileName);
   1.144 +	templateFileName[0] = 'Y';
   1.145 +	TInt err = ff.FindByDir(parse.NameAndExt(),parse.DriveAndPath());
   1.146 +	if(err)
   1.147 +		{
   1.148 +		// no normal template, search ROM for blank
   1.149 +		TWordFilePath::GetNormalTemplateFolderName(templateFileName);
   1.150 +		iEikonEnv->ReadResource(tempFileName, R_WORD_BLANK_TEMPLATE_FILE_NAME);
   1.151 +		templateFileName.Append(tempFileName);
   1.152 +		templateFileName[0] = 'Z';
   1.153 +		TParsePtr blankParse(templateFileName);
   1.154 +		User::LeaveIfError(ff.FindByDir(blankParse.NameAndExt(),blankParse.DriveAndPath()));
   1.155 +		}
   1.156 +	return ff.File();
   1.157 +	}
   1.158 +
   1.159 +void CWordAppUi::DoFileOpenL(const TFileName& aFileName)
   1.160 +	{
   1.161 +	Document()->DoFileOpenL(aFileName,EFileWrite);
   1.162 +	iRichEd->ResetUndo();
   1.163 +	iRichEd->SetBookmark();
   1.164 +	iEikonEnv->UpdateTaskNameL();
   1.165 +	HandleModelChangeL();
   1.166 +	}
   1.167 +
   1.168 +
   1.169 +void CWordAppUi::CmdFileSaveL()
   1.170 +// Ascertain whether the document should be saved.
   1.171 +// If so, then save; otherwise do nothing.
   1.172 +//
   1.173 +	{DoFileSaveL(ETrue);}
   1.174 +
   1.175 +
   1.176 +void CWordAppUi::DoFileSaveL(TBool aEchoFileSaved)
   1.177 +// If the current document has changed, then save it.
   1.178 +// An info message confirmation is only required when not running as embedded.
   1.179 +//
   1.180 +	{
   1.181 +	if (iRichEd->IsReadOnly())
   1.182 +		return;  // all changes are lost - allow print model etc.. to be changed.
   1.183 +	if (DocHasChanged())
   1.184 +		{
   1.185 +		__ASSERT_DEBUG(iDocument->AppFileMode()&EFileWrite,Panic(EWordSaveReadOnlyFile));
   1.186 +		SaveL();
   1.187 +		iRichEd->SetBookmark();
   1.188 +		if (!iContainerAppUi && aEchoFileSaved)
   1.189 +			iEikonEnv->InfoMsg(R_EIK_TBUF_FILE_SAVED);
   1.190 +		}
   1.191 +	else
   1.192 +		{
   1.193 +		if (aEchoFileSaved)
   1.194 +			iEikonEnv->InfoMsg(R_WORD_DOCUMENT_UNCHANGED);
   1.195 +		}
   1.196 +	}
   1.197 +
   1.198 +
   1.199 +void CWordAppUi::CmdFileSaveAsL()
   1.200 +	{
   1.201 +	TFileName fileName;
   1.202 +	SetInitialPathL(fileName);
   1.203 +	CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&fileName,NULL,NULL);
   1.204 +	if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
   1.205 +		{
   1.206 +		if (Document()->FileNameExists(fileName))
   1.207 +			{
   1.208 +			CmdFileSaveL();
   1.209 +			return;
   1.210 +			}
   1.211 +		TEntry entry;
   1.212 +		if (!iEikonEnv->FsSession().Entry(fileName,entry))
   1.213 +			User::LeaveIfError(iEikonEnv->FsSession().Delete(fileName));
   1.214 +		Document()->DoFileSaveToNewL(fileName);
   1.215 +		iEikonEnv->InfoMsg(R_EIK_TBUF_FILE_SAVED);
   1.216 +		// set the filename label to read correctly
   1.217 +		iEikonEnv->UpdateTaskNameL();
   1.218 +		UpdateFileNameLabelL();
   1.219 +		SetReadOnly(EFalse);
   1.220 +		iRichEd->SetBookmark();
   1.221 +		}
   1.222 +	}
   1.223 +
   1.224 +
   1.225 +void CWordAppUi::CmdFileRevertL()
   1.226 +	{
   1.227 +	if (DocHasChanged())
   1.228 +		{
   1.229 +		if (ConfirmationDialogL(ERevertTitle,ERevertText))
   1.230 +			{
   1.231 +			Document()->DoFileRevertL();
   1.232 +			TRAPD(ret,
   1.233 +			HandleModelChangeL());  // resets document to not saved yet.
   1.234 +				if (ret!=KErrNone)
   1.235 +					{// Just clear the screen cos we have new content but cannot draw it.
   1.236 +					CWindowGc& gc=iEikonEnv->SystemGc();
   1.237 +					gc.Activate(*iRichEd->DrawableWindow());
   1.238 +					gc.Clear(iRichEd->TextView()->ViewRect());
   1.239 +					gc.Deactivate();
   1.240 +					User::Leave(ret);
   1.241 +					}
   1.242 +			Document()->SetChanged(EFalse);
   1.243 +			iRichEd->ResetUndo();
   1.244 +			iRichEd->SetBookmark();
   1.245 +			}
   1.246 +		}
   1.247 +	else
   1.248 +		iEikonEnv->InfoMsg(R_WORD_DOCUMENT_UNCHANGED);
   1.249 +	}
   1.250 +
   1.251 +void CWordAppUi::CmdFileSaveAsTemplateL()
   1.252 +	{
   1.253 +	TFileName filename;
   1.254 +	CEikDialog* dialog=new(ELeave) CWordSaveAsTemplateDialog(filename, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue));
   1.255 +	if (dialog->ExecuteLD(R_WORD_TEMPLATE_SAVE_AS))
   1.256 +		{
   1.257 +		iEikonEnv->BusyMsgL(R_WORD_TEMPLATE_SAVING_FILE,KFileBusyInitialDelayInMicroSeconds);
   1.258 +		TParse parse;
   1.259 +		parse.Set(filename,NULL,NULL);
   1.260 +		if (!EikFileUtils::FolderExists(parse.DriveAndPath()))
   1.261 +			iEikonEnv->FsSession().MkDirAll(parse.DriveAndPath());
   1.262 +		if(ConeUtils::FileExists(filename))
   1.263 +			iEikonEnv->FsSession().Delete(filename);
   1.264 +		Document()->DoFileSaveToNewNoSwitchL(filename);
   1.265 +		iEikonEnv->BusyMsgCancel();
   1.266 +		TFileName file = parse.Name(); // can CEikUnifiedFileNameSelector has guaranteed the extra will fit
   1.267 +		TBuf<32> msg;
   1.268 +		iEikonEnv->ReadResource(msg,R_EIK_TBUF_UNIFIED_PRE_DRIVE);
   1.269 +		file.Append(msg);
   1.270 +		file.Append(parse.Drive()[0]);
   1.271 +		iEikonEnv->ReadResource(msg,R_EIK_TBUF_UNIFIED_POST_DRIVE);
   1.272 +		file.Append(msg);
   1.273 +		iEikonEnv->ReadResource(msg,R_WORD_TEMPLATE_SAVED_MESSAGE);
   1.274 +		TBuf<KMaxTemplateMsgLen> fullmsg;
   1.275 +		fullmsg.Format(msg,&file);
   1.276 +		iEikonEnv->InfoMsg(fullmsg);
   1.277 +		}
   1.278 +	}
   1.279 +
   1.280 +void CWordAppUi::CmdFileDeleteTemplateL()
   1.281 +	{
   1.282 +	TFileName filename=NormalTemplateFileNameL();
   1.283 +	CEikDialog* dialog=new(ELeave) CWordDeleteTemplateDialog(filename, TUidType(KNullUid, KUidAppDllDoc, KUidWordAppValue));
   1.284 +	if (dialog->ExecuteLD(R_WORD_TEMPLATE_DELETE))
   1.285 +		{
   1.286 +		if (filename.Length())
   1.287 +			iEikonEnv->FsSession().Delete(filename);
   1.288 +		}
   1.289 +	}
   1.290 +
   1.291 +void CWordAppUi::CmdFileTextImportL()
   1.292 +	{
   1.293 +    TFileName filename=CurrentFilePath();
   1.294 +    CEikDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename,R_WORD_TEXT_IMPORT_DIALOG_TITLE);
   1.295 +    if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
   1.296 +		{
   1.297 +		iCoeEnv->WsSession().Flush();  // !! check this out
   1.298 +		iEikonEnv->BusyMsgL(R_EIK_TBUF_IMPORTING,KFileBusyInitialDelayInMicroSeconds);
   1.299 +		iRichEd->InsertFromTextFileL(filename,CPlainText::EOrganiseByParagraph);
   1.300 +		SetPaginationOutOfDate(ETrue);
   1.301 +		SetDocChanged();
   1.302 +		iEikonEnv->BusyMsgCancel();
   1.303 +		}
   1.304 +	}
   1.305 +
   1.306 +
   1.307 +void CWordAppUi::CmdFileTextExportL()const
   1.308 +	{
   1.309 +	TFileName filename=CurrentFilePath();
   1.310 +	filename.Append(_L(".txt"));
   1.311 +	ConeUtils::EnsurePathExistsL(filename);
   1.312 +	CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&filename,NULL,R_WORD_TEXT_EXPORT_DIALOG_TITLE);
   1.313 +	if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
   1.314 +		{
   1.315 +		iEikonEnv->BusyMsgL(R_EIK_TBUF_EXPORTING,KFileBusyInitialDelayInMicroSeconds);
   1.316 +		Text()->ExportAsTextL(filename,CPlainText::EOrganiseByParagraph,KExportTextWrapWidth); 
   1.317 +		iEikonEnv->BusyMsgCancel();
   1.318 +		}
   1.319 +	}
   1.320 +
   1.321 +void CWordAppUi::CmdFileHtmlImportL()
   1.322 +	{
   1.323 +    TFileName filename=CurrentFilePath();
   1.324 +    CEikDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename,R_WORD_HTML_IMPORT_DIALOG_TITLE);
   1.325 +    if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
   1.326 +		{
   1.327 +		iCoeEnv->WsSession().Flush();
   1.328 +		iEikonEnv->BusyMsgL(R_EIK_TBUF_IMPORTING,KFileBusyInitialDelayInMicroSeconds);
   1.329 +		iRichEd->InsertFromHtmlFileL(filename);
   1.330 +		SetPaginationOutOfDate(ETrue);
   1.331 +		SetDocChanged();
   1.332 +		iEikonEnv->BusyMsgCancel();
   1.333 +		}
   1.334 +	}