DirectPrint/DirectPrintApp/ui/src/directprintpreviewview.cpp
changeset 19 2275db202402
parent 11 613a5ff70823
equal deleted inserted replaced
2:acc370d7f2f6 19:2275db202402
       
     1 /*
       
     2 * Copyright (c) 2010 Kanrikogaku Kenkyusho, Ltd.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Kanrikogaku Kenkyusho, Ltd. - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <aknviewappui.h>
       
    19 #include <akntoolbar.h>
       
    20 #include <barsread.h>
       
    21 #include <DirectPrintApp.rsg>
       
    22 #include <eikcore.rsg>
       
    23 #include <prnprev.h> 
       
    24 
       
    25 #include "clog.h"
       
    26 #include "directprintapp.hrh"
       
    27 #include "DirectPrintAppAppUi.h"
       
    28 #include "DirectPrintEngine.h"
       
    29 #include "directprintpreviewview.h"
       
    30 #include "directprintpreviewcontrol.h"
       
    31 
       
    32 CDirectPrintPreviewView::CDirectPrintPreviewView()
       
    33 	{
       
    34 	}
       
    35 
       
    36 CDirectPrintPreviewView::~CDirectPrintPreviewView()
       
    37 	{
       
    38 	delete iPrevCtrl;
       
    39 	}
       
    40 
       
    41 CDirectPrintPreviewView* CDirectPrintPreviewView::NewL()
       
    42 	{
       
    43 	CDirectPrintPreviewView* self = CDirectPrintPreviewView::NewLC();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 CDirectPrintPreviewView* CDirectPrintPreviewView::NewLC()
       
    49 	{
       
    50 	CDirectPrintPreviewView* self = new(ELeave) CDirectPrintPreviewView();
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL();
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 void CDirectPrintPreviewView::ConstructL()
       
    57 	{
       
    58 	LOG("CDirectPrintPreviewView::ConstructL BEGIN");
       
    59 	BaseConstructL(R_DIRECTPRINT_PREVIEW_VIEW);
       
    60 	LOG("CDirectPrintPreviewView::ConstructL END");
       
    61 	}
       
    62 
       
    63 void CDirectPrintPreviewView::HandleCommandL(TInt aCommand)
       
    64 	{
       
    65 	switch (aCommand)
       
    66 		{
       
    67 		case EAknSoftkeyBack:
       
    68 			{
       
    69 			AppUi()->HandleCommandL(EDirectPrintCmdIdPreviewViewBack);
       
    70 			}
       
    71 			break;
       
    72 		case EDirectPrintCmdIdPreviewViewPrint:
       
    73 		case EDirectPrintCmdIdPreviewViewExpand:
       
    74 		case EDirectPrintCmdIdPreviewViewReduce:
       
    75 		case EDirectPrintCmdIdPreviewViewBack:
       
    76 			{
       
    77 			AppUi()->HandleCommandL(aCommand);
       
    78 			}
       
    79 			break;
       
    80 		default:
       
    81 			{
       
    82 			AppUi()->HandleCommandL(aCommand);
       
    83 			}
       
    84 			break;
       
    85 		}
       
    86 	}
       
    87 
       
    88 TUid CDirectPrintPreviewView::Id() const
       
    89 	{
       
    90 	return TUid::Uid(EDirectPrintPreviewViewId);
       
    91 	}
       
    92 
       
    93 void CDirectPrintPreviewView::OfferToolbarEventL(TInt aCommand)
       
    94 	{
       
    95 	switch (aCommand)
       
    96 		{
       
    97 		case EDirectPrintCmdIdPreviewViewPrint:
       
    98 			{
       
    99 			AppUi()->HandleCommandL(aCommand);
       
   100 			}
       
   101 			break;
       
   102 		case EDirectPrintCmdIdPreviewViewExpand:
       
   103 			{
       
   104 			iPrevCtrl->IncrementZoomLevel();
       
   105 			ChangeVisibleState();
       
   106 			}
       
   107 			break;
       
   108 		case EDirectPrintCmdIdPreviewViewReduce:
       
   109 			{
       
   110 			iPrevCtrl->DecrementZoomLevel();
       
   111 			ChangeVisibleState();
       
   112 			}
       
   113 			break;
       
   114 		default:
       
   115 			break;
       
   116 		}
       
   117 	}
       
   118 
       
   119 void CDirectPrintPreviewView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   120 	{
       
   121 	LOG("CDirectPrintPreviewView::DoActivateL BEGIN");
       
   122 	CAknToolbar* toolbar = AppUi()->CurrentFixedToolbar();
       
   123 	toolbar->SetToolbarObserver(this);
       
   124 	// set the title pane
       
   125 	SetActiveTitleL(R_DIRECTPRINT_PREVIEW_TITLE);
       
   126 
       
   127 	if (!iPrevCtrl)
       
   128 		{
       
   129 		CDirectPrintAppAppUi* appui = static_cast<CDirectPrintAppAppUi*>( AppUi() );
       
   130 		CDirectPrintEngine* engine = appui->Engine();
       
   131 
       
   132 		const TInt KPanelGutter=5;
       
   133 		const TInt KShadowWidth=2;
       
   134 		const TInt KLabelFontHeight=12;
       
   135 
       
   136 		TFontSpec normalFontSpec = CEikonEnv::Static()->NormalFont()->FontSpecInTwips();
       
   137 		TFontSpec fontSpec(normalFontSpec);
       
   138 		fontSpec.iHeight = KLabelFontHeight;
       
   139 		iPrintPreviewFormat.iLabelFontSpecInPixels=fontSpec;
       
   140 		iPrintPreviewFormat.iMinPanelGutterInPixels=TSize(KPanelGutter,KPanelGutter);
       
   141 		iPrintPreviewFormat.iPanelShadowWidthInPixels=KShadowWidth;
       
   142 		iPrintPreviewFormat.iPanelShadowColor=KRgbDarkGray;
       
   143 		iPrintPreviewFormat.iPanelMarginColor=KRgbGray;
       
   144 		iPrintPreviewFormat.iLabelOffsetInPixels=5;
       
   145 
       
   146 		iPrevCtrl = CDirectPrintPreviewControl::NewL(NULL);
       
   147 		iPrevCtrl->SetMopParent(this);
       
   148 
       
   149 		//iNumPagesInDoc = engine->MaxPageNum();
       
   150 		iNumPagesInDoc = 3;
       
   151 		iFirstPageToDisplay = 1;
       
   152 		iNumPagesToView = 1;
       
   153 		iNumBands = 2;
       
   154 		iMarginState = CPrintPreviewImage::EShowMargins;
       
   155 
       
   156 		engine->StartPrintPreviewL();
       
   157 
       
   158 		iPrevCtrl->InitializeFormat(*(engine->PrintSetup()),
       
   159 									*(engine->PageRegionPrinter()),
       
   160 									iPrintPreviewFormat,
       
   161 									iNumPagesInDoc,
       
   162 									iFirstPageToDisplay,
       
   163 									iNumPagesToView,
       
   164 									iMarginState);
       
   165 		iPrevCtrl->ActivateL();
       
   166 		iPrevCtrl->SetNumBands(2);
       
   167 		}
       
   168 	iPrevCtrl->SetRect(ClientRect());
       
   169 	iPrevCtrl->SetDrawFlag(ETrue);
       
   170 	iPrevCtrl->MakeVisible(ETrue);
       
   171 	iPrevCtrl->DrawDeferred();
       
   172 	AppUi()->AddToStackL(*this, iPrevCtrl);
       
   173 	ChangeVisibleState();
       
   174 	LOG("CDirectPrintPreviewView::DoActivateL END");
       
   175 	}
       
   176 
       
   177 void CDirectPrintPreviewView::DoDeactivate()
       
   178 	{
       
   179 	LOG("CDirectPrintPreviewView::DoDeactivate BEGIN");
       
   180 	AppUi()->RemoveFromViewStack(*this, iPrevCtrl);
       
   181 	if (iPrevCtrl)
       
   182 		{
       
   183 		CDirectPrintAppAppUi* appui = static_cast<CDirectPrintAppAppUi*>( AppUi() );
       
   184 		CDirectPrintEngine* engine = appui->Engine();
       
   185 		engine->EndPrintPreview();
       
   186 		delete iPrevCtrl;
       
   187 		iPrevCtrl = NULL;
       
   188 		}
       
   189 	LOG("CDirectPrintPreviewView::DoDeactivate END");
       
   190 	}
       
   191 
       
   192 
       
   193 void CDirectPrintPreviewView::NotifyBandPrinted(TInt /*aPercentageOfPagePrinted*/, 
       
   194 												TInt /*aCurrentPageNum*/, 
       
   195 												TInt /*aCurrentCopyNum*/)
       
   196     {
       
   197 	LOG("CDirectPrintPreviewView::NotifyBandPrinted");
       
   198 	} 
       
   199 
       
   200 
       
   201 void CDirectPrintPreviewView::NotifyPrintStarted(TPrintParameters /*aPrintParams*/)
       
   202 	{
       
   203 	LOG("CDirectPrintPreviewView::NotifyPrintStarted");
       
   204 	}
       
   205 
       
   206 void CDirectPrintPreviewView::NotifyPrintEnded(TInt anErrorCode)
       
   207 	// ignore any errors before fully initialized
       
   208     {
       
   209 	LOG1("CDirectPrintPreviewView::NotifyPrintEnded [%d]", anErrorCode);
       
   210 	if (anErrorCode!=KErrNone && anErrorCode!=KErrCancel)
       
   211 		{
       
   212 		TBuf<80> previewError;
       
   213 		if (anErrorCode==KErrNoMemory)
       
   214 			iCoeEnv->ReadResource(previewError,R_EIK_TBUF_NOT_ENOUGH_MEMORY);
       
   215 		else
       
   216 			iCoeEnv->ReadResource(previewError,R_DIRECTPRINT_MSG_PREVIEW_ERR);
       
   217 		iEikonEnv->AlertWin(previewError);
       
   218 		// ToDo: Go back to Main view
       
   219 		//delete this;
       
   220 		}
       
   221 	}
       
   222 
       
   223 void CDirectPrintPreviewView::ChangeVisibleState()
       
   224 	{
       
   225 	CAknToolbar* toolbar = AppUi()->CurrentFixedToolbar();
       
   226 
       
   227 	TBool isDimmedExpand = EFalse;
       
   228 	TBool isDimmedReduce = EFalse;
       
   229 	switch (iPrevCtrl->GetZoomLebel())
       
   230 		{
       
   231 		case CDirectPrintPreviewControl::EPreviewZoomLevel1:
       
   232 			isDimmedReduce = ETrue;
       
   233 			break;
       
   234 		case CDirectPrintPreviewControl::EPreviewZoomLevel5:
       
   235 			isDimmedExpand = ETrue;
       
   236 			break;
       
   237 		default:
       
   238 			break;
       
   239 		}
       
   240 	toolbar->SetItemDimmed(EDirectPrintCmdIdPreviewViewExpand, isDimmedExpand, ETrue);
       
   241 	toolbar->SetItemDimmed(EDirectPrintCmdIdPreviewViewReduce, isDimmedReduce, ETrue);
       
   242 	}
       
   243 
       
   244 // End of file