Back to index

lightning-sunbird  0.9+nobinonly
nsGfxFactoryWin.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  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nscore.h"
00039 #include "nsIFactory.h"
00040 #include "nsISupports.h"
00041 #include "nsGfxCIID.h"
00042 #include "nsFontMetricsWin.h"
00043 #include "nsRenderingContextWin.h"
00044 #include "nsImageWin.h"
00045 #include "nsDeviceContextWin.h"
00046 #include "nsRegionWin.h"
00047 #include "nsBlender.h"
00048 #include "nsDeviceContextSpecWin.h"
00049 #include "nsDeviceContextSpecFactoryW.h"
00050 #include "nsScriptableRegion.h"
00051 #include "nsScreenManagerWin.h"
00052 #include "nsPrintOptionsWin.h"
00053 #include "nsFontList.h"
00054 #include "nsIGenericFactory.h"
00055 #include "nsNativeThemeWin.h"
00056 #include "nsPrintSession.h"
00057 #include "gfxImageFrame.h"
00058 
00059 
00060 //NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsWin)
00061 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextWin)
00062 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextWin)
00063 NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageWin)
00064 NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionWin)
00065 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender)
00066 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDrawingSurfaceWin)
00067 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecWin)
00068 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryWin)
00069 //NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableRegion)
00070 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorWin)
00071 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList)
00072 NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerWin)
00073 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeWin)
00074 NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame)
00075 
00076 #ifndef WINCE
00077 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsWin, Init)
00078 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorWin)
00079 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
00080 #endif
00081 
00082 PRBool
00083 UseAFunctions()
00084 {
00085 #ifndef WINCE
00086   static PRBool useAFunctions = PR_FALSE;
00087   static PRBool init = PR_FALSE;
00088   if (!init) {
00089     init = 1;
00090     OSVERSIONINFO os;
00091     os.dwOSVersionInfoSize = sizeof(os);
00092     ::GetVersionEx(&os);
00093     if ((os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) &&
00094         (os.dwMajorVersion == 4) &&
00095         (os.dwMinorVersion == 0) &&    // Windows 95 (not 98)
00096         (::GetACP() == 932)) {         // Shift-JIS (Japanese)
00097       useAFunctions = 1;
00098     }
00099   }
00100 
00101   return useAFunctions;
00102 #else
00103   return PR_FALSE;
00104 #endif
00105 }
00106 
00107 static NS_IMETHODIMP
00108 nsFontMetricsWinConstructor(nsISupports* aOuter, REFNSIID aIID, void** aResult)
00109 {
00110   *aResult = nsnull;
00111 
00112   if (aOuter)
00113     return NS_ERROR_NO_AGGREGATION;
00114 
00115   nsFontMetricsWin* result;
00116   if (UseAFunctions())
00117     result = new nsFontMetricsWinA();
00118   else
00119     result = new nsFontMetricsWin();
00120 
00121   if (! result)
00122     return NS_ERROR_OUT_OF_MEMORY;
00123 
00124   nsresult rv;
00125   NS_ADDREF(result);
00126   rv = result->QueryInterface(aIID, aResult);
00127   NS_RELEASE(result);
00128   return rv;
00129 }
00130 
00131 static NS_IMETHODIMP
00132 nsScriptableRegionConstructor(nsISupports* aOuter, REFNSIID aIID, void** aResult)
00133 {
00134   *aResult = nsnull;
00135 
00136   if (aOuter)
00137     return NS_ERROR_NO_AGGREGATION;
00138 
00139   nsRegionWin* region = new nsRegionWin();
00140   if (! region)
00141     return NS_ERROR_OUT_OF_MEMORY;
00142 
00143   NS_ADDREF(region);
00144 
00145   nsresult rv = NS_ERROR_OUT_OF_MEMORY;
00146   nsScriptableRegion* result = new nsScriptableRegion(region);
00147   if (result) {
00148     NS_ADDREF(result);
00149     rv = result->QueryInterface(aIID, aResult);
00150     NS_RELEASE(result);
00151   }
00152 
00153   NS_RELEASE(region);
00154   return rv;
00155 }
00156 
00157 static const nsModuleComponentInfo components[] =
00158 {
00159   { "nsFontMetricsWin",
00160     NS_FONT_METRICS_CID,
00161     "@mozilla.org/gfx/fontmetrics;1",
00162     nsFontMetricsWinConstructor },
00163 
00164   { "nsDeviceContextWin",
00165     NS_DEVICE_CONTEXT_CID,
00166     "@mozilla.org/gfx/devicecontext;1",
00167     nsDeviceContextWinConstructor },
00168 
00169   { "nsRenderingContextWin",
00170     NS_RENDERING_CONTEXT_CID,
00171     "@mozilla.org/gfx/renderingcontext;1",
00172     nsRenderingContextWinConstructor },
00173 
00174   { "nsImageWin",
00175     NS_IMAGE_CID,
00176     "@mozilla.org/gfx/image;1",
00177     nsImageWinConstructor },
00178 
00179   { "nsRegionWin",
00180     NS_REGION_CID,
00181     "@mozilla.org/gfx/unscriptable-region;1",
00182     nsRegionWinConstructor },
00183 
00184   { "nsBlender",
00185     NS_BLENDER_CID,
00186     "@mozilla.org/gfx/blender;1",
00187     nsBlenderConstructor },
00188 
00189   { "nsDrawingSurfaceWin",
00190     NS_DRAWING_SURFACE_CID,
00191     "@mozilla.org/gfx/drawing-surface;1",
00192     nsDrawingSurfaceWinConstructor },
00193 
00194   { "nsDeviceContextSpecWin",
00195     NS_DEVICE_CONTEXT_SPEC_CID,
00196     "@mozilla.org/gfx/devicecontextspec;1",
00197     nsDeviceContextSpecWinConstructor },
00198 
00199   { "nsDeviceContextSpecFactoryWin",
00200     NS_DEVICE_CONTEXT_SPEC_FACTORY_CID,
00201     "@mozilla.org/gfx/devicecontextspecfactory;1",
00202     nsDeviceContextSpecFactoryWinConstructor },
00203 
00204   { "nsScriptableRegion",
00205     NS_SCRIPTABLE_REGION_CID,
00206     "@mozilla.org/gfx/region;1",
00207     nsScriptableRegionConstructor },
00208 
00209   { "nsFontEnumeratorWin",
00210     NS_FONT_ENUMERATOR_CID,
00211     "@mozilla.org/gfx/fontenumerator;1",
00212     nsFontEnumeratorWinConstructor },
00213 
00214   { "nsFontList",
00215     NS_FONTLIST_CID,
00216     "@mozilla.org/gfx/fontlist;1",
00217     nsFontListConstructor },
00218 
00219   { "nsScreenManagerWin",
00220     NS_SCREENMANAGER_CID,
00221     "@mozilla.org/gfx/screenmanager;1",
00222     nsScreenManagerWinConstructor },
00223 
00224   { "Native Theme Renderer", 
00225     NS_THEMERENDERER_CID,
00226     "@mozilla.org/chrome/chrome-native-theme;1", 
00227     NS_NewNativeTheme
00228   },
00229   { "windows image frame",
00230     GFX_IMAGEFRAME_CID,
00231     "@mozilla.org/gfx/image/frame;2",
00232     gfxImageFrameConstructor, },
00233 
00234 #ifndef WINCE
00235   { "nsPrintOptionsWin",
00236     NS_PRINTSETTINGSSERVICE_CID,
00237     "@mozilla.org/gfx/printsettings-service;1",
00238     nsPrintOptionsWinConstructor },
00239 
00240   { "Win Printer Enumerator",
00241     NS_PRINTER_ENUMERATOR_CID,
00242     //    "@mozilla.org/gfx/printer_enumerator/win;1",
00243     "@mozilla.org/gfx/printerenumerator;1",
00244     nsPrinterEnumeratorWinConstructor },
00245 
00246   { "Print Session",
00247     NS_PRINTSESSION_CID,
00248     "@mozilla.org/gfx/printsession;1",
00249     nsPrintSessionConstructor }
00250 #endif
00251 
00252 };
00253 
00254 NS_IMPL_NSGETMODULE(nsGfxModule, components)