Back to index

lightning-sunbird  0.9+nobinonly
nsIDeviceContext.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  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
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 nsIDeviceContext_h___
00040 #define nsIDeviceContext_h___
00041 
00042 #include "nsISupports.h"
00043 #include "nsCoord.h"
00044 #include "nsRect.h"
00045 #include "nsIWidget.h"
00046 #include "nsIRenderingContext.h"
00047 
00048 class nsIView;
00049 class nsIFontMetrics;
00050 class nsIWidget;
00051 class nsIDeviceContextSpec;
00052 class nsIAtom;
00053 
00054 struct nsFont;
00055 struct nsColor;
00056 
00057 //a cross platform way of specifying a native device context
00058 typedef void * nsNativeDeviceContext;
00059 
00060 /* error codes for printer device contexts */
00061 #define NS_ERROR_GFX_PRINTER_BASE (1) /* adjustable :-) */
00062 /* Unix: print command (lp/lpr) not found */
00063 #define NS_ERROR_GFX_PRINTER_CMD_NOT_FOUND          \
00064   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+1)
00065 /* Unix: print command returned an error */  
00066 #define NS_ERROR_GFX_PRINTER_CMD_FAILURE            \
00067   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+2)
00068 /* no printer available (e.g. cannot find _any_ printer) */
00069 #define NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE  \
00070   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+3)
00071 /* _specified_ (by name) printer not found */
00072 #define NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND         \
00073   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+4)
00074 /* access to printer denied */
00075 #define NS_ERROR_GFX_PRINTER_ACCESS_DENIED          \
00076   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+5)
00077 /* invalid printer attribute (for example: unsupported paper size etc.) */
00078 #define NS_ERROR_GFX_PRINTER_INVALID_ATTRIBUTE      \
00079   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+6)
00080 /* printer not "ready" (offline ?) */
00081 #define NS_ERROR_GFX_PRINTER_PRINTER_NOT_READY     \
00082   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+8)
00083 /* printer out of paper */
00084 #define NS_ERROR_GFX_PRINTER_OUT_OF_PAPER           \
00085   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+9)
00086 /* generic printer I/O error */
00087 #define NS_ERROR_GFX_PRINTER_PRINTER_IO_ERROR       \
00088   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+10)
00089 /* print-to-file: could not open output file */
00090 #define NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE    \
00091   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+11)
00092 /* print-to-file: I/O error while printing to file */
00093 #define NS_ERROR_GFX_PRINTER_FILE_IO_ERROR          \
00094   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+12)
00095 /* print preview: needs at least one printer */
00096 #define NS_ERROR_GFX_PRINTER_PRINTPREVIEW          \
00097   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+13)
00098 /* print: starting document */
00099 #define NS_ERROR_GFX_PRINTER_STARTDOC          \
00100   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+14)
00101 /* print: ending document */
00102 #define NS_ERROR_GFX_PRINTER_ENDDOC          \
00103   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+15)
00104 /* print: starting page */
00105 #define NS_ERROR_GFX_PRINTER_STARTPAGE          \
00106   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+16)
00107 /* print: ending page */
00108 #define NS_ERROR_GFX_PRINTER_ENDPAGE          \
00109   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+17)
00110 /* print: print while in print preview */
00111 #define NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW          \
00112   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+18)
00113 /* requested page size not supported by printer */
00114 #define NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED \
00115   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+19)
00116 /* requested page orientation not supported */
00117 #define NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED \
00118   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+20)
00119 /* requested colorspace not supported (like printing "color" on a "grayscale"-only printer) */
00120 #define NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED \
00121   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+21)
00122 /* too many copies requested */
00123 #define NS_ERROR_GFX_PRINTER_TOO_MANY_COPIES \
00124   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+22)
00125 /* driver configuration error */
00126 #define NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR \
00127   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+23)
00128 /* Xprint module specific: Xprt server broken */
00129 #define NS_ERROR_GFX_PRINTER_XPRINT_BROKEN_XPRT \
00130   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+24)
00131 /* The document is still being loaded, can't Print Preview */
00132 #define NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP \
00133   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+25)
00134 /* The document was asked to be destroyed while we were preparing printing */
00135 #define NS_ERROR_GFX_PRINTER_DOC_WAS_DESTORYED \
00136   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+26)
00137 /* Cannot Print or Print Preview XUL Documents */
00138 #define NS_ERROR_GFX_PRINTER_NO_XUL \
00139   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+27)
00140 /* The toolkit no longer supports the Print Dialog (for embedders) */
00141 #define NS_ERROR_GFX_NO_PRINTDIALOG_IN_TOOLKIT \
00142   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+28)
00143 /* The was wasn't any Print Prompt service registered (this shouldn't happen) */
00144 #define NS_ERROR_GFX_NO_PRINTROMPTSERVICE \
00145   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+29)
00146 /* Xprint module specific: No Xprint servers found */
00147 #define NS_ERROR_GFX_PRINTER_XPRINT_NO_XPRINT_SERVERS_FOUND \
00148   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+30)
00149 /* requested plex mode not supported by printer */
00150 #define NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED \
00151   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+31)
00152 /* The document is still being loaded */
00153 #define NS_ERROR_GFX_PRINTER_DOC_IS_BUSY \
00154   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+32)
00155 /* Printing is not implemented */
00156 #define NS_ERROR_GFX_PRINTING_NOT_IMPLEMENTED \
00157   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+33)
00158 /* Cannot load the matching print module */
00159 #define NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE \
00160   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+34)   
00161 /* requested resolution/quality mode not supported by printer */
00162 #define NS_ERROR_GFX_PRINTER_RESOLUTION_NOT_SUPPORTED \
00163   NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+35)
00164       
00168 #ifdef NS_PRINT_PREVIEW
00169 const PRUint8 kUseAltDCFor_NONE            = 0x00; // Do not use the AltDC for anything
00170 const PRUint8 kUseAltDCFor_FONTMETRICS     = 0x01; // Use it for only getting the font metrics
00171 const PRUint8 kUseAltDCFor_CREATERC_REFLOW = 0x02; // Use when creating RenderingContexts for Reflow
00172 const PRUint8 kUseAltDCFor_CREATERC_PAINT  = 0x04; // Use when creating RenderingContexts for Painting
00173 const PRUint8 kUseAltDCFor_SURFACE_DIM     = 0x08; // Use it for getting the Surface Dimensions
00174 #endif
00175 
00176 #define NS_IDEVICE_CONTEXT_IID   \
00177 { 0xb31ad9ce, 0x40cb, 0x43c4, \
00178   { 0x90, 0xf8, 0x0f, 0x30, 0x53, 0xf6, 0xb8, 0xea } }
00179 
00180 //a cross platform way of specifying a native palette handle
00181 typedef void * nsPalette;
00182 
00183   //structure used to return information about a device's palette capabilities
00184   struct nsPaletteInfo {
00185      PRPackedBool  isPaletteDevice;
00186      PRUint16      sizePalette;  // number of entries in the palette
00187      PRUint16      numReserved;  // number of reserved palette entries
00188      nsPalette     palette;      // native palette handle
00189   };
00190 
00191   typedef enum {
00192     eSystemFont_Caption,         // css2
00193     eSystemFont_Icon,
00194     eSystemFont_Menu,
00195     eSystemFont_MessageBox,
00196     eSystemFont_SmallCaption,
00197     eSystemFont_StatusBar,
00198 
00199     eSystemFont_Window,          // css3
00200     eSystemFont_Document,
00201     eSystemFont_Workspace,
00202     eSystemFont_Desktop,
00203     eSystemFont_Info,
00204     eSystemFont_Dialog,
00205     eSystemFont_Button,
00206     eSystemFont_PullDownMenu,
00207     eSystemFont_List,
00208     eSystemFont_Field,
00209 
00210     eSystemFont_Tooltips,        // moz
00211     eSystemFont_Widget
00212   } nsSystemFontID;
00213 
00214 class nsIDeviceContext : public nsISupports
00215 {
00216 public:
00217   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_IID)
00218 
00219   
00224   NS_IMETHOD  Init(nsNativeWidget aWidget) = 0;
00225 
00232   NS_IMETHOD  CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) = 0;
00233 
00240   NS_IMETHOD  CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext) = 0;
00241 
00248   NS_IMETHOD  CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) = 0;
00249 
00256   NS_IMETHOD  CreateRenderingContext(nsIRenderingContext *&aContext) = 0;
00257 
00263   NS_IMETHOD  CreateRenderingContextInstance(nsIRenderingContext *&aContext) = 0;
00264 
00272   NS_IMETHOD  SupportsNativeWidgets(PRBool &aSupportsWidgets) = 0;
00273 
00279   float DevUnitsToTwips() const { return mPixelsToTwips; }
00280 
00285   float TwipsToDevUnits() const { return mTwipsToPixels; }
00286 
00298   void SetAppUnitsToDevUnits(float aAppUnits)
00299   {
00300     mAppUnitsToDevUnits = aAppUnits;
00301   }
00302 
00310   void SetDevUnitsToAppUnits(float aDevUnits)
00311   {
00312     mDevUnitsToAppUnits = aDevUnits;
00313   }
00314 
00320   float AppUnitsToDevUnits() const { return mAppUnitsToDevUnits; }
00321 
00328   float DevUnitsToAppUnits() const { return mDevUnitsToAppUnits; }
00329 
00340   NS_IMETHOD  GetCanonicalPixelScale(float &aScale) const = 0;
00341 
00352   NS_IMETHOD  SetCanonicalPixelScale(float aScale) = 0;
00353 
00361   NS_IMETHOD  GetScrollBarDimensions(float &aWidth, float &aHeight) const = 0;
00362 
00372   NS_IMETHOD  GetSystemFont(nsSystemFontID aID, nsFont *aFont) const = 0;
00373 
00382   NS_IMETHOD  GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
00383                             nsIFontMetrics*& aMetrics) = 0;
00384 
00392   NS_IMETHOD  GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics) = 0;
00393 
00394   //get and set the document zoom value used for display-time
00395   //scaling. default is 1.0 (no zoom)
00396   NS_IMETHOD  SetZoom(float aZoom) = 0;
00397   NS_IMETHOD  GetZoom(float &aZoom) const = 0;
00398 
00404   NS_IMETHOD CheckFontExistence(const nsString& aFaceName) = 0;
00405   NS_IMETHOD FirstExistingFont(const nsFont& aFont, nsString& aFaceName) = 0;
00406 
00407   NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName,
00408                               PRBool& aAliased) = 0;
00409 
00414   NS_IMETHOD FontMetricsDeleted(const nsIFontMetrics* aFontMetrics) = 0;
00415 
00421   NS_IMETHOD FlushFontCache(void) = 0;
00422 
00426   NS_IMETHOD GetDepth(PRUint32& aDepth) = 0;
00427 
00431   NS_IMETHOD GetPaletteInfo(nsPaletteInfo& aPaletteInfo) = 0;
00432 
00440   NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) = 0;
00441 
00449   NS_IMETHOD GetRect ( nsRect &aRect ) = 0;
00450 
00461   NS_IMETHOD GetClientRect(nsRect &aRect) = 0;
00462 
00473   NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
00474                                  nsIDeviceContext *&aContext) = 0;
00475 
00484   NS_IMETHOD PrepareDocument(PRUnichar * aTitle, 
00485                              PRUnichar*  aPrintToFileName) = 0;
00486 
00487   //XXX need to work out re-entrancy issues for these APIs... MMP
00502   NS_IMETHOD BeginDocument(PRUnichar*  aTitle, 
00503                            PRUnichar*  aPrintToFileName,
00504                            PRInt32     aStartPage, 
00505                            PRInt32     aEndPage) = 0;
00506 
00513   NS_IMETHOD EndDocument(void) = 0;
00514 
00520   NS_IMETHOD AbortDocument(void) = 0;
00521 
00528   NS_IMETHOD BeginPage(void) = 0;
00529 
00536   NS_IMETHOD EndPage(void) = 0;
00537 
00538 #ifdef NS_PRINT_PREVIEW
00539 
00543   NS_IMETHOD SetAltDevice(nsIDeviceContext* aAltDC) = 0;
00544 
00548   NS_IMETHOD GetAltDevice(nsIDeviceContext** aAltDC) = 0;
00549 
00554   NS_IMETHOD SetUseAltDC(PRUint8 aValue, PRBool aOn) = 0;
00555 #endif
00556 
00557 protected:
00558   float mTwipsToPixels;
00559   float mPixelsToTwips;
00560   float mAppUnitsToDevUnits;
00561   float mDevUnitsToAppUnits;
00562 };
00563 
00564 #endif /* nsIDeviceContext_h___ */