Back to index

lightning-sunbird  0.9+nobinonly
nsGfxFactoryGTK.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Christopher Blizzard.
00019  * Portions created by the Initial Developer are Copyright (C) 2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Christopher Blizzzard <blizzard@mozilla.org>
00024  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "gfx-config.h"
00041 #include "nsIGenericFactory.h"
00042 #include "nsIModule.h"
00043 #include "nsCOMPtr.h"
00044 #include "nsGfxCIID.h"
00045 
00046 #include "nsBlender.h"
00047 #include "nsRenderingContextGTK.h"
00048 #include "nsDeviceContextGTK.h"
00049 // aka    nsDeviceContextSpecGTK.h
00050 #include "nsDeviceContextSpecG.h"
00051 // aka    nsDeviceContextSpecFactoryGTK.h
00052 #include "nsDeviceContextSpecFactoryG.h"
00053 #include "nsScreenManagerGtk.h"
00054 #include "nsScriptableRegion.h"
00055 #include "nsDeviceContextGTK.h"
00056 #include "nsImageGTK.h"
00057 #include "nsPrintOptionsGTK.h"
00058 #include "nsFontList.h"
00059 #include "nsRegionGTK.h"
00060 #include "nsGCCache.h"
00061 #ifdef NATIVE_THEME_SUPPORT
00062 #include "nsNativeThemeGTK.h"
00063 #endif
00064 #ifdef MOZ_ENABLE_PANGO
00065 #include "nsFontMetricsPango.h"
00066 #endif
00067 #ifdef MOZ_ENABLE_XFT
00068 #include "nsFontMetricsXft.h"
00069 #endif
00070 #ifdef MOZ_ENABLE_COREXFONTS
00071 #include "nsFontMetricsGTK.h"
00072 #endif
00073 #include "nsFontMetricsUtils.h"
00074 #include "nsPrintSession.h"
00075 #include "gfxImageFrame.h"
00076 #ifdef MOZ_ENABLE_FREETYPE2
00077 #include "nsFT2FontCatalog.h"
00078 #include "nsFreeType.h"
00079 #endif
00080 
00081 // objects that just require generic constructors
00082 
00083 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextGTK)
00084 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextGTK)
00085 NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageGTK)
00086 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender)
00087 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionGTK)
00088 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecGTK)
00089 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryGTK)
00090 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList)
00091 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk)
00092 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsGTK, Init)
00093 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK)
00094 #ifdef NATIVE_THEME_SUPPORT
00095 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK)
00096 #endif
00097 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
00098 NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
00099 #ifdef MOZ_ENABLE_FREETYPE2
00100 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFT2FontCatalog)
00101 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFreeType2, Init)
00102 #endif
00103 
00104 // our custom constructors
00105 
00106 static nsresult
00107 nsFontMetricsConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00108 {
00109   nsIFontMetrics *result;
00110 
00111   if (!aResult)
00112     return NS_ERROR_NULL_POINTER;
00113 
00114   *aResult = nsnull;
00115 
00116   if (aOuter)
00117     return NS_ERROR_NO_AGGREGATION;
00118 
00119 #ifdef MOZ_ENABLE_PANGO
00120   if (NS_IsPangoEnabled()) {
00121     result = new nsFontMetricsPango();
00122     if (!result)
00123       return NS_ERROR_OUT_OF_MEMORY;
00124   } else {
00125 #endif
00126 #ifdef MOZ_ENABLE_XFT
00127   if (NS_IsXftEnabled()) {
00128     result = new nsFontMetricsXft();
00129     if (!result)
00130       return NS_ERROR_OUT_OF_MEMORY;
00131   } else {
00132 #endif
00133 #ifdef MOZ_ENABLE_COREXFONTS
00134     result = new nsFontMetricsGTK();
00135     if (!result)
00136       return NS_ERROR_OUT_OF_MEMORY;
00137 #endif
00138 #ifdef MOZ_ENABLE_XFT
00139   }
00140 #endif
00141 #ifdef MOZ_ENABLE_PANGO
00142   }
00143 #endif
00144 
00145   NS_ADDREF(result);
00146   nsresult rv = result->QueryInterface(aIID, aResult);
00147   NS_RELEASE(result);
00148 
00149   return rv;
00150 }
00151 
00152 static nsresult
00153 nsFontEnumeratorConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00154 {
00155   nsIFontEnumerator *result;
00156 
00157   if (!aResult)
00158     return NS_ERROR_NULL_POINTER;
00159 
00160   *aResult = nsnull;
00161 
00162   if (aOuter)
00163     return NS_ERROR_NO_AGGREGATION;
00164 
00165 #ifdef MOZ_ENABLE_PANGO
00166   if (NS_IsPangoEnabled()) {
00167     result = new nsFontEnumeratorPango();
00168     if (!result)
00169       return NS_ERROR_OUT_OF_MEMORY;
00170   } else {
00171 #endif
00172 #ifdef MOZ_ENABLE_XFT
00173   if (NS_IsXftEnabled()) {
00174     result = new nsFontEnumeratorXft();
00175     if (!result)
00176       return NS_ERROR_OUT_OF_MEMORY;
00177   } else {
00178 #endif
00179 #ifdef MOZ_ENABLE_COREXFONTS
00180     result = new nsFontEnumeratorGTK();
00181     if (!result)
00182       return NS_ERROR_OUT_OF_MEMORY;
00183 #endif
00184 #ifdef MOZ_ENABLE_XFT
00185   }
00186 #endif
00187 #ifdef MOZ_ENABLE_PANGO
00188   }
00189 #endif
00190 
00191   NS_ADDREF(result);
00192   nsresult rv = result->QueryInterface(aIID, aResult);
00193   NS_RELEASE(result);
00194 
00195   return rv;
00196 }
00197 
00198 static NS_IMETHODIMP nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
00199 {
00200   nsresult rv;
00201 
00202   nsIScriptableRegion *inst;
00203 
00204   if ( !aResult )
00205   {
00206     rv = NS_ERROR_NULL_POINTER;
00207     return rv;
00208   }
00209   *aResult = nsnull;
00210   if (aOuter)
00211   {
00212     rv = NS_ERROR_NO_AGGREGATION;
00213     return rv;
00214   }
00215   // create an nsRegionGtk and get the scriptable region from it
00216   nsCOMPtr <nsIRegion> rgn;
00217   NS_NEWXPCOM(rgn, nsRegionGTK);
00218   nsCOMPtr<nsIScriptableRegion> scriptableRgn;
00219   if (rgn != nsnull)
00220   {
00221     scriptableRgn = new nsScriptableRegion(rgn);
00222     inst = scriptableRgn;
00223   }
00224   if (!inst)
00225   {
00226     rv = NS_ERROR_OUT_OF_MEMORY;
00227     return rv;
00228   }
00229   NS_ADDREF(inst);
00230   // release our variable above now that we have created our owning
00231   // reference - we don't want this to go out of scope early!
00232   scriptableRgn = nsnull;
00233   rv = inst->QueryInterface(aIID, aResult);
00234   NS_RELEASE(inst);
00235 
00236   return rv;
00237 }
00238 
00239 static const nsModuleComponentInfo components[] =
00240 {
00241   { "Gtk Font Metrics",
00242     NS_FONT_METRICS_CID,
00243     //    "@mozilla.org/gfx/font_metrics/gtk;1",
00244     "@mozilla.org/gfx/fontmetrics;1",
00245     nsFontMetricsConstructor },
00246   { "Gtk Device Context",
00247     NS_DEVICE_CONTEXT_CID,
00248     //    "@mozilla.org/gfx/device_context/gtk;1",
00249     "@mozilla.org/gfx/devicecontext;1",
00250     nsDeviceContextGTKConstructor },
00251   { "Gtk Rendering Context",
00252     NS_RENDERING_CONTEXT_CID,
00253     //    "@mozilla.org/gfx/rendering_context/gtk;1",
00254     "@mozilla.org/gfx/renderingcontext;1",
00255     nsRenderingContextGTKConstructor },
00256   { "Gtk Image",
00257     NS_IMAGE_CID,
00258     //    "@mozilla.org/gfx/image/gtk;1",
00259     "@mozilla.org/gfx/image;1",
00260     nsImageGTKConstructor },
00261   { "Gtk Region",
00262     NS_REGION_CID,
00263     "@mozilla.org/gfx/region/gtk;1",
00264     nsRegionGTKConstructor },
00265   { "Scriptable Region",
00266     NS_SCRIPTABLE_REGION_CID,
00267     //    "@mozilla.org/gfx/scriptable_region;1",
00268     "@mozilla.org/gfx/region;1",
00269     nsScriptableRegionConstructor },
00270   { "Blender",
00271     NS_BLENDER_CID,
00272     //    "@mozilla.org/gfx/blender;1",
00273     "@mozilla.org/gfx/blender;1",
00274     nsBlenderConstructor },
00275   { "Gtk Device Context Spec",
00276     NS_DEVICE_CONTEXT_SPEC_CID,
00277     //    "@mozilla.org/gfx/device_context_spec/gtk;1",
00278     "@mozilla.org/gfx/devicecontextspec;1",
00279     nsDeviceContextSpecGTKConstructor },
00280   { "Gtk Device Context Spec Factory",
00281     NS_DEVICE_CONTEXT_SPEC_FACTORY_CID,
00282     //    "@mozilla.org/gfx/device_context_spec_factory/gtk;1",
00283     "@mozilla.org/gfx/devicecontextspecfactory;1",
00284     nsDeviceContextSpecFactoryGTKConstructor },
00285   { "PrintSettings Service",
00286     NS_PRINTSETTINGSSERVICE_CID,
00287     //    "@mozilla.org/gfx/printsettings-service;1",
00288     "@mozilla.org/gfx/printsettings-service;1",
00289     nsPrintOptionsGTKConstructor },
00290   { "GTK Font Enumerator",
00291     NS_FONT_ENUMERATOR_CID,
00292     //    "@mozilla.org/gfx/font_enumerator/gtk;1",
00293     "@mozilla.org/gfx/fontenumerator;1",
00294     nsFontEnumeratorConstructor },
00295   { "Font List",  
00296     NS_FONTLIST_CID,
00297     //    "@mozilla.org/gfx/fontlist;1"
00298     NS_FONTLIST_CONTRACTID,
00299     nsFontListConstructor },
00300   { "Gtk Screen Manager",
00301     NS_SCREENMANAGER_CID,
00302     //    "@mozilla.org/gfx/screenmanager/gtk;1",
00303     "@mozilla.org/gfx/screenmanager;1",
00304     nsScreenManagerGtkConstructor },
00305   { "Gtk Printer Enumerator",
00306     NS_PRINTER_ENUMERATOR_CID,
00307     //    "@mozilla.org/gfx/printer_enumerator/gtk;1",
00308     "@mozilla.org/gfx/printerenumerator;1",
00309     nsPrinterEnumeratorGTKConstructor },
00310   { "windows image frame",
00311     GFX_IMAGEFRAME_CID,
00312     "@mozilla.org/gfx/image/frame;2",
00313     gfxImageFrameConstructor, },
00314   { "Print Session",
00315     NS_PRINTSESSION_CID,
00316     "@mozilla.org/gfx/printsession;1",
00317     nsPrintSessionConstructor },
00318 #ifdef MOZ_ENABLE_FREETYPE2
00319   { "TrueType Font Catalog Service",
00320     NS_FONTCATALOGSERVICE_CID,
00321     "@mozilla.org/gfx/xfontcatalogservice;1",
00322     nsFT2FontCatalogConstructor },
00323   { "FreeType2 routines",
00324     NS_FREETYPE2_CID,
00325     NS_FREETYPE2_CONTRACTID,
00326     nsFreeType2Constructor },
00327 #endif
00328 #ifdef NATIVE_THEME_SUPPORT
00329    { "Native Theme Renderer",
00330     NS_THEMERENDERER_CID,
00331     "@mozilla.org/chrome/chrome-native-theme;1",
00332     nsNativeThemeGTKConstructor }
00333 #endif
00334 };
00335 
00336 PR_STATIC_CALLBACK(nsresult)
00337 nsGfxGTKModuleCtor(nsIModule *self)
00338 {
00339   nsImageGTK::Startup();
00340   return NS_OK;
00341 }
00342 
00343 PR_STATIC_CALLBACK(void)
00344 nsGfxGTKModuleDtor(nsIModule *self)
00345 {
00346   nsRenderingContextGTK::Shutdown();
00347   nsDeviceContextGTK::Shutdown();
00348   nsImageGTK::Shutdown();
00349   nsGCCache::Shutdown();
00350 #ifdef MOZ_WIDGET_GTK
00351   nsRegionGTK::Shutdown();
00352 #endif
00353 }
00354 
00355 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsGfxGTKModule, components,
00356                                    nsGfxGTKModuleCtor, nsGfxGTKModuleDtor)