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