home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / pagepart / iodpgprn.cpp < prev    next >
C/C++ Source or Header  |  1997-04-02  |  12KB  |  393 lines

  1. //   @(#) 1.5 com/src/samples/pagepart/iodpgprn.cpp, odpagepart, od96os2, odos29712d 3/4/97 18:17:58 [3/21/97 17:49:00]
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odpagepart
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28. /*
  29.     File:        IODPgPrn.cpp
  30.  
  31.     Contains:    Implementation of PageLayoutPrintExtension class.
  32.  
  33.     Owned by:    John Alcorn
  34.  
  35.     Copyright:    ⌐ 1996 by IBM, Inc., all rights reserved.
  36.  
  37.     Change History (most recent first):
  38.  
  39.          <1>     10/23/96    JWA        first checked in
  40.  
  41.     To Do:
  42.     In Progress:
  43.         
  44. */
  45.  
  46. #define PageLayoutPrintExtension_Class_Source
  47. #define VARIABLE_MACROS
  48. #define METHOD_MACROS
  49.  
  50. #ifdef _PLATFORM_OS2_
  51. #define INCL_PM
  52. #define INCL_GPI
  53. #define INCL_GPICIDS
  54. #define INCL_GPIPRIMITIVES
  55. #define INCL_DOS
  56. #define INCL_DOSERRORS
  57. #define INCL_DEV
  58. #define INCL_SPL
  59. #define INCL_SPLDOSPRINT
  60.  
  61. #include <os2.h>
  62.  
  63. #define HDRAW HPS
  64. #endif //_PLATFORM_OS2_
  65.  
  66. #ifdef _PLATFORM_WIN32_
  67. #include <windows.h>
  68. #include <winuser.h>
  69. #include <wingdi.h>
  70.  
  71. #define HDRAW HDC
  72. #endif //_PLATFORM_WIN32_
  73.  
  74. #ifndef _ALTPOINT_
  75. #include <AltPoint.h> //jwa - MUST be included BEFORE ODTypes.h (better ODPoint, ODRect)
  76. #endif
  77.  
  78. #include <ODRes.h>
  79. #include <ODTypes.h>
  80. #include <ODUtils.h>
  81. #include <ODDebug.h>
  82. #include <ODExcept.h>
  83.  
  84. #ifndef SOM_ODShape_xh
  85. #include <shape.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODFacet_xh
  89. #include <Facet.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODFrame_xh
  93. #include <Frame.xh>
  94. #endif
  95.  
  96. #ifndef SOM_Module_xh5cStdProps_OpenDoc_StdProps_defined
  97. #include <StdProps.xh>
  98. #endif
  99.  
  100. #ifndef SOM_Module_xh5cStdTypes_OpenDoc_StdTypes_defined
  101. #include <StdTypes.xh>
  102. #endif
  103.  
  104. #include <stdio.h>
  105. #include <iostream.h>
  106.  
  107. #include <IODPrint.hpp>
  108. #include "IODPgPrn.xih"
  109.  
  110. HMODULE IODPgPrn_Resources;
  111.  
  112.  
  113. #ifdef _PLATFORM_OS2_
  114. extern MRESULT EXPENTRY PrintRangeProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  115. #endif //_PLATFORM_OS2_
  116.  
  117.  
  118. char* IODPgPrn_MRI(int id)
  119. {
  120.    char *ReturnValue = (char *) malloc(sizeof(char)*256);
  121. #ifdef _PLATFORM_OS2_
  122. // read string from string table in resource file
  123.    USHORT rc = WinLoadString((HAB)0, IODPgPrn_Resources, id, 255, ReturnValue);
  124.    if (!rc) {
  125.       strcpy(ReturnValue, StringNotFoundMsg);
  126.    } /* endif */
  127. #endif //_PLATFORM_OS2_
  128.  
  129. #ifdef _PLATFORM_WIN32_
  130.    strcpy(ReturnValue, StringNotFoundMsg);
  131. #endif
  132.  
  133.    return ReturnValue;
  134. }
  135.  
  136.  
  137. //==============================================================================
  138. // PageLayoutPrintExtension
  139. //==============================================================================
  140.  
  141.  
  142. //-------------------------------------------------------------------------
  143. //
  144. //  This Method displays the Print Dialog and returns its info in pPi
  145. //
  146. //-------------------------------------------------------------------------
  147.  
  148. SOM_Scope ODBoolean  SOMLINK PageLayoutPrintExtensionDisplayPrintDialog(PageLayoutPrintExtension *somSelf,
  149.                                              Environment *ev,
  150.                                             PRNINFO* pPI,
  151.                                             HWND hwnd,
  152.                                             char *pszTitle)
  153. {
  154.    PageLayoutPrintExtensionData *somThis = PageLayoutPrintExtensionGetData(somSelf);
  155.    PageLayoutPrintExtensionMethodDebug("PageLayoutPrintExtension","PageLayoutPrintExtensionDisplayPrintDialog");
  156.  
  157.    ODBoolean rc = kODFalse;
  158.  
  159. #ifdef _PLATFORM_WIN32_
  160.    PRINTDLG *dlgInfo = new PRINTDLG;
  161.    memset(dlgInfo, 0, sizeof(PRINTDLG));
  162.  
  163.    dlgInfo->lStructSize = sizeof(PRINTDLG);
  164.    dlgInfo->hwndOwner = hwnd;
  165.    dlgInfo->Flags = PD_PAGENUMS | PD_NOSELECTION | PD_RETURNDC |
  166.                     PD_USEDEVMODECOPIESANDCOLLATE;
  167.    dlgInfo->nCopies = 1;
  168.    dlgInfo->nFromPage = 1;
  169.    dlgInfo->nToPage = _NumberOfPages;
  170.    dlgInfo->nMinPage = 1;
  171.    dlgInfo->nMaxPage = _NumberOfPages;
  172.  
  173.    rc = PrintDlg(dlgInfo);
  174.  
  175.    pPI->printDlg = dlgInfo;
  176.    pPI->hdc = dlgInfo->hDC;
  177. #endif //_PLATFORM_WIN32_
  178.  
  179. #ifdef _PLATFORM_OS2_
  180.    PPRNRANGE pRange = new PRNRANGE;
  181.  
  182.    pRange->pszPrinter     = _GetCurrentPrinterQueueDisplayName(ev);
  183.    pRange->pszDocument    = pszTitle;
  184.    pRange->usCopies       = 1;
  185.    pRange->usPrintFrom    = 1;
  186.    pRange->usPrintTo      = _NumberOfPages;
  187.    pRange->fPrintAllPages = kODTrue;
  188.    pRange->fAllowChoiceOfPages = kODTrue;
  189.  
  190.    rc = WinDlgBox (HWND_DESKTOP, hwnd, PrintRangeProc, IODPgPrn_Resources,
  191.            PrintRangeDlgRes, (PVOID)pRange);
  192.  
  193.    pPI->pRange = pRange;
  194. #endif //_PLATFORM_OS2_
  195.  
  196.    return rc;
  197. }
  198.  
  199.  
  200. //-------------------------------------------------------------------------
  201. //
  202. //  This Method handles printing Multiple Pages
  203. //
  204. //-------------------------------------------------------------------------
  205.  
  206. SOM_Scope ODBoolean  SOMLINK PageLayoutPrintExtensionPrintPages(PageLayoutPrintExtension *somSelf,
  207.                                               Environment *ev,
  208.                                              ODFrame* frame,
  209.                                              PRNINFO* pPI)
  210. {
  211.    PageLayoutPrintExtensionData *somThis = PageLayoutPrintExtensionGetData(somSelf);
  212.    PageLayoutPrintExtensionMethodDebug("PageLayoutPrintExtension","PageLayoutPrintExtensionPrintPages");
  213.  
  214.    ODFacet*   prFacet;
  215.    CHAR *buf = new CHAR[50];
  216.  
  217. // TRY
  218.       prFacet = _BeginPrinting(ev, frame, pPI);
  219.  
  220. //    THROW_IF_NULL(prFacet);
  221.       if (prFacet==kODNULL) {
  222.          return(kODFalse);
  223.       } /* endif */
  224.  
  225.       HWND PrintHWND = _GetPrintProgressHWND(ev);
  226.  
  227.       short firstPage = 1;
  228.       short lastPage = _NumberOfPages;
  229.  
  230. #ifdef _PLATFORM_OS2_
  231.       if (pPI->pRange && !pPI->pRange->fPrintAllPages) {
  232.          firstPage = pPI->pRange->usPrintFrom;
  233.          lastPage = pPI->pRange->usPrintTo;
  234.       } /* endif */
  235. #endif //_PLATFORM_OS2_
  236.  
  237. #ifdef _PLATFORM_WIN32_
  238.       if (pPI->printDlg && !(pPI->printDlg->Flags & PD_ALLPAGES)) {
  239.          firstPage = pPI->printDlg->nFromPage;
  240.          lastPage = pPI->printDlg->nToPage;
  241.       } /* endif */
  242. #endif //_PLATFORM_WIN32_
  243.  
  244.       for (short pageNumber=firstPage; pageNumber<=lastPage; pageNumber++) {
  245.          ODBoolean rc;
  246.          if (PrintHWND != NULL)
  247.          {
  248.             sprintf(buf, IODPgPrn_MRI(PrintingPageXString), pageNumber);
  249.  
  250. #ifdef _PLATFORM_OS2_
  251.             rc = WinSetDlgItemText(PrintHWND, PrintPageNum, buf);
  252. #endif
  253.  
  254. #ifdef _PLATFORM_WIN32_
  255.             rc = SetDlgItemText(PrintHWND, PrintPageNum, buf);
  256. #endif
  257.          } /* endif */
  258.  
  259.          ODFrame* prFrame    = prFacet->GetFrame(ev);
  260.          ODShape* frameShape = prFrame->AcquireFrameShape(ev, kNoBias);
  261.  
  262.          ODRect bbox;
  263.          frameShape->GetBoundingBox(ev, &bbox); //bbox is size of frame rect
  264.          frameShape->Release(ev);
  265.  
  266.          pPI->offset.x = bbox.left+_HorzPageOffset*0x10000;
  267.  
  268. #ifdef _PLATFORM_OS2_
  269.          pPI->offset.y = bbox.bottom+(_VertPageOffset+
  270.             (_NumberOfPages-pageNumber)*_TotalPageHeight)*0x10000;
  271. #endif //_PLATFORM_OS2_
  272.  
  273. #ifdef _PLATFORM_WIN32_
  274.          pPI->offset.y = bbox.top+(_VertPageOffset+
  275.             (pageNumber-1)*_TotalPageHeight)*0x10000;
  276. #endif //_PLATFORM_WIN32_
  277.  
  278.          rc = _PrintPage(ev, prFacet, pPI, pageNumber!=lastPage);
  279.  
  280.          if (rc==kODFalse) {
  281.             return kODFalse;
  282.          } /* endif */
  283.       } /* endfor */
  284.  
  285.       _EndPrinting(ev, prFacet);
  286.  
  287. // CATCH_ALL
  288.       // garbage collection needs to be improved
  289. // ENDTRY
  290.  
  291.    return kODTrue; // no error
  292. }
  293.  
  294.  
  295. //-------------------------------------------------------------------------
  296. //
  297. //  This Method Creates the frameShape to be used in BeginPrinting()
  298. //
  299. //-------------------------------------------------------------------------
  300.  
  301. SOM_Scope ODShape*  SOMLINK PageLayoutPrintExtensionSetPrintingFrameShape(PageLayoutPrintExtension *somSelf,
  302.                                                      Environment *ev,
  303.                                                     ODFrame* rootFrame)
  304. {
  305.     PageLayoutPrintExtensionData *somThis = PageLayoutPrintExtensionGetData(somSelf);
  306.     PageLayoutPrintExtensionMethodDebug("PageLayoutPrintExtension","PageLayoutPrintExtensionSetPrintingFrameShape");
  307.  
  308. /* Since our content area is generally different from our frame shape, we   */
  309. /* override this method so that we can set the size of the printing frame   */
  310. /* (to which the drawing during printing is clipped) to be our content area */
  311.  
  312.     ODShape *frameShape = rootFrame->CreateShape(ev);
  313.     ODRect PageRect;
  314.     PageRect.left   = 0;
  315.     PageRect.right  = _TotalPageWidth*0x10000;
  316.  
  317. #ifdef _PLATFORM_OS2_
  318.     PageRect.bottom = 0;
  319.     PageRect.top    = _TotalPageHeight*_NumberOfPages*0x10000;
  320. #endif //_PLATFORM_OS2_
  321.  
  322. #ifdef _PLATFORM_WIN32_
  323.     PageRect.top    = 0;
  324.     PageRect.bottom = _TotalPageHeight*_NumberOfPages*0x10000;
  325. #endif //_PLATFORM_WIN32_
  326.  
  327.     frameShape->SetRectangle(ev, &PageRect);
  328.  
  329.     return(frameShape);
  330. }
  331.  
  332.  
  333. //-------------------------------------------------------------------------
  334. //
  335. //  This Method updates the page width and height instance variables
  336. //
  337. //-------------------------------------------------------------------------
  338.  
  339. SOM_Scope void  SOMLINK PageLayoutPrintExtensionSetPageDimensions(PageLayoutPrintExtension *somSelf,
  340.                                               Environment *ev,
  341.                                               long width, long height)
  342. {
  343.    PageLayoutPrintExtensionData *somThis = PageLayoutPrintExtensionGetData(somSelf);
  344.    PageLayoutPrintExtensionMethodDebug("PageLayoutPrintExtension","PageLayoutPrintExtensionSetTotalPageWidth");
  345.  
  346.    _TotalPageWidth = width;
  347.    _TotalPageHeight = height;
  348. }
  349.  
  350.  
  351. //-------------------------------------------------------------------------
  352. //
  353. //  This Method updates the NumberOfPages instance variable
  354. //
  355. //-------------------------------------------------------------------------
  356.  
  357. SOM_Scope void  SOMLINK PageLayoutPrintExtensionSetNumberOfPages(PageLayoutPrintExtension *somSelf,
  358.                                               Environment *ev,
  359.                                               short count)
  360. {
  361.    PageLayoutPrintExtensionData *somThis = PageLayoutPrintExtensionGetData(somSelf);
  362.    PageLayoutPrintExtensionMethodDebug("PageLayoutPrintExtension","PageLayoutPrintExtensionSetNumberOfPages");
  363.  
  364.    _NumberOfPages = count;
  365. }
  366.  
  367.  
  368. //------------------------------------------------------------------------------
  369. // Initialize our instance variables
  370. //------------------------------------------------------------------------------
  371.  
  372. SOM_Scope void SOMLINK PageLayoutPrintExtensionInitializeForPageLayout
  373.     (PageLayoutPrintExtension *somSelf, Environment *ev,
  374.         ODPart* base, char *pszQueueName, long HorzOffset, long VertOffset,
  375.         long TotalPageWidth, long TotalPageHeight, short NumberOfPages)
  376. {
  377.     PageLayoutPrintExtensionData *somThis = PageLayoutPrintExtensionGetData(somSelf);
  378.     PageLayoutPrintExtensionMethodDebug("PageLayoutPrintExtension","InitializeForPageLayout");
  379.  
  380.     _NumberOfPages = NumberOfPages;
  381.  
  382.     _HorzPageOffset = HorzOffset;
  383.     _VertPageOffset = VertOffset;
  384.  
  385.     _TotalPageWidth = TotalPageWidth;
  386.     _TotalPageHeight = TotalPageHeight;
  387.  
  388.     _Initialize(ev, base, pszQueueName);
  389.  
  390.     IODPgPrn_Resources = _GetResourceHandle(ev);
  391. }
  392.  
  393.