Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Friends
nsRenderingContextWin Class Reference

#include <nsRenderingContextWin.h>

Inheritance diagram for nsRenderingContextWin:
Inheritance graph
[legend]
Collaboration diagram for nsRenderingContextWin:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsRenderingContextWin ()
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS NS_IMETHOD 
Init (nsIDeviceContext *aContext, nsIWidget *aWindow)
 Initialize the RenderingContext.
NS_IMETHOD Init (nsIDeviceContext *aContext, nsIDrawingSurface *aSurface)
 Initialize the RenderingContext.
NS_IMETHOD Reset (void)
 Reset the rendering context.
NS_IMETHOD GetDeviceContext (nsIDeviceContext *&aContext)
 Get the DeviceContext that this RenderingContext was initialized with.
NS_IMETHOD LockDrawingSurface (PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, PRUint32 aFlags)
 Lock a rect of the drawing surface associated with the rendering context.
NS_IMETHOD UnlockDrawingSurface (void)
 Unlock a rect of the drawing surface associated with the rendering context.
NS_IMETHOD SelectOffScreenDrawingSurface (nsIDrawingSurface *aSurface)
 Selects an offscreen drawing surface into the RenderingContext to draw to.
NS_IMETHOD GetDrawingSurface (nsIDrawingSurface **aSurface)
 Get the currently selected drawing surface.
NS_IMETHOD GetHints (PRUint32 &aResult)
 Returns in aResult any rendering hints that the context has.
NS_IMETHOD PushState (void)
 Save a graphical state onto a stack.
NS_IMETHOD PopState (void)
 Get and and set RenderingContext to this graphical state.
NS_IMETHOD IsVisibleRect (const nsRect &aRect, PRBool &aClipState)
 Tells if a given rectangle is visible within the rendering context.
NS_IMETHOD SetClipRect (const nsRect &aRect, nsClipCombine aCombine)
 Sets the clipping for the RenderingContext to the passed in rectangle.
NS_IMETHOD GetClipRect (nsRect &aRect, PRBool &aClipState)
 Gets the bounds of the clip region of the RenderingContext.
NS_IMETHOD SetClipRegion (const nsIRegion &aRegion, nsClipCombine aCombine)
 Sets the clipping for the RenderingContext to the passed in region.
NS_IMETHOD CopyClipRegion (nsIRegion &aRegion)
 Fills in |aRegion| with a copy of the current clip region.
NS_IMETHOD GetClipRegion (nsIRegion **aRegion)
 Gets the current clipping region for the RenderingContext The region is in device coordinates!
NS_IMETHOD SetLineStyle (nsLineStyle aLineStyle)
 Sets the line style for the RenderingContext.
NS_IMETHOD GetLineStyle (nsLineStyle &aLineStyle)
 Gets the line style for the RenderingContext.
NS_IMETHOD SetColor (nscolor aColor)
 Sets the forground color for the RenderingContext.
NS_IMETHOD GetColor (nscolor &aColor) const
 Get the forground color for the RenderingContext.
NS_IMETHOD SetFont (const nsFont &aFont, nsIAtom *aLangGroup)
 Sets the font for the RenderingContext.
NS_IMETHOD SetFont (nsIFontMetrics *aFontMetrics)
 Sets the font for the RenderingContext.
NS_IMETHOD GetFontMetrics (nsIFontMetrics *&aFontMetrics)
 Get the current fontmetrics for the RenderingContext.
NS_IMETHOD Translate (nscoord aX, nscoord aY)
 Add in a translate to the RenderingContext's transformation matrix.
NS_IMETHOD Scale (float aSx, float aSy)
 Add in a scale to the RenderingContext's transformation matrix.
NS_IMETHOD GetCurrentTransform (nsTransform2D *&aTransform)
 Get the current transformation matrix for the RenderingContext.
NS_IMETHOD CreateDrawingSurface (const nsRect &aBounds, PRUint32 aSurfFlags, nsIDrawingSurface *&aSurface)
 Create an offscreen drawing surface compatible with this RenderingContext.
NS_IMETHOD DestroyDrawingSurface (nsIDrawingSurface *aDS)
 Destroy a drawing surface created by CreateDrawingSurface()
NS_IMETHOD DrawLine (nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1)
 Draw a line.
NS_IMETHOD DrawPolyline (const nsPoint aPoints[], PRInt32 aNumPoints)
 Draw a polyline.
NS_IMETHOD DrawRect (const nsRect &aRect)
 Draw a rectangle.
NS_IMETHOD DrawRect (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
 Draw a rectangle.
NS_IMETHOD FillRect (const nsRect &aRect)
 Fill a rectangle in the current foreground color.
NS_IMETHOD FillRect (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
 Fill a rectangle in the current foreground color.
NS_IMETHOD InvertRect (const nsRect &aRect)
 XOR Invert a rectangle in the current foreground color.
NS_IMETHOD InvertRect (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
 XOR Invert a rectangle in the current foreground color.
NS_IMETHOD DrawPolygon (const nsPoint aPoints[], PRInt32 aNumPoints)
 Draw a poly in the current foreground color.
NS_IMETHOD FillPolygon (const nsPoint aPoints[], PRInt32 aNumPoints)
 Fill a poly in the current foreground color.
NS_IMETHOD SetPenMode (nsPenMode aPenMode)
 Sets the Pen Mode for the RenderingContext.
NS_IMETHOD GetPenMode (nsPenMode &aPenMode)
 Gets the Pen Mode for the RenderingContext.
NS_IMETHOD DrawEllipse (const nsRect &aRect)
 Draw an ellipse in the current foreground color.
NS_IMETHOD DrawEllipse (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
 Draw an ellipse in the current foreground color.
NS_IMETHOD FillEllipse (const nsRect &aRect)
 Fill an ellipse in the current foreground color.
NS_IMETHOD FillEllipse (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
 Fill an ellipse in the current foreground color.
NS_IMETHOD DrawArc (const nsRect &aRect, float aStartAngle, float aEndAngle)
 Draw an arc in the current forground color.
NS_IMETHOD DrawArc (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, float aStartAngle, float aEndAngle)
 Draw an arc in the current forground color.
NS_IMETHOD FillArc (const nsRect &aRect, float aStartAngle, float aEndAngle)
 Fill an arc in the current forground color.
NS_IMETHOD FillArc (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, float aStartAngle, float aEndAngle)
 Fill an arc in the current forground color.
NS_IMETHOD GetWidth (const nsString &aString, nscoord &aWidth, PRInt32 *aFontID=nsnull)
 Returns the width (in app units) of an nsString If no font has been Set, the results are undefined.
NS_IMETHOD GetWidth (const char *aString, nscoord &aWidth)
 Returns the width (in app units) of an 8-bit character string If no font has been Set, the results are undefined.
NS_IMETHOD GetWidth (const char *aString, PRUint32 aLength, nscoord &aWidth)
 Returns the width (in app units) of an 8-bit character string If no font has been Set, the results are undefined.
NS_IMETHOD GetWidth (const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID=nsnull)
 Returns the width (in app units) of a Unicode character string If no font has been Set, the results are undefined.
NS_IMETHOD DrawString (const nsString &aString, nscoord aX, nscoord aY, PRInt32 aFontID=-1, const nscoord *aSpacing=nsnull)
 Draw a string in the RenderingContext.
NS_IMETHOD GetWidth (char aC, nscoord &aWidth)
 Returns the width (in app units) of an 8-bit character If no font has been Set, the results are undefined.
NS_IMETHOD GetWidth (PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID)
 Returns the width (in app units) of a unicode character If no font has been Set, the results are undefined.
NS_IMETHOD GetWidthInternal (const char *aString, PRUint32 aLength, nscoord &aWidth)
NS_IMETHOD GetWidthInternal (const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID)
NS_IMETHOD DrawStringInternal (const char *aString, PRUint32 aLength, nscoord aX, nscoord aY, const nscoord *aSpacing)
NS_IMETHOD DrawStringInternal (const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord *aSpacing)
NS_IMETHOD GetTextDimensionsInternal (const char *aString, PRUint32 aLength, nsTextDimensions &aDimensions)
NS_IMETHOD GetTextDimensionsInternal (const PRUnichar *aString, PRUint32 aLength, nsTextDimensions &aDimensions, PRInt32 *aFontID)
NS_IMETHOD GetTextDimensionsInternal (const char *aString, PRInt32 aLength, PRInt32 aAvailWidth, PRInt32 *aBreaks, PRInt32 aNumBreaks, nsTextDimensions &aDimensions, PRInt32 &aNumCharsFit, nsTextDimensions &aLastWordDimensions, PRInt32 *aFontID)
NS_IMETHOD GetTextDimensionsInternal (const PRUnichar *aString, PRInt32 aLength, PRInt32 aAvailWidth, PRInt32 *aBreaks, PRInt32 aNumBreaks, nsTextDimensions &aDimensions, PRInt32 &aNumCharsFit, nsTextDimensions &aLastWordDimensions, PRInt32 *aFontID)
virtual PRInt32 GetMaxStringLength ()
 Return the maximum length of a string that can be handled by the platform using the current font metrics.
NS_IMETHOD CopyOffScreenBits (nsIDrawingSurface *aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, const nsRect &aDestBounds, PRUint32 aCopyFlags)
 Copy offscreen pixelmap to this RenderingContext.
NS_IMETHOD RetrieveCurrentNativeGraphicData (void **ngd)
NS_IMETHOD CreateDrawingSurface (HDC aDC, nsIDrawingSurface *&aSurface)
 Create a new drawing surface to represent an HDC.
NS_IMETHOD GetBackbuffer (const nsRect &aRequestedSize, const nsRect &aMaxSize, PRBool aForBlending, nsIDrawingSurface *&aBackbuffer)
 Get a drawing surface used as a backbuffer.
NS_IMETHOD ReleaseBackbuffer (void)
 Release a drawing surface used as the backbuffer If the platform caches the backbuffer this call will destroy it.
NS_IMETHOD SetRightToLeftText (PRBool aIsRTL)
 Let the device context know whether we want text reordered with right-to-left base direction.
NS_IMETHOD GetRightToLeftText (PRBool *aIsRTL)
NS_IMETHOD FlushRect (const nsRect &aRect)
 For platforms (e.g., Cocoa) that implicitly double buffer, this call can be used to force a buffer flush following the painting of a rectangle.
NS_IMETHOD FlushRect (nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
NS_IMETHOD DestroyCachedBackbuffer (void)
 Destroy the drawing surface used as the backbuffer.
NS_IMETHOD UseBackbuffer (PRBool *aUseBackbuffer)
 Some platforms may not want a backbuffer at all.
NS_IMETHOD PushTranslation (PushedTranslation *aState)
NS_IMETHOD PopTranslation (PushedTranslation *aState)
NS_IMETHOD DrawImage (imgIContainer *aImage, const nsRect &aSrcRect, const nsRect &aDestRect)
 Draw a portion of an image, scaling it to fit within a specified rect.
NS_IMETHOD DrawTile (imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect *aTargetRect)
NS_IMETHOD GetClusterInfo (const PRUnichar *aText, PRUint32 aLength, PRUint8 *aClusterStarts)
 Get cluster details for a chunk of text.
virtual PRInt32 GetPosition (const PRUnichar *aText, PRUint32 aLength, nsPoint aPt)
 Find the closest cursor position for a given x coordinate.
NS_IMETHOD GetRangeWidth (const PRUnichar *aText, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd, PRUint32 &aWidth)
 Get the width for the specific range of a given string.
NS_IMETHOD GetRangeWidth (const char *aText, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd, PRUint32 &aWidth)
 Get the width for the specific range of a given string.
NS_IMETHOD DrawString (const char *aString, PRUint32 aLength, nscoord aX, nscoord aY, const nscoord *aSpacing=nsnull)
 Draw a string in the RenderingContext.
NS_IMETHOD DrawString (const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID=-1, const nscoord *aSpacing=nsnull)
 Draw a string in the RenderingContext.
NS_IMETHOD GetTextDimensions (const char *aString, PRUint32 aLength, nsTextDimensions &aDimensions)
 Returns the dimensions of a string, i.e., the overall extent of a string whose rendering may involve switching between different fonts that have different metrics.
NS_IMETHOD GetTextDimensions (const PRUnichar *aString, PRUint32 aLength, nsTextDimensions &aDimensions, PRInt32 *aFontID=nsnull)
NS_IMETHOD RenderEPS (const nsRect &aRect, FILE *aDataFile)
 Render an encapsulated postscript object onto the current rendering surface.

Protected Member Functions

void SetupFontAndColor (void)
 ~nsRenderingContextWin ()
PRBool RectFitsInside (const nsRect &aRect, PRInt32 aWidth, PRInt32 aHeight) const
 Determine if a rect's width and height will fit within a specified width and height.
PRBool BothRectsFitInside (const nsRect &aRect1, const nsRect &aRect2, PRInt32 aWidth, PRInt32 aHeight, nsRect &aNewSize) const
 Determine if two rectangles width and height will fit within a specified width and height.
void CalculateDiscreteSurfaceSize (const nsRect &aMaxBackbufferSize, const nsRect &aRequestedSize, nsRect &aSize)
 Return an offscreen surface size from a set of discrete surface sizes.
void GetDrawingSurfaceSize (const nsRect &aMaxBackbufferSize, const nsRect &aRequestedSize, nsRect &aSurfaceSize)
 Get the size of the offscreen drawing surface.
nsresult AllocateBackbuffer (const nsRect &aRequestedSize, const nsRect &aMaxSize, nsIDrawingSurface *&aBackbuffer, PRBool aCacheBackbuffer, PRUint32 aSurfFlags)
 Utility method used to implement NS_IMETHOD GetBackbuffer.

Protected Attributes

nscolor mCurrentColor
nsIFontMetricsmFontMetrics
HDC mDC
HDC mMainDC
nsDrawingSurfaceWinmSurface
nsDrawingSurfaceWinmMainSurface
COLORREF mColor
nsIWidgetmDCOwner
nsIDeviceContextmContext
float mP2T
HRGN mClipRegion
HBRUSH mOrigSolidBrush
HFONT mOrigFont
HPEN mOrigSolidPen
HPALETTE mOrigPalette
GraphicsStatemStates
nsVoidArraymStateCache
nscolor mCurrBrushColor
HBRUSH mCurrBrush
nsFontWinmCurrFontWin
HFONT mCurrFont
nscolor mCurrPenColor
HPEN mCurrPen
HPEN mNullPen
PRUint8mGammaTable
nscolor mCurrTextColor
nsLineStyle mCurrLineStyle
PRPackedBool mRightToLeftText
nsTransform2D * mTranMatrix
int mAct
EdgemActive
nsPenMode mPenMode

Private Member Functions

void ConditionRect (nsRect &aSrcRect, RECT &aDestRect)
 ConditionRect is used to fix a coordinate overflow problem under WIN95/WIN98.
nsresult CommonInit (void)
nsresult SetupDC (HDC aOldDC, HDC aNewDC)
HBRUSH SetupSolidBrush (void)
HPEN SetupPen (void)
HPEN SetupSolidPen (void)
HPEN SetupDashedPen (void)
HPEN SetupDottedPen (void)
void PushClipState (void)
void InitBidiInfo (void)
 Init gBidiInfo with reordering and shaping capabilities of the system.

Friends

class nsNativeThemeWin

Detailed Description

Definition at line 63 of file nsRenderingContextWin.h.


Constructor & Destructor Documentation

Definition at line 179 of file nsRenderingContextWin.cpp.

{
#ifdef WINCE
  gIsWIN95 = PR_FALSE;
  gBidiInfo = DONT_INIT;
#else
  // The first time in we initialize gIsWIN95 flag
  if (NOT_SETUP == gIsWIN95) {
    OSVERSIONINFO os;
    os.dwOSVersionInfoSize = sizeof(os);
    ::GetVersionEx(&os);
    // gIsWIN95 must be true for Win98 and WinME too
    if (VER_PLATFORM_WIN32_NT == os.dwPlatformId) {
      gIsWIN95 = PR_FALSE;
    }
    else {
      gIsWIN95 = PR_TRUE;

      if ( (os.dwMajorVersion < 4)
           || ( (os.dwMajorVersion == 4) && (os.dwMinorVersion == 0) ) ) {
        // Windows 95 or earlier: assume it's not Bidi
        gBidiInfo = DONT_INIT;
      }
      else if (os.dwMajorVersion >= 4) {
        // Windows 98 or later
        UINT cp = ::GetACP();
        if (1256 == cp) {
          gBidiInfo = GCP_REORDER | GCP_GLYPHSHAPE;
        }
        else if (1255 == cp) {
          gBidiInfo = GCP_REORDER;
        }
      }
    }
  }
#endif

  mDC = NULL;
  mMainDC = NULL;
  mDCOwner = nsnull;
  mFontMetrics = nsnull;
  mOrigSolidBrush = NULL;
  mOrigFont = NULL;
  mOrigSolidPen = NULL;
  mCurrBrushColor = RGB(255, 255, 255);
  mCurrFontWin = nsnull;
  mCurrPenColor = NULL;
  mCurrPen = NULL;
  mNullPen = NULL;
  mCurrTextColor = RGB(0, 0, 0);
  mCurrLineStyle = nsLineStyle_kSolid;
#ifdef NS_DEBUG
  mInitialized = PR_FALSE;
#endif
  mSurface = nsnull;
  mMainSurface = nsnull;

  mStateCache = new nsVoidArray();
  mRightToLeftText = PR_FALSE;

  //create an initial GraphicsState

  PushState();

  mP2T = 1.0f;
}

Here is the call graph for this function:

Definition at line 246 of file nsRenderingContextWin.cpp.

{
  NS_IF_RELEASE(mContext);
  NS_IF_RELEASE(mFontMetrics);

  //destroy the initial GraphicsState

  PopState();

  //cleanup the DC so that we can just destroy objects
  //in the graphics state without worrying that we are
  //ruining the dc

  if (NULL != mDC)
  {
    if (NULL != mOrigSolidBrush)
    {
      ::SelectObject(mDC, mOrigSolidBrush);
      mOrigSolidBrush = NULL;
    }

    if (NULL != mOrigFont)
    {
      ::SelectObject(mDC, mOrigFont);
      mOrigFont = NULL;
    }

    if (NULL != mOrigSolidPen)
    {
      ::SelectObject(mDC, mOrigSolidPen);
      mOrigSolidPen = NULL;
    }
  }

  mCurrBrush = NULL;   // don't delete - owned by brush cache

  //don't kill the font because the font cache/metrics owns it
  mCurrFont = NULL;

  if (mCurrPen && (mCurrPen != gStockBlackPen) && (mCurrPen != gStockWhitePen)) {
    VERIFY(::DeleteObject(mCurrPen));
  }

  if ((NULL != mNullPen) && (mNullPen != mCurrPen)) {
    VERIFY(::DeleteObject(mNullPen));
  }

  mCurrPen = NULL;
  mNullPen = NULL;

  if (nsnull != mStateCache)
  {
    PRInt32 cnt = mStateCache->Count();

    while (--cnt >= 0)
    {
      GraphicsState *state = (GraphicsState *)mStateCache->ElementAt(cnt);
      mStateCache->RemoveElementAt(cnt);

      if (nsnull != state)
        delete state;
    }

    delete mStateCache;
    mStateCache = nsnull;
  }

  if (nsnull != mSurface)
  {
    mSurface->ReleaseDC();
    NS_RELEASE(mSurface);
  }

  if (nsnull != mMainSurface)
  {
    mMainSurface->ReleaseDC();
    NS_RELEASE(mMainSurface);
  }

  if (nsnull != mDCOwner)
  {
    ::ReleaseDC((HWND)mDCOwner->GetNativeData(NS_NATIVE_WINDOW), mMainDC);
    NS_RELEASE(mDCOwner);
  }

  mTranMatrix = nsnull;
  mDC = NULL;
  mMainDC = NULL;
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsRenderingContextImpl::AllocateBackbuffer ( const nsRect aRequestedSize,
const nsRect aMaxSize,
nsIDrawingSurface *&  aBackbuffer,
PRBool  aCacheBackbuffer,
PRUint32  aSurfFlags 
) [protected, inherited]

Utility method used to implement NS_IMETHOD GetBackbuffer.

Parameters:
aRequestedSizesize of the backbuffer area requested
aMaxSizemaximum size that may be requested for the backbuffer
aBackbufferdrawing surface used as the backbuffer
aCacheBackbufferPR_TRUE then the backbuffer will be cached, if PR_FALSE it is created each time
aSurfFlagsflags passed to CreateDrawingSurface()

Definition at line 86 of file nsRenderingContextImpl.cpp.

{
  nsRect newBounds;
  nsresult rv = NS_OK;

   if (! aCacheBackbuffer) {
    newBounds = aRequestedSize;
  } else {
    GetDrawingSurfaceSize(aMaxSize, aRequestedSize, newBounds);
  }

  if ((nsnull == gBackbuffer)
      || (gBackbufferBounds.width != newBounds.width)
      || (gBackbufferBounds.height != newBounds.height))
    {
      if (gBackbuffer) {
        //destroy existing DS
        DestroyDrawingSurface(gBackbuffer);
        gBackbuffer = nsnull;
      }

      rv = CreateDrawingSurface(newBounds, aSurfFlags, gBackbuffer);
      //   printf("Allocating a new drawing surface %d %d\n", newBounds.width, newBounds.height);
      if (NS_SUCCEEDED(rv)) {
        gBackbufferBounds = newBounds;
        SelectOffScreenDrawingSurface(gBackbuffer);
      } else {
        gBackbufferBounds.SetRect(0,0,0,0);
        gBackbuffer = nsnull;
      }
    } else {
      SelectOffScreenDrawingSurface(gBackbuffer);

      float p2t;
      nsCOMPtr<nsIDeviceContext>  dx;
      GetDeviceContext(*getter_AddRefs(dx));
      p2t = dx->DevUnitsToAppUnits();
      nsRect bounds = aRequestedSize;
      bounds *= p2t;

      SetClipRect(bounds, nsClipCombine_kReplace);
    }

  aBackbuffer = gBackbuffer;
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsRenderingContextImpl::BothRectsFitInside ( const nsRect aRect1,
const nsRect aRect2,
PRInt32  aWidth,
PRInt32  aHeight,
nsRect aNewSize 
) const [protected, inherited]

Determine if two rectangles width and height will fit within a specified width and height.

Parameters:
aRect1first rectangle to test
aRect1second rectangle to test
aWidthwidth to determine if both rectangle's width will fit within
aHeightheight to determine if both rectangles height will fit within
Returns:
PR_TRUE if the rect1's and rect2's width and height fits with aWidth, aHeight, PR_FALSE otherwise.

Definition at line 199 of file nsRenderingContextImpl.cpp.

{
  if (PR_FALSE == RectFitsInside(aRect1, aWidth, aHeight)) {
    return PR_FALSE;
  }

  if (PR_FALSE == RectFitsInside(aRect2, aWidth, aHeight)) {
    return PR_FALSE;
  }

  aNewSize.width = aWidth;
  aNewSize.height = aHeight;

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRenderingContextImpl::CalculateDiscreteSurfaceSize ( const nsRect aMaxBackbufferSize,
const nsRect aRequestedSize,
nsRect aSize 
) [protected, inherited]

Return an offscreen surface size from a set of discrete surface sizes.

The smallest discrete surface size that can enclose both the Maximum widget size (

See also:
GetMaxWidgetBounds) and the requested size is returned.
Parameters:
aMaxBackbufferSizeMaximum size that may be requested for the backbuffer
aRequestedSizeRequested size for the offscreen.
aSurfaceSizecontains the surface size

Definition at line 221 of file nsRenderingContextImpl.cpp.

{
  // Get the height and width of the screen
  PRInt32 height;
  PRInt32 width;

  nsCOMPtr<nsIDeviceContext>  dx;
  GetDeviceContext(*getter_AddRefs(dx));
  dx->GetDeviceSurfaceDimensions(width, height);

  float devUnits;
  devUnits = dx->DevUnitsToAppUnits();
  PRInt32 screenHeight = NSToIntRound(float( height) / devUnits );
  PRInt32 screenWidth = NSToIntRound(float( width) / devUnits );

  // These tests must go from smallest rectangle to largest rectangle.

  // 1/8 screen
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, screenWidth / 8, screenHeight / 8, aSurfaceSize)) {
    return;
  }

  // 1/4 screen
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, screenWidth / 4, screenHeight / 4, aSurfaceSize)) {
    return;
  }

  // 1/2 screen
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, screenWidth / 2, screenHeight / 2, aSurfaceSize)) {
    return;
  }

  // 3/4 screen
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, (screenWidth * 3) / 4, (screenHeight * 3) / 4, aSurfaceSize)) {
    return;
  }

  // 3/4 screen width full screen height
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, (screenWidth * 3) / 4, screenHeight, aSurfaceSize)) {
    return;
  }

  // Full screen
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, screenWidth, screenHeight, aSurfaceSize)) {
    return;
  }

  // Bigger than Full Screen use the largest request every made.
  if (BothRectsFitInside(aRequestedSize, aMaxBackbufferSize, gLargestRequestedSize.width, gLargestRequestedSize.height, aSurfaceSize)) {
    return;
  } else {
    gLargestRequestedSize.width = PR_MAX(aRequestedSize.width, aMaxBackbufferSize.width);
    gLargestRequestedSize.height = PR_MAX(aRequestedSize.height, aMaxBackbufferSize.height);
    aSurfaceSize.width = gLargestRequestedSize.width;
    aSurfaceSize.height = gLargestRequestedSize.height;
    //   printf("Expanding the largested requested size to %d %d\n", gLargestRequestedSize.width, gLargestRequestedSize.height);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 501 of file nsRenderingContextWin.cpp.

{
  float app2dev;

  app2dev = mContext->AppUnitsToDevUnits();
       mTranMatrix->AddScale(app2dev, app2dev);
  mP2T = mContext->DevUnitsToAppUnits();

#ifdef NS_DEBUG
  mInitialized = PR_TRUE;
#endif

  return SetupDC(nsnull, mDC);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRenderingContextWin::ConditionRect ( nsRect aSrcRect,
RECT &  aDestRect 
) [private]

ConditionRect is used to fix a coordinate overflow problem under WIN95/WIN98.

Some operations fail for rectangles whose coordinates have very large absolute values. Since these values are (hopefully) off the screen, they can be truncated to reasonable ones.

Parameters:
aSrcRectinput rectangle
aDestRectoutput rectangle, same as input except with large coordinates changed so they are acceptable to WIN95/WIN98

Definition at line 2834 of file nsRenderingContextWin.cpp.

{
  // There is no limit in NT class Windows versions (this includes W2K and XP)
  if (!gIsWIN95)
  {
    aDestRect.top = aSrcRect.y;
    aDestRect.bottom = aSrcRect.y + aSrcRect.height;
    aDestRect.left = aSrcRect.x;
    aDestRect.right = aSrcRect.x + aSrcRect.width;
    return;
  }

  // The following is for WIN95, WIN98 and WINME
  const nscoord kBottomRightLimit = 16384;
  const nscoord kTopLeftLimit = -8192;

  aDestRect.top = (aSrcRect.y < kTopLeftLimit)
                      ? kTopLeftLimit
                      : aSrcRect.y;
  aDestRect.bottom = ((aSrcRect.y + aSrcRect.height) > kBottomRightLimit)
                      ? kBottomRightLimit
                      : (aSrcRect.y + aSrcRect.height);
  aDestRect.left = (aSrcRect.x < kTopLeftLimit)
                      ? kTopLeftLimit
                      : aSrcRect.x;
  aDestRect.right = ((aSrcRect.x + aSrcRect.width) > kBottomRightLimit)
                      ? kBottomRightLimit
                      : (aSrcRect.x + aSrcRect.width);
}

Here is the caller graph for this function:

Fills in |aRegion| with a copy of the current clip region.

Implements nsIRenderingContext.

Definition at line 905 of file nsRenderingContextWin.cpp.

{
  int rstat = ::GetClipRgn(mDC, ((nsRegionWin *)&aRegion)->mRegion);

  if (rstat == 1)
  {
    //i can't find a way to get the actual complexity
    //of the region without actually messing with it, so
    //if the region is non-empty, we'll call it complex. MMP

    ((nsRegionWin *)&aRegion)->mRegionType = eRegionComplexity_complex;
  }
 
  return NS_OK;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsRenderingContextWin::CopyOffScreenBits ( nsIDrawingSurface aSrcSurf,
PRInt32  aSrcX,
PRInt32  aSrcY,
const nsRect aDestBounds,
PRUint32  aCopyFlags 
) [virtual]

Copy offscreen pixelmap to this RenderingContext.

Parameters:
aSrcSurfdrawing surface to copy bits from
aSrcXx offset into source pixelmap to copy from
aSrcYy offset into source pixelmap to copy from
aDestBoundsDestination rectangle to copy to
aCopyFlagssee below

Implements nsIRenderingContext.

Definition at line 2431 of file nsRenderingContextWin.cpp.

{

  if ((nsnull != aSrcSurf) && (nsnull != mMainDC))
  {
    PRInt32 x = aSrcX;
    PRInt32 y = aSrcY;
    nsRect  drect = aDestBounds;
    HDC     destdc, srcdc;

    //get back a DC

    ((nsDrawingSurfaceWin *)aSrcSurf)->GetDC(&srcdc);

    if (nsnull != srcdc)
    {
      if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER)
      {
        NS_ASSERTION(!(nsnull == mDC), "no back buffer");
        destdc = mDC;
      }
      else
        destdc = mMainDC;

      if (aCopyFlags & NS_COPYBITS_USE_SOURCE_CLIP_REGION)
      {
        HRGN  tregion = ::CreateRectRgn(0, 0, 0, 0);

        if (::GetClipRgn(srcdc, tregion) == 1)
          ::SelectClipRgn(destdc, tregion);

        ::DeleteObject(tregion);
      }

      // If there's a palette make sure it's selected.
      // XXX This doesn't seem like the best place to be doing this...

      nsPaletteInfo palInfo;

      mContext->GetPaletteInfo(palInfo);

      if (palInfo.isPaletteDevice && palInfo.palette){
        ::SelectPalette(destdc, (HPALETTE)palInfo.palette, PR_TRUE);
        // this is called to many times here.. taking this out because it breaks
        // embedding.. its like fighting palettes.  All the palette stuff should
        // be taken out.. but its so late in the beta cycle... I am taking the safe
        // road until I can get all this figured out.. and completed correctly.
        // Opened bug #153367 to take care of this palette issue.
        //::RealizePalette(destdc);
#ifndef WINCE
        ::UpdateColors(mDC);                                                      
#endif
      }

      if (aCopyFlags & NS_COPYBITS_XFORM_SOURCE_VALUES)
        mTranMatrix->TransformCoord(&x, &y);

      if (aCopyFlags & NS_COPYBITS_XFORM_DEST_VALUES)
        mTranMatrix->TransformCoord(&drect.x, &drect.y, &drect.width, &drect.height);

      ::BitBlt(destdc, drect.x, drect.y,
               drect.width, drect.height,
               srcdc, x, y, SRCCOPY);


      //kill the DC
      ((nsDrawingSurfaceWin *)aSrcSurf)->ReleaseDC();
    }
    else
      NS_ASSERTION(0, "attempt to blit with bad DCs");
  }
  else
    NS_ASSERTION(0, "attempt to blit with bad DCs");

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::CreateDrawingSurface ( const nsRect aBounds,
PRUint32  aSurfFlags,
nsIDrawingSurface *&  aSurface 
) [virtual]

Create an offscreen drawing surface compatible with this RenderingContext.

The rect passed in is not affected by any transforms in the rendering context and the values are in device units.

Parameters:
aBoundsA rectangle representing the size for the drawing surface. if nsnull then a bitmap will not be created and associated with the new drawing surface
aSurfFlagssee bottom of nsIRenderingContext.h
Returns:
A nsIDrawingSurface*

Implements nsIRenderingContext.

Definition at line 1027 of file nsRenderingContextWin.cpp.

{
  nsDrawingSurfaceWin *surf = new nsDrawingSurfaceWin();

  if (nsnull != surf)
  {
    NS_ADDREF(surf);

    surf->Init(mMainDC, aBounds.width, aBounds.height, aSurfFlags);
  }

  aSurface = surf;

  return NS_OK;
}

Here is the call graph for this function:

Create a new drawing surface to represent an HDC.

Parameters:
aDCWindows HDC.
aSurfaceout parameter for new drawing surface
Returns:
error status

Implements nsIRenderingContextWin.

Definition at line 2805 of file nsRenderingContextWin.cpp.

{
  nsDrawingSurfaceWin *surf = new nsDrawingSurfaceWin();

  if (nsnull != surf)
  {
    NS_ADDREF(surf);
    surf->Init(aDC);
  }

  aSurface = surf;

  return NS_OK;
}

Here is the call graph for this function:

Destroy the drawing surface used as the backbuffer.

If the platform does not maintain a cached backbuffer this call will do nothing.

Implements nsIRenderingContext.

Definition at line 140 of file nsRenderingContextImpl.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Destroy a drawing surface created by CreateDrawingSurface()

Parameters:
aDSA drawing surface to destroy

Implements nsIRenderingContext.

Definition at line 1043 of file nsRenderingContextWin.cpp.

{
  nsDrawingSurfaceWin *surf = (nsDrawingSurfaceWin *)aDS;

  //are we using the surface that we want to kill?
  if (surf == mSurface)
  {
    //remove our local ref to the surface
    NS_IF_RELEASE(mSurface);

    mDC = mMainDC;
    mSurface = mMainSurface;

    //two pointers: two refs
    NS_IF_ADDREF(mSurface);
  }

  //release it...
  NS_IF_RELEASE(surf);

  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin::DrawArc ( const nsRect aRect,
float  aStartAngle,
float  aEndAngle 
) [virtual]

Draw an arc in the current forground color.

Parameters:
aRectThe rectangle define bounds of ellipse to use
aStartAnglethe starting angle of the arc, in degrees
aEndAngleThe ending angle of the arc, in degrees

Implements nsIRenderingContext.

Definition at line 1333 of file nsRenderingContextWin.cpp.

{
  return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle);
}
NS_IMETHODIMP nsRenderingContextWin::DrawArc ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight,
float  aStartAngle,
float  aEndAngle 
) [virtual]

Draw an arc in the current forground color.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of horizontal axis in twips
aHeightHeight of vertical axis in twips
aStartAnglethe starting angle of the arc, in degrees
aEndAngleThe ending angle of the arc, in degrees

Implements nsIRenderingContext.

Definition at line 1339 of file nsRenderingContextWin.cpp.

{
  if (nsLineStyle_kNone == mCurrLineStyle)
    return NS_OK;

  PRInt32 quad1, quad2, sx, sy, ex, ey, cx, cy;
  float   anglerad, distance;

  mTranMatrix->TransformCoord(&aX, &aY, &aWidth, &aHeight);

  SetupPen();
  SetupSolidBrush();

  // figure out the the coordinates of the arc from the angle
  distance = (float)sqrt((float)(aWidth * aWidth + aHeight * aHeight));
  cx = aX + aWidth / 2;
  cy = aY + aHeight / 2;

  anglerad = (float)(aStartAngle / (180.0 / 3.14159265358979323846));
  quad1 = (PRInt32)(aStartAngle / 90.0);
  sx = (PRInt32)(distance * cos(anglerad) + cx);
  sy = (PRInt32)(cy - distance * sin(anglerad));

  anglerad = (float)(aEndAngle / (180.0 / 3.14159265358979323846));
  quad2 = (PRInt32)(aEndAngle / 90.0);
  ex = (PRInt32)(distance * cos(anglerad) + cx);
  ey = (PRInt32)(cy - distance * sin(anglerad));

  // this just makes it consitent, on windows 95 arc will always draw CC, nt this sets direction
#ifndef WINCE
  ::SetArcDirection(mDC, AD_COUNTERCLOCKWISE);
#endif

  ::Arc(mDC, aX, aY, aX + aWidth, aY + aHeight, sx, sy, ex, ey); 

  return NS_OK;
}

Here is the call graph for this function:

Draw an ellipse in the current foreground color.

Parameters:
aRectThe rectangle define bounds of ellipse to draw

Implements nsIRenderingContext.

Definition at line 1294 of file nsRenderingContextWin.cpp.

{
  return DrawEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
}
NS_IMETHODIMP nsRenderingContextWin::DrawEllipse ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight 
) [virtual]

Draw an ellipse in the current foreground color.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of horizontal axis in twips
aHeightHeight of vertical axis in twips

Implements nsIRenderingContext.

Definition at line 1299 of file nsRenderingContextWin.cpp.

{
  if (nsLineStyle_kNone == mCurrLineStyle)
    return NS_OK;

  mTranMatrix->TransformCoord(&aX, &aY, &aWidth, &aHeight);

  SetupPen();

  HBRUSH oldBrush = (HBRUSH)::SelectObject(mDC, ::GetStockObject(NULL_BRUSH));
  
  ::Ellipse(mDC, aX, aY, aX + aWidth, aY + aHeight);
  ::SelectObject(mDC, oldBrush);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::DrawImage ( imgIContainer aImage,
const nsRect aSrcRect,
const nsRect aDestRect 
) [virtual, inherited]

Draw a portion of an image, scaling it to fit within a specified rect.

Parameters:
aImageThe image to draw
aSrcRectThe rect (in twips) of the image to draw. [x,y] denotes the top left corner of the region.
aDestRectThe device context rect (in twips) that the image portion should occupy. [x,y] denotes the top left corner. [height,width] denotes the desired image size.

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextGTK, nsRenderingContextPS, nsRenderingContextXlib, nsRenderingContextMac, and nsRenderingContextXp.

Definition at line 304 of file nsRenderingContextImpl.cpp.

{
  nsRect dr = aDestRect;
  mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);

  nsRect sr = aSrcRect;
  mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
  
  if (sr.IsEmpty() || dr.IsEmpty())
    return NS_OK;

  sr.x = aSrcRect.x;
  sr.y = aSrcRect.y;
  mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y);

  nsCOMPtr<gfxIImageFrame> iframe;
  aImage->GetCurrentFrame(getter_AddRefs(iframe));
  if (!iframe) return NS_ERROR_FAILURE;

  nsCOMPtr<nsIImage> img(do_GetInterface(iframe));
  if (!img) return NS_ERROR_FAILURE;

  nsIDrawingSurface *surface = nsnull;
  GetDrawingSurface(&surface);
  if (!surface) return NS_ERROR_FAILURE;

  // For Bug 87819
  // iframe may want image to start at different position, so adjust
  nsRect iframeRect;
  iframe->GetRect(iframeRect);
  
  if (iframeRect.x > 0) {
    // Adjust for the iframe offset before we do scaling.
    sr.x -= iframeRect.x;

    nscoord scaled_x = sr.x;
    if (dr.width != sr.width) {
      PRFloat64 scale_ratio = PRFloat64(dr.width) / PRFloat64(sr.width);
      scaled_x = NSToCoordRound(scaled_x * scale_ratio);
    }
    if (sr.x < 0) {
      dr.x -= scaled_x;
      sr.width += sr.x;
      dr.width += scaled_x;
      if (sr.width <= 0 || dr.width <= 0)
        return NS_OK;
      sr.x = 0;
    } else if (sr.x > iframeRect.width) {
      return NS_OK;
    }
  }

  if (iframeRect.y > 0) {
    // Adjust for the iframe offset before we do scaling.
    sr.y -= iframeRect.y;

    nscoord scaled_y = sr.y;
    if (dr.height != sr.height) {
      PRFloat64 scale_ratio = PRFloat64(dr.height) / PRFloat64(sr.height);
      scaled_y = NSToCoordRound(scaled_y * scale_ratio);
    }
    if (sr.y < 0) {
      dr.y -= scaled_y;
      sr.height += sr.y;
      dr.height += scaled_y;
      if (sr.height <= 0 || dr.height <= 0)
        return NS_OK;
      sr.y = 0;
    } else if (sr.y > iframeRect.height) {
      return NS_OK;
    }
  }

  // Multiple paint rects may have been coalesced into a bounding box, so
  // ensure that this rect is actually within the clip region before we draw.
  nsCOMPtr<nsIRegion> clipRegion;
  GetClipRegion(getter_AddRefs(clipRegion));
  if (clipRegion && !clipRegion->ContainsRect(dr.x, dr.y, dr.width, dr.height))
    return NS_OK;

  return img->Draw(*this, surface, sr.x, sr.y, sr.width, sr.height,
                   dr.x, dr.y, dr.width, dr.height);
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::DrawLine ( nscoord  aX0,
nscoord  aY0,
nscoord  aX1,
nscoord  aY1 
) [virtual]

Draw a line.

Parameters:
aXOstarting horiztonal coord in twips
aY0starting vertical coord in twips
aX1end horiztonal coord in twips
aY1end vertical coord in twips

Implements nsIRenderingContext.

Definition at line 1066 of file nsRenderingContextWin.cpp.

{
  if (nsLineStyle_kNone == mCurrLineStyle)
    return NS_OK;

       mTranMatrix->TransformCoord(&aX0,&aY0);
       mTranMatrix->TransformCoord(&aX1,&aY1);

  SetupPen();

#ifndef WINCE
  if (nsLineStyle_kDotted == mCurrLineStyle)
  {
    lineddastruct dda_struct;

    dda_struct.nDottedPixel = 1;
    dda_struct.dc = mDC;
    dda_struct.crColor = mColor;

    LineDDA((int)(aX0),(int)(aY0),(int)(aX1),(int)(aY1),(LINEDDAPROC) LineDDAFunc,(long)&dda_struct);
  }
  else
#endif
  {
    ::MoveToEx(mDC, (int)(aX0), (int)(aY0), NULL);
    ::LineTo(mDC, (int)(aX1), (int)(aY1));
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::DrawPolygon ( const nsPoint  aPoints[],
PRInt32  aNumPoints 
) [virtual]

Draw a poly in the current foreground color.

Parameters:
aPointspoints to use for the drawing, last must equal first
aNumPontsnumber of points in the polygon

Implements nsIRenderingContext.

Definition at line 1222 of file nsRenderingContextWin.cpp.

{
  // First transform nsPoint's into POINT's; perform coordinate space
  // transformation at the same time
  POINT pts[20];
  POINT* pp0 = pts;

  if (aNumPoints > 20)
    pp0 = new POINT[aNumPoints];

  POINT* pp = pp0;
  const nsPoint* np = &aPoints[0];

       for (PRInt32 i = 0; i < aNumPoints; i++, pp++, np++)
  {
              pp->x = np->x;
              pp->y = np->y;
              mTranMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
       }

  // Outline the polygon - note we are implicitly ignoring the linestyle here
  SetupSolidPen();
  HBRUSH oldBrush = (HBRUSH)::SelectObject(mDC, ::GetStockObject(NULL_BRUSH));
  ::Polygon(mDC, pp0, int(aNumPoints));
  ::SelectObject(mDC, oldBrush);

  // Release temporary storage if necessary
  if (pp0 != pts)
    delete [] pp0;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::DrawPolyline ( const nsPoint  aPoints[],
PRInt32  aNumPoints 
) [virtual]

Draw a polyline.

Parameters:
aPointsarray of endpoints
aNumPontsnumber of points

Implements nsIRenderingContext.

Definition at line 1098 of file nsRenderingContextWin.cpp.

{
  if (nsLineStyle_kNone == mCurrLineStyle)
    return NS_OK;

  // First transform nsPoint's into POINT's; perform coordinate space
  // transformation at the same time
  POINT pts[20];
  POINT* pp0 = pts;

  if (aNumPoints > 20)
    pp0 = new POINT[aNumPoints];

  POINT* pp = pp0;
  const nsPoint* np = &aPoints[0];

       for (PRInt32 i = 0; i < aNumPoints; i++, pp++, np++)
  {
              pp->x = np->x;
              pp->y = np->y;
              mTranMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
       }

  // Draw the polyline
  SetupPen();
  ::Polyline(mDC, pp0, int(aNumPoints));

  // Release temporary storage if necessary
  if (pp0 != pts)
    delete [] pp0;

  return NS_OK;
}

Here is the call graph for this function:

Draw a rectangle.

Parameters:
aRectThe rectangle to draw

Implements nsIRenderingContext.

Definition at line 1132 of file nsRenderingContextWin.cpp.

{
  RECT nr;
       nsRect tr;

       tr = aRect;
       mTranMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
       nr.left = tr.x;
       nr.top = tr.y;
       nr.right = tr.x+tr.width;
       nr.bottom = tr.y+tr.height;

  ::FrameRect(mDC, &nr, SetupSolidBrush());

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::DrawRect ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight 
) [virtual]

Draw a rectangle.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of rectangle in twips
aHeightHeight of rectangle in twips

Implements nsIRenderingContext.

Definition at line 1149 of file nsRenderingContextWin.cpp.

{
  RECT nr;

       mTranMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight);
       nr.left = aX;
       nr.top = aY;
       nr.right = aX+aWidth;
       nr.bottom = aY+aHeight;

  ::FrameRect(mDC, &nr, SetupSolidBrush());

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD nsRenderingContextWin::DrawString ( const nsString aString,
nscoord  aX,
nscoord  aY,
PRInt32  aFontID = -1,
const nscoord aSpacing = nsnull 
) [inline, virtual]

Draw a string in the RenderingContext.

Parameters:
aStringA nsString of the string
aXHorizontal starting point of baseline
aYVertical starting point of baseline.
aFontIDan optional parameter used to speed font selection for complex unicode strings. the value passed is returned by the DrawString() methods.
aSpacinginter-character spacing to apply

Reimplemented from nsRenderingContextImpl.

Definition at line 161 of file nsRenderingContextWin.h.

  { return nsRenderingContextImpl::DrawString(aString, aX, aY, aFontID, aSpacing); }
NS_IMETHODIMP nsRenderingContextImpl::DrawString ( const char *  aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
const nscoord aSpacing = nsnull 
) [virtual, inherited]

Draw a string in the RenderingContext.

Parameters:
aStringThe string to draw
aLengthThe length of the aString
aXHorizontal starting point of baseline
aYVertical starting point of baseline.
aSpacinginter-character spacing to apply

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextPh, nsRenderingContextQt, nsRenderingContextOS2, nsRenderingContextBeOS, nsRenderingContextXlib, and nsRenderingContextPS.

Definition at line 847 of file nsRenderingContextImpl.cpp.

{
  PRUint32 maxChunkLength = GetMaxChunkLength(this);
  while (aLength > 0) {
    PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
    nsresult rv = DrawStringInternal(aString, len, aX, aY);
    if (NS_FAILED(rv))
      return rv;
    aLength -= len;

    if (aLength > 0) {
      nscoord width;
      rv = GetWidthInternal(aString, len, width);
      if (NS_FAILED(rv))
        return rv;
      aX += width;
      aString += len;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::DrawString ( const PRUnichar aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
PRInt32  aFontID = -1,
const nscoord aSpacing = nsnull 
) [virtual, inherited]

Draw a string in the RenderingContext.

Parameters:
aStringA PRUnichar of the string
aLengthThe length of the aString
aXHorizontal starting point of baseline
aYVertical starting point of baseline.
aFontIDan optional parameter used to speed font selection for complex unicode strings. the value passed is returned by the DrawString() methods.
aSpacinginter-character spacing to apply

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextPh, nsRenderingContextQt, nsRenderingContextOS2, nsRenderingContextBeOS, nsRenderingContextXlib, and nsRenderingContextPS.

Definition at line 872 of file nsRenderingContextImpl.cpp.

{
  PRUint32 maxChunkLength = GetMaxChunkLength(this);
  if (aLength <= maxChunkLength) {
    return DrawStringInternal(aString, aLength, aX, aY, aFontID, aSpacing);
  }

  PRBool isRTL = PR_FALSE;
  GetRightToLeftText(&isRTL);

  if (isRTL) {
    nscoord totalWidth = 0;
    if (aSpacing) {
      for (PRUint32 i = 0; i < aLength; ++i) {
        totalWidth += aSpacing[i];
      }
    } else {
      nsresult rv = GetWidth(aString, aLength, totalWidth);
      if (NS_FAILED(rv))
        return rv;
    }
    aX += totalWidth;
  }
  
  while (aLength > 0) {
    PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
    nscoord width = 0;
    if (aSpacing) {
      for (PRInt32 i = 0; i < len; ++i) {
        width += aSpacing[i];
      }
    } else {
      nsresult rv = GetWidthInternal(aString, len, width);
      if (NS_FAILED(rv))
        return rv;
    }

    if (isRTL) {
      aX -= width;
    }
    nsresult rv = DrawStringInternal(aString, len, aX, aY, aFontID, aSpacing);
    if (NS_FAILED(rv))
      return rv;
    aLength -= len;
    if (!isRTL) {
      aX += width;
    }
    aString += len;
    if (aSpacing) {
      aSpacing += len;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::DrawStringInternal ( const char *  aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
const nscoord aSpacing 
)

Reimplemented from nsRenderingContextImpl.

Definition at line 2189 of file nsRenderingContextWin.cpp.

{
  NS_PRECONDITION(mFontMetrics,"Something is wrong somewhere");

  PRInt32 x = aX;
  PRInt32 y = aY;

  CheckLength(&aLength);
  SetupFontAndColor();

  INT dxMem[500];
  INT* dx0 = NULL;
  if (aSpacing) {
    dx0 = dxMem;
    if (aLength > 500) {
      dx0 = new INT[aLength];
    }
    mTranMatrix->ScaleXCoords(aSpacing, aLength, dx0);
  }
  mTranMatrix->TransformCoord(&x, &y);

  mCurrFontWin->DrawString(mDC, x, y, aString, aLength, dx0);

  if (dx0 && (dx0 != dxMem)) {
    delete [] dx0;
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::DrawStringInternal ( const PRUnichar aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
PRInt32  aFontID,
const nscoord aSpacing 
)

Reimplemented from nsRenderingContextImpl.

Definition at line 2288 of file nsRenderingContextWin.cpp.

{
  if (!mFontMetrics) return NS_ERROR_FAILURE;

  CheckLength(&aLength);
  SetupFontAndColor();

  nsFontMetricsWin* metrics = (nsFontMetricsWin*)mFontMetrics;
  DrawStringData data = {mDC, mCurrFont, mTranMatrix, 
    aX, aY, aSpacing, aLength, 0
  };
  if (!aSpacing) { // @see do_DrawString for the spacing case
    mTranMatrix->TransformCoord(&data.mX, &data.mY);
  }

  if (mRightToLeftText) {
    metrics->ResolveBackwards(mDC, aString, aLength, do_DrawString, &data);
  }
  else
  {
    metrics->ResolveForwards(mDC, aString, aLength, do_DrawString, &data);
  }

  if (mCurrFont != data.mFont) {
    // If the font was changed along the way, restore our font
    ::SelectObject(mDC, mCurrFont);
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::DrawTile ( imgIContainer aImage,
nscoord  aXOffset,
nscoord  aYOffset,
const nsRect aTargetRect 
) [virtual, inherited]

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextPS, nsRenderingContextMac, and nsRenderingContextXp.

Definition at line 390 of file nsRenderingContextImpl.cpp.

{
  nsRect dr(*aTargetRect);
  mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
  mTranMatrix->TransformCoord(&aXImageStart, &aYImageStart);

  // may have become empty due to transform shinking small number to 0
  if (dr.IsEmpty())
    return NS_OK;

  nscoord width, height;
  aImage->GetWidth(&width);
  aImage->GetHeight(&height);

  if (width == 0 || height == 0)
    return NS_OK;

  nscoord xOffset = (dr.x - aXImageStart) % width;
  nscoord yOffset = (dr.y - aYImageStart) % height;

  nsCOMPtr<gfxIImageFrame> iframe;
  aImage->GetCurrentFrame(getter_AddRefs(iframe));
  if (!iframe) return NS_ERROR_FAILURE;

  nsCOMPtr<nsIImage> img(do_GetInterface(iframe));
  if (!img) return NS_ERROR_FAILURE;

  nsIDrawingSurface *surface = nsnull;
  GetDrawingSurface(&surface);
  if (!surface) return NS_ERROR_FAILURE;

  /* bug 113561 - frame can be smaller than container */
  nsRect iframeRect;
  iframe->GetRect(iframeRect);
  PRInt32 padx = width - iframeRect.width;
  PRInt32 pady = height - iframeRect.height;

  return img->DrawTile(*this, surface,
                       xOffset - iframeRect.x, yOffset - iframeRect.y,
                       padx, pady,
                       dr);
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::FillArc ( const nsRect aRect,
float  aStartAngle,
float  aEndAngle 
) [virtual]

Fill an arc in the current forground color.

Parameters:
aRectThe rectangle define bounds of ellipse to use
aStartAnglethe starting angle of the arc, in degrees
aEndAngleThe ending angle of the arc, in degrees

Implements nsIRenderingContext.

Definition at line 1378 of file nsRenderingContextWin.cpp.

{
  return FillArc(aRect.x, aRect.y, aRect.width, aRect.height, aStartAngle, aEndAngle);
}
NS_IMETHODIMP nsRenderingContextWin::FillArc ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight,
float  aStartAngle,
float  aEndAngle 
) [virtual]

Fill an arc in the current forground color.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of horizontal axis in twips
aHeightHeight of vertical axis in twips
aStartAnglethe starting angle of the arc, in degrees
aEndAngleThe ending angle of the arc, in degrees

Implements nsIRenderingContext.

Definition at line 1384 of file nsRenderingContextWin.cpp.

{
  PRInt32 quad1, quad2, sx, sy, ex, ey, cx, cy;
  float   anglerad, distance;

  mTranMatrix->TransformCoord(&aX, &aY, &aWidth, &aHeight);

  SetupSolidPen();
  SetupSolidBrush();

  // figure out the the coordinates of the arc from the angle
  distance = (float)sqrt((float)(aWidth * aWidth + aHeight * aHeight));
  cx = aX + aWidth / 2;
  cy = aY + aHeight / 2;

  anglerad = (float)(aStartAngle / (180.0 / 3.14159265358979323846));
  quad1 = (PRInt32)(aStartAngle / 90.0);
  sx = (PRInt32)(distance * cos(anglerad) + cx);
  sy = (PRInt32)(cy - distance * sin(anglerad));

  anglerad = (float)(aEndAngle / (180.0 / 3.14159265358979323846));
  quad2 = (PRInt32)(aEndAngle / 90.0);
  ex = (PRInt32)(distance * cos(anglerad) + cx);
  ey = (PRInt32)(cy - distance * sin(anglerad));

  // this just makes it consistent, on windows 95 arc will always draw CC,
  // on NT this sets direction
#ifndef WINCE
  ::SetArcDirection(mDC, AD_COUNTERCLOCKWISE);
#endif
  ::Pie(mDC, aX, aY, aX + aWidth, aY + aHeight, sx, sy, ex, ey); 

  return NS_OK;
}

Here is the call graph for this function:

Fill an ellipse in the current foreground color.

Parameters:
aRectThe rectangle define bounds of ellipse to draw

Implements nsIRenderingContext.

Definition at line 1316 of file nsRenderingContextWin.cpp.

{
  return FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height);
}
NS_IMETHODIMP nsRenderingContextWin::FillEllipse ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight 
) [virtual]

Fill an ellipse in the current foreground color.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of horizontal axis in twips
aHeightHeight of vertical axis in twips

Implements nsIRenderingContext.

Definition at line 1321 of file nsRenderingContextWin.cpp.

{
  mTranMatrix->TransformCoord(&aX, &aY, &aWidth, &aHeight);

  SetupSolidPen();
  SetupSolidBrush();
  
  ::Ellipse(mDC, aX, aY, aX + aWidth, aY + aHeight);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::FillPolygon ( const nsPoint  aPoints[],
PRInt32  aNumPoints 
) [virtual]

Fill a poly in the current foreground color.

Parameters:
aPointspoints to use for the drawing, last must equal first
aNumPontsnumber of points in the polygon

Implements nsIRenderingContext.

Definition at line 1255 of file nsRenderingContextWin.cpp.

{
  // First transform nsPoint's into POINT's; perform coordinate space
  // transformation at the same time

  POINT pts[20];
  POINT* pp0 = pts;

  if (aNumPoints > 20)
    pp0 = new POINT[aNumPoints];

  POINT* pp = pp0;
  const nsPoint* np = &aPoints[0];

       for (PRInt32 i = 0; i < aNumPoints; i++, pp++, np++)
       {
              pp->x = np->x;
              pp->y = np->y;
              mTranMatrix->TransformCoord((int*)&pp->x,(int*)&pp->y);
       }

  // Fill the polygon
  SetupSolidBrush();

  if (NULL == mNullPen)
    mNullPen = ::CreatePen(PS_NULL, 0, 0);

  HPEN oldPen = (HPEN)::SelectObject(mDC, mNullPen);
  ::Polygon(mDC, pp0, int(aNumPoints));
  ::SelectObject(mDC, oldPen);

  // Release temporary storage if necessary
  if (pp0 != pts)
    delete [] pp0;

  return NS_OK;
}

Here is the call graph for this function:

Fill a rectangle in the current foreground color.

Parameters:
aRectThe rectangle to draw

Implements nsIRenderingContext.

Definition at line 1164 of file nsRenderingContextWin.cpp.

{
  RECT nr;
       nsRect tr;

       tr = aRect;
       mTranMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
  ConditionRect(tr, nr);
  ::FillRect(mDC, &nr, SetupSolidBrush());

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsRenderingContextWin::FillRect ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight 
) [virtual]

Fill a rectangle in the current foreground color.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of rectangle in twips
aHeightHeight of rectangle in twips

Implements nsIRenderingContext.

Definition at line 1177 of file nsRenderingContextWin.cpp.

{
  RECT nr;
       nsRect tr;

       mTranMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight);
       nr.left = aX;
       nr.top = aY;
       nr.right = aX+aWidth;
       nr.bottom = aY+aHeight;

  ::FillRect(mDC, &nr, SetupSolidBrush());

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::FlushRect ( const nsRect aRect) [virtual, inherited]

For platforms (e.g., Cocoa) that implicitly double buffer, this call can be used to force a buffer flush following the painting of a rectangle.

This call needs to be used any time drawing of rects is being done "on the fly", outside of the normal painting process. Examples include the blinking caret and tabbing through subimages in an image map.

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextMac.

Definition at line 436 of file nsRenderingContextImpl.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextImpl::FlushRect ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight 
) [virtual, inherited]

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextMac.

Definition at line 442 of file nsRenderingContextImpl.cpp.

{
    return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin::GetBackbuffer ( const nsRect aRequestedSize,
const nsRect aMaxSize,
PRBool  aForBlending,
nsIDrawingSurface *&  aBackbuffer 
) [virtual]

Get a drawing surface used as a backbuffer.

Depending on the platform this will either cause a backbuffer surface to be allocated or an existing cached backbuffer will be returned. If the backbuffer is being cached asking for aMaxSize which is different from a previous request may cause the platform to dump it's cached backbuffer and reallocate a backbuffer of a size which will allow aMaxSize buffer to be allocated.

Parameters:
aRequestedSizesize of the backbuffer area requested
aMaxSizemaximum size that may be requested for the backbuffer
aForBlendingparameter telling if the buffer will be used for blending
aBackbufferdrawing surface used as the backbuffer

Reimplemented from nsRenderingContextImpl.

Definition at line 2866 of file nsRenderingContextWin.cpp.

{
  // Do not cache the backbuffer. On WIN32 it is faster to get allocate
  // the backbuffer as needed. @see bug 95952
  return AllocateBackbuffer(aRequestedSize, aMaxSize, aBackbuffer, PR_FALSE, aForBlending ? NS_CREATEDRAWINGSURFACE_FOR_PIXEL_ACCESS : 0);
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetClipRect ( nsRect aRect,
PRBool aHasLocalClip 
) [virtual]

Gets the bounds of the clip region of the RenderingContext.

The bounds are returned in device units!

Parameters:
aRectout parameter to contain the clip region bounds for the RenderingContext
Returns:
PR_TRUE if the rendering context has a local cliprect set else aRect is undefined

Implements nsIRenderingContext.

Definition at line 850 of file nsRenderingContextWin.cpp.

{
  if (mStates->mFlags & FLAG_LOCAL_CLIP_VALID)
  {
    aRect = mStates->mLocalClip;
    aClipValid = PR_TRUE;
  }
  else
    aClipValid = PR_FALSE;

  return NS_OK;
}

Gets the current clipping region for the RenderingContext The region is in device coordinates!

Parameters:
aRegionout parameter representing the clip region. if SetClipRegion() is called, do not assume that GetClipRegion() will return the same object.

Implements nsIRenderingContext.

Definition at line 921 of file nsRenderingContextWin.cpp.

{
  nsresult  rv = NS_OK;

  NS_ASSERTION(!(nsnull == aRegion), "no region ptr");

  if (nsnull == *aRegion)
  {
    nsRegionWin *rgn = new nsRegionWin();

    if (nsnull != rgn)
    {
      NS_ADDREF(rgn);

      rv = rgn->Init();

      if (NS_OK != rv)
        NS_RELEASE(rgn);
      else
        *aRegion = rgn;
    }
    else
      rv = NS_ERROR_OUT_OF_MEMORY;
  }

  if (rv == NS_OK) {
    rv = CopyClipRegion(**aRegion);
  }

  return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::GetClusterInfo ( const PRUnichar aText,
PRUint32  aLength,
PRUint8 aClusterStarts 
) [virtual, inherited]

Get cluster details for a chunk of text.

This will fill in the aClusterStarts array with information about what characters are the start of clusters for display. The information is just a bitfield that is set to 1 if the character is the start of a cluster. aClusterStarts must already be allocated to at least aLength items in length. Array index zero being set to one indicates that the first character is the beginning of a cluster.

Parameters:
aTextText on which to get details.
aLengthLength of the text.
aClusterStartsArray of ints that will be populated with information about which characters are the starts of clusters.

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextGTK.

Definition at line 448 of file nsRenderingContextImpl.cpp.

Here is the caller graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetColor ( nscolor aColor) const [virtual]

Get the forground color for the RenderingContext.

Returns:
The current forground color of the RenderingContext

Implements nsIRenderingContext.

Definition at line 962 of file nsRenderingContextWin.cpp.

{
  aColor = mCurrentColor;
  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin::GetCurrentTransform ( nsTransform2D *&  aTransform) [virtual]

Get the current transformation matrix for the RenderingContext.

Returns:
The transformation matrix for the RenderingContext

Implements nsIRenderingContext.

Definition at line 1021 of file nsRenderingContextWin.cpp.

{
  aTransform = mTranMatrix;
  return NS_OK;
}

Get the DeviceContext that this RenderingContext was initialized with.

Returns:
the device context

Implements nsIRenderingContext.

Definition at line 672 of file nsRenderingContextWin.cpp.

Get the currently selected drawing surface.

Parameters:
aSurfaceout parameter for the current drawing surface

Implements nsIRenderingContext.

Definition at line 634 of file nsRenderingContextWin.cpp.

{
  *aSurface = mSurface;
  return NS_OK;
}
void nsRenderingContextImpl::GetDrawingSurfaceSize ( const nsRect aMaxBackbufferSize,
const nsRect aRequestedSize,
nsRect aSurfaceSize 
) [protected, inherited]

Get the size of the offscreen drawing surface.

Parameters:
aMaxBackbufferSizeMaximum size that may be requested for the backbuffer
aRequestedSizeDesired size for the offscreen.
aSurfaceSizeOffscreen adjusted to a discrete size which encloses aRequestedSize.

Definition at line 215 of file nsRenderingContextImpl.cpp.

{ 
  CalculateDiscreteSurfaceSize(aMaxBackbufferSize, aRequestedSize, aNewSize);
  aNewSize.MoveTo(aRequestedSize.x, aRequestedSize.y);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get the current fontmetrics for the RenderingContext.

Returns:
The current font of the RenderingContext

Implements nsIRenderingContext.

Definition at line 999 of file nsRenderingContextWin.cpp.

{
  NS_IF_ADDREF(mFontMetrics);
  aFontMetrics = mFontMetrics;

  return NS_OK;
}

Returns in aResult any rendering hints that the context has.

See below for the hints bits. Always returns NS_OK.

Implements nsIRenderingContext.

Definition at line 641 of file nsRenderingContextWin.cpp.

{
  PRUint32 result = 0;
  
#ifndef WINCE
  result |= NS_RENDERING_HINT_FAST_MEASURE;
#endif

  if (gIsWIN95)
    result |= NS_RENDERING_HINT_FAST_8BIT_TEXT;

  if (NOT_SETUP == gBidiInfo) {
    InitBidiInfo();
  }
#ifndef WINCE
  if (GCP_REORDER == (gBidiInfo & GCP_REORDER) )
    result |= NS_RENDERING_HINT_BIDI_REORDERING;
  if (GCP_GLYPHSHAPE == (gBidiInfo & GCP_GLYPHSHAPE) )
    result |= NS_RENDERING_HINT_ARABIC_SHAPING;
#endif
  
  aResult = result;

  return NS_OK;
}

Here is the call graph for this function:

Gets the line style for the RenderingContext.

Parameters:
aLineStyleThe line style to be retrieved
Returns:
NS_OK if the line style is correctly retrieved

Implements nsIRenderingContext.

Definition at line 974 of file nsRenderingContextWin.cpp.

{
  aLineStyle = mCurrLineStyle;
  return NS_OK;
}

Return the maximum length of a string that can be handled by the platform using the current font metrics.

The implementation here is just a stub; classes that don't override the safe string methods need to implement this.

Reimplemented from nsRenderingContextImpl.

Definition at line 2424 of file nsRenderingContextWin.cpp.

{
  if (!mFontMetrics)
    return 1;
  return NS_STATIC_CAST(nsFontMetricsWin*, mFontMetrics)->GetMaxStringLength();
}

Gets the Pen Mode for the RenderingContext.

Parameters:
aPenModeThe Pen Mode to be retrieved
Returns:
NS_OK if the Pen Mode is correctly retrieved

Reimplemented from nsRenderingContextImpl.

Definition at line 2769 of file nsRenderingContextWin.cpp.

{
  // can use the ::GetROP2(mDC); for debugging, see if windows is in the correct mode
  aPenMode = mPenMode;

  return NS_OK;
}
PRInt32 nsRenderingContextImpl::GetPosition ( const PRUnichar aText,
PRUint32  aLength,
nsPoint  aPt 
) [virtual, inherited]

Find the closest cursor position for a given x coordinate.

This will find the closest byte index for a given x coordinate. This takes into account grapheme clusters and bidi text.

Parameters:
aTextText on which to operate.
aLengthLength of the text.
aPtthe x/y position in the string to check.
Returns:
Index where the cursor falls. If the return is zero, it's before the first character, if it falls off the end of the string it's the length of the string + 1.

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextGTK.

Definition at line 456 of file nsRenderingContextImpl.cpp.

{
  return -1;
}
NS_IMETHODIMP nsRenderingContextImpl::GetRangeWidth ( const PRUnichar aText,
PRUint32  aLength,
PRUint32  aStart,
PRUint32  aEnd,
PRUint32 aWidth 
) [virtual, inherited]

Get the width for the specific range of a given string.

This function is similar to other GetWidth functions, except that it gets the width for a part of the string instead of the entire string. This is useful when you're interested in finding out the length of a chunk in the middle of the string. Lots of languages require you to include surrounding information to accurately determine the length of a substring.

Parameters:
aTextText on which to operate
aLengthLength of the text
aStartStart index into the string
aEndEnd index into the string (inclusive)
aWidthReturned with in app coordinates

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextGTK.

Definition at line 464 of file nsRenderingContextImpl.cpp.

NS_IMETHODIMP nsRenderingContextImpl::GetRangeWidth ( const char *  aText,
PRUint32  aLength,
PRUint32  aStart,
PRUint32  aEnd,
PRUint32 aWidth 
) [virtual, inherited]

Get the width for the specific range of a given string.

Same as GetRangeWidth for PRUnichar, but takes a char * as the text argument.

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextGTK.

Definition at line 474 of file nsRenderingContextImpl.cpp.

Reimplemented from nsRenderingContextImpl.

Definition at line 2908 of file nsRenderingContextWin.cpp.

{
#ifndef WINCE
  *aIsRTL = mRightToLeftText;
#else
  *aIsRTL = PR_FALSE;
#endif
  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextImpl::GetTextDimensions ( const char *  aString,
PRUint32  aLength,
nsTextDimensions aDimensions 
) [virtual, inherited]

Returns the dimensions of a string, i.e., the overall extent of a string whose rendering may involve switching between different fonts that have different metrics.

Parameters:
aStringstring to measure
aLengthnumber of characters in string
aFontIDan optional out parameter used to store a font identifier that can be passed into the DrawString() methods to speed measurements
Returns:
aDimensions struct that contains the extent of the string (see below)

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextPh, nsRenderingContextPS, nsRenderingContextXlib, nsRenderingContextOS2, nsRenderingContextQt, and nsRenderingContextBeOS.

Definition at line 601 of file nsRenderingContextImpl.cpp.

{
  PRUint32 maxChunkLength = GetMaxChunkLength(this);
  if (aLength <= maxChunkLength)
    return GetTextDimensionsInternal(aString, aLength, aDimensions);
 
  PRBool firstIteration = PR_TRUE;
  while (aLength > 0) {
    PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
    nsTextDimensions dimensions;
    nsresult rv = GetTextDimensionsInternal(aString, len, dimensions);
    if (NS_FAILED(rv))
      return rv;
    if (firstIteration) {
      // Instead of combining with a Clear()ed nsTextDimensions, we assign
      // directly in the first iteration. This ensures that negative ascent/
      // descent can be returned.
      aDimensions = dimensions;
    } else {
      aDimensions.Combine(dimensions);
    }
    aLength -= len;
    aString += len;
    firstIteration = PR_FALSE;
  }
  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::GetTextDimensions ( const PRUnichar aString,
PRUint32  aLength,
nsTextDimensions aDimensions,
PRInt32 aFontID = nsnull 
) [virtual, inherited]

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextPh, nsRenderingContextPS, nsRenderingContextXlib, nsRenderingContextOS2, nsRenderingContextQt, and nsRenderingContextBeOS.

Definition at line 631 of file nsRenderingContextImpl.cpp.

{
  PRUint32 maxChunkLength = GetMaxChunkLength(this);
  if (aLength <= maxChunkLength)
    return GetTextDimensionsInternal(aString, aLength, aDimensions);
    
  if (aFontID) {
    *aFontID = nsnull;
  }
 
  PRBool firstIteration = PR_TRUE;
  while (aLength > 0) {
    PRInt32 len = FindSafeLength(this, aString, aLength, maxChunkLength);
    nsTextDimensions dimensions;
    nsresult rv = GetTextDimensionsInternal(aString, len, dimensions);
    if (NS_FAILED(rv))
      return rv;
    if (firstIteration) {
      // Instead of combining with a Clear()ed nsTextDimensions, we assign
      // directly in the first iteration. This ensures that negative ascent/
      // descent can be returned.
      aDimensions = dimensions;
    } else {
      aDimensions.Combine(dimensions);
    }
    aLength -= len;
    aString += len;
    firstIteration = PR_FALSE;
  }
  return NS_OK;  
}

Here is the call graph for this function:

Reimplemented from nsRenderingContextImpl.

Definition at line 2114 of file nsRenderingContextWin.cpp.

{
  if (!mFontMetrics) {
    aDimensions.Clear();
    return NS_ERROR_FAILURE;
  }
  GetWidth(aString, aLength, aDimensions.width);
  mFontMetrics->GetMaxAscent(aDimensions.ascent);
  mFontMetrics->GetMaxDescent(aDimensions.descent);
  return NS_OK;
}

Here is the call graph for this function:

Reimplemented from nsRenderingContextImpl.

Definition at line 2160 of file nsRenderingContextWin.cpp.

{
  aDimensions.Clear();
  if (!mFontMetrics) return NS_ERROR_FAILURE;

  CheckLength(&aLength);
  SetupFontAndColor();

  nsFontMetricsWin* metrics = (nsFontMetricsWin*)mFontMetrics;
  GetTextDimensionsData data = {mDC, mCurrFont, 0, 0, 0};

  metrics->ResolveForwards(mDC, aString, aLength, do_GetTextDimensions, &data);
  aDimensions.width = NSToCoordRound(float(data.mWidth) * mP2T);
  aDimensions.ascent = data.mAscent;
  aDimensions.descent = data.mDescent;

  if (mCurrFont != data.mFont) {
    // If the font was changed on the way, restore our font
    ::SelectObject(mDC, mCurrFont);
  }

  if (aFontID) *aFontID = 0;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetTextDimensionsInternal ( const char *  aString,
PRInt32  aLength,
PRInt32  aAvailWidth,
PRInt32 aBreaks,
PRInt32  aNumBreaks,
nsTextDimensions aDimensions,
PRInt32 aNumCharsFit,
nsTextDimensions aLastWordDimensions,
PRInt32 aFontID 
)

Definition at line 1517 of file nsRenderingContextWin.cpp.

{
  NS_PRECONDITION(aBreaks[aNumBreaks - 1] == aLength, "invalid break array");

  if (nsnull != mFontMetrics) {
    // Setup the font and foreground color
    CheckLength((PRUint32*)&aLength);
    SetupFontAndColor();

    // If we need to back up this state represents the last place we could
    // break. We can use this to avoid remeasuring text
    PRInt32 prevBreakState_BreakIndex = -1; // not known (hasn't been computed)
    nscoord prevBreakState_Width = 0; // accumulated width to this point

    // Initialize OUT parameters
    mFontMetrics->GetMaxAscent(aLastWordDimensions.ascent);
    mFontMetrics->GetMaxDescent(aLastWordDimensions.descent);
    aLastWordDimensions.width = -1;
    aNumCharsFit = 0;

    // Iterate each character in the string and determine which font to use
    nscoord width = 0;
    PRInt32 start = 0;
    nscoord aveCharWidth;
    mFontMetrics->GetAveCharWidth(aveCharWidth);

    while (start < aLength) {
      // Estimate how many characters will fit. Do that by diving the available
      // space by the average character width. Make sure the estimated number
      // of characters is at least 1
      PRInt32 estimatedNumChars = 0;
      if (aveCharWidth > 0) {
        estimatedNumChars = (aAvailWidth - width) / aveCharWidth;
      }
      if (estimatedNumChars < 1) {
        estimatedNumChars = 1;
      }

      // Find the nearest break offset
      PRInt32 estimatedBreakOffset = start + estimatedNumChars;
      PRInt32 breakIndex;
      nscoord numChars;

      // Find the nearest place to break that is less than or equal to
      // the estimated break offset
      if (aLength <= estimatedBreakOffset) {
        // All the characters should fit
        numChars = aLength - start;
        breakIndex = aNumBreaks - 1;
      } 
      else {
        breakIndex = prevBreakState_BreakIndex;
        while (((breakIndex + 1) < aNumBreaks) &&
               (aBreaks[breakIndex + 1] <= estimatedBreakOffset)) {
          ++breakIndex;
        }
        if (breakIndex == prevBreakState_BreakIndex) {
          ++breakIndex; // make sure we advanced past the previous break index
        }
        numChars = aBreaks[breakIndex] - start;
      }

      // Measure the text
      nscoord pxWidth, twWidth = 0;
      if ((1 == numChars) && (aString[start] == ' ')) {
        mFontMetrics->GetSpaceWidth(twWidth);
      } 
      else if (numChars > 0) {
        pxWidth = mCurrFontWin->GetWidth(mDC, &aString[start], numChars);
        twWidth = NSToCoordRound(float(pxWidth) * mP2T);
      }

      // See if the text fits
      PRBool  textFits = (twWidth + width) <= aAvailWidth;

      // If the text fits then update the width and the number of
      // characters that fit
      if (textFits) {
        aNumCharsFit += numChars;
        width += twWidth;
        start += numChars;

        // This is a good spot to back up to if we need to so remember
        // this state
        prevBreakState_BreakIndex = breakIndex;
        prevBreakState_Width = width;
      }
      else {
        // See if we can just back up to the previous saved state and not
        // have to measure any text
        if (prevBreakState_BreakIndex > 0) {
          // If the previous break index is just before the current break index
          // then we can use it
          if (prevBreakState_BreakIndex == (breakIndex - 1)) {
            aNumCharsFit = aBreaks[prevBreakState_BreakIndex];
            width = prevBreakState_Width;
            break;
          }
        }

        // We can't just revert to the previous break state
        if (0 == breakIndex) {
          // There's no place to back up to, so even though the text doesn't fit
          // return it anyway
          aNumCharsFit += numChars;
          width += twWidth;
          break;
        }

        // Repeatedly back up until we get to where the text fits or we're all
        // the way back to the first word
        width += twWidth;
        while ((breakIndex >= 1) && (width > aAvailWidth)) {
          twWidth = 0;
          start = aBreaks[breakIndex - 1];
          numChars = aBreaks[breakIndex] - start;
          
          if ((1 == numChars) && (aString[start] == ' ')) {
            mFontMetrics->GetSpaceWidth(twWidth);
          } 
          else if (numChars > 0) {
            pxWidth = mCurrFontWin->GetWidth(mDC, &aString[start], numChars);
            twWidth = NSToCoordRound(float(pxWidth) * mP2T);
          }

          width -= twWidth;
          aNumCharsFit = start;
          breakIndex--;
        }
        break;
      }
    }

    aDimensions.width = width;
    mFontMetrics->GetMaxAscent(aDimensions.ascent);
    mFontMetrics->GetMaxDescent(aDimensions.descent);

    return NS_OK;
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetTextDimensionsInternal ( const PRUnichar aString,
PRInt32  aLength,
PRInt32  aAvailWidth,
PRInt32 aBreaks,
PRInt32  aNumBreaks,
nsTextDimensions aDimensions,
PRInt32 aNumCharsFit,
nsTextDimensions aLastWordDimensions,
PRInt32 aFontID 
)

Definition at line 1951 of file nsRenderingContextWin.cpp.

{
  if (!mFontMetrics) return NS_ERROR_FAILURE;

  CheckLength((PRUint32*)&aLength);
  SetupFontAndColor();

  nsFontMetricsWin* metrics = (nsFontMetricsWin*)mFontMetrics;

  nscoord spaceWidth, aveCharWidth;
  metrics->GetSpaceWidth(spaceWidth);
  metrics->GetAveCharWidth(aveCharWidth);

  // Note: aBreaks[] is supplied to us so that the first word is located
  // at aString[0 .. aBreaks[0]-1] and more generally, the k-th word is
  // located at aString[aBreaks[k-1] .. aBreaks[k]-1]. Whitespace can
  // be included and each of them counts as a word in its own right.

  // Upon completion of glyph resolution, characters that can be
  // represented with fonts[i] are at offsets[i] .. offsets[i+1]-1

  nsAutoVoidArray fonts, offsets;
  offsets.AppendElement((void*)aString);

  BreakGetTextDimensionsData data = {mDC, mCurrFont, mP2T, 
    aAvailWidth, aBreaks, aNumBreaks, spaceWidth, aveCharWidth,
    0, 0, 0, -1, 0, &fonts, &offsets 
  };

  metrics->ResolveForwards(mDC, aString, aLength, do_BreakGetTextDimensions, &data);

  if (mCurrFont != data.mFont) {
    // If the font was changed along the way, restore our font
    ::SelectObject(mDC, mCurrFont);
  }

  if (aFontID) *aFontID = 0;

  aNumCharsFit = data.mNumCharsFit;
  aDimensions.width = data.mWidth;

  // Post-processing for the ascent and descent:
  //
  // The width of the last word is included in the final width, but its
  // ascent and descent are kept aside for the moment. The problem is that
  // line-breaking may occur _before_ the last word, and we don't want its
  // ascent and descent to interfere. We can re-measure the last word and
  // substract its width later. However, we need a special care for the ascent
  // and descent at the break-point. The idea is to keep the ascent and descent
  // of the last word separate, and let layout consider them later when it has
  // determined that line-breaking doesn't occur before the last word.
  //
  // Therefore, there are two things to do:
  // 1. Determine the ascent and descent up to where line-breaking may occur.
  // 2. Determine the ascent and descent of the remainder.
  //    For efficiency however, it is okay to bail out early if there is only
  //    one font (in this case, the height of the last word has no special
  //    effect on the total height).

  // aLastWordDimensions.width should be set to -1 to reply that we don't
  // know the width of the last word since we measure multiple words
  aLastWordDimensions.Clear();
  aLastWordDimensions.width = -1;

  PRInt32 count = fonts.Count();
  if (!count)
    return NS_OK;
  nsFontWin* fontWin = (nsFontWin*)fonts[0];
  NS_ASSERTION(fontWin, "internal error in do_BreakGetTextDimensions");
  aDimensions.ascent = fontWin->mMaxAscent;
  aDimensions.descent = fontWin->mMaxDescent;

  // fast path - normal case, quick return if there is only one font
  if (count == 1)
    return NS_OK;

  // get the last break index.
  // If there is only one word, we end up with lastBreakIndex = 0. We don't
  // need to worry about aLastWordDimensions in this case too. But if we didn't
  // return earlier, it would mean that the unique word needs several fonts
  // and we will still have to loop over the fonts to return the final height
  PRInt32 lastBreakIndex = 0;
  while (aBreaks[lastBreakIndex] < aNumCharsFit)
    ++lastBreakIndex;

  const PRUnichar* lastWord = (lastBreakIndex > 0) 
    ? aString + aBreaks[lastBreakIndex-1]
    : aString + aNumCharsFit; // let it point outside to play nice with the loop

  // now get the desired ascent and descent information... this is however
  // a very fast loop of the order of the number of additional fonts

  PRInt32 currFont = 0;
  const PRUnichar* pstr = aString;
  const PRUnichar* last = aString + aNumCharsFit;

  while (pstr < last) {
    fontWin = (nsFontWin*)fonts[currFont];
    PRUnichar* nextOffset = (PRUnichar*)offsets[++currFont]; 

    // For consistent word-wrapping, we are going to handle the whitespace
    // character with special care because a whitespace character can come
    // from a font different from that of the previous word. If 'x', 'y', 'z',
    // are Unicode points that require different fonts, we want 'xyz <br>'
    // and 'xyz<br>' to have the same height because it gives a more stable
    // rendering, especially when the window is resized at the edge of the word.
    // If we don't do this, a 'tall' trailing whitespace, i.e., if the whitespace
    // happens to come from a font with a bigger ascent and/or descent than all
    // current fonts on the line, this can cause the next lines to be shifted
    // down when the window is slowly resized to fit that whitespace.
    if (*pstr == ' ') {
      // skip pass the whitespace to ignore the height that it may contribute
      ++pstr;
      // get out if we reached the end
      if (pstr == last) {
        break;
      }
      // switch to the next font if we just passed the current font 
      if (pstr == nextOffset) {
        fontWin = (nsFontWin*)fonts[currFont];
        nextOffset = (PRUnichar*)offsets[++currFont];
      } 
    }

    // see if the last word intersects with the current font
    // (we are testing for 'nextOffset-1 >= lastWord' since the
    // current font ends at nextOffset-1)
    if (nextOffset > lastWord) {
      if (aLastWordDimensions.ascent < fontWin->mMaxAscent) {
        aLastWordDimensions.ascent = fontWin->mMaxAscent;
      }
      if (aLastWordDimensions.descent < fontWin->mMaxDescent) {
        aLastWordDimensions.descent = fontWin->mMaxDescent;
      }
    }

    // see if we have not reached the last word yet
    if (pstr < lastWord) {
      if (aDimensions.ascent < fontWin->mMaxAscent) {
        aDimensions.ascent = fontWin->mMaxAscent;
      }
      if (aDimensions.descent < fontWin->mMaxDescent) {
        aDimensions.descent = fontWin->mMaxDescent;
      }
    }

    // advance to where the next font starts
    pstr = nextOffset;
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD nsRenderingContextWin::GetWidth ( const nsString aString,
nscoord aWidth,
PRInt32 aFontID = nsnull 
) [inline, virtual]

Returns the width (in app units) of an nsString If no font has been Set, the results are undefined.

Parameters:
aStringstring to measure
aWidthout parameter for width
aFontIDan optional out parameter used to store a font identifier that can be passed into the DrawString() methods to speed rendering
Returns:
error status

Reimplemented from nsRenderingContextImpl.

Definition at line 150 of file nsRenderingContextWin.h.

  { return nsRenderingContextImpl::GetWidth(aString, aWidth, aFontID); }

Here is the caller graph for this function:

NS_IMETHOD nsRenderingContextWin::GetWidth ( const char *  aString,
nscoord aWidth 
) [inline, virtual]

Returns the width (in app units) of an 8-bit character string If no font has been Set, the results are undefined.

Parameters:
aStringstring to measure
aWidthout parameter for width
Returns:
error status

Reimplemented from nsRenderingContextImpl.

Definition at line 153 of file nsRenderingContextWin.h.

  { return nsRenderingContextImpl::GetWidth(aString, aWidth); }

Here is the call graph for this function:

NS_IMETHOD nsRenderingContextWin::GetWidth ( const char *  aString,
PRUint32  aLength,
nscoord aWidth 
) [inline, virtual]

Returns the width (in app units) of an 8-bit character string If no font has been Set, the results are undefined.

Parameters:
aStringstring to measure
aLengthnumber of characters in string
aWidthout parameter for width
Returns:
error status

Reimplemented from nsRenderingContextImpl.

Definition at line 155 of file nsRenderingContextWin.h.

  { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth); }

Here is the call graph for this function:

NS_IMETHOD nsRenderingContextWin::GetWidth ( const PRUnichar aString,
PRUint32  aLength,
nscoord aWidth,
PRInt32 aFontID = nsnull 
) [inline, virtual]

Returns the width (in app units) of a Unicode character string If no font has been Set, the results are undefined.

Parameters:
aStringstring to measure
aLengthnumber of characters in string
aWidthout parameter for width
aFontIDan optional out parameter used to store a font identifier that can be passed into the DrawString() methods to speed rendering
Returns:
error status

Reimplemented from nsRenderingContextImpl.

Definition at line 158 of file nsRenderingContextWin.h.

  { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth, aFontID); }

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetWidth ( char  aC,
nscoord aWidth 
) [virtual]

Returns the width (in app units) of an 8-bit character If no font has been Set, the results are undefined.

Parameters:
aCcharacter to measure
aWidthout parameter for width
Returns:
error status

Implements nsRenderingContextImpl.

Definition at line 1427 of file nsRenderingContextWin.cpp.

{
  char buf[1];
  buf[0] = ch;
  return GetWidth(buf, 1, aWidth);
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetWidth ( PRUnichar  aC,
nscoord aWidth,
PRInt32 aFontID 
) [virtual]

Returns the width (in app units) of a unicode character If no font has been Set, the results are undefined.

Parameters:
aCcharacter to measure
aWidthout parameter for width
aFontIDan optional out parameter used to store a font identifier that can be passed into the DrawString() methods to speed rendering
Returns:
error status

Implements nsRenderingContextImpl.

Definition at line 1434 of file nsRenderingContextWin.cpp.

{
  PRUnichar buf[1];
  buf[0] = ch;
  return GetWidth(buf, 1, aWidth, aFontID);
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetWidthInternal ( const char *  aString,
PRUint32  aLength,
nscoord aWidth 
)

Reimplemented from nsRenderingContextImpl.

Definition at line 1441 of file nsRenderingContextWin.cpp.

{

  if (nsnull != mFontMetrics)
  {
    // Check for the very common case of trying to get the width of a single
    // space.
    if ((1 == aLength) && (aString[0] == ' '))
    {
      return mFontMetrics->GetSpaceWidth(aWidth);
    }

    CheckLength(&aLength);
    SetupFontAndColor();
    nscoord pxWidth = mCurrFontWin->GetWidth(mDC, aString, aLength);
    aWidth = NSToCoordRound(float(pxWidth) * mP2T);

    return NS_OK;
  }
  else
    return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::GetWidthInternal ( const PRUnichar aString,
PRUint32  aLength,
nscoord aWidth,
PRInt32 aFontID 
)

Reimplemented from nsRenderingContextImpl.

Definition at line 1490 of file nsRenderingContextWin.cpp.

{
  if (!mFontMetrics) return NS_ERROR_FAILURE;

  CheckLength(&aLength);
  SetupFontAndColor();

  nsFontMetricsWin* metrics = (nsFontMetricsWin*)mFontMetrics;
  GetWidthData data = {mDC, mCurrFont, 0};

  metrics->ResolveForwards(mDC, aString, aLength, do_GetWidth, &data);
  aWidth = NSToCoordRound(float(data.mWidth) * mP2T);

  if (mCurrFont != data.mFont) {
    // If the font was changed along the way, restore our font
    ::SelectObject(mDC, mCurrFont);
  }

  if (aFontID) *aFontID = 0;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::Init ( nsIDeviceContext aContext,
nsIWidget aWidget 
) [virtual]

Initialize the RenderingContext.

Parameters:
aContextthe device context to use.
aWidgetthe widget to hook up to
Returns:
The result of the initialization, NS_Ok if no errors

Implements nsIRenderingContext.

Definition at line 376 of file nsRenderingContextWin.cpp.

{
  NS_PRECONDITION(PR_FALSE == mInitialized, "double init");

  mContext = aContext;
  NS_IF_ADDREF(mContext);

  mSurface = (nsDrawingSurfaceWin *)new nsDrawingSurfaceWin();

  if (nsnull != mSurface)
  {
    HDC tdc = (HDC)aWindow->GetNativeData(NS_NATIVE_GRAPHIC);

    NS_ADDREF(mSurface);
    mSurface->Init(tdc);
    mDC = tdc;

    mMainDC = mDC;
    mMainSurface = mSurface;
    NS_ADDREF(mMainSurface);
  }

  mDCOwner = aWindow;

  NS_IF_ADDREF(mDCOwner);

  return CommonInit();
}

Here is the call graph for this function:

Initialize the RenderingContext.

Parameters:
aContextthe device context to use for the drawing.
aSurfacethe surface to draw into
Returns:
The result of the initialization, NS_Ok if no errors

Implements nsIRenderingContext.

Definition at line 407 of file nsRenderingContextWin.cpp.

Here is the call graph for this function:

Init gBidiInfo with reordering and shaping capabilities of the system.

Definition at line 2923 of file nsRenderingContextWin.cpp.

{
#ifndef WINCE
  if (NOT_SETUP == gBidiInfo) {
    gBidiInfo = DONT_INIT;

    const PRUnichar araAin  = 0x0639;
    const PRUnichar one     = 0x0031;

    int distanceArray[2];
    PRUnichar glyphArray[2];
    PRUnichar outStr[] = {0, 0};

    GCP_RESULTSW gcpResult;
    gcpResult.lStructSize = sizeof(GCP_RESULTS);
    gcpResult.lpOutString = outStr;     // Output string
    gcpResult.lpOrder = nsnull;         // Ordering indices
    gcpResult.lpDx = distanceArray;     // Distances between character cells
    gcpResult.lpCaretPos = nsnull;      // Caret positions
    gcpResult.lpClass = nsnull;         // Character classifications
    gcpResult.lpGlyphs = glyphArray;    // Character glyphs
    gcpResult.nGlyphs = 2;              // Array size

    PRUnichar inStr[] = {araAin, one};

    if (::GetCharacterPlacementW(mDC, inStr, 2, 0, &gcpResult, GCP_REORDER) 
        && (inStr[0] == outStr[1]) ) {
      gBidiInfo = GCP_REORDER | GCP_GLYPHSHAPE;
#ifdef NS_DEBUG
      printf("System has shaping\n");
#endif
    }
    else {
      const PRUnichar hebAlef = 0x05D0;
      inStr[0] = hebAlef;
      inStr[1] = one;
      if (::GetCharacterPlacementW(mDC, inStr, 2, 0, &gcpResult, GCP_REORDER) 
          && (inStr[0] == outStr[1]) ) {
        gBidiInfo = GCP_REORDER;
#ifdef NS_DEBUG
        printf("System has Bidi\n");
#endif
      }
    }
  }
#endif //WINCE
}

Here is the caller graph for this function:

XOR Invert a rectangle in the current foreground color.

Parameters:
aRectThe rectangle to draw

Implements nsIRenderingContext.

Definition at line 1193 of file nsRenderingContextWin.cpp.

{
  RECT nr;
       nsRect tr;

       tr = aRect;
       mTranMatrix->TransformCoord(&tr.x,&tr.y,&tr.width,&tr.height);
  ConditionRect(tr, nr);
  ::InvertRect(mDC, &nr);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsRenderingContextWin::InvertRect ( nscoord  aX,
nscoord  aY,
nscoord  aWidth,
nscoord  aHeight 
) [virtual]

XOR Invert a rectangle in the current foreground color.

Parameters:
aXHorizontal left Coordinate in twips
aYVertical top Coordinate in twips
aWidthWidth of rectangle in twips
aHeightHeight of rectangle in twips

Implements nsIRenderingContext.

Definition at line 1206 of file nsRenderingContextWin.cpp.

{
  RECT nr;
       nsRect tr;

       mTranMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight);
       nr.left = aX;
       nr.top = aY;
       nr.right = aX+aWidth;
       nr.bottom = aY+aHeight;

  ::InvertRect(mDC, &nr);

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextWin::IsVisibleRect ( const nsRect aRect,
PRBool aIsVisible 
) [virtual]

Tells if a given rectangle is visible within the rendering context.

Parameters:
aRectis the rectangle that will be checked for visiblity
Returns:
If true, that rectanglular area is visable.

Implements nsIRenderingContext.

Definition at line 781 of file nsRenderingContextWin.cpp.

{
  aVisible = PR_TRUE;
  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin::LockDrawingSurface ( PRInt32  aX,
PRInt32  aY,
PRUint32  aWidth,
PRUint32  aHeight,
void **  aBits,
PRInt32 aStride,
PRInt32 aWidthBytes,
PRUint32  aFlags 
) [virtual]

Lock a rect of the drawing surface associated with the rendering context.

do not attempt to use any of the Rendering Context rendering or state management methods until the drawing surface has been Unlock()ed. if a drawing surface is Lock()ed with this method, it must be Unlock()ed by calling UnlockDrawingSurface() rather than just calling the Unlock() method on the drawing surface directly. see nsIDrawingSurface.h for more information

Returns:
error status

Implements nsIRenderingContext.

Definition at line 516 of file nsRenderingContextWin.cpp.

{
  PRBool        destructive;
  nsPaletteInfo palInfo;

  PushState();

  mSurface->IsReleaseDCDestructive(&destructive);

  if (destructive)
  {
    PushClipState();

    if (nsnull != mOrigSolidBrush)
      mCurrBrush = (HBRUSH)::SelectObject(mDC, mOrigSolidBrush);

    if (nsnull != mOrigFont)
      mCurrFont = (HFONT)::SelectObject(mDC, mOrigFont);

    if (nsnull != mOrigSolidPen)
      mCurrPen = (HPEN)::SelectObject(mDC, mOrigSolidPen);

    mContext->GetPaletteInfo(palInfo);
    if(palInfo.isPaletteDevice && palInfo.palette){
      ::SelectPalette(mDC,(HPALETTE)palInfo.palette,PR_TRUE);
      ::RealizePalette(mDC);
#ifndef WINCE
      ::UpdateColors(mDC);                                                      
#endif
    }
  }

  mSurface->ReleaseDC();

  return mSurface->Lock(aX, aY, aWidth, aHeight, aBits, aStride, aWidthBytes, aFlags);
}

Here is the call graph for this function:

Get and and set RenderingContext to this graphical state.

Implements nsIRenderingContext.

Definition at line 727 of file nsRenderingContextWin.cpp.

{
  if (nsnull == mStates)
  {
    NS_ASSERTION(!(nsnull == mStates), "state underflow");
  }
  else
  {
    GraphicsState *oldstate = mStates;

    mStates = mStates->mNext;

    mStateCache->AppendElement(oldstate);

    if (nsnull != mStates)
    {
      mTranMatrix = &mStates->mMatrix;

      GraphicsState *pstate;

      if (oldstate->mFlags & FLAG_CLIP_CHANGED)
      {
        pstate = mStates;

        //the clip rect has changed from state to state, so
        //install the previous clip rect

        while ((nsnull != pstate) && !(pstate->mFlags & FLAG_CLIP_VALID))
          pstate = pstate->mNext;

        if (nsnull != pstate)
          ::SelectClipRgn(mDC, pstate->mClipRegion);
      }

      oldstate->mFlags &= ~FLAGS_ALL;
      oldstate->mSolidPen = NULL;
      oldstate->mDashedPen = NULL;
      oldstate->mDottedPen = NULL;

      NS_IF_RELEASE(mFontMetrics);
      mFontMetrics = mStates->mFontMetrics;

      mCurrentColor = mStates->mColor;
      mColor = mStates->mColorREF;

      SetLineStyle(mStates->mLineStyle);
    }
    else
      mTranMatrix = nsnull;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIRenderingContext.

Definition at line 178 of file nsRenderingContextImpl.cpp.

{
  nsTransform2D *theTransform; 
  GetCurrentTransform(theTransform);
  NS_ASSERTION(theTransform != nsnull, "The rendering context transform is null");
  theTransform->SetTranslation(aState->mSavedX, aState->mSavedY);

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 2779 of file nsRenderingContextWin.cpp.

{
  if (!(mStates->mFlags & FLAG_CLIP_CHANGED))
  {
    GraphicsState *tstate = mStates->mNext;

    //we have never set a clip on this state before, so
    //remember the current clip state in the next state on the
    //stack. kind of wacky, but avoids selecting stuff in the DC
    //all the damned time.

    if (nsnull != tstate)
    {
      if (NULL == tstate->mClipRegion)
        tstate->mClipRegion = ::CreateRectRgn(0, 0, 0, 0);

      if (::GetClipRgn(mDC, tstate->mClipRegion) == 1)
        tstate->mFlags |= FLAG_CLIP_VALID;
      else
        tstate->mFlags &= ~FLAG_CLIP_VALID;
    }
  
    mStates->mFlags |= FLAG_CLIP_CHANGED;
  }
}

Here is the caller graph for this function:

Save a graphical state onto a stack.

Implements nsIRenderingContext.

Definition at line 679 of file nsRenderingContextWin.cpp.

{
  PRInt32 cnt = mStateCache->Count();

  if (cnt == 0)
  {
    if (nsnull == mStates)
      mStates = new GraphicsState();
    else
      mStates = new GraphicsState(*mStates);
  }
  else
  {
    GraphicsState *state = (GraphicsState *)mStateCache->ElementAt(cnt - 1);
    mStateCache->RemoveElementAt(cnt - 1);

    state->mNext = mStates;

    //clone state info

    state->mMatrix = mStates->mMatrix;
    state->mLocalClip = mStates->mLocalClip;
// we don't want to NULL this out since we reuse the region
// from state to state. if we NULL it, we need to also delete it,
// which means we'll just re-create it when we push the clip state. MMP
//    state->mClipRegion = NULL;
    state->mSolidPen = NULL;
    state->mDashedPen = NULL;
    state->mDottedPen = NULL;
    state->mFlags = ~FLAGS_ALL;
    state->mLineStyle = mStates->mLineStyle;

    mStates = state;
  }

  if (nsnull != mStates->mNext)
  {
    mStates->mNext->mColor = mCurrentColor;
    mStates->mNext->mColorREF = mColor;
    mStates->mNext->mFontMetrics = mFontMetrics;
    NS_IF_ADDREF(mStates->mNext->mFontMetrics);
  }

  mTranMatrix = &mStates->mMatrix;

  return NS_OK;
}

Here is the caller graph for this function:

Implements nsIRenderingContext.

Definition at line 155 of file nsRenderingContextImpl.cpp.

{
  // The transform components are saved and restored instead 
  // of using PushState and PopState because they are too slow
  // because they also save and restore the clip state.
  // Note: Setting a negative translation to restore the 
  // state does not work because the floating point errors can accumulate
  // causing the display of some frames to be off by one pixel. 
  // This happens frequently when running in 120DPI mode where frames are
  // often positioned at 1/2 pixel locations and small floating point errors
  // will cause the frames to vary their pixel x location during scrolling
  // operations causes a single scan line of pixels to be shifted left relative
  // to the other scan lines for the same text. 
  
  // Save the transformation matrix's translation components.
  nsTransform2D *theTransform; 
  GetCurrentTransform(theTransform);
  NS_ASSERTION(theTransform != nsnull, "The rendering context transform is null");
  theTransform->GetTranslation(&aState->mSavedX, &aState->mSavedY);
  
  return NS_OK;
}

Here is the call graph for this function:

PRBool nsRenderingContextImpl::RectFitsInside ( const nsRect aRect,
PRInt32  aWidth,
PRInt32  aHeight 
) const [protected, inherited]

Determine if a rect's width and height will fit within a specified width and height.

Parameters:
aRectrectangle to test
aWidthwidth to determine if the rectangle's width will fit within
aHeightheight to determine if the rectangles height will fit within
Returns:
PR_TRUE if the rect width and height fits with aWidth, aHeight, PR_FALSE otherwise.

Definition at line 188 of file nsRenderingContextImpl.cpp.

{
  if (aRect.width > aWidth)
    return (PR_FALSE);

  if (aRect.height > aHeight)
    return (PR_FALSE);

  return PR_TRUE;
}

Here is the caller graph for this function:

Release a drawing surface used as the backbuffer If the platform caches the backbuffer this call will destroy it.

Reimplemented from nsRenderingContextImpl.

Definition at line 2874 of file nsRenderingContextWin.cpp.

                                             {
  // Destroy the backbuffer. Do not cache it. On WIN32 it is faster to get allocate
  // the backbuffer as needed. @see bug 95952
  return DestroyCachedBackbuffer();
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::RenderEPS ( const nsRect aRect,
FILE aDataFile 
) [virtual, inherited]

Render an encapsulated postscript object onto the current rendering surface.

The EPS object must conform to the EPSF standard. See Adobe specification #5002, "Encapsulated PostScript File Format Specification" at http://partners.adobe.com/asn/developer/pdfs/tn/5002.EPSF_Spec.pdf. In particular, the EPS object must contain a BoundingBox comment.

Parameters:
aRectRectangle in which to render the EPSF.
aDataFile- plugin data stored in a file
Returns:
NS_OK for success, or a suitable error value. NS_ERROR_NOT_IMPLEMENTED is returned if the rendering context doesn't support rendering EPSF,

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextPS, and nsRenderingContextXp.

Definition at line 931 of file nsRenderingContextImpl.cpp.

Reset the rendering context.

Implements nsIRenderingContext.

Definition at line 667 of file nsRenderingContextWin.cpp.

{
  return NS_OK;
}

Implements nsIRenderingContext.

Definition at line 2512 of file nsRenderingContextWin.cpp.

{
  if(ngd != nsnull)
    *ngd = (void*)mDC;
  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin::Scale ( float  aSx,
float  aSy 
) [virtual]

Add in a scale to the RenderingContext's transformation matrix.

Parameters:
aXThe horizontal scale
aYThe vertical scale

Implements nsIRenderingContext.

Definition at line 1015 of file nsRenderingContextWin.cpp.

{
       mTranMatrix->AddScale(aSx, aSy);
  return NS_OK;
}

Selects an offscreen drawing surface into the RenderingContext to draw to.

Parameters:
aSurfaceis the offscreen surface we are going to draw to. if nsnull, the original drawing surface obtained at initialization should be selected.

Implements nsIRenderingContext.

Definition at line 587 of file nsRenderingContextWin.cpp.

{
  nsresult  rv;

  //XXX this should reset the data in the state stack.

  if (aSurface != mSurface)
  {
    if (nsnull != aSurface)
    {
      HDC tdc;

      //get back a DC
      ((nsDrawingSurfaceWin *)aSurface)->GetDC(&tdc);

      rv = SetupDC(mDC, tdc);

      //kill the DC
      mSurface->ReleaseDC();

      NS_IF_RELEASE(mSurface);
      mSurface = (nsDrawingSurfaceWin *)aSurface;
    }
    else
    {
      if (NULL != mDC)
      {
        rv = SetupDC(mDC, mMainDC);

        //kill the DC
        mSurface->ReleaseDC();

        NS_IF_RELEASE(mSurface);
        mSurface = mMainSurface;
      }
    }

    NS_ADDREF(mSurface);
    mSurface->GetDC(&mDC);
  }
  else
    rv = NS_OK;

  return rv;
}

Here is the call graph for this function:

Sets the clipping for the RenderingContext to the passed in rectangle.

The rectangle is in app units!

Parameters:
aRectThe rectangle to set the clipping rectangle to
aCombinehow to combine this rect with the current clip region. see the bottom of nsIRenderingContext.h

Implements nsIRenderingContext.

Definition at line 787 of file nsRenderingContextWin.cpp.

{
  nsRect  trect = aRect;

  mStates->mLocalClip = aRect;

       mTranMatrix->TransformCoord(&trect.x, &trect.y,
                           &trect.width, &trect.height);

  RECT nr;
  ConditionRect(trect, nr);

  mStates->mFlags |= FLAG_LOCAL_CLIP_VALID;

  //how we combine the new rect with the previous?

  if (aCombine == nsClipCombine_kIntersect)
  {
    PushClipState();

    ::IntersectClipRect(mDC, nr.left,
                        nr.top,
                        nr.right,
                        nr.bottom);
  }
  else if (aCombine == nsClipCombine_kUnion)
  {
    PushClipState();

    HRGN  tregion = ::CreateRectRgn(nr.left,
                                    nr.top,
                                    nr.right,
                                    nr.bottom);

    ::ExtSelectClipRgn(mDC, tregion, RGN_OR);
    ::DeleteObject(tregion);
  }
  else if (aCombine == nsClipCombine_kSubtract)
  {
    PushClipState();

    ::ExcludeClipRect(mDC, nr.left,
                      nr.top,
                      nr.right,
                      nr.bottom);
  }
  else if (aCombine == nsClipCombine_kReplace)
  {
    PushClipState();

    HRGN  tregion = ::CreateRectRgn(nr.left,
                                    nr.top,
                                    nr.right,
                                    nr.bottom);
    ::SelectClipRgn(mDC, tregion);
    ::DeleteObject(tregion);
  }
  else
    NS_ASSERTION(PR_FALSE, "illegal clip combination");

  return NS_OK;
}

Here is the call graph for this function:

Sets the clipping for the RenderingContext to the passed in region.

The region is in device coordinates!

Parameters:
aRegionThe region to set the clipping area to, IN DEVICE COORDINATES
aCombinehow to combine this region with the current clip region. see the bottom of nsIRenderingContext.h

Implements nsIRenderingContext.

Definition at line 863 of file nsRenderingContextWin.cpp.

{
  HRGN        hrgn;
  int         cmode;

  aRegion.GetNativeRegion((void *&)hrgn);

  switch (aCombine)
  {
    case nsClipCombine_kIntersect:
      cmode = RGN_AND;
      break;

    case nsClipCombine_kUnion:
      cmode = RGN_OR;
      break;

    case nsClipCombine_kSubtract:
      cmode = RGN_DIFF;
      break;

    default:
    case nsClipCombine_kReplace:
      cmode = RGN_COPY;
      break;
  }

  if (NULL != hrgn)
  {
    mStates->mFlags &= ~FLAG_LOCAL_CLIP_VALID;
    PushClipState();
    ::ExtSelectClipRgn(mDC, hrgn, cmode);
  }
  else
    return PR_FALSE;

  return NS_OK;
}

Here is the call graph for this function:

Sets the forground color for the RenderingContext.

Parameters:
aColorThe color to set the RenderingContext to

Implements nsIRenderingContext.

Definition at line 953 of file nsRenderingContextWin.cpp.

{
  mCurrentColor = aColor;
  mColor = RGB(NS_GET_R(aColor),
               NS_GET_G(aColor),
               NS_GET_B(aColor));
  return NS_OK;
}
NS_IMETHODIMP nsRenderingContextWin::SetFont ( const nsFont aFont,
nsIAtom aLangGroup 
) [virtual]

Sets the font for the RenderingContext.

Parameters:
aFontThe font to use in the RenderingContext

Implements nsIRenderingContext.

Definition at line 980 of file nsRenderingContextWin.cpp.

{
  mCurrFontWin = nsnull; // owned & released by mFontMetrics
  NS_IF_RELEASE(mFontMetrics);
  mContext->GetMetricsFor(aFont, aLangGroup, mFontMetrics);

  return NS_OK;
}

Here is the call graph for this function:

Sets the font for the RenderingContext.

Parameters:
aFontMetricThe font metrics representing the font to use in the RenderingContext

Implements nsIRenderingContext.

Definition at line 989 of file nsRenderingContextWin.cpp.

{
  mCurrFontWin = nsnull; // owned & released by mFontMetrics
  NS_IF_RELEASE(mFontMetrics);
  mFontMetrics = aFontMetrics;
  NS_IF_ADDREF(mFontMetrics);

  return NS_OK;
}

Sets the line style for the RenderingContext.

Parameters:
aLineStyleThe line style
Returns:
NS_OK if the line style is correctly set

Implements nsIRenderingContext.

Definition at line 968 of file nsRenderingContextWin.cpp.

{
  mCurrLineStyle = aLineStyle;
  return NS_OK;
}

Here is the caller graph for this function:

Sets the Pen Mode for the RenderingContext.

Parameters:
aPenModeThe Pen Mode
Returns:
NS_OK if the Pen Mode is correctly set

Reimplemented from nsRenderingContextImpl.

Definition at line 2749 of file nsRenderingContextWin.cpp.

{

  switch(aPenMode){
  case nsPenMode_kNone:
    ::SetROP2(mDC,R2_COPYPEN);
    mPenMode = nsPenMode_kNone;
    break;
  case nsPenMode_kInvert:
    ::SetROP2(mDC,R2_NOT);
    mPenMode = nsPenMode_kInvert;
    break;
  }

  return NS_OK;
}

Let the device context know whether we want text reordered with right-to-left base direction.

The Windows implementation does this by calling SetTextAlign() to set or clear the flag TA_RTLREADING

Reimplemented from nsRenderingContextImpl.

Definition at line 2886 of file nsRenderingContextWin.cpp.

{
#ifndef WINCE
  // Only call SetTextAlign if the new value is different from the
  // current value
  if (aIsRTL != mRightToLeftText) {
    UINT flags = ::GetTextAlign(mDC);
    if (aIsRTL) {
      flags |= TA_RTLREADING;
    }
    else {
      flags &= (~TA_RTLREADING);
    }
    ::SetTextAlign(mDC, flags);
  }

  mRightToLeftText = aIsRTL;
#endif
  return NS_OK;
}

Definition at line 2703 of file nsRenderingContextWin.cpp.

{
  if ((mCurrentColor != mCurrPenColor) || (NULL == mCurrPen) || (mCurrPen != mStates->mDashedPen))
  {
    HPEN  tpen = ::CreatePen(PS_DASH, 0, PALETTERGB_COLORREF(mColor));

    ::SelectObject(mDC, tpen);

    if (NULL != mCurrPen)
      VERIFY(::DeleteObject(mCurrPen));

    mStates->mDashedPen = mCurrPen = tpen;
    mCurrPenColor = mCurrentColor;
  }

  return mCurrPen;
}

Here is the caller graph for this function:

nsresult nsRenderingContextWin::SetupDC ( HDC  aOldDC,
HDC  aNewDC 
) [private]

Definition at line 432 of file nsRenderingContextWin.cpp.

{
  HBRUSH  prevbrush;
  HFONT   prevfont;
  HPEN    prevpen;

  ::SetTextColor(aNewDC, PALETTERGB_COLORREF(mColor));
  mCurrTextColor = mCurrentColor;
  ::SetBkMode(aNewDC, TRANSPARENT);
#ifndef WINCE
  ::SetPolyFillMode(aNewDC, WINDING);
#endif
  // Temporary fix for bug 135226 until we do better decode-time
  // dithering and paletized storage of images.
  nsPaletteInfo palInfo;
  mContext->GetPaletteInfo(palInfo);
#ifndef WINCE
  if (palInfo.isPaletteDevice)
    ::SetStretchBltMode(aNewDC, HALFTONE);
  else
    ::SetStretchBltMode(aNewDC, COLORONCOLOR);                                  
#endif

  ::SetTextAlign(aNewDC, TA_BASELINE);

  if (nsnull != aOldDC)
  {
    if (nsnull != mOrigSolidBrush)
      prevbrush = (HBRUSH)::SelectObject(aOldDC, mOrigSolidBrush);

    if (nsnull != mOrigFont)
      prevfont = (HFONT)::SelectObject(aOldDC, mOrigFont);

    if (nsnull != mOrigSolidPen)
      prevpen = (HPEN)::SelectObject(aOldDC, mOrigSolidPen);

  }
  else
  {
    prevbrush = gStockWhiteBrush;
    prevfont = gStockSystemFont;
    prevpen = gStockBlackPen;
  }

  mOrigSolidBrush = (HBRUSH)::SelectObject(aNewDC, prevbrush);
  mOrigFont = (HFONT)::SelectObject(aNewDC, prevfont);
  mOrigSolidPen = (HPEN)::SelectObject(aNewDC, prevpen);

#if 0
  GraphicsState *pstate = mStates;

  while ((nsnull != pstate) && !(pstate->mFlags & FLAG_CLIP_VALID))
    pstate = pstate->mNext;

  if (nsnull != pstate)
    ::SelectClipRgn(aNewDC, pstate->mClipRegion);
#endif
  
  // If this is a palette device, then select and realize the palette
  if (palInfo.isPaletteDevice && palInfo.palette)
  {
    // Select the palette in the background
    ::SelectPalette(aNewDC, (HPALETTE)palInfo.palette, PR_TRUE);
    ::RealizePalette(aNewDC);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2721 of file nsRenderingContextWin.cpp.

{
  if ((mCurrentColor != mCurrPenColor) || (NULL == mCurrPen) || (mCurrPen != mStates->mDottedPen))
  {
    HPEN  tpen = ::CreatePen(
#ifndef WINCE
                             PS_DOT, 
#else
                             PS_DASH,
#endif
                             0, PALETTERGB_COLORREF(mColor));


    ::SelectObject(mDC, tpen);

    if (NULL != mCurrPen)
      VERIFY(::DeleteObject(mCurrPen));

    mStates->mDottedPen = mCurrPen = tpen;
    mCurrPenColor = mCurrentColor;
  }

  return mCurrPen;
}

Here is the caller graph for this function:

Definition at line 2620 of file nsRenderingContextWin.cpp.

{
  if (mFontMetrics && (!mCurrFontWin || mCurrFontWin->mFont != mCurrFont)) {
    nsFontHandle  fontHandle;
    mFontMetrics->GetFontHandle(fontHandle);
    HFONT         tfont = (HFONT)fontHandle;

    ::SelectObject(mDC, tfont);

    mCurrFont = tfont;
    mCurrFontWin = ((nsFontMetricsWin*)mFontMetrics)->GetFontFor(mCurrFont);

    // nsFontMetricsWin vs. nsFontMetricsWinA
    // When making changes in the font code, set |useAFunctions = 1| in nsGfxFactoryWin
    // to verify that the changes didn't let the 'A' versions out of sync. 
    NS_ASSERTION(mCurrFontWin, "internal error");
  }

  if (mCurrentColor != mCurrTextColor)
  {
    ::SetTextColor(mDC, PALETTERGB_COLORREF(mColor));
    mCurrTextColor = mCurrentColor;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

HPEN nsRenderingContextWin::SetupPen ( void  ) [private]

Definition at line 2645 of file nsRenderingContextWin.cpp.

{
  HPEN pen;

  switch(mCurrLineStyle)
  {
    case nsLineStyle_kSolid:
      pen = SetupSolidPen();
      break;

    case nsLineStyle_kDashed:
      pen = SetupDashedPen();
      break;

    case nsLineStyle_kDotted:
      pen = SetupDottedPen();
      break;

    case nsLineStyle_kNone:
      pen = NULL;
      break;

    default:
      pen = SetupSolidPen();
      break;
  }

  return pen;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2607 of file nsRenderingContextWin.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2676 of file nsRenderingContextWin.cpp.

{
  if ((mCurrentColor != mCurrPenColor) || (NULL == mCurrPen) || (mCurrPen != mStates->mSolidPen))
  {
    HPEN  tpen;
     
    if (RGB(0, 0, 0) == mColor) {
      tpen = gStockBlackPen;
    } else if (RGB(255, 255, 255) == mColor) {
      tpen = gStockWhitePen;
    } else {
      tpen = ::CreatePen(PS_SOLID, 0, PALETTERGB_COLORREF(mColor));
    }

    ::SelectObject(mDC, tpen);

    if (mCurrPen && (mCurrPen != gStockBlackPen) && (mCurrPen != gStockWhitePen)) {
      VERIFY(::DeleteObject(mCurrPen));
    }

    mStates->mSolidPen = mCurrPen = tpen;
    mCurrPenColor = mCurrentColor;
  }

  return mCurrPen;
}

Here is the caller graph for this function:

Add in a translate to the RenderingContext's transformation matrix.

Parameters:
aXThe horizontal translation
aYThe vertical translation

Implements nsIRenderingContext.

Definition at line 1008 of file nsRenderingContextWin.cpp.

{
       mTranMatrix->AddTranslation((float)aX,(float)aY);
  return NS_OK;
}

Unlock a rect of the drawing surface associated with the rendering context.

see nsIDrawingSurface.h for more information.

Returns:
error status

Implements nsIRenderingContext.

Definition at line 556 of file nsRenderingContextWin.cpp.

{
  PRBool  clipstate;

  mSurface->Unlock();
  mSurface->GetDC(&mDC);

  PopState();

  mSurface->IsReleaseDCDestructive(&clipstate);

  if (clipstate)
  {
    ::SetTextColor(mDC, PALETTERGB_COLORREF(mColor));
    mCurrTextColor = mCurrentColor;

    ::SetBkMode(mDC, TRANSPARENT);
#ifndef WINCE
    ::SetPolyFillMode(mDC, WINDING);
    ::SetStretchBltMode(mDC, COLORONCOLOR);
#endif

    mOrigSolidBrush = (HBRUSH)::SelectObject(mDC, mCurrBrush);
    mOrigFont = (HFONT)::SelectObject(mDC, mCurrFont);
    mOrigSolidPen = (HPEN)::SelectObject(mDC, mCurrPen);
  }

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHODIMP nsRenderingContextImpl::UseBackbuffer ( PRBool aUseBackbuffer) [virtual, inherited]

Some platforms may not want a backbuffer at all.

Returning false here allows them to achieve that

Parameters:
aUseBackbufferPR_TRUE if we should use a backbuffer, PR_FALSE if not

Implements nsIRenderingContext.

Reimplemented in nsRenderingContextMac.

Definition at line 149 of file nsRenderingContextImpl.cpp.

{
  *aUseBackbuffer = PR_TRUE;
  return NS_OK;
}

Friends And Related Function Documentation

friend class nsNativeThemeWin [friend]

Definition at line 258 of file nsRenderingContextWin.h.


Member Data Documentation

int nsRenderingContextImpl::mAct [protected, inherited]

Definition at line 65 of file nsRenderingContextImpl.h.

Edge* nsRenderingContextImpl::mActive [protected, inherited]

Definition at line 66 of file nsRenderingContextImpl.h.

Definition at line 273 of file nsRenderingContextWin.h.

Definition at line 268 of file nsRenderingContextWin.h.

Definition at line 271 of file nsRenderingContextWin.h.

Definition at line 283 of file nsRenderingContextWin.h.

Definition at line 282 of file nsRenderingContextWin.h.

Definition at line 261 of file nsRenderingContextWin.h.

Definition at line 289 of file nsRenderingContextWin.h.

Definition at line 288 of file nsRenderingContextWin.h.

Definition at line 295 of file nsRenderingContextWin.h.

Definition at line 291 of file nsRenderingContextWin.h.

Definition at line 290 of file nsRenderingContextWin.h.

Definition at line 294 of file nsRenderingContextWin.h.

HDC nsRenderingContextWin::mDC [protected]

Definition at line 264 of file nsRenderingContextWin.h.

Definition at line 269 of file nsRenderingContextWin.h.

Definition at line 263 of file nsRenderingContextWin.h.

Definition at line 293 of file nsRenderingContextWin.h.

Definition at line 265 of file nsRenderingContextWin.h.

Definition at line 267 of file nsRenderingContextWin.h.

Definition at line 292 of file nsRenderingContextWin.h.

Definition at line 276 of file nsRenderingContextWin.h.

Definition at line 278 of file nsRenderingContextWin.h.

Definition at line 275 of file nsRenderingContextWin.h.

Definition at line 277 of file nsRenderingContextWin.h.

float nsRenderingContextWin::mP2T [protected]

Definition at line 272 of file nsRenderingContextWin.h.

Definition at line 321 of file nsRenderingContextImpl.h.

Definition at line 300 of file nsRenderingContextWin.h.

Definition at line 281 of file nsRenderingContextWin.h.

Definition at line 280 of file nsRenderingContextWin.h.

Definition at line 266 of file nsRenderingContextWin.h.

nsTransform2D* nsRenderingContextImpl::mTranMatrix [protected, inherited]

Definition at line 64 of file nsRenderingContextImpl.h.


The documentation for this class was generated from the following files: