home *** CD-ROM | disk | FTP | other *** search
- // PdfAppUi.cpp
- //
- // Copyright (c) 1999-2000 Sander van der Wal. All rights reserved.
- //
- // $Id: pdfappui.cpp 1.4 2000-09-27 09:39:05+02 svdwal Exp svdwal $
- //
- // $Log: pdfappui.cpp $
- // Revision 1.4 2000-09-27 09:39:05+02 svdwal
- // OOM and Trace in separate submenu of Tools
- //
- // Revision 1.3 2000-09-24 21:11:27+02 svdwal
- // Different OOM tests can be turned on and of in a debugger
- //
- // Revision 1.2 2000-09-21 14:02:00+02 svdwal
- // More OOM testing
- //
- // Revision 1.1 2000-09-17 13:18:10+02 svdwal
- // Initial checkin
- //
-
- #include "PdfAppUi.h"
-
- // --o AppArc
- #ifndef __APGTASK_H__
- #include <apgtask.h>
- #endif
- #ifndef __APGWGNAM_H__
- #include <apgwgnam.h>
- #endif
-
- // --o CONE
- #ifndef __COEUTILS_H__
- #include <coeutils.h>
- #endif
-
- // --o EIKON
- #include <eikapp.h>
- #include <eikcfdlg.h>
- #include <eikchkbx.h>
- #include <eikcmbox.h>
- #include <eikcmbut.h>
- #include <eikdll.h>
- #include <eikenv.h>
- #include <eikfindd.h>
- #include <eikfnlab.h>
- #include <eikmenub.h>
- #include <eiklabel.h>
- #include <eikprtpv.h>
- #include <eikproc.h>
- #include <eiktbar.h>
- #include <eiktxlbm.h>
- #include <eiktxlbx.h>
-
- #include <eikcmds.hrh>
- #include <eikmenu.hrh>
- #include <eikon.rsg> // needed for file browse dialog
-
- // User interface
- #include "PdfPageView.h"
- #include "Pdf.hrh"
- #include "Pdf.rsg"
-
- // Framework
- #include "PdfDocument.h"
-
- // Engine
- #include "SearchState.h"
-
- // --o PDFLib
- #include "PDFDoc.h"
- #include "TextOutputDev.h"
-
- // Profiling
- #include "PROFILE.H"
-
- //
- // Global const
- //
- static const TInt KBusyInitialDelay=1000000; // in microseconds
-
- static inline TInt round(double x) { return TInt(x+0.5); };
-
- // index to zoom factor percentage
- static const TInt KZoom[11] = { 33, 50, 66, 75, 87, 100, 125, 150, 200, 300, 400};
-
- static TInt ZoomToIndex(TInt aZoom)
- {
- TInt index;
- if (aZoom == CPdfPageView::KZoomPage)
- index = 11;
- else if (aZoom == CPdfPageView::KZoomWidth)
- index = 12;
- else if (aZoom <= 33)
- index = 0;
- else if (aZoom <= 50)
- index = 1;
- else if (aZoom <= 66)
- index = 2;
- else if (aZoom <= 75)
- index = 3;
- else if (aZoom <= 87)
- index = 4;
- else if (aZoom <= 100)
- index = 5;
- else if (aZoom <= 125)
- index = 6;
- else if (aZoom <= 150)
- index = 7;
- else if (aZoom <= 200)
- index = 8;
- else if (aZoom <= 300)
- index = 9;
- else if (aZoom <= 400)
- index = 10;
- else // > 400
- index = 10;
- return index;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // CPdfTextListBox
- //
- //////////////////////////////////////////////////////////////////////////////
- class CPdfTextListBox: public CEikTextListBox
- {
- public:
- TInt MaxWidth();
- };
-
-
- TInt CPdfTextListBox::MaxWidth()
- {
- iView->CalcDataWidth();
- TInt width=iView->DataWidth();
- width+=(HorizontalMargin()<<1)+iBorder.SizeDelta().iWidth;
- return width;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // CPdfDocInfoDialog
- //
- //////////////////////////////////////////////////////////////////////////////
- class CPdfDocInfoDialog : public CEikDialog
- {
- public:
- CPdfDocInfoDialog(PDFDoc* aDoc):iDoc(aDoc) {};
-
- // -- CEikDialog
- private:
- void PreLayoutDynInitL();
- TBool OkToExitL(TInt /* aKeycode */) { return(ETrue); };
-
- // -- CPdfDocInfoDialog
- private:
- CEikEdwin* Edwin(TInt aControlId) { return STATIC_CAST(CEikEdwin*,Control(aControlId)); };
- void SetDateTimeValueL(TInt aControlId, const TText8* aValue);
- void SetCheckBoxState(TInt aControlId, TBool aState);
-
- private:
- PDFDoc* iDoc;
- };
-
-
- void CPdfDocInfoDialog::PreLayoutDynInitL()
- {
- RAutoObject info;
-
- // print doc info
- iDoc->getDocInfoL(&info);
- if (info.isDict()) {
- RAutoObject obj;
-
- if (info.dictLookupL("Title", &obj)->isString())
- SetEdwinTextL(EPdfDocInfoDialogTitle, &obj.getString()->getTPtr());
- obj.free();
-
- if (info.dictLookupL("Subject", &obj)->isString())
- SetEdwinTextL(EPdfDocInfoDialogSubject, &obj.getString()->getTPtr());
- obj.free();
-
- if (info.dictLookupL("Keywords", &obj)->isString())
- SetEdwinTextL(EPdfDocInfoDialogKeywords, &obj.getString()->getTPtr());
- obj.free();
-
- if (info.dictLookupL("Author", &obj)->isString())
- SetEdwinTextL(EPdfDocInfoDialogAuthor, &obj.getString()->getTPtr());
- obj.free();
-
- if (info.dictLookupL("Creator", &obj)->isString())
- SetEdwinTextL(EPdfDocInfoDialogCreator, &obj.getString()->getTPtr());
- obj.free();
-
- if (info.dictLookupL("Producer", &obj)->isString())
- SetEdwinTextL(EPdfDocInfoDialogProducer, &obj.getString()->getTPtr());
- obj.free();
-
- if (info.dictLookupL("CreationDate", &obj)->isString())
- SetDateTimeValueL(EPdfDocInfoDialogCreated, (const TText8*)obj.getString()->getCString());
- obj.free();
-
- if (info.dictLookupL("ModDate", &obj)->isString())
- SetDateTimeValueL(EPdfDocInfoDialogModified, (const TText8*)obj.getString()->getCString());
- obj.free();
- }
- info.free();
-
- // file size in bytes
- TEntry entry;
- if (KErrNone == iCoeEnv->FsSession().Entry(*iDoc->getFileName(), entry)) {
- SetNumberEditorMinAndMax(EPdfDocInfoDialogFileSize, entry.iSize, entry.iSize);
- SetNumberEditorValue(EPdfDocInfoDialogFileSize, entry.iSize);
- }
-
- SetCheckBoxState(EPdfDocInfoDialogEncrypted, iDoc->isEncrypted());
-
- SetCheckBoxState(EPdfDocInfoDialogPrinting, iDoc->okToPrint());
- SetCheckBoxState(EPdfDocInfoDialogChanging, iDoc->okToChange());
- SetCheckBoxState(EPdfDocInfoDialogSelecting, iDoc->okToCopy());
- SetCheckBoxState(EPdfDocInfoDialogAdding, iDoc->okToAddNotes());
- }
-
-
- void CPdfDocInfoDialog::SetDateTimeValueL(TInt aControlId, const TText8* aValue)
- {
- //
- // the syntax of the time is D:YYYYMMDDHHmmSSOHH'mm'
- // with: D: optinal: indicates this is a date
- // YYYY year, MM month (1-12), DD day (1-31)
- // HH hour (0-23), mm minutes (0-59), SS seconds (0-59)
- // O: + later than GMT, - earlier thhan GMT, % GMT
- // HH'mm': HH hours and mm minutes before/after GMT
-
- TBuf<23> buf;
- buf.Copy(aValue, 23);
-
- if (buf[0] == 'D' && buf[1] == ':')
- buf.Delete(0,2);
-
- // There must be at leas the year
- if (buf.Length() >= 4) {
-
- TDateTime datetime;
-
- // Unfortunately the datetime parsing functions expect months and days
- // to be ofsetted from zero instead of 1. Now we have to do all the work.
- TInt year =(((buf[0]-'0')* 10 + (buf[1]-'0'))*10+(buf[2]-'0'))*10+(buf[3]-'0');
- TMonth month=(buf.Length()< 6) ? EJanuary:TMonth((buf[4]-'0')*10+(buf[5]-'0')-1);
- TInt day =(buf.Length()< 8) ? 0:(buf[ 6]-'0')*10+(buf[ 7]-'0')-1;
-
- TInt hour =(buf.Length()<10) ? 0:(buf[ 8]-'0')*10+(buf[ 9]-'0');
- TInt mins =(buf.Length()<12) ? 0:(buf[10]-'0')*10+(buf[11]-'0');
- TInt secs =(buf.Length()<14) ? 0:(buf[12]-'0')*10+(buf[13]-'0');
-
- if (KErrNone == datetime.Set(year, month, day, hour, mins, secs, 0)) {
-
- TTime time(datetime);
- // turn it into a formatted string according to the locale
- TBuf<64> string;
- TRAPD(ignore,
- time.FormatL(string, _L("%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B")));
-
- //SetTTimeEditorMinAndMax(aControlId, val, val);
- SetEdwinTextL(aControlId, &string);
- }
- }
- }
-
-
- // This way the state stays as it has been set.
- void CPdfDocInfoDialog::SetCheckBoxState(TInt aControlId, TBool aState)
- {
- CEikDialog::SetCheckBoxState(aControlId,
- aState ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- ((CEikCheckBox*)Control(aControlId))->SetBehavior(
- aState ? EEikButtonStaysSet: EEikButtonStaysClear);
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // TPdfUiState
- //
- //////////////////////////////////////////////////////////////////////////////
- TPdfUiState::TPdfUiState()
- {
- SetDefaults();
- }
-
-
- void TPdfUiState::SetDefaults()
- {
- iZoom = 100; // percent
- iRotate = 0;
- iDoLinks = ETrue;
- iDrawAccurate = EFalse;
- iHBarVisibility = 2; // auto
- iVBarVisibility = 2; // auto
- iShowToolBar = ETrue;
- iShowToolBand = ETrue;
- iMaximizeView = EFalse;
- iRenderText = ETrue;
- iRenderLineDrawings = EImageVisOn;
- iRenderImages = ETrue;
- iDitherImages = ETrue;
- iClip = ETrue;
- }
-
-
- void TPdfUiState::InternalizeL(RReadStream& aStream)
- {
- iZoom = aStream.ReadInt32L();
- iRotate = aStream.ReadInt16L();
- iDoLinks = TBool(aStream.ReadInt8L());
- iDrawAccurate = TBool(aStream.ReadInt8L());
-
- iHBarVisibility = aStream.ReadInt8L();
- iVBarVisibility = aStream.ReadInt8L();
-
- iShowToolBar = TBool(aStream.ReadInt8L());
- iShowToolBand = TBool(aStream.ReadInt8L());
- iMaximizeView = TBool(aStream.ReadInt8L());
-
- iRenderText = TBool(aStream.ReadInt8L());
- iRenderLineDrawings = TBool(aStream.ReadInt8L());
- iRenderImages = aStream.ReadInt8L();
- iDitherImages = TBool(aStream.ReadInt8L());
- iClip = TBool(aStream.ReadInt8L());
- }
-
-
- void TPdfUiState::ExternalizeL(RWriteStream& aStream) const
- {
- aStream.WriteInt32L(iZoom);
- aStream.WriteInt16L(iRotate);
- aStream.WriteInt8L(TInt8(iDoLinks));
- aStream.WriteInt8L(TInt8(iDrawAccurate));
-
- aStream.WriteInt8L(iHBarVisibility);
- aStream.WriteInt8L(iVBarVisibility);
-
- aStream.WriteInt8L(TInt8(iShowToolBar));
- aStream.WriteInt8L(TInt8(iShowToolBand));
- aStream.WriteInt8L(TInt8(iMaximizeView));
-
- aStream.WriteInt8L(TInt8(iRenderText));
- aStream.WriteInt8L(TInt8(iRenderLineDrawings));
- aStream.WriteInt8L(iRenderImages);
- aStream.WriteInt8L(TInt8(iDitherImages));
- aStream.WriteInt8L(TInt8(iClip));
- }
-
-
- void TPdfUiState::StoreL(CDictionaryStore* aIniFile, TUid aStreamUid) const
- {
- RDictionaryWriteStream writeStream;
- writeStream.AssignLC(*aIniFile,aStreamUid);
- ExternalizeL(writeStream);
- writeStream.CommitL();
- CleanupStack::PopAndDestroy(); // writeStream
- }
-
-
- void TPdfUiState::RestoreL(CDictionaryStore* aIniFile, TUid aStreamUid)
- {
- RDictionaryReadStream readStream;
- readStream.OpenLC(*aIniFile, aStreamUid);
- InternalizeL(readStream);
- CleanupStack::PopAndDestroy(); // readStream
- }
-
-
- TBool TPdfUiState::operator!=(const TPdfUiState& y)
- {
- if (iZoom != y.iZoom)
- return ETrue;
- else if (iHBarVisibility != y.iHBarVisibility)
- return ETrue;
- else if (iVBarVisibility != y.iVBarVisibility)
- return ETrue;
- else if (iDrawAccurate != y.iDrawAccurate)
- return ETrue;
- else if (iRotate != y.iRotate)
- return ETrue;
- else if (iDoLinks != y.iDoLinks)
- return ETrue;
- else if (iShowToolBar != y.iShowToolBar)
- return ETrue;
- else if (iShowToolBand != y.iShowToolBand)
- return ETrue;
- else if (iMaximizeView != y.iMaximizeView)
- return ETrue;
- else if (iRenderText != y.iRenderText)
- return ETrue;
- else if (iRenderLineDrawings != y.iRenderLineDrawings)
- return ETrue;
- else if (iRenderImages != y.iRenderImages)
- return ETrue;
- else if (iDitherImages != y.iDitherImages)
- return ETrue;
- else if (iClip != y.iClip)
- return ETrue;
- else
- return EFalse;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // CSetViewDialog
- //
- //////////////////////////////////////////////////////////////////////////////
- class CSetViewDialog : public CEikDialog
- {
- public:
- CSetViewDialog(TPdfUiState& aState): iState(aState) {};
-
- // -- CEikDialog
- protected:
- void PreLayoutDynInitL();
- TBool OkToExitL(TInt aKeycode);
- void HandleControlStateChangeL(TInt aControlId);
-
- //--o CSetViewDialog
- protected:
- virtual void ShowControls();
-
- protected:
- TPdfUiState& iState;
- };
-
-
- void CSetViewDialog::PreLayoutDynInitL()
- {
- TInt index = ZoomToIndex(iState.iZoom);
- SetChoiceListCurrentItem(ESetViewDialogZoomFactor, index);
-
- SetCheckBoxState(ESetViewDialogAccurate, iState.iDrawAccurate ? CEikButtonBase::ESet : CEikButtonBase::EClear);
-
- TInt list;
- switch (iState.iRotate) {
- case 90: list = 1; break;
- case 180: list = 2; break;
- case 270: list = 3; break;
- default : list = 0; break;
- }
- SetChoiceListCurrentItem(ESetViewDialogRotate, list);
-
- SetCheckBoxState(ESetViewDialogDoLinks, iState.iDoLinks ? CEikButtonBase::ESet : CEikButtonBase::EClear);
-
- SetHorOptionButListCurrentSet(ESetViewDialogHBar, iState.iHBarVisibility);
- SetHorOptionButListCurrentSet(ESetViewDialogVBar, iState.iVBarVisibility);
-
- SetCheckBoxState(ESetViewDialogRenderText, iState.iRenderText ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- SetCheckBoxState(ESetViewDialogRenderLineDrawings, iState.iRenderLineDrawings ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- SetHorOptionButListCurrentSet(ESetViewDialogRenderImages, iState.iRenderImages);
- SetCheckBoxState(ESetViewDialogDitherImages, iState.iDitherImages ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- SetCheckBoxState(ESetViewDialogClip, iState.iClip ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- ShowControls();
- }
-
-
- TBool CSetViewDialog::OkToExitL(TInt /*aKeycode*/)
- {
- TInt index = ChoiceListCurrentItem(ESetViewDialogZoomFactor);
- switch (index) {
- case 11: iState.iZoom = CPdfPageView::KZoomPage; break;
- case 12: iState.iZoom = CPdfPageView::KZoomWidth; break;
- default: iState.iZoom = KZoom[index]; break;
- }
-
- iState.iDrawAccurate = CheckBoxState(ESetViewDialogAccurate)== CEikButtonBase::ESet;
-
- switch (ChoiceListCurrentItem(ESetViewDialogRotate)) {
- case 1: iState.iRotate = 90; break;
- case 2: iState.iRotate = 180; break;
- case 3: iState.iRotate = 270; break;
- default: iState.iRotate = 0; break;
- }
-
- iState.iDoLinks = CheckBoxState(ESetViewDialogDoLinks) == CEikButtonBase::ESet;
-
- iState.iHBarVisibility = HorOptionButListCurrentSet(ESetViewDialogHBar);
- iState.iVBarVisibility = HorOptionButListCurrentSet(ESetViewDialogVBar);
-
- iState.iRenderText = CheckBoxState(ESetViewDialogRenderText) == CEikButtonBase::ESet;
- iState.iRenderLineDrawings = CheckBoxState(ESetViewDialogRenderLineDrawings) == CEikButtonBase::ESet;
- iState.iRenderImages = HorOptionButListCurrentSet(ESetViewDialogRenderImages);
- iState.iDitherImages = CheckBoxState(ESetViewDialogDitherImages) == CEikButtonBase::ESet;
- iState.iClip = CheckBoxState(ESetViewDialogClip) == CEikButtonBase::ESet;
-
- return ETrue;
- }
-
-
- void CSetViewDialog::HandleControlStateChangeL(TInt aControlId)
- {
- switch (aControlId) {
- case ESetViewDialogZoomFactor:
- break;
- case ESetViewDialogRenderImages:
- // dim the dither checkbox if images aren't drawn
- ShowControls();
- break;
- }
- }
-
-
- void CSetViewDialog::ShowControls()
- {
- TBool visible = (EImageVisOn == HorOptionButListCurrentSet(ESetViewDialogRenderImages));
- MakeLineVisible(ESetViewDialogDitherImages , visible);
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // CPreferencesDialog
- //
- //////////////////////////////////////////////////////////////////////////////
- class CPreferencesDialog: public CSetViewDialog
- {
- public:
- CPreferencesDialog(TPdfUiState& aState): CSetViewDialog(aState) {};
-
- // --o CEikDialog
- private:
- void PreLayoutDynInitL();
- TBool OkToExitL(TInt aKeycode);
- void HandleControlStateChangeL(TInt aControlId);
-
- //--o CPreferencesDialog
- private:
- void ShowControls();
- };
-
-
- void CPreferencesDialog::PreLayoutDynInitL()
- {
- SetCheckBoxState(EPreferencesDialogToolBar , iState.iShowToolBar ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- SetCheckBoxState(EPreferencesDialogToolBand , iState.iShowToolBand ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- SetCheckBoxState(EPreferencesDialogMaximizeView, iState.iMaximizeView ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- CSetViewDialog::PreLayoutDynInitL();
- }
-
-
- void CPreferencesDialog::HandleControlStateChangeL(TInt aControlId)
- {
- // dim the toolbar controls if miximise view is on
- if (aControlId == EPreferencesDialogMaximizeView)
- ShowControls();
- else
- CSetViewDialog::HandleControlStateChangeL(aControlId);
- }
-
-
- TBool CPreferencesDialog::OkToExitL(TInt aKeycode)
- {
- if (CSetViewDialog::OkToExitL(aKeycode)) {
-
- iState.iShowToolBar = CheckBoxState(EPreferencesDialogToolBar) == CEikButtonBase::ESet;
- iState.iShowToolBand = CheckBoxState(EPreferencesDialogToolBand)== CEikButtonBase::ESet;
-
- iState.iMaximizeView = CheckBoxState(EPreferencesDialogMaximizeView) == CEikButtonBase::ESet;
- return(ETrue);
- }
- else
- return EFalse;
- }
-
-
- void CPreferencesDialog::ShowControls()
- {
- CSetViewDialog::ShowControls();
-
- int visible = CheckBoxState(EPreferencesDialogMaximizeView) == CEikButtonBase::EClear;
-
- MakeLineVisible(EPreferencesDialogToolBar , visible);
- MakeLineVisible(EPreferencesDialogToolBand, visible);
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // CPdfAppUi
- //
- //////////////////////////////////////////////////////////////////////////////
- const TUid CPdfAppUi::KPreferencesStreamUid = { 1 };
-
- void CPdfAppUi::ConstructL()
- {
- // Allow base class (CEikAppUi) to perform necessary construction
- BaseConstructL();
-
- // Construct the container control which forms the main view
- // for this application. Construction requires the rectangle
- // available.
- iPageView = new(ELeave) CPdfPageView();
- iPageView->ConstructL(ClientRect());
- iPageView->SetCmdHandler(this);
-
- iAppView = iPageView;
-
- // The container is added to the control stack (for key event handling).
- AddToStackL(iAppView);
-
- // hack toolband: set the font of the page movement buttons to the eikon symbolic font
- for (TInt i=EPdfCmdFirstPage; i<=EPdfCmdLastPage; i++) {
- if (i == EPdfLblCurrentPage)
- i = EPdfCmdNextPage;
- CEikCommandButton* button = STATIC_CAST(CEikCommandButton*, iToolBand->ControlById(i));
- CEikLabel* label = button->Label();
- label->SetFont(iEikonEnv->SymbolFont());
- }
-
- // draw toolbars
- iToolBar->DrawNow();
- iToolBand->DrawNow();
-
- // int ui state
- iUiState = TPdfUiState();
- ReflectUiStateL();
-
- // create the find model and -list
- iFindModel=new(ELeave) SEdwinFindModel;
- iFindModel->iFlags=0;
- iFindList=new(ELeave) CDesCArrayFlat(5);
- iSearchState = 0;
-
- // clear the fields
- CEikLabel* maxPage=STATIC_CAST(CEikLabel*, iToolBand->ControlById(EPdfLblMaxPage));
- maxPage->SetTextL(_L(" "));
-
- CEikLabel* page=STATIC_CAST(CEikLabel*, iToolBand->ControlById(EPdfLblCurrentPage));
- page->SetTextL(_L(" "));
- }
-
-
- CPdfAppUi::~CPdfAppUi()
- {
- delete iSearchState;
- delete iFindModel;
- iFindList->Reset();
- delete iFindList;
-
- delete iPopoutListBox;
-
- delete iPageView;
- }
-
-
- TBool CPdfAppUi::ProcessCommandParametersL(TApaCommand aCommand,TFileName& aDocumentName,const TDesC& /* aTail */)
- {
- if (aCommand==EApaCommandCreate)
- return EFalse; // assume aDocumentName is valid
-
- if (aCommand==EApaCommandRun || aCommand==EApaCommandBackground) {
- TFileName fileName=iEikonEnv->Process()->LastUsedFileL(CEikProcess::ELastOpenFile);
- if (ConeUtils::FileExists(fileName)) {
- aDocumentName=fileName;
- return ETrue;
- }
- }
- return ConeUtils::FileExists(aDocumentName);
- }
-
-
- TFileName CPdfAppUi::CurrentFilePath()const
- {
- TParsePtrC parser(Document()->Process()->MainDocFileName());
- return parser.DriveAndPath();
- }
-
-
- // checks that the initial path exists, creating it if not
- // if the path was read-only a default is used instead
- void CPdfAppUi::SetInitialPathL(TFileName& aFileName)const
- {
- aFileName=CurrentFilePath();
- TRAPD(ret,ConeUtils::EnsurePathExistsL(aFileName) );
- if (ret!=KErrNone) {
- // if the path is eg read-only default to C:
- aFileName=R_DEFAULT_PATH;
- ConeUtils::EnsurePathExistsL(aFileName);
- }
- }
-
-
- void CPdfAppUi::SetModel()
- {
- // Get the model via an ugly cast
- iDoc=((CPdfDocument*)iDocument)->Model();
-
- CEikLabel* maxPage=STATIC_CAST(CEikLabel*, iToolBand->ControlById(EPdfLblMaxPage));
- if (iDoc) {
-
- TBuf<10> num(10);
- num.Num(iDoc->getNumPages());
- maxPage->SetTextL(num);
-
- // Set the UI vars
- CEikLabel* page=STATIC_CAST(CEikLabel*, iToolBand->ControlById(EPdfLblCurrentPage));
- num.Num(1);
- page->SetTextL(num);
- page->DrawNow();
- }
- else {
- maxPage->SetTextL(_L(" "));
- }
- maxPage->DrawNow();
- }
-
-
- void CPdfAppUi::SetPage(TInt aPage)
- {
- CEikLabel* pageControl=STATIC_CAST(CEikLabel*, iToolBand->ControlById(EPdfLblCurrentPage));
-
- TBuf<10> num(10);
- num.Num(aPage);
- pageControl->SetTextL(num);
- pageControl->DrawNow();
-
- iPage = aPage;
- }
-
-
- void CPdfAppUi::UpdateFileNameLabelL()
- {
- // draw the label that is part of the toolbar
- CEikFileNameLabel* label=STATIC_CAST(CEikFileNameLabel*,iToolBar->ControlById(EPdfLblFileName));
- label->UpdateL();
- label->DrawNow();
-
- // draw the same label that is part of the toolband
- label=STATIC_CAST(CEikFileNameLabel*,iToolBand->ControlById(EPdfLblFileName));
- label->UpdateL();
- label->DrawNow();
- }
-
-
- void CPdfAppUi::HandleModelChangeL()
- {
- SetModel();
- iPageView->SetModelL(iDoc);
-
- // update visible signs of the ui state
- iSelection = TRect();
- iPageView->SetSelection(iSelection);
- SetUiStateForModelL();
- ReflectUiStateL();
-
- // set the filename
- iEikonEnv->UpdateTaskNameL();
- UpdateFileNameLabelL();
-
- // start at the first page
- SetPage(iDoc ? 1 : 0);
-
- if (iDoc && iUiState.iDoLinks)
- iDoc->getLinksL(1);
-
- // draw the first page
- StartRenderingL();
- }
-
-
- void CPdfAppUi::SetUiStateForModelL()
- {
- LoadUiStateL(CPdfAppUi::KPreferencesStreamUid, iUiState);
- }
-
-
- void CPdfAppUi::StartRenderingL()
- {
- if (iDoc)
- iPageView->StartRenderingL(iPage, iUiState);
- }
-
-
- void CPdfAppUi::DynInitMenuPaneL(int aMenuId, CEikMenuPane *aMenuPane)
- {
- switch (aMenuId) {
- case R_FILE_MENU:
- if (!iDoc)
- aMenuPane->SetItemDimmed(EPdfCmdDocumentInfo, ETrue);
- break;
-
- case R_MORE_MENU:
- if (!iDoc || !(iDoc->okToCopy()))
- aMenuPane->SetItemDimmed(EPdfCmdExportAsText, ETrue);
- break;
-
- case R_FIND_MENU:
- if (!iDoc) {
- aMenuPane->SetItemDimmed(EEikCmdSearchFind, ETrue);
- aMenuPane->SetItemDimmed(EEikCmdSearchFindAgain, ETrue);
- aMenuPane->SetItemDimmed(EPdfCmdGoTo, ETrue);
- }
- else if (!iSearchState)
- aMenuPane->SetItemDimmed(EEikCmdSearchFindAgain, ETrue);
- break;
-
- case R_VIEW_MENU:
- if (iToolBar->IsVisible())
- aMenuPane->SetItemButtonState(EPdfCmdShowToolBar, EEikMenuItemSymbolOn);
- if (iToolBand->IsVisible())
- aMenuPane->SetItemButtonState(EPdfCmdShowToolBand, EEikMenuItemSymbolOn);
-
- aMenuPane->SetItemDimmed(EPdfCmdShowToolBar, iUiState.iMaximizeView);
- aMenuPane->SetItemDimmed(EPdfCmdShowToolBand, iUiState.iMaximizeView);
- if (iUiState.iMaximizeView)
- aMenuPane->SetItemButtonState(EPdfCmdMaximizeView, EEikMenuItemSymbolOn);
- break;
-
- #if defined(OOM) || defined(TRACE)
- case R_TOOLS_MENU: {
- CEikMenuPane::TItem::SData extraItem;
- extraItem.iCommandId=0;
- extraItem.iCascadeId=R_DEBUG_MENU;
- extraItem.iFlags=0;
- extraItem.iText=_L("Debug");
- aMenuPane->AddMenuItemL(extraItem);
- }
- break;
-
- case R_DEBUG_MENU:
- #ifndef TRACE
- aMenuPane->SetItemDimmed(EPdfTstShowProfile, ETrue);
- #endif
- #ifndef OOM
- aMenuPane->SetItemDimmed(EPdfTstOOM, ETrue);
- #endif
- break;
-
- #endif
-
- // default silk screen menu's
- case R_EIK_SIDEBAR_EDIT_MENU:
- aMenuPane->SetItemDimmed(EEikCmdEditCut, ETrue);
- aMenuPane->SetItemDimmed(EEikCmdEditCopy, ETrue);
- aMenuPane->SetItemDimmed(EEikCmdEditPaste, ETrue);
- break;
-
- case R_EIK_SIDEBAR_IRDA_MENU:
- aMenuPane->SetItemDimmed(EEikCmdIrdaSend, ETrue);
- aMenuPane->SetItemDimmed(EEikCmdIrdaReceive, ETrue);
- break;
-
- default:
- break;
- }
- }
-
-
- void CPdfAppUi::OpenFileL(const TDesC& aFileName)
- {
- // pdf does not write files: no need to save anything
-
- STATIC_CAST(CPdfDocument*,iDocument)->DoOpenFileL(aFileName);
- HandleModelChangeL();
- }
-
-
- TErrorHandlerResponse CPdfAppUi::HandleError(TInt aError, const SExtendedError& aExtErr, TDes& aErrorText, TDes& aContextText)
- {
- iAppView->DrawDeferred();
- return CEikAppUi::HandleError(aError, aExtErr, aErrorText, aContextText);
- }
-
-
- void CPdfAppUi::SetDrawAccurate(TBool aDrawAccurate)
- {
- iUiState.iDrawAccurate = aDrawAccurate;
-
- // redraw the button
- CEikButtonBase* b = (CEikButtonBase*)iToolBand->ControlById(EPdfCmdDrawAccurate);
- b->SetState(iUiState.iDrawAccurate ? CEikButtonBase::ESet : CEikButtonBase::EClear);
- b->DrawNow();
- }
-
-
- void CPdfAppUi::SetZoom(TInt aZoom)
- {
- // turn all buttons off
- CEikButtonBase* b = (CEikButtonBase*)iToolBand->ControlById(EPdfCmdFitActualSize);
- b->SetState(CEikButtonBase::EClear);
- b->DrawNow();
-
- b = (CEikButtonBase*)iToolBand->ControlById(EPdfCmdFitPage);
- b->SetState(CEikButtonBase::EClear);
- b->DrawNow();
-
- b = (CEikButtonBase*)iToolBand->ControlById(EPdfCmdFitWidth);
- b->SetState(CEikButtonBase::EClear);
- b->DrawNow();
-
- // set new state
- iUiState.iZoom = aZoom;
- TInt id;
- if (iUiState.iZoom == 100)
- id = EPdfCmdFitActualSize;
- else if (CPdfPageView::KZoomPage == iUiState.iZoom)
- id = EPdfCmdFitPage;
- else if (CPdfPageView::KZoomWidth == iUiState.iZoom)
- id = EPdfCmdFitWidth;
- else
- return;
-
- b = (CEikButtonBase*)iToolBand->ControlById(id);
- b->SetState(CEikButtonBase::ESet);
- b->DrawNow();
- }
-
-
- void CPdfAppUi::DoZoomL(TInt aZoom)
- {
- TPdfPageViewMemento zoomPars = iUiState;
- zoomPars.iZoom = aZoom;
-
- TPoint center = iPageView->Center();
-
- iPageView->StartRenderingL(iPage, zoomPars);
- SetZoom(zoomPars.iZoom);
- if (!iSelection.IsEmpty())
- iPageView->SetSelection(iSelection);
- else
- iPageView->SetCenter(center);
- }
-
-
- void CPdfAppUi::SetToolBarsL(TBool aShowToolBar, TBool aShowToolBand)
- {
- // Note: don't use Ui state vars iShowToolBar and -Band here
- if (aShowToolBar != iToolBar->IsVisible())
- iToolBar->MakeVisible(aShowToolBar);
-
- if (aShowToolBand != iToolBand->IsVisible())
- iToolBand->MakeVisible(aShowToolBand);
-
- if (aShowToolBar)
- iToolBand->ControlById(EPdfLblFileName)->DrawNow(); // redraw the filename label only
- else if (aShowToolBand) {
- TRect bottomBorder=iAppView->Rect();
- bottomBorder.iTl.iY=bottomBorder.iBr.iY-1;
- STATIC_CAST(RWindow*, iAppView->DrawableWindow())->Invalidate(bottomBorder);
- }
-
- TInt adjacent=ECoeAdjNone;
- if (aShowToolBar)
- adjacent|=ECoeAdjRight;
- if (aShowToolBand)
- adjacent|=ECoeAdjTop;
-
- iAppView->SetAdjacent(adjacent);
- iAppView->SetRectL(ClientRect());
- }
-
-
- void CPdfAppUi::SetMaximizeViewL(TBool aMaximizeView)
- {
- iUiState.iMaximizeView = aMaximizeView;
- if (iUiState.iMaximizeView) {
- SetToolBarsL(EFalse, EFalse);
- iPageView->SetScrollBarVisibility(0, 0);
- }
- else {
- SetToolBarsL(iUiState.iShowToolBar, iUiState.iShowToolBand);
- iPageView->SetScrollBarVisibility(iUiState.iHBarVisibility,
- iUiState.iVBarVisibility);
- }
- }
-
-
- void CPdfAppUi::ReflectUiStateL()
- {
- SetMaximizeViewL(iUiState.iMaximizeView);
- SetDrawAccurate(iUiState.iDrawAccurate);
- SetZoom(iUiState.iZoom);
- }
-
-
- void CPdfAppUi::UpdateUiStateL(const TPdfUiState& aNewState)
- {
- TBool doRedraw = EFalse;
- TBool doDisplay= EFalse;
- TBool doLinks = iUiState.iDoLinks != aNewState.iDoLinks;
-
- if (doLinks ||
- iUiState.iZoom != aNewState.iZoom ||
- iUiState.iDrawAccurate != aNewState.iDrawAccurate ||
- iUiState.iRotate != aNewState.iRotate ||
- iUiState.iRenderText != aNewState.iRenderText ||
- iUiState.iRenderLineDrawings != aNewState.iRenderLineDrawings ||
- iUiState.iRenderImages != aNewState.iRenderImages ||
- iUiState.iDitherImages != aNewState.iDitherImages ||
- iUiState.iClip != aNewState.iClip)
- doDisplay = ETrue;
-
- if (iUiState.iHBarVisibility != aNewState.iHBarVisibility ||
- iUiState.iVBarVisibility != aNewState.iVBarVisibility ||
- iUiState.iShowToolBar != aNewState.iShowToolBar ||
- iUiState.iShowToolBand != aNewState.iShowToolBand ||
- iUiState.iMaximizeView != aNewState.iMaximizeView ||
- (iUiState.iZoom==CPdfPageView::KZoomPage && iUiState.iZoom!=aNewState.iZoom) ||
- (iUiState.iZoom==CPdfPageView::KZoomWidth&& iUiState.iZoom!=aNewState.iZoom)
- )
- doRedraw = ETrue;
-
- iUiState.iHBarVisibility = aNewState.iHBarVisibility;
- iUiState.iVBarVisibility = aNewState.iVBarVisibility;
- iUiState.iShowToolBar = aNewState.iShowToolBar;
- iUiState.iShowToolBand = aNewState.iShowToolBand;
- SetMaximizeViewL(aNewState.iMaximizeView);
-
- if (doLinks)
- iDoc->getLinksL(iPage);
-
- if (doDisplay && iDoc) {
-
- TPoint center = iPageView->Center();
- iPageView->StartRenderingL(iPage, aNewState);
- if (!iSelection.IsEmpty())
- iPageView->SetSelection(iSelection);
- else if (iUiState.iZoom != aNewState.iZoom)
- iPageView->SetCenter(center);
-
- }
- else if (doRedraw) {
- iPageView->DrawNow();
- }
-
- SetDrawAccurate(aNewState.iDrawAccurate);
- SetZoom(aNewState.iZoom);
- iUiState.iRenderText = aNewState.iRenderText;
- iUiState.iRenderLineDrawings = aNewState.iRenderLineDrawings;
- iUiState.iRenderImages = aNewState.iRenderImages;
- iUiState.iDitherImages = aNewState.iDitherImages;
- iUiState.iClip = aNewState.iClip;
- iUiState.iRotate = aNewState.iRotate;
- iUiState.iDoLinks = aNewState.iDoLinks;
- }
-
-
- void CPdfAppUi::LoadUiStateL(const TUid& aStreamUid, TPdfUiState& aUiState)
- {
- CDictionaryStore* iniFile =
- iDocument->Application()->OpenIniFileLC(iDocument->Process()->FsSession());
-
- if (iniFile->IsPresentL(aStreamUid)) {
- TRAPD(ignore, aUiState.RestoreL(iniFile, aStreamUid));
- if (ignore)
- aUiState.SetDefaults();
- }
- else
- aUiState.SetDefaults();
- CleanupStack::PopAndDestroy(); //iniFile
- }
-
-
- void CPdfAppUi::StoreUiStateL(const TUid& aStreamUid, const TPdfUiState& aUiState) const
- {
- CDictionaryStore* iniFile =
- iDocument->Application()->OpenIniFileLC(iDocument->Process()->FsSession());
-
- aUiState.StoreL(iniFile, aStreamUid);
-
- iniFile->CommitL();
- CleanupStack::PopAndDestroy(); // iniFile
- }
-
-
- void CPdfAppUi::DoSearch()
- {
- if (iSearchState->FindNextL()) {
- if (iSearchState->Page() != iPage)
- ChangePageL(iSearchState->Page());
- iSelection = iSearchState->Selection();
- iPageView->SetSelection(iSelection);
- }
- else {
- delete iSearchState;
- iSearchState = 0;
- iSelection = TRect(0,0,0,0);
- iPageView->SetSelection(iSelection);
- iEikonEnv->InfoMsg(R_NOTHING_FOUND);
- }
- }
-
-
- void CPdfAppUi::HandleCommandL(TInt aCommand)
- {
-
- switch (aCommand) {
- case EEikCmdFileOpen: CmdFileOpenL(); break;
- case EPdfCmdDocumentInfo: CmdDocumentInfoL(); break;
- case EPdfCmdExportAsText: CmdExportAsTextL(); break;
- case EEikCmdExit: CmdExit(); break;
-
- case EEikCmdSearchFind: CmdSearchFindL(); break;
- case EEikCmdSearchFindAgain: CmdSearchFindAgainL(); break;
- case EPdfCmdGoTo: CmdGoToL(); break;
-
- case EEikCmdZoomIn: CmdZoomInL(); break;
- case EEikCmdZoomOut: CmdZoomOutL(); break;
- case EPdfCmdSetView: CmdSetViewL(); break;
- case EPdfCmdShowToolBar:
- case EPdfCmdShowToolBand: CmdShowToolBarsL(aCommand); break;
- case EPdfCmdMaximizeView: CmdMaximizeViewL(); break;
-
- case EPdfCmdPreferences: CmdPreferencesL(); break;
- case EEikCmdHelpContents: DoHelpContentsL(ETrue); break; // show Help
- case EEikCmdHelpAbout: CmdHelpAboutL(); break;
-
- #ifdef TRACE
- case EPdfTstShowProfile: CmdShowProfile(); break;
- #endif
- #ifdef OOM
- case EPdfTstOOM: CmdOOML(); break;
- #endif
-
- case EPdfCmdZoomPopup: CmdZoomPopupL(); break;
- case EPdfCmdFitActualSize: CmdFitActualSizeL(); break;
- case EPdfCmdFitPage: CmdFitPageL(); break;
- case EPdfCmdFitWidth: CmdFitWidthL(); break;
-
- case EPdfCmdFirstPage: CmdFirstPageL(); break;
- case EPdfCmdPrevPage: CmdPrevPageL(); break;
- case EPdfCmdNextPage: CmdNextPageL(); break;
- case EPdfCmdLastPage: CmdLastPageL(); break;
-
- case EPdfCmdDrawAccurate: CmdDrawAccurateL(); break;
-
- default: break;
- }
- }
-
-
- void CPdfAppUi::CmdFileOpenL()
- {
- _LIT(KPdfExtension, "pdf");
-
- // Set an initial value for the folder to contain the new file
- // Pass this to the dialog box to display in the "Folder" field.
- TFileName filename(CurrentFilePath());
- SetInitialPathL(filename);
-
- // Launch the standard EIKON dialog for the user to enter a filename
- CEikFileOpenDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename);
- dialog->SetRequiredExtension(&KPdfExtension);
-
- // If the dialog returns a filename, open the file.
- if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN)) {
-
- iPageView->CancelRendering();
- delete iSearchState;
- iSearchState = 0;
-
- OpenFileL(filename);
- }
- }
-
-
- void CPdfAppUi::CmdDocumentInfoL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- CEikDialog* dialog = new(ELeave) CPdfDocInfoDialog(iDoc);
- dialog->ExecuteLD(R_DOC_INFO_DIALOG);
- }
-
-
- void CPdfAppUi::CmdExportAsTextL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- // check for copy permission
- if (!iDoc->okToCopy()) {
- iEikonEnv->InfoMsg(R_COPYING_OF_TEXT_FROM_THIS_DOCUMENT_IS_NOT_ALLOWED);
- return;
- }
-
- TFileName textFileName=*iDoc->getFileName();
- textFileName.Replace(textFileName.Length()-4, 4, _L(".txt"));
- //filename.Append(_L(".txt"));
- ConeUtils::EnsurePathExistsL(textFileName);
- CEikDialog* dialog=new(ELeave) CEikFileSaveAsDialog(&textFileName,NULL,R_EXPORT_AS_TEXT_DIALOG_TITLE);
- if (!dialog->ExecuteLD(R_EIK_DIALOG_FILE_SAVEAS))
- return;
-
- // get page range
- TInt firstPage = 1;
- TInt lastPage = iDoc->getNumPages();
-
- GBool useASCII7 = gFalse;
- GBool rawOrder = gFalse;
-
- // exporting as text takes a while
- iAppView->DrawNow();
- iEikonEnv->BusyMsgL(R_EIK_TBUF_EXPORTING, KBusyInitialDelay);
-
- TextOutputDev* textOut = new(ELeave) TextOutputDev();
- CleanupStack::PushL(textOut);
- textOut->ConstructL(&textFileName, useASCII7, rawOrder);
- if (textOut->isOk())
- iDoc->displayPagesL(textOut, firstPage, lastPage, 72, 0);
- CleanupStack::PopAndDestroy(); // delete textOut;
-
- iEikonEnv->BusyMsgCancel();
- }
-
-
- void CPdfAppUi::CmdExit()
- {
- TRAPD(ignore, DoHelpContentsL(EFalse)); // stop our 'Help' app if it is running
- iPageView->CancelRendering();
- Exit();
- }
-
-
- void CPdfAppUi::CmdSearchFindL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- iFindModel->iFlags&=(~CSearchState::EFindAgain);
-
- CEikEdwinFindDialog* dialog=new(ELeave) CEikEdwinFindDialog(iFindModel, iFindList);
- if (dialog->ExecuteLD(R_PDF_FIND_DIALOG)) {
-
- iSelection = TRect(0,0,0,0);
- iPageView->SetSelection(iSelection);
-
- delete iSearchState;
- iSearchState = 0;
- iSearchState = new(ELeave) CSearchState(iDoc, iPage, iFindModel);
- iSearchState->ConstructL();
-
- DoSearch();
- }
- }
-
-
- void CPdfAppUi::CmdSearchFindAgainL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
- iFindModel->iFlags|=CSearchState::EFindAgain;
- if (iSearchState)
- DoSearch();
- }
-
- void CPdfAppUi::ChangePageL(TInt aPage, TBool aTop)
- {
- iPageView->CancelRendering();
- iSelection = TRect(0,0,0,0);
- iPageView->SetSelection(iSelection);
- if (aTop)
- iPageView->ScrollToTop();
- else
- iPageView->ScrollToBottom();
- if (iUiState.iDoLinks)
- iDoc->getLinksL(aPage);
- iPageView->StartRenderingL(aPage, iUiState);
- SetPage(aPage);
- }
-
- void CPdfAppUi::CmdFirstPageL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- if (iPage != 1)
- ChangePageL(1);
- }
-
- void CPdfAppUi::CmdPrevPageL(TBool aTop)
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- if (iPage > 1)
- ChangePageL(iPage-1, aTop);
- }
-
- void CPdfAppUi::CmdNextPageL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- if (iPage < iDoc->getNumPages())
- ChangePageL(iPage+1);
- }
-
-
- void CPdfAppUi::CmdLastPageL(TBool aTop)
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- if (iPage != iDoc->getNumPages())
- ChangePageL(iDoc->getNumPages(), aTop);
- }
-
-
- void CPdfAppUi::CmdCancelL()
- {
- iSelection = TRect(0,0,0,0);
- iPageView->SetSelection(iSelection);
- iPageView->DrawNow();
- }
-
-
- void CPdfAppUi::CmdGoToL()
- {
- if (!iDoc) {
- iEikonEnv->InfoMsg(R_OPEN_A_DOCUMENT);
- return;
- }
-
- TInt newPage = iPage;
- CEikPreviewGotoDialog* dialog=new(ELeave) CEikPreviewGotoDialog(newPage, iDoc->getNumPages());
- if (dialog->ExecuteLD(R_EIK_DIALOG_PREVIEW_GOTO)) {
- if (newPage != iPage)
- ChangePageL(newPage);
- }
- }
-
-
- void CPdfAppUi::CmdShowToolBarsL(TInt aCommand)
- {
- if (aCommand==EPdfCmdShowToolBar)
- iUiState.iShowToolBar = !(iUiState.iShowToolBar);
- else
- iUiState.iShowToolBand = !(iUiState.iShowToolBand);
-
- // toggle state but do not show it
- if (!iUiState.iMaximizeView)
- SetToolBarsL(iUiState.iShowToolBar, iUiState.iShowToolBand);
-
- if (iDoc && (iUiState.iZoom == CPdfPageView::KZoomPage || iUiState.iZoom == CPdfPageView::KZoomWidth))
- StartRenderingL();
- else
- iAppView->DrawNow();
- }
-
-
- void CPdfAppUi::CmdMaximizeViewL()
- {
- SetMaximizeViewL(!iUiState.iMaximizeView);
- if (iDoc && (iUiState.iZoom == CPdfPageView::KZoomPage || iUiState.iZoom == CPdfPageView::KZoomWidth))
- StartRenderingL();
- else
- iAppView->DrawNow();
- }
-
-
- void CPdfAppUi::CmdZoomInL()
- {
- if (iDoc) {
-
- TInt oldZoom;
- TInt zoom;
-
- if (iUiState.iZoom==CPdfPageView::KZoomPage || iUiState.iZoom==CPdfPageView::KZoomWidth)
- oldZoom = iPageView->RealZoom();
- else
- oldZoom = iUiState.iZoom;
-
- if (oldZoom < 33)
- zoom = 33;
- else if (oldZoom < 50)
- zoom = 50;
- else if (oldZoom < 66)
- zoom = 66;
- else if (oldZoom < 75)
- zoom = 75;
- else if (oldZoom < 87)
- zoom = 87;
- else if (oldZoom < 100)
- zoom = 100;
- else if (oldZoom < 125)
- zoom = 125;
- else if (oldZoom < 150)
- zoom = 150;
- else if (oldZoom < 200)
- zoom = 200;
- else if (oldZoom < 300)
- zoom = 300;
- else if (oldZoom < 400)
- zoom = 400;
- else
- zoom = 33;
-
- DoZoomL(zoom);
- }
- }
-
-
- void CPdfAppUi::CmdZoomOutL()
- {
- if (iDoc) {
-
- TInt oldZoom;
- TInt zoom;
-
- if (iUiState.iZoom==CPdfPageView::KZoomPage || iUiState.iZoom==CPdfPageView::KZoomWidth)
- oldZoom = iPageView->RealZoom();
- else
- oldZoom = iUiState.iZoom;
-
- if (oldZoom > 400)
- zoom = 400;
- else if (oldZoom > 300)
- zoom = 300;
- else if (oldZoom > 200)
- zoom = 200;
- else if (oldZoom > 125)
- zoom = 125;
- else if (oldZoom > 100)
- zoom = 100;
- else if (oldZoom > 87)
- zoom = 87;
- else if (oldZoom > 75)
- zoom = 75;
- else if (oldZoom > 66)
- zoom = 66;
- else if (oldZoom > 50)
- zoom = 50;
- else if (oldZoom > 33)
- zoom = 33;
- else
- zoom = 400;
-
- DoZoomL(zoom);
- }
- }
-
-
- void CPdfAppUi::CmdSetViewL()
- {
- TPdfUiState newState = iUiState;
- CSetViewDialog* dialog=new(ELeave) CSetViewDialog(newState);
- if (dialog->ExecuteLD(R_SET_VIEW_DIALOG)) {
- if (newState != iUiState)
- UpdateUiStateL(newState);
- }
- }
-
-
- void CPdfAppUi::CmdPreferencesL()
- {
- TPdfUiState oldPrefs;
- LoadUiStateL(KPreferencesStreamUid, oldPrefs);
-
- TPdfUiState newPrefs = oldPrefs;
- CPreferencesDialog* dialog=new(ELeave) CPreferencesDialog(newPrefs);
- if (dialog->ExecuteLD(R_PREFERENCES_DIALOG)) {
-
- if (oldPrefs != newPrefs) {
-
- // store all new preferences
- StoreUiStateL(KPreferencesStreamUid, newPrefs);
-
- // only set new preferences that differs from old preferences
- // do this by setting the current state in preferences if not changed
- if (oldPrefs.iZoom == newPrefs.iZoom)
- newPrefs.iZoom = iUiState.iZoom;
-
- if (oldPrefs.iDrawAccurate == newPrefs.iDrawAccurate)
- newPrefs.iDrawAccurate = iUiState.iDrawAccurate;
-
- if (oldPrefs.iRenderText == newPrefs.iRenderText)
- newPrefs.iRenderText = iUiState.iRenderText;
-
- if (oldPrefs.iRenderLineDrawings == newPrefs.iRenderLineDrawings)
- newPrefs.iRenderLineDrawings = iUiState.iRenderLineDrawings;
-
- if (oldPrefs.iRenderImages == newPrefs.iRenderImages)
- newPrefs.iRenderImages = iUiState.iRenderImages;
-
- if (oldPrefs.iDitherImages == newPrefs.iDitherImages)
- newPrefs.iDitherImages = iUiState.iDitherImages;
-
- if (oldPrefs.iClip == newPrefs.iClip)
- newPrefs.iClip = iUiState.iClip;
-
- if (oldPrefs.iRotate == newPrefs.iRotate)
- newPrefs.iRotate = iUiState.iRotate;
-
- if (oldPrefs.iDoLinks == newPrefs.iDoLinks)
- newPrefs.iDoLinks = iUiState.iDoLinks;
-
- if (oldPrefs.iHBarVisibility == newPrefs.iHBarVisibility)
- newPrefs.iHBarVisibility = iUiState.iHBarVisibility;
-
- if (oldPrefs.iVBarVisibility == newPrefs.iVBarVisibility)
- newPrefs.iVBarVisibility = iUiState.iVBarVisibility;
-
- if (oldPrefs.iShowToolBar == newPrefs.iShowToolBar)
- newPrefs.iShowToolBar = iUiState.iShowToolBar;
-
- if (oldPrefs.iShowToolBand == newPrefs.iShowToolBand)
- newPrefs.iShowToolBand = iUiState.iShowToolBand;
-
- if (oldPrefs.iMaximizeView == newPrefs.iMaximizeView)
- newPrefs.iMaximizeView = iUiState.iMaximizeView;
-
- // set new ui state
- if (newPrefs != iUiState)
- UpdateUiStateL(newPrefs);
- }
- }
- }
-
-
- void CPdfAppUi::CmdDrawAccurateL()
- {
- TPdfPageViewMemento drawAccuratePars = iUiState;
- drawAccuratePars.iDrawAccurate = !iUiState.iDrawAccurate;
- if (iDoc)
- iPageView->StartRenderingL(iPage, drawAccuratePars);
- SetDrawAccurate(drawAccuratePars.iDrawAccurate);
- }
-
-
- //
- // see 'Professional Symbian Programming', page 424
- //
- void CPdfAppUi::DoHelpContentsL(TBool aStartup)
- {
- // get the help filename
- TFileName appName(Application()->AppFullName());
- TParse parser;
- parser.SetNoWild(_L(".hlp"),&appName, 0);
- TPtrC helpFile(parser.FullName());
- if (!ConeUtils::FileExists(helpFile))
- User::Leave(KErrNotFound);
-
- // schan through open programs
- TPtrC helpFileName(parser.Name());
- HBufC *caption = HBufC::NewLC(helpFileName.Length()+2);
- caption->Des().Format(_L("- %S"), &helpFileName);
- TApaTaskList taskList(iEikonEnv->WsSession());
- TInt numGroups = iEikonEnv->WsSession().NumWindowGroups(0);
-
- // look through applist to see what we can find
- for (TInt index=0; index < numGroups; index++) {
- // Get task information
- TApaTask *task= new(ELeave) TApaTask(taskList.FindByPos(index));
- CleanupStack::PushL(task);
- CApaWindowGroupName* wgName=CApaWindowGroupName::NewLC(iEikonEnv->WsSession(), task->WgId());
- TUid uid = wgName->AppUid();
- TPtrC taskCaption = wgName->Caption();
-
- // check it's a 'Help' app with the desired caption
- TBool found = (uid.iUid == 0x10000171 && taskCaption.FindF(*caption)>=0);
- if (found) {
- // either start or stop our 'Help' app
- if (aStartup)
- task->BringToForeground();
- else
- task->EndTask();
- CleanupStack::PopAndDestroy(3); // wgName, task and caption
- return; // exit procedure
- }
- CleanupStack::PopAndDestroy(2); // wgName and task
- }
- CleanupStack::PopAndDestroy(); // caption
-
- if (aStartup) {
- // if not found, then open using EikDll
- EikDll::StartDocL(helpFile);
- User::After(1000000); // pause 1s
- }
- }
-
-
- void CPdfAppUi::CmdHelpAboutL()
- {
- CEikDialog* dialog = new(ELeave) CEikDialog();
- dialog->ExecuteLD(R_HELP_ABOUT_DIALOG);
- }
-
-
- void CPdfAppUi::HandleControlEventL(CCoeControl* /*aControl*/, TCoeEvent aEventType)
- {
- if (iZoomBoxPopped && (aEventType==EEventRequestCancel || aEventType==EEventRequestExit)) {
-
- TInt zoom = iUiState.iZoom;
-
- if (aEventType==EEventRequestExit) {
- TInt index = iPopoutListBox->CurrentItemIndex();
- switch (index) {
- case 11: zoom = CPdfPageView::KZoomPage; break;
- case 12: zoom = CPdfPageView::KZoomWidth; break;
- default: zoom = KZoom[index]; break;
- }
- }
-
- iEikonEnv->RemoveFromStack(iPopoutListBox);
- delete iPopoutListBox;
- iPopoutListBox = 0;
- iZoomBoxPopped = EFalse;
-
- if (iUiState.iZoom != zoom)
- DoZoomL(zoom);
- }
- return;
- }
-
-
- void CPdfAppUi::CmdZoomPopupL()
- {
- if (iZoomBoxPopped)
- return;
-
- CDesCArray* zoomList = iCoeEnv->ReadDesCArrayResourceL(R_ZOOM_LIST);
- CleanupStack::PushL(zoomList);
-
- TInt index = ZoomToIndex(iUiState.iZoom);
-
- CEikCommandButtonBase* zoomButton = STATIC_CAST(CEikCommandButtonBase*, iToolBand->ControlById(EPdfCmdZoomPopup));
-
- DoCreatePopoutL(zoomList, index, zoomButton);
- iZoomBoxPopped = ETrue;
- }
-
-
- void CPdfAppUi::DoCreatePopoutL(CDesCArray* aText, TInt aIndex, CEikCommandButtonBase* aLaunchingButton)
- {
- CPdfTextListBox* popout=new(ELeave) CPdfTextListBox;
- CleanupStack::PushL(popout);
- popout->ConstructL(0, CEikListBox::EPopout|CEikListBox::ELeftDownInViewRect);
- popout->CreateScrollBarFrameL();
- popout->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
- popout->SetObserver(this);
- iEikonEnv->AddWindowShadow(popout);
- popout->Model()->SetItemTextArray(aText);
- CleanupStack::Pop(); // aText
- const TSize screenSize=iEikonEnv->ScreenDevice()->SizeInPixels();
- TSize butSize=aLaunchingButton->Size();
- TInt width=Max(butSize.iWidth,popout->MaxWidth())+CEikScrollBar::EScrollbarWidth;
- if (width>screenSize.iWidth)
- width = screenSize.iWidth;
- TPoint pos=aLaunchingButton->PositionRelativeToScreen();
- pos.iY+=butSize.iHeight;
- TRect listBoxRect(pos,TSize(width,0));
- popout->CalculatePopoutRect(0,pos.iY,listBoxRect);
- if (listBoxRect.iTl.iY<pos.iY) {
- const TInt itemHeight=popout->ItemHeight();
- while (listBoxRect.iTl.iY<pos.iY)
- listBoxRect.iTl.iY+=itemHeight;
- listBoxRect.iTl.iY=pos.iY;
- }
- if (listBoxRect.iBr.iX>screenSize.iWidth)
- listBoxRect.Move(listBoxRect.iBr.iX-screenSize.iWidth,0);
- popout->SetExtentL(TPoint(pos.iX,listBoxRect.iTl.iY),listBoxRect.Size());
- popout->SetCurrentItemIndex(aIndex);
- iEikonEnv->AddDialogLikeControlToStackL(popout);
- popout->SetLaunchingButton(aLaunchingButton);
- popout->ActivateL();
- CleanupStack::Pop(); // popout
- iPopoutListBox=popout;
- aLaunchingButton->SetIgnoreNextPointerUp();
- iPopoutListBox->ClaimPointerGrab();
- }
-
-
- void CPdfAppUi::CmdFitActualSizeL()
- {
- if (iDoc && 100 != iUiState.iZoom)
- DoZoomL(100);
- }
-
-
- void CPdfAppUi::CmdFitPageL()
- {
- if (iDoc && CPdfPageView::KZoomPage != iUiState.iZoom)
- DoZoomL(CPdfPageView::KZoomPage);
- }
-
-
- void CPdfAppUi::CmdFitWidthL()
- {
- if (iDoc && CPdfPageView::KZoomWidth != iUiState.iZoom)
- DoZoomL(CPdfPageView::KZoomWidth);
- }
-
-
- #ifdef TRACE
- void CPdfAppUi::CmdShowProfile()
- {
- PROFILE_DUMP();
- }
- #endif
-
-
- #ifdef OOM
-
- #include "FbsBitmapOutputDev.h"
-
- void CPdfAppUi::CmdOOML()
- {
- _LIT(KPdfExtension, "pdf");
-
- // As in CmdFileOpenL()
- TFileName filename(CurrentFilePath());
- SetInitialPathL(filename);
- CEikFileOpenDialog* dialog=new(ELeave) CEikFileOpenDialog(&filename);
- dialog->SetRequiredExtension(&KPdfExtension);
- if (!dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
- return;
-
- iPageView->CancelRendering();
-
- // no displaying of links, reallocates memory
- TBool oldLinks = iUiState.iDoLinks;
- iUiState.iDoLinks = EFalse;
-
- // drawing of rotated pages use extra memory
- TInt oldRotate = iUiState.iRotate;
-
- // drawing of zoomed page use extra memory
- TInt oldZoom = iUiState.iZoom;
-
- TInt err;
- TInt i;
-
- // set these vars to zero if you need to skip a test
- TInt run1 =1, run2=1, run3=1, run4=1;
-
- if (run1) {
- // check reading and destroying a doc
- __UHEAP_MARK;
- PDFDoc* newDoc = 0;
- for (i= 1; ; i++) {
- __UHEAP_FAILNEXT(i);
- __UHEAP_MARK;
- TRAP(err, newDoc = DoOpenFileOOML(filename));
- delete newDoc;
- __UHEAP_MARKEND;
- newDoc = 0;
- if (err!=KErrNoMemory)
- break;
- }
- __UHEAP_MARKEND;
- __UHEAP_RESET;
-
- // other errors are still bad
- User::LeaveIfError(err);
-
- User::Beep(440, 1000000);
- }
-
-
- // now it is safe to replace the old doc with the new doc
- STATIC_CAST(CPdfDocument*,iDocument)->DoOpenFileL(filename);
- if (!iDoc->isOk()) {
- iEikonEnv->InfoMsg(_L("Bad document"));
- }
- else {
- // cannot be OOM tested in a trap harness, because it deletes and creates
- // views. however, errors here are trapped by the overall CONE OOM check
- HandleModelChangeL();
- iPageView->CancelRendering();
-
- // no displaying of links, reallocates memory
- iUiState.iDoLinks = EFalse;
-
- // display all the pages
- __UHEAP_MARK;
- for (TInt p=1; p<= iDoc->getNumPages(); p++) {
- // start rendering
- iSelection = TRect(0,0,0,0);
- iPageView->SetSelection(iSelection);
- iPageView->ScrollToTop();
-
- if (run2) {
- // start rendering, then zoom out
- iUiState.iRotate = 0;
- for (TInt zoom = 100; zoom <= 125; zoom += 25) {
- iUiState.iZoom = zoom;
- for (i = 0; ; i++) {
- __UHEAP_FAILNEXT(i);
- __UHEAP_MARK;
- TRAP(err, iPageView->StartRenderingL(p, iUiState));
- iPageView->CancelRendering();
- __UHEAP_MARKEND;
- if (err!=KErrNoMemory)
- break;
- }
- }
- __UHEAP_RESET;
- iUiState.iZoom = oldZoom;
- } // if (run2)
-
- if (run3) {
- // start rendering a rotated page
- __UHEAP_MARK;
- iUiState.iRotate = 90;
- for (i= 0; ; i++) {
- __UHEAP_FAILNEXT(i);
- __UHEAP_MARK;
- TRAP(err, iPageView->StartRenderingL(p, iUiState));
- iPageView->CancelRendering();
- __UHEAP_MARKEND;
- if (err!=KErrNoMemory)
- break;
- }
- iUiState.iRotate = oldRotate;
- __UHEAP_MARKEND;
- __UHEAP_RESET;
-
- User::Beep(660, 1000000);
- } // if (run3)
-
- // it is too hard to do OOM testing on a running active object
- // this is the next best thing
- // zooming is less important here, because that does not generate extra
- // allocations during rendering, only at the start and that is tested above
- if (run4) {
- __UHEAP_MARK;
- for (TInt rotate = 0; rotate <= 90; rotate +=90) {
- iUiState.iRotate = rotate;
- for (i= 0; ; i++) {
- __UHEAP_FAILNEXT(i);
- __UHEAP_MARK;
- TRAP(err, DisplayPageOOML(p));
- __UHEAP_MARKEND;
- if (err!=KErrNoMemory)
- break;
- }
- }
- __UHEAP_MARKEND;
- __UHEAP_RESET;
- User::Beep(660, 1000000);
- } // if (run4)
-
- } // for (p=1; ...
-
- __UHEAP_MARKEND;
-
- // done
- iEikonEnv->InfoMsg(_L("OOM Test passed"));
- User::Beep(880, 1000000);
- }
-
- // restore setting
- iUiState.iDoLinks = oldLinks;
- iUiState.iRotate = oldRotate;
- iUiState.iZoom = oldZoom;
-
- iPageView->SetObserver(0);
- OpenFileL(filename);
- }
-
-
- PDFDoc* CPdfAppUi::DoOpenFileOOML(const TFileName& aFileName)
- {
- PDFDoc* newDoc = new(ELeave) PDFDoc();
- CleanupStack::PushL(newDoc);
- newDoc->ConstructL(Document()->Process()->FsSession(), aFileName);
- CleanupStack::Pop(); // newDoc
- return newDoc;
- }
-
-
- void CPdfAppUi::DisplayPageOOML(TInt aPage)
- {
- // set bitmapsize in twips
- TSize sizeInTwips(round(iDoc->getPageWidth(aPage) *KTwipsPerPoint),
- round(iDoc->getPageHeight(aPage)*KTwipsPerPoint));
-
- // create the bitmap
- CWsBitmap* bitmap = new(ELeave) CWsBitmap(iCoeEnv->WsSession());
- CleanupStack::PushL(bitmap);
- User::LeaveIfError(bitmap->Create(TSize(0,0), iCoeEnv->ScreenDevice()->DisplayMode()));
-
- // create the output device
- CFbsBitmapOutputDev* out = new(ELeave) CFbsBitmapOutputDev(0);
- CleanupStack::PushL(out);
- out->ConstructL(bitmap, iCoeEnv->ScreenDevice()->DisplayMode());
- out->InitPageRendering(sizeInTwips, iUiState);
-
- // draw the page
- iDoc->displayPageL(out, aPage, iUiState.iZoom, iUiState.iRotate, iUiState.iDoLinks);
-
- CleanupStack::PopAndDestroy(2); // out, bitmap
- }
-
- #endif
-