Back to index

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

#include <nsDeviceContextGTK.h>

Collaboration diagram for nsDeviceContextGTK:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsDeviceContextGTK ()
virtual ~nsDeviceContextGTK ()
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 GetClientRect (nsRect &aRect)
NS_IMETHOD GetRect (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 GetDepth (PRUint32 &aDepth)

Static Public Member Functions

static void Shutdown ()
static int prefChanged (const char *aPref, void *aClosure)
static void ClearCachedSystemFonts ()

Protected Member Functions

nsresult SetDPI (PRInt32 aPrefDPI)

Private Member Functions

nsresult GetSystemFontInfo (GdkFont *iFont, nsSystemFontID anID, nsFont *aFont) const

Private Attributes

PRUint32 mDepth
PRBool mWriteable
PRUint32 mNumCells
PRInt16 mScrollbarHeight
PRInt16 mScrollbarWidth
float mWidthFloat
float mHeightFloat
PRInt32 mWidth
PRInt32 mHeight
GdkWindow * mDeviceWindow
nsCOMPtr< nsIScreenManagermScreenManager

Static Private Attributes

static nscoord mDpi = 96

Detailed Description

Definition at line 50 of file nsDeviceContextGTK.h.


Constructor & Destructor Documentation

Definition at line 142 of file nsDeviceContextGTK.cpp.

  : DeviceContextImpl()
{
  mTwipsToPixels = 1.0;
  mPixelsToTwips = 1.0;
  mDepth = 0 ;
  mNumCells = 0;

  mWidthFloat = 0.0f;
  mHeightFloat = 0.0f;
  mWidth = -1;
  mHeight = -1;
  mDeviceWindow = nsnull;
}

Definition at line 157 of file nsDeviceContextGTK.cpp.

{
  nsresult rv;
  nsCOMPtr<nsIPref> prefs = do_GetService(kPrefCID, &rv);
  if (NS_SUCCEEDED(rv)) {
    prefs->UnregisterCallback("layout.css.dpi",
                              prefChanged, (void *)this);
  }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 611 of file nsDeviceContextGTK.cpp.

{
  return NS_OK;
}
NS_IMETHODIMP nsDeviceContextGTK::BeginDocument ( PRUnichar aTitle,
PRUnichar aPrintToFileName,
PRInt32  aStartPage,
PRInt32  aEndPage 
)

Definition at line 601 of file nsDeviceContextGTK.cpp.

{
  return NS_OK;
}

Definition at line 616 of file nsDeviceContextGTK.cpp.

{
  return NS_OK;
}

Definition at line 445 of file nsDeviceContextGTK.cpp.

{
  return NS_FontMetricsFamilyExists(this, aFontName);
}

Here is the call graph for this function:

Definition at line 681 of file nsDeviceContextGTK.cpp.

{
  //clear our cache of stored system fonts
  if (gSystemFonts) {
    delete gSystemFonts;
    gSystemFonts = nsnull;
  }
}

Here is the caller graph for this function:

Definition at line 297 of file nsDeviceContextGTK.cpp.

{
#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

  nsIRenderingContext *pContext;
  nsresult             rv;
  nsDrawingSurfaceGTK  *surf;
  GtkWidget *w;

  w = (GtkWidget*)mWidget;

  // to call init for this, we need to have a valid nsDrawingSurfaceGTK created
  pContext = new nsRenderingContextGTK();

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

    // create the nsDrawingSurfaceGTK
    surf = new nsDrawingSurfaceGTK();

    if (surf && w)
      {
        GdkDrawable *gwin = nsnull;
        GdkDrawable *win = nsnull;
        // FIXME
        if (GTK_IS_LAYOUT(w))
          gwin = (GdkDrawable*)GTK_LAYOUT(w)->bin_window;
        else
          gwin = (GdkDrawable*)(w)->window;

        // window might not be realized... ugh
        if (gwin)
          gdk_window_ref(gwin);
        else {
          win = gdk_pixmap_new(nsnull,
                               w->allocation.width,
                               w->allocation.height,
                               gdk_rgb_get_visual()->depth);
#ifdef MOZ_WIDGET_GTK2
          gdk_drawable_set_colormap(win, gdk_rgb_get_colormap());
#endif
        }

        GdkGC *gc = gdk_gc_new(win);

        // init the nsDrawingSurfaceGTK
        rv = surf->Init(win,gc);

        if (NS_OK == rv)
          // Init the nsRenderingContextGTK
          rv = pContext->Init(this, surf);
      }
    else
      rv = NS_ERROR_OUT_OF_MEMORY;
  }
  else
    rv = NS_ERROR_OUT_OF_MEMORY;

  if (NS_OK != rv)
  {
    NS_IF_RELEASE(pContext);
  }

  aContext = pContext;

  return rv;
}

Here is the call graph for this function:

Definition at line 61 of file nsDeviceContextGTK.h.

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

Definition at line 62 of file nsDeviceContextGTK.h.

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

Definition at line 63 of file nsDeviceContextGTK.h.

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

Definition at line 371 of file nsDeviceContextGTK.cpp.

{
  nsCOMPtr<nsIRenderingContext> renderingContext = new nsRenderingContextGTK();
  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 606 of file nsDeviceContextGTK.cpp.

{
  return NS_OK;
}

Definition at line 621 of file nsDeviceContextGTK.cpp.

{
  return NS_OK;
}

Definition at line 505 of file nsDeviceContextGTK.cpp.

{
  // if we have an initialized widget for this device context, use it
  // to try and get real screen coordinates.
  if (mDeviceWindow) {
    gint x, y, width, height, depth;
    x = y = width = height = 0;

    gdk_window_get_geometry(mDeviceWindow, &x, &y, &width, &height,
                            &depth);
    gdk_window_get_origin(mDeviceWindow, &x, &y);

    nsCOMPtr<nsIScreen> screen;
    mScreenManager->ScreenForRect(x, y, width, height, getter_AddRefs(screen));
    screen->GetAvailRect(&aRect.x, &aRect.y, &aRect.width, &aRect.height);
    aRect.x = NSToIntRound(mDevUnitsToAppUnits * aRect.x);
    aRect.y = NSToIntRound(mDevUnitsToAppUnits * aRect.y);
    aRect.width = NSToIntRound(mDevUnitsToAppUnits * aRect.width);
    aRect.height = NSToIntRound(mDevUnitsToAppUnits * aRect.height);
  }
  else {
    PRInt32 width, height;
    GetDeviceSurfaceDimensions(width, height);
    aRect.x = 0;
    aRect.y = 0;
    aRect.width = width;
    aRect.height = height;
  }

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 626 of file nsDeviceContextGTK.cpp.

{
  aDepth = mDepth;
  return NS_OK;
}

Definition at line 537 of file nsDeviceContextGTK.cpp.

{
  nsresult                 rv;
  PrintMethod              method;
  nsDeviceContextSpecGTK  *spec = NS_STATIC_CAST(nsDeviceContextSpecGTK *, 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 450 of file nsDeviceContextGTK.cpp.

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

  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:

Definition at line 473 of file nsDeviceContextGTK.cpp.

{
  // if we have an initialized widget for this device context, use it
  // to try and get real screen coordinates.
  if (mDeviceWindow) {
    gint x, y, width, height, depth;
    x = y = width = height = 0;

    gdk_window_get_geometry(mDeviceWindow, &x, &y, &width, &height,
                            &depth);
    gdk_window_get_origin(mDeviceWindow, &x, &y);

    nsCOMPtr<nsIScreen> screen;
    mScreenManager->ScreenForRect(x, y, width, height, getter_AddRefs(screen));
    screen->GetRect(&aRect.x, &aRect.y, &aRect.width, &aRect.height);
    aRect.x = NSToIntRound(mDevUnitsToAppUnits * aRect.x);
    aRect.y = NSToIntRound(mDevUnitsToAppUnits * aRect.y);
    aRect.width = NSToIntRound(mDevUnitsToAppUnits * aRect.width);
    aRect.height = NSToIntRound(mDevUnitsToAppUnits * aRect.height);
  }
  else {
    PRInt32 width, height;
    GetDeviceSurfaceDimensions(width, height);
    aRect.x = 0;
    aRect.y = 0;
    aRect.width = width;
    aRect.height = height;
  }
  return NS_OK;
}

Here is the call graph for this function:

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

Definition at line 392 of file nsDeviceContextGTK.cpp.

{
  float scale;
  GetCanonicalPixelScale(scale);
  aWidth = mScrollbarWidth * mPixelsToTwips * scale;
  aHeight = mScrollbarHeight * mPixelsToTwips * scale;

  return NS_OK;
}

Definition at line 402 of file nsDeviceContextGTK.cpp.

{
  nsresult status = NS_OK;

  if (!gSystemFonts) {
    gSystemFonts = new nsSystemFontsGTK(mPixelsToTwips);
  }

  switch (aID) {
    case eSystemFont_Menu:         // css2
    case eSystemFont_PullDownMenu: // css3
        *aFont = gSystemFonts->GetMenuFont();
        break;

    case eSystemFont_Field:        // css3
    case eSystemFont_List:         // css3
        *aFont = gSystemFonts->GetFieldFont();
        break;

    case eSystemFont_Button:       // css3
        *aFont = gSystemFonts->GetButtonFont();
        break;

    case eSystemFont_Caption:      // css2
    case eSystemFont_Icon:         // css2
    case eSystemFont_MessageBox:   // css2
    case eSystemFont_SmallCaption: // css2
    case eSystemFont_StatusBar:    // css2
    case eSystemFont_Window:       // css3
    case eSystemFont_Document:     // css3
    case eSystemFont_Workspace:    // css3
    case eSystemFont_Desktop:      // css3
    case eSystemFont_Info:         // css3
    case eSystemFont_Dialog:       // css3
    case eSystemFont_Tooltips:     // moz
    case eSystemFont_Widget:       // moz
        *aFont = gSystemFonts->GetDefaultFont();
        break;
  }

  return status;
}

Here is the call graph for this function:

nsresult nsDeviceContextGTK::GetSystemFontInfo ( GdkFont *  iFont,
nsSystemFontID  anID,
nsFont aFont 
) const [private]

Definition at line 175 of file nsDeviceContextGTK.cpp.

{
  GtkRequisition req;
  GtkWidget *sb;
  
  // get the screen object and its width/height
  // XXXRight now this will only get the primary monitor.

  if (!mScreenManager)
    mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
  if (!mScreenManager) {
    return NS_ERROR_FAILURE;
  }

#ifdef MOZ_WIDGET_GTK

  if (aNativeWidget) {
    // superwin?
    if (GDK_IS_SUPERWIN(aNativeWidget)) {
      mDeviceWindow = GDK_SUPERWIN(aNativeWidget)->shell_window;
    }
    // gtk widget?
    else if (GTK_IS_WIDGET(aNativeWidget)) {
      mDeviceWindow = GTK_WIDGET(aNativeWidget)->window;
    }
    // must be a bin_window
    else {
      mDeviceWindow = NS_STATIC_CAST(GdkWindow *, aNativeWidget);
    }
  }

#endif /* MOZ_WIDGET_GTK */

#ifdef MOZ_WIDGET_GTK2

  if (aNativeWidget) {
    // can only be a gdk window
    if (GDK_IS_WINDOW(aNativeWidget))
      mDeviceWindow = GDK_WINDOW(aNativeWidget);
    else 
      NS_WARNING("unsupported native widget type!");
  }

#endif

  nsCOMPtr<nsIScreen> screen;
  mScreenManager->GetPrimaryScreen ( getter_AddRefs(screen) );
  if ( screen ) {
    PRInt32 x, y, width, height, depth;
    screen->GetRect ( &x, &y, &width, &height );
    screen->GetPixelDepth ( &depth );
    mWidthFloat = float(width);
    mHeightFloat = float(height);
    mDepth = NS_STATIC_CAST ( PRUint32, depth );
  }
    
  static int initialized = 0;
  PRInt32 prefVal = -1;
  if (!initialized) {
    initialized = 1;

    // Set prefVal the value of the preference
    // "layout.css.dpi"
    // or -1 if we can't get it.
    // If it's negative, we pretend it's not set.
    // If it's 0, it means force use of the operating system's logical
    // resolution.
    // If it's positive, we use it as the logical resolution
    nsresult res;

    nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &res));
    if (NS_SUCCEEDED(res) && prefs) {
      res = prefs->GetIntPref("layout.css.dpi", &prefVal);
      if (NS_FAILED(res)) {
        prefVal = -1;
      }
      prefs->RegisterCallback("layout.css.dpi", prefChanged,
                              (void *)this);
    }

    SetDPI(prefVal);
  } else {
    SetDPI(mDpi); // to setup p2t and t2p
  }

  sb = gtk_vscrollbar_new(NULL);
  gtk_widget_ref(sb);
  gtk_object_sink(GTK_OBJECT(sb));
#ifdef MOZ_WIDGET_GTK2
  gtk_widget_ensure_style(sb);
  gtk_widget_queue_resize(sb);
#endif /* MOZ_WIDGET_GTK2 */
  gtk_widget_size_request(sb,&req);
  mScrollbarWidth = req.width;
  gtk_widget_destroy(sb);
  gtk_widget_unref(sb);
  
  sb = gtk_hscrollbar_new(NULL);
  gtk_widget_ref(sb);
  gtk_object_sink(GTK_OBJECT(sb));
#ifdef MOZ_WIDGET_GTK2
  gtk_widget_ensure_style(sb);
  gtk_widget_queue_resize(sb);
#endif /* MOZ_WIDGET_GTK2 */
  gtk_widget_size_request(sb,&req);
  mScrollbarHeight = req.height;
  gtk_widget_destroy(sb);
  gtk_widget_unref(sb);

#ifdef DEBUG
  static PRBool once = PR_TRUE;
  if (once) {
    printf("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n", mDpi, mTwipsToPixels, mPixelsToTwips,mDepth);
    once = PR_FALSE;
  }
#endif

  DeviceContextImpl::CommonInit();

  return NS_OK;
}

Here is the call graph for this function:

int nsDeviceContextGTK::prefChanged ( const char *  aPref,
void aClosure 
) [static]

Definition at line 661 of file nsDeviceContextGTK.cpp.

{
  nsDeviceContextGTK *context = (nsDeviceContextGTK*)aClosure;
  nsresult rv;
  
  if (nsCRT::strcmp(aPref, "layout.css.dpi")==0) {
    PRInt32 dpi;
    nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &rv));
    rv = prefs->GetIntPref(aPref, &dpi);
    if (NS_SUCCEEDED(rv))
      context->SetDPI(dpi);

    // If this pref changes, we have to clear our cache of stored system
    // fonts.
    ClearCachedSystemFonts();
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsDeviceContextGTK::SetDPI ( PRInt32  aPrefDPI) [protected]

Definition at line 633 of file nsDeviceContextGTK.cpp.

{
  PRInt32 OSVal = GetOSDPI();

  if (aPrefDPI > 0) {
    // If there's a valid pref value for the logical resolution,
    // use it.
    mDpi = aPrefDPI;
  } else if ((aPrefDPI == 0) || (OSVal > 96)) {
    // Either if the pref is 0 (force use of OS value) or the OS
    // value is bigger than 96, use the OS value.
    mDpi = OSVal;
  } else {
    // if we couldn't get the pref or it's negative, and the OS
    // value is under 96ppi, then use 96.
    mDpi = 96;
  }
  
  int pt2t = 72;

  // make p2t a nice round number - this prevents rounding problems
  mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(mDpi)));
  mTwipsToPixels = 1.0f / mPixelsToTwips;

  // XXX need to reflow all documents
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 167 of file nsDeviceContextGTK.cpp.

{
  if (gSystemFonts) {
    delete gSystemFonts;
    gSystemFonts = nsnull;
  }
}

Here is the caller graph for this function:

Definition at line 383 of file nsDeviceContextGTK.cpp.

{
  //XXX it is very critical that this not lie!! MMP
  // read the comments in the mac code for this
  aSupportsWidgets = PR_TRUE;

  return NS_OK;
}

Member Data Documentation

Definition at line 96 of file nsDeviceContextGTK.h.

GdkWindow* nsDeviceContextGTK::mDeviceWindow [private]

Definition at line 107 of file nsDeviceContextGTK.h.

nscoord nsDeviceContextGTK::mDpi = 96 [static, private]

Definition at line 101 of file nsDeviceContextGTK.h.

Definition at line 106 of file nsDeviceContextGTK.h.

Definition at line 104 of file nsDeviceContextGTK.h.

Definition at line 98 of file nsDeviceContextGTK.h.

Definition at line 109 of file nsDeviceContextGTK.h.

Definition at line 99 of file nsDeviceContextGTK.h.

Definition at line 100 of file nsDeviceContextGTK.h.

Definition at line 105 of file nsDeviceContextGTK.h.

Definition at line 103 of file nsDeviceContextGTK.h.

Definition at line 97 of file nsDeviceContextGTK.h.


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