Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextBeOS.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: 4; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Daniel Switkin, Mathias Agopian, Sergei Dolgov
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 nsRenderingContextBeOS_h___
00040 #define nsRenderingContextBeOS_h___
00041 
00042 #include "nsRenderingContextImpl.h"
00043 #include "nsUnitConversion.h"
00044 #include "nsFont.h"
00045 #include "nsIFontMetrics.h"
00046 #include "nsPoint.h"
00047 #include "nsString.h"
00048 #include "nsCRT.h"
00049 #include "nsTransform2D.h"
00050 #include "nsIWidget.h"
00051 #include "nsRect.h"
00052 #include "nsIDeviceContext.h"
00053 #include "nsVoidArray.h"
00054 #include "nsGfxCIID.h"
00055 #include "nsDrawingSurfaceBeOS.h"
00056 #include "nsRegionBeOS.h"
00057 
00058 class nsRenderingContextBeOS : public nsRenderingContextImpl
00059 {
00060 public:
00061        nsRenderingContextBeOS();
00062        virtual ~nsRenderingContextBeOS();
00063        
00064        NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW     
00065        NS_DECL_ISUPPORTS
00066        
00067        NS_IMETHOD Init(nsIDeviceContext *aContext, nsIWidget *aWindow);
00068        NS_IMETHOD Init(nsIDeviceContext *aContext, nsIDrawingSurface* aSurface);
00069        
00070        NS_IMETHOD Reset();
00071        NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00072        
00073        NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00074               void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, PRUint32 aFlags);
00075        NS_IMETHOD UnlockDrawingSurface();
00076        
00077        NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00078        NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00079        NS_IMETHOD GetHints(PRUint32 &aResult);
00080        
00081        NS_IMETHOD PushState();
00082        NS_IMETHOD PopState();
00083        
00084        NS_IMETHOD IsVisibleRect(const nsRect &aRect, PRBool &aVisible);
00085        
00086        NS_IMETHOD SetClipRect(const nsRect &aRect, nsClipCombine aCombine);
00087        NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
00088        NS_IMETHOD SetClipRegion(const nsIRegion &aRegion, nsClipCombine aCombine);
00089        NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00090        NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00091        
00092        NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00093        NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00094        
00095        NS_IMETHOD SetColor(nscolor aColor);
00096        NS_IMETHOD GetColor(nscolor &aColor) const;
00097        
00098        NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00099        NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00100        
00101        NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00102        
00103        NS_IMETHOD Translate(nscoord aX, nscoord aY);
00104        NS_IMETHOD Scale(float aSx, float aSy);
00105        NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00106        
00107        NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
00108        NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00109        
00110        NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00111        NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00112        
00113        NS_IMETHOD DrawRect(const nsRect &aRect);
00114        NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00115        
00116        NS_IMETHOD FillRect(const nsRect &aRect);
00117        NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00118        
00119        NS_IMETHOD InvertRect(const nsRect &aRect);
00120        NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00121        
00122        NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00123        NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00124        
00125        NS_IMETHOD DrawEllipse(const nsRect &aRect);
00126        NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00127        NS_IMETHOD FillEllipse(const nsRect &aRect);
00128        NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00129        
00130        NS_IMETHOD DrawArc(const nsRect &aRect, float aStartAngle, float aEndAngle);
00131        NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00132               float aStartAngle, float aEndAngle);
00133        NS_IMETHOD FillArc(const nsRect &aRect, float aStartAngle, float aEndAngle);
00134        NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00135               float aStartAngle, float aEndAngle);
00136        
00137        NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
00138        NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID);
00139        NS_IMETHOD GetWidth(const nsString &aString, nscoord &aWidth, PRInt32 *aFontID);
00140        NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
00141        NS_IMETHOD GetWidth(const char *aString, PRUint32 aLength, nscoord &aWidth);
00142        NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
00143               PRInt32 *aFontID);
00144        
00145        NS_IMETHOD GetTextDimensions(const char *aString, PRUint32 aLength,
00146               nsTextDimensions &aDimensions);
00147        NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
00148               nsTextDimensions &aDimensions, PRInt32 *aFontID);
00149        NS_IMETHOD GetTextDimensions(const char*       aString,
00150                                                         PRInt32           aLength,
00151                                                         PRInt32           aAvailWidth,
00152                                                         PRInt32*          aBreaks,
00153                                                         PRInt32           aNumBreaks,
00154                                                         nsTextDimensions& aDimensions,
00155                                                         PRInt32&          aNumCharsFit,
00156                                                         nsTextDimensions& aLastWordDimensions,
00157                                                         PRInt32*          aFontID = nsnull);
00158        NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
00159                                                         PRInt32           aLength,
00160                                                         PRInt32           aAvailWidth,
00161                                                         PRInt32*          aBreaks,
00162                                                         PRInt32           aNumBreaks,
00163                                                         nsTextDimensions& aDimensions,
00164                                                         PRInt32&          aNumCharsFit,
00165                                                         nsTextDimensions& aLastWordDimensions,
00166                                                         PRInt32*          aFontID = nsnull);
00167                                    
00168        NS_IMETHOD DrawString(const char *aString, PRUint32 aLength, nscoord aX, nscoord aY,
00169               const nscoord *aSpacing);
00170        NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY,
00171               PRInt32 aFontID, const nscoord *aSpacing);
00172        NS_IMETHOD DrawString(const nsString &aString, nscoord aX, nscoord aY, PRInt32 aFontID,
00173               const nscoord *aSpacing);
00174        
00175        NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
00176               const nsRect &aDestBounds, PRUint32 aCopyFlags);
00177        NS_IMETHOD RetrieveCurrentNativeGraphicData(void** ngd);
00178        
00179        void CreateClipRegion();
00180 
00181 #ifdef MOZ_MATHML
00182 
00185   NS_IMETHOD GetBoundingMetrics(const char*        aString,
00186                                 PRUint32           aLength,
00187                                 nsBoundingMetrics& aBoundingMetrics);
00188   
00192   NS_IMETHOD GetBoundingMetrics(const PRUnichar*   aString,
00193                                 PRUint32           aLength,
00194                                 nsBoundingMetrics& aBoundingMetrics,
00195                                 PRInt32*           aFontID = nsnull);
00196 #endif /* MOZ_MATHML */
00197 
00198 #ifdef NOBBCACHE
00199        NS_IMETHOD GetBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize,
00200                            PRBool aForBlending, nsIDrawingSurface* &aBackbuffer);
00201        NS_IMETHOD ReleaseBackbuffer(void);
00202 #endif
00203 
00204   //LockAndUpdateView() - method, similar to UpdateGC (from gtk gfx).
00205   //Acquires "fresh" drawable mView (BView) from drawing surface, locks it (BeOS specifics),
00206   //updates font, color and sets clipping region. 
00207   bool LockAndUpdateView(); 
00208   //Each LockAndUpdateView() statement must have UnlockView() counterpart somewhere, 
00209   //if returned true.
00210   void UnlockView();
00211 
00212 protected:
00213        NS_IMETHOD CommonInit();
00214        
00215        // ConditionRect is used to fix coordinate overflow problems for
00216        // rectangles after they are transformed to screen coordinates
00217        void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h)
00218        {
00219               if (y < -32766) y = -32766;
00220               if (y + h > 32766) h = 32766 - y;
00221               if (x < -32766) x = -32766;
00222               if (x + w > 32766) w = 32766 - x;
00223        }
00224        
00225        nsDrawingSurfaceBeOS *mOffscreenSurface;
00226        nsDrawingSurfaceBeOS *mSurface;
00227        nsIDeviceContext *mContext;
00228        nsIFontMetrics *mFontMetrics;
00229        nsCOMPtr<nsIRegion> mClipRegion;
00230        nsVoidArray *mStateCache;
00231        BView *mView;
00232        nscolor mCurrentColor;
00233        rgb_color mRGB_color;
00234        BFont *mCurrentBFont;
00235        nsLineStyle mCurrentLineStyle;
00236        pattern mCurrentLinePattern;
00237        float mP2T;
00238 };
00239 
00240 #endif /* nsRenderingContextBeOS_h___ */