home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / drawable.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.0 KB  |  154 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. //   drawable.h - Classes used for maintaining the notion of 
  20. //                offscreen and onscreen drawables, so that 
  21. //                document contents can be drawn to either
  22. //                location. Currently used for LAYERS.
  23. #include "stdafx.h"
  24. #include "layers.h"
  25. #include "fe_rgn.h"
  26. #include "cl_types.h"
  27.  
  28. #ifndef _DRAWABLE_H_
  29. #define _DRAWABLE_H_
  30.  
  31. #ifdef LAYERS 
  32.  
  33. extern CL_DrawableVTable wfe_drawable_vtable;
  34.  
  35. class CDrawable {
  36.   protected:
  37.     int32 m_lOrgX, m_lOrgY;
  38.     FE_Region m_hClipRgn;
  39.     CAbstractCX*    m_parentContext;
  40.  
  41.   public:
  42.     // Constructor and destructor
  43.     CDrawable();
  44.     CDrawable(    CAbstractCX*    m_parentContext);
  45.     ~CDrawable() {}
  46.  
  47.     // Lock the drawable for use, based on the state passed in.
  48.     // Does nothing in the super class.
  49.     virtual PRBool LockDrawable(CL_Drawable *pCLDrawable, 
  50.                 CL_DrawableState newState) 
  51.       { return PR_TRUE; }
  52.  
  53.     // Calls to indicate a new client or the relinquishing of the drawable
  54.     // by a client.
  55.     virtual void InitDrawable(CL_Drawable *pCLDrawable) {};
  56.     virtual void RelinquishDrawable(CL_Drawable *pCLDrawable) {};
  57.  
  58.     // Get and set the origin of the drawable
  59.     void SetOrigin(int32 lOrgX, int32 lOrgY);
  60.     void GetOrigin(int32 *lOrgX, int32 *lOrgY);
  61.  
  62.     // Set the drawable's clip. A value of NULL indicates that the
  63.     // clip should be restored to its initial value.
  64.     virtual void SetClip(FE_Region hClipRgn);
  65.  
  66.     FE_Region GetClip() { return m_hClipRgn; }
  67.         
  68.     // Call to copy pixels from the given drawable
  69.     void CopyPixels(CDrawable *pSrcDrawable, FE_Region hCopyRgn);
  70.  
  71.     // Call to set the width and height of a drawable;
  72.     virtual void SetDimensions(int32 width, int32 height) {}
  73.     
  74.     // Call to set the palette of drawable
  75.     virtual void SetPalette(HPALETTE hPal) {}
  76.  
  77.     // Return the device context associated with the drawable
  78.     virtual HDC GetDrawableDC() {return NULL;}
  79.     virtual void ReleaseDrawableDC(HDC hdc) {;}
  80. };
  81.  
  82. class COnscreenDrawable : public CDrawable {
  83.   protected:
  84.     HDC m_hDC;
  85.   public:
  86.     COnscreenDrawable(HDC hDC, CAbstractCX* parentContext);
  87.     ~COnscreenDrawable() {}
  88.  
  89.     // Return the device context associated with the drawable
  90.     virtual HDC GetDrawableDC() {return m_hDC;}
  91.     virtual void ReleaseDrawableDC(HDC hdc) {;}
  92. };
  93.  
  94. class CPrinterDrawable : public CDrawable {
  95.   protected:
  96.     HDC m_hDC;
  97.     int32 m_lLeftMargin, m_lRightMargin, m_lTopMargin, m_lBottomMargin;
  98.     
  99.   public:
  100.     CPrinterDrawable(HDC hDC, int32 lLeftMargin, int32 lRightMargin,
  101.                      int32 lTopMargin, int32 lBottomMargin, CAbstractCX* parentContext);
  102.     ~CPrinterDrawable() {}
  103.  
  104.     virtual void SetClip(FE_Region hClipRgn);
  105.  
  106.     // Return the device context associated with the drawable
  107.     virtual HDC GetDrawableDC() {return m_hDC;}
  108.     virtual void ReleaseDrawableDC(HDC hdc) {;}
  109. };
  110.  
  111. class COffscreenDrawable : public CDrawable {
  112.   protected:
  113.     HBITMAP m_hSaveBitmap;
  114.     HPALETTE m_hSavePalette;
  115.     HDC m_hParentDC;
  116.     HPALETTE m_hParentPal;
  117.  
  118.     // In this implementation, we only have a single offscreen drawable
  119.     static COffscreenDrawable *m_pOffscreenDrawable;
  120.     static CL_Drawable *m_pOwner;
  121.     static int32 m_lWidth, m_lHeight;
  122.     static HBITMAP m_hBitmap;
  123.     static HDC m_hDC;
  124.     static UINT m_uRefCnt;
  125.     static HPALETTE m_hSelectedPalette;
  126.  
  127.   public:
  128.     COffscreenDrawable(HDC hParentDC, HPALETTE hPal, CAbstractCX* parentContext);
  129.     ~COffscreenDrawable();
  130.     
  131.     // Factory for creating offscreen drawables
  132.     static COffscreenDrawable *AllocateOffscreen(HDC hParentDC, HPALETTE hPal, CAbstractCX* parentContext);
  133.  
  134.     virtual void InitDrawable(CL_Drawable *pCLDrawable);
  135.     virtual void RelinquishDrawable(CL_Drawable *pCLDrawable);
  136.  
  137.     virtual PRBool LockDrawable(CL_Drawable *pCLDrawable, 
  138.                 CL_DrawableState newState);
  139.     virtual void SetDimensions(int32 width, int32 height);
  140.  
  141.     virtual void SetPalette(HPALETTE hPal);
  142.     virtual void SetClip(FE_Region hClipRgn);
  143.     
  144.     // Return the device context associated with the drawable
  145.     virtual HDC GetDrawableDC();
  146.     virtual void ReleaseDrawableDC(HDC hdc);
  147.  
  148.   private:
  149.     void delete_offscreen();
  150. };
  151.  
  152. #endif // LAYERS 
  153. #endif // _DRAWABLE_H_ 
  154.