Back to index

lightning-sunbird  0.9+nobinonly
nsWidgetFactory.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* vim:expandtab:shiftwidth=4:tabstop=4:
00003  */
00004 /* ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is Christopher Blizzard
00020  * <blizzard@mozilla.org>.  Portions created by the Initial Developer
00021  * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsIGenericFactory.h"
00040 #include "nsWidgetsCID.h"
00041 #include "nsAppShell.h"
00042 #include "nsBaseWidget.h"
00043 #include "nsLookAndFeel.h"
00044 #include "nsWindow.h"
00045 #include "nsTransferable.h"
00046 #include "nsClipboardHelper.h"
00047 #include "nsHTMLFormatConverter.h"
00048 #include "nsClipboard.h"
00049 #include "nsDragService.h"
00050 #include "nsFilePicker.h"
00051 #include "nsSound.h"
00052 #include "nsBidiKeyboard.h"
00053 #include "nsNativeKeyBindings.h"
00054 #include "nsIPrefService.h"
00055 #include "nsIPrefBranch.h"
00056 
00057 #include "nsIComponentRegistrar.h"
00058 #include "nsComponentManagerUtils.h"
00059 #include "nsAutoPtr.h"
00060 #include <gtk/gtk.h>
00061 
00062 /* from nsFilePicker.js */
00063 #define XULFILEPICKER_CID \
00064   { 0x54ae32f8, 0x1dd2, 0x11b2, \
00065     { 0xa2, 0x09, 0xdf, 0x7c, 0x50, 0x53, 0x70, 0xf8} }
00066 static NS_DEFINE_CID(kXULFilePickerCID, XULFILEPICKER_CID);
00067 static NS_DEFINE_CID(kNativeFilePickerCID, NS_FILEPICKER_CID);
00068 
00069 NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
00070 NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
00071 NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell)
00072 NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
00073 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
00074 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
00075 NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
00076 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
00077 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsClipboard, Init)
00078 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
00079 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
00080 
00081 static NS_IMETHODIMP
00082 nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID,
00083                         void **aResult)
00084 {
00085   *aResult = nsnull;
00086   if (aOuter != nsnull) {
00087     return NS_ERROR_NO_AGGREGATION;
00088   }
00089 
00090   PRBool allowPlatformPicker = PR_TRUE;
00091   nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
00092   if (prefs) {
00093     PRBool prefAllow;
00094     nsresult rv = prefs->GetBoolPref("ui.allow_platform_file_picker",
00095                                      &prefAllow);
00096     if (NS_SUCCEEDED(rv)) {
00097         allowPlatformPicker = prefAllow;
00098     }
00099   }
00100 
00101   nsCOMPtr<nsIFilePicker> picker;
00102   if (allowPlatformPicker && gtk_check_version(2,6,3) == NULL) {
00103     picker = new nsFilePicker;
00104   } else {
00105     picker = do_CreateInstance(kXULFilePickerCID);
00106   }
00107 
00108   if (!picker) {
00109     return NS_ERROR_OUT_OF_MEMORY;
00110   }
00111 
00112   return picker->QueryInterface(aIID, aResult);
00113 }
00114 
00115 static NS_IMETHODIMP
00116 nsNativeKeyBindingsConstructor(nsISupports *aOuter, REFNSIID aIID,
00117                                void **aResult,
00118                                NativeKeyBindingsType aKeyBindingsType)
00119 {
00120     nsresult rv;
00121 
00122     nsNativeKeyBindings *inst;
00123 
00124     *aResult = NULL;
00125     if (NULL != aOuter) {
00126         rv = NS_ERROR_NO_AGGREGATION;
00127         return rv;
00128     }
00129 
00130     NS_NEWXPCOM(inst, nsNativeKeyBindings);
00131     if (NULL == inst) {
00132         rv = NS_ERROR_OUT_OF_MEMORY;
00133         return rv;
00134     }
00135     NS_ADDREF(inst);
00136     inst->Init(aKeyBindingsType);
00137     rv = inst->QueryInterface(aIID, aResult);
00138     NS_RELEASE(inst);
00139 
00140     return rv;
00141 }
00142 
00143 static NS_IMETHODIMP
00144 nsNativeKeyBindingsInputConstructor(nsISupports *aOuter, REFNSIID aIID,
00145                                     void **aResult)
00146 {
00147     return nsNativeKeyBindingsConstructor(aOuter, aIID, aResult,
00148                                           eKeyBindings_Input);
00149 }
00150 
00151 static NS_IMETHODIMP
00152 nsNativeKeyBindingsTextAreaConstructor(nsISupports *aOuter, REFNSIID aIID,
00153                                        void **aResult)
00154 {
00155     return nsNativeKeyBindingsConstructor(aOuter, aIID, aResult,
00156                                           eKeyBindings_TextArea);
00157 }
00158 
00159 static const nsModuleComponentInfo components[] =
00160 {
00161     { "Gtk2 Window",
00162       NS_WINDOW_CID,
00163       "@mozilla.org/widget/window/gtk;1",
00164       nsWindowConstructor },
00165     { "Gtk2 Child Window",
00166       NS_CHILD_CID,
00167       "@mozilla.org/widgets/child_window/gtk;1",
00168       nsChildWindowConstructor },
00169     { "Gtk2 AppShell",
00170       NS_APPSHELL_CID,
00171       "@mozilla.org/widget/appshell/gtk;1",
00172       nsAppShellConstructor },
00173     { "Gtk2 Look And Feel",
00174       NS_LOOKANDFEEL_CID,
00175       "@mozilla.org/widget/lookandfeel;1",
00176       nsLookAndFeelConstructor },
00177     { "Gtk2 File Picker",
00178       NS_FILEPICKER_CID,
00179       "@mozilla.org/filepicker;1",
00180       nsFilePickerConstructor },
00181     { "Gtk2 Sound",
00182       NS_SOUND_CID,
00183       "@mozilla.org/sound;1",
00184       nsSoundConstructor },
00185   { "Transferable",
00186     NS_TRANSFERABLE_CID,
00187     "@mozilla.org/widget/transferable;1",
00188     nsTransferableConstructor },
00189   { "Gtk Clipboard",
00190     NS_CLIPBOARD_CID,
00191     "@mozilla.org/widget/clipboard;1",
00192     nsClipboardConstructor },
00193   { "Clipboard Helper",
00194     NS_CLIPBOARDHELPER_CID,
00195     "@mozilla.org/widget/clipboardhelper;1",
00196     nsClipboardHelperConstructor },
00197   { "Gtk Drag Service",
00198     NS_DRAGSERVICE_CID,
00199     "@mozilla.org/widget/dragservice;1",
00200     nsDragServiceConstructor },
00201   { "HTML Format Converter",
00202     NS_HTMLFORMATCONVERTER_CID,
00203     "@mozilla.org/widget/htmlformatconverter;1",
00204     nsHTMLFormatConverterConstructor },
00205   { "Gtk2 Bidi Keyboard",
00206     NS_BIDIKEYBOARD_CID,
00207     "@mozilla.org/widget/bidikeyboard;1",
00208     nsBidiKeyboardConstructor },
00209   { "Input Native Keybindings",
00210     NS_NATIVEKEYBINDINGSINPUT_CID,
00211     NS_NATIVEKEYBINDINGSINPUT_CONTRACTID,
00212     nsNativeKeyBindingsInputConstructor },
00213   { "TextArea Native Keybindings",
00214     NS_NATIVEKEYBINDINGSTEXTAREA_CID,
00215     NS_NATIVEKEYBINDINGSTEXTAREA_CONTRACTID,
00216     nsNativeKeyBindingsTextAreaConstructor },
00217   { "Editor Native Keybindings",
00218     NS_NATIVEKEYBINDINGSEDITOR_CID,
00219     NS_NATIVEKEYBINDINGSEDITOR_CONTRACTID,
00220     nsNativeKeyBindingsTextAreaConstructor }
00221 };
00222 
00223 PR_STATIC_CALLBACK(void)
00224 nsWidgetGtk2ModuleDtor(nsIModule *aSelf)
00225 {
00226   nsFilePicker::Shutdown();
00227   nsWindow::ReleaseGlobals();
00228   nsAppShell::ReleaseGlobals();
00229 }
00230 
00231 NS_IMPL_NSGETMODULE_WITH_DTOR(nsWidgetGtk2Module,
00232                               components,
00233                               nsWidgetGtk2ModuleDtor)