home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cxdc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  25.5 KB  |  788 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 __Context_Device_Context_H
  20. //    Avoid include redundancy
  21. //
  22. #define __Context_Device_Context_H
  23.  
  24. //    Purpose:    Implement a Context which holds the common code for
  25. //                    contexts which draw information.
  26. //    Comments:    Use for those contexts with actual windows to display,
  27. //                    or for printing.  Basically those with a CDC on
  28. //                    which to display and which handle output formats
  29. //                    that go through layout or other engines.
  30. //    Revision History:
  31. //        05-26-95    created GAB
  32. //
  33.  
  34. //    Required Includes
  35. //
  36. #include "cxstubs.h"
  37. #include "ni_pixmp.h"
  38. #include "prtypes.h"
  39. #include "il_types.h"
  40. #include "il_util.h"
  41. #include "libimg.h"
  42. #ifdef XP_WIN32
  43. //#define DDRAW
  44. #endif
  45. #ifdef DDRAW
  46. #include "ddraw.h"
  47. #endif
  48.  
  49. //    Constants
  50. //
  51. #define HIMETRIC_INCH 2540    // HIMETRIC units per inch
  52. #define TWIPS_INCH 1440
  53. #define MAX_IMAGE_PALETTE_ENTRIES 216
  54. // DIBSECTIONS are pretty slow on most platforms except NT3.51
  55. // We can use them if they're sped up in a later version of Windows
  56. #define USE_DIB_SECTIONS 0
  57.  
  58. // Use for selection highlighting of objects in Editor
  59. #define ED_SELECTION_BORDER 3
  60.  
  61. //#ifndef NO_TAB_NAVIGATION 
  62. typedef enum {
  63.     FE_DRAW_NORMAL        = 0x00000000,
  64.     FE_DRAW_TAB_FOCUS    = 0x00000001,
  65. } feDrawFlag_t ;
  66. //#endif /* NO_TAB_NAVIGATION */
  67.  
  68.  
  69. void WFE_StretchDIBitsWithMask(HDC hTargetDC,
  70.                             BOOL isDeviceDC,
  71.                             HDC hOffscreenDC,
  72.                             int dx,
  73.                             int dy,
  74.                             int dw,
  75.                             int dh,
  76.                             int sx,
  77.                             int sy,
  78.                             int sw,
  79.                             int sh,
  80.                             void XP_HUGE *imageBit,
  81.                             BITMAPINFO* lpImageInfo,
  82.                             void XP_HUGE *maskBit,
  83.                             BOOL bUseDibPalColors = FALSE,
  84.                             COLORREF fillWithBackground = NULL
  85.                             );
  86.  
  87.  
  88. //    Structures
  89. //
  90. class LTRB    {
  91. public:
  92.     union    {
  93.         int32 m_lLeft;
  94.         int32 left;
  95.     };
  96.     union    {
  97.         int32 m_lTop;
  98.         int32 top;
  99.     };
  100.     union    {
  101.         int32 m_lRight;
  102.         int32 right;
  103.     };
  104.     union    {
  105.         int32 m_lBottom;
  106.         int32 bottom;
  107.     };
  108.  
  109.     LTRB( LTRB& theRect)    {
  110.         m_lLeft = theRect.m_lLeft;
  111.         m_lTop = theRect.m_lTop;
  112.         m_lRight = theRect.m_lRight;
  113.         m_lBottom = theRect.m_lBottom;
  114.     }
  115.  
  116.     LTRB& operator = (LTRB& theRect) {
  117.         m_lLeft = theRect.m_lLeft;
  118.         m_lTop = theRect.m_lTop;
  119.         m_lRight = theRect.m_lRight;
  120.         m_lBottom = theRect.m_lBottom;
  121.         return *this;
  122.     }
  123.  
  124.     void MergeRect(LTRB& theRect) {
  125.         if ( m_lLeft >theRect.m_lLeft) 
  126.             m_lLeft = theRect.m_lLeft;
  127.         if (m_lTop > theRect.m_lTop)
  128.             m_lTop = theRect.m_lTop;
  129.         if (m_lRight < theRect.m_lRight)
  130.             m_lRight = theRect.m_lRight;
  131.         if (m_lBottom < theRect.m_lBottom)
  132.             m_lBottom = theRect.m_lBottom;
  133.     }
  134.  
  135.     void Empty() {
  136.         m_lLeft = 0;
  137.         m_lTop = 0;
  138.         m_lRight = 0;
  139.         m_lBottom = 0;
  140.     }
  141.  
  142.     BOOL IsEmpty() {
  143.         return(    m_lLeft == 0 &&
  144.                 m_lTop == 0 &&
  145.                 m_lRight == 0 &&
  146.                 m_lBottom == 0);
  147.     }
  148.     LTRB(int32 lLeft, int32 lTop, int32 lRight, int32 lBottom)    {
  149.         m_lLeft = lLeft;
  150.         m_lTop = lTop;
  151.         m_lRight = lRight;
  152.         m_lBottom = lBottom;
  153.     }
  154.  
  155.     LTRB()    {
  156.         m_lLeft = m_lTop = m_lRight = m_lBottom = 0L;
  157.     }
  158.  
  159.     int32 Width()    {
  160.         return(m_lRight - m_lLeft);
  161.     }
  162.  
  163.     int32 Height()    {
  164.         return(m_lBottom - m_lTop);
  165.     }
  166.  
  167.     
  168.     void Inflate(int32 lDelta)  {
  169.         m_lLeft -= lDelta;
  170.         m_lTop -= lDelta;
  171.         m_lRight += lDelta;
  172.         m_lBottom += lDelta;
  173.     }
  174.     void Inflate(int32 lDeltaX, int32 lDeltaY)  {
  175.         m_lLeft -= lDeltaX;
  176.         m_lTop -= lDeltaY;
  177.         m_lRight += lDeltaX;
  178.         m_lBottom += lDeltaY;
  179.     }
  180. };
  181.  
  182. class XY    {
  183. public:
  184.     union    {
  185.         int32 m_lX;
  186.         int32 x;
  187.     };
  188.     union    {
  189.         int32 m_lY;
  190.         int32 y;
  191.     };
  192.  
  193.     XY(int32 lX, int32 lY)    {
  194.         m_lX = lX;
  195.         m_lY = lY;
  196.     }
  197.  
  198.     XY()    {
  199.         m_lX = m_lY = 0L;
  200.     }
  201. };
  202.  
  203. class CDCCX : public CStubsCX    {
  204. //    Construction/Destruction
  205. public:
  206.     CDCCX();
  207.     ~CDCCX();
  208.     virtual void DestroyContext();
  209.  
  210. //    CDC Access
  211. private:
  212.     BOOL m_bOwnDC;
  213.     BOOL m_bClassDC;
  214. protected:
  215.     void SetOwnDC(BOOL bSet) { m_bOwnDC = bSet; }
  216.     void SetClassDC(BOOL bSet) { m_bClassDC = bSet; }
  217. protected:
  218.     HDC m_pImageDC;
  219.     IL_IRGB rgbTransparentColor;
  220.     IL_ColorSpace* curColorSpace;
  221.     IL_ColorMap *curColorMap;
  222.  
  223. public:
  224.     virtual HDC GetContextDC() = 0;
  225.     virtual void ReleaseContextDC(HDC hDC) = 0;
  226.     virtual HDC GetAttribDC() { return GetContextDC(); }
  227.     virtual void ReleaseAttribDC(HDC hDC) { ReleaseContextDC(hDC); }
  228.     virtual HDC GetDispDC() { return GetContextDC(); }
  229.     virtual void ReleaseDispDC(HDC hDC) { ReleaseContextDC(hDC); }
  230.     
  231.     virtual BOOL IsDeviceDC() { return TRUE; }
  232.     virtual int32  GetXConvertUnit() { return m_lConvertX;}
  233.     virtual int32  GetYConvertUnit() { return m_lConvertY;}
  234.     IL_ColorSpace* GetCurrentColorSpace() { return curColorSpace;}
  235.     virtual BOOL IsOwnDC() const    {
  236.         return(m_bOwnDC);
  237.     }
  238.     virtual BOOL IsClassDC() const  {
  239.         return(m_bClassDC);
  240.     }
  241.     HDC GetImageDC()    {
  242.         //    Use this, a compatible DC, to size things to the display or for bitmaps
  243.         //        to blt on the screen.
  244.         //    Don't use to actually attempt display of anything.
  245.         return(m_pImageDC);
  246.     }
  247.  
  248. //    Post construction initialization.
  249. //    Variables should be set by those deriving from this class at
  250. //        the appropriate times.
  251. public:
  252.     // MWH - The usage for  bInitialPalette and     bNewMemDC flags -
  253.     // if  bInitialPalette is set to FALSE, we will use the default palette that is created when the App started.
  254.     // otherwise a palette will be created.
  255.     // if bNewMemDC = TRUE, the the cache memory DC(m_pImageDC) will be created.  Otherwise, it will be 
  256.     // NULL.  If you set bNewMemDC = FALSE, you should call PrepareDraw() before any drawing happen, and
  257.     // call    EndDraw() when you are done with this CDCCX.  When I'm working on Aurora, I find out that
  258.     // I need this flag.   In Aurora, every button has an associate view, it gets created when the button
  259.     // is created.  If the view has HTML pane, it will create a CDCCX.  I need to control when to cache
  260.     // memory DC and when to destroy memory DC in order to use GDI resource efficiently under WIN16.
  261.     virtual void Initialize(BOOL bOwnDC, RECT *pRect = NULL, BOOL bInitialPalette = TRUE, BOOL bNewMemDC = TRUE);
  262.     virtual void PrepareDraw();
  263.     virtual void EndDraw();
  264.     int32 m_lOrgX;
  265.     int32 m_lOrgY;
  266.     int32 m_lWidth;
  267.     int32 m_lHeight;
  268.     int32 m_lDocHeight;
  269.     int32 m_lDocWidth;
  270. #ifdef DDRAW
  271.     virtual LPDDSURFACEDESC    GetSurfDesc() {return 0;}
  272.     virtual LPDIRECTDRAWSURFACE GetPrimarySurface() {return 0;}
  273.     virtual LPDIRECTDRAW GetDrawObj() {return 0;}
  274.     virtual LPDIRECTDRAWSURFACE GetBackSurface(){return 0;}
  275.     virtual void ReleaseSurfDC(LPDIRECTDRAWSURFACE surf, HDC hdc){;}
  276.     virtual void RestoreAllDrawSurface() {;}
  277.     virtual void SetClipOnDrawSurface(LPDIRECTDRAWSURFACE surface, HRGN hClipRgn) {;}
  278.     virtual LPDIRECTDRAWSURFACE CreateOffscreenSurface(RECT& rect) {return NULL;}
  279.     virtual void BltToScreen(LTRB& rect) {;}
  280.     virtual void LockOffscreenSurfDC(){;}
  281.     virtual void ReleaseOffscreenSurfDC() {;}
  282. #endif
  283. //    Drawing conversions, informational.
  284. protected:
  285.     //    Hacks for speedup.
  286.     int32 m_lConvertX;
  287.     int32 m_lConvertY;
  288.     //    What mapping mode we're in.
  289.     int m_MM;
  290.     HRGN curClipRgn;
  291. public:
  292.     virtual int GetLeftMargin() {return 0;}
  293.     virtual int GetTopMargin() {return 0;}
  294.     //    How to set the mapping mode.
  295.     void SetMappingMode(HDC hdc)    {
  296.         if(MMIsText() == TRUE)    {
  297.             ::SetMapMode(hdc, MM_TEXT);
  298.         }
  299.         else    {
  300.             ::SetMapMode(hdc, MM_ANISOTROPIC);
  301.             ::SetWindowExtEx(hdc, 1440,1440, NULL);
  302.             ::SetViewportExtEx(hdc, ::GetDeviceCaps(hdc, LOGPIXELSX), ::GetDeviceCaps(hdc, LOGPIXELSY), NULL);
  303.         }
  304.     }
  305.     //    Can opt for 1 to 1 conversions.
  306.     BOOL MMIsText() const    {
  307.         return(m_MM == MM_TEXT);
  308.     }
  309.     int32 Pix2TwipsX(int32 lPixX)    {
  310.         return(GetXConvertUnit() * lPixX);
  311.     }
  312.     int32 Twips2PixX(int32 lTwipsX)    {
  313.         return(lTwipsX / m_lConvertX);
  314.     }
  315.     int32 Pix2TwipsY(int32 lPixY)    {
  316.         return(GetYConvertUnit() * lPixY);
  317.     }
  318.     int32 Twips2PixY(int32 lTwipsY)    {
  319.         return(lTwipsY / m_lConvertY);
  320.     }
  321.     int32 Metric2TwipsX(int32 lMetricX)    {
  322.         //    We use a screen DC to get WYSIWYG
  323.         CDC *pTempDC = theApp.m_pMainWnd->GetDC();
  324.         float convertPixX = ((float)HIMETRIC_INCH / (float)pTempDC->GetDeviceCaps(LOGPIXELSX));
  325.         theApp.m_pMainWnd->ReleaseDC(pTempDC);
  326.  
  327.         //    Convert the Metrics to pixels first.
  328.         lMetricX = (int32)((float)lMetricX / convertPixX);
  329.  
  330.         //    Complete the conversion to twips.
  331.         return(Pix2TwipsX(lMetricX));
  332.     }
  333.     int32 Metric2TwipsY(int32 lMetricY)    {
  334.         //    We use a screen DC to get WYSIWYG
  335.         CDC *pTempDC = theApp.m_pMainWnd->GetDC();
  336.         float convertPixY = ((float)HIMETRIC_INCH / (float)pTempDC->GetDeviceCaps(LOGPIXELSY));
  337.         theApp.m_pMainWnd->ReleaseDC(pTempDC);
  338.  
  339.         //    Convert the Metrics to pixels first.
  340.         lMetricY = (int32)((float)lMetricY / convertPixY);
  341.  
  342.         //    Complete the conversion to twips.
  343.         return(Pix2TwipsY(lMetricY));
  344.     }
  345.     int32 Twips2MetricX(int32 lTwipsX)    {
  346.         //    Convert the twips to pixels first.
  347.         lTwipsX = Twips2PixX(lTwipsX);
  348.  
  349.         //    We use a screen DC to get WYSIWYG
  350.         CDC *pTempDC = theApp.m_pMainWnd->GetDC();
  351.         float convertPixX = ((float)HIMETRIC_INCH / (float)pTempDC->GetDeviceCaps(LOGPIXELSX));
  352.         theApp.m_pMainWnd->ReleaseDC(pTempDC);
  353.  
  354.         //    Go metric.
  355.         lTwipsX = (int32)((float)lTwipsX * convertPixX);
  356.         return(lTwipsX);
  357.     }
  358.     int32 Twips2MetricY(int32 lTwipsY)    {
  359.         //    Convert the twips to pixels first.
  360.         lTwipsY = Twips2PixY(lTwipsY);
  361.  
  362.         //    We use a screen DC to get WYSIWYG
  363.         CDC *pTempDC = theApp.m_pMainWnd->GetDC();
  364.         float convertPixY = ((float)HIMETRIC_INCH / (float)pTempDC->GetDeviceCaps(LOGPIXELSY));
  365.         theApp.m_pMainWnd->ReleaseDC(pTempDC);
  366.  
  367.         //    Go metric.
  368.         lTwipsY = (int32)((float)lTwipsY * convertPixY);
  369.         return(lTwipsY);
  370.     }
  371.     int32 GetOriginX()    {
  372.         return(m_lOrgX);
  373.     }
  374.     int32 GetOriginY()    {
  375.         return(m_lOrgY);
  376.     }
  377.     int32 GetWidth()    {
  378.         return(m_lWidth);
  379.     }
  380.     int32 GetHeight()    {
  381.         return(m_lHeight);
  382.     }
  383.     int32 GetDocumentWidth()    {
  384.         return(m_lDocWidth);
  385.     }
  386.     int32 GetDocumentHeight()    {
  387.         return(m_lDocHeight);
  388.     }
  389.  
  390.     void SetTransparentColor(BYTE red, BYTE green, BYTE blue);
  391.     IL_IRGB &GetTransparentColor() {return rgbTransparentColor;}
  392.  
  393. //    Turning on or off display blocking.
  394. private:
  395.     BOOL m_bResolveElements;
  396. protected:
  397.     BOOL CanBlockDisplay() const    {
  398.         return(m_bResolveElements);
  399.     }
  400. public:
  401.     void DisableDisplayBlocking()    {
  402.         m_bResolveElements = FALSE;
  403.     }
  404.     void EnableDisplayBlocking()    {
  405.         m_bResolveElements = TRUE;
  406.     }
  407.  
  408. //    Coordinate resolution and display blocking.
  409. public:
  410.     virtual BOOL ResolveElement(LTRB& Rect, NI_Pixmap *pImage, int32 lX, int32 lY, 
  411.                            int32 orgx, int32 orgy,
  412.                            uint32 ulWidth, uint32 ulHeight);
  413.     virtual BOOL ResolveElement(LTRB& Rect, int32 x, int32 y, int32 x_offset, int32 y_offset,
  414.                                 int32 width, int32 height);
  415.     virtual BOOL ResolveElement(LTRB& Rect, LO_SubDocStruct *pSubDoc, int iLocation);
  416.     virtual BOOL ResolveElement(LTRB& Rect, LO_LinefeedStruct *pLineFeed, int iLocation);
  417.     virtual BOOL ResolveElement(LTRB& Rect, LO_CellStruct *pCell, int iLocation);
  418.     virtual BOOL ResolveElement(LTRB& Rect, LO_TableStruct *pTable, int iLocation);
  419.     virtual BOOL ResolveElement(LTRB& Rect, LO_EmbedStruct *pEmbed, int iLocation, Bool bWindowed);
  420.         virtual BOOL ResolveElement(LTRB& Rect, LO_FormElementStruct *pFormElement);
  421.     virtual BOOL ResolveElement(LTRB& Rect, LO_TextStruct *pText, int iLocation, int32 lStartPos, int32 lEndPos, int iClear);
  422.  
  423. //    How to make sure above functions work on windows 16.
  424. public:
  425.     void SafeSixteen(LTRB& Rect)    {
  426.         //    This routine is called to make sure that drawing coords don't wrap
  427.         //        with GDI functions which take short ints.
  428.         //    Use some hard coded values to end this pain quickly.
  429.         //    Leave some marginal values to allow for additional leeway of
  430.         //        the result (2767 twips).
  431.         //    Maximum display height known is 1200 pixels, which is about 24000
  432.         //        twips, which is kinda close for the future of this product.
  433.         //        This doesn't count those users which somehow get their app much
  434.         //        larger than the screen size by using other means, and they
  435.         //        are dead.
  436.         const int iMax = 30000;
  437.         const int iMin = -30000;
  438.  
  439.         if(Rect.left > iMax)    {
  440.             Rect.left = iMax;
  441.         }
  442.         else if(Rect.left < iMin)    {
  443.             Rect.left = iMin;
  444.         }
  445.         if(Rect.top > iMax)    {
  446.             Rect.top = iMax;
  447.         }
  448.         else if(Rect.top < iMin)    {
  449.             Rect.top = iMin;
  450.         }
  451.         if(Rect.right > iMax)    {
  452.             Rect.right = iMax;
  453.         }
  454.         else if(Rect.right < iMin)    {
  455.             Rect.right = iMin;
  456.         }
  457.         if(Rect.bottom > iMax)    {
  458.             Rect.bottom = iMax;
  459.         }
  460.         else if(Rect.bottom < iMin)    {
  461.             Rect.bottom = iMin;
  462.         }
  463.     }
  464.  
  465. //    Font selection, deselection, caching
  466. private:
  467.     enum    {
  468.         m_MaxFontSizes = 9,
  469.         m_MaxUnderline = 2,
  470.         m_MaxItalic = 2,
  471.         m_MaxBold = 2,
  472.         m_MaxFixed = 2
  473.     };
  474. private :
  475.     CPtrList m_cplCachedFontList;
  476.  
  477. protected:
  478.     HDC                m_lastDCWithCachedFont;
  479.     CyaFont            *m_pSelectedCachedFont;
  480.     int                m_iOffset;
  481. public:
  482.     static void ClearAllFontCaches();
  483.     void ClearFontCache();
  484.     virtual int SelectNetscapeFont( HDC hdc, LO_TextAttr *pAttr, CyaFont *& pMyFont);
  485.     virtual int SelectNetscapeFontWithCache( HDC hdc, LO_TextAttr *pAttr, CyaFont *& pMyFont );
  486.     virtual void ReleaseNetscapeFont(HDC hdc, CyaFont * pNetscapeFont);
  487.     virtual void ReleaseNetscapeFontWithCache(HDC hdc, CyaFont * pNetscapeFont);
  488.     virtual void ChangeFontOffset(int iIncrementor);
  489. //    Context sensitive attribute mapping.
  490. public:
  491.     virtual COLORREF ResolveTextColor(LO_TextAttr *pAttr);
  492.     virtual COLORREF ResolveBGColor(unsigned uRed, unsigned uGreen, unsigned uBlue);
  493.     virtual BOOL ResolveHRSolid(LO_HorizRuleStruct *pHorizRule);
  494.     virtual BOOL ResolveLineSolid();
  495.     virtual void ResolveTransparentColor(unsigned uRed, unsigned uGreen, unsigned uBlue);
  496.     virtual COLORREF ResolveDarkLineColor();
  497.     virtual COLORREF ResolveLightLineColor();
  498.     virtual COLORREF ResolveBorderColor(LO_TextAttr *pAttr);
  499.     COLORREF ResolveLOColor(LO_Color *color);
  500.     virtual PRBool ResolveIncrementalImages();
  501.  
  502. #ifdef XP_WIN16
  503.     static void HugeFree(void XP_HUGE *pFreeMe)    {
  504. #ifdef __WATCOMC__
  505.         hfree(pFreeMe);
  506. #else
  507.         _hfree(pFreeMe);
  508. #endif
  509.     }
  510.     void XP_HUGE *HugeAlloc(int32 iSize, int32 iNum)    {
  511. #ifdef __WATCOMC__
  512.         return(halloc( (long) iSize, (size_t) iNum));
  513. #else
  514.         return(_halloc( (long) iSize, (size_t) iNum));
  515. #endif
  516.     }
  517. #else
  518.     static void HugeFree(void XP_HUGE *pFreeMe)    {
  519.         free(pFreeMe);
  520.     }
  521.     void XP_HUGE *HugeAlloc(int32 iSize, int32 iNum)    {
  522.         return(calloc(iNum, iSize));
  523.     }
  524. #endif
  525.  
  526.     BOOL ResolveTextExtent(int16 wincsid, HDC pDC, LPCTSTR pString, int iLength, LPSIZE pSize, CyaFont *pMyFont);
  527.     BOOL ResolveTextExtent(HDC pDC, LPCTSTR pString, int iLength, LPSIZE pSize, CyaFont *pMyFont );
  528.     BOOL ResolveTextExtent(HDC pDC, LPCTSTR pString, int iLength, LPSIZE pSize)
  529.     {
  530.         BOOL bRetval;
  531.         bRetval = CIntlWin::GetTextExtentPoint(0, pDC, pString, iLength, pSize);
  532.         return(bRetval);
  533.     }
  534.  
  535. //    Color and palette.
  536. protected:
  537.     COLORREF m_rgbLightColor;
  538.     COLORREF m_rgbDarkColor;
  539.     HPALETTE m_pPal;
  540.     BOOL      m_bRGB565;  // driver supports 565 mode for DIBs
  541. public:
  542.     virtual HPALETTE  GetPalette() const;
  543.     COLORREF m_rgbBackgroundColor;  // let our view access this
  544.  
  545. //    Misc draw helpers
  546. public:
  547.     virtual double CalcFontPointSize(int size, int iBaseSize, int iOffset = 0);
  548.     void Display3DBox(LTRB& Rect, COLORREF rgbLight, COLORREF rgbDark, int32 lWidth, BOOL bAdjust = FALSE);
  549.     void EditorDisplayZeroWidthBorder(LTRB& Rect, BOOL bSelected);
  550.     void Compute3DColors(COLORREF rgbColor, COLORREF &rgbLight, COLORREF &rgbDark);
  551.     // Returns width of selection border (if any) - used only by Composer
  552.     int32 DisplayTableBorder(LTRB& Rect, LO_TableStruct *pTable);
  553.     void Display3DBorder(LTRB& Rect, COLORREF rgbLight, COLORREF rgbDark, LTRB &);
  554.     BOOL cxLoadBitmap(LPCSTR pszBmName, char** bits,  BITMAPINFOHEADER** myBitmapInfo); 
  555.     virtual void DisplayIcon(int32 x, int32 y, int icon_number);
  556.     virtual void GetIconDimensions(int32* width, int32* height, int iconNumber);
  557.     void FloodRect(LTRB& Rect, HBRUSH hColor);
  558.     BOOL WriteBitmapFile(LPCSTR lpszFileName, LO_ImageStruct*);
  559.     HANDLE WriteBitmapToMemory(    IL_ImageReq *image_req, LO_Color* bgColor);
  560.     BOOL CanWriteBitmapFile(LO_ImageStruct*);
  561.  
  562.     // Uses the document color/backdrop by default, but you can specify a color or backdrop image to be used instead
  563.     virtual BOOL _EraseBkgnd(HDC pDC, RECT&, int32 tileX, int32 tileY, 
  564.                              LO_Color* bg = NULL);
  565.  
  566.     void DisplaySelectionFeedback(uint16 ele_attrmask, const LTRB& rect);
  567.     void EraseToBackground(const LTRB& rect, int32 borderWidth = 0);
  568.  
  569. protected:
  570.     int m_iBitsPerPixel;
  571.     BOOL m_bUseDibPalColors;
  572.  
  573. public:
  574.     BOOL GetUseDibPalColors() {
  575.          return m_bUseDibPalColors;
  576.     }
  577.  
  578.     int GetBitsPerPixel() {
  579.         return m_iBitsPerPixel;
  580.     }
  581.     void SetUseDibPalColors(BOOL flag) {
  582.         m_bUseDibPalColors = flag;
  583.     }
  584.  
  585. //    Preference representations needed per context.
  586. protected:
  587. public:
  588.  
  589. //    OLE Embed implementation.
  590. private:
  591.     BOOL m_bAutoDeleteDocument;
  592. protected:
  593.     CGenericDoc *m_pDocument;
  594. public:
  595.     CGenericDoc *GetDocument() const    {
  596.         return(m_pDocument);
  597.     }
  598.     void ClearDoc()    {
  599.         m_pDocument = NULL;
  600.     }
  601. void GetPluginRect(MWContext *pContext,
  602.                    LO_EmbedStruct *pLayoutData,
  603.                    RECT &rect, int iLocation, 
  604.                    BOOL windowed);
  605. BOOL IsPluginFullPage(LO_EmbedStruct *pLayoutData);
  606. BOOL ContainsFullPagePlugin();
  607.  
  608. //    Document helpers.
  609. public:
  610.     virtual BOOL OnOpenDocumentCX(const char *pPathName);
  611.  
  612. //    URL retrieval
  613. public:
  614.     virtual int GetUrl(URL_Struct *pUrl, FO_Present_Types iFormatOut, BOOL bReallyLoad = TRUE, BOOL bForceNew = FALSE);
  615.  
  616. //    Function for easy creation of a URL from the current history entry.
  617. public:
  618.     virtual URL_Struct *CreateUrlFromHist(BOOL bClearStateData = FALSE, SHIST_SavedData *pSavedData = NULL, BOOL bWysiwyg = FALSE);
  619.  
  620. //    Image conditional loading.
  621. private:
  622.     CString m_csForceLoadImage;
  623.     CString m_csNexttimeForceLoadImage;
  624.     BOOL m_bLoadImagesNow;
  625.     BOOL m_bNexttimeLoadImagesNow;
  626. public:
  627.     void ExplicitlyLoadThisImage(const char *pImageUrl)    {
  628.         m_csNexttimeForceLoadImage = pImageUrl;
  629.         NiceReload();
  630.     }
  631.     void ExplicitlyLoadAllImages()    {
  632.         m_bNexttimeLoadImagesNow = TRUE;
  633.         NiceReload();
  634.     }
  635.  
  636. //    Wether or not we exist in an OLE server....
  637. private:
  638.     BOOL m_bOleServer;
  639. public:
  640.     BOOL IsOleServer() const    {
  641.         return(m_bOleServer);
  642.     }
  643.     void EnableOleServer();
  644.     void DisableOleServer()    {
  645.         m_bOleServer = FALSE;
  646.     }
  647.  
  648. //  Font for Form Text Entry
  649. private:
  650.     friend class CFormElement;
  651.     enum    {
  652.         m_FixedFont,
  653.         m_ProportionalFont
  654.     };
  655.  
  656. #if 0 /* dp */
  657.     int        m_DownloadedFontList;    // for testing
  658. #endif /* 0 */
  659.     HFONT m_pFormFixFont;
  660.     HFONT m_pFormPropFont;
  661.     int   m_iFormFixCSID;    // csid for current form.
  662.     int   m_iFormPropCSID;    // csid for current form.
  663.     void ExtendCoord(LTRB &Rect);
  664.     virtual void GetDrawingOrigin(int32 *plOrgX, int32 *plOrgY)
  665.       { *plOrgX = 0; *plOrgY = 0; }
  666.         virtual FE_Region GetDrawingClip()
  667.           { return NULL; }
  668.         
  669.  
  670. private :
  671.     void CDCCX::DrawTabFocusLine( HDC hdc, BOOL supportPixel, int x, int y, int x2, int y2);
  672.     void CDCCX::DrawTabFocusRect( HDC hdc, BOOL supportPixel, int left, int top, int right, int bottom);
  673.     void CDCCX::DrawRectBorder(LTRB& Rect, COLORREF rgbColor, int32 lWidth);
  674.     void CDCCX::DrawMapAreaBorder( int baseX, int baseY, lo_MapAreaRec * theArea );
  675.  
  676. //    MFC Helpers;  abstraction away
  677. public:
  678.     virtual void ViewImages();
  679.     virtual BOOL CanViewImages();
  680.  
  681. //    Context Overrides
  682.     virtual void DisplayBullet(MWContext *pContext, int iLocation, LO_BullettStruct *pBullet);
  683.     virtual void DisplayEmbed(MWContext *pContext, int iLocation, LO_EmbedStruct *pEmbed);
  684.     virtual void DisplayBorder(MWContext *pContext, int iLocation, int x, int y, int width, int height, int bw, LO_Color *color, LO_LineStyle style);
  685.     virtual void DisplayHR(MWContext *pContext, int iLocation, LO_HorizRuleStruct *pHorizRule);
  686.     virtual BITMAPINFO*     NewPixmap(NI_Pixmap* pImage, BOOL mask = FALSE);
  687.     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);
  688.     virtual void DisplayLineFeed(MWContext *pContext, int iLocation, LO_LinefeedStruct *pLineFeed, XP_Bool clear);
  689.     virtual void DisplaySubDoc(MWContext *pContext, int iLocation, LO_SubDocStruct *pSubDoc);
  690.     virtual void DisplayCell(MWContext *pContext, int iLocation, LO_CellStruct *pCell);
  691.     virtual void DisplaySubtext(MWContext *pContext, int iLocation, LO_TextStruct *pText, int32 lStartPos, int32 lEndPos, XP_Bool clear);
  692.     virtual void DisplayTable(MWContext *pContext, int iLocation, LO_TableStruct *pTable);
  693.  
  694.     // need to keep the old interface  for calling from C
  695.     virtual void DisplayText(MWContext *pContext, int iLocation, LO_TextStruct *pText, XP_Bool clear);
  696.     void CDCCX::DisplayImageFeedback(MWContext *pContext, int iLocation, LO_Element *pElement, lo_MapAreaRec * theArea, uint32 drawFlag );
  697.  
  698.     // /* cannot use default drawFlag = 0, if this function is called from C */
  699.     virtual void DisplayText(MWContext *pContext, int iLocation, LO_TextStruct *pText, XP_Bool clear, uint32 drawFlag );
  700.     // handle strike and under-line, after text is drawn.
  701.     virtual void CDCCX::DrawTextPostDecoration(HDC hdc, LO_TextAttr * attr, LTRB * Rect, COLORREF rgbColor );
  702.  
  703.         virtual void DisplayWindowlessPlugin(MWContext *pContext, LO_EmbedStruct *pEmbed, NPEmbeddedApp *pEmbeddedApp, int iLocation);
  704.     virtual void DisplayPlugin(MWContext *pContext, LO_EmbedStruct *pEmbed, NPEmbeddedApp* pEmbeddedApp, int iLocation);
  705. #ifdef LAYERS
  706.         virtual void EraseBackground(MWContext *pContext, int iLocation, int32 x, int32 y, uint32 width, uint32 height, LO_Color *pColor);
  707. #endif
  708.     virtual void FreeEmbedElement(MWContext *pContext, LO_EmbedStruct *pEmbed);
  709.     virtual void GetEmbedSize(MWContext *pContext, LO_EmbedStruct *pEmbed, NET_ReloadMethod bReload);
  710. #ifdef LAYERS
  711.     virtual void GetTextFrame(MWContext *pContext, LO_TextStruct *pText,
  712.                   int32 start, int32 end, XP_Rect *frame);
  713. #endif
  714.            virtual int GetTextInfo(MWContext *pContext, LO_TextStruct *pText, LO_TextInfo *pTextInfo);
  715.     virtual void ImageComplete(NI_Pixmap* image);
  716.     virtual void LayoutNewDocument(MWContext *pContext, URL_Struct *pURL, int32 *pWidth, int32 *pHeight, int32 *pmWidth, int32 *pmHeight);
  717.     virtual void SetBackgroundColor(MWContext *pContext, uint8 uRed, uint8 uGreen, uint8 uBlue);
  718.     virtual COLORREF GetBackgroundColor() {return m_rgbBackgroundColor;}
  719.     virtual void Set3DColors( COLORREF crBackground );
  720.     static HPALETTE InitPalette(HDC hdc);
  721.     static HPALETTE CreateColorPalette(HDC hdc, IL_IRGB& transparentColor, int bitsPerPixel);
  722.     static void SetColormap(HDC hdc, NI_ColorMap *pMap, IL_IRGB& transparentColor, HPALETTE hPal);
  723.     virtual void SetDocDimension(MWContext *pContext, int iLocation, int32 lWidth, int32 lLength);
  724.     virtual void GetDocPosition(MWContext *pContext, int iLocation, int32 *lX_p, int32 *lY_p);
  725.     virtual void DisplayFormElement(MWContext *pContext, int iLocation, LO_FormElementStruct *pFormElement);
  726.     virtual void FormTextIsSubmit(MWContext *pContext, LO_FormElementStruct *pFormElement);
  727.     virtual void GetFormElementInfo(MWContext *pContext, LO_FormElementStruct *pFormElement);
  728.     virtual void GetFormElementValue(MWContext *pContext, LO_FormElementStruct *pFormElement, XP_Bool bTurnOff);
  729.     virtual void ResetFormElement(MWContext *pContext, LO_FormElementStruct *pFormElement);
  730.     virtual void SetFormElementToggle(MWContext *pContext, LO_FormElementStruct *pFormElement, XP_Bool iState);
  731.  
  732.         virtual void DrawJavaApp(MWContext *pContext, int iLocation, LO_JavaAppStruct *pJava);
  733.  
  734. protected:
  735.     void StretchMaskBlt(HDC hTargetDC, HBITMAP theBitmap, HBITMAP theMask, 
  736.                                 int32 dx, int32 dy, int32 dw, int32 dh,
  737.                                 int32 sx, int32 sy, int32 sw, int32 sh);
  738.     void StretchPixmap(HDC hTargetDC, NI_Pixmap* pImage, 
  739.                                 int32 dx, int32 dy, int32 dw, int32 dh,
  740.                                 int32 sx, int32 sy, int32 sw, int32 sh);
  741.     virtual void _StretchDIBitsWithMask(HDC pDC,
  742.                             int iDestX,
  743.                             int iDestY,
  744.                             int iDestWidth,
  745.                             int iDestHeight,
  746.                             int iSrcX,
  747.                             int iSrcY,
  748.                             int iSrcWidth,
  749.                             int iSrcHeight,
  750.                             NI_Pixmap *image,
  751.                             NI_Pixmap *mask);
  752.  
  753. #ifdef DDRAW
  754.     BOOL TransparentBlt(int iDestX,
  755.                             int iDestY,
  756.                             int iDestWidth,
  757.                             int iDestHeight,
  758.                             int iSrcX,
  759.                             int iSrcY,
  760.                             int iSrcWidth,
  761.                             int iSrcHeight,
  762.                             NI_Pixmap *image,
  763.                             COLORREF transColor,
  764.                             LPDIRECTDRAWSURFACE surf);
  765. #endif
  766.     BITMAPINFO* FillBitmapInfoHeader(NI_Pixmap* pImage);
  767.     HBITMAP CreateBitmap(HDC hTargetDC,  NI_Pixmap *image);
  768.     HBITMAP CreateMask(HDC hTargetDC, NI_Pixmap* mask); 
  769.     void TileImage(HDC hdc, LTRB& Rect, NI_Pixmap* image, NI_Pixmap* mask, int32 x, int32 y);
  770.  
  771. };
  772.  
  773. // Global functions
  774.  
  775. // Calculate a contrastng text and background colors to use for selection
  776. //   given a background color
  777. void wfe_GetSelectionColors( COLORREF rgbBackgroundColor, 
  778.                              COLORREF* pTextColor, COLORREF* pBackColor);
  779.  
  780. //    Global variables
  781. //
  782.  
  783. //    Macros
  784. //
  785.  
  786.  
  787. #endif // __Context_Device_Context_H
  788.