Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextWin.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsRenderingContextWin_h___
00040 #define nsRenderingContextWin_h___
00041 
00042 #include "nsIRenderingContext.h"
00043 #include "nsUnitConversion.h"
00044 #include "nsFont.h"
00045 #include "nsFontMetricsWin.h"
00046 #include "nsPoint.h"
00047 #include "nsString.h"
00048 #include "nsCRT.h"
00049 #include "nsTransform2D.h"
00050 #include "nsIViewManager.h"
00051 #include "nsIWidget.h"
00052 #include "nsRect.h"
00053 #include "nsImageWin.h"
00054 #include "nsIDeviceContext.h"
00055 #include "nsVoidArray.h"
00056 #include "nsIRenderingContextWin.h"
00057 #include "nsDrawingSurfaceWin.h"
00058 #include "nsRenderingContextImpl.h"
00059 
00060 class GraphicsState;
00061 class nsDrawingSurfaceWin;
00062 
00063 class nsRenderingContextWin : public nsRenderingContextImpl,
00064                               nsIRenderingContextWin
00065 {
00066 public:
00067   nsRenderingContextWin();
00068 
00069   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00070 
00071   NS_DECL_ISUPPORTS
00072 
00073   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
00074   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface);
00075 
00076   NS_IMETHOD Reset(void);
00077 
00078   NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00079 
00080   NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00081                                 void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00082                                 PRUint32 aFlags);
00083   NS_IMETHOD UnlockDrawingSurface(void);
00084 
00085   NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00086   NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00087   NS_IMETHOD GetHints(PRUint32& aResult);
00088 
00089   NS_IMETHOD PushState(void);
00090   NS_IMETHOD PopState(void);
00091 
00092   NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aClipState);
00093 
00094   NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
00095   NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipState);
00096   NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
00097   NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00098   NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00099 
00100   NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00101   NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00102 
00103   NS_IMETHOD SetColor(nscolor aColor);
00104   NS_IMETHOD GetColor(nscolor &aColor) const;
00105 
00106   NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00107   NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00108 
00109   NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00110 
00111   NS_IMETHOD Translate(nscoord aX, nscoord aY);
00112   NS_IMETHOD Scale(float aSx, float aSy);
00113   NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00114 
00115   NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
00116   NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00117 
00118   NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00119   NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00120 
00121   NS_IMETHOD DrawRect(const nsRect& aRect);
00122   NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00123 
00124   NS_IMETHOD FillRect(const nsRect& aRect);
00125   NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00126 
00127   NS_IMETHOD InvertRect(const nsRect& aRect);
00128   NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00129 
00130   NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00131   NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00132 
00133   NS_IMETHOD SetPenMode(nsPenMode aPenMode);
00134   NS_IMETHOD GetPenMode(nsPenMode &aPenMode);
00135 
00136   NS_IMETHOD DrawEllipse(const nsRect& aRect);
00137   NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00138   NS_IMETHOD FillEllipse(const nsRect& aRect);
00139   NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00140 
00141   NS_IMETHOD DrawArc(const nsRect& aRect,
00142                      float aStartAngle, float aEndAngle);
00143   NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00144                      float aStartAngle, float aEndAngle);
00145   NS_IMETHOD FillArc(const nsRect& aRect,
00146                      float aStartAngle, float aEndAngle);
00147   NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00148                      float aStartAngle, float aEndAngle);
00149 
00150   NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
00151                       PRInt32 *aFontID = nsnull)
00152   { return nsRenderingContextImpl::GetWidth(aString, aWidth, aFontID); }
00153   NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth)
00154   { return nsRenderingContextImpl::GetWidth(aString, aWidth); }
00155   NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength,
00156                       nscoord& aWidth)
00157   { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth); }
00158   NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength,
00159                       nscoord &aWidth, PRInt32 *aFontID = nsnull)
00160   { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth, aFontID); }
00161   NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
00162                         PRInt32 aFontID = -1,
00163                         const nscoord* aSpacing = nsnull)
00164   { return nsRenderingContextImpl::DrawString(aString, aX, aY, aFontID, aSpacing); }
00165 
00166   NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
00167   NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
00168                       PRInt32 *aFontID);
00169 
00170   NS_IMETHOD GetWidthInternal(const char *aString, PRUint32 aLength, nscoord &aWidth);
00171   NS_IMETHOD GetWidthInternal(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
00172                               PRInt32 *aFontID);
00173 
00174   NS_IMETHOD DrawStringInternal(const char *aString, PRUint32 aLength,
00175                                 nscoord aX, nscoord aY,
00176                                 const nscoord* aSpacing);
00177   NS_IMETHOD DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
00178                                 nscoord aX, nscoord aY,
00179                                 PRInt32 aFontID,
00180                                 const nscoord* aSpacing);
00181 
00182   NS_IMETHOD GetTextDimensionsInternal(const char* aString, PRUint32 aLength,
00183                                        nsTextDimensions& aDimensions);
00184   NS_IMETHOD GetTextDimensionsInternal(const PRUnichar *aString, PRUint32 aLength,
00185                                        nsTextDimensions& aDimensions,PRInt32 *aFontID);
00186   NS_IMETHOD GetTextDimensionsInternal(const char*       aString,
00187                                        PRInt32           aLength,
00188                                        PRInt32           aAvailWidth,
00189                                        PRInt32*          aBreaks,
00190                                        PRInt32           aNumBreaks,
00191                                        nsTextDimensions& aDimensions,
00192                                        PRInt32&          aNumCharsFit,
00193                                        nsTextDimensions& aLastWordDimensions,
00194                                        PRInt32*          aFontID);
00195   NS_IMETHOD GetTextDimensionsInternal(const PRUnichar*  aString,
00196                                        PRInt32           aLength,
00197                                        PRInt32           aAvailWidth,
00198                                        PRInt32*          aBreaks,
00199                                        PRInt32           aNumBreaks,
00200                                        nsTextDimensions& aDimensions,
00201                                        PRInt32&          aNumCharsFit,
00202                                        nsTextDimensions& aLastWordDimensions,
00203                                        PRInt32*          aFontID);
00204 
00205 #ifdef MOZ_MATHML
00206 
00209   NS_IMETHOD GetBoundingMetricsInternal(const char*        aString,
00210                                         PRUint32           aLength,
00211                                         nsBoundingMetrics& aBoundingMetrics);
00212 
00216   NS_IMETHOD GetBoundingMetricsInternal(const PRUnichar*   aString,
00217                                         PRUint32           aLength,
00218                                         nsBoundingMetrics& aBoundingMetrics,
00219                                         PRInt32*           aFontID = nsnull);
00220 #endif /* MOZ_MATHML */
00221 
00222   virtual PRInt32 GetMaxStringLength();
00223 
00224   NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
00225                                const nsRect &aDestBounds, PRUint32 aCopyFlags);
00226   //~~~
00227   NS_IMETHOD RetrieveCurrentNativeGraphicData(void** ngd);
00228 
00229   // nsIRenderingContextWin
00230   NS_IMETHOD CreateDrawingSurface(HDC aDC, nsIDrawingSurface* &aSurface);
00231 
00232   NS_IMETHOD GetBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, PRBool aForBlending, nsIDrawingSurface* &aBackbuffer);
00233  
00234   NS_IMETHOD ReleaseBackbuffer(void);
00235 
00236   NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
00237   NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL);
00238 
00239 protected:
00240   void SetupFontAndColor(void);
00241 
00242   ~nsRenderingContextWin();
00243 
00244 private:
00245    // ConditionRect is used to fix a coordinate overflow problem under WIN95. 
00246   void ConditionRect(nsRect& aSrcRect, RECT& aDestRect);
00247 
00248   nsresult CommonInit(void);
00249   nsresult SetupDC(HDC aOldDC, HDC aNewDC);
00250   HBRUSH SetupSolidBrush(void);
00251   HPEN SetupPen(void);
00252   HPEN SetupSolidPen(void);
00253   HPEN SetupDashedPen(void);
00254   HPEN SetupDottedPen(void);
00255   void PushClipState(void);
00256   void InitBidiInfo(void);
00257 
00258 friend class nsNativeThemeWin;
00259 
00260 protected:
00261   nscolor            mCurrentColor;
00262   // current font-metrics set in this RC
00263   nsIFontMetrics    *mFontMetrics;
00264   HDC               mDC;
00265   HDC               mMainDC;
00266   nsDrawingSurfaceWin *mSurface;
00267   nsDrawingSurfaceWin *mMainSurface;
00268   COLORREF          mColor;
00269   nsIWidget         *mDCOwner;
00270 //  int               mOldMapMode;
00271   nsIDeviceContext  *mContext;
00272   float             mP2T;
00273   HRGN              mClipRegion;
00274   //default objects
00275   HBRUSH            mOrigSolidBrush;
00276   HFONT             mOrigFont;
00277   HPEN              mOrigSolidPen;
00278   HPALETTE          mOrigPalette;
00279   //state management
00280   GraphicsState     *mStates;
00281   nsVoidArray       *mStateCache;
00282   nscolor           mCurrBrushColor;
00283   HBRUSH            mCurrBrush;
00284   // mFontMetrics owns mCurrFontWin which is a thin wrapper
00285   // around mCurrFont (the actual GDI font handle). These variables
00286   // allow us to quickly tell the current selected font and to
00287   // avoid the extra cost of a redundant setup of the same font.
00288   nsFontWin         *mCurrFontWin;
00289   HFONT             mCurrFont;
00290   nscolor           mCurrPenColor;
00291   HPEN              mCurrPen;
00292   HPEN              mNullPen;
00293   PRUint8           *mGammaTable;
00294   nscolor           mCurrTextColor;
00295   nsLineStyle       mCurrLineStyle;
00296 
00297 #ifdef NS_DEBUG
00298   PRPackedBool      mInitialized;
00299 #endif
00300   PRPackedBool      mRightToLeftText;
00301 };
00302 
00303 #endif /* nsRenderingContextWin_h___ */