Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
nsDeviceContextXlib Class Reference

#include <nsDeviceContextXlib.h>

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

List of all members.

Public Member Functions

 nsDeviceContextXlib ()
NS_IMETHOD Init (nsNativeWidget aNativeWidget)
NS_IMETHOD CreateRenderingContext (nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContext (nsIView *aView, nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContext (nsIWidget *aWidget, nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContext (nsIDrawingSurface *aSurface, nsIRenderingContext *&aContext)
NS_IMETHOD CreateRenderingContextInstance (nsIRenderingContext *&aContext)
NS_IMETHOD SupportsNativeWidgets (PRBool &aSupportsWidgets)
NS_IMETHOD GetScrollBarDimensions (float &aWidth, float &aHeight) const
NS_IMETHOD GetSystemFont (nsSystemFontID anID, nsFont *aFont) const
NS_IMETHOD CheckFontExistence (const nsString &aFontName)
NS_IMETHOD GetDeviceSurfaceDimensions (PRInt32 &aWidth, PRInt32 &aHeight)
NS_IMETHOD GetRect (nsRect &aRect)
NS_IMETHOD GetClientRect (nsRect &aRect)
NS_IMETHOD GetDeviceContextFor (nsIDeviceContextSpec *aDevice, nsIDeviceContext *&aContext)
NS_IMETHOD BeginDocument (PRUnichar *aTitle, PRUnichar *aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage)
NS_IMETHOD EndDocument (void)
NS_IMETHOD AbortDocument (void)
NS_IMETHOD BeginPage (void)
NS_IMETHOD EndPage (void)
NS_IMETHOD CreateFontCache ()
NS_IMETHOD GetXlibRgbHandle (XlibRgbHandle *&aHandle)
XlibRgbHandle * GetXlibRgbHandle ()
NS_IMETHOD GetDepth (PRUint32 &depth)
virtual void GetFontMetricsContext (nsFontMetricsXlibContext *&aContext)
virtual void GetRCContext (nsRenderingContextXlibContext *&aContext)

Protected Member Functions

virtual ~nsDeviceContextXlib ()

Private Member Functions

nsresult CommonInit (void)

Private Attributes

PRBool mWriteable
PRUint32 mNumCells
nsIDrawingSurfacemSurface
XlibRgbHandle * mXlibRgbHandle
DisplaymDisplay
Screen * mScreen
Visual * mVisual
int mDepth
float mWidthFloat
float mHeightFloat
PRInt32 mWidth
PRInt32 mHeight

Static Private Attributes

static nsFontMetricsXlibContextmFontMetricsContext = nsnull
static
nsRenderingContextXlibContext
mRCContext = nsnull
static int mContextCounter = 0

Detailed Description

Definition at line 46 of file nsDeviceContextXlib.h.


Constructor & Destructor Documentation

Definition at line 80 of file nsDeviceContextXlib.cpp.

  : nsDeviceContextX()
{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::nsDeviceContextXlib()\n"));
  mTwipsToPixels = 1.0;
  mPixelsToTwips = 1.0;
  mNumCells = 0;
  mSurface = nsnull;
  mDisplay = nsnull;
  mScreen = nsnull;
  mVisual = nsnull;
  mDepth = 0;

  mWidthFloat = 0.0f;
  mHeightFloat = 0.0f;
  mWidth = -1;
  mHeight = -1;
  mXlibRgbHandle = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE);
  if (!mXlibRgbHandle)
    abort();
    
  mContextCounter++;
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 495 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndDocument()\n"));
  return NS_OK;
}
NS_IMETHODIMP nsDeviceContextXlib::BeginDocument ( PRUnichar aTitle,
PRUnichar aPrintToFileName,
PRInt32  aStartPage,
PRInt32  aEndPage 
)

Definition at line 483 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::BeginDocument()\n"));
  return NS_OK;
}

Definition at line 501 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::BeginPage()\n"));
  return NS_OK;
}

Definition at line 369 of file nsDeviceContextXlib.cpp.

Here is the call graph for this function:

Definition at line 161 of file nsDeviceContextXlib.cpp.

{
  nsresult rv = NS_OK;;

  // FIXME: PeterH
  // This was set to 100 dpi, then later on in the function is was changed
  // to a default of 96dpi IF we had a preference component. We need to 
  // find a way to get the actual server dpi for a comparison ala GTK.
  static nscoord dpi = 96;
  static int initialized = 0;

  if (!initialized) {
    initialized = 1;
    nsresult res;
    nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &res));
    if (NS_SUCCEEDED(res) && prefs) {
      PRInt32 intVal = 96;
      res = prefs->GetIntPref("layout.css.dpi", &intVal);
      if (NS_SUCCEEDED(res)) {
        if (intVal) {
          dpi = intVal;
        }
        else {
          // Compute dpi of display
          float screenWidth = float(XWidthOfScreen(mScreen));
          float screenWidthIn = float(XWidthMMOfScreen(mScreen)) / 25.4f;
          dpi = nscoord(screenWidth / screenWidthIn);
        }
      }
    }
  }

  // Do extra rounding (based on GTK). KenF
  mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(72)) / float(dpi)));
  mTwipsToPixels = 1.0f / mPixelsToTwips;

  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("GFX: dpi=%d t2p=%g p2t=%g\n", dpi, mTwipsToPixels, mPixelsToTwips));

  mWidthFloat  = (float) XWidthOfScreen(mScreen);
  mHeightFloat = (float) XHeightOfScreen(mScreen);

  DeviceContextImpl::CommonInit();
  
  if (!mFontMetricsContext)
  {
    rv = CreateFontMetricsXlibContext(this, PR_FALSE, &mFontMetricsContext);
    if (NS_FAILED(rv))
      return rv;
  }

  if (!mRCContext)
  {
    rv = CreateRenderingContextXlibContext(this, &mRCContext);
    if (NS_FAILED(rv))
      return rv;
  }
   
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 533 of file nsDeviceContextXlib.cpp.

{
  mFontCache = new nsFontCacheXlib();
  if (nsnull == mFontCache) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  return mFontCache->Init(this);
}

Definition at line 221 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::CreateRenderingContext()\n"));

#ifdef NS_PRINT_PREVIEW
  /* Defer to Alt when there is one */
  if (mAltDC && ((mUseAltDC & kUseAltDCFor_CREATERC_PAINT) || (mUseAltDC & kUseAltDCFor_CREATERC_REFLOW))) {
    return mAltDC->CreateRenderingContext(aContext);
  }
#endif /* NS_PRINT_PREVIEW */

  nsIRenderingContext      *context;
  nsDrawingSurfaceXlibImpl *surface = nsnull;
  nsresult                  rv;

  context = new nsRenderingContextXlib();

  if (nsnull != context) {
    NS_ADDREF(context);
    surface = new nsDrawingSurfaceXlibImpl();
    if (nsnull != surface) {
      xGC *gc = new xGC(mDisplay, (Drawable)mWidget, 0, nsnull);
      rv = surface->Init(mXlibRgbHandle,
                         (Drawable)mWidget, 
                         gc);

      if (NS_SUCCEEDED(rv)) {
        rv = context->Init(this, surface);
      }
    }
    else {
      rv = NS_ERROR_OUT_OF_MEMORY;
    }
  }
  else {
    rv = NS_ERROR_OUT_OF_MEMORY;
  }
  
  if (NS_FAILED(rv)) {
    NS_IF_RELEASE(context);
  }
  aContext = context;
  
  return rv;
}

Here is the call graph for this function:

Definition at line 54 of file nsDeviceContextXlib.h.

    {return (DeviceContextImpl::CreateRenderingContext(aView, aContext)); }

Definition at line 56 of file nsDeviceContextXlib.h.

    {return (DeviceContextImpl::CreateRenderingContext(aWidget, aContext)); }

Definition at line 58 of file nsDeviceContextXlib.h.

    {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));}

Definition at line 267 of file nsDeviceContextXlib.cpp.

{
  nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextXlib();
  if (!renderingContext)
    return NS_ERROR_OUT_OF_MEMORY;
         
  aContext = renderingContext;
  NS_ADDREF(aContext);
  
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 489 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndDocument()\n"));
  return NS_OK;
}

Definition at line 507 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndPage()\n"));
  return NS_OK;
}

Definition at line 407 of file nsDeviceContextXlib.cpp.

{
  PRInt32 width, height;
  nsresult rv;
  rv = GetDeviceSurfaceDimensions(width, height);
  aRect.x = 0;
  aRect.y = 0;
  aRect.width = width;
  aRect.height = height;
  return rv;
}

Here is the call graph for this function:

Definition at line 88 of file nsDeviceContextXlib.h.

{ depth = (PRUint32)mDepth; return NS_OK; }

Definition at line 419 of file nsDeviceContextXlib.cpp.

{
  nsresult                 rv;
  PrintMethod              method;
  nsDeviceContextSpecXlib *spec = NS_STATIC_CAST(nsDeviceContextSpecXlib *, aDevice);
  
  rv = spec->GetPrintMethod(method);
  if (NS_FAILED(rv)) 
    return rv;

#ifdef USE_XPRINT
  if (method == pmXprint) { // XPRINT
    static NS_DEFINE_CID(kCDeviceContextXp, NS_DEVICECONTEXTXP_CID);
    nsCOMPtr<nsIDeviceContextXp> dcxp(do_CreateInstance(kCDeviceContextXp, &rv));
    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create Xp Device context.");    
    if (NS_FAILED(rv)) 
      return NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE;
    
    rv = dcxp->SetSpec(aDevice);
    if (NS_FAILED(rv)) 
      return rv;
    
    rv = dcxp->InitDeviceContextXP((nsIDeviceContext*)aContext,
                                   (nsIDeviceContext*)this);
    if (NS_FAILED(rv)) 
      return rv;
      
    rv = dcxp->QueryInterface(NS_GET_IID(nsIDeviceContext),
                              (void **)&aContext);
    return rv;
  }
  else
#endif /* USE_XPRINT */
#ifdef USE_POSTSCRIPT
  if (method == pmPostScript) { // PostScript
    // default/PS
    static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID);
  
    // Create a Postscript device context 
    nsCOMPtr<nsIDeviceContextPS> dcps(do_CreateInstance(kCDeviceContextPS, &rv));
    NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create PS Device context.");
    if (NS_FAILED(rv)) 
      return NS_ERROR_GFX_COULD_NOT_LOAD_PRINT_MODULE;
  
    rv = dcps->SetSpec(aDevice);
    if (NS_FAILED(rv)) 
      return rv;
      
    rv = dcps->InitDeviceContextPS((nsIDeviceContext*)aContext,
                                   (nsIDeviceContext*)this);
    if (NS_FAILED(rv)) 
      return rv;

    rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext),
                              (void **)&aContext);
    return rv;
  }
#endif /* USE_POSTSCRIPT */  
  
  NS_WARNING("no print module created.");
  return NS_ERROR_UNEXPECTED;
}

Here is the call graph for this function:

Definition at line 374 of file nsDeviceContextXlib.cpp.

{
#ifdef NS_PRINT_PREVIEW                                                         
  /* Defer to Alt when there is one */
  if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) {
    return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight);
  }
#endif /* NS_PRINT_PREVIEW */
 
  if (mWidth == -1)
    mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits);

  if (mHeight == -1)
    mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits);

  aWidth = mWidth;
  aHeight = mHeight;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void nsDeviceContextXlib::GetFontMetricsContext ( nsFontMetricsXlibContext *&  aContext) [inline, virtual]

Implements nsDeviceContextX.

Definition at line 89 of file nsDeviceContextXlib.h.

{ aContext = mFontMetricsContext; };
virtual void nsDeviceContextXlib::GetRCContext ( nsRenderingContextXlibContext *&  aContext) [inline, virtual]

Implements nsDeviceContextX.

Definition at line 90 of file nsDeviceContextXlib.h.

{ aContext = mRCContext; };

Definition at line 395 of file nsDeviceContextXlib.cpp.

{
  PRInt32 width, height;
  nsresult rv;
  rv = GetDeviceSurfaceDimensions(width, height);
  aRect.x = 0;
  aRect.y = 0;
  aRect.width = width;
  aRect.height = height;
  return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsDeviceContextXlib::GetScrollBarDimensions ( float &  aWidth,
float &  aHeight 
) const

Definition at line 286 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::GetScrollBarDimensions()\n"));
  float scale;
  GetCanonicalPixelScale(scale);
  // XXX Oh, yeah.  These are hard coded.
  aWidth = 15 * mPixelsToTwips * scale;
  aHeight = 15 * mPixelsToTwips * scale;

  return NS_OK;
}

Definition at line 298 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::GetSystemFont()\n"));

  switch (anID) {
    case eSystemFont_Caption:              // css2
    case eSystemFont_Icon:
    case eSystemFont_Menu:
    case eSystemFont_MessageBox:
    case eSystemFont_SmallCaption:
    case eSystemFont_StatusBar:
    case eSystemFont_Window:                       // css3
    case eSystemFont_Document:
    case eSystemFont_Workspace:
    case eSystemFont_Desktop:
    case eSystemFont_Info:
    case eSystemFont_Dialog:
    case eSystemFont_Button:
    case eSystemFont_PullDownMenu:
    case eSystemFont_List:
    case eSystemFont_Field:
    case eSystemFont_Tooltips:             // moz
    case eSystemFont_Widget:
      aFont->style       = NS_FONT_STYLE_NORMAL;
      aFont->weight      = NS_FONT_WEIGHT_NORMAL;
      aFont->decorations = NS_FONT_DECORATION_NONE;

      if (!mDefaultFont)
        return NS_ERROR_FAILURE;
      else
      {
        char *fontName = nsnull;
        unsigned long pr = 0;

        ::XGetFontProperty(mDefaultFont, XA_FULL_NAME, &pr);
        if(pr)
          {
            fontName = XGetAtomName(mDisplay, pr);
            aFont->name.AssignWithConversion(fontName);
            ::XFree(fontName);
          }
  
        pr = 0;
        ::XGetFontProperty(mDefaultFont, XA_WEIGHT, &pr);
        if ( pr > 10 )
          aFont->weight = NS_FONT_WEIGHT_BOLD;
    
        pr = 0;
        Atom pixelSizeAtom = ::XInternAtom(mDisplay, "PIXEL_SIZE", 0);
        ::XGetFontProperty(mDefaultFont, pixelSizeAtom, &pr);
        if( pr )
          aFont->size = NSIntPixelsToTwips(pr, mPixelsToTwips);

        pr = 0;
        ::XGetFontProperty(mDefaultFont, XA_ITALIC_ANGLE, &pr );
        if( pr )
          aFont->style = NS_FONT_STYLE_ITALIC;
    
        pr = 0;
        ::XGetFontProperty(mDefaultFont, XA_UNDERLINE_THICKNESS, &pr);
        if( pr )
          aFont->decorations = NS_FONT_DECORATION_UNDERLINE;
      }
      break;
  }

  aFont->systemFont = PR_TRUE;

  return NS_OK;
}

Here is the call graph for this function:

NS_IMETHOD nsDeviceContextXlib::GetXlibRgbHandle ( XlibRgbHandle *&  aHandle) [inline, virtual]

Implements nsDeviceContextX.

Definition at line 85 of file nsDeviceContextXlib.h.

             { aHandle =  mXlibRgbHandle; return NS_OK; }
XlibRgbHandle* nsDeviceContextXlib::GetXlibRgbHandle ( ) [inline]

Definition at line 87 of file nsDeviceContextXlib.h.

{ return mXlibRgbHandle; }

Definition at line 125 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::Init()\n"));

  mWidget = aNativeWidget;

  mDisplay = xxlib_rgb_get_display(mXlibRgbHandle);
  mScreen  = xxlib_rgb_get_screen(mXlibRgbHandle);
  mVisual  = xxlib_rgb_get_visual(mXlibRgbHandle);
  mDepth   = xxlib_rgb_get_depth(mXlibRgbHandle);

  if (!mDefaultFont)
    mDefaultFont = XLoadQueryFont(mDisplay, XLIB_DEFAULT_FONT1);

  if (!mDefaultFont)
    mDefaultFont = XLoadQueryFont(mDisplay, XLIB_DEFAULT_FONT2);

#ifdef DEBUG
  static PRBool once = PR_TRUE;

  if (once)
  {
    once = PR_FALSE;

    printf("nsDeviceContextXlib::Init(dpy=%p  screen=%p  visual=%p  depth=%d)\n",
           mDisplay,
           mScreen,
           mVisual,
           mDepth);
  }
#endif /* DEBUG */

  return CommonInit();
}

Here is the call graph for this function:

Definition at line 279 of file nsDeviceContextXlib.cpp.

{
  PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::SupportsNativeWidgets()\n"));
  aSupportsWidgets = PR_TRUE;
  return NS_OK;
}

Member Data Documentation

Definition at line 107 of file nsDeviceContextXlib.h.

Definition at line 104 of file nsDeviceContextXlib.h.

Definition at line 101 of file nsDeviceContextXlib.h.

Definition at line 105 of file nsDeviceContextXlib.h.

Definition at line 112 of file nsDeviceContextXlib.h.

Definition at line 110 of file nsDeviceContextXlib.h.

Definition at line 98 of file nsDeviceContextXlib.h.

Definition at line 106 of file nsDeviceContextXlib.h.

Screen* nsDeviceContextXlib::mScreen [private]

Definition at line 102 of file nsDeviceContextXlib.h.

Definition at line 99 of file nsDeviceContextXlib.h.

Visual* nsDeviceContextXlib::mVisual [private]

Definition at line 103 of file nsDeviceContextXlib.h.

Definition at line 111 of file nsDeviceContextXlib.h.

Definition at line 109 of file nsDeviceContextXlib.h.

Definition at line 97 of file nsDeviceContextXlib.h.

XlibRgbHandle* nsDeviceContextXlib::mXlibRgbHandle [private]

Definition at line 100 of file nsDeviceContextXlib.h.


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