1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim:expandtab:shiftwidth=4:tabstop=4:
3 : */
4 : /* ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is mozilla.org code.
18 : *
19 : * The Initial Developer of the Original Code is Christopher Blizzard
20 : * <blizzard@mozilla.org>. Portions created by the Initial Developer
21 : * are Copyright (C) 2001 the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "mozilla/ModuleUtils.h"
40 : #include "nsWidgetsCID.h"
41 : #include "nsAppShell.h"
42 : #include "nsAppShellSingleton.h"
43 : #include "nsBaseWidget.h"
44 : #include "nsLookAndFeel.h"
45 : #include "nsWindow.h"
46 : #include "nsTransferable.h"
47 : #include "nsHTMLFormatConverter.h"
48 : #ifdef MOZ_X11
49 : #include "nsClipboardHelper.h"
50 : #include "nsClipboard.h"
51 : #include "nsDragService.h"
52 : #endif
53 : #include "nsFilePicker.h"
54 : #include "nsSound.h"
55 : #include "nsBidiKeyboard.h"
56 : #include "nsNativeKeyBindings.h"
57 : #include "nsScreenManagerGtk.h"
58 : #include "nsGTKToolkit.h"
59 :
60 : #ifdef NS_PRINTING
61 : #include "nsPrintOptionsGTK.h"
62 : #include "nsPrintSession.h"
63 : #include "nsDeviceContextSpecG.h"
64 : #endif
65 :
66 : #include "mozilla/Preferences.h"
67 :
68 : #include "nsImageToPixbuf.h"
69 : #include "nsPrintDialogGTK.h"
70 :
71 : #if defined(MOZ_X11)
72 : #include "nsIdleServiceGTK.h"
73 : #include "GfxInfoX11.h"
74 : #endif
75 :
76 : #ifdef NATIVE_THEME_SUPPORT
77 : #include "nsNativeThemeGTK.h"
78 : #endif
79 :
80 : #include "nsIComponentRegistrar.h"
81 : #include "nsComponentManagerUtils.h"
82 : #include "nsAutoPtr.h"
83 : #include <gtk/gtk.h>
84 :
85 : using namespace mozilla;
86 :
87 : /* from nsFilePicker.js */
88 : #define XULFILEPICKER_CID \
89 : { 0x54ae32f8, 0x1dd2, 0x11b2, \
90 : { 0xa2, 0x09, 0xdf, 0x7c, 0x50, 0x53, 0x70, 0xf8} }
91 : static NS_DEFINE_CID(kXULFilePickerCID, XULFILEPICKER_CID);
92 : static NS_DEFINE_CID(kNativeFilePickerCID, NS_FILEPICKER_CID);
93 :
94 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow)
95 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsChildWindow)
96 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
97 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
98 432 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
99 : #ifdef MOZ_X11
100 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
101 0 : NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsClipboard, Init)
102 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
103 : #endif
104 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
105 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk)
106 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf)
107 :
108 :
109 : #ifdef NATIVE_THEME_SUPPORT
110 : // from nsWindow.cpp
111 : extern bool gDisableNativeTheme;
112 :
113 : static nsresult
114 0 : nsNativeThemeGTKConstructor(nsISupports *aOuter, REFNSIID aIID,
115 : void **aResult)
116 : {
117 : nsresult rv;
118 : nsNativeThemeGTK * inst;
119 :
120 0 : if (gDisableNativeTheme)
121 0 : return NS_ERROR_NO_INTERFACE;
122 :
123 0 : *aResult = NULL;
124 0 : if (NULL != aOuter) {
125 0 : rv = NS_ERROR_NO_AGGREGATION;
126 0 : return rv;
127 : }
128 :
129 0 : inst = new nsNativeThemeGTK();
130 0 : if (NULL == inst) {
131 0 : rv = NS_ERROR_OUT_OF_MEMORY;
132 0 : return rv;
133 : }
134 0 : NS_ADDREF(inst);
135 0 : rv = inst->QueryInterface(aIID, aResult);
136 0 : NS_RELEASE(inst);
137 :
138 0 : return rv;
139 : }
140 : #endif
141 :
142 : #if defined(MOZ_X11)
143 2 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceGTK)
144 : namespace mozilla {
145 : namespace widget {
146 : // This constructor should really be shared with all platforms.
147 52 : NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(GfxInfo, Init)
148 : }
149 : }
150 : #endif
151 :
152 : #ifdef NS_PRINTING
153 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecGTK)
154 0 : NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsGTK, Init)
155 0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK)
156 0 : NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
157 0 : NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintDialogServiceGTK, Init)
158 : #endif
159 :
160 : static nsresult
161 0 : nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID,
162 : void **aResult)
163 : {
164 0 : *aResult = nsnull;
165 0 : if (aOuter != nsnull) {
166 0 : return NS_ERROR_NO_AGGREGATION;
167 : }
168 :
169 : bool allowPlatformPicker =
170 0 : Preferences::GetBool("ui.allow_platform_file_picker", true);
171 :
172 0 : nsCOMPtr<nsIFilePicker> picker;
173 0 : if (allowPlatformPicker && gtk_check_version(2,6,3) == NULL) {
174 0 : picker = new nsFilePicker;
175 : } else {
176 0 : picker = do_CreateInstance(kXULFilePickerCID);
177 : }
178 :
179 0 : if (!picker) {
180 0 : return NS_ERROR_OUT_OF_MEMORY;
181 : }
182 :
183 0 : return picker->QueryInterface(aIID, aResult);
184 : }
185 :
186 : static nsresult
187 0 : nsNativeKeyBindingsConstructor(nsISupports *aOuter, REFNSIID aIID,
188 : void **aResult,
189 : NativeKeyBindingsType aKeyBindingsType)
190 : {
191 : nsresult rv;
192 :
193 : nsNativeKeyBindings *inst;
194 :
195 0 : *aResult = NULL;
196 0 : if (NULL != aOuter) {
197 0 : rv = NS_ERROR_NO_AGGREGATION;
198 0 : return rv;
199 : }
200 :
201 0 : inst = new nsNativeKeyBindings();
202 0 : if (NULL == inst) {
203 0 : rv = NS_ERROR_OUT_OF_MEMORY;
204 0 : return rv;
205 : }
206 0 : NS_ADDREF(inst);
207 0 : inst->Init(aKeyBindingsType);
208 0 : rv = inst->QueryInterface(aIID, aResult);
209 0 : NS_RELEASE(inst);
210 :
211 0 : return rv;
212 : }
213 :
214 : static nsresult
215 0 : nsNativeKeyBindingsInputConstructor(nsISupports *aOuter, REFNSIID aIID,
216 : void **aResult)
217 : {
218 : return nsNativeKeyBindingsConstructor(aOuter, aIID, aResult,
219 0 : eKeyBindings_Input);
220 : }
221 :
222 : static nsresult
223 0 : nsNativeKeyBindingsTextAreaConstructor(nsISupports *aOuter, REFNSIID aIID,
224 : void **aResult)
225 : {
226 : return nsNativeKeyBindingsConstructor(aOuter, aIID, aResult,
227 0 : eKeyBindings_TextArea);
228 : }
229 :
230 : NS_DEFINE_NAMED_CID(NS_WINDOW_CID);
231 : NS_DEFINE_NAMED_CID(NS_CHILD_CID);
232 : NS_DEFINE_NAMED_CID(NS_APPSHELL_CID);
233 : NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
234 : NS_DEFINE_NAMED_CID(NS_SOUND_CID);
235 : NS_DEFINE_NAMED_CID(NS_TRANSFERABLE_CID);
236 : #ifdef MOZ_X11
237 : NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
238 : NS_DEFINE_NAMED_CID(NS_CLIPBOARDHELPER_CID);
239 : NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
240 : #endif
241 : NS_DEFINE_NAMED_CID(NS_HTMLFORMATCONVERTER_CID);
242 : NS_DEFINE_NAMED_CID(NS_BIDIKEYBOARD_CID);
243 : NS_DEFINE_NAMED_CID(NS_NATIVEKEYBINDINGSINPUT_CID);
244 : NS_DEFINE_NAMED_CID(NS_NATIVEKEYBINDINGSTEXTAREA_CID);
245 : NS_DEFINE_NAMED_CID(NS_NATIVEKEYBINDINGSEDITOR_CID);
246 : NS_DEFINE_NAMED_CID(NS_SCREENMANAGER_CID);
247 : #ifdef NATIVE_THEME_SUPPORT
248 : NS_DEFINE_NAMED_CID(NS_THEMERENDERER_CID);
249 : #endif
250 : #ifdef NS_PRINTING
251 : NS_DEFINE_NAMED_CID(NS_PRINTSETTINGSSERVICE_CID);
252 : NS_DEFINE_NAMED_CID(NS_PRINTER_ENUMERATOR_CID);
253 : NS_DEFINE_NAMED_CID(NS_PRINTSESSION_CID);
254 : NS_DEFINE_NAMED_CID(NS_DEVICE_CONTEXT_SPEC_CID);
255 : NS_DEFINE_NAMED_CID(NS_PRINTDIALOGSERVICE_CID);
256 : #endif
257 : NS_DEFINE_NAMED_CID(NS_IMAGE_TO_PIXBUF_CID);
258 : #if defined(MOZ_X11)
259 : NS_DEFINE_NAMED_CID(NS_IDLE_SERVICE_CID);
260 : NS_DEFINE_NAMED_CID(NS_GFXINFO_CID);
261 : #endif
262 :
263 :
264 : static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
265 : { &kNS_WINDOW_CID, false, NULL, nsWindowConstructor },
266 : { &kNS_CHILD_CID, false, NULL, nsChildWindowConstructor },
267 : { &kNS_APPSHELL_CID, false, NULL, nsAppShellConstructor },
268 : { &kNS_FILEPICKER_CID, false, NULL, nsFilePickerConstructor },
269 : { &kNS_SOUND_CID, false, NULL, nsSoundConstructor },
270 : { &kNS_TRANSFERABLE_CID, false, NULL, nsTransferableConstructor },
271 : #ifdef MOZ_X11
272 : { &kNS_CLIPBOARD_CID, false, NULL, nsClipboardConstructor },
273 : { &kNS_CLIPBOARDHELPER_CID, false, NULL, nsClipboardHelperConstructor },
274 : { &kNS_DRAGSERVICE_CID, false, NULL, nsDragServiceConstructor },
275 : #endif
276 : { &kNS_HTMLFORMATCONVERTER_CID, false, NULL, nsHTMLFormatConverterConstructor },
277 : { &kNS_BIDIKEYBOARD_CID, false, NULL, nsBidiKeyboardConstructor },
278 : { &kNS_NATIVEKEYBINDINGSINPUT_CID, false, NULL, nsNativeKeyBindingsInputConstructor },
279 : { &kNS_NATIVEKEYBINDINGSTEXTAREA_CID, false, NULL, nsNativeKeyBindingsTextAreaConstructor },
280 : { &kNS_NATIVEKEYBINDINGSEDITOR_CID, false, NULL, nsNativeKeyBindingsTextAreaConstructor },
281 : { &kNS_SCREENMANAGER_CID, false, NULL, nsScreenManagerGtkConstructor },
282 : #ifdef NATIVE_THEME_SUPPORT
283 : { &kNS_THEMERENDERER_CID, false, NULL, nsNativeThemeGTKConstructor },
284 : #endif
285 : #ifdef NS_PRINTING
286 : { &kNS_PRINTSETTINGSSERVICE_CID, false, NULL, nsPrintOptionsGTKConstructor },
287 : { &kNS_PRINTER_ENUMERATOR_CID, false, NULL, nsPrinterEnumeratorGTKConstructor },
288 : { &kNS_PRINTSESSION_CID, false, NULL, nsPrintSessionConstructor },
289 : { &kNS_DEVICE_CONTEXT_SPEC_CID, false, NULL, nsDeviceContextSpecGTKConstructor },
290 : { &kNS_PRINTDIALOGSERVICE_CID, false, NULL, nsPrintDialogServiceGTKConstructor },
291 : #endif
292 : { &kNS_IMAGE_TO_PIXBUF_CID, false, NULL, nsImageToPixbufConstructor },
293 : #if defined(MOZ_X11)
294 : { &kNS_IDLE_SERVICE_CID, false, NULL, nsIdleServiceGTKConstructor },
295 : { &kNS_GFXINFO_CID, false, NULL, mozilla::widget::GfxInfoConstructor },
296 : #endif
297 : { NULL }
298 : };
299 :
300 : static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
301 : { "@mozilla.org/widget/window/gtk;1", &kNS_WINDOW_CID },
302 : { "@mozilla.org/widgets/child_window/gtk;1", &kNS_CHILD_CID },
303 : { "@mozilla.org/widget/appshell/gtk;1", &kNS_APPSHELL_CID },
304 : { "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID },
305 : { "@mozilla.org/sound;1", &kNS_SOUND_CID },
306 : { "@mozilla.org/widget/transferable;1", &kNS_TRANSFERABLE_CID },
307 : #ifdef MOZ_X11
308 : { "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID },
309 : { "@mozilla.org/widget/clipboardhelper;1", &kNS_CLIPBOARDHELPER_CID },
310 : { "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID },
311 : #endif
312 : { "@mozilla.org/widget/htmlformatconverter;1", &kNS_HTMLFORMATCONVERTER_CID },
313 : { "@mozilla.org/widget/bidikeyboard;1", &kNS_BIDIKEYBOARD_CID },
314 : { NS_NATIVEKEYBINDINGSINPUT_CONTRACTID, &kNS_NATIVEKEYBINDINGSINPUT_CID },
315 : { NS_NATIVEKEYBINDINGSTEXTAREA_CONTRACTID, &kNS_NATIVEKEYBINDINGSTEXTAREA_CID },
316 : { NS_NATIVEKEYBINDINGSEDITOR_CONTRACTID, &kNS_NATIVEKEYBINDINGSEDITOR_CID },
317 : { "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID },
318 : #ifdef NATIVE_THEME_SUPPORT
319 : { "@mozilla.org/chrome/chrome-native-theme;1", &kNS_THEMERENDERER_CID },
320 : #endif
321 : #ifdef NS_PRINTING
322 : { "@mozilla.org/gfx/printsettings-service;1", &kNS_PRINTSETTINGSSERVICE_CID },
323 : { "@mozilla.org/gfx/printerenumerator;1", &kNS_PRINTER_ENUMERATOR_CID },
324 : { "@mozilla.org/gfx/printsession;1", &kNS_PRINTSESSION_CID },
325 : { "@mozilla.org/gfx/devicecontextspec;1", &kNS_DEVICE_CONTEXT_SPEC_CID },
326 : { NS_PRINTDIALOGSERVICE_CONTRACTID, &kNS_PRINTDIALOGSERVICE_CID },
327 : #endif
328 : { "@mozilla.org/widget/image-to-gdk-pixbuf;1", &kNS_IMAGE_TO_PIXBUF_CID },
329 : #if defined(MOZ_X11)
330 : { "@mozilla.org/widget/idleservice;1", &kNS_IDLE_SERVICE_CID },
331 : { "@mozilla.org/gfx/info;1", &kNS_GFXINFO_CID },
332 : #endif
333 : { NULL }
334 : };
335 :
336 : static void
337 1387 : nsWidgetGtk2ModuleDtor()
338 : {
339 1387 : nsLookAndFeel::Shutdown();
340 1387 : nsFilePicker::Shutdown();
341 1387 : nsSound::Shutdown();
342 1387 : nsWindow::ReleaseGlobals();
343 1387 : nsGTKToolkit::Shutdown();
344 1387 : nsAppShellShutdown();
345 1387 : }
346 :
347 : static const mozilla::Module kWidgetModule = {
348 : mozilla::Module::kVersion,
349 : kWidgetCIDs,
350 : kWidgetContracts,
351 : NULL,
352 : NULL,
353 : nsAppShellInit,
354 : nsWidgetGtk2ModuleDtor
355 : };
356 :
357 : NSMODULE_DEFN(nsWidgetGtk2Module) = &kWidgetModule;
|