home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 27.9 KB | 1,092 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPrHdlr.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPRHDLR_H
- #include "FWPrHdlr.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPRINFO_H
- #include "FWPrInfo.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWPRINT_K
- #include "FWPrint.k"
- #endif
-
- #ifndef FWALERT_H
- #include "FWAlert.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRESACC_H
- #include "FWResAcc.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OpenDoc includes
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfprinting
- #endif
-
- //========================================================================================
- // Local helpers
- //========================================================================================
-
- #ifdef FW_BUILD_WIN
-
- static FW_Boolean gWinAbortPrinting = FALSE;
- static HWND gWinProgressDlg = NULL;
-
- static HWND WinGetFrameWindow(
- Environment* ev,
- ODFrame* frame);
-
-
- static void WinShowControl(
- HWND hWnd,
- int nID,
- BOOL bShow);
-
- static int CALLBACK WinPrintProgessDlgProc(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam);
-
- static BOOL CALLBACK WinAbortProc(
- HDC hDC,
- int nCode);
-
- #endif
-
- #ifdef FW_BUILD_MAC
-
- static DialogPtr gMacProgressDlg = NULL;
- static PrIdleUPP gMacIdleProcUPP = NULL;
- static FW_Boolean gMacPrintAborted = FALSE;
-
- static pascal void MacIdleProc();
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::FW_CPrintHandler
- //----------------------------------------------------------------------------------------
-
- FW_CPrintHandler::FW_CPrintHandler(FW_CPart* part, FW_CFrame* frame, FW_Boolean updateEmbeddedFacets) :
- fPart(part),
- fFrame(frame),
- fPrintView(NULL),
- fUpdateEmbeddedFacets(updateEmbeddedFacets)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::~FW_CPrintHandler
- //----------------------------------------------------------------------------------------
-
- FW_CPrintHandler::~FW_CPrintHandler()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::GetPart
- //----------------------------------------------------------------------------------------
-
- FW_CPart* FW_CPrintHandler::GetPart() const
- {
- return fPart;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::GetFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* FW_CPrintHandler::GetFrame() const
- {
- return fFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::GetPrintView
- //----------------------------------------------------------------------------------------
-
- FW_CView* FW_CPrintHandler::GetPrintView() const
- {
- return fPrintView;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::IsCurrentlyPrintable
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrintHandler::IsCurrentlyPrintable(Environment* /* ev */) const
- {
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CPrintHandler::DoAdjustMenus(Environment *ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- FW_UNUSED(hasMenuFocus);
- if (isRoot)
- {
- menuBar->EnableCommand(ev, kODCommandPageSetup, TRUE);
- menuBar->EnableCommand(ev, kODCommandPrint, IsCurrentlyPrintable(ev));
- }
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::GetPrintContentExtent
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::GetPrintContentExtent(Environment* ev, FW_CPoint& extent) const
- {
- fFrame->GetContentExtent(ev, extent);
- FW_ASSERT(extent.x != FW_kFixed0);
- FW_ASSERT(extent.y != FW_kFixed0);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::GetPrintJobTitle
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::GetPrintJobTitle(Environment* ev, FW_CString& jobTitle) const
- {
- fPart->GetPartName(ev, jobTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled FW_CPrintHandler::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Handled result = FW_kNotHandled;
-
- if (fFrame->IsRoot(ev))
- {
- switch (theMenuEvent.GetCommandID(ev))
- {
- case kODCommandPageSetup:
- HandlePageSetup(ev);
- result = FW_kHandled;
- break;
-
- case kODCommandPrint:
- HandlePrint(ev);
- result = FW_kHandled;
- break;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::DoPageSetupDialog
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrintHandler::DoPageSetupDialog(Environment* ev)
- {
- FW_Boolean result = FALSE;
-
- if (PreModalDialog(ev))
- {
- FW_CPrintInfo* printInfo = GetPrintInfo();
-
- #ifdef FW_SUPPORT_GX
- gxJob job = printInfo->GetGXJob();
- if (job != NULL)
- {
- result = ::GXJobDefaultFormatDialog(job, NULL);
- }
- else
- {
- #endif
- #ifdef FW_BUILD_WIN
- LPPRINTDLG lppd = printInfo->WinGetPrintDlg()
- lppd->Flags = PD_PRINTSETUP;
- lppd->hwndOwner = WinGetFrameWindow(ev, fFrame->GetODFrame(ev));
- result = ::PrintDlg(lppd);
- #endif
- #ifdef FW_BUILD_MAC
- THPrint thPrint = printInfo->MacGetTHPrint();
- result = ::PrStlDialog(thPrint);
- #endif
- #ifdef FW_SUPPORT_GX
- }
- #endif
- PostModalDialog(ev);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::DoJobDialog
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrintHandler::DoJobDialog(Environment* ev)
- {
- FW_Boolean result = FALSE;
-
- if (PreModalDialog(ev))
- {
- FW_CPrintInfo* printInfo = GetPrintInfo();
-
- #ifdef FW_SUPPORT_GX
- gxJob job = printInfo->GetGXJob();
- if (job != NULL)
- {
- result = ::GXJobPrintDialog(job, NULL);
- }
- else
- {
- #endif
- #ifdef FW_BUILD_WIN
- LPPRINTDLG lppd = printInfo->WinGetPrintDlg()
- lppd->Flags = PD_RETURNDC;
- lppd->hwndOwner = WinGetFrameWindow(ev, fFrame->GetODFrame(ev));
- if (::PrintDlg(lppd))
- {
- printInfo->WinUpdatePageRect();
- result = TRUE;
- }
- #endif
- #ifdef FW_BUILD_MAC
- THPrint thPrint = printInfo->MacGetTHPrint();
- (*thPrint)->prJob.iFstPage = 1;
- (*thPrint)->prJob.iLstPage = 9999;
-
- result = ::PrJobDialog(thPrint);
- #endif
- #ifdef FW_SUPPORT_GX
- }
- #endif
- PostModalDialog(ev);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::NotifyNoDefaultPrinter
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::NotifyNoDefaultPrinter(Environment* ev)
- {
- // fix #1345077 we don't want the OpenDoc error dialog after ODF alert
- FW_SetEvError(ev, FW_xNoError);
-
- FW_CString partName;
- fPart->GetPartName(ev, partName);
-
- FW_CString message;
- ::FW_PrivLoadODFString(ev, FW_kNoDefaultPrinterMsg, message);
-
- FW_NoteAlert(partName, message);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::NotifyPrintingCanceled
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::NotifyPrintingCanceled(Environment* ev)
- {
- // fix #1345077 we don't want the OpenDoc error dialog after ODF alert
- FW_SetEvError(ev, FW_xNoError);
-
- FW_CString partName;
- fPart->GetPartName(ev, partName);
-
- FW_CString message;
- ::FW_PrivLoadODFString(ev, FW_kPrintingCanceledMsg, message);
-
- FW_NoteAlert(partName, message);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::PreModalDialog
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrintHandler::PreModalDialog(Environment* ev)
- {
- ODFrame* odFrame = fFrame->GetODFrame(ev);
- ODToken modalFocus = FW_CSession::Tokenize(ev, kODModalFocus);
-
- return FW_CSession::GetArbitrator(ev)->RequestFocus(ev, modalFocus, odFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::PostModalDialog
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::PostModalDialog(Environment* ev)
- {
- ODFrame* odFrame = fFrame->GetODFrame(ev);
- ODToken modalFocus = FW_CSession::Tokenize(ev, kODModalFocus);
-
- FW_CSession::GetArbitrator(ev)->RelinquishFocus(ev, modalFocus, odFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::GetPrintInfo
- //----------------------------------------------------------------------------------------
-
- FW_CPrintInfo* FW_CPrintHandler::GetPrintInfo() const
- {
- FW_CPrintInfo* printInfo = fPart->GetPrintInfo();
-
- #if 0
- if (printInfo == NULL)
- {
- printInfo = fPart->NewPrintInfo();
- fPart->SetPrintInfo(printInfo);
- }
- #endif
-
- return printInfo;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::CreateProgressDialog
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::CreateProgressDialog(
- Environment* ev,
- ODFrame* frame,
- long numPages,
- const FW_CString& title)
- {
- FW_UNUSED(frame);
- FW_CPrintInfo* printInfo = GetPrintInfo();
-
- #ifdef FW_SUPPORT_GX
- gxJob job = printInfo->GetGXJob();
- if (job != NULL)
- return;
- #endif
- #ifdef FW_BUILD_WIN
- FW_ASSERT(gWinProgressDlg == NULL);
-
- HWND hWndParent = WinGetFrameWindow(ev, frame);
- gWinProgressDlg = ::CreateDialog(FW_gInstance,
- FW_kWinPrintDialog, hWndParent, WinPrintProgessDlgProc);
- FW_ASSERT(gWinProgressDlg);
-
- ::EnableWindow(hWndParent, FALSE);
-
- // Initialize some fields
- ::SetDlgItemText(gWinProgressDlg, FW_kFileNameID, title);
- ::SetDlgItemInt(gWinProgressDlg, FW_kTotalPagesNumID, numPages, TRUE);
- ::ShowWindow(gWinProgressDlg, SW_NORMAL);
- ::UpdateWindow(gWinProgressDlg);
-
- // Set up the abort proc
- gWinAbortPrinting = FALSE;
- ::SetAbortProc(lppd->hDC, WinAbortProc);
- #endif
- #ifdef FW_BUILD_MAC
- FW_ASSERT(gMacProgressDlg == NULL);
-
- gMacPrintAborted = FALSE;
-
- FW_PSharedLibraryResourceFile resourceFile(ev);
- gMacProgressDlg = ::GetNewDialog(FW_kMacPrintDialog, NULL, (WindowPtr) -1L);
-
- // Return if no Progress dialog resource available
- if (!gMacProgressDlg) return;
-
- THPrint thPrint = printInfo->MacGetTHPrint();
- gMacIdleProcUPP = NewPrIdleProc(MacIdleProc);
- (*thPrint)->prJob.pIdleProc = gMacIdleProcUPP;
-
- ::HideDialogItem(gMacProgressDlg, FW_kCurrentPageStrID);
- ::HideDialogItem(gMacProgressDlg, FW_kCurrentPageNumID);
-
- ::HideDialogItem(gMacProgressDlg, FW_kCancelingJobID);
-
- short iType;
- Handle iHndl;
- Rect iRect;
- Str255 pasString;
-
- ::GetDialogItem(gMacProgressDlg, FW_kFileNameID, &iType, &iHndl, &iRect);
- title.ExportPascal(pasString);
- ::SetDialogItemText(iHndl, pasString);
- ::SetWTitle(gMacProgressDlg, pasString);
-
- ::GetDialogItem(gMacProgressDlg, FW_kTotalPagesNumID, &iType, &iHndl, &iRect);
- ::NumToString(numPages, pasString);
- ::SetDialogItemText(iHndl, pasString);
-
- ::ShowWindow(gMacProgressDlg);
- ::SelectWindow(gMacProgressDlg);
- ::UpdateControls(gMacProgressDlg, gMacProgressDlg->visRgn);
- ::UpdateDialog(gMacProgressDlg, gMacProgressDlg->visRgn);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::DestroyProgressDialog
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::DestroyProgressDialog(
- Environment* ev,
- ODFrame* frame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(frame);
- FW_CPrintInfo* printInfo = GetPrintInfo();
-
- #ifdef FW_SUPPORT_GX
- gxJob job = printInfo->GetGXJob();
- if (job != NULL)
- return;
- #endif
- #ifdef FW_BUILD_WIN
- FW_ASSERT(gWinProgressDlg != NULL);
-
- ::SetAbortProc(lppd->hDC, NULL);
-
- HWND hWndParent = WinGetFrameWindow(ev, frame);
- ::EnableWindow(hWndParent, TRUE);
- ::EndDialog(gWinProgressDlg, 0);
- gWinProgressDlg = NULL;
- #endif
- #ifdef FW_BUILD_MAC
- // Return if Progress dialog was not created
- if (gMacProgressDlg == NULL) return;
-
- ::DisposeDialog(gMacProgressDlg);
- gMacProgressDlg = NULL;
-
- DisposeRoutineDescriptor(gMacIdleProcUPP);
- gMacIdleProcUPP = NULL;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::UpdateProgressDialog
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::UpdateProgressDialog(
- long pageNumber)
- {
- FW_CPrintInfo* printInfo = GetPrintInfo();
-
- #ifdef FW_SUPPORT_GX
- gxJob job = printInfo->GetGXJob();
- if (job != NULL)
- return;
- #endif
- #ifdef FW_BUILD_WIN
- ::WinShowControl(gWinProgressDlg, FW_kStartingJobID, FALSE);
-
- ::WinShowControl(gWinProgressDlg, FW_kTotalPagesStrID, TRUE);
- ::WinShowControl(gWinProgressDlg, FW_kTotalPagesNumID, TRUE);
-
- ::WinShowControl(gWinProgressDlg, FW_kCurrentPageStrID, TRUE);
- ::WinShowControl(gWinProgressDlg, FW_kCurrentPageNumID, TRUE);
-
- ::SetDlgItemInt(gWinProgressDlg, FW_kCurrentPageNumID, pageNumber, FALSE);
-
- ::UpdateWindow(gWinProgressDlg);
- #endif
- #ifdef FW_BUILD_MAC
- // Return if Progress dialog was not created
- if (!gMacProgressDlg) return;
-
- ::HideDialogItem(gMacProgressDlg, FW_kStartingJobID);
-
- ::ShowDialogItem(gMacProgressDlg, FW_kTotalPagesStrID);
- ::ShowDialogItem(gMacProgressDlg, FW_kTotalPagesNumID);
-
- ::ShowDialogItem(gMacProgressDlg, FW_kCurrentPageStrID);
- ::ShowDialogItem(gMacProgressDlg, FW_kCurrentPageNumID);
-
- short iType;
- Handle iHndl;
- Rect iRect;
- Str255 pasString;
-
- ::GetDialogItem(gMacProgressDlg, FW_kCurrentPageNumID, &iType, &iHndl, &iRect);
- ::NumToString(pageNumber, pasString);
- ::SetDialogItemText(iHndl, pasString);
-
- ::UpdateControls(gMacProgressDlg, gMacProgressDlg->visRgn);
- ::UpdateDialog(gMacProgressDlg, gMacProgressDlg->visRgn);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::HandlePageSetup
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::HandlePageSetup(Environment* ev)
- {
- FW_TRY
- {
- FW_CPrintEnvironment printEnv;
-
- FW_CPrintInfo* printInfo = GetPrintInfo();
- if (printInfo == NULL)
- {
- ODStorageUnit* storageUnit = fPart->GetStorageUnit(ev);
- printInfo = FW_NEW(FW_CPrintInfo, (ev, storageUnit, &printEnv));
- fPart->SetPrintInfo(printInfo);
- fPart->PrintInfoChanged(ev, printInfo);
- }
-
- if(DoPageSetupDialog(ev))
- {
- fPart->PrintInfoChanged(ev, printInfo);
- ODStorageUnit* storageUnit = fPart->GetStorageUnit(ev);
- printInfo->SaveToStorageUnit(ev, storageUnit);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, pr)
- {
- if (pr.GetPlatformError() == FW_xNoDefaultPrinter)
- NotifyNoDefaultPrinter(ev);
- else
- FW_THROW_SAME();
- }
- FW_CATCH_EVERYTHING()
- {
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::HandlePrint
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::HandlePrint(Environment* ev)
- {
- FW_TRY
- {
- FW_CPrintEnvironment printEnv;
-
- FW_CPrintInfo* printInfo = GetPrintInfo();
- if (printInfo == NULL)
- {
- ODStorageUnit* storageUnit = fPart->GetStorageUnit(ev);
- printInfo = FW_NEW(FW_CPrintInfo, (ev, storageUnit, &printEnv));
- fPart->SetPrintInfo(printInfo);
- fPart->PrintInfoChanged(ev, printInfo);
- }
-
- if (DoJobDialog(ev))
- {
- fPart->PrintInfoChanged(ev, printInfo);
- fPrintView = CreatePrintView(ev);
- PrintDocument(ev, &printEnv);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_REFERENCE(FW_XException, pr)
- {
- switch(pr.GetPlatformError())
- {
- case FW_xNoDefaultPrinter:
- {
- NotifyNoDefaultPrinter(ev);
- break;
- }
- case FW_xPrintingCanceled:
- {
- NotifyPrintingCanceled(ev);
- break;
- }
- default:
- {
- if (fPrintView != NULL)
- {
- ReleasePrintView(ev);
- fPrintView = NULL;
- }
- FW_THROW_SAME();
- }
- }
- }
- FW_CATCH_END
-
- if (fPrintView != NULL)
- {
- ReleasePrintView(ev);
- fPrintView = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::CreatePrintView
- //----------------------------------------------------------------------------------------
- // return by default the content view
-
- FW_CView* FW_CPrintHandler::CreatePrintView(Environment* ev)
- {
- return fFrame->GetContentView(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::ReleasePrintView
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::ReleasePrintView(Environment* ev)
- {
- FW_UNUSED(ev);
- // Does nothing
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::PrintDocument
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::PrintDocument(Environment* ev, FW_CPrintEnvironment* printEnv)
- {
- long xPageCount, yPageCount;
- CountPrintPages(ev, xPageCount, yPageCount);
-
- FW_ASSERT(xPageCount > 0);
- FW_ASSERT(yPageCount > 0);
-
- FW_CPrintInfo* printInfo = GetPrintInfo();
- FW_ASSERT(printInfo != NULL);
-
- short numCopies;
- FW_Boolean collate;
- printInfo->GetCopyCount(numCopies, collate);
-
- long firstPage, lastPage;
- printInfo->GetPages(firstPage, lastPage);
-
- FW_ASSERT(firstPage > 0);
- FW_ASSERT(lastPage > 0);
-
- long numPages = xPageCount * yPageCount;
-
- if (lastPage > numPages)
- {
- // prevent printing past last page
- lastPage = numPages;
- }
-
- // Get some OD objects that we will need
- ODFrame* odFrame = fPrintView->GetFrame(ev)->GetODFrame(ev);
-
- FW_CPrintJob printJob(printInfo, this, printEnv);
-
- // Print the requested number of copies
- short numCopiesPerPrintJob = collate ? 1 : numCopies;
- short numCopiesPerPage = collate ? numCopies : 1;
-
- for (short copiesOfJob = 1; copiesOfJob <= numCopiesPerPrintJob; ++ copiesOfJob)
- {
- FW_CString jobTitle;
- GetPrintJobTitle(ev, jobTitle);
-
- ODFacet* facet = printJob.OpenDocument(ev, odFrame, numPages, jobTitle);
-
- FW_TRY
- {
- for (long pageNumber = firstPage; pageNumber <= lastPage; ++ pageNumber)
- {
- for (short copiesOfPage = 1; copiesOfPage <= numCopiesPerPage; ++ copiesOfPage)
- {
- printJob.OpenPage(pageNumber);
-
- FW_TRY
- {
- long xPage = (pageNumber - 1) % xPageCount;
- long yPage = (pageNumber - 1) / xPageCount;
-
- FW_CPrintInfo* printInfo = GetPrintInfo();
-
- FW_CRect pageBounds = printInfo->GetPageBounds();
- FW_Fixed pageWidth = pageBounds.Width();
- FW_Fixed pageHeight = pageBounds.Height();
-
- pageBounds.Offset(FW_MultipliedByInt(pageWidth, xPage), FW_MultipliedByInt(pageHeight, yPage));
-
- PrintPage(ev, facet, pageBounds, xPage, yPage);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- printJob.ClosePageOnError();
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- printJob.ClosePage();
- }
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- printJob.CloseDocumentOnError(ev, facet);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- printJob.CloseDocument(ev, facet);
- }
-
- printJob.FinishPrinting();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::CountPrintPages
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::CountPrintPages(Environment* ev, long& xPageCount, long& yPageCount)
- {
- FW_CPrintInfo* printInfo = GetPrintInfo();
- FW_ASSERT(printInfo != NULL);
-
- FW_CRect pageBounds = printInfo->GetPageBounds();
- FW_Fixed pageWidth = pageBounds.Width();
- FW_Fixed pageHeight = pageBounds.Height();
-
- FW_CPoint content;
- GetPrintContentExtent(ev, content);
-
- FW_ASSERT(content.x != FW_kFixed0);
- FW_ASSERT(content.y != FW_kFixed0);
-
- xPageCount = FW_FixedToInt((content.x + FW_Half(pageWidth) - FW_kFixedPos1) / pageWidth );
- yPageCount = FW_FixedToInt((content.y + FW_Half(pageHeight) - FW_kFixedPos1) / pageHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrintHandler::PrintPage
- //----------------------------------------------------------------------------------------
-
- void FW_CPrintHandler::PrintPage(Environment* ev, ODFacet* facet, const FW_CRect& pageBounds, long xPage, long yPage)
- {
- FW_UNUSED(xPage);
- FW_UNUSED(yPage);
-
- // ----- Construct an appropriate transform and shape for this page
- // Note: aqPageShape is in content coordinate
- FW_CAcquiredODTransform aqTransform = ::FW_NewODTransform(ev, pageBounds.TopLeft());
-
- FW_CAcquiredODShape aqPageShape = ::FW_NewODShape(ev, pageBounds);
-
- // ----- Intersect the page shape with the print frame's extent
- FW_CPoint content;
- GetPrintContentExtent(ev, content);
-
- {
- FW_CRect contentRect(FW_kFixed0, FW_kFixed0, content.x, content.y);
- FW_CAcquiredODShape aqExtentShape = ::FW_NewODShape(ev, contentRect);
- aqPageShape->Intersect(ev, aqExtentShape);
- }
-
- // Transform from content to frame coordinate
- fPrintView->ViewContentToFrame(ev, aqPageShape);
-
- // Take into account the position and scrolling of the print view
- FW_CAcquiredODTransform aqContentToFrame = fPrintView->AcquireViewContentToFrameTransform(ev);
- aqTransform->PostCompose(ev, aqContentToFrame);
-
- // Set the facet to use this transform and shape
- aqTransform->Invert(ev);
- facet->ChangeGeometry(ev, aqPageShape, aqTransform, NULL);
-
- // Print
- fPrintView->PrivSetTopPrintedView(ev, TRUE);
- FW_TRY
- {
- // ----- First draw the printing view
- fPrintView->HandleDraw(ev, facet, aqPageShape);
-
- // ----- OpenDoc is not going to draw embedded facets. I need to force them to draw -----
- if (fUpdateEmbeddedFacets)
- {
- FW_CFacetIterator ite(ev, facet);
- for (ODFacet* embeddedFacet = ite.First(ev); ite.IsNotComplete(ev); embeddedFacet = ite.Next(ev))
- embeddedFacet->Update(ev, NULL, NULL);
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- fPrintView->PrivSetTopPrintedView(ev, FALSE);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- fPrintView->PrivSetTopPrintedView(ev, FALSE);
- }
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // WinGetFrameWindow
- //----------------------------------------------------------------------------------------
-
- HWND WinGetFrameWindow(
- Environment* ev,
- ODFrame* frame)
- {
- ODFrameFacetIterator* ite = frame->->CreateFacetIterator(ev);
- ODFacet* facet = ite->First(ev);
- delete ite;
-
- return facet->GetWindow(ev)->GetPlatformWindow(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // WinShowControl
- //----------------------------------------------------------------------------------------
-
- void WinShowControl(
- HWND hWnd,
- int nID,
- BOOL bShow)
- {
- HWND hWndControl = ::GetDlgItem(hWnd, nID);
- if (hWndControl != NULL)
- ::ShowWindow(hWndControl, bShow ? SW_SHOW : SW_HIDE);
- }
-
- //----------------------------------------------------------------------------------------
- // WinPrintProgessDlgProc
- //----------------------------------------------------------------------------------------
-
- int CALLBACK WinPrintProgessDlgProc(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return TRUE;
-
- case WM_COMMAND:
- gWinAbortPrinting = TRUE;
-
- ::WinShowControl(gWinProgressDlg, FW_kStartingJobID, FALSE);
-
- ::WinShowControl(gWinProgressDlg, FW_kTotalPagesStrID, FALSE);
- ::WinShowControl(gWinProgressDlg, FW_kTotalPagesNumID, FALSE);
-
- ::WinShowControl(gWinProgressDlg, FW_kCurrentPageStrID, FALSE);
- ::WinShowControl(gWinProgressDlg, FW_kCurrentPageNumID, FALSE);
-
- ::WinShowControl(gWinProgressDlg, FW_kCancelingJobID, TRUE);
-
- ::UpdateWindow(gWinProgressDlg);
-
- return TRUE;
-
- default:
- return FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // WinAbortProc
- //----------------------------------------------------------------------------------------
-
- BOOL CALLBACK WinAbortProc(
- HDC hDC,
- int nCode)
- {
- MSG msg;
-
- while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
- {
- if (gWinProgressDlg == NULL || !::IsDialogMessage(gWinProgressDlg, &msg))
- {
- ::TranslateMessage(&msg);
- ::DispatchMessage(&msg);
- }
- }
-
- return !gWinAbortPrinting;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
-
- //----------------------------------------------------------------------------------------
- // MacIdleProc
- //----------------------------------------------------------------------------------------
-
- pascal void MacIdleProc()
- {
- #if 0
- short resFile = ::CurResFile();
-
- if (!gMacPrintAborted)
- {
- FW_Boolean bCancel = FALSE;
-
- FW_CMacTempPort tempPort = gMacProgressDlg;
-
- EventRecord event;
- RgnHandle rgnCursor = NULL;
- if (::WaitNextEvent(everyEvent, &event, 0, rgnCursor))
- {
- if (event.what == keyDown || event.what == autoKey)
- {
- if ((event.message & charCodeMask) == '.')
- {
- if ((event.modifiers & cmdKey) != 0)
- {
- short itemType;
- ControlHandle hItem = NULL;
- Rect box;
-
- ::GetDialogItem(gMacProgressDlg, FW_kCancelButtonID, &itemType, (Handle*) &hItem, &box);
- if (hItem != NULL)
- {
- long theTick;
- ::HiliteControl(hItem, 1);
- ::Delay(6,&theTick);
- ::HiliteControl(hItem, 0);
- }
-
- bCancel = TRUE;
- }
- }
- }
- else if (::IsDialogEvent(&event))
- {
- short nItemHit = 0;
- DialogPtr dialog = NULL;
- if (::DialogSelect(&event, &dialog, &nItemHit) &&
- dialog == gMacProgressDlg &&
- nItemHit == FW_kCancelButtonID)
- {
- bCancel = TRUE;
- }
- }
- }
-
- if (bCancel)
- {
- // Update the dialog
- ::HideDialogItem(gMacProgressDlg, FW_kStartingJobID);
-
- ::HideDialogItem(gMacProgressDlg, FW_kTotalPagesStrID);
- ::HideDialogItem(gMacProgressDlg, FW_kTotalPagesNumID);
-
- ::HideDialogItem(gMacProgressDlg, FW_kCurrentPageStrID);
- ::HideDialogItem(gMacProgressDlg, FW_kCurrentPageNumID);
-
- ::ShowDialogItem(gMacProgressDlg, FW_kCancelingJobID);
-
- ::UpdateControls(gMacProgressDlg, gMacProgressDlg->visRgn);
- ::UpdateDialog(gMacProgressDlg, gMacProgressDlg->visRgn);
-
- // Tell the print manager that the job should be aborted
- ::PrSetError(iPrAbort);
-
- gMacPrintAborted = TRUE;
- }
- }
-
- ::UseResFile(resFile);
- #endif
- }
-
- #endif
-
-