Back to index

lightning-sunbird  0.9+nobinonly
nsDeviceContextPh.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsDeviceContextPh_h___
00039 #define nsDeviceContextPh_h___
00040 
00041 #include "nsDeviceContext.h"
00042 #include "nsUnitConversion.h"
00043 #include "nsIWidget.h"
00044 #include "nsIView.h"
00045 #include "nsIRenderingContext.h"
00046 #include "nsIScreenManager.h"
00047 
00048 #include "nsRenderingContextPh.h"
00049 #include <Pt.h>
00050 
00051 class nsDeviceContextPh : public DeviceContextImpl
00052 {
00053 public:
00054   nsDeviceContextPh();
00055   virtual ~nsDeviceContextPh();
00056   
00057   NS_IMETHOD  Init(nsNativeWidget aWidget);
00058 
00059 
00060   NS_IMETHOD  CreateRenderingContext(nsIRenderingContext *&aContext);
00061   NS_IMETHOD  CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));}
00062   NS_IMETHOD  CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));}
00063 
00064        inline
00065   NS_IMETHODIMP SupportsNativeWidgets(PRBool &aSupportsWidgets)
00066               {
00067               /* REVISIT: These needs to return FALSE if we are printing! */
00068          if( nsnull == mDC ) aSupportsWidgets = PR_TRUE;
00069          else aSupportsWidgets = PR_FALSE;   /* while printing! */
00070          return NS_OK;
00071               }
00072 
00073        inline
00074   NS_IMETHODIMP GetScrollBarDimensions(float &aWidth, float &aHeight) const
00075               {
00076               /* Revisit: the scroll bar sizes is a gross guess based on Phab */
00077               float scale;
00078               GetCanonicalPixelScale(scale);
00079               aWidth = mScrollbarWidth * mPixelsToTwips * scale;
00080               aHeight = mScrollbarHeight * mPixelsToTwips * scale;
00081               return NS_OK;
00082               }
00083 
00084   NS_IMETHOD  GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
00085 
00086   //get a low level drawing surface for rendering. the rendering context
00087   //that is passed in is used to create the drawing surface if there isn't
00088   //already one in the device context. the drawing surface is then cached
00089   //in the device context for re-use.
00090 
00091        inline
00092   NS_IMETHODIMP GetDrawingSurface(nsIRenderingContext &aContext, nsIDrawingSurface* &aSurface)
00093               {
00094               nsRect aRect;
00095               GetClientRect( aRect );
00096               aContext.CreateDrawingSurface(aRect, 0, aSurface);
00097               return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
00098               }
00099 
00100   NS_IMETHOD  CheckFontExistence(const nsString& aFontName);
00101 
00102   NS_IMETHOD  GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
00103   inline NS_IMETHOD  GetClientRect(nsRect &aRect) { return GetRect ( aRect ); }
00104   NS_IMETHOD GetRect(nsRect &aRect);
00105  
00106   NS_IMETHOD  GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
00107                                   nsIDeviceContext *&aContext);
00108 
00109        NS_IMETHOD  BeginDocument(PRUnichar *t, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
00110   NS_IMETHOD  EndDocument(void);
00111   NS_IMETHOD  AbortDocument(void);
00112 
00113   NS_IMETHOD  BeginPage(void);
00114   NS_IMETHOD  EndPage(void);
00115 
00116        inline
00117   NS_IMETHODIMP GetDepth(PRUint32& aDepth)
00118               {
00119               aDepth = mDepth; // 24;
00120               return NS_OK;
00121               }
00122 
00123   static int prefChanged(const char *aPref, void *aClosure);
00124   nsresult    SetDPI(PRInt32 dpi);
00125 
00126 protected:
00127 
00128   nsresult    Init(nsNativeDeviceContext aContext, nsIDeviceContext *aOrigContext);
00129   nsresult    GetDisplayInfo(PRInt32 &aWidth, PRInt32 &aHeight, PRUint32 &aDepth);
00130   void        CommonInit(nsNativeDeviceContext aDC);
00131   void               GetPrinterRect(int *width, int *height);
00132 
00133   nsIDrawingSurface*      mSurface;
00134   PRUint32              mDepth;  // bit depth of device
00135   float                 mPixelScale;
00136   PRInt16               mScrollbarHeight;
00137   PRInt16               mScrollbarWidth;
00138   
00139   float                 mWidthFloat;
00140   float                 mHeightFloat;
00141   PRInt32               mWidth;
00142   PRInt32               mHeight;
00143 
00144   nsIDeviceContextSpec  *mSpec;
00145   nsNativeDeviceContext mDC;
00146        PhGC_t                                                  *mGC;
00147 
00148   static nscoord        mDpi;
00149 
00150   PRBool mIsPrintingStart;
00151 
00152 private:
00153        nsCOMPtr<nsIScreenManager> mScreenManager;
00154        int ReadSystemFonts( ) const;
00155        void DefaultSystemFonts( ) const;
00156 };
00157 
00158 #define       NS_FONT_STYLE_ANTIALIAS                          0xf0
00159 
00160 #endif /* nsDeviceContextPh_h___ */