Back to index

lightning-sunbird  0.9+nobinonly
nsDrawingSurfaceOS2.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Mozilla OS/2 libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * John Fairhurst, <john_fairhurst@iname.com>.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK *****
00036  * This Original Code has been modified by IBM Corporation.
00037  * Modifications made by IBM described herein are
00038  * Copyright (c) International Business Machines
00039  * Corporation, 2000
00040  *
00041  * Modifications to Mozilla code or documentation
00042  * identified per MPL Section 3.3
00043  *
00044  * Date           Modified by     Description of modification
00045  * 03/28/2000   IBM Corp.        Changes to make os2.h file similar to windows.h file
00046  */
00047 
00048 #ifndef _nsDrawingSurfaceOS2_h
00049 #define _nsDrawingSurfaceOS2_h
00050 
00051 #include "nsIDrawingSurface.h"
00052 
00053 class nsHashtable;
00054 class nsIWidget;
00055 class nsFontOS2;
00056 
00057 // These were called `drawables' in os2fe.
00058 //
00059 // Note that each surface has a ref to the palette of the device context
00060 // from which it was spun off.  This is because drawing surfaces have
00061 // lifetimes which extend further than the rendering context which
00062 // created them.  The creating object must select the palette into the
00063 // surface's presentation space; all the drawing surface does is deselect
00064 // the palette when it's dying.
00065 //
00066 // This is rather unwieldy...
00067 
00068 class nsDrawingSurfaceOS2 : public nsIDrawingSurface
00069 {
00070    nsHashtable   *mHTFonts; // cache of fonthandle to lcid
00071    long           mNextID;  // next lcid to allocate
00072    long           mTopID;   // highest used lcid
00073 
00074 protected:
00075    HPS            mPS;      // presentation space for this surface
00076    PRBool         mOwnPS;   // did we instantiate PS or was it passed in?
00077    PRInt32        mWidth;   // dimensions of drawing surface
00078    PRInt32        mHeight;
00079 
00080 
00081    nsDrawingSurfaceOS2();
00082    virtual ~nsDrawingSurfaceOS2();
00083 
00084    NS_DECL_ISUPPORTS
00085 
00086    void DisposeFonts();     // MUST be called before disposing of PS
00087 
00088 
00089  public:
00090    NS_IMETHOD GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight);
00091 
00092    // os/2 methods
00093    HPS  GetPS() { return mPS; }
00094    void SelectFont(nsFontOS2* aFont);
00095    void FlushFontCache();
00096    virtual PRUint32 GetHeight() { return mHeight; }
00097 
00098    // Convertion between XP and OS/2 coordinate space.
00099    void NS2PM_ININ (const nsRect &in, RECTL &rcl);
00100    void NS2PM_INEX (const nsRect &in, RECTL &rcl);
00101    void PM2NS_ININ (const RECTL &in, nsRect &out);
00102    void NS2PM      (PPOINTL aPointl, ULONG cPointls);
00103 };
00104 
00105 // Offscreen surface. Others depend on this.
00106 class nsOffscreenSurface : public nsDrawingSurfaceOS2
00107 {
00108    HDC     mDC;
00109    HBITMAP mBitmap;
00110 
00111    PBITMAPINFOHEADER2  mInfoHeader;
00112    PRUint8            *mBits;
00113 
00114    PRInt32  mYPels;
00115    PRUint32 mScans;
00116 
00117  public:
00118    nsOffscreenSurface();
00119    virtual ~nsOffscreenSurface();
00120 
00121    // os/2 methods
00122    NS_IMETHOD Init( HPS aCompatiblePS, PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags);
00123    NS_IMETHOD Init(HPS aPS);
00124 
00125    HDC GetDC() { return mDC; }
00126 
00127    // nsIDrawingSurface methods
00128    NS_IMETHOD Lock( PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00129                     void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00130                     PRUint32 aFlags);
00131    NS_IMETHOD Unlock();
00132    NS_IMETHOD IsOffscreen( PRBool *aOffScreen);
00133    NS_IMETHOD IsPixelAddressable( PRBool *aAddressable);
00134    NS_IMETHOD GetPixelFormat( nsPixelFormat *aFormat);
00135 };
00136 
00137 // Onscreen surface - uses an offscreen to implement bitlevel access
00138 class nsOnscreenSurface : public nsDrawingSurfaceOS2
00139 {
00140    nsOffscreenSurface *mProxySurface;
00141    void                EnsureProxy();
00142 
00143  protected:
00144    nsOnscreenSurface();
00145    virtual ~nsOnscreenSurface();
00146 
00147  public:
00148    // nsIDrawingSurface methods
00149    NS_IMETHOD Lock( PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00150                     void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00151                     PRUint32 aFlags);
00152    NS_IMETHOD Unlock();
00153    NS_IMETHOD IsOffscreen( PRBool *aOffScreen);
00154    NS_IMETHOD IsPixelAddressable( PRBool *aAddressable);
00155    NS_IMETHOD GetPixelFormat( nsPixelFormat *aFormat);
00156 };
00157 
00158 // Surface for an onscreen window
00159 class nsWindowSurface : public nsOnscreenSurface
00160 {
00161    nsIWidget *mWidget; // window who owns the surface
00162 
00163  public:
00164    nsWindowSurface();
00165    virtual ~nsWindowSurface();
00166 
00167    NS_IMETHOD Init(HPS aPS, nsIWidget *aWidget);
00168    NS_IMETHOD Init( nsIWidget *aOwner);
00169    NS_IMETHOD GetDimensions( PRUint32 *aWidth, PRUint32 *aHeight);
00170 
00171    virtual PRUint32 GetHeight ();
00172 };
00173 
00174 // Surface for a printer-page
00175 class nsPrintSurface : public nsOnscreenSurface
00176 {
00177  public:
00178    nsPrintSurface();
00179    virtual ~nsPrintSurface();
00180 
00181    NS_IMETHOD Init( HPS aPS, PRInt32 aWidth, PRInt32 aHeight, PRUint32 aFlags);
00182 };
00183 
00184 #endif