home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cxprint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.1 KB  |  300 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef __PrintContext_H
  20. //    Avoid include redundancy
  21. //
  22. #define __PrintContext_H
  23.  
  24. //    Purpose:    Provide a context specifically for printing
  25. //    Comments:
  26.  
  27. //    Required Includes
  28. //
  29. #include "cxdc.h"
  30. #include "cxprndlg.h"
  31. #include "drawable.h"
  32.  
  33. //    Constants
  34. //
  35.  
  36. #define POS_CENTER    1
  37. #define POS_LEFT    2
  38. #define POS_RIGHT     3
  39.  
  40. #define    POS_HEADER    1
  41. #define    POS_FOOTER    2
  42.  
  43. typedef enum {
  44.     BLOCK_DISPLAY,
  45.     CAPTURE_POSITION,
  46.     DISPLAY
  47. } PrinterDisplayMode;
  48.  
  49. //    Structures
  50. //
  51. class CPrintCX : public CDCCX    {
  52. //    Construction, destruction, indirect construction
  53. public:
  54.     CPrintCX(URL_Struct *pUrl, SHIST_SavedData *pSavedData = NULL, char *pDisplayUrl = NULL);
  55.     ~CPrintCX();
  56.     virtual void DestroyContext();
  57.     static void PrintAnchorObject(URL_Struct *pUrl, CView *pView, 
  58.                                   SHIST_SavedData *pSavedData = NULL,  char *pDisplayUrl = NULL);
  59.     static void PreviewAnchorObject(CPrintCX *& pPreview, URL_Struct *pUrl, CView *pView, CDC* pDC, 
  60.                                     CPrintInfo *pInfo, SHIST_SavedData *pSavedData = NULL, char *pDisplayUrl = NULL);
  61.     static void AutomatedPrint(const char *pDocument, const char *pPrinter, const char *pDriver, const char *pPort);
  62.  
  63. //    The anchor we're printing.
  64. protected:
  65.     char *m_pAnchor;
  66. // The actual anchor name to use for Header/Footer
  67. // (In Composer: we may be printing from a temporary local file)
  68.     char *m_pDisplayUrl;
  69.  
  70.     HFONT m_hFont;
  71.     int m_iFontCSID;
  72.     int m_iMaxWidth;
  73.     int m_offscrnWidth;
  74.     int m_offscrnHeight;
  75.  
  76. //    CDC Access
  77. private:
  78.     HDC m_hdcPrint;
  79. #ifdef XP_WIN32
  80.     HDC m_hOffscrnDC;
  81.     HDC m_hOrgPrintDC;
  82.     HDC m_hOtherPrintDC;
  83.     HBITMAP m_hOffScrnBitmap;
  84.     HBITMAP m_saveBitmap;
  85.     BOOL m_printBk;
  86.     void SubOffscreenPrintDC() {m_hOrgPrintDC = m_hdcPrint; m_hdcPrint = m_hOffscrnDC;} 
  87.     void RestorePrintDC() { m_hdcPrint = m_hOrgPrintDC;}
  88. #endif
  89.     CDC *m_previewDC;
  90.     lo_SavedEmbedListData* m_embedList;        /* to save the savedData from the URL struct.*/
  91.  
  92. public:
  93.     virtual HDC GetContextDC(){
  94.         if(IsPrintPreview()) 
  95.             return m_previewDC->GetSafeHdc();
  96.         else    
  97.             return m_hdcPrint;
  98.     }
  99.  
  100.     virtual BOOL IsDeviceDC();
  101. #ifdef XP_WIN32
  102.     BOOL IsPrintingBackground() {return m_printBk;}
  103. #endif
  104.     virtual HDC GetAttribDC();
  105.     virtual void ReleaseContextDC(HDC pDC);
  106.  
  107.  
  108. //    Post Initialization
  109. public:
  110.     virtual void Initialize(BOOL bOwnDC, RECT *pRect = NULL, BOOL bInitialPalette = TRUE, BOOL bNewMemDC = TRUE);
  111. private:
  112.     //    Margins
  113.     int32 m_lLeftMargin;
  114.     int32 m_lTopMargin;
  115.     int32 m_lRightMargin;
  116.     int32 m_lBottomMargin;
  117.  
  118.     //    True page dimensions
  119.     int32 m_lPageHeight;
  120.     int32 m_lPageWidth;
  121.  
  122.     // Document dimensions
  123.     int32 m_lDocWidth;
  124.     int32 m_lDocHeight;
  125.     
  126.     //    Color contingencies
  127.     BOOL m_bBlackText;    //    All text as black?
  128.     BOOL m_bBlackLines;    //    All line drawing as black?
  129.  
  130.     //    Drawing contingencies
  131.     BOOL m_bSolidLines;    //    All lines are solid?
  132.     BOOL m_bBackground;    //    Should we draw the backgrounds?
  133.     BOOL m_bBitmaps;    //    Should we print bitmaps?
  134.     BOOL m_bReverseOrder;   //  Print in reverse order?
  135.  
  136.     //    Headers/footers
  137.     BOOL m_bNumber;    //    Number the pages?
  138.     BOOL m_bTitle;    //    Give each page the appropriate title?
  139.  
  140.     CPrinterDrawable *m_pDrawable; // Drawable that represents the printer
  141.     
  142. //    Print status dialog, also the parent of any dialogs we present!
  143. private:
  144.     CPrintStatusDialog *m_pStatusDialog;
  145.  
  146. //    the real meat of the print process
  147. public:
  148. #ifdef XP_WIN32
  149.     HDC GetOffscreenDC() {return m_hOffscrnDC;}
  150.     virtual int GetLeftMargin() 
  151.     {    if (m_printBk && m_hdcPrint == m_hOffscrnDC) 
  152.                 return 0;
  153.         else return m_lLeftMargin;
  154.     }
  155.     virtual int GetTopMargin() 
  156.     {    if (m_printBk && m_hdcPrint == m_hOffscrnDC) 
  157.                 return 0;
  158.         else return m_lTopMargin;
  159.     }
  160.     int32  GetXConvertUnit() 
  161.     { 
  162.         if (m_printBk && (m_hdcPrint == m_hOffscrnDC)) return 1;
  163.         else return m_lConvertX;
  164.     }
  165.     int32  GetYConvertUnit()
  166.     { 
  167.         if (m_printBk && (m_hdcPrint == m_hOffscrnDC)) return 1;
  168.         else return m_lConvertY;
  169.     }
  170. #endif
  171.     void PrintPage(int iPage, HDC pNewDC = NULL, CPrintInfo *pNewInfo = NULL);
  172. private:
  173.     void CommencePrinting(URL_Struct *pUrl);
  174.     void FormatPages();
  175.     void CapturePositions();
  176.     void Capture(int32 lOrgX, int32 lOrgY, int32 lWidth, int32 lHeight);
  177.     CPtrList m_cplCaptured;
  178.     CPtrList m_cplPages;
  179.     int32 m_lCaptureScrollOffset;
  180.  
  181.     void CreateHeaderFooterFont();
  182.  
  183. //  Useful information.
  184. private:
  185.     int m_iLastPagePrinted;
  186. public:
  187.     int PageCount();
  188.     int LastPagePrinted();
  189.  
  190. private:
  191.     PrinterDisplayMode m_iDisplayMode;
  192. public:
  193.     static BOOL m_bGlobalBlockDisplay;
  194.     PrinterDisplayMode GetDisplayMode();
  195.  
  196. //    Output overrides.
  197. public:
  198.     virtual void DisplayIcon(int32 x, int32 y, int icon_number);
  199.     BOOL    AdjustRect(LTRB& Rect);    
  200.     virtual BOOL ResolveElement(LTRB& Rect, int32 x, int32 y, int32 x_offset, int32 y_offset,
  201.                                 int32 width, int32 height);
  202.     virtual BOOL ResolveElement(LTRB& Rect, NI_Pixmap *pImage, int32 lX, int32 lY, 
  203.                                 int32 orgx, int32 orgy, 
  204.                                 uint32 ulWidth, uint32 ulHeight);
  205.     virtual BOOL ResolveElement(LTRB& Rect, LO_EmbedStruct *pEmbed, int iLocation, Bool bWindowed);
  206.     virtual BOOL ResolveElement(LTRB& Rect, LO_FormElementStruct *pFormElement);
  207.     virtual COLORREF ResolveTextColor(LO_TextAttr *pAttr);
  208.     virtual COLORREF ResolveBGColor(unsigned uRed, unsigned uGreen, unsigned uBlue);
  209.     virtual BOOL ResolveHRSolid(LO_HorizRuleStruct *pHorizRule);
  210.     virtual BOOL ResolveLineSolid();
  211.     virtual void ResolveTransparentColor(unsigned uRed, unsigned uGreen, unsigned uBlue);
  212.     virtual COLORREF ResolveDarkLineColor();
  213.     virtual COLORREF ResolveLightLineColor();
  214.     virtual COLORREF ResolveBorderColor(LO_TextAttr *pAttr);
  215.     virtual PRBool ResolveIncrementalImages();
  216.  
  217.     virtual void SetDocDimension(MWContext *pContext, int iLocation, int32 lWidth, int32 lHeight);
  218.     virtual void GetDrawingOrigin(int32 *plOrgX, int32 *plOrgY);
  219.     virtual FE_Region GetDrawingClip();
  220.     virtual void EraseBackground(MWContext *pContext, int iLocation, 
  221.                                      int32 x, int32 y, uint32 width, uint32 height,
  222.                                      LO_Color *pColor);
  223.  
  224. //    Members needed to properly implement printing.
  225. protected:
  226.     CPrintInfo *m_pcpiPrintJob;
  227.     DOCINFO m_docInfo;
  228. //  document charset id
  229. public:
  230.     int  m_iCSID;
  231.     void* p_TimeOut;
  232.  
  233. //    Members need to properly implement print preview.
  234. protected:
  235.     CView *m_pPreviewView;
  236.     BOOL m_bPreview;
  237. public:
  238.     BOOL IsPrintPreview() const    {
  239.         return(m_bPreview);
  240.     }
  241.  
  242. //    Overrides
  243. public:
  244.     //    Dialog owner
  245.     virtual CWnd *GetDialogOwner() const;
  246.     //    Progress messages.
  247.     virtual void Progress(MWContext *pContext, const char *pMessage);
  248.     //    All connections complete.
  249.     virtual void AllConnectionsComplete(MWContext *pContext);
  250.     virtual void FinishedLayout(MWContext *pContext);
  251.     //    Display routines
  252.     virtual void DisplayBullet(MWContext *pContext, int iLocation, LO_BullettStruct *pBullet);
  253.     virtual void DisplayEmbed(MWContext *pContext, int iLocation, LO_EmbedStruct *pEmbed);
  254.     virtual void DisplayFormElement(MWContext *pContext, int iLocation, LO_FormElementStruct *pFormElement);
  255.     virtual void DisplayHR(MWContext *pContext, int iLocation, LO_HorizRuleStruct *pHorizRule);
  256.     virtual int     DisplayPixmap(NI_Pixmap* image, NI_Pixmap* mask, int32 x, int32 y, int32 x_offset, int32 y_offset, int32 width, int32 height, LTRB& Rect);
  257.     virtual void DisplayLineFeed(MWContext *pContext, int iLocation, LO_LinefeedStruct *pLineFeed, XP_Bool clear);
  258.     virtual void DisplaySubDoc(MWContext *pContext, int iLocation, LO_SubDocStruct *pSubDoc);
  259.     virtual void DisplayCell(MWContext *pContext, int iLocation, LO_CellStruct *pCell);
  260.     virtual void DisplaySubtext(MWContext *pContext, int iLocation, LO_TextStruct *pText, int32 lStartPos, int32 lEndPos, XP_Bool clear);
  261.     virtual void DisplayTable(MWContext *pContext, int iLocation, LO_TableStruct *pTable);
  262.     virtual void DisplayText(MWContext *pContext, int iLocation, LO_TextStruct *pText, XP_Bool clear);
  263.     virtual void DisplayPlugin(MWContext *pContext, LO_EmbedStruct *pEmbed, NPEmbeddedApp* pEmbeddedApp, int iLocation);
  264.     virtual void DisplayWindowlessPlugin(MWContext *pContext, LO_EmbedStruct *pEmbed, NPEmbeddedApp *pEmbeddedApp, int iLocation);
  265. #ifdef XP_WIN32
  266.     void CopyOffscreenBitmap(NI_Pixmap* image, int32 x, int32 y, int32 x_offset, int32 y_offset, int32 width, int32 height, LTRB& Rect);
  267. #endif
  268.     //    Layout initialization respecting page size.
  269.     virtual void LayoutNewDocument(MWContext *pContext, URL_Struct *pURL, int32 *pWidth, int32 *pHeight, int32 *pmWidth, int32 *pmHeight);
  270.  
  271.     virtual void GetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext);
  272.  
  273. //    Call this to cancel the print job.
  274. public:
  275.     void CancelPrintJob();
  276. private:
  277.     BOOL m_bCancel;
  278.     // this is to prevent the destroycontext get call twice.
  279.  
  280.     BOOL m_bHandleCancel;    
  281.  
  282. //    These determine wether or not we need to continue to attempt to start the
  283. //        document, and how we end the printing of the document.
  284. //    Doesn't apply to preview.
  285. private:
  286.     BOOL m_bAbort;
  287.     BOOL m_bNeedStartDoc;
  288.     BOOL m_bAllConnectionCompleteCalled;
  289.         BOOL m_bFormatStarted;
  290.     BOOL m_bFinishedLayoutCalled;
  291.     SIZE screenRes;
  292.     SIZE printRes;
  293.     int StartDoc();
  294.     void PrintTextAllign ( HDC pDC, char * szBuffer, int position, int hpos );
  295.     void ScreenToPrint(POINT* point, int num = 1);
  296.     void FormatAndPrintPages(MWContext *context);
  297. };
  298.  
  299. #endif // __PrintContext_H
  300.