1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsIDeviceContext_h___
40 #define nsIDeviceContext_h___
42 #include "nsISupports.h"
45 #include "nsIWidget.h"
46 #include "nsIRenderingContext.h"
47 // XXX we need only gfxTypes.h, but we cannot include it directly.
53 class nsIDeviceContextSpec
;
59 //a cross platform way of specifying a native device context
60 typedef void * nsNativeDeviceContext
;
62 /* error codes for printer device contexts */
63 #define NS_ERROR_GFX_PRINTER_BASE (1) /* adjustable :-) */
64 /* Unix: print command (lp/lpr) not found */
65 #define NS_ERROR_GFX_PRINTER_CMD_NOT_FOUND \
66 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+1)
67 /* Unix: print command returned an error */
68 #define NS_ERROR_GFX_PRINTER_CMD_FAILURE \
69 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+2)
70 /* no printer available (e.g. cannot find _any_ printer) */
71 #define NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE \
72 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+3)
73 /* _specified_ (by name) printer not found */
74 #define NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND \
75 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+4)
76 /* access to printer denied */
77 #define NS_ERROR_GFX_PRINTER_ACCESS_DENIED \
78 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+5)
79 /* invalid printer attribute (for example: unsupported paper size etc.) */
80 #define NS_ERROR_GFX_PRINTER_INVALID_ATTRIBUTE \
81 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+6)
82 /* printer not "ready" (offline ?) */
83 #define NS_ERROR_GFX_PRINTER_PRINTER_NOT_READY \
84 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+8)
85 /* printer out of paper */
86 #define NS_ERROR_GFX_PRINTER_OUT_OF_PAPER \
87 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+9)
88 /* generic printer I/O error */
89 #define NS_ERROR_GFX_PRINTER_PRINTER_IO_ERROR \
90 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+10)
91 /* print-to-file: could not open output file */
92 #define NS_ERROR_GFX_PRINTER_COULD_NOT_OPEN_FILE \
93 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+11)
94 /* print-to-file: I/O error while printing to file */
95 #define NS_ERROR_GFX_PRINTER_FILE_IO_ERROR \
96 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+12)
97 /* print preview: needs at least one printer */
98 #define NS_ERROR_GFX_PRINTER_PRINTPREVIEW \
99 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+13)
100 /* print: starting document */
101 #define NS_ERROR_GFX_PRINTER_STARTDOC \
102 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+14)
103 /* print: ending document */
104 #define NS_ERROR_GFX_PRINTER_ENDDOC \
105 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+15)
106 /* print: starting page */
107 #define NS_ERROR_GFX_PRINTER_STARTPAGE \
108 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+16)
109 /* print: ending page */
110 #define NS_ERROR_GFX_PRINTER_ENDPAGE \
111 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+17)
112 /* print: print while in print preview */
113 #define NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW \
114 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+18)
115 /* requested page size not supported by printer */
116 #define NS_ERROR_GFX_PRINTER_PAPER_SIZE_NOT_SUPPORTED \
117 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+19)
118 /* requested page orientation not supported */
119 #define NS_ERROR_GFX_PRINTER_ORIENTATION_NOT_SUPPORTED \
120 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+20)
121 /* requested colorspace not supported (like printing "color" on a "grayscale"-only printer) */
122 #define NS_ERROR_GFX_PRINTER_COLORSPACE_NOT_SUPPORTED \
123 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+21)
124 /* too many copies requested */
125 #define NS_ERROR_GFX_PRINTER_TOO_MANY_COPIES \
126 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+22)
127 /* driver configuration error */
128 #define NS_ERROR_GFX_PRINTER_DRIVER_CONFIGURATION_ERROR \
129 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+23)
130 /* The document is still being loaded, can't Print Preview */
131 #define NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP \
132 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+24)
133 /* The document was asked to be destroyed while we were preparing printing */
134 #define NS_ERROR_GFX_PRINTER_DOC_WAS_DESTORYED \
135 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+25)
136 /* Cannot Print or Print Preview XUL Documents */
137 #define NS_ERROR_GFX_PRINTER_NO_XUL \
138 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+26)
139 /* The toolkit no longer supports the Print Dialog (for embedders) */
140 #define NS_ERROR_GFX_NO_PRINTDIALOG_IN_TOOLKIT \
141 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+27)
142 /* The was wasn't any Print Prompt service registered (this shouldn't happen) */
143 #define NS_ERROR_GFX_NO_PRINTROMPTSERVICE \
144 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+28)
145 /* requested plex mode not supported by printer */
146 #define NS_ERROR_GFX_PRINTER_PLEX_NOT_SUPPORTED \
147 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+29)
148 /* The document is still being loaded */
149 #define NS_ERROR_GFX_PRINTER_DOC_IS_BUSY \
150 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+30)
151 /* Printing is not implemented */
152 #define NS_ERROR_GFX_PRINTING_NOT_IMPLEMENTED \
153 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+31)
154 /* Cannot load the matching print module */
155 #define NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE \
156 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+32)
157 /* requested resolution/quality mode not supported by printer */
158 #define NS_ERROR_GFX_PRINTER_RESOLUTION_NOT_SUPPORTED \
159 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_GFX,NS_ERROR_GFX_PRINTER_BASE+33)
162 * Conts need for Print Preview
164 #ifdef NS_PRINT_PREVIEW
165 const PRUint8 kUseAltDCFor_NONE
= 0x00; // Do not use the AltDC for anything
166 const PRUint8 kUseAltDCFor_FONTMETRICS
= 0x01; // Use it for only getting the font metrics
167 const PRUint8 kUseAltDCFor_CREATERC_REFLOW
= 0x02; // Use when creating RenderingContexts for Reflow
168 const PRUint8 kUseAltDCFor_CREATERC_PAINT
= 0x04; // Use when creating RenderingContexts for Painting
169 const PRUint8 kUseAltDCFor_SURFACE_DIM
= 0x08; // Use it for getting the Surface Dimensions
172 // eca27eb2-ef6f-4142-bf77-89c14e595171
173 #define NS_IDEVICE_CONTEXT_IID \
174 { 0xeca27eb2, 0xef6f, 0x4142, \
175 { 0xbf, 0x77, 0x89, 0xc1, 0x4e, 0x59, 0x51, 0x71 } }
177 //a cross platform way of specifying a native palette handle
178 typedef void * nsPalette
;
180 //structure used to return information about a device's palette capabilities
181 struct nsPaletteInfo
{
182 PRPackedBool isPaletteDevice
;
183 PRUint16 sizePalette
; // number of entries in the palette
184 PRUint16 numReserved
; // number of reserved palette entries
185 nsPalette palette
; // native palette handle
189 eSystemFont_Caption
, // css2
192 eSystemFont_MessageBox
,
193 eSystemFont_SmallCaption
,
194 eSystemFont_StatusBar
,
196 eSystemFont_Window
, // css3
197 eSystemFont_Document
,
198 eSystemFont_Workspace
,
203 eSystemFont_PullDownMenu
,
207 eSystemFont_Tooltips
, // moz
211 class nsIDeviceContext
: public nsISupports
214 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_IID
)
217 * Initialize the device context from a widget
218 * @param aWidget a native widget to initialize the device context from
219 * @return error status
221 NS_IMETHOD
Init(nsNativeWidget aWidget
) = 0;
224 * Initialize the device context from a device context spec
225 * @param aDevSpec the specification of the printng device (platform-specific)
226 * @return error status
228 NS_IMETHOD
InitForPrinting(nsIDeviceContextSpec
* aDevSpec
) = 0;
231 * Create a rendering context and initialize it from an nsIView
232 * @param aView view to initialize context from
233 * @param aContext out parameter for new rendering context
234 * @return error status
236 NS_IMETHOD
CreateRenderingContext(nsIView
*aView
, nsIRenderingContext
*&aContext
) = 0;
239 * Create a rendering context and initialize it from an nsIWidget
240 * @param aWidget widget to initialize context from
241 * @param aContext out parameter for new rendering context
242 * @return error status
244 NS_IMETHOD
CreateRenderingContext(nsIWidget
*aWidget
, nsIRenderingContext
*&aContext
) = 0;
247 * Create a rendering context and initialize it. This API should *only* be called
248 * on device contexts whose SupportsNativeWidgets() method return PR_FALSE.
249 * @param aContext out parameter for new rendering context
250 * @return error status
252 NS_IMETHOD
CreateRenderingContext(nsIRenderingContext
*&aContext
) = 0;
255 * Create an uninitalised rendering context.
256 * @param aContext out parameter for new rendering context
257 * @return error status
259 NS_IMETHOD
CreateRenderingContextInstance(nsIRenderingContext
*&aContext
) = 0;
262 * Query the device to see if it supports native widgets. If not, then
263 * nsIWidget->Create() calls should be avoided.
264 * @param aSupportsWidgets out paramater. If PR_TRUE, then native widgets
266 * @return error status
268 NS_IMETHOD
SupportsNativeWidgets(PRBool
&aSupportsWidgets
) = 0;
271 * We are in the process of creating the native widget for aWidget.
272 * Do any device-specific processing required to initialize the
273 * native widget for this device. A pointer to some platform-specific data is
276 * GTK2 calls this to get the required visual for the window.
278 NS_IMETHOD
PrepareNativeWidget(nsIWidget
* aWidget
, void** aOut
) = 0;
281 * Gets the number of app units in one CSS pixel; this number is global,
282 * not unique to each device context.
284 static PRInt32
AppUnitsPerCSSPixel() { return 60; }
287 * Convert app units to CSS pixels which is used in gfx/thebes.
289 static gfxFloat
AppUnitsToGfxCSSPixels(nscoord aAppUnits
)
290 { return gfxFloat(aAppUnits
) / AppUnitsPerCSSPixel(); }
293 * Gets the number of app units in one device pixel; this number is usually
294 * a factor of AppUnitsPerCSSPixel(), although that is not guaranteed.
296 PRInt32
AppUnitsPerDevPixel() const { return mAppUnitsPerDevPixel
; }
299 * Convert device pixels which is used for gfx/thebes to nearest (rounded)
302 nscoord
GfxUnitsToAppUnits(gfxFloat aGfxUnits
) const
303 { return nscoord(NS_round(aGfxUnits
* AppUnitsPerDevPixel())); }
306 * Convert app units to device pixels which is used for gfx/thebes.
308 gfxFloat
AppUnitsToGfxUnits(nscoord aAppUnits
) const
309 { return gfxFloat(aAppUnits
) / AppUnitsPerDevPixel(); }
312 * Gets the number of app units in one inch; this is the device's DPI
313 * times AppUnitsPerDevPixel().
315 PRInt32
AppUnitsPerInch() const { return mAppUnitsPerInch
; }
318 * Fill in an nsFont based on the ID of a system font. This function
319 * may or may not fill in the size, so the size should be set to a
320 * reasonable default before calling.
322 * @param aID The system font ID.
323 * @param aInfo The font structure to be filled in.
324 * @return error status
326 NS_IMETHOD
GetSystemFont(nsSystemFontID aID
, nsFont
*aFont
) const = 0;
329 * Get the nsIFontMetrics that describe the properties of
331 * @param aFont font description to obtain metrics for
332 * @param aLangGroup the language group of the document
333 * @param aMetrics out parameter for font metrics
334 * @param aUserFontSet user font set
335 * @return error status
337 NS_IMETHOD
GetMetricsFor(const nsFont
& aFont
, nsIAtom
* aLangGroup
,
338 gfxUserFontSet
* aUserFontSet
,
339 nsIFontMetrics
*& aMetrics
) = 0;
342 * Get the nsIFontMetrics that describe the properties of
344 * @param aFont font description to obtain metrics for
345 * @param aMetrics out parameter for font metrics
346 * @param aUserFontSet user font set
347 * @return error status
349 NS_IMETHOD
GetMetricsFor(const nsFont
& aFont
, gfxUserFontSet
* aUserFontSet
,
350 nsIFontMetrics
*& aMetrics
) = 0;
353 * Check to see if a particular named font exists.
354 * @param aFontName character string of font face name
355 * @return NS_OK if font is available, else font is unavailable
357 NS_IMETHOD
CheckFontExistence(const nsString
& aFaceName
) = 0;
358 NS_IMETHOD
FirstExistingFont(const nsFont
& aFont
, nsString
& aFaceName
) = 0;
360 NS_IMETHOD
GetLocalFontName(const nsString
& aFaceName
, nsString
& aLocalName
,
361 PRBool
& aAliased
) = 0;
364 * Notification when a font metrics instance created for this device is
365 * about to be deleted
367 NS_IMETHOD
FontMetricsDeleted(const nsIFontMetrics
* aFontMetrics
) = 0;
370 * Attempt to free up resoruces by flushing out any fonts no longer
371 * referenced by anything other than the font cache itself.
372 * @return error status
374 NS_IMETHOD
FlushFontCache(void) = 0;
377 * Return the bit depth of the device.
379 NS_IMETHOD
GetDepth(PRUint32
& aDepth
) = 0;
382 * Returns information about the device's palette capabilities.
384 NS_IMETHOD
GetPaletteInfo(nsPaletteInfo
& aPaletteInfo
) = 0;
387 * Get the size of the displayable area of the output device
389 * @param aWidth out parameter for width
390 * @param aHeight out parameter for height
391 * @return error status
393 NS_IMETHOD
GetDeviceSurfaceDimensions(nscoord
&aWidth
, nscoord
&aHeight
) = 0;
396 * Get the size of the content area of the output device in app units.
397 * This corresponds on a screen device, for instance, to the entire screen.
398 * @param aRect out parameter for full rect. Position (x,y) will be (0,0) or
399 * relative to the primary monitor if this is not the primary.
400 * @return error status
402 NS_IMETHOD
GetRect ( nsRect
&aRect
) = 0;
405 * Get the size of the content area of the output device in app units.
406 * This corresponds on a screen device, for instance, to the area reported
407 * by GetDeviceSurfaceDimensions, minus the taskbar (Windows) or menubar
409 * @param aRect out parameter for client rect. Position (x,y) will be (0,0)
410 * adjusted for any upper/left non-client space if present or
411 * relative to the primary monitor if this is not the primary.
412 * @return error status
414 NS_IMETHOD
GetClientRect(nsRect
&aRect
) = 0;
417 * This is enables the DeviceContext to anything it needs to do for Printing
418 * before Reflow and BeginDocument is where work can be done after reflow.
419 * @param aTitle - itle of Document
420 * @param aPrintToFileName - name of file to print to, if NULL then don't print to file
422 * @return error status
424 NS_IMETHOD
PrepareDocument(PRUnichar
* aTitle
,
425 PRUnichar
* aPrintToFileName
) = 0;
427 //XXX need to work out re-entrancy issues for these APIs... MMP
429 * Inform the output device that output of a document is beginning
430 * Used for print related device contexts. Must be matched 1:1 with
432 * XXX needs to take parameters so that feedback can be given to the
433 * app regarding pagination progress and aborting print operations?
435 * @param aTitle - itle of Document
436 * @param aPrintToFileName - name of file to print to, if NULL then don't print to file
437 * @param aStartPage - starting page number (must be greater than zero)
438 * @param aEndPage - ending page number (must be less than or equal to number of pages)
440 * @return error status
442 NS_IMETHOD
BeginDocument(PRUnichar
* aTitle
,
443 PRUnichar
* aPrintToFileName
,
445 PRInt32 aEndPage
) = 0;
448 * Inform the output device that output of a document is ending.
449 * Used for print related device contexts. Must be matched 1:1 with
451 * @return error status
453 NS_IMETHOD
EndDocument(void) = 0;
456 * Inform the output device that output of a document is being aborted.
457 * Must be matched 1:1 with BeginDocument()
458 * @return error status
460 NS_IMETHOD
AbortDocument(void) = 0;
463 * Inform the output device that output of a page is beginning
464 * Used for print related device contexts. Must be matched 1:1 with
465 * EndPage() and within a BeginDocument()/EndDocument() pair.
466 * @return error status
468 NS_IMETHOD
BeginPage(void) = 0;
471 * Inform the output device that output of a page is ending
472 * Used for print related device contexts. Must be matched 1:1 with
473 * BeginPage() and within a BeginDocument()/EndDocument() pair.
474 * @return error status
476 NS_IMETHOD
EndPage(void) = 0;
479 * Clear cached system fonts (refresh from theme when
480 * requested). This method is effectively static,
481 * and can be called on a new DeviceContext instance
482 * without any initialization. Only really used by
483 * Gtk native theme stuff.
485 NS_IMETHOD
ClearCachedSystemFonts() = 0;
488 * Check to see if the DPI has changed
489 * @return whether there was actually a change in the DPI
490 * (whether AppUnitsPerDevPixel() or AppUnitsPerInch() changed)
492 virtual PRBool
CheckDPIChange() = 0;
495 * Set the pixel scaling factor: all lengths are multiplied by this factor
496 * when we convert them to device pixels. Returns whether the ratio of
497 * app units to dev pixels changed because of the scale factor.
499 virtual PRBool
SetPixelScale(float aScale
) = 0;
502 * Get the pixel scaling factor; defaults to 1.0, but can be changed with
505 float GetPixelScale() const { return mPixelScale
; }
508 * Get the unscaled ratio of app units to dev pixels; useful if something
509 * needs to be converted from to unscaled pixels
511 PRInt32
UnscaledAppUnitsPerDevPixel() const { return mAppUnitsPerDevNotScaledPixel
; }
514 PRInt32 mAppUnitsPerDevPixel
;
515 PRInt32 mAppUnitsPerInch
;
516 PRInt32 mAppUnitsPerDevNotScaledPixel
;
520 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContext
, NS_IDEVICE_CONTEXT_IID
)
522 #endif /* nsIDeviceContext_h___ */