From 8e802771d31eecabeaaca4b10c08dfd4563648f7 Mon Sep 17 00:00:00 2001 From: "mats.palmgren%bredband.net" Date: Thu, 3 May 2007 00:10:04 +0000 Subject: [PATCH] Bye bye gtk1 and xlib (part 2 of 2). b=326152 r+sr=roc git-svn-id: svn://10.0.0.236/trunk@225500 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/xlib/Makefile.in | 156 - mozilla/gfx/src/xlib/XIE.c | 194 - mozilla/gfx/src/xlib/drawers.h | 64 - .../gfx/src/xlib/nsDeviceContextSpecXlib.cpp | 1393 ---- .../gfx/src/xlib/nsDeviceContextSpecXlib.h | 140 - mozilla/gfx/src/xlib/nsDeviceContextX.h | 66 - mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp | 528 -- mozilla/gfx/src/xlib/nsDeviceContextXlib.h | 115 - mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.cpp | 302 - mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.h | 136 - mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp | 6067 ----------------- mozilla/gfx/src/xlib/nsFontMetricsXlib.h | 535 -- mozilla/gfx/src/xlib/nsGCCache.cpp | 249 - mozilla/gfx/src/xlib/nsGCCache.h | 148 - mozilla/gfx/src/xlib/nsGfxFactoryXlib.cpp | 190 - mozilla/gfx/src/xlib/nsImageXlib.cpp | 1685 ----- mozilla/gfx/src/xlib/nsImageXlib.h | 199 - mozilla/gfx/src/xlib/nsPrintOptionsXlib.cpp | 57 - mozilla/gfx/src/xlib/nsPrintOptionsXlib.h | 57 - mozilla/gfx/src/xlib/nsPrintdXlib.cpp | 0 mozilla/gfx/src/xlib/nsPrintdXlib.h | 0 mozilla/gfx/src/xlib/nsRegionXlib.cpp | 424 -- mozilla/gfx/src/xlib/nsRegionXlib.h | 88 - .../gfx/src/xlib/nsRenderingContextXlib.cpp | 2505 ------- mozilla/gfx/src/xlib/nsRenderingContextXlib.h | 280 - mozilla/gfx/src/xlib/xlib.pkg | 6 - mozilla/gfx/src/xlib/xregion.h | 177 - mozilla/widget/public/nsIDragSessionXlib.h | 60 - mozilla/widget/src/gtk/Makefile.in | 160 - mozilla/widget/src/gtk/gtkdrawing.c | 1252 ---- mozilla/widget/src/gtk/gtkdrawing.h | 293 - mozilla/widget/src/gtk/keysym2ucs.c | 894 --- mozilla/widget/src/gtk/keysym2ucs.h | 57 - mozilla/widget/src/gtk/mozicon.xpm | 292 - mozilla/widget/src/gtk/mozicon16.xpm | 105 - mozilla/widget/src/gtk/mozicon50.xpm | 63 - mozilla/widget/src/gtk/nsAppShell.cpp | 127 - mozilla/widget/src/gtk/nsAppShell.h | 71 - mozilla/widget/src/gtk/nsBidiKeyboard.cpp | 63 - mozilla/widget/src/gtk/nsBidiKeyboard.h | 56 - mozilla/widget/src/gtk/nsClipboard.cpp | 1562 ----- mozilla/widget/src/gtk/nsClipboard.h | 169 - mozilla/widget/src/gtk/nsDragService.cpp | 1162 ---- mozilla/widget/src/gtk/nsDragService.h | 150 - mozilla/widget/src/gtk/nsGtkCursors.h | 493 -- mozilla/widget/src/gtk/nsGtkEventHandler.cpp | 899 --- mozilla/widget/src/gtk/nsGtkEventHandler.h | 58 - mozilla/widget/src/gtk/nsGtkIMEHelper.cpp | 1642 ----- mozilla/widget/src/gtk/nsGtkIMEHelper.h | 191 - mozilla/widget/src/gtk/nsGtkUtils.cpp | 214 - mozilla/widget/src/gtk/nsGtkUtils.h | 100 - mozilla/widget/src/gtk/nsKeyboardUtils.cpp | 274 - mozilla/widget/src/gtk/nsKeyboardUtils.h | 72 - mozilla/widget/src/gtk/nsLookAndFeel.cpp | 543 -- mozilla/widget/src/gtk/nsLookAndFeel.h | 72 - mozilla/widget/src/gtk/nsNativeThemeGTK.cpp | 872 --- mozilla/widget/src/gtk/nsNativeThemeGTK.h | 103 - mozilla/widget/src/gtk/nsPointerService.cpp | 138 - mozilla/widget/src/gtk/nsPointerService.h | 48 - mozilla/widget/src/gtk/nsScreenGtk.cpp | 190 - mozilla/widget/src/gtk/nsScreenGtk.h | 71 - mozilla/widget/src/gtk/nsScreenManagerGtk.cpp | 246 - mozilla/widget/src/gtk/nsScreenManagerGtk.h | 69 - mozilla/widget/src/gtk/nsSound.cpp | 324 - mozilla/widget/src/gtk/nsSound.h | 67 - mozilla/widget/src/gtk/nsToolkit.cpp | 161 - mozilla/widget/src/gtk/nsToolkit.h | 70 - mozilla/widget/src/gtk/nsWidget.cpp | 2417 ------- mozilla/widget/src/gtk/nsWidget.h | 436 -- mozilla/widget/src/gtk/nsWidgetFactory.cpp | 158 - mozilla/widget/src/gtk/nsWindow.cpp | 4464 ------------ mozilla/widget/src/gtk/nsWindow.h | 439 -- mozilla/widget/src/gtk/widget_gtk.pkg | 10 - mozilla/widget/src/gtksuperwin/Makefile.in | 79 - mozilla/widget/src/gtksuperwin/gdksuperwin.c | 729 -- mozilla/widget/src/gtksuperwin/gdksuperwin.h | 139 - mozilla/widget/src/gtksuperwin/gtkmozarea.c | 414 -- mozilla/widget/src/gtksuperwin/gtkmozarea.h | 87 - mozilla/widget/src/gtksuperwin/gtkmozbox.c | 269 - mozilla/widget/src/gtksuperwin/gtkmozbox.h | 82 - .../widget/src/gtksuperwin/gtksuperwin.pkg | 4 - mozilla/widget/src/xlib/Makefile.in | 106 - mozilla/widget/src/xlib/nsAppShell.cpp | 1254 ---- mozilla/widget/src/xlib/nsAppShell.h | 114 - mozilla/widget/src/xlib/nsBidiKeyboard.cpp | 63 - mozilla/widget/src/xlib/nsBidiKeyboard.h | 56 - mozilla/widget/src/xlib/nsClipboard.cpp | 437 -- mozilla/widget/src/xlib/nsClipboard.h | 101 - mozilla/widget/src/xlib/nsDragService.cpp | 313 - mozilla/widget/src/xlib/nsDragService.h | 102 - mozilla/widget/src/xlib/nsKeyCode.cpp | 213 - mozilla/widget/src/xlib/nsKeyCode.h | 56 - mozilla/widget/src/xlib/nsLookAndFeel.cpp | 384 -- mozilla/widget/src/xlib/nsLookAndFeel.h | 53 - .../widget/src/xlib/nsScreenManagerXlib.cpp | 127 - mozilla/widget/src/xlib/nsScreenManagerXlib.h | 67 - mozilla/widget/src/xlib/nsScreenXlib.cpp | 117 - mozilla/widget/src/xlib/nsScreenXlib.h | 60 - mozilla/widget/src/xlib/nsSound.cpp | 111 - mozilla/widget/src/xlib/nsSound.h | 61 - mozilla/widget/src/xlib/nsToolkit.cpp | 136 - mozilla/widget/src/xlib/nsToolkit.h | 68 - mozilla/widget/src/xlib/nsWidget.cpp | 1508 ---- mozilla/widget/src/xlib/nsWidget.h | 257 - mozilla/widget/src/xlib/nsWidgetFactory.cpp | 141 - mozilla/widget/src/xlib/nsWindow.cpp | 803 --- mozilla/widget/src/xlib/nsWindow.h | 152 - mozilla/widget/src/xlib/nsXUtils.cpp | 140 - mozilla/widget/src/xlib/nsXUtils.h | 62 - mozilla/widget/src/xlib/nsXlibCursors.h | 492 -- mozilla/widget/src/xlib/widget_xlib.pkg | 6 - mozilla/widget/src/xlibxtbin/Makefile.in | 74 - mozilla/widget/src/xlibxtbin/xlibxtbin.cpp | 188 - mozilla/widget/src/xlibxtbin/xlibxtbin.h | 130 - mozilla/widget/src/xlibxtbin/xlibxtbin.pkg | 4 - 115 files changed, 46897 deletions(-) delete mode 100644 mozilla/gfx/src/xlib/Makefile.in delete mode 100644 mozilla/gfx/src/xlib/XIE.c delete mode 100644 mozilla/gfx/src/xlib/drawers.h delete mode 100644 mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsDeviceContextX.h delete mode 100644 mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsDeviceContextXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsFontMetricsXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsGCCache.cpp delete mode 100644 mozilla/gfx/src/xlib/nsGCCache.h delete mode 100644 mozilla/gfx/src/xlib/nsGfxFactoryXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsImageXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsImageXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsPrintOptionsXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsPrintOptionsXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsPrintdXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsPrintdXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsRegionXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsRegionXlib.h delete mode 100644 mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp delete mode 100644 mozilla/gfx/src/xlib/nsRenderingContextXlib.h delete mode 100644 mozilla/gfx/src/xlib/xlib.pkg delete mode 100644 mozilla/gfx/src/xlib/xregion.h delete mode 100644 mozilla/widget/public/nsIDragSessionXlib.h delete mode 100644 mozilla/widget/src/gtk/Makefile.in delete mode 100644 mozilla/widget/src/gtk/gtkdrawing.c delete mode 100644 mozilla/widget/src/gtk/gtkdrawing.h delete mode 100644 mozilla/widget/src/gtk/keysym2ucs.c delete mode 100644 mozilla/widget/src/gtk/keysym2ucs.h delete mode 100644 mozilla/widget/src/gtk/mozicon.xpm delete mode 100644 mozilla/widget/src/gtk/mozicon16.xpm delete mode 100644 mozilla/widget/src/gtk/mozicon50.xpm delete mode 100644 mozilla/widget/src/gtk/nsAppShell.cpp delete mode 100644 mozilla/widget/src/gtk/nsAppShell.h delete mode 100644 mozilla/widget/src/gtk/nsBidiKeyboard.cpp delete mode 100644 mozilla/widget/src/gtk/nsBidiKeyboard.h delete mode 100644 mozilla/widget/src/gtk/nsClipboard.cpp delete mode 100644 mozilla/widget/src/gtk/nsClipboard.h delete mode 100644 mozilla/widget/src/gtk/nsDragService.cpp delete mode 100644 mozilla/widget/src/gtk/nsDragService.h delete mode 100644 mozilla/widget/src/gtk/nsGtkCursors.h delete mode 100644 mozilla/widget/src/gtk/nsGtkEventHandler.cpp delete mode 100644 mozilla/widget/src/gtk/nsGtkEventHandler.h delete mode 100644 mozilla/widget/src/gtk/nsGtkIMEHelper.cpp delete mode 100644 mozilla/widget/src/gtk/nsGtkIMEHelper.h delete mode 100644 mozilla/widget/src/gtk/nsGtkUtils.cpp delete mode 100644 mozilla/widget/src/gtk/nsGtkUtils.h delete mode 100644 mozilla/widget/src/gtk/nsKeyboardUtils.cpp delete mode 100644 mozilla/widget/src/gtk/nsKeyboardUtils.h delete mode 100644 mozilla/widget/src/gtk/nsLookAndFeel.cpp delete mode 100644 mozilla/widget/src/gtk/nsLookAndFeel.h delete mode 100644 mozilla/widget/src/gtk/nsNativeThemeGTK.cpp delete mode 100644 mozilla/widget/src/gtk/nsNativeThemeGTK.h delete mode 100644 mozilla/widget/src/gtk/nsPointerService.cpp delete mode 100644 mozilla/widget/src/gtk/nsPointerService.h delete mode 100644 mozilla/widget/src/gtk/nsScreenGtk.cpp delete mode 100644 mozilla/widget/src/gtk/nsScreenGtk.h delete mode 100644 mozilla/widget/src/gtk/nsScreenManagerGtk.cpp delete mode 100644 mozilla/widget/src/gtk/nsScreenManagerGtk.h delete mode 100644 mozilla/widget/src/gtk/nsSound.cpp delete mode 100644 mozilla/widget/src/gtk/nsSound.h delete mode 100644 mozilla/widget/src/gtk/nsToolkit.cpp delete mode 100644 mozilla/widget/src/gtk/nsToolkit.h delete mode 100644 mozilla/widget/src/gtk/nsWidget.cpp delete mode 100644 mozilla/widget/src/gtk/nsWidget.h delete mode 100644 mozilla/widget/src/gtk/nsWidgetFactory.cpp delete mode 100644 mozilla/widget/src/gtk/nsWindow.cpp delete mode 100644 mozilla/widget/src/gtk/nsWindow.h delete mode 100644 mozilla/widget/src/gtk/widget_gtk.pkg delete mode 100644 mozilla/widget/src/gtksuperwin/Makefile.in delete mode 100644 mozilla/widget/src/gtksuperwin/gdksuperwin.c delete mode 100644 mozilla/widget/src/gtksuperwin/gdksuperwin.h delete mode 100644 mozilla/widget/src/gtksuperwin/gtkmozarea.c delete mode 100644 mozilla/widget/src/gtksuperwin/gtkmozarea.h delete mode 100644 mozilla/widget/src/gtksuperwin/gtkmozbox.c delete mode 100644 mozilla/widget/src/gtksuperwin/gtkmozbox.h delete mode 100644 mozilla/widget/src/gtksuperwin/gtksuperwin.pkg delete mode 100644 mozilla/widget/src/xlib/Makefile.in delete mode 100644 mozilla/widget/src/xlib/nsAppShell.cpp delete mode 100644 mozilla/widget/src/xlib/nsAppShell.h delete mode 100644 mozilla/widget/src/xlib/nsBidiKeyboard.cpp delete mode 100644 mozilla/widget/src/xlib/nsBidiKeyboard.h delete mode 100644 mozilla/widget/src/xlib/nsClipboard.cpp delete mode 100644 mozilla/widget/src/xlib/nsClipboard.h delete mode 100644 mozilla/widget/src/xlib/nsDragService.cpp delete mode 100644 mozilla/widget/src/xlib/nsDragService.h delete mode 100644 mozilla/widget/src/xlib/nsKeyCode.cpp delete mode 100644 mozilla/widget/src/xlib/nsKeyCode.h delete mode 100644 mozilla/widget/src/xlib/nsLookAndFeel.cpp delete mode 100644 mozilla/widget/src/xlib/nsLookAndFeel.h delete mode 100644 mozilla/widget/src/xlib/nsScreenManagerXlib.cpp delete mode 100644 mozilla/widget/src/xlib/nsScreenManagerXlib.h delete mode 100644 mozilla/widget/src/xlib/nsScreenXlib.cpp delete mode 100644 mozilla/widget/src/xlib/nsScreenXlib.h delete mode 100644 mozilla/widget/src/xlib/nsSound.cpp delete mode 100644 mozilla/widget/src/xlib/nsSound.h delete mode 100644 mozilla/widget/src/xlib/nsToolkit.cpp delete mode 100644 mozilla/widget/src/xlib/nsToolkit.h delete mode 100644 mozilla/widget/src/xlib/nsWidget.cpp delete mode 100644 mozilla/widget/src/xlib/nsWidget.h delete mode 100644 mozilla/widget/src/xlib/nsWidgetFactory.cpp delete mode 100644 mozilla/widget/src/xlib/nsWindow.cpp delete mode 100644 mozilla/widget/src/xlib/nsWindow.h delete mode 100644 mozilla/widget/src/xlib/nsXUtils.cpp delete mode 100644 mozilla/widget/src/xlib/nsXUtils.h delete mode 100644 mozilla/widget/src/xlib/nsXlibCursors.h delete mode 100644 mozilla/widget/src/xlib/widget_xlib.pkg delete mode 100644 mozilla/widget/src/xlibxtbin/Makefile.in delete mode 100644 mozilla/widget/src/xlibxtbin/xlibxtbin.cpp delete mode 100644 mozilla/widget/src/xlibxtbin/xlibxtbin.h delete mode 100644 mozilla/widget/src/xlibxtbin/xlibxtbin.pkg diff --git a/mozilla/gfx/src/xlib/Makefile.in b/mozilla/gfx/src/xlib/Makefile.in deleted file mode 100644 index a2b01560ea7..00000000000 --- a/mozilla/gfx/src/xlib/Makefile.in +++ /dev/null @@ -1,156 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Roland Mainz -# -# Alternatively, the contents of this file may be used under the terms of -# either of the GNU General Public License Version 2 or later (the "GPL"), -# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = gfx -EXPORTS = nsGCCache.h -LIBRARY_NAME = gfx_xlib -EXPORT_LIBRARY = 1 -IS_COMPONENT = 1 -MODULE_NAME = nsGfxXlibModule -GRE_MODULE = 1 -LIBXUL_LIBRARY = 1 - -REQUIRES = xpcom \ - string \ - xlibrgb \ - widget \ - js \ - necko \ - pref \ - util \ - view \ - uconv \ - locale \ - unicharutil \ - imglib2 \ - mozcomps \ - intl \ - $(NULL) - -# Sun's Complex Text Layout support -ifdef SUNCTL -REQUIRES += ctl -endif - -ifdef MOZ_ENABLE_XPRINT -REQUIRES += xprintutil -endif - -# Code shared between GTK+, Xlib and Xprint gfx modules -# (empty for now - but this will be filled soon...) -X11SHARED_LCPPSRCS = \ - $(NULL) - -CPPSRCS = \ - $(X11SHARED_LCPPSRCS) \ - nsDeviceContextSpecXlib.cpp \ - nsDeviceContextXlib.cpp \ - nsDrawingSurfaceXlib.cpp \ - nsFontMetricsXlib.cpp \ - nsGfxFactoryXlib.cpp \ - nsImageXlib.cpp \ - nsRegionXlib.cpp \ - nsRenderingContextXlib.cpp \ - nsPrintOptionsXlib.cpp \ - nsGCCache.cpp \ - $(NULL) - -ifdef HAVE_XIE -CSRCS += XIE.c -endif - -GARBAGE += $(X11SHARED_LCPPSRCS) $(wildcard *.$(OBJ_SUFFIX)) - -EXTRA_DSO_LDOPTS = $(DIST)/lib/$(LIB_PREFIX)gfxshared_s.$(LIB_SUFFIX) - -include $(topsrcdir)/config/rules.mk - -EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lxlibrgb $(MOZ_XLIB_LDFLAGS) -CXXFLAGS += $(MOZ_XLIB_CFLAGS) - -ifdef HAVE_XIE -DEFINES += -DHAVE_XIE -GFX_XIE_LIBS += $(MOZ_XIE_LIBS) -endif - -EXTRA_DSO_LDOPTS += \ - $(LIBS_DIR) \ - -lgkgfx \ - $(GFX_XIE_LIBS) \ - $(MOZ_COMPONENT_LIBS) \ - $(MOZ_UNICHARUTIL_LIBS) \ - $(NULL) - -DEFINES += -DUSE_MOZILLA_TYPES - -ifdef MOZ_ENABLE_POSTSCRIPT -DEFINES += -DUSE_POSTSCRIPT -EXTRA_DSO_LDOPTS += -lgfxpsshar -endif - -ifdef MOZ_ENABLE_XPRINT -DEFINES += -DUSE_XPRINT -EXTRA_DSO_LDOPTS += \ - -lxprintutil \ - $(MOZ_XPRINT_LDFLAGS) -endif - -LOCAL_INCLUDES += \ - -I../.. \ - -I$(srcdir)/. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../shared \ - -I$(srcdir)/../x11shared \ - $(NULL) - -ifdef MOZ_ENABLE_XPRINT -#export:: $(addprefix $(srcdir)/../x11shared/,$(X11SHARED_LCPPSRCS)) -# $(INSTALL) $^ . -else -# disabled until X11SHARED_LCPPSRCS becomes non-empty -# export:: $(addprefix $(srcdir)/../x11shared/,$(X11SHARED_LCPPSRCS)) -# $(INSTALL) $^ . -endif - diff --git a/mozilla/gfx/src/xlib/XIE.c b/mozilla/gfx/src/xlib/XIE.c deleted file mode 100644 index 7cab0025cc3..00000000000 --- a/mozilla/gfx/src/xlib/XIE.c +++ /dev/null @@ -1,194 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim:ts=2:et:sw=2: - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Syd Logan - * Xlibified by tim copperfield - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "drawers.h" - -#ifdef HAVE_XIE - -#include -#include -#include "prenv.h" -#include "xlibrgb.h" -#include - -/* #define DEBUG_XIE 1 */ -static PRBool useXIE = PR_TRUE; -static PRBool inited = PR_FALSE; -static XiePhotospace gPhotospace; -static XiePhotoElement *photoElement; - -static void -DoFlo(Display *display, - Drawable aDest, - GC aGC, - Drawable aSrc, - PRInt32 aSrcWidth, - PRInt32 aSrcHeight, - PRInt32 aSX, - PRInt32 aSY, - PRInt32 aSWidth, - PRInt32 aSHeight, - PRInt32 aDX, - PRInt32 aDY, - PRInt32 aDWidth, - PRInt32 aDHeight) -{ - XieExtensionInfo *info; - float coeffs[6]; - XieConstant constant; - XiePhototag idx = 0, src; - - /* create the pretty flo graph */ - - - /* import */ - XieFloImportDrawable(&photoElement[idx], aSrc, - aSX, aSY, aSWidth, aSHeight, - 0, PR_FALSE); - ++idx; - src = idx; - - /* do the scaling stuff */ - coeffs[0] = (float)aSrcWidth / (float)aDWidth; - coeffs[1] = 0.0; - coeffs[2] = 0.0; - coeffs[3] = (float)aSrcHeight / (float)aDHeight; - coeffs[4] = 0.0; - coeffs[5] = 0.0; - - constant[0] = 128.0; - constant[1] = 128.0; - constant[2] = 128.0; - - XieFloGeometry(&photoElement[idx], src, aDWidth, aDHeight, - coeffs, - constant, - 0x07, - xieValGeomNearestNeighbor, - NULL); - ++idx; - - /* export */ - XieFloExportDrawable(&photoElement[idx], idx, aDest, aGC, - (aDX - aSX), - (aDY - aSY)); -#ifdef DEBUG_XIE - printf("export to %d, %d (%dx%d)\n", (aDX - aSX), (aDY - aSY), - aDWidth, aDHeight); -#endif - ++idx; - - /* do the scale thing baby */ - XieExecuteImmediate(display, gPhotospace, 1, PR_FALSE, photoElement, idx); - - /* - XieFreePhotofloGraph(photoElement, 3); - */ -} - -PRBool -DrawScaledImageXIE(Display *display, - Drawable aDest, - GC aGC, - Drawable aSrc, - PRInt32 aSrcWidth, - PRInt32 aSrcHeight, - PRInt32 aSX, - PRInt32 aSY, - PRInt32 aSWidth, - PRInt32 aSHeight, - PRInt32 aDX, - PRInt32 aDY, - PRInt32 aDWidth, - PRInt32 aDHeight) -{ -#ifdef DEBUG_XIE - printf("DrawScaledImageXIE\n"); -#endif - - if (!useXIE) { -#ifdef DEBUG_XIE - fprintf(stderr, "useXIE is false.\n"); -#endif - return PR_FALSE; - } - - if (!inited) { - XieExtensionInfo *info; - - if (useXIE) { - char *text = PR_GetEnv("MOZ_DISABLE_XIE"); - if (text) { -#ifdef DEBUG_XIE - fprintf(stderr, "MOZ_DISABLE_XIE set, disabling use of XIE.\n"); -#endif - useXIE = PR_FALSE; - return PR_FALSE; - } - } - - if (!XieInitialize(display, &info)) { - useXIE = PR_FALSE; - return PR_FALSE; - } - - inited = PR_TRUE; - - /* create the photospace (we only need to do this once) */ - gPhotospace = XieCreatePhotospace(display); - - photoElement = XieAllocatePhotofloGraph(3); - - /* XXX we want to destroy this at shutdown - XieDestroyPhotospace(display, photospace); - */ - } - - /* run the flo on the image to get a the scaled image */ - DoFlo(display, aDest, aGC, aSrc, - aSrcWidth, aSrcHeight, - aSX, aSY, aSWidth, aSHeight, - aDX, aDY, aDWidth, aDHeight); - - return PR_TRUE; -} -#endif diff --git a/mozilla/gfx/src/xlib/drawers.h b/mozilla/gfx/src/xlib/drawers.h deleted file mode 100644 index 852aca73ced..00000000000 --- a/mozilla/gfx/src/xlib/drawers.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim:ts=2:et:sw=2: - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "prtypes.h" -#include - -PR_BEGIN_EXTERN_C - -#ifdef HAVE_XIE -PRBool -DrawScaledImageXIE(Display *display, - Drawable aDest, - GC aGC, - Drawable aSrc, - PRInt32 aSrcWidth, - PRInt32 aSrcHeight, - PRInt32 aSX, - PRInt32 aSY, - PRInt32 aSWidth, - PRInt32 aSHeight, - PRInt32 aDX, - PRInt32 aDY, - PRInt32 aDWidth, - PRInt32 aDHeight); -#endif - -PR_END_EXTERN_C diff --git a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp b/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp deleted file mode 100644 index c51bc322526..00000000000 --- a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp +++ /dev/null @@ -1,1393 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Roland Mainz - * Ken Herron - * Julien Lafon - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* Store per-printer features in temp. prefs vars that the - * print dialog can pick them up... */ -#define SET_PRINTER_FEATURES_VIA_PREFS 1 -#define PRINTERFEATURES_PREF "print.tmp.printerfeatures" - -#ifdef MOZ_LOGGING -#define FORCE_PR_LOG 1 /* Allow logging in the release build */ -#endif /* MOZ_LOGGING */ -#include "prlog.h" - -#include "plstr.h" - -#include "nsDeviceContextSpecXlib.h" - -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "prenv.h" /* for PR_GetEnv */ - -#include "nsPrintfCString.h" -#include "nsReadableUtils.h" -#include "nsIServiceManager.h" - -#ifdef USE_XPRINT -#include "xprintutil.h" -#endif /* USE_XPRINT */ - -#ifdef USE_POSTSCRIPT -#include "nsPSPrinters.h" -#include "nsPaperPS.h" /* Paper size list */ -#endif /* USE_POSTSCRIPT */ - -/* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */ -#define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE)) - -#ifdef PR_LOGGING -static PRLogModuleInfo *DeviceContextSpecXlibLM = PR_NewLogModule("DeviceContextSpecXlib"); -#endif /* PR_LOGGING */ -/* Macro to make lines shorter */ -#define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecXlibLM, PR_LOG_DEBUG, x) - -//---------------------------------------------------------------------------------- -// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecXlib -// The PrinterEnumerator creates the printer info -// but the nsDeviceContextSpecXlib cleans it up -// If it gets created (via the Page Setup Dialog) but the user never prints anything -// then it will never be delete, so this class takes care of that. -class GlobalPrinters { -public: - static GlobalPrinters* GetInstance() { return &mGlobalPrinters; } - ~GlobalPrinters() { FreeGlobalPrinters(); } - - void FreeGlobalPrinters(); - nsresult InitializeGlobalPrinters(); - - PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; } - PRInt32 GetNumPrinters() - { return mGlobalPrinterList ? mGlobalPrinterList->Count() : 0; } - nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); } - void GetDefaultPrinterName(PRUnichar **aDefaultPrinterName); - -protected: - GlobalPrinters() {} - - static GlobalPrinters mGlobalPrinters; - static nsStringArray* mGlobalPrinterList; -}; - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS -/* "Prototype" for the new nsPrinterFeatures service */ -class nsPrinterFeatures { -public: - nsPrinterFeatures( const char *printername ); - ~nsPrinterFeatures() {}; - - /* Does this printer allow to set/change the paper size ? */ - void SetCanChangePaperSize( PRBool aCanSetPaperSize ); - /* Does this Mozilla print module allow set/change the paper size ? */ - void SetSupportsPaperSizeChange( PRBool aSupportsPaperSizeChange ); - /* Set number of paper size records and the records itself */ - void SetNumPaperSizeRecords( PRInt32 aCount ); - void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch ); - - /* Does this printer allow to set/change the content orientation ? */ - void SetCanChangeOrientation( PRBool aCanSetOrientation ); - /* Does this Mozilla print module allow set/change the content orientation ? */ - void SetSupportsOrientationChange( PRBool aSupportsOrientationChange ); - /* Set number of orientation records and the records itself */ - void SetNumOrientationRecords( PRInt32 aCount ); - void SetOrientationRecord( PRInt32 aIndex, const char *aName ); - - /* Does this printer allow to set/change the plex mode ? */ - void SetCanChangePlex( PRBool aCanSetPlex ); - /* Does this Mozilla print module allow set/change the plex mode ? */ - void SetSupportsPlexChange( PRBool aSupportsPlexChange ); - /* Set number of plex records and the records itself */ - void SetNumPlexRecords( PRInt32 aCount ); - void SetPlexRecord( PRInt32 aIndex, const char *aName ); - - /* Does this printer allow to set/change the resolution name ? */ - void SetCanChangeResolutionName( PRBool aCanSetResolutionName ); - /* Does this Mozilla print module allow set/change the resolution name ? */ - void SetSupportsResolutionNameChange( PRBool aSupportsResolutionChange ); - /* Set number of resolution records and the records itself */ - void SetNumResolutionNameRecords( PRInt32 aCount ); - void SetResolutionNameRecord( PRInt32 aIndex, const char *aName ); - - /* Does this printer allow to set/change the colorspace ? */ - void SetCanChangeColorspace( PRBool aCanSetColorspace ); - /* Does this Mozilla print module allow set/change the colorspace ? */ - void SetSupportsColorspaceChange( PRBool aSupportsColorspace ); - /* Set number of colorspace records and the records itself */ - void SetNumColorspaceRecords( PRInt32 aCount ); - void SetColorspaceRecord( PRInt32 aIndex, const char *aName ); - - /* Does this device allow to set/change the usage of the internal grayscale mode ? */ - void SetCanChangePrintInColor( PRBool aCanSetPrintInColor ); - /* Does this printer allow to set/change the usage of the internal grayscale mode ? */ - void SetSupportsPrintInColorChange( PRBool aSupportPrintInColorChange ); - - /* Does this device allow to set/change the usage of font download to the printer? */ - void SetCanChangeDownloadFonts( PRBool aCanSetDownloadFonts ); - /* Does this printer allow to set/change the usage of font download to the printer? */ - void SetSupportsDownloadFontsChange( PRBool aSupportDownloadFontsChange ); - - /* Does this device allow to set/change the job title ? */ - void SetCanChangeJobTitle( PRBool aCanSetJobTitle ); - /* Does this printer allow to set/change the job title ? */ - void SetSupportsJobTitleChange( PRBool aSupportJobTitleChange ); - - /* Does this device allow to set/change the spooler command ? */ - void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand ); - /* Does this printer allow to set/change the spooler command ? */ - void SetSupportsSpoolerCommandChange( PRBool aSupportSpoolerCommandChange ); - - /* Does this device allow to set/change number of copies for an document ? */ - void SetCanChangeNumCopies( PRBool aCanSetNumCopies ); - - /* Does this device allow multiple devicecontext instances to be used in - * parallel (e.g. print while the device is already in use by print-preview - * or printing while another print job is in progress) ? */ - void SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ); - -private: - /* private helper methods */ - void SetBoolValue( const char *tagname, PRBool value ); - void SetIntValue( const char *tagname, PRInt32 value ); - void SetCharValue( const char *tagname, const char *value ); - - nsCString mPrinterName; - nsCOMPtr mPrefs; -}; - -void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value ) -{ - mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); -} - -void nsPrinterFeatures::SetIntValue( const char *tagname, PRInt32 value ) -{ - mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); -} - -void nsPrinterFeatures::SetCharValue( const char *tagname, const char *value ) -{ - mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); -} - -nsPrinterFeatures::nsPrinterFeatures( const char *printername ) -{ - DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername)); - mPrinterName.Assign(printername); - mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - - SetBoolValue("has_special_printerfeatures", PR_TRUE); -} - -void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize ) -{ - SetBoolValue("can_change_paper_size", aCanSetPaperSize); -} - -void nsPrinterFeatures::SetSupportsPaperSizeChange( PRBool aSupportsPaperSizeChange ) -{ - SetBoolValue("supports_paper_size_change", aSupportsPaperSizeChange); -} - -/* Set number of paper size records and the records itself */ -void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount ) -{ - SetIntValue("paper.count", aCount); -} - -void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch) -{ - SetCharValue(nsPrintfCString(256, "paper.%d.name", aIndex).get(), aPaperName); - SetIntValue( nsPrintfCString(256, "paper.%d.width_mm", aIndex).get(), aWidthMM); - SetIntValue( nsPrintfCString(256, "paper.%d.height_mm", aIndex).get(), aHeightMM); - SetBoolValue(nsPrintfCString(256, "paper.%d.is_inch", aIndex).get(), aIsInch); -} - -void nsPrinterFeatures::SetCanChangeOrientation( PRBool aCanSetOrientation ) -{ - SetBoolValue("can_change_orientation", aCanSetOrientation); -} - -void nsPrinterFeatures::SetSupportsOrientationChange( PRBool aSupportsOrientationChange ) -{ - SetBoolValue("supports_orientation_change", aSupportsOrientationChange); -} - -void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount ) -{ - SetIntValue("orientation.count", aCount); -} - -void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName ) -{ - SetCharValue(nsPrintfCString(256, "orientation.%d.name", aIndex).get(), aOrientationName); -} - -void nsPrinterFeatures::SetCanChangePlex( PRBool aCanSetPlex ) -{ - SetBoolValue("can_change_plex", aCanSetPlex); -} - -void nsPrinterFeatures::SetSupportsPlexChange( PRBool aSupportsPlexChange ) -{ - SetBoolValue("supports_plex_change", aSupportsPlexChange); -} - -void nsPrinterFeatures::SetNumPlexRecords( PRInt32 aCount ) -{ - SetIntValue("plex.count", aCount); -} - -void nsPrinterFeatures::SetPlexRecord( PRInt32 aIndex, const char *aPlexName ) -{ - SetCharValue(nsPrintfCString(256, "plex.%d.name", aIndex).get(), aPlexName); -} - -void nsPrinterFeatures::SetCanChangeResolutionName( PRBool aCanSetResolutionName ) -{ - SetBoolValue("can_change_resolution", aCanSetResolutionName); -} - -void nsPrinterFeatures::SetSupportsResolutionNameChange( PRBool aSupportsResolutionNameChange ) -{ - SetBoolValue("supports_resolution_change", aSupportsResolutionNameChange); -} - -void nsPrinterFeatures::SetNumResolutionNameRecords( PRInt32 aCount ) -{ - SetIntValue("resolution.count", aCount); -} - -void nsPrinterFeatures::SetResolutionNameRecord( PRInt32 aIndex, const char *aResolutionName ) -{ - SetCharValue(nsPrintfCString(256, "resolution.%d.name", aIndex).get(), aResolutionName); -} - -void nsPrinterFeatures::SetCanChangeColorspace( PRBool aCanSetColorspace ) -{ - SetBoolValue("can_change_colorspace", aCanSetColorspace); -} - -void nsPrinterFeatures::SetSupportsColorspaceChange( PRBool aSupportsColorspaceChange ) -{ - SetBoolValue("supports_colorspace_change", aSupportsColorspaceChange); -} - -void nsPrinterFeatures::SetNumColorspaceRecords( PRInt32 aCount ) -{ - SetIntValue("colorspace.count", aCount); -} - -void nsPrinterFeatures::SetColorspaceRecord( PRInt32 aIndex, const char *aColorspace ) -{ - SetCharValue(nsPrintfCString(256, "colorspace.%d.name", aIndex).get(), aColorspace); -} - -void nsPrinterFeatures::SetCanChangeDownloadFonts( PRBool aCanSetDownloadFonts ) -{ - SetBoolValue("can_change_downloadfonts", aCanSetDownloadFonts); -} - -void nsPrinterFeatures::SetSupportsDownloadFontsChange( PRBool aSupportDownloadFontsChange ) -{ - SetBoolValue("supports_downloadfonts_change", aSupportDownloadFontsChange); -} - -void nsPrinterFeatures::SetCanChangePrintInColor( PRBool aCanSetPrintInColor ) -{ - SetBoolValue("can_change_printincolor", aCanSetPrintInColor); -} - -void nsPrinterFeatures::SetSupportsPrintInColorChange( PRBool aSupportPrintInColorChange ) -{ - SetBoolValue("supports_printincolor_change", aSupportPrintInColorChange); -} - -void nsPrinterFeatures::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand ) -{ - SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand); -} - -void nsPrinterFeatures::SetSupportsSpoolerCommandChange( PRBool aSupportSpoolerCommandChange ) -{ - SetBoolValue("supports_spoolercommand_change", aSupportSpoolerCommandChange); -} - -void nsPrinterFeatures::SetCanChangeJobTitle( PRBool aCanSetJobTitle ) -{ - SetBoolValue("can_change_jobtitle", aCanSetJobTitle); -} - -void nsPrinterFeatures::SetSupportsJobTitleChange( PRBool aSupportsJobTitle ) -{ - SetBoolValue("supports_jobtitle_change", aSupportsJobTitle); -} - -void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies ) -{ - SetBoolValue("can_change_num_copies", aCanSetNumCopies); -} - -void nsPrinterFeatures::SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ) -{ - SetBoolValue("can_use_multiple_devicecontexts_concurrently", aCanUseMultipleInstances); -} - -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - -//--------------- -// static members -GlobalPrinters GlobalPrinters::mGlobalPrinters; -nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull; -//--------------- - -nsDeviceContextSpecXlib::nsDeviceContextSpecXlib() -{ - DO_PR_DEBUG_LOG(("nsDeviceContextSpecXlib::nsDeviceContextSpecXlib()\n")); -} - -nsDeviceContextSpecXlib::~nsDeviceContextSpecXlib() -{ - DO_PR_DEBUG_LOG(("nsDeviceContextSpecXlib::~nsDeviceContextSpecXlib()\n")); -} - -/* Use both PostScript and Xprint module */ -#if defined(USE_XPRINT) && defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS3(nsDeviceContextSpecXlib, - nsIDeviceContextSpec, - nsIDeviceContextSpecPS, - nsIDeviceContextSpecXp) -/* Use only PostScript module */ -#elif !defined(USE_XPRINT) && defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS2(nsDeviceContextSpecXlib, - nsIDeviceContextSpec, - nsIDeviceContextSpecPS) -/* Use only Xprint module module */ -#elif defined(USE_XPRINT) && !defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS2(nsDeviceContextSpecXlib, - nsIDeviceContextSpec, - nsIDeviceContextSpecXp) -/* Both Xprint and PostScript module are missing */ -#elif !defined(USE_XPRINT) && !defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS1(nsDeviceContextSpecXlib, - nsIDeviceContextSpec) -#else -#error "This should not happen" -#endif - -/** ------------------------------------------------------- - * Initialize the nsDeviceContextSpecXlib - * @update dc 2/15/98 - * @update syd 3/2/99 - * - * gisburn: Please note that this function exists as 1:1 copy in other - * toolkits including: - * - GTK+-toolkit: - * file: mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp - * function: NS_IMETHODIMP nsDeviceContextSpecXlib::Init() - * - Xlib-toolkit: - * file: mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.cpp - * function: NS_IMETHODIMP nsDeviceContextSpecXlib::Init() - * - * ** Please update the other toolkits when changing this function. - */ -NS_IMETHODIMP nsDeviceContextSpecXlib::Init(nsIWidget *aWidget, - nsIPrintSettings* aPS, - PRBool aIsPrintPreview) -{ - DO_PR_DEBUG_LOG(("nsDeviceContextSpecXlib::Init(aPS=%p)\n", aPS)); - nsresult rv = NS_ERROR_FAILURE; - - mPrintSettings = aPS; - - // if there is a current selection then enable the "Selection" radio button - rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); - if (NS_FAILED(rv)) { - return rv; - } - - GlobalPrinters::GetInstance()->FreeGlobalPrinters(); - - if (aPS) { - PRBool reversed = PR_FALSE; - PRBool color = PR_FALSE; - PRBool tofile = PR_FALSE; - PRInt16 printRange = nsIPrintSettings::kRangeAllPages; - PRInt32 orientation = NS_PORTRAIT; - PRInt32 fromPage = 1; - PRInt32 toPage = 1; - PRUnichar *command = nsnull; - PRInt32 copies = 1; - PRUnichar *printer = nsnull; - PRUnichar *papername = nsnull; - PRUnichar *plexname = nsnull; - PRUnichar *resolutionname = nsnull; - PRUnichar *colorspace = nsnull; - PRBool downloadfonts = PR_TRUE; - PRUnichar *printfile = nsnull; - double dleft = 0.5; - double dright = 0.5; - double dtop = 0.5; - double dbottom = 0.5; - - aPS->GetPrinterName(&printer); - aPS->GetPrintReversed(&reversed); - aPS->GetPrintInColor(&color); - aPS->GetPaperName(&papername); - aPS->GetResolutionName(&resolutionname); - aPS->GetColorspace(&colorspace); - aPS->GetDownloadFonts(&downloadfonts); - aPS->GetPlexName(&plexname); - aPS->GetOrientation(&orientation); - aPS->GetPrintCommand(&command); - aPS->GetPrintRange(&printRange); - aPS->GetToFileName(&printfile); - aPS->GetPrintToFile(&tofile); - aPS->GetStartPageRange(&fromPage); - aPS->GetEndPageRange(&toPage); - aPS->GetNumCopies(&copies); - aPS->GetMarginTop(&dtop); - aPS->GetMarginLeft(&dleft); - aPS->GetMarginBottom(&dbottom); - aPS->GetMarginRight(&dright); - - if (printfile) - PL_strncpyz(mPath, NS_ConvertUTF16toUTF8(printfile).get(), sizeof(mPath)); - if (command) - PL_strncpyz(mCommand, NS_ConvertUTF16toUTF8(command).get(), sizeof(mCommand)); - if (printer) - PL_strncpyz(mPrinter, NS_ConvertUTF16toUTF8(printer).get(), sizeof(mPrinter)); - if (papername) - PL_strncpyz(mPaperName, NS_ConvertUTF16toUTF8(papername).get(), sizeof(mPaperName)); - if (plexname) - PL_strncpyz(mPlexName, NS_ConvertUTF16toUTF8(plexname).get(), sizeof(mPlexName)); - if (resolutionname) - PL_strncpyz(mResolutionName, NS_ConvertUTF16toUTF8(resolutionname).get(), sizeof(mResolutionName)); - if (colorspace) - PL_strncpyz(mColorspace, NS_ConvertUTF16toUTF8(colorspace).get(), sizeof(mColorspace)); - - DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright)); - DO_PR_DEBUG_LOG(("printRange %d\n", printRange)); - DO_PR_DEBUG_LOG(("fromPage %d\n", fromPage)); - DO_PR_DEBUG_LOG(("toPage %d\n", toPage)); - DO_PR_DEBUG_LOG(("tofile %d\n", tofile)); - DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUTF16toUTF8(printfile).get():"")); - DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUTF16toUTF8(command).get():"")); - DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUTF16toUTF8(printer).get():"")); - DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUTF16toUTF8(papername).get():"")); - DO_PR_DEBUG_LOG(("plexname '%s'\n", plexname? NS_ConvertUTF16toUTF8(plexname).get():"")); - DO_PR_DEBUG_LOG(("resolution '%s'\n", resolutionname? NS_ConvertUTF16toUTF8(resolutionname).get():"")); - DO_PR_DEBUG_LOG(("colorspace '%s'\n", colorspace? NS_ConvertUTF16toUTF8(colorspace).get():"")); - - mTop = dtop; - mBottom = dbottom; - mLeft = dleft; - mRight = dright; - mFpf = !reversed; - mDownloadFonts = downloadfonts; - mGrayscale = !color; - mOrientation = orientation; - mToPrinter = !tofile; - mCopies = copies; - mIsPPreview = aIsPrintPreview; - mCancel = PR_FALSE; - } - - return rv; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetToPrinter(PRBool &aToPrinter) -{ - aToPrinter = mToPrinter; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetIsPrintPreview(PRBool &aIsPPreview) -{ - aIsPPreview = mIsPPreview; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrinterName ( const char **aPrinter ) -{ - *aPrinter = mPrinter; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetCopies ( int &aCopies ) -{ - aCopies = mCopies; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetFirstPageFirst(PRBool &aFpf) -{ - aFpf = mFpf; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetGrayscale(PRBool &aGrayscale) -{ - aGrayscale = mGrayscale; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetLandscape(PRBool &aLandscape) -{ - aLandscape = (mOrientation == NS_LANDSCAPE); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetTopMargin(float &aValue) -{ - aValue = mTop; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetBottomMargin(float &aValue) -{ - aValue = mBottom; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetRightMargin(float &aValue) -{ - aValue = mRight; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetLeftMargin(float &aValue) -{ - aValue = mLeft; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetCommand(const char **aCommand) -{ - *aCommand = mCommand; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPath(const char **aPath) -{ - *aPath = mPath; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetUserCancelled(PRBool &aCancel) -{ - aCancel = mCancel; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPaperName( const char **aPaperName ) -{ - *aPaperName = mPaperName; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPlexName( const char **aPlexName ) -{ - *aPlexName = mPlexName; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetResolutionName( const char **aResolutionName ) -{ - *aResolutionName = mResolutionName; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetColorspace( const char **aColorspace ) -{ - *aColorspace = mColorspace; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetDownloadFonts(PRBool &aDownloadFonts) -{ - aDownloadFonts = mDownloadFonts; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) -{ - return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::GetPrintMethod(PrintMethod &aMethod) -{ - return GetPrintMethod(mPrinter, aMethod); -} - -/* static !! */ -nsresult nsDeviceContextSpecXlib::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod) -{ -#if defined(USE_POSTSCRIPT) && defined(USE_XPRINT) - if (nsPSPrinterList::kTypeUnknown == - nsPSPrinterList::GetPrinterType(nsDependentCString(aPrinter))) - aMethod = pmXprint; - else - aMethod = pmPostScript; - return NS_OK; -#elif defined(USE_XPRINT) - aMethod = pmXprint; - return NS_OK; -#elif defined(USE_POSTSCRIPT) - aMethod = pmPostScript; - return NS_OK; -#else - return NS_ERROR_UNEXPECTED; -#endif -} - -NS_IMETHODIMP nsDeviceContextSpecXlib::ClosePrintManager() -{ - return NS_OK; -} - -/* Get prefs for printer - * Search order: - * - Get prefs per printer name and module name - * - Get prefs per printer name - * - Get prefs per module name - * - Get prefs - */ -static -nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char *printername, const char *prefname, char **return_buf) -{ - DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname)); - - nsresult rv = NS_ERROR_FAILURE; - - if (printername && modulename) { - /* Get prefs per printer name and module name */ - nsPrintfCString name(512, "print.%s.printer_%s.%s", modulename, printername, prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); - } - - if (NS_FAILED(rv)) { - if (printername) { - /* Get prefs per printer name */ - name = nsPrintfCString(512, "print.printer_%s.%s", printername, prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); - } - - if (NS_FAILED(rv)) { - if (modulename) { - /* Get prefs per module name */ - nsPrintfCString name(512, "print.%s.%s", modulename, prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); - } - - if (NS_FAILED(rv)) { - /* Get prefs */ - nsPrintfCString name(512, "print.%s", prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->GetCharPref(name.get(), getter_Copies(return_buf)); - } - } - } - -#ifdef PR_LOG - if (NS_SUCCEEDED(rv)) { - DO_PR_DEBUG_LOG(("CopyPrinterCharPref returning '%s'.\n", return_buf.get())); - } - else - { - DO_PR_DEBUG_LOG(("CopyPrinterCharPref failure.\n")); - } -#endif /* PR_LOG */ - - return rv; -} - -// Printer Enumerator -nsPrinterEnumeratorXlib::nsPrinterEnumeratorXlib() -{ -} - -NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorXlib, nsIPrinterEnumerator) - -NS_IMETHODIMP nsPrinterEnumeratorXlib::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) -{ - NS_ENSURE_ARG(aCount); - NS_ENSURE_ARG_POINTER(aResult); - - if (aCount) - *aCount = 0; - else - return NS_ERROR_NULL_POINTER; - - if (aResult) - *aResult = nsnull; - else - return NS_ERROR_NULL_POINTER; - - nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); - if (NS_FAILED(rv)) { - return rv; - } - - PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters(); - - PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*)); - if (!array && numPrinters > 0) { - GlobalPrinters::GetInstance()->FreeGlobalPrinters(); - return NS_ERROR_OUT_OF_MEMORY; - } - - int count = 0; - while( count < numPrinters ) - { - PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count)); - - if (!str) { - for (int i = count - 1; i >= 0; i--) - nsMemory::Free(array[i]); - - nsMemory::Free(array); - - GlobalPrinters::GetInstance()->FreeGlobalPrinters(); - return NS_ERROR_OUT_OF_MEMORY; - } - array[count++] = str; - - } - *aCount = count; - *aResult = array; - GlobalPrinters::GetInstance()->FreeGlobalPrinters(); - - return NS_OK; -} - -/* readonly attribute wstring defaultPrinterName; */ -NS_IMETHODIMP nsPrinterEnumeratorXlib::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName) -{ - DO_PR_DEBUG_LOG(("nsPrinterEnumeratorXlib::GetDefaultPrinterName()\n")); - NS_ENSURE_ARG_POINTER(aDefaultPrinterName); - - GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName); - - DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUTF16toUTF8(*aDefaultPrinterName).get())); - return NS_OK; -} - -/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */ -NS_IMETHODIMP nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings) -{ - DO_PR_DEBUG_LOG(("nsPrinterEnumeratorXlib::InitPrintSettingsFromPrinter()")); - nsresult rv; - - NS_ENSURE_ARG_POINTER(aPrinterName); - NS_ENSURE_ARG_POINTER(aPrintSettings); - - NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE); - - nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - - nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */ - printerName; /* "Stripped" name of printer */ - fullPrinterName.Assign(NS_ConvertUTF16toUTF8(aPrinterName)); - printerName.Assign(NS_ConvertUTF16toUTF8(aPrinterName)); - DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get())); - - PrintMethod type = pmInvalid; - rv = nsDeviceContextSpecXlib::GetPrintMethod(printerName, type); - if (NS_FAILED(rv)) - return rv; - -#ifdef USE_POSTSCRIPT - /* "Demangle" postscript printer name */ - if (type == pmPostScript) { - /* Strip the printing method name from the printer, - * e.g. turn "PostScript/foobar" to "foobar" */ - PRInt32 slash = printerName.FindChar('/'); - if (kNotFound != slash) - printerName.Cut(0, slash + 1); - } -#endif /* USE_POSTSCRIPT */ - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - /* Defaults to FALSE */ - pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - - /* Set filename */ - nsXPIDLCString filename; - if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", filename))) { - const char *path; - - if (!(path = PR_GetEnv("PWD"))) - path = PR_GetEnv("HOME"); - - if (path) - filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path); - else - filename.AssignLiteral("mozilla.ps"); - } - DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get())); - aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename).get()); - - aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE); - -#ifdef USE_XPRINT - if (type == pmXprint) { - DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for Xprint printer\n")); - - /* Setup the capabilities list of Mozilla's Xprint print module */ -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - nsPrinterFeatures printerFeatures(fullPrinterName); - - printerFeatures.SetSupportsPaperSizeChange(PR_TRUE); - printerFeatures.SetSupportsOrientationChange(PR_TRUE); - printerFeatures.SetSupportsPlexChange(PR_TRUE); - printerFeatures.SetSupportsResolutionNameChange(PR_TRUE); - printerFeatures.SetSupportsColorspaceChange(PR_TRUE); - printerFeatures.SetSupportsJobTitleChange(PR_TRUE); - printerFeatures.SetSupportsSpoolerCommandChange(PR_FALSE); /* won't work by design and very good reasons! */ -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* Setup the capabilities list of this specific printer */ - - Display *pdpy; - XPContext pcontext; - if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1) - return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND; - - XpuSupportedFlags supported_doc_attrs = XpuGetSupportedDocAttributes(pdpy, pcontext); - - /* Setup orientation stuff */ - XpuOrientationList olist; - int ocount; - XpuOrientationRec *default_orientation; - - /* Setup plex stuff */ - XpuPlexList plexlist; - int plexcount; - XpuPlexRec *default_plex; - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - PRBool canSetOrientation = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION); - printerFeatures.SetCanChangeOrientation(canSetOrientation); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* Get list of supported orientations */ - olist = XpuGetOrientationList(pdpy, pcontext, &ocount); - if (olist) { - default_orientation = &olist[0]; /* First entry is the default one */ - - if (!PL_strcasecmp(default_orientation->orientation, "portrait")) { - DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n")); - aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); - } - else if (!PL_strcasecmp(default_orientation->orientation, "landscape")) { - DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n")); - aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation); - } - else { - DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation)); - } - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - int i; - for( i = 0 ; i < ocount ; i++ ) - { - XpuOrientationRec *curr = &olist[i]; - printerFeatures.SetOrientationRecord(i, curr->orientation); - } - printerFeatures.SetNumOrientationRecords(ocount); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuFreeOrientationList(olist); - } - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - PRBool canSetPlexMode = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_PLEX); - printerFeatures.SetCanChangePlex(canSetPlexMode); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* Get list of supported plex modes */ - plexlist = XpuGetPlexList(pdpy, pcontext, &plexcount); - if (plexlist) { - default_plex = &plexlist[0]; /* First entry is the default one */ - - DO_PR_DEBUG_LOG(("setting default plex to '%s'\n", default_plex->plex)); - aPrintSettings->SetPlexName(NS_ConvertUTF8toUTF16(default_plex->plex).get()); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - int i; - for( i = 0 ; i < plexcount ; i++ ) - { - XpuPlexRec *curr = &plexlist[i]; - printerFeatures.SetPlexRecord(i, curr->plex); - } - printerFeatures.SetNumPlexRecords(plexcount); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuFreePlexList(plexlist); - } - - /* Setup Number of Copies */ -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - PRBool canSetNumCopies = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_COPY_COUNT); - printerFeatures.SetCanChangeNumCopies(canSetNumCopies); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - long numCopies; - if( XpuGetOneLongAttribute(pdpy, pcontext, XPDocAttr, "copy-count", &numCopies) != 1 ) - { - /* Fallback on failure */ - numCopies = 1; - } - aPrintSettings->SetNumCopies(numCopies); - - /* Setup paper size stuff */ - XpuMediumSourceSizeList mlist; - int mcount; - XpuMediumSourceSizeRec *default_medium; - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - PRBool canSetPaperSize = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM); - printerFeatures.SetCanChangePaperSize(canSetPaperSize); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount); - if (mlist) { - nsCAutoString papername; - - default_medium = &mlist[0]; /* First entry is the default one */ - double total_width = default_medium->ma1 + default_medium->ma2, - total_height = default_medium->ma3 + default_medium->ma4; - - /* Either "paper" or "tray/paper" */ - if (default_medium->tray_name) { - papername.Append(default_medium->tray_name); - papername.Append('/'); - } - papername.Append(default_medium->medium_name); - - DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g/%g mm)\n", papername.get(), total_width, total_height)); - aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined); - aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); - aPrintSettings->SetPaperWidth(total_width); - aPrintSettings->SetPaperHeight(total_height); - aPrintSettings->SetPaperName(NS_ConvertUTF8toUTF16(papername).get()); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - int i; - for( i = 0 ; i < mcount ; i++ ) - { - XpuMediumSourceSizeRec *curr = &mlist[i]; - double total_width = curr->ma1 + curr->ma2, - total_height = curr->ma3 + curr->ma4; - - papername.Truncate(); - if (curr->tray_name) { - papername.Append(curr->tray_name); - papername.Append('/'); - } - papername.Append(curr->medium_name); - - printerFeatures.SetPaperRecord(i, papername.get(), PRInt32(total_width), PRInt32(total_height), PR_FALSE); - } - printerFeatures.SetNumPaperSizeRecords(mcount); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuFreeMediumSourceSizeList(mlist); - } - - /* Setup resolution/quality stuff */ - XpuResolutionList rlist; - int rcount; - XpuResolutionRec *default_resolution; - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - PRBool canSetResolutionName = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION); - printerFeatures.SetCanChangeResolutionName(canSetResolutionName); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - rlist = XpuGetResolutionList(pdpy, pcontext, &rcount); - if (rlist) { - default_resolution = &rlist[0]; /* First entry is the default one */ - - DO_PR_DEBUG_LOG(("setting default resolution to '%s'/%ldx%ld\n", - default_resolution->name, - default_resolution->x_dpi, - default_resolution->y_dpi)); - aPrintSettings->SetResolutionName(NS_ConvertUTF8toUTF16(default_resolution->name).get()); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - int i; - for( i = 0 ; i < rcount ; i++ ) - { - XpuResolutionRec *curr = &rlist[i]; - printerFeatures.SetResolutionNameRecord(i, curr->name); - } - printerFeatures.SetNumResolutionNameRecords(rcount); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuFreeResolutionList(rlist); - } - - /* We still support the old print-in-color boolean */ - printerFeatures.SetSupportsPrintInColorChange(PR_TRUE); - printerFeatures.SetCanChangePrintInColor(PR_TRUE); - - /* Setup colorspace stuff */ - XpuColorspaceList cslist; - int cscount; - XpuColorspaceRec *default_colorspace; - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangeColorspace(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - cslist = XpuGetColorspaceList(pdpy, pcontext, &cscount); - if (cslist) { - default_colorspace = &cslist[0]; /* First entry is the default one */ - - DO_PR_DEBUG_LOG(("setting default colorspace to '%s'\n", default_colorspace->name)); - aPrintSettings->SetColorspace(NS_ConvertUTF8toUTF16(default_colorspace->name).get()); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - int i; - for( i = 0 ; i < cscount ; i++ ) - { - XpuColorspaceRec *curr = &cslist[i]; - printerFeatures.SetColorspaceRecord(i, curr->name); - } - printerFeatures.SetNumColorspaceRecords(cscount); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuFreeColorspaceList(cslist); - } - - /* Fonts */ - PRBool canSetListFontsMode = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_LISTFONTS_MODES); - printerFeatures.SetCanChangeDownloadFonts(canSetListFontsMode); - printerFeatures.SetSupportsDownloadFontsChange(PR_TRUE); - - Bool downloadFonts = XpuGetEnableFontDownload(pdpy, pcontext); - aPrintSettings->SetDownloadFonts(downloadFonts); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - /* Xprint does not allow the client to set a spooler command. - * Job spooling is the job of the server side (=Xprt) */ - printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE); - - /* Check whether printer/driver allow changes of the job name */ - PRBool canSetJobName = MAKE_PR_BOOL(XpuGetSupportedJobAttributes(pdpy, pcontext) & XPUATTRIBUTESUPPORTED_JOB_NAME); - printerFeatures.SetCanChangeJobTitle(canSetJobName); - - /* Mozilla's Xprint support allows multiple nsIDeviceContext instances - * be used in parallel */ - printerFeatures.SetMultipleConcurrentDeviceContextsSupported(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuClosePrinterDisplay(pdpy, pcontext); - - return NS_OK; - } - else -#endif /* USE_XPRINT */ - -#ifdef USE_POSTSCRIPT - if (type == pmPostScript) { - DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n")); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - nsPrinterFeatures printerFeatures(fullPrinterName); - - printerFeatures.SetSupportsPaperSizeChange(PR_TRUE); - printerFeatures.SetSupportsOrientationChange(PR_TRUE); - printerFeatures.SetSupportsPlexChange(PR_FALSE); - printerFeatures.SetSupportsResolutionNameChange(PR_FALSE); - printerFeatures.SetSupportsColorspaceChange(PR_FALSE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangeOrientation(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - nsXPIDLCString orientation; - if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", orientation))) { - if (orientation.LowerCaseEqualsLiteral("portrait")) { - DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n")); - aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); - } - else if (orientation.LowerCaseEqualsLiteral("landscape")) { - DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n")); - aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation); - } - else { - DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get())); - } - } - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetOrientationRecord(0, "portrait"); - printerFeatures.SetOrientationRecord(1, "landscape"); - printerFeatures.SetNumOrientationRecords(2); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* PostScript module does not support changing the plex mode... */ -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangePlex(PR_FALSE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - DO_PR_DEBUG_LOG(("setting default plex to '%s'\n", "default")); - aPrintSettings->SetPlexName(NS_LITERAL_STRING("default").get()); -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetPlexRecord(0, "default"); - printerFeatures.SetNumPlexRecords(1); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* PostScript module does not support changing the resolution mode... */ -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangeResolutionName(PR_FALSE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - DO_PR_DEBUG_LOG(("setting default resolution to '%s'\n", "default")); - aPrintSettings->SetResolutionName(NS_LITERAL_STRING("default").get()); -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetResolutionNameRecord(0, "default"); - printerFeatures.SetNumResolutionNameRecords(1); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* PostScript module does not support changing the colorspace... */ -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangeColorspace(PR_FALSE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - DO_PR_DEBUG_LOG(("setting default colorspace to '%s'\n", "default")); - aPrintSettings->SetColorspace(NS_LITERAL_STRING("default").get()); -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetColorspaceRecord(0, "default"); - printerFeatures.SetNumColorspaceRecords(1); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangePaperSize(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - nsXPIDLCString papername; - if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", papername))) { - nsPaperSizePS paper; - - if (paper.Find(papername)) { - DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g mm/%g mm)\n", - paper.Name(), paper.Width_mm(), paper.Height_mm())); - aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); - aPrintSettings->SetPaperWidth(paper.Width_mm()); - aPrintSettings->SetPaperHeight(paper.Height_mm()); - aPrintSettings->SetPaperName(NS_ConvertASCIItoUTF16(paper.Name()).get()); - } - else { - DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get())); - } -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - paper.First(); - int count = 0; - while (!paper.AtEnd()) - { - printerFeatures.SetPaperRecord(count++, paper.Name(), - (int)paper.Width_mm(), (int)paper.Height_mm(), !paper.IsMetric()); - paper.Next(); - } - printerFeatures.SetNumPaperSizeRecords(count); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - } - - PRBool hasSpoolerCmd = (nsPSPrinterList::kTypePS == - nsPSPrinterList::GetPrinterType(fullPrinterName)); -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetSupportsSpoolerCommandChange(hasSpoolerCmd); - printerFeatures.SetCanChangeSpoolerCommand(hasSpoolerCmd); - - /* Postscript module does not pass the job title to lpr */ - printerFeatures.SetSupportsJobTitleChange(PR_FALSE); - printerFeatures.SetCanChangeJobTitle(PR_FALSE); - /* Postscript module has no control over builtin fonts yet */ - printerFeatures.SetSupportsDownloadFontsChange(PR_FALSE); - printerFeatures.SetCanChangeDownloadFonts(PR_FALSE); - /* Postscript module does not support multiple colorspaces - * so it has to use the old way */ - printerFeatures.SetSupportsPrintInColorChange(PR_TRUE); - printerFeatures.SetCanChangePrintInColor(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - if (hasSpoolerCmd) { - nsXPIDLCString command; - if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", - printerName, "print_command", command))) { - DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", - command.get())); - aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUTF16(command).get()); - } - } - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangeNumCopies(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - return NS_OK; - } -#endif /* USE_POSTSCRIPT */ - - return NS_ERROR_UNEXPECTED; -} - -NS_IMETHODIMP nsPrinterEnumeratorXlib::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings) -{ - return NS_OK; -} - - -//---------------------------------------------------------------------- -//String array enumeration callback to append a printer to the global -//printer list. -static PRBool -GlobalPrinterEnumFunc(nsCString& aName, void *aData) -{ - nsStringArray *a = (nsStringArray *)aData; - a->AppendString(NS_ConvertUTF8toUTF16(aName)); - return PR_TRUE; -} - -//---------------------------------------------------------------------- -nsresult GlobalPrinters::InitializeGlobalPrinters () -{ - if (PrintersAreAllocated()) { - return NS_OK; - } - - mGlobalPrinterList = new nsStringArray(); - if (!mGlobalPrinterList) - return NS_ERROR_OUT_OF_MEMORY; - - nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - -#ifdef USE_XPRINT - int printerCount; - XPPrinterList plist = XpuGetPrinterList(nsnull, &printerCount); - - if (plist) - { - int i; - for( i = 0 ; i < printerCount ; i++ ) - { - /* Add name to our list of printers... */ - mGlobalPrinterList->AppendString(nsString(NS_ConvertUTF8toUTF16(plist[i].name))); - - /* ... and store the description text for this printer */ - pPrefs->SetCharPref(nsPrintfCString(256, "print.printer_%s.printer_description", plist[i].name).get(), plist[i].desc); - } - - XpuFreePrinterList(plist); - } -#endif /* USE_XPRINT */ - -#ifdef USE_POSTSCRIPT - nsPSPrinterList psMgr; - if (NS_SUCCEEDED(psMgr.Init()) && psMgr.Enabled()) { - /* Get the list of PostScript-module printers */ - nsCStringArray printerList; - psMgr.GetPrinterList(printerList); - printerList.EnumerateForwards(GlobalPrinterEnumFunc, mGlobalPrinterList); - } -#endif /* USE_POSTSCRIPT */ - - /* If there are no printers available after all checks, return an error */ - if (!mGlobalPrinterList->Count()) - { - /* Make sure we do not cache an empty printer list */ - FreeGlobalPrinters(); - -#ifdef USE_XPRINT - /* Check if there are actually any Xprint servers available */ - if (!XpuXprintServersAvailable()) { - return NS_ERROR_GFX_PRINTER_XPRINT_NO_XPRINT_SERVERS_FOUND; - } -#endif /* USE_XPRINT */ - - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; - } - - return NS_OK; -} - -//---------------------------------------------------------------------- -void GlobalPrinters::FreeGlobalPrinters() -{ - if (mGlobalPrinterList) { - delete mGlobalPrinterList; - mGlobalPrinterList = nsnull; - } -} - -void -GlobalPrinters::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName) -{ - *aDefaultPrinterName = nsnull; - - PRBool allocate = (GlobalPrinters::GetInstance()->PrintersAreAllocated() == PR_FALSE); - - if (allocate) { - nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); - if (NS_FAILED(rv)) { - return; - } - } - NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters"); - - if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0) - return; - - *aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0)); - - if (allocate) { - GlobalPrinters::GetInstance()->FreeGlobalPrinters(); - } -} - diff --git a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h b/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h deleted file mode 100644 index 979e7bd5b4c..00000000000 --- a/mozilla/gfx/src/xlib/nsDeviceContextSpecXlib.h +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Roland Mainz - * Julien Lafon - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDeviceContextSpecXlib_h___ -#define nsDeviceContextSpecXlib_h___ - -#include "nsIDeviceContextSpec.h" -#include "nsIPrintSettings.h" -#include "nsIPrintOptions.h" -#include "nsVoidArray.h" -#include "nsCOMPtr.h" -#ifdef USE_POSTSCRIPT -#include "nsIDeviceContextSpecPS.h" -#endif /* USE_POSTSCRIPT */ -#ifdef USE_XPRINT -#include "nsIDeviceContextSpecXPrint.h" -#endif /* USE_XPRINT */ -#include "nsCRT.h" /* should be ? */ - -#define NS_PORTRAIT 0 -#define NS_LANDSCAPE 1 - -typedef enum -{ - pmInvalid = 0, - pmXprint, - pmPostScript -} PrintMethod; - -class nsDeviceContextSpecXlib : public nsIDeviceContextSpec -#ifdef USE_POSTSCRIPT - , public nsIDeviceContextSpecPS -#endif /* USE_POSTSCRIPT */ -#ifdef USE_XPRINT - , public nsIDeviceContextSpecXp -#endif /* USE_XPRINT */ -{ -public: - nsDeviceContextSpecXlib(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(nsIWidget *aWidget, nsIPrintSettings* aPS, PRBool aIsPrintPreview); - NS_IMETHOD ClosePrintManager(); - - NS_IMETHOD GetToPrinter(PRBool &aToPrinter); - NS_IMETHOD GetIsPrintPreview(PRBool &aIsPPreview); - NS_IMETHOD GetPrinterName ( const char **aPrinter ); - NS_IMETHOD GetCopies ( int &aCopies ); - NS_IMETHOD GetFirstPageFirst(PRBool &aFpf); - NS_IMETHOD GetGrayscale(PRBool &aGrayscale); - NS_IMETHOD GetTopMargin(float &value); - NS_IMETHOD GetBottomMargin(float &value); - NS_IMETHOD GetLeftMargin(float &value); - NS_IMETHOD GetRightMargin(float &value); - NS_IMETHOD GetCommand(const char **aCommand); - NS_IMETHOD GetPath (const char **aPath); - NS_IMETHOD GetLandscape (PRBool &aLandscape); - NS_IMETHOD GetUserCancelled(PRBool &aCancel); - NS_IMETHOD GetPrintMethod(PrintMethod &aMethod); - static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod); - NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight); - NS_IMETHOD GetPaperName(const char **aPaperName); - NS_IMETHOD GetPlexName(const char **aPlexName); - NS_IMETHOD GetResolutionName(const char **aResolutionName); - NS_IMETHOD GetColorspace(const char **aColorspace); - NS_IMETHOD GetDownloadFonts(PRBool &aDownloadFonts); - virtual ~nsDeviceContextSpecXlib(); - -protected: - nsCOMPtr mPrintSettings; - PRPackedBool mToPrinter : 1; /* If PR_TRUE, print to printer */ - PRPackedBool mIsPPreview : 1; /* If PR_TRUE, is print preview */ - PRPackedBool mFpf : 1; /* If PR_TRUE, first page first */ - PRPackedBool mGrayscale : 1; /* If PR_TRUE, print grayscale */ - PRPackedBool mDownloadFonts : 1; /* If PR_TRUE, download fonts to printer */ - PRPackedBool mCancel : 1; /* If PR_TRUE, user cancelled */ - int mOrientation; /* Orientation e.g. Portrait */ - char mCommand[PATH_MAX]; /* Print command e.g., lpr */ - char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */ - char mPrinter[256]; /* Printer name */ - char mPaperName[256]; /* Printer name */ - char mPlexName[256]; /* Plex mode name */ - char mResolutionName[256];/* Resolution name */ - char mColorspace[256]; /* Colorspace */ - int mCopies; /* number of copies */ - float mLeft; /* left margin */ - float mRight; /* right margin */ - float mTop; /* top margin */ - float mBottom; /* bottom margin */ -}; - -//------------------------------------------------------------------------- -// Printer Enumerator -//------------------------------------------------------------------------- -class nsPrinterEnumeratorXlib : public nsIPrinterEnumerator -{ -public: - nsPrinterEnumeratorXlib(); - NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTERENUMERATOR -}; - -#endif /* !nsDeviceContextSpecXlib_h___ */ diff --git a/mozilla/gfx/src/xlib/nsDeviceContextX.h b/mozilla/gfx/src/xlib/nsDeviceContextX.h deleted file mode 100644 index 1d447571be1..00000000000 --- a/mozilla/gfx/src/xlib/nsDeviceContextX.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDeviceContextX_h__ -#define nsDeviceContextX_h__ - -#include "nsDeviceContext.h" -#include "xlibrgb.h" - -class nsFontMetricsXlibContext; -class nsRenderingContextXlibContext; - -/* common baseclass for |nsDeviceContextXlib| and |nsDeviceContextXp| */ -class nsDeviceContextX : public DeviceContextImpl -{ -public: - nsDeviceContextX() - : DeviceContextImpl() - { - } - - virtual ~nsDeviceContextX() {} - - - NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) = 0; - - virtual void GetFontMetricsContext(nsFontMetricsXlibContext *&aContext) = 0; - virtual void GetRCContext(nsRenderingContextXlibContext *&aContext) = 0; -}; - -#endif /* !nsDeviceContextX_h__ */ diff --git a/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp b/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp deleted file mode 100644 index 09776739980..00000000000 --- a/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp +++ /dev/null @@ -1,528 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * Peter Hartshorn - * Ken Faulkner - * Tony Tsui - * Tim Copperfield - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsRenderingContextXlib.h" -#include "nsDrawingSurfaceXlib.h" -#include "nsDeviceContextXlib.h" -#include "nsIPref.h" -#include "nsIServiceManager.h" -#include "nsGfxCIID.h" -#include "nspr.h" - -#include "nsFontMetricsXlib.h" - -#include "xlibrgb.h" -#include - -#include "nsDeviceContextSpecXlib.h" - -#ifdef USE_POSTSCRIPT -#include "nsGfxPSCID.h" -#include "nsIDeviceContextPS.h" -#endif /* USE_POSTSCRIPT */ -#ifdef USE_XPRINT -#include "nsGfxXPrintCID.h" -#include "nsIDeviceContextXPrint.h" -#endif /* USE_XPRINT */ - -#define XLIB_DEFAULT_FONT1 "-*-helvetica-medium-r-*--*-120-*-*-*-*-iso8859-1" -#define XLIB_DEFAULT_FONT2 "-*-fixed-medium-r-*-*-*-120-*-*-*-*-*-*" - -#ifdef PR_LOGGING -static PRLogModuleInfo *DeviceContextXlibLM = PR_NewLogModule("DeviceContextXlib"); -#endif /* PR_LOGGING */ - -/* global default font handle */ -static XFontStruct *mDefaultFont = nsnull; - -nsDeviceContextXlib::nsDeviceContextXlib() - : nsDeviceContextX() -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::nsDeviceContextXlib()\n")); - mTwipsToPixels = 1.0; - mPixelsToTwips = 1.0; - mNumCells = 0; - mSurface = nsnull; - mDisplay = nsnull; - mScreen = nsnull; - mVisual = nsnull; - mDepth = 0; - - mWidthFloat = 0.0f; - mHeightFloat = 0.0f; - mWidth = -1; - mHeight = -1; - mXlibRgbHandle = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE); - if (!mXlibRgbHandle) - abort(); - - mContextCounter++; -} - -nsDeviceContextXlib::~nsDeviceContextXlib() -{ - nsIDrawingSurfaceXlib *surf = NS_STATIC_CAST(nsIDrawingSurfaceXlib *, mSurface); - NS_IF_RELEASE(surf); - mSurface = nsnull; - - mContextCounter--; - - if (mContextCounter == 0) - { - DeleteRenderingContextXlibContext(mRCContext); - DeleteFontMetricsXlibContext(mFontMetricsContext); - mRCContext = nsnull; - mFontMetricsContext = nsnull; - } -} - -nsFontMetricsXlibContext *nsDeviceContextXlib::mFontMetricsContext = nsnull; -nsRenderingContextXlibContext *nsDeviceContextXlib::mRCContext = nsnull; -int nsDeviceContextXlib::mContextCounter = 0; - -NS_IMETHODIMP nsDeviceContextXlib::Init(nsNativeWidget aNativeWidget) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::Init()\n")); - - mWidget = aNativeWidget; - - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - mScreen = xxlib_rgb_get_screen(mXlibRgbHandle); - mVisual = xxlib_rgb_get_visual(mXlibRgbHandle); - mDepth = xxlib_rgb_get_depth(mXlibRgbHandle); - - if (!mDefaultFont) - mDefaultFont = XLoadQueryFont(mDisplay, XLIB_DEFAULT_FONT1); - - if (!mDefaultFont) - mDefaultFont = XLoadQueryFont(mDisplay, XLIB_DEFAULT_FONT2); - -#ifdef DEBUG - static PRBool once = PR_TRUE; - - if (once) - { - once = PR_FALSE; - - printf("nsDeviceContextXlib::Init(dpy=%p screen=%p visual=%p depth=%d)\n", - mDisplay, - mScreen, - mVisual, - mDepth); - } -#endif /* DEBUG */ - - return CommonInit(); -} - -nsresult -nsDeviceContextXlib::CommonInit(void) -{ - nsresult rv = NS_OK;; - - // FIXME: PeterH - // This was set to 100 dpi, then later on in the function is was changed - // to a default of 96dpi IF we had a preference component. We need to - // find a way to get the actual server dpi for a comparison ala GTK. - static nscoord dpi = 96; - static int initialized = 0; - - if (!initialized) { - initialized = 1; - nsresult res; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &res)); - if (NS_SUCCEEDED(res) && prefs) { - PRInt32 intVal = 96; - res = prefs->GetIntPref("layout.css.dpi", &intVal); - if (NS_SUCCEEDED(res)) { - if (intVal) { - dpi = intVal; - } - else { - // Compute dpi of display - float screenWidth = float(XWidthOfScreen(mScreen)); - float screenWidthIn = float(XWidthMMOfScreen(mScreen)) / 25.4f; - dpi = nscoord(screenWidth / screenWidthIn); - } - } - } - } - - // Do extra rounding (based on GTK). KenF - mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(72)) / float(dpi))); - mTwipsToPixels = 1.0f / mPixelsToTwips; - - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("GFX: dpi=%d t2p=%g p2t=%g\n", dpi, mTwipsToPixels, mPixelsToTwips)); - - mWidthFloat = (float) XWidthOfScreen(mScreen); - mHeightFloat = (float) XHeightOfScreen(mScreen); - - DeviceContextImpl::CommonInit(); - - if (!mFontMetricsContext) - { - rv = CreateFontMetricsXlibContext(this, PR_FALSE, &mFontMetricsContext); - if (NS_FAILED(rv)) - return rv; - } - - if (!mRCContext) - { - rv = CreateRenderingContextXlibContext(this, &mRCContext); - if (NS_FAILED(rv)) - return rv; - } - - return rv; -} - -NS_IMETHODIMP nsDeviceContextXlib::CreateRenderingContext(nsIRenderingContext *&aContext) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::CreateRenderingContext()\n")); - -#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 /* NS_PRINT_PREVIEW */ - - nsIRenderingContext *context; - nsDrawingSurfaceXlibImpl *surface = nsnull; - nsresult rv; - - context = new nsRenderingContextXlib(); - - if (nsnull != context) { - NS_ADDREF(context); - surface = new nsDrawingSurfaceXlibImpl(); - if (nsnull != surface) { - xGC *gc = new xGC(mDisplay, (Drawable)mWidget, 0, nsnull); - rv = surface->Init(mXlibRgbHandle, - (Drawable)mWidget, - gc); - - if (NS_SUCCEEDED(rv)) { - rv = context->Init(this, surface); - } - } - else { - rv = NS_ERROR_OUT_OF_MEMORY; - } - } - else { - rv = NS_ERROR_OUT_OF_MEMORY; - } - - if (NS_FAILED(rv)) { - NS_IF_RELEASE(context); - } - aContext = context; - - return rv; -} - -NS_IMETHODIMP nsDeviceContextXlib::CreateRenderingContextInstance(nsIRenderingContext *&aContext) -{ - nsCOMPtr renderingContext = new nsRenderingContextXlib(); - if (!renderingContext) - return NS_ERROR_OUT_OF_MEMORY; - - aContext = renderingContext; - NS_ADDREF(aContext); - - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::SupportsNativeWidgets(PRBool &aSupportsWidgets) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::SupportsNativeWidgets()\n")); - aSupportsWidgets = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::GetSystemFont(nsSystemFontID anID, nsFont *aFont) const -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::GetSystemFont()\n")); - - switch (anID) { - case eSystemFont_Caption: // css2 - case eSystemFont_Icon: - case eSystemFont_Menu: - case eSystemFont_MessageBox: - case eSystemFont_SmallCaption: - case eSystemFont_StatusBar: - case eSystemFont_Window: // css3 - case eSystemFont_Document: - case eSystemFont_Workspace: - case eSystemFont_Desktop: - case eSystemFont_Info: - case eSystemFont_Dialog: - case eSystemFont_Button: - case eSystemFont_PullDownMenu: - case eSystemFont_List: - case eSystemFont_Field: - case eSystemFont_Tooltips: // moz - case eSystemFont_Widget: - aFont->style = NS_FONT_STYLE_NORMAL; - aFont->weight = NS_FONT_WEIGHT_NORMAL; - aFont->decorations = NS_FONT_DECORATION_NONE; - - if (!mDefaultFont) - return NS_ERROR_FAILURE; - else - { - char *fontName = nsnull; - unsigned long pr = 0; - - ::XGetFontProperty(mDefaultFont, XA_FULL_NAME, &pr); - if(pr) - { - fontName = XGetAtomName(mDisplay, pr); - aFont->name.AssignWithConversion(fontName); - ::XFree(fontName); - } - - pr = 0; - ::XGetFontProperty(mDefaultFont, XA_WEIGHT, &pr); - if ( pr > 10 ) - aFont->weight = NS_FONT_WEIGHT_BOLD; - - pr = 0; - Atom pixelSizeAtom = ::XInternAtom(mDisplay, "PIXEL_SIZE", 0); - ::XGetFontProperty(mDefaultFont, pixelSizeAtom, &pr); - if( pr ) - aFont->size = NSIntPixelsToTwips(pr, mPixelsToTwips); - - pr = 0; - ::XGetFontProperty(mDefaultFont, XA_ITALIC_ANGLE, &pr ); - if( pr ) - aFont->style = NS_FONT_STYLE_ITALIC; - - pr = 0; - ::XGetFontProperty(mDefaultFont, XA_UNDERLINE_THICKNESS, &pr); - if( pr ) - aFont->decorations = NS_FONT_DECORATION_UNDERLINE; - } - break; - } - - aFont->systemFont = PR_TRUE; - - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::CheckFontExistence(const nsString& aFontName) -{ - return nsFontMetricsXlib::FamilyExists(mFontMetricsContext, aFontName); -} - -NS_IMETHODIMP nsDeviceContextXlib::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) -{ -#ifdef NS_PRINT_PREVIEW - /* Defer to Alt when there is one */ - if (mAltDC && (mUseAltDC & kUseAltDCFor_SURFACE_DIM)) { - return mAltDC->GetDeviceSurfaceDimensions(aWidth, aHeight); - } -#endif /* NS_PRINT_PREVIEW */ - - if (mWidth == -1) - mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits); - - if (mHeight == -1) - mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits); - - aWidth = mWidth; - aHeight = mHeight; - - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::GetRect(nsRect &aRect) -{ - PRInt32 width, height; - nsresult rv; - rv = GetDeviceSurfaceDimensions(width, height); - aRect.x = 0; - aRect.y = 0; - aRect.width = width; - aRect.height = height; - return rv; -} - -NS_IMETHODIMP nsDeviceContextXlib::GetClientRect(nsRect &aRect) -{ - PRInt32 width, height; - nsresult rv; - rv = GetDeviceSurfaceDimensions(width, height); - aRect.x = 0; - aRect.y = 0; - aRect.width = width; - aRect.height = height; - return rv; -} - -NS_IMETHODIMP nsDeviceContextXlib::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, - nsIDeviceContext *&aContext) -{ - nsresult rv; - PrintMethod method; - nsDeviceContextSpecXlib *spec = NS_STATIC_CAST(nsDeviceContextSpecXlib *, 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 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 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; -} - -NS_IMETHODIMP nsDeviceContextXlib::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::BeginDocument()\n")); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::EndDocument(void) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndDocument()\n")); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::AbortDocument(void) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndDocument()\n")); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::BeginPage(void) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::BeginPage()\n")); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextXlib::EndPage(void) -{ - PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndPage()\n")); - return NS_OK; -} - -class nsFontCacheXlib : public nsFontCache -{ -public: - /* override DeviceContextImpl::CreateFontCache() */ - virtual nsresult CreateFontMetricsInstance(nsIFontMetrics** aResult); -}; - - -nsresult nsFontCacheXlib::CreateFontMetricsInstance(nsIFontMetrics** aResult) -{ - NS_PRECONDITION(aResult, "null out param"); - nsIFontMetrics *fm = new nsFontMetricsXlib(); - if (!fm) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(fm); - *aResult = fm; - return NS_OK; -} - -/* override DeviceContextImpl::CreateFontCache() */ -NS_IMETHODIMP nsDeviceContextXlib::CreateFontCache() -{ - mFontCache = new nsFontCacheXlib(); - if (nsnull == mFontCache) { - return NS_ERROR_OUT_OF_MEMORY; - } - return mFontCache->Init(this); -} - - diff --git a/mozilla/gfx/src/xlib/nsDeviceContextXlib.h b/mozilla/gfx/src/xlib/nsDeviceContextXlib.h deleted file mode 100644 index 42ae141ae00..00000000000 --- a/mozilla/gfx/src/xlib/nsDeviceContextXlib.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * David Smith - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDeviceContextXlib_h__ -#define nsDeviceContextXlib_h__ - -#include "nsDeviceContextX.h" -#include "nsRenderingContextXlib.h" - -class nsDeviceContextXlib : public nsDeviceContextX -{ -public: - nsDeviceContextXlib(); - - NS_IMETHOD Init(nsNativeWidget aNativeWidget); - - NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext); - NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) - {return (DeviceContextImpl::CreateRenderingContext(aView, aContext)); } - NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) - {return (DeviceContextImpl::CreateRenderingContext(aWidget, aContext)); } - NS_IMETHOD CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext) - {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));} - NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext); - - NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets); - - NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const; - - NS_IMETHOD CheckFontExistence(const nsString& aFontName); - - NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight); - NS_IMETHOD GetRect(nsRect &aRect); - NS_IMETHOD GetClientRect(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 CreateFontCache(); - - NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) - { aHandle = mXlibRgbHandle; return NS_OK; } - XlibRgbHandle *GetXlibRgbHandle() { return mXlibRgbHandle; } - NS_IMETHOD GetDepth( PRUint32 &depth ) { depth = (PRUint32)mDepth; return NS_OK; } - virtual void GetFontMetricsContext(nsFontMetricsXlibContext *&aContext) { aContext = mFontMetricsContext; }; - virtual void GetRCContext(nsRenderingContextXlibContext *&aContext) { aContext = mRCContext; }; - -protected: - virtual ~nsDeviceContextXlib(); - -private: - nsresult CommonInit(void); - PRBool mWriteable; - PRUint32 mNumCells; - nsIDrawingSurface* mSurface; - XlibRgbHandle *mXlibRgbHandle; - Display * mDisplay; - Screen * mScreen; - Visual * mVisual; - int mDepth; - static nsFontMetricsXlibContext *mFontMetricsContext; - static nsRenderingContextXlibContext *mRCContext; - static int mContextCounter; - - float mWidthFloat; - float mHeightFloat; - PRInt32 mWidth; - PRInt32 mHeight; -}; - -#endif /* !nsDeviceContextXlib_h__ */ - diff --git a/mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.cpp b/mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.cpp deleted file mode 100644 index 59ae60fb4e7..00000000000 --- a/mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * David Smith - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDrawingSurfaceXlib.h" -#include "prlog.h" -#include "nsGCCache.h" - -#include "xlibrgb.h" // for xxlib_rgb_get_visual_info - -#ifdef PR_LOGGING -static PRLogModuleInfo *DrawingSurfaceXlibLM = PR_NewLogModule("DrawingSurfaceXlib"); -#endif /* PR_LOGGING */ - -nsDrawingSurfaceXlibImpl::nsDrawingSurfaceXlibImpl() : - nsIDrawingSurfaceXlib(), - mXlibRgbHandle(nsnull), - mDisplay(nsnull), - mScreen(nsnull), - mVisual(nsnull), - mDepth(0), - mGC(nsnull), - mDrawable(None), - mImage(nsnull), - // set up lock info - mLockX(0), - mLockY(0), - mLockWidth(0), - mLockHeight(0), - mLockFlags(0), - mLocked(PR_FALSE), - // dimensions... - mWidth(0), - mHeight(0), - mIsOffscreen(PR_FALSE) -{ - PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::nsDrawingSurfaceXlibImpl()\n")); - -} - -nsDrawingSurfaceXlibImpl::~nsDrawingSurfaceXlibImpl() -{ - PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::~nsDrawingSurfaceXlibImpl()\n")); - // if it's been labeled as destroy, it's a pixmap. - if (mDrawable!=None && mIsOffscreen) { - XFreePixmap(mDisplay, mDrawable); - } - if (mImage) { - XDestroyImage(mImage); - } - - // We are freeing the GC here now [See nsWidget::CreateGC()] - if(mGC) { - mGC->Release(); - mGC = nsnull; - } -} - -NS_IMPL_ISUPPORTS1(nsDrawingSurfaceXlibImpl, nsIDrawingSurfaceXlib) - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::Init(XlibRgbHandle *aXlibRgbHandle, - Drawable aDrawable, - xGC *aGC) -{ - PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::Init()\n")); - - mXlibRgbHandle = aXlibRgbHandle; - mDrawable = aDrawable; - - CommonInit(); - - if (mGC) - mGC->Release(); - mGC = aGC; - mGC->AddRef(); - - mIsOffscreen = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::Init(XlibRgbHandle *aXlibRgbHandle, - xGC * aGC, - PRUint32 aWidth, - PRUint32 aHeight, - PRUint32 aFlags) -{ - mXlibRgbHandle = aXlibRgbHandle; - mWidth = aWidth; - mHeight = aHeight; - mLockFlags = aFlags; - - CommonInit(); - - if (mGC) - mGC->Release(); - mGC = aGC; - mGC->AddRef(); - - mIsOffscreen = PR_TRUE; - - mDrawable = XCreatePixmap(mDisplay, - XRootWindow(mDisplay, XScreenNumberOfScreen(mScreen)), - mWidth, - mHeight, - mDepth); - - return (mDrawable!=None)?(NS_OK):(NS_ERROR_FAILURE); -} - -void -nsDrawingSurfaceXlibImpl::CommonInit() -{ - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - mScreen = xxlib_rgb_get_screen(mXlibRgbHandle); - mVisual = xxlib_rgb_get_visual(mXlibRgbHandle); - mDepth = xxlib_rgb_get_depth(mXlibRgbHandle); - - XVisualInfo *x_visual_info = xxlib_rgb_get_visual_info(mXlibRgbHandle); - NS_ASSERTION(nsnull != x_visual_info, "Visual info from xlibrgb is null."); - - if (x_visual_info) - { - mPixFormat.mRedMask = x_visual_info->red_mask; - mPixFormat.mGreenMask = x_visual_info->green_mask;; - mPixFormat.mBlueMask = x_visual_info->blue_mask;; - mPixFormat.mAlphaMask = 0; - - mPixFormat.mRedCount = ConvertMaskToCount(x_visual_info->red_mask); - mPixFormat.mGreenCount = ConvertMaskToCount(x_visual_info->green_mask); - mPixFormat.mBlueCount = ConvertMaskToCount(x_visual_info->blue_mask);; - mPixFormat.mAlphaCount = 0; - - mPixFormat.mRedShift = GetShiftForMask(x_visual_info->red_mask); - mPixFormat.mGreenShift = GetShiftForMask(x_visual_info->green_mask); - mPixFormat.mBlueShift = GetShiftForMask(x_visual_info->blue_mask); - mPixFormat.mAlphaShift = 0; - } -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::Lock(PRInt32 aX, PRInt32 aY, - PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, - PRInt32 *aWidthBytes, PRUint32 aFlags) -{ - PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::Lock()\n")); - if (mLocked) - { - NS_ASSERTION(0, "nested lock attempt"); - return NS_ERROR_FAILURE; - } - if (aWidth == 0 || aHeight == 0) - { - NS_ASSERTION(0, "Width or Height is 0"); - return NS_ERROR_FAILURE; - } - - mLocked = PR_TRUE; - - mLockX = aX; - mLockY = aY; - mLockWidth = aWidth; - mLockHeight = aHeight; - mLockFlags = aFlags; - - mImage = XGetImage(mDisplay, mDrawable, - mLockX, mLockY, - mLockWidth, mLockHeight, - 0xFFFFFFFF, - ZPixmap); - - if (!mImage) { - mLocked = PR_FALSE; - return NS_ERROR_FAILURE; - } - - *aBits = mImage->data; - - *aWidthBytes = mImage->bytes_per_line; - *aStride = mImage->bytes_per_line; - - return NS_OK; -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::Unlock(void) -{ - PR_LOG(DrawingSurfaceXlibLM, PR_LOG_DEBUG, ("nsDrawingSurfaceXlibImpl::UnLock()\n")); - if (!mLocked) { - NS_ASSERTION(0, "attempting to unlock an DS that isn't locked"); - return NS_ERROR_FAILURE; - } - - // If the lock was not read only, put the bits back on the pixmap - if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) { - XPutImage(mDisplay, mDrawable, *mGC, mImage, - 0, 0, mLockX, mLockY, - mLockWidth, mLockHeight); - } - if (mImage) { - XDestroyImage(mImage); - mImage = nsnull; - } - mLocked = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight) -{ - *aWidth = mWidth; - *aHeight = mHeight; - return NS_OK; -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::IsOffscreen(PRBool *aOffScreen) -{ - *aOffScreen = mIsOffscreen; - return NS_OK; -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::IsPixelAddressable(PRBool *aAddressable) -{ - *aAddressable = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsDrawingSurfaceXlibImpl::GetPixelFormat(nsPixelFormat *aFormat) -{ - *aFormat = mPixFormat; - return NS_OK; -} - -PRUint8 -nsDrawingSurfaceXlibImpl::ConvertMaskToCount(unsigned long val) -{ - PRUint8 retval = 0; - PRUint8 cur_bit = 0; - // walk through the number, incrementing the value if - // the bit in question is set. - while (cur_bit < (sizeof(unsigned long) * 8)) { - if ((val >> cur_bit) & 0x1) { - retval++; - } - cur_bit++; - } - return retval; -} - -PRUint8 -nsDrawingSurfaceXlibImpl::GetShiftForMask(unsigned long val) -{ - PRUint8 cur_bit = 0; - // walk through the number, looking for the first 1 - while (cur_bit < (sizeof(unsigned long) * 8)) { - if ((val >> cur_bit) & 0x1) { - return cur_bit; - } - cur_bit++; - } - return cur_bit; -} diff --git a/mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.h b/mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.h deleted file mode 100644 index 0f1df0cef68..00000000000 --- a/mozilla/gfx/src/xlib/nsDrawingSurfaceXlib.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDrawingSurfaceXlib_h__ -#define nsDrawingSurfaceXlib_h__ - -#include "nsIDrawingSurface.h" -#include "nsGCCache.h" -#include "xlibrgb.h" - -/* common interface for both nsDrawingSurfaceXlibImpl (drawing surface for - * normal displays) and nsXPrintContext (drawing surface for printers) - */ -class nsIDrawingSurfaceXlib : public nsIDrawingSurface -{ -public: - NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, - PRUint32 aFlags) = 0; - NS_IMETHOD Unlock(void) = 0; - NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight) = 0; - NS_IMETHOD IsOffscreen(PRBool *aOffScreen) = 0; - NS_IMETHOD IsPixelAddressable(PRBool *aAddressable) = 0; - NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat) = 0; - - NS_IMETHOD GetDrawable(Drawable &aDrawable) = 0; - NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) = 0; - NS_IMETHOD GetGC(xGC *&aXGC) = 0; - - virtual Drawable GetDrawable() = 0; -}; - - -class nsDrawingSurfaceXlibImpl : public nsIDrawingSurfaceXlib -{ -public: - nsDrawingSurfaceXlibImpl(); - virtual ~nsDrawingSurfaceXlibImpl(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, - PRUint32 aFlags); - NS_IMETHOD Unlock(void); - NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight); - NS_IMETHOD IsOffscreen(PRBool *aOffScreen); - NS_IMETHOD IsPixelAddressable(PRBool *aAddressable); - NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat); - - NS_IMETHOD Init (XlibRgbHandle *aHandle, - Drawable aDrawable, - xGC * aGC); - - NS_IMETHOD Init (XlibRgbHandle *aHandle, - xGC * aGC, - PRUint32 aWidth, - PRUint32 aHeight, - PRUint32 aFlags); - - NS_IMETHOD GetDrawable(Drawable &aDrawable) { aDrawable = mDrawable; return NS_OK; } - NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) { aHandle = mXlibRgbHandle; return NS_OK; } - NS_IMETHOD GetGC(xGC *&aXGC) { mGC->AddRef(); aXGC = mGC; return NS_OK; } - - virtual Drawable GetDrawable() { return mDrawable; } - -private: - void CommonInit(); - - XlibRgbHandle *mXlibRgbHandle; - Display * mDisplay; - Screen * mScreen; - Visual * mVisual; - int mDepth; - xGC *mGC; - Drawable mDrawable; - XImage * mImage; - nsPixelFormat mPixFormat; - - // for locking - PRInt32 mLockX; - PRInt32 mLockY; - PRUint32 mLockWidth; - PRUint32 mLockHeight; - PRUint32 mLockFlags; - PRBool mLocked; - - // dimensions - PRUint32 mWidth; - PRUint32 mHeight; - - // are we offscreen - PRBool mIsOffscreen; - -private: - static PRUint8 ConvertMaskToCount(unsigned long val); - static PRUint8 GetShiftForMask(unsigned long val); -}; - -#endif /* !nsDrawingSurfaceXlib_h__ */ - diff --git a/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp b/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp deleted file mode 100644 index 518b6a442b9..00000000000 --- a/mozilla/gfx/src/xlib/nsFontMetricsXlib.cpp +++ /dev/null @@ -1,6067 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * Peter Hartshorn - * Quy Tonthat - * Tony Tsui - * Tim Copperfield - * Roland Mainz - * Brian Stell - * Jungshik Shin - * IBM Corporation - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#define ENABLE_X_FONT_BANNING 1 - -#include -#include "gfx-config.h" -#include "nscore.h" -#include "nsQuickSort.h" -#include "nsFontMetricsXlib.h" -#include "nsIServiceManager.h" -#include "nsICharsetConverterManager.h" -#include "nsILanguageAtomService.h" -#include "nsISaveAsCharset.h" -#include "nsIPref.h" -#include "nsCOMPtr.h" -#include "nsPrintfCString.h" -#include "nspr.h" -#include "nsHashtable.h" -#include "nsReadableUtils.h" -#include "nsAString.h" -#include "nsXPIDLString.h" -#ifdef MOZ_ENABLE_FREETYPE2 -#include "nsFT2FontCatalog.h" -#include "nsFreeType.h" -#endif /* MOZ_ENABLE_FREETYPE2 */ -#ifdef USE_X11SHARED_CODE -#include "nsXFontNormal.h" -#endif /* USE_X11SHARED_CODE */ -#ifdef USE_AASB -#include "nsX11AlphaBlend.h" -#include "nsXFontAAScaledBitmap.h" -#endif /* USE_AASB */ -#ifdef USE_XPRINT -#include "xprintutil.h" -#endif /* USE_XPRINT */ -#include "xlibrgb.h" -#include "nsUnicharUtils.h" -#ifdef ENABLE_X_FONT_BANNING -#include -#endif /* ENABLE_X_FONT_BANNING */ - -#include - -#define UCS2_NOMAPPING 0XFFFD - -#ifdef PR_LOGGING -static PRLogModuleInfo *FontMetricsXlibLM = PR_NewLogModule("FontMetricsXlib"); -#endif /* PR_LOGGING */ - -#ifdef ENABLE_X_FONT_BANNING -/* Not all platforms may have REG_OK */ -#ifndef REG_OK -#define REG_OK (0) -#endif /* !REG_OK */ -#endif /* ENABLE_X_FONT_BANNING */ - -#undef USER_DEFINED -#define USER_DEFINED "x-user-def" - -// This is the scaling factor that we keep fonts limited to against -// the display size. If a pixel size is requested that is more than -// this factor larger than the height of the display, it's clamped to -// that value instead of the requested size. -#define FONT_MAX_FONT_SCALE 2 - -#undef NOISY_FONTS -#undef REALLY_NOISY_FONTS - -/* Local prototypes */ -static PRBool FreeNode(nsHashKey* aKey, void* aData, void* aClosure); -#ifdef MOZ_ENABLE_FREETYPE2 -static void CharSetNameToCodeRangeBits(const char*, PRUint32*, PRUint32*); -#endif /* MOZ_ENABLE_FREETYPE2 */ -static const nsFontCharSetMapXlib *GetCharSetMap(nsFontMetricsXlibContext *aFmctx, const char *aCharSetName); - -// the font catalog is so expensive to generate -// always tell the user what is happening -static PRUint32 gFontDebug = 0 | NS_FONT_DEBUG_FONT_SCAN; - -struct nsFontCharSetMapXlib; -struct nsFontFamilyNameXlib; -struct nsFontPropertyNameXlib; -struct nsFontStyleXlib; -struct nsFontWeightXlib; -struct nsFontLangGroupXlib; - -/* Container to hold per-device data (not per nsIDeviceContext data - one - * nsFontMetricsXlibContext instance may be used by multiple nsIDeviceContext - * as long they map to the same physical device) for fontmetrics code - */ -class nsFontMetricsXlibContext -{ -public: - nsFontMetricsXlibContext(); - nsresult Init(nsIDeviceContext *aDevice, PRBool printermode); - ~nsFontMetricsXlibContext(); - - XlibRgbHandle *mXlibRgbHandle; -#ifdef USE_XPRINT - /* Does this nsFont(Metrics)Xlib class operate on a Xprt (X11 print server) */ - PRPackedBool mPrinterMode; -#endif /* USE_XPRINT */ - PRPackedBool mAllowDoubleByteSpecialChars; - PRPackedBool mForceOutlineScaledFonts; - - PRPackedBool mScaleBitmapFontsWithDevScale; - float mDevScale; - - nsCOMPtr mPref; - - nsCOMPtr mCharSetManager; - nsCOMPtr mUserDefinedConverter; - - nsHashtable mAliases; - nsHashtable mCharSetMaps; - nsHashtable mFamilies; - nsHashtable mFFRENodes; - nsHashtable mAFRENodes; - - // mCachedFFRESearches holds the "already looked up" - // FFRE (Foundry Family Registry Encoding) font searches - nsHashtable mCachedFFRESearches; - nsHashtable mSpecialCharSets; - nsHashtable mStretches; - nsHashtable mWeights; - nsCOMPtr mFontSubConverter; - - PRBool mGlobalListInitalised; - nsFontNodeArrayXlib mGlobalList; - - nsFontCharSetInfoXlib *mUnknown, - *mSpecial, - *mISO106461; - - nsCOMPtr mUnicode; - nsCOMPtr mUserDefined; - nsCOMPtr mZHTW; - nsCOMPtr mZHHK; - nsCOMPtr mZHTWHK; // common to TW and HK - nsCOMPtr mUsersLocale; - nsCOMPtr mWesternLocale; - - const nsFontCharSetMapXlib *mCharSetMap; - const nsFontCharSetMapXlib *mNoneCharSetMap; - const nsFontCharSetMapXlib *mSpecialCharSetMap; - - PRUint16 *mUserDefinedCCMap; - PRUint16 *mEmptyCCMap; - PRUint16 *mDoubleByteSpecialCharsCCMap; - - // Controls for Outline Scaled Fonts (okay looking) - - PRInt32 mOutlineScaleMinimum; -#ifdef USE_AASB -// Controls for Anti-Aliased Scaled Bitmaps (okay looking) - PRBool mAABitmapScaleEnabled; - PRBool mAABitmapScaleAlways; - PRInt32 mAABitmapScaleMinimum; - double mAABitmapOversize; - double mAABitmapUndersize; -#endif /* USE_AASB */ - -// Controls for (regular) Scaled Bitmaps (very ugly) - PRInt32 mBitmapScaleMinimum; - double mBitmapOversize; - double mBitmapUndersize; - -#ifdef USE_AASB - PRInt32 mAntiAliasMinimum; -#endif /* USE_AASB */ - PRInt32 mEmbeddedBitmapMaximumHeight; - -#ifdef MOZ_ENABLE_FREETYPE2 - PRBool mEnableFreeType2; - PRBool mFreeType2Autohinted; - PRBool mFreeType2Unhinted; -#endif /* MOZ_ENABLE_FREETYPE2 */ -#ifdef USE_AASB - PRUint8 mAATTDarkTextMinValue; - double mAATTDarkTextGain; -#endif /* USE_AASB */ - -#ifdef ENABLE_X_FONT_BANNING - regex_t *mFontRejectRegEx, - *mFontAcceptRegEx; -#endif /* ENABLE_X_FONT_BANNING */ -}; - -struct nsFontCharSetInfoXlib -{ - const char* mCharSet; - nsFontCharSetConverterXlib Convert; - PRUint8 mSpecialUnderline; -#ifdef MOZ_ENABLE_FREETYPE2 - PRInt32 mCodeRange1Bits; - PRInt32 mCodeRange2Bits; -#endif - PRUint16* mCCMap; - nsIUnicodeEncoder* mConverter; - nsIAtom* mLangGroup; - PRBool mInitedSizeInfo; - PRInt32 mOutlineScaleMin; - PRInt32 mBitmapScaleMin; - double mBitmapOversize; - double mBitmapUndersize; -#ifdef USE_AASB - PRInt32 mAABitmapScaleMin; - double mAABitmapOversize; - double mAABitmapUndersize; - PRBool mAABitmapScaleAlways; -#endif /* USE_AASB */ -}; - -struct nsFontFamilyXlib -{ - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - nsFontNodeArrayXlib mNodes; -}; - -struct nsFontFamilyNameXlib -{ - const char* mName; - const char* mXName; -}; - -struct nsFontPropertyNameXlib -{ - const char* mName; - int mValue; -}; - -static void SetCharsetLangGroup(nsFontMetricsXlibContext *aFmctx, nsFontCharSetInfoXlib* aCharSetInfo); - -static int SingleByteConvert(nsFontCharSetInfoXlib* aSelf, XFontStruct* aFont, - const PRUnichar* aSrcBuf, PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen); -static int DoubleByteConvert(nsFontCharSetInfoXlib* aSelf, XFontStruct* aFont, - const PRUnichar* aSrcBuf, PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen); -static int ISO10646Convert(nsFontCharSetInfoXlib* aSelf, XFontStruct* aFont, - const PRUnichar* aSrcBuf, PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen); - -static nsFontCharSetInfoXlib Unknown = { nsnull }; -static nsFontCharSetInfoXlib Special = { nsnull }; - -#ifdef MOZ_ENABLE_FREETYPE2 -static nsFontCharSetInfoXlib USASCII = - { "us-ascii", SingleByteConvert, 0, - TT_OS2_CPR1_LATIN1 | TT_OS2_CPR1_MAC_ROMAN, - TT_OS2_CPR2_CA_FRENCH | TT_OS2_CPR2_PORTUGESE - | TT_OS2_CPR2_WE_LATIN1 | TT_OS2_CPR2_US }; -static nsFontCharSetInfoXlib ISO88591 = - { "ISO-8859-1", SingleByteConvert, 0, - TT_OS2_CPR1_LATIN1 | TT_OS2_CPR1_MAC_ROMAN, - TT_OS2_CPR2_CA_FRENCH | TT_OS2_CPR2_PORTUGESE - | TT_OS2_CPR2_WE_LATIN1 | TT_OS2_CPR2_US }; -static nsFontCharSetInfoXlib ISO88592 = - { "ISO-8859-2", SingleByteConvert, 0, - TT_OS2_CPR1_LATIN2, TT_OS2_CPR2_LATIN2 }; -static nsFontCharSetInfoXlib ISO88593 = - { "ISO-8859-3", SingleByteConvert, 0, - TT_OS2_CPR1_TURKISH, TT_OS2_CPR2_TURKISH }; -static nsFontCharSetInfoXlib ISO88594 = - { "ISO-8859-4", SingleByteConvert, 0, - TT_OS2_CPR1_BALTIC, TT_OS2_CPR2_BALTIC }; -static nsFontCharSetInfoXlib ISO88595 = - { "ISO-8859-5", SingleByteConvert, 0, - TT_OS2_CPR1_CYRILLIC, TT_OS2_CPR2_RUSSIAN | TT_OS2_CPR2_CYRILLIC }; -static nsFontCharSetInfoXlib ISO88596 = - { "ISO-8859-6", SingleByteConvert, 0, - TT_OS2_CPR1_ARABIC, TT_OS2_CPR2_ARABIC | TT_OS2_CPR2_ARABIC_708 }; -static nsFontCharSetInfoXlib ISO885968x = - { "x-iso-8859-6-8-x", SingleByteConvert, 0, - TT_OS2_CPR1_ARABIC, TT_OS2_CPR2_ARABIC | TT_OS2_CPR2_ARABIC_708 }; -static nsFontCharSetInfoXlib ISO8859616 = - { "x-iso-8859-6-16", SingleByteConvert, 0, - TT_OS2_CPR1_ARABIC, TT_OS2_CPR2_ARABIC | TT_OS2_CPR2_ARABIC_708 }; -static nsFontCharSetInfoXlib IBM1046 = - { "x-IBM1046", SingleByteConvert, 0, - TT_OS2_CPR1_ARABIC, TT_OS2_CPR2_ARABIC | TT_OS2_CPR2_ARABIC_708 }; -static nsFontCharSetInfoXlib ISO88597 = - { "ISO-8859-7", SingleByteConvert, 0, - TT_OS2_CPR1_GREEK, TT_OS2_CPR2_GREEK | TT_OS2_CPR2_GREEK_437G }; -static nsFontCharSetInfoXlib ISO88598 = - { "ISO-8859-8", SingleByteConvert, 0, - TT_OS2_CPR1_HEBREW, TT_OS2_CPR2_HEBREW }; -// change from -// { "ISO-8859-8", SingleByteConvertReverse, 0, 0, 0 }; -// untill we fix the layout and ensure we only call this with pure RTL text -static nsFontCharSetInfoXlib ISO88599 = - { "ISO-8859-9", SingleByteConvert, 0, - TT_OS2_CPR1_TURKISH, TT_OS2_CPR2_TURKISH }; -// no support for iso-8859-10 (Nordic/Icelandic) currently -// static nsFontCharSetInfoXlib ISO885910 = -// { "ISO-8859-10", SingleByteConvert, 0, -// 0, TT_OS2_CPR2_NORDIC | TT_OS2_CPR2_ICELANDIC }; -// no support for iso-8859-12 (Vietnamese) currently -// static nsFontCharSetInfoXlib ISO885912 = -// { "ISO-8859-12", SingleByteConvert, 0, -// TT_OS2_CPR1_VIETNAMESE, 0 }; -static nsFontCharSetInfoXlib ISO885913 = - { "ISO-8859-13", SingleByteConvert, 0, - TT_OS2_CPR1_BALTIC, TT_OS2_CPR2_BALTIC }; -static nsFontCharSetInfoXlib ISO885915 = - { "ISO-8859-15", SingleByteConvert, 0, - TT_OS2_CPR1_LATIN2, TT_OS2_CPR2_LATIN2 }; -static nsFontCharSetInfoXlib JISX0201 = - { "jis_0201", SingleByteConvert, 1, - TT_OS2_CPR1_JAPANESE, 0 }; -static nsFontCharSetInfoXlib KOI8R = - { "KOI8-R", SingleByteConvert, 0, - TT_OS2_CPR1_CYRILLIC, TT_OS2_CPR2_RUSSIAN | TT_OS2_CPR2_CYRILLIC }; -static nsFontCharSetInfoXlib KOI8U = - { "KOI8-U", SingleByteConvert, 0, - TT_OS2_CPR1_CYRILLIC, TT_OS2_CPR2_RUSSIAN | TT_OS2_CPR2_CYRILLIC }; -static nsFontCharSetInfoXlib TIS6202 = -/* Added to support thai context sensitive shaping if - * CTL extension is is in force */ -#ifdef SUNCTL - { "tis620-2", SingleByteConvert, 0, - TT_OS2_CPR1_THAI, 0 }; -#else - { "windows-874", SingleByteConvert, 0, - TT_OS2_CPR1_THAI, 0 }; -#endif /* SUNCTL */ -static nsFontCharSetInfoXlib TIS620 = - { "TIS-620", SingleByteConvert, 0, - TT_OS2_CPR1_THAI, 0 }; -static nsFontCharSetInfoXlib ISO885911 = - { "ISO-8859-11", SingleByteConvert, 0, - TT_OS2_CPR1_THAI, 0 }; -static nsFontCharSetInfoXlib Big5 = - { "x-x-big5", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -// a kludge to distinguish zh-TW only fonts in Big5 (such as hpbig5-) -// from zh-TW/zh-HK common fonts in Big5 (such as big5-0, big5-1) -static nsFontCharSetInfoXlib Big5TWHK = - { "x-x-big5", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116431 = - { "x-cns-11643-1", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116432 = - { "x-cns-11643-2", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116433 = - { "x-cns-11643-3", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116434 = - { "x-cns-11643-4", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116435 = - { "x-cns-11643-5", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116436 = - { "x-cns-11643-6", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib CNS116437 = - { "x-cns-11643-7", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib GB2312 = - { "gb_2312-80", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_SIMP, 0 }; -static nsFontCharSetInfoXlib GB18030_0 = - { "gb18030.2000-0", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_SIMP, 0 }; -static nsFontCharSetInfoXlib GB18030_1 = - { "gb18030.2000-1", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_SIMP, 0 }; -static nsFontCharSetInfoXlib GBK = - { "x-gbk-noascii", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_SIMP, 0 }; -static nsFontCharSetInfoXlib HKSCS = - { "hkscs-1", DoubleByteConvert, 1, - TT_OS2_CPR1_CHINESE_TRAD, 0 }; -static nsFontCharSetInfoXlib JISX0208 = - { "jis_0208-1983", DoubleByteConvert, 1, - TT_OS2_CPR1_JAPANESE, 0 }; -static nsFontCharSetInfoXlib JISX0212 = - { "jis_0212-1990", DoubleByteConvert, 1, - TT_OS2_CPR1_JAPANESE, 0 }; -static nsFontCharSetInfoXlib KSC5601 = - { "ks_c_5601-1987", DoubleByteConvert, 1, - TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, 0 }; -static nsFontCharSetInfoXlib X11Johab = - { "x-x11johab", DoubleByteConvert, 1, - TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, 0 }; -static nsFontCharSetInfoXlib JohabNoAscii = - { "x-johab-noascii", DoubleByteConvert, 1, - TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, 0 }; -static nsFontCharSetInfoXlib JamoTTF = - { "x-koreanjamo-0", DoubleByteConvert, 1, - TT_OS2_CPR1_KO_WANSUNG | TT_OS2_CPR1_KO_JOHAB, 0 }; -static nsFontCharSetInfoXlib TamilTTF = - { "x-tamilttf-0", DoubleByteConvert, 1, - 0, 0 }; -static nsFontCharSetInfoXlib CP1250 = - { "windows-1250", SingleByteConvert, 0, - TT_OS2_CPR1_LATIN2, TT_OS2_CPR2_LATIN2 }; -static nsFontCharSetInfoXlib CP1251 = - { "windows-1251", SingleByteConvert, 0, - TT_OS2_CPR1_CYRILLIC, TT_OS2_CPR2_RUSSIAN }; -static nsFontCharSetInfoXlib CP1252 = - { "windows-1252", SingleByteConvert, 0, - TT_OS2_CPR1_LATIN1 | TT_OS2_CPR1_MAC_ROMAN, - TT_OS2_CPR2_CA_FRENCH | TT_OS2_CPR2_PORTUGESE - | TT_OS2_CPR2_WE_LATIN1 | TT_OS2_CPR2_US }; -static nsFontCharSetInfoXlib CP1253 = - { "windows-1253", SingleByteConvert, 0, - TT_OS2_CPR1_GREEK, TT_OS2_CPR2_GREEK | TT_OS2_CPR2_GREEK_437G }; -static nsFontCharSetInfoXlib CP1257 = - { "windows-1257", SingleByteConvert, 0, - TT_OS2_CPR1_BALTIC, TT_OS2_CPR2_BALTIC }; - -#ifdef SUNCTL -/* Hindi range currently unsupported in FT2 range. Change TT* once we - arrive at a way to identify hindi */ -static nsFontCharSetInfoXlib SunIndic = - { "x-sun-unicode-india-0", DoubleByteConvert, 0, - 0, 0 }; -#endif /* SUNCTL */ - -static nsFontCharSetInfoXlib ISO106461 = - { nsnull, ISO10646Convert, 1, 0xFFFFFFFF, 0xFFFFFFFF }; - -static nsFontCharSetInfoXlib AdobeSymbol = - { "Adobe-Symbol-Encoding", SingleByteConvert, 0, - TT_OS2_CPR1_SYMBOL, 0 }; -static nsFontCharSetInfoXlib AdobeEuro = - { "x-adobe-euro", SingleByteConvert, 0, - 0, 0 }; - -#ifdef MOZ_MATHML -static nsFontCharSetInfoXlib CMCMEX = - { "x-t1-cmex", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib CMCMSY = - { "x-t1-cmsy", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib CMCMR = - { "x-t1-cmr", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib CMCMMI = - { "x-t1-cmmi", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib Mathematica1 = - { "x-mathematica1", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib Mathematica2 = - { "x-mathematica2", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib Mathematica3 = - { "x-mathematica3", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib Mathematica4 = - { "x-mathematica4", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -static nsFontCharSetInfoXlib Mathematica5 = - { "x-mathematica5", SingleByteConvert, 0, TT_OS2_CPR1_SYMBOL, 0}; -#endif /* MATHML */ - -#else - -static nsFontCharSetInfoXlib USASCII = - { "us-ascii", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88591 = - { "ISO-8859-1", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88592 = - { "ISO-8859-2", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88593 = - { "ISO-8859-3", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88594 = - { "ISO-8859-4", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88595 = - { "ISO-8859-5", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88596 = - { "ISO-8859-6", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO885968x = - { "x-iso-8859-6-8-x", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO8859616 = - { "x-iso-8859-6-16", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib IBM1046 = - { "x-IBM1046", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88597 = - { "ISO-8859-7", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO88598 = - { "ISO-8859-8", SingleByteConvert, 0 }; -// change from -// { "ISO-8859-8", SingleByteConvertReverse, 0, 0, 0 }; -// untill we fix the layout and ensure we only call this with pure RTL text -static nsFontCharSetInfoXlib ISO88599 = - { "ISO-8859-9", SingleByteConvert, 0 }; -// no support for iso-8859-10 (Nordic/Icelandic) currently -// static nsFontCharSetInfoXlib ISO885910 = -// { "ISO-8859-10", SingleByteConvert, 0, -// 0, TT_OS2_CPR2_NORDIC | TT_OS2_CPR2_ICELANDIC }; -// no support for iso-8859-12 (Vietnamese) currently -// static nsFontCharSetInfoXlib ISO885912 = -// { "ISO-8859-12", SingleByteConvert, 0, -// TT_OS2_CPR1_VIETNAMESE, 0 }; -static nsFontCharSetInfoXlib ISO885913 = - { "ISO-8859-13", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO885915 = - { "ISO-8859-15", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib JISX0201 = - { "jis_0201", SingleByteConvert, 1 }; -static nsFontCharSetInfoXlib KOI8R = - { "KOI8-R", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib KOI8U = - { "KOI8-U", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib TIS6202 = -/* Added to support thai context sensitive shaping if - * CTL extension is is in force */ -#ifdef SUNCTL - { "tis620-2", SingleByteConvert, 0 }; -#else - { "windows-874", SingleByteConvert, 0 }; -#endif /* SUNCTL */ -static nsFontCharSetInfoXlib TIS620 = - { "TIS-620", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib ISO885911 = - { "ISO-8859-11", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib Big5 = - { "x-x-big5", DoubleByteConvert, 1 }; -// a kludge to distinguish zh-TW only fonts in Big5 (such as hpbig5-) -// from zh-TW/zh-HK common fonts in Big5 (such as big5-1) -static nsFontCharSetInfoXlib Big5TWHK = - { "x-x-big5", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116431 = - { "x-cns-11643-1", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116432 = - { "x-cns-11643-2", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116433 = - { "x-cns-11643-3", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116434 = - { "x-cns-11643-4", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116435 = - { "x-cns-11643-5", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116436 = - { "x-cns-11643-6", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib CNS116437 = - { "x-cns-11643-7", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib GB2312 = - { "gb_2312-80", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib GB18030_0 = - { "gb18030.2000-0", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib GB18030_1 = - { "gb18030.2000-1", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib GBK = - { "x-gbk-noascii", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib HKSCS = - { "hkscs-1", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib JISX0208 = - { "jis_0208-1983", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib JISX0212 = - { "jis_0212-1990", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib KSC5601 = - { "ks_c_5601-1987", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib X11Johab = - { "x-x11johab", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib JohabNoAscii = - { "x-johab-noascii", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib JamoTTF = - { "x-koreanjamo-0", DoubleByteConvert, 1 }; -static nsFontCharSetInfoXlib TamilTTF = - { "x-tamilttf-0", DoubleByteConvert, 0 }; -static nsFontCharSetInfoXlib CP1250 = - { "windows-1250", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib CP1251 = - { "windows-1251", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib CP1252 = - { "windows-1252", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib CP1253 = - { "windows-1253", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib CP1257 = - { "windows-1257", SingleByteConvert, 0 }; - -#ifdef SUNCTL -/* Hindi range currently unsupported in FT2 range. Change TT* once we - arrive at a way to identify hindi */ -static nsFontCharSetInfoXlib SunIndic = - { "x-sun-unicode-india-0", DoubleByteConvert, 0 }; -#endif /* SUNCTL */ - -static nsFontCharSetInfoXlib ISO106461 = - { nsnull, ISO10646Convert, 1}; - -static nsFontCharSetInfoXlib AdobeSymbol = - { "Adobe-Symbol-Encoding", SingleByteConvert, 0 }; -static nsFontCharSetInfoXlib AdobeEuro = - { "x-adobe-euro", SingleByteConvert, 0 }; - -#ifdef MOZ_MATHML -static nsFontCharSetInfoXlib CMCMEX = - { "x-t1-cmex", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib CMCMSY = - { "x-t1-cmsy", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib CMCMR = - { "x-t1-cmr", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib CMCMMI = - { "x-t1-cmmi", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib Mathematica1 = - { "x-mathematica1", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib Mathematica2 = - { "x-mathematica2", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib Mathematica3 = - { "x-mathematica3", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib Mathematica4 = - { "x-mathematica4", SingleByteConvert, 0}; -static nsFontCharSetInfoXlib Mathematica5 = - { "x-mathematica5", SingleByteConvert, 0}; -#endif /* MATHML */ -#endif /* FREETYPE2 */ - -static nsFontLangGroupXlib FLG_WESTERN = { "x-western", nsnull }; -static nsFontLangGroupXlib FLG_BALTIC = { "x-baltic", nsnull }; -static nsFontLangGroupXlib FLG_CE = { "x-central-euro",nsnull }; -static nsFontLangGroupXlib FLG_RUSSIAN = { "x-cyrillic", nsnull }; -static nsFontLangGroupXlib FLG_GREEK = { "el", nsnull }; -static nsFontLangGroupXlib FLG_TURKISH = { "tr", nsnull }; -static nsFontLangGroupXlib FLG_HEBREW = { "he", nsnull }; -static nsFontLangGroupXlib FLG_ARABIC = { "ar", nsnull }; -static nsFontLangGroupXlib FLG_THAI = { "th", nsnull }; -static nsFontLangGroupXlib FLG_ZHCN = { "zh-CN", nsnull }; -static nsFontLangGroupXlib FLG_ZHTW = { "zh-TW", nsnull }; -static nsFontLangGroupXlib FLG_ZHHK = { "zh-HK", nsnull }; -static nsFontLangGroupXlib FLG_ZHTWHK = { "x-zh-TWHK", nsnull }; -static nsFontLangGroupXlib FLG_JA = { "ja", nsnull }; -static nsFontLangGroupXlib FLG_KO = { "ko", nsnull }; -#ifdef SUNCTL -static nsFontLangGroupXlib FLG_INDIC = { "x-devanagari", nsnull }; -#endif -static nsFontLangGroupXlib FLG_TAMIL = { "x-tamil", nsnull }; -static nsFontLangGroupXlib FLG_NONE = { nsnull, nsnull }; - -/* - * Normally, the charset of an X font can be determined simply by looking at - * the last 2 fields of the long XLFD font name (CHARSET_REGISTRY and - * CHARSET_ENCODING). However, there are a number of special cases: - * - * Sometimes, X server vendors use the same name to mean different things. For - * example, IRIX uses "cns11643-1" to mean the 2nd plane of CNS 11643, while - * Solaris uses that name for the 1st plane. - * - * Some X server vendors use certain names for something completely different. - * For example, some Solaris fonts say "gb2312.1980-0" but are actually ASCII - * fonts. These cases can be detected by looking at the POINT_SIZE and - * AVERAGE_WIDTH fields. If the average width is half the point size, this is - * an ASCII font, not GB 2312. - * - * Some fonts say "fontspecific" in the CHARSET_ENCODING field. Their charsets - * depend on the FAMILY_NAME. For example, the following is a "Symbol" font: - * - * -adobe-symbol-medium-r-normal--17-120-100-100-p-95-adobe-fontspecific - * - * Some vendors use one name to mean 2 different things, depending on the font. - * For example, AIX has some "ksc5601.1987-0" fonts that require the 8th bit of - * both bytes to be zero, while other fonts require them to be set to one. - * These cases can be distinguished by looking at the FOUNDRY field, but a - * better way is to look at XFontStruct.min_byte1. - */ -static const nsFontCharSetMapXlib gConstCharSetMap[] = -{ - { "-ascii", &FLG_NONE, &Unknown }, - { "-ibm pc", &FLG_NONE, &Unknown }, - { "adobe-fontspecific", &FLG_NONE, &Special }, - { "ansi-1251", &FLG_RUSSIAN, &CP1251 }, - // On Solaris, big5-0 is used for ASCII-only fonts while in XFree86, - // it's for Big5 fonts without US-ASCII. When a non-Solaris binary - // is displayed on a Solaris X server, this would break. -#ifndef SOLARIS - { "big5-0", &FLG_ZHTWHK, &Big5TWHK }, // common to TW/HK -#else - { "big5-0", &FLG_ZHTW, &USASCII }, -#endif - { "big5-1", &FLG_ZHTWHK, &Big5TWHK }, // ditto - { "big5.et-0", &FLG_ZHTW, &Big5 }, - { "big5.et.ext-0", &FLG_ZHTW, &Big5 }, - { "big5.etext-0", &FLG_ZHTW, &Big5 }, - { "big5.hku-0", &FLG_ZHTW, &Big5 }, - { "big5.hku-1", &FLG_ZHTW, &Big5 }, - { "big5.pc-0", &FLG_ZHTW, &Big5 }, - { "big5.shift-0", &FLG_ZHTW, &Big5 }, - { "big5hkscs-0", &FLG_ZHHK, &HKSCS }, - { "cns11643.1986-1", &FLG_ZHTW, &CNS116431 }, - { "cns11643.1986-2", &FLG_ZHTW, &CNS116432 }, - { "cns11643.1992-1", &FLG_ZHTW, &CNS116431 }, - { "cns11643.1992.1-0", &FLG_ZHTW, &CNS116431 }, - { "cns11643.1992-12", &FLG_NONE, &Unknown }, - { "cns11643.1992.2-0", &FLG_ZHTW, &CNS116432 }, - { "cns11643.1992-2", &FLG_ZHTW, &CNS116432 }, - { "cns11643.1992-3", &FLG_ZHTW, &CNS116433 }, - { "cns11643.1992.3-0", &FLG_ZHTW, &CNS116433 }, - { "cns11643.1992.4-0", &FLG_ZHTW, &CNS116434 }, - { "cns11643.1992-4", &FLG_ZHTW, &CNS116434 }, - { "cns11643.1992.5-0", &FLG_ZHTW, &CNS116435 }, - { "cns11643.1992-5", &FLG_ZHTW, &CNS116435 }, - { "cns11643.1992.6-0", &FLG_ZHTW, &CNS116436 }, - { "cns11643.1992-6", &FLG_ZHTW, &CNS116436 }, - { "cns11643.1992.7-0", &FLG_ZHTW, &CNS116437 }, - { "cns11643.1992-7", &FLG_ZHTW, &CNS116437 }, - { "cns11643-1", &FLG_ZHTW, &CNS116431 }, - { "cns11643-2", &FLG_ZHTW, &CNS116432 }, - { "cns11643-3", &FLG_ZHTW, &CNS116433 }, - { "cns11643-4", &FLG_ZHTW, &CNS116434 }, - { "cns11643-5", &FLG_ZHTW, &CNS116435 }, - { "cns11643-6", &FLG_ZHTW, &CNS116436 }, - { "cns11643-7", &FLG_ZHTW, &CNS116437 }, - { "cp1251-1", &FLG_RUSSIAN, &CP1251 }, - { "dec-dectech", &FLG_NONE, &Unknown }, - { "dtsymbol-1", &FLG_NONE, &Unknown }, - { "fontspecific-0", &FLG_NONE, &Unknown }, - { "gb2312.1980-0", &FLG_ZHCN, &GB2312 }, - { "gb2312.1980-1", &FLG_ZHCN, &GB2312 }, - { "gb13000.1993-1", &FLG_ZHCN, &GBK }, - { "gb18030.2000-0", &FLG_ZHCN, &GB18030_0 }, - { "gb18030.2000-1", &FLG_ZHCN, &GB18030_1 }, - { "gbk-0", &FLG_ZHCN, &GBK }, - { "gbk1988.1989-0", &FLG_ZHCN, &USASCII }, - { "hkscs-1", &FLG_ZHHK, &HKSCS }, - { "hp-japanese15", &FLG_NONE, &Unknown }, - { "hp-japaneseeuc", &FLG_NONE, &Unknown }, - { "hp-roman8", &FLG_NONE, &Unknown }, - { "hp-schinese15", &FLG_NONE, &Unknown }, - { "hp-tchinese15", &FLG_NONE, &Unknown }, - { "hp-tchinesebig5", &FLG_ZHTW, &Big5 }, - { "hp-wa", &FLG_NONE, &Unknown }, - { "hpbig5-", &FLG_ZHTW, &Big5 }, - { "hphkbig5-", &FLG_ZHHK, &HKSCS }, - { "hproc16-", &FLG_NONE, &Unknown }, - { "ibm-1046", &FLG_ARABIC, &IBM1046 }, - { "ibm-1252", &FLG_NONE, &Unknown }, - { "ibm-850", &FLG_NONE, &Unknown }, - { "ibm-fontspecific", &FLG_NONE, &Unknown }, - { "ibm-sbdcn", &FLG_NONE, &Unknown }, - { "ibm-sbdtw", &FLG_NONE, &Unknown }, - { "ibm-special", &FLG_NONE, &Unknown }, - { "ibm-udccn", &FLG_NONE, &Unknown }, - { "ibm-udcjp", &FLG_NONE, &Unknown }, - { "ibm-udctw", &FLG_NONE, &Unknown }, - { "iso646.1991-irv", &FLG_NONE, &Unknown }, - { "iso8859-1", &FLG_WESTERN, &ISO88591 }, - { "iso8859-13", &FLG_BALTIC, &ISO885913 }, - { "iso8859-15", &FLG_WESTERN, &ISO885915 }, - { "iso8859-1@cn", &FLG_NONE, &Unknown }, - { "iso8859-1@kr", &FLG_NONE, &Unknown }, - { "iso8859-1@tw", &FLG_NONE, &Unknown }, - { "iso8859-1@zh", &FLG_NONE, &Unknown }, - { "iso8859-2", &FLG_CE, &ISO88592 }, - { "iso8859-3", &FLG_WESTERN, &ISO88593 }, - { "iso8859-4", &FLG_BALTIC, &ISO88594 }, - { "iso8859-5", &FLG_RUSSIAN, &ISO88595 }, - { "iso8859-6", &FLG_ARABIC, &ISO88596 }, - { "iso8859-6.8x", &FLG_ARABIC, &ISO885968x }, - { "iso8859-6.16", &FLG_ARABIC, &ISO8859616 }, - { "iso8859-7", &FLG_GREEK, &ISO88597 }, - { "iso8859-8", &FLG_HEBREW, &ISO88598 }, - { "iso8859-9", &FLG_TURKISH, &ISO88599 }, - { "iso10646-1", &FLG_NONE, &ISO106461 }, - { "jisx0201.1976-0", &FLG_JA, &JISX0201 }, - { "jisx0201.1976-1", &FLG_JA, &JISX0201 }, - { "jisx0208.1983-0", &FLG_JA, &JISX0208 }, - { "jisx0208.1990-0", &FLG_JA, &JISX0208 }, - { "jisx0212.1990-0", &FLG_JA, &JISX0212 }, - { "koi8-r", &FLG_RUSSIAN, &KOI8R }, - { "koi8-u", &FLG_RUSSIAN, &KOI8U }, - { "johab-1", &FLG_KO, &X11Johab }, - { "johabs-1", &FLG_KO, &X11Johab }, - { "johabsh-1", &FLG_KO, &X11Johab }, - { "ksc5601.1987-0", &FLG_KO, &KSC5601 }, - // We can handle GR fonts with GL encoders (KSC5601 and GB2312) - // See |DoubleByteConvert| - { "ksc5601.1987-1", &FLG_KO, &KSC5601 }, - { "ksc5601.1992-3", &FLG_KO, &JohabNoAscii }, - { "koreanjamo-0", &FLG_KO, &JamoTTF }, - { "microsoft-cp1250", &FLG_CE, &CP1250 }, - { "microsoft-cp1251", &FLG_RUSSIAN, &CP1251 }, - { "microsoft-cp1252", &FLG_WESTERN, &CP1252 }, - { "microsoft-cp1253", &FLG_GREEK, &CP1253 }, - { "microsoft-cp1257", &FLG_BALTIC, &CP1257 }, - { "misc-fontspecific", &FLG_NONE, &Unknown }, - { "sgi-fontspecific", &FLG_NONE, &Unknown }, - { "sun-fontspecific", &FLG_NONE, &Unknown }, - { "sunolcursor-1", &FLG_NONE, &Unknown }, - { "sunolglyph-1", &FLG_NONE, &Unknown }, - { "symbol-fontspecific",&FLG_NONE, &Special }, - { "tis620.2529-1", &FLG_THAI, &TIS620 }, - { "tis620.2533-0", &FLG_THAI, &TIS620 }, - { "tis620.2533-1", &FLG_THAI, &TIS620 }, - { "tis620-0", &FLG_THAI, &TIS620 }, - { "tis620-2", &FLG_THAI, &TIS6202 }, - { "iso8859-11", &FLG_THAI, &ISO885911 }, - { "ucs2.cjk-0", &FLG_NONE, &ISO106461 }, - { "ucs2.cjk_china-0", &FLG_ZHCN, &ISO106461 }, - { "iso10646.2000-cn", &FLG_ZHCN, &ISO106461 }, // HP/UX - { "ucs2.cjk_japan-0", &FLG_JA, &ISO106461 }, - { "ucs2.cjk_korea-0", &FLG_KO, &ISO106461 }, - { "korean.ucs2-0", &FLG_KO, &ISO106461 }, // HP/UX - { "ucs2.cjk_taiwan-0", &FLG_ZHTW, &ISO106461 }, - { "ucs2.thai-0", &FLG_THAI, &ISO106461 }, - { "tamilttf-0", &FLG_TAMIL, &TamilTTF }, -#ifdef SUNCTL - { "sun.unicode.india-0",&FLG_INDIC, &SunIndic }, -#endif /* SUNCTL */ - - { nsnull, nsnull, nsnull } -}; - -static const nsFontFamilyNameXlib gFamilyNameTable[] = -{ - { "arial", "helvetica" }, - { "courier new", "courier" }, - { "times new roman", "times" }, - -#ifdef MOZ_MATHML - { "cmex", "cmex10" }, - { "cmsy", "cmsy10" }, - { "-moz-math-text", "times" }, - { "-moz-math-symbol", "symbol" }, -#endif /* MOZ_MATHML */ - - { nsnull, nsnull } -}; - -static const nsFontCharSetMapXlib gConstNoneCharSetMap[] = { { nsnull }, }; - -static const nsFontCharSetMapXlib gConstSpecialCharSetMap[] = -{ - { "symbol-adobe-fontspecific", &FLG_NONE, &AdobeSymbol }, - { "euromono-adobe-fontspecific", &FLG_NONE, &AdobeEuro }, - { "eurosans-adobe-fontspecific", &FLG_NONE, &AdobeEuro }, - { "euroserif-adobe-fontspecific", &FLG_NONE, &AdobeEuro }, - -#ifdef MOZ_MATHML - { "cmex10-adobe-fontspecific", &FLG_NONE, &CMCMEX }, - { "cmsy10-adobe-fontspecific", &FLG_NONE, &CMCMSY }, - { "cmr10-adobe-fontspecific", &FLG_NONE, &CMCMR }, - { "cmmi10-adobe-fontspecific", &FLG_NONE, &CMCMMI }, - - { "math1-adobe-fontspecific", &FLG_NONE, &Mathematica1 }, - { "math2-adobe-fontspecific", &FLG_NONE, &Mathematica2 }, - { "math3-adobe-fontspecific", &FLG_NONE, &Mathematica3 }, - { "math4-adobe-fontspecific", &FLG_NONE, &Mathematica4 }, - { "math5-adobe-fontspecific", &FLG_NONE, &Mathematica5 }, - - { "math1mono-adobe-fontspecific", &FLG_NONE, &Mathematica1 }, - { "math2mono-adobe-fontspecific", &FLG_NONE, &Mathematica2 }, - { "math3mono-adobe-fontspecific", &FLG_NONE, &Mathematica3 }, - { "math4mono-adobe-fontspecific", &FLG_NONE, &Mathematica4 }, - { "math5mono-adobe-fontspecific", &FLG_NONE, &Mathematica5 }, -#endif /* MOZ_MATHML */ - - { nsnull, nsnull } -}; - -static const nsFontPropertyNameXlib gStretchNames[] = -{ - { "block", 5 }, // XXX - { "bold", 7 }, // XXX - { "double wide", 9 }, - { "medium", 5 }, - { "narrow", 3 }, - { "normal", 5 }, - { "semicondensed", 4 }, - { "wide", 7 }, - - { nsnull, 0 } -}; - -static const nsFontPropertyNameXlib gWeightNames[] = -{ - { "black", 900 }, - { "bold", 700 }, - { "book", 400 }, - { "demi", 600 }, - { "demibold", 600 }, - { "light", 300 }, - { "medium", 400 }, - { "regular", 400 }, - - { nsnull, 0 } -}; - -#ifdef DEBUG_copyfontcharsetmap -void DumpFontCharSetMap(const nsFontCharSetMapXlib *fcsm) -{ - printf("fcsm = %lx\n", fcsm); - printf("{\n"); - - for( ; fcsm->mName ; fcsm++ ) - { -#define STRNULL(s) ((s)?(s):("nsnull")) - printf(" { mName='%s', \tmFontLangGroup=%lx {mFontLangGroupName='%s'}, \tmInfo=%lx {mCharSet='%s'}}\n", - STRNULL(fcsm->mName), - fcsm->mFontLangGroup, - STRNULL(fcsm->mFontLangGroup->mFontLangGroupName), - fcsm->mInfo, - STRNULL(fcsm->mInfo->mCharSet)); -#undef STRNULL - } - printf("}\n"); -} -#endif /* DEBUG_copyfontcharsetmap */ - -/* Copy nsFontCharSetMapXlib structures to the appropriate members of - * |aFmctx|: - * |gConstCharSetMap| --> |aFmctx->mCharSetMap| - * |gConstNoneCharSetMap| --> |aFmctx->mNoneCharSetMap| - * |gConstSpecialCharSetMap| --> |aFmctx->mSpecialCharSetMap| - * When copying, we ensure that structures with identical content - * have identical pointers (since fontmetrics code uses such pointers - * for |equal|, |not equal| comparisons etc.). - */ -static -PRBool CopyFontCharSetMapXlib(nsFontMetricsXlibContext *aFmctx) -{ - long size1[3], - size2[3], - size3[3]; - int i, - j, - k, - l, - count[3]; - char *s; - const nsFontCharSetMapXlib *fcsm[3]; - nsFontCharSetMapXlib *copy[3]; - nsFontLangGroupXlib *langgroup; - nsFontCharSetInfoXlib *charsetinfo; - - fcsm[0] = gConstCharSetMap; - fcsm[1] = gConstNoneCharSetMap; - fcsm[2] = gConstSpecialCharSetMap; - - size1[0] = size2[0] = size3[0] = 0; - size1[1] = size2[1] = size3[1] = 0; - size1[2] = size2[2] = size3[2] = 0; - -/* Alignment macros to force memory alignment required by most RISC platforms - * MAX_ALIGN_BYTES = sizeof(pointer) incl. the doubleword alignment required - * by some platforms, ALIGN_PTR() aligns the given pointer to match - * MAX_ALIGN_BYTES alignment - * XXX: NSPR should define that... - */ -#define MAX_ALIGN_BYTES (sizeof(void *) * 2) -#define ALIGN_PTR(ptr) ((void *)(((PRUptrdiff)(ptr) & ~(MAX_ALIGN_BYTES-1L)) + MAX_ALIGN_BYTES)) - - for( l = 0 ; l < 3 ; l++ ) - { - /* Count entries in fcsm */ - for( count[l]=0 ; fcsm[l][count[l]].mName ; count[l]++ ) ; - - count[l]++; - size1[l] = sizeof(nsFontCharSetMapXlib) * count[l] + MAX_ALIGN_BYTES; - size2[l] = sizeof(nsFontLangGroupXlib) * count[l] + MAX_ALIGN_BYTES; - size3[l] = sizeof(nsFontCharSetInfoXlib) * count[l] + MAX_ALIGN_BYTES; - count[l]--; - } - - s = (char *)calloc(1, size1[0]+size2[0]+size3[0]+ - size1[1]+size2[1]+size3[1]+ - size1[2]+size2[2]+size3[2]); - if (!s) - return PR_FALSE; - - /* Note that the pointer in |copy[0]| is stored in |mCharSetMap| later which - * is finally passed to |free()| when the nsFontMetricsXlibContext destructor - * is called. */ - copy[0] = (nsFontCharSetMapXlib *)s; s += size1[0]; - copy[1] = (nsFontCharSetMapXlib *)ALIGN_PTR(s); s += size1[1]; - copy[2] = (nsFontCharSetMapXlib *)ALIGN_PTR(s); s += size1[2]; - langgroup = (nsFontLangGroupXlib *)ALIGN_PTR(s); s += size2[0] + size2[1] + size2[2]; - charsetinfo = (nsFontCharSetInfoXlib *)ALIGN_PTR(s); - - for( l = 0 ; l < 3 ; l++ ) - { - for( i = 0 ; i < count[l] ; i++ ) - { - copy[l][i].mName = fcsm[l][i].mName; - - if (!copy[l][i].mFontLangGroup) - { - nsFontLangGroupXlib *slot = langgroup++; - *slot = *fcsm[l][i].mFontLangGroup; - copy[l][i].mFontLangGroup = slot; - - for( k = 0 ; k < 3 ; k++ ) - { - for( j = 0 ; j < count[k] ; j++ ) - { - if ((!copy[k][j].mFontLangGroup) && - (fcsm[k][j].mFontLangGroup == fcsm[l][i].mFontLangGroup)) - { - copy[k][j].mFontLangGroup = slot; - } - } - } - } - - if (!copy[l][i].mInfo) - { - nsFontCharSetInfoXlib *slot = charsetinfo++; - - if (fcsm[l][i].mInfo == &Unknown) - { - aFmctx->mUnknown = slot; - } - else if (fcsm[l][i].mInfo == &Special) - { - aFmctx->mSpecial = slot; - } - else if (fcsm[l][i].mInfo == &ISO106461) - { - aFmctx->mISO106461 = slot; - } - - *slot = *fcsm[l][i].mInfo; - - copy[l][i].mInfo = slot; - - for( k = 0 ; k < 3 ; k++ ) - { - for( j = 0 ; j < count[k] ; j++ ) - { - if ((!copy[k][j].mInfo) && - (fcsm[k][j].mInfo == fcsm[l][i].mInfo)) - { - copy[k][j].mInfo = slot; - } - } - } - } - } - } - - aFmctx->mCharSetMap = copy[0]; - aFmctx->mNoneCharSetMap = copy[1]; - aFmctx->mSpecialCharSetMap = copy[2]; - -#ifdef DEBUG_copyfontcharsetmap - DumpFontCharSetMap(aFmctx->mCharSetMap); - DumpFontCharSetMap(aFmctx->mNoneCharSetMap); - DumpFontCharSetMap(aFmctx->mSpecialCharSetMap); -#endif /* DEBUG_copyfontcharsetmap */ - - return PR_TRUE; -} - -static char* -atomToName(nsIAtom* aAtom) -{ - const char *namePRU; - aAtom->GetUTF8String(&namePRU); - return ToNewCString(nsDependentCString(namePRU)); -} - -// -// smart quotes (and other special chars) in Asian (double byte) -// fonts are too large to use is western fonts. -// To update the list, see one of files included below. (bug 180266) -// -#include "dbyte_special_chars.ccmap" -DEFINE_CCMAP(gDoubleByteSpecialCharsCCMap, const); - -static PRBool -FreeCharSetMap(nsHashKey* aKey, void* aData, void* aClosure) -{ - nsFontCharSetMapXlib* charsetMap = (nsFontCharSetMapXlib*) aData; - NS_IF_RELEASE(charsetMap->mInfo->mConverter); - NS_IF_RELEASE(charsetMap->mInfo->mLangGroup); - FreeCCMap(charsetMap->mInfo->mCCMap); - - return PR_TRUE; -} - -static PRBool -FreeFamily(nsHashKey* aKey, void* aData, void* aClosure) -{ - delete (nsFontFamilyXlib*) aData; - - return PR_TRUE; -} - -static void -FreeStretch(nsFontStretchXlib* aStretch) -{ - PR_smprintf_free(aStretch->mScalable); - - for (PRInt32 count = aStretch->mScaledFonts.Count()-1; count >= 0; --count) { - nsFontXlib *font = (nsFontXlib*)aStretch->mScaledFonts.ElementAt(count); - if (font) delete font; - } - // aStretch->mScaledFonts.Clear(); handled by delete of aStretch - - for (int i = 0; i < aStretch->mSizesCount; i++) { - delete aStretch->mSizes[i]; - } - delete [] aStretch->mSizes; - delete aStretch; -} - -static void -FreeWeight(nsFontWeightXlib* aWeight) -{ - for (int i = 0; i < 9; i++) { - if (aWeight->mStretches[i]) { - for (int j = i + 1; j < 9; j++) { - if (aWeight->mStretches[j] == aWeight->mStretches[i]) { - aWeight->mStretches[j] = nsnull; - } - } - FreeStretch(aWeight->mStretches[i]); - } - } - delete aWeight; -} - -static void -FreeStyle(nsFontStyleXlib* aStyle) -{ - for (int i = 0; i < 9; i++) { - if (aStyle->mWeights[i]) { - for (int j = i + 1; j < 9; j++) { - if (aStyle->mWeights[j] == aStyle->mWeights[i]) { - aStyle->mWeights[j] = nsnull; - } - } - FreeWeight(aStyle->mWeights[i]); - } - } - delete aStyle; -} - -static -PRBool -FreeNode(nsHashKey* aKey, void* aData, void* aClosure) -{ - nsFontNodeXlib* node = (nsFontNodeXlib*) aData; - for (int i = 0; i < 3; i++) { - if (node->mStyles[i]) { - for (int j = i + 1; j < 3; j++) { - if (node->mStyles[j] == node->mStyles[i]) { - node->mStyles[j] = nsnull; - } - } - FreeStyle(node->mStyles[i]); - } - } - delete node; - - return PR_TRUE; -} - -static -PRBool -FreeNodeArray(nsHashKey* aKey, void* aData, void* aClosure) -{ - nsFontNodeArrayXlib* nodes = (nsFontNodeArrayXlib*) aData; - delete nodes; - - return PR_TRUE; -} - -/* This is only required for the main display */ -static nsFontMetricsXlibContext *global_fmctx = nsnull; - -nsFontMetricsXlibContext::~nsFontMetricsXlibContext() -{ - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("# nsFontMetricsXlibContext destroy()\n")); - -#ifdef MOZ_ENABLE_FREETYPE2 - nsFreeTypeFreeGlobals(); -#endif /* MOZ_ENABLE_FREETYPE2 */ - -#ifdef ENABLE_X_FONT_BANNING - if (mFontRejectRegEx) { - regfree(mFontRejectRegEx); - delete mFontRejectRegEx; - } - - if (mFontAcceptRegEx) { - regfree(mFontAcceptRegEx); - delete mFontAcceptRegEx; - } -#endif /* ENABLE_X_FONT_BANNING */ - -#ifdef USE_AASB - nsXFontAAScaledBitmap::FreeGlobals(); - nsX11AlphaBlendFreeGlobals(); -#endif /* USE_AASB */ - - mCharSetMaps.Reset(FreeCharSetMap, nsnull); - mFamilies.Reset(FreeFamily, nsnull); - mCachedFFRESearches.Reset(FreeNodeArray, nsnull); - mFFRENodes.Reset(FreeNode, nsnull); - mAFRENodes.Reset(FreeNode, nsnull); - mSpecialCharSets.Reset(FreeCharSetMap, nsnull); - - const nsFontCharSetMapXlib* charSetMap; - for (charSetMap=mCharSetMap; charSetMap->mFontLangGroup; charSetMap++) { - NS_IF_RELEASE(charSetMap->mFontLangGroup->mFontLangGroupAtom); - } - FreeCCMap(mUserDefinedCCMap); - FreeCCMap(mEmptyCCMap); - PR_Free(mDoubleByteSpecialCharsCCMap); - - /* Free memory allocated by |CopyFontCharSetMapXlib()| */ - if (mCharSetMap) { - free((void *)mCharSetMap); - } -} - -/* - * Initialize all the font lookup hash tables and other globals - */ - -nsresult CreateFontMetricsXlibContext(nsIDeviceContext *aDevice, PRBool aPrintermode, nsFontMetricsXlibContext **aFontMetricsXlibContext) -{ - nsresult rv; - nsFontMetricsXlibContext *fmctx; - - *aFontMetricsXlibContext = nsnull; - - fmctx = new nsFontMetricsXlibContext(); - if (!fmctx) - return NS_ERROR_OUT_OF_MEMORY; - - rv = fmctx->Init(aDevice, aPrintermode); - if ((NS_FAILED(rv))) { - delete fmctx; - return rv; - } - - *aFontMetricsXlibContext = fmctx; - - return rv; -} - -void DeleteFontMetricsXlibContext(nsFontMetricsXlibContext *aFontMetricsXlibContext) -{ - if (aFontMetricsXlibContext) { - delete aFontMetricsXlibContext; - } -} - - -nsFontMetricsXlibContext::nsFontMetricsXlibContext() -{ -} - -nsresult -nsFontMetricsXlibContext::Init(nsIDeviceContext *aDevice, PRBool aPrintermode) -{ - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("# nsFontMetricsXlibContext new() for device=%p\n", aDevice)); - - NS_ENSURE_TRUE(aDevice != nsnull, NS_ERROR_NULL_POINTER); - -#ifdef USE_XPRINT - mPrinterMode = aPrintermode; -#endif /* USE_XPRINT */ - - mForceOutlineScaledFonts = PR_FALSE; - mXlibRgbHandle = nsnull; - mAllowDoubleByteSpecialChars = PR_TRUE; - - // XXX many of these statics need to be freed at shutdown time - - mDevScale = 0.0f; /* Scaler value from |GetCanonicalPixelScale()| */ - mScaleBitmapFontsWithDevScale = PR_FALSE; - - mGlobalListInitalised = PR_FALSE; - - mUserDefinedCCMap = nsnull; - mEmptyCCMap = nsnull; - mDoubleByteSpecialCharsCCMap = nsnull; - - mCharSetMap = nsnull; - mNoneCharSetMap = nsnull; - mSpecialCharSetMap = nsnull; - - // Controls for Outline Scaled Fonts (okay looking) - - mOutlineScaleMinimum = 6; -#ifdef USE_AASB -// Controls for Anti-Aliased Scaled Bitmaps (okay looking) - mAABitmapScaleEnabled = PR_TRUE; - mAABitmapScaleAlways = PR_FALSE; - mAABitmapScaleMinimum = 6; - mAABitmapOversize = 1.1; - mAABitmapUndersize = 0.9; -#endif /* USE_AASB */ - -// Controls for (regular) Scaled Bitmaps (very ugly) - mBitmapScaleMinimum = 10; - mBitmapOversize = 1.2; - mBitmapUndersize = 0.8; - -#ifdef USE_AASB - mAntiAliasMinimum = 8; -#endif /* USE_AASB */ - mEmbeddedBitmapMaximumHeight = 1000000; - -#ifdef MOZ_ENABLE_FREETYPE2 - mEnableFreeType2 = PR_TRUE; - mFreeType2Autohinted = PR_FALSE; - mFreeType2Unhinted = PR_TRUE; -#endif /* MOZ_ENABLE_FREETYPE2 */ -#ifdef USE_AASB - mAATTDarkTextMinValue = 64; - mAATTDarkTextGain = 0.8; -#endif /* USE_AASB */ - -#ifdef ENABLE_X_FONT_BANNING - mFontRejectRegEx = nsnull; - mFontAcceptRegEx = nsnull; -#endif /* ENABLE_X_FONT_BANNING */ - - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("## CopyFontCharSetMapXlib start.\n")); - - if (!CopyFontCharSetMapXlib(this)) { - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("## CopyFontCharSetMapXlib FAILED.\n")); - return NS_ERROR_OUT_OF_MEMORY; - } - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("## CopyFontCharSetMapXlib done.\n")); - -#ifdef NS_FONT_DEBUG - /* First check gfx/src/xlib/-specific env var "NS_FONT_DEBUG_XLIB" (or - * "NS_FONT_DEBUG_XPRINT" if the device is a printer), - * then the more general "NS_FONT_DEBUG" if - * "NS_FONT_DEBUG_XLIB"/"NS_FONT_DEBUG_XPRINT" is not present */ - const char *debug; -#ifdef USE_XPRINT - if (mPrinterMode) { - debug = PR_GetEnv("NS_FONT_DEBUG_XPRINT"); - } - else -#endif /* USE_XPRINT */ - { - debug = PR_GetEnv("NS_FONT_DEBUG_XLIB"); - } - - if (!debug) { - debug = PR_GetEnv("NS_FONT_DEBUG"); - } - - if (debug) { - PR_sscanf(debug, "%lX", &gFontDebug); - } -#endif /* NS_FONT_DEBUG */ - - NS_STATIC_CAST(nsDeviceContextX *, aDevice)->GetXlibRgbHandle(mXlibRgbHandle); - - aDevice->GetCanonicalPixelScale(mDevScale); - - mCharSetManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID); - if (!mCharSetManager) { - return NS_ERROR_FAILURE; - } - - mPref = do_GetService(NS_PREF_CONTRACTID); - if (!mPref) { - return NS_ERROR_FAILURE; - } - - nsCompressedCharMap empty_ccmapObj; - mEmptyCCMap = empty_ccmapObj.NewCCMap(); - if (!mEmptyCCMap) - return NS_ERROR_OUT_OF_MEMORY; - - // get the "disable double byte font special chars" setting - PRBool val = PR_TRUE; - nsresult rv = mPref->GetBoolPref("font.allow_double_byte_special_chars", &val); - if (NS_SUCCEEDED(rv)) - mAllowDoubleByteSpecialChars = val; - - /* Make sure we allocate/copy enough (see bug 235913, comment 12)*/ - PRUint32 dbmapSize = sizeof(gDoubleByteSpecialCharsCCMapUnion); - mDoubleByteSpecialCharsCCMap = (PRUint16*)PR_Malloc(dbmapSize); - if (!mDoubleByteSpecialCharsCCMap) - return NS_ERROR_OUT_OF_MEMORY; - memcpy(mDoubleByteSpecialCharsCCMap, gDoubleByteSpecialCharsCCMap, dbmapSize); - - PRInt32 scale_minimum = 0; - rv = mPref->GetIntPref("font.scale.outline.min", &scale_minimum); - if (NS_SUCCEEDED(rv)) { - mOutlineScaleMinimum = scale_minimum; - SIZE_FONT_PRINTF(("mOutlineScaleMinimum = %d", mOutlineScaleMinimum)); - } - - PRInt32 int_val = 0; - PRInt32 percent = 0; -#ifdef USE_AASB - val = PR_TRUE; - rv = mPref->GetBoolPref("font.scale.aa_bitmap.enable", &val); - if (NS_SUCCEEDED(rv)) { - mAABitmapScaleEnabled = val; - SIZE_FONT_PRINTF(("mAABitmapScaleEnabled = %d", mAABitmapScaleEnabled)); - } - - val = PR_FALSE; - rv = mPref->GetBoolPref("font.scale.aa_bitmap.always", &val); - if (NS_SUCCEEDED(rv)) { - mAABitmapScaleAlways = val; - SIZE_FONT_PRINTF(("mAABitmapScaleAlways = %d", mAABitmapScaleAlways)); - } - - rv = mPref->GetIntPref("font.scale.aa_bitmap.min", &scale_minimum); - if (NS_SUCCEEDED(rv)) { - mAABitmapScaleMinimum = scale_minimum; - SIZE_FONT_PRINTF(("mAABitmapScaleMinimum = %d", mAABitmapScaleMinimum)); - } - - percent = 0; - rv = mPref->GetIntPref("font.scale.aa_bitmap.undersize", &percent); - if ((NS_SUCCEEDED(rv)) && (percent)) { - mAABitmapUndersize = percent/100.0; - SIZE_FONT_PRINTF(("mAABitmapUndersize = %g", mAABitmapUndersize)); - } - percent = 0; - rv = mPref->GetIntPref("font.scale.aa_bitmap.oversize", &percent); - if ((NS_SUCCEEDED(rv)) && (percent)) { - mAABitmapOversize = percent/100.0; - SIZE_FONT_PRINTF(("mAABitmapOversize = %g", mAABitmapOversize)); - } - int_val = 0; - rv = mPref->GetIntPref("font.scale.aa_bitmap.dark_text.min", &int_val); - if (NS_SUCCEEDED(rv)) { - gAASBDarkTextMinValue = int_val; - SIZE_FONT_PRINTF(("gAASBDarkTextMinValue = %d", gAASBDarkTextMinValue)); - } - nsXPIDLCString str; - rv = mPref->GetCharPref("font.scale.aa_bitmap.dark_text.gain", - getter_Copies(str)); - if (NS_SUCCEEDED(rv)) { - gAASBDarkTextGain = atof(str.get()); - SIZE_FONT_PRINTF(("gAASBDarkTextGain = %g", gAASBDarkTextGain)); - } - int_val = 0; - rv = mPref->GetIntPref("font.scale.aa_bitmap.light_text.min", &int_val); - if (NS_SUCCEEDED(rv)) { - gAASBLightTextMinValue = int_val; - SIZE_FONT_PRINTF(("gAASBLightTextMinValue = %d", gAASBLightTextMinValue)); - } - rv = mPref->GetCharPref("font.scale.aa_bitmap.light_text.gain", - getter_Copies(str)); - if (NS_SUCCEEDED(rv)) { - gAASBLightTextGain = atof(str.get()); - SIZE_FONT_PRINTF(("gAASBLightTextGain = %g", gAASBLightTextGain)); - } -#endif /* USE_AASB */ - - rv = mPref->GetIntPref("font.scale.bitmap.min", &scale_minimum); - if (NS_SUCCEEDED(rv)) { - mBitmapScaleMinimum = scale_minimum; - SIZE_FONT_PRINTF(("mBitmapScaleMinimum = %d", mBitmapScaleMinimum)); - } - percent = 0; - mPref->GetIntPref("font.scale.bitmap.oversize", &percent); - if (percent) { - mBitmapOversize = percent/100.0; - SIZE_FONT_PRINTF(("mBitmapOversize = %g", mBitmapOversize)); - } - percent = 0; - mPref->GetIntPref("font.scale.bitmap.undersize", &percent); - if (percent) { - mBitmapUndersize = percent/100.0; - SIZE_FONT_PRINTF(("mBitmapUndersize = %g", mBitmapUndersize)); - } - -#ifdef USE_XPRINT - if (mPrinterMode) { - mForceOutlineScaledFonts = PR_TRUE; - } -#endif /* USE_XPRINT */ - - PRBool force_outline_scaled_fonts = mForceOutlineScaledFonts; -#ifdef USE_XPRINT - if (mPrinterMode) { - rv = mPref->GetBoolPref("print.xprint.font.force_outline_scaled_fonts", &force_outline_scaled_fonts); - } - if (!mPrinterMode || NS_FAILED(rv)) { -#endif /* USE_XPRINT */ - rv = mPref->GetBoolPref("font.x11.force_outline_scaled_fonts", &force_outline_scaled_fonts); -#ifdef USE_XPRINT - } -#endif /* USE_XPRINT */ - if (NS_SUCCEEDED(rv)) { - mForceOutlineScaledFonts = force_outline_scaled_fonts; - } - -#ifdef MOZ_ENABLE_FREETYPE2 - PRBool enable_freetype2 = PR_TRUE; - rv = mPref->GetBoolPref("font.FreeType2.enable", &enable_freetype2); - if (NS_SUCCEEDED(rv)) { - mEnableFreeType2 = enable_freetype2; - FREETYPE_FONT_PRINTF(("mEnableFreeType2 = %d", mEnableFreeType2)); - } - - PRBool freetype2_autohinted = PR_FALSE; - rv = mPref->GetBoolPref("font.FreeType2.autohinted", &freetype2_autohinted); - if (NS_SUCCEEDED(rv)) { - mFreeType2Autohinted = freetype2_autohinted; - FREETYPE_FONT_PRINTF(("mFreeType2Autohinted = %d", mFreeType2Autohinted)); - } - - PRBool freetype2_unhinted = PR_TRUE; - rv = mPref->GetBoolPref("font.FreeType2.unhinted", &freetype2_unhinted); - if (NS_SUCCEEDED(rv)) { - mFreeType2Unhinted = freetype2_unhinted; - FREETYPE_FONT_PRINTF(("mFreeType2Unhinted = %d", mFreeType2Unhinted)); - } -#endif /* MOZ_ENABLE_FREETYPE2 */ - -#ifdef USE_AASB - PRInt32 antialias_minimum = 8; - rv = mPref->GetIntPref("font.antialias.min", &antialias_minimum); - if (NS_SUCCEEDED(rv)) { - mAntiAliasMinimum = antialias_minimum; - FREETYPE_FONT_PRINTF(("mAntiAliasMinimum = %d", mAntiAliasMinimum)); - } -#endif /* USE_AASB */ - - PRInt32 embedded_bitmaps_maximum = 1000000; - rv = mPref->GetIntPref("font.embedded_bitmaps.max",&embedded_bitmaps_maximum); - if (NS_SUCCEEDED(rv)) { - mEmbeddedBitmapMaximumHeight = embedded_bitmaps_maximum; - FREETYPE_FONT_PRINTF(("mEmbeddedBitmapMaximumHeight = %d", - mEmbeddedBitmapMaximumHeight)); - } - int_val = 0; -#ifdef USE_AASB - rv = mPref->GetIntPref("font.scale.tt_bitmap.dark_text.min", &int_val); - if (NS_SUCCEEDED(rv)) { - mAATTDarkTextMinValue = int_val; - SIZE_FONT_PRINTF(("mAATTDarkTextMinValue = %d", mAATTDarkTextMinValue)); - } - rv = mPref->GetCharPref("font.scale.tt_bitmap.dark_text.gain", - getter_Copies(str)); - if (NS_SUCCEEDED(rv)) { - mAATTDarkTextGain = atof(str.get()); - SIZE_FONT_PRINTF(("mAATTDarkTextGain = %g", mAATTDarkTextGain)); - } -#endif /* USE_AASB */ - -#ifdef USE_XPRINT - if (mPrinterMode) { - mScaleBitmapFontsWithDevScale = PR_TRUE; - } -#endif /* USE_XPRINT */ - - PRBool scale_bitmap_fonts_with_devscale = mScaleBitmapFontsWithDevScale; -#ifdef USE_XPRINT - if (mPrinterMode) { - rv = mPref->GetBoolPref("print.xprint.font.scale_bitmap_fonts_with_devscale", &scale_bitmap_fonts_with_devscale); - } - if (!mPrinterMode || NS_FAILED(rv)) { -#endif /* USE_XPRINT */ - rv = mPref->GetBoolPref("font.x11.scale_bitmap_fonts_with_devscale", &scale_bitmap_fonts_with_devscale); -#ifdef USE_XPRINT - } -#endif /* USE_XPRINT */ - if (NS_SUCCEEDED(rv)) { - mScaleBitmapFontsWithDevScale = scale_bitmap_fonts_with_devscale; - } - - const nsFontFamilyNameXlib* f = gFamilyNameTable; - while (f->mName) { - nsCStringKey key(f->mName); - mAliases.Put(&key, (void *)f->mXName); - f++; - } - - const nsFontPropertyNameXlib* p = gWeightNames; - while (p->mName) { - nsCStringKey key(p->mName); - mWeights.Put(&key, (void*) p->mValue); - p++; - } - - p = gStretchNames; - while (p->mName) { - nsCStringKey key(p->mName); - mStretches.Put(&key, (void*) p->mValue); - p++; - } - - const nsFontCharSetMapXlib* charSetMap = mCharSetMap; - while (charSetMap->mName) { - nsCStringKey key(charSetMap->mName); - mCharSetMaps.Put(&key, (void *)charSetMap); - charSetMap++; - } - - const nsFontCharSetMapXlib* specialCharSetMap = mSpecialCharSetMap; - while (specialCharSetMap->mName) { - nsCStringKey key(specialCharSetMap->mName); - mSpecialCharSets.Put(&key, (void *)specialCharSetMap); - specialCharSetMap++; - } - - mUnicode = do_GetAtom("x-unicode"); - if (!mUnicode) { - return NS_ERROR_OUT_OF_MEMORY; - } - mUserDefined = do_GetAtom(USER_DEFINED); - if (!mUserDefined) { - return NS_ERROR_OUT_OF_MEMORY; - } - mZHTW = do_GetAtom("zh-TW"); - if (!mZHTW) { - return NS_ERROR_OUT_OF_MEMORY; - } - mZHHK = do_GetAtom("zh-HK"); - if (!mZHHK) { - return NS_ERROR_OUT_OF_MEMORY; - } - mZHTWHK = do_GetAtom("x-zh-TWHK"); - if (!mZHTWHK) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // the user's locale - nsCOMPtr langService; - langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - if (langService) { - mUsersLocale = langService->GetLocaleLanguageGroup(); - } - if (!mUsersLocale) { - mUsersLocale = do_GetAtom("x-western"); - } - mWesternLocale = do_GetAtom("x-western"); - if (!mUsersLocale) { - return NS_ERROR_OUT_OF_MEMORY; - } - -#ifdef USE_AASB - rv = nsX11AlphaBlendInitGlobals(xxlib_rgb_get_display(mXlibRgbHandle)); - if (NS_FAILED(rv) || (!nsX11AlphaBlend::CanAntiAlias())) { - mAABitmapScaleEnabled = PR_FALSE; - } - - if (mAABitmapScaleEnabled) { - mAABitmapScaleEnabled = nsXFontAAScaledBitmap::InitGlobals(xxlib_rgb_get_display(mXlibRgbHandle), - xxlib_rgb_get_screen(mXlibRgbHandle)); - } -#endif /* USE_AASB */ - -#ifdef ENABLE_X_FONT_BANNING - /* get the font banning pattern */ - nsXPIDLCString fbpattern; -#ifdef USE_XPRINT - if (mPrinterMode) { - rv = mPref->GetCharPref("print.xprint.font.rejectfontpattern", getter_Copies(fbpattern)); - } - if (!mPrinterMode || NS_FAILED(rv)) { -#endif /* USE_XPRINT */ - rv = mPref->GetCharPref("font.x11.rejectfontpattern", getter_Copies(fbpattern)); -#ifdef USE_XPRINT - } -#endif /* USE_XPRINT */ - if (NS_SUCCEEDED(rv)) { - mFontRejectRegEx = new regex_t; - if (!mFontRejectRegEx) { - return NS_ERROR_OUT_OF_MEMORY; - } - - /* Compile the pattern - and return an error if we get an invalid pattern... */ - if (regcomp(mFontRejectRegEx, fbpattern.get(), REG_EXTENDED|REG_NOSUB) != REG_OK) { - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("Invalid rejectfontpattern '%s'\n", fbpattern.get())); - BANNED_FONT_PRINTF(("Invalid font.x11.rejectfontpattern '%s'", fbpattern.get())); - delete mFontRejectRegEx; - mFontRejectRegEx = nsnull; - - return NS_ERROR_INVALID_ARG; - } - } - -#ifdef USE_XPRINT - if (mPrinterMode) { - rv = mPref->GetCharPref("print.xprint.font.acceptfontpattern", getter_Copies(fbpattern)); - } - if (!mPrinterMode || NS_FAILED(rv)) { -#endif /* USE_XPRINT */ - rv = mPref->GetCharPref("font.x11.acceptfontpattern", getter_Copies(fbpattern)); -#ifdef USE_XPRINT - } -#endif /* USE_XPRINT */ - if (NS_SUCCEEDED(rv)) { - mFontAcceptRegEx = new regex_t; - if (!mFontAcceptRegEx) { - return NS_ERROR_OUT_OF_MEMORY; - } - - /* Compile the pattern - and return an error if we get an invalid pattern... */ - if (regcomp(mFontAcceptRegEx, fbpattern.get(), REG_EXTENDED|REG_NOSUB) != REG_OK) { - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("Invalid acceptfontpattern '%s'\n", fbpattern.get())); - BANNED_FONT_PRINTF(("Invalid font.x11.acceptfontpattern '%s'", fbpattern.get())); - delete mFontAcceptRegEx; - mFontAcceptRegEx = nsnull; - - return NS_ERROR_INVALID_ARG; - } - } -#endif /* ENABLE_X_FONT_BANNING */ - -#ifdef MOZ_ENABLE_FREETYPE2 - rv = nsFreeTypeInitGlobals(); - if (NS_FAILED(rv)) { - return NS_ERROR_OUT_OF_MEMORY; - } -#endif /* MOZ_ENABLE_FREETYPE2 */ - - return NS_OK; -} - -#ifdef USE_X11SHARED_CODE -#error not implemented yet -#else -void -nsXFontNormal::DrawText8(Drawable aDrawable, GC aGC, - PRInt32 aX, PRInt32 aY, - const char *aString, PRUint32 aLength) -{ - XDrawString(mDisplay, aDrawable, aGC, aX, aY, aString, PR_MIN(aLength, 32767)); -} - -void -nsXFontNormal::DrawText16(Drawable aDrawable, GC aGC, - PRInt32 aX, PRInt32 aY, - const XChar2b *aString, PRUint32 aLength) -{ - XDrawString16(mDisplay, aDrawable, aGC, aX, aY, aString, PR_MIN(aLength, 32767)); -} - -PRBool -nsXFontNormal::GetXFontProperty(Atom aAtom, unsigned long *aValue) -{ - NS_ASSERTION(mXFont, "GetXFontProperty called before font loaded"); - if (mXFont==nsnull) - return PR_FALSE; - - return ::XGetFontProperty(mXFont, aAtom, aValue); -} - -XFontStruct * -nsXFontNormal::GetXFontStruct() -{ - NS_ASSERTION(mXFont, "GetXFontStruct called before font loaded"); - return mXFont; -} - -PRBool -nsXFontNormal::LoadFont() -{ - if (!mXFont) - return PR_FALSE; - mIsSingleByte = (mXFont->min_byte1 == 0) && (mXFont->max_byte1 == 0); - return PR_TRUE; -} - -nsXFontNormal::nsXFontNormal(Display *aDisplay, XFontStruct *aXFont) -{ - mDisplay = aDisplay; - mXFont = aXFont; -} - -void -nsXFontNormal::TextExtents8(const char *aString, PRUint32 aLength, - PRInt32* aLBearing, PRInt32* aRBearing, - PRInt32* aWidth, PRInt32* aAscent, - PRInt32* aDescent) -{ - XCharStruct overall; - int direction, font_ascent, font_descent; - ::XTextExtents(mXFont, aString, aLength, - &direction, &font_ascent, &font_descent, - &overall); - - *aLBearing = overall.lbearing; - *aRBearing = overall.rbearing; - *aWidth = overall.width; - *aAscent = overall.ascent; - *aDescent = overall.descent; -} - -void -nsXFontNormal::TextExtents16(const XChar2b *aString, PRUint32 aLength, - PRInt32* aLBearing, PRInt32* aRBearing, - PRInt32* aWidth, PRInt32* aAscent, - PRInt32* aDescent) -{ - XCharStruct overall; - int direction, font_ascent, font_descent; - ::XTextExtents16(mXFont, aString, aLength, - &direction, &font_ascent, &font_descent, - &overall); - - *aLBearing = overall.lbearing; - *aRBearing = overall.rbearing; - *aWidth = overall.width; - *aAscent = overall.ascent; - *aDescent = overall.descent; -} - -PRInt32 -nsXFontNormal::TextWidth8(const char *aString, PRUint32 aLength) -{ - NS_ASSERTION(mXFont, "TextWidth8 called before font loaded"); - if (mXFont==nsnull) - return 0; - PRInt32 width = ::XTextWidth(mXFont, aString, aLength); - return width; -} - -PRInt32 -nsXFontNormal::TextWidth16(const XChar2b *aString, PRUint32 aLength) -{ - NS_ASSERTION(mXFont, "TextWidth16 called before font loaded"); - if (mXFont==nsnull) - return 0; - PRInt32 width = ::XTextWidth16(mXFont, aString, aLength); - - return width; -} - -void -nsXFontNormal::UnloadFont() -{ - delete this; -} - -nsXFontNormal::~nsXFontNormal() -{ -} -#endif /* USE_X11SHARED_CODE */ - -nsFontMetricsXlib::nsFontMetricsXlib() - : mFonts() // I'm not sure what the common size is here - I generally - // see 2-5 entries. For now, punt and let it be allocated later. We can't - // make it an nsAutoVoidArray since it's a cString array. - // XXX mFontIsGeneric will generally need to be the same size; right now - // it's an nsAutoVoidArray. If the average is under 8, that's ok. -{ -} - -nsFontMetricsXlib::~nsFontMetricsXlib() -{ - // do not free mGeneric here - - if (mLoadedFonts) { - PR_Free(mLoadedFonts); - mLoadedFonts = nsnull; - } - - if (mSubstituteFont) { - delete mSubstituteFont; - mSubstituteFont = nsnull; - } - - mWesternFont = nsnull; - - if (mDeviceContext) { - // Notify our device context that owns us so that it can update its font cache - mDeviceContext->FontMetricsDeleted(this); - mDeviceContext = nsnull; - } -} - -NS_IMPL_ISUPPORTS1(nsFontMetricsXlib, nsIFontMetrics) - -static PRBool -IsASCIIFontName(const nsString& aName) -{ - PRUint32 len = aName.Length(); - const PRUnichar* str = aName.get(); - for (PRUint32 i = 0; i < len; i++) { - /* - * X font names are printable ASCII, ignore others (for now) - */ - if ((str[i] < 0x20) || (str[i] > 0x7E)) { - return PR_FALSE; - } - } - - return PR_TRUE; -} - -static PRBool -FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData) -{ -#ifdef REALLY_NOISY_FONTS - printf("font = '"); - fputs(NS_LossyConvertUTF16toASCII(aFamily).get(), stdout); - printf("'\n"); -#endif - - if (!IsASCIIFontName(aFamily)) { - return PR_TRUE; // skip and continue - } - - nsCAutoString name; - name.AssignWithConversion(aFamily.get()); - ToLowerCase(name); - nsFontMetricsXlib* metrics = (nsFontMetricsXlib*) aData; - metrics->mFonts.AppendCString(name); - metrics->mFontIsGeneric.AppendElement((void*) aGeneric); - if (aGeneric) { - metrics->mGeneric = metrics->mFonts.CStringAt(metrics->mFonts.Count() - 1); - return PR_FALSE; // stop - } - - return PR_TRUE; // continue -} - -NS_IMETHODIMP nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup, - nsIDeviceContext* aContext) -{ - NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null device context"); - - nsresult res; - mDocConverterType = nsnull; - - mDeviceContext = aContext; - - NS_STATIC_CAST(nsDeviceContextX *, mDeviceContext)->GetFontMetricsContext(mFontMetricsContext); - - mFont = aFont; - mLangGroup = aLangGroup; - - float app2dev; - app2dev = mDeviceContext->AppUnitsToDevUnits(); - - mPixelSize = NSToIntRound(app2dev * mFont.size); - // Make sure to clamp the pixel size to something reasonable so we - // don't make the X server blow up. - mPixelSize = PR_MIN(XHeightOfScreen(xxlib_rgb_get_screen(mFontMetricsContext->mXlibRgbHandle)) * FONT_MAX_FONT_SCALE, mPixelSize); - - mStretchIndex = 4; // Normal - mStyleIndex = mFont.style; - - mFont.EnumerateFamilies(FontEnumCallback, this); - nsXPIDLCString value; - const char* langGroup = nsnull; - mLangGroup->GetUTF8String(&langGroup); - if (!mGeneric) { - nsCAutoString name("font.default."); - name.Append(langGroup); - mFontMetricsContext->mPref->CopyCharPref(name.get(), getter_Copies(value)); - if (value.get()) { - mDefaultFont = value.get(); - } - else { - mDefaultFont = "serif"; - } - mGeneric = &mDefaultFont; - } - - if (mLangGroup) { - nsCAutoString name("font.min-size."); - if (mGeneric->Equals("monospace")) { - name.Append("fixed"); - } - else { - name.Append("variable"); - } - name.Append(char('.')); - name.Append(langGroup); - PRInt32 minimum = 0; - res = mFontMetricsContext->mPref->GetIntPref(name.get(), &minimum); - if (NS_FAILED(res)) { - mFontMetricsContext->mPref->GetDefaultIntPref(name.get(), &minimum); - } - if (minimum < 0) { - minimum = 0; - } - if (mPixelSize < minimum) { - mPixelSize = minimum; - } - } - - if (mLangGroup.get() == mFontMetricsContext->mUserDefined) { - if (!mFontMetricsContext->mUserDefinedConverter) { - nsIUnicodeEncoder *ud_conv; - res = mFontMetricsContext->mCharSetManager->GetUnicodeEncoderRaw("x-user-defined", &ud_conv); - if (NS_SUCCEEDED(res)) { - mFontMetricsContext->mUserDefinedConverter = ud_conv; - res = mFontMetricsContext->mUserDefinedConverter->SetOutputErrorBehavior( - mFontMetricsContext->mUserDefinedConverter->kOnError_Replace, nsnull, '?'); - nsCOMPtr mapper = - do_QueryInterface(mFontMetricsContext->mUserDefinedConverter); - if (mapper) { - mFontMetricsContext->mUserDefinedCCMap = MapperToCCMap(mapper); - if (!mFontMetricsContext->mUserDefinedCCMap) - return NS_ERROR_OUT_OF_MEMORY; - } - } - else { - return res; - } - } - - nsCAutoString name("font.name."); - name.Append(*mGeneric); - name.Append(char('.')); - name.Append(USER_DEFINED); - mFontMetricsContext->mPref->CopyCharPref(name.get(), getter_Copies(value)); - if (value.get()) { - mUserDefined = value.get(); - mIsUserDefined = 1; - } - } - - mWesternFont = FindFont('a'); - if (!mWesternFont) - return NS_ERROR_FAILURE; - - RealizeFont(); - - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::Destroy() -{ - mDeviceContext = nsnull; - mFontMetricsContext = nsnull; - return NS_OK; -} - -void nsFontMetricsXlib::RealizeFont() -{ - float f; - f = mDeviceContext->DevUnitsToAppUnits(); - -#ifdef MOZ_ENABLE_FREETYPE2 - if (mWesternFont->IsFreeTypeFont()) { - nsFreeTypeFont *ft = (nsFreeTypeFont *)mWesternFont; - if (!ft) - return; - // now that there are multiple font types (eg: core X fonts - // and TrueType fonts) there should be a common set of methods - // to get the metrics info from the font object. These methods - // probably should be virtual functions defined in nsFontXlib. -#ifdef MOZ_ENABLE_FREETYPE2 - int lineSpacing = ft->ascent() + ft->descent(); - if (lineSpacing > mWesternFont->mSize) { - mLeading = nscoord((lineSpacing - mWesternFont->mSize) * f); - } - else { - mLeading = 0; - } - mEmHeight = PR_MAX(1, nscoord(mWesternFont->mSize * f)); - mEmAscent = nscoord(ft->ascent() * mWesternFont->mSize * f / lineSpacing); - mEmDescent = mEmHeight - mEmAscent; - - mMaxHeight = nscoord((ft->max_ascent() + ft->max_descent()) * f); - mMaxAscent = nscoord(ft->max_ascent() * f) ; - mMaxDescent = nscoord(ft->max_descent() * f); - - mMaxAdvance = nscoord(ft->max_width() * f); - - // 56% of ascent, best guess for non-true type - mXHeight = NSToCoordRound((float) ft->ascent()* f * 0.56f); - - PRUnichar space = (PRUnichar)' '; - mSpaceWidth = NSToCoordRound(ft->GetWidth(&space, 1) * f); - - PRUnichar averageX = (PRUnichar)'x'; - mAveCharWidth = NSToCoordRound(ft->GetWidth(&averageX, 1) * f); - - unsigned long pr = 0; - if (ft->getXHeight(pr)) { - mXHeight = nscoord(pr * f); - } - - float height; - long val; - if (ft->underlinePosition(val)) { - /* this will only be provided from adobe .afm fonts and TrueType - * fonts served by xfsft (not xfstt!) */ - mUnderlineOffset = -NSToIntRound(val * f); - } - else { - height = ft->ascent() + ft->descent(); - mUnderlineOffset = -NSToIntRound(PR_MAX (1, floor (0.1 * height + 0.5)) * f); - } - - if (ft->underline_thickness(pr)) { - /* this will only be provided from adobe .afm fonts */ - mUnderlineSize = nscoord(PR_MAX(f, NSToIntRound(pr * f))); - } - else { - height = ft->ascent() + ft->descent(); - mUnderlineSize = NSToIntRound(PR_MAX(1, floor (0.05 * height + 0.5)) * f); - } - - if (ft->superscript_y(val)) { - mSuperscriptOffset = nscoord(PR_MAX(f, NSToIntRound(val * f))); - } - else { - mSuperscriptOffset = mXHeight; - } - - if (ft->subscript_y(val)) { - mSubscriptOffset = nscoord(PR_MAX(f, NSToIntRound(val * f))); - } - else { - mSubscriptOffset = mXHeight; - } - - /* need better way to calculate this */ - mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0); - mStrikeoutSize = mUnderlineSize; - - return; -#endif /* MOZ_ENABLE_FREETYPE2 */ - } -#endif /* MOZ_ENABLE_FREETYPE2 */ - nsXFont *xFont = mWesternFont->GetXFont(); - XFontStruct *fontInfo = xFont->GetXFontStruct(); - f = mDeviceContext->DevUnitsToAppUnits(); - - nscoord lineSpacing = nscoord((fontInfo->ascent + fontInfo->descent) * f); - mEmHeight = PR_MAX(1, nscoord(mWesternFont->mSize * f)); - if (lineSpacing > mEmHeight) { - mLeading = lineSpacing - mEmHeight; - } - else { - mLeading = 0; - } - mMaxHeight = nscoord((fontInfo->ascent + fontInfo->descent) * f); - mMaxAscent = nscoord(fontInfo->ascent * f); - mMaxDescent = nscoord(fontInfo->descent * f); - - mEmAscent = nscoord(mMaxAscent * mEmHeight / lineSpacing); - mEmDescent = mEmHeight - mEmAscent; - - mMaxAdvance = nscoord(fontInfo->max_bounds.width * f); - - int rawWidth, rawAverage; - if ((fontInfo->min_byte1 == 0) && (fontInfo->max_byte1 == 0)) { - rawWidth = xFont->TextWidth8(" ", 1); - rawAverage = xFont->TextWidth8("x", 1); - } - else { - XChar2b my16bit_space, my16bit_x; - my16bit_space.byte1 = '\0'; - my16bit_space.byte2 = ' '; - my16bit_x.byte1 = 0; - my16bit_x.byte2 = 'x'; - rawWidth = xFont->TextWidth16(&my16bit_space, 1); - rawAverage = xFont->TextWidth16(&my16bit_x, 1); - } - mSpaceWidth = NSToCoordRound(rawWidth * f); - mAveCharWidth = NSToCoordRound(rawAverage * f); - - unsigned long pr = 0; - if (xFont->GetXFontProperty(XA_X_HEIGHT, &pr) && pr != 0 && - pr < 0x00ffffff) // Bug 43214: arbitrary to exclude garbage values - { - mXHeight = nscoord(pr * f); -#ifdef REALLY_NOISY_FONTS - printf("xHeight=%d\n", mXHeight); -#endif - } - else - { - // 56% of ascent, best guess for non-true type - mXHeight = NSToCoordRound((float) fontInfo->ascent* f * 0.56f); - } - - if (xFont->GetXFontProperty(XA_UNDERLINE_POSITION, &pr)) - { - /* this will only be provided from adobe .afm fonts and TrueType - * fonts served by xfsft (not xfstt!) */ - mUnderlineOffset = -NSToIntRound(pr * f); -#ifdef REALLY_NOISY_FONTS - printf("underlineOffset=%d\n", mUnderlineOffset); -#endif - } - else - { - /* this may need to be different than one for those weird asian fonts */ - float height; - height = fontInfo->ascent + fontInfo->descent; - mUnderlineOffset = -NSToIntRound(PR_MAX (1, floor (0.1 * height + 0.5)) * f); - } - - if (xFont->GetXFontProperty(XA_UNDERLINE_THICKNESS, &pr)) - { - /* this will only be provided from adobe .afm fonts */ - mUnderlineSize = nscoord(PR_MAX(f, NSToIntRound(pr * f))); -#ifdef REALLY_NOISY_FONTS - printf("underlineSize=%d\n", mUnderlineSize); -#endif - } - else - { - float height; - height = fontInfo->ascent + fontInfo->descent; - mUnderlineSize = NSToIntRound(PR_MAX(1, floor (0.05 * height + 0.5)) * f); - } - - if (xFont->GetXFontProperty(XA_SUPERSCRIPT_Y, &pr)) - { - mSuperscriptOffset = nscoord(PR_MAX(f, NSToIntRound(pr * f))); -#ifdef REALLY_NOISY_FONTS - printf("superscriptOffset=%d\n", mSuperscriptOffset); -#endif - } - else - { - mSuperscriptOffset = mXHeight; - } - - if (xFont->GetXFontProperty(XA_SUBSCRIPT_Y, &pr)) - { - mSubscriptOffset = nscoord(PR_MAX(f, NSToIntRound(pr * f))); -#ifdef REALLY_NOISY_FONTS - printf("subscriptOffset=%d\n", mSubscriptOffset); -#endif - } - else - { - mSubscriptOffset = mXHeight; - } - - /* need better way to calculate this */ - mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0); - mStrikeoutSize = mUnderlineSize; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetXHeight(nscoord& aResult) -{ - aResult = mXHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetSuperscriptOffset(nscoord& aResult) -{ - aResult = mSuperscriptOffset; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetSubscriptOffset(nscoord& aResult) -{ - aResult = mSubscriptOffset; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetStrikeout(nscoord& aOffset, nscoord& aSize) -{ - aOffset = mStrikeoutOffset; - aSize = mStrikeoutSize; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetUnderline(nscoord& aOffset, nscoord& aSize) -{ - aOffset = mUnderlineOffset; - aSize = mUnderlineSize; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetHeight(nscoord &aHeight) -{ - aHeight = mMaxHeight; - return NS_OK; -} - -#ifdef FONT_LEADING_APIS_V2 -NS_IMETHODIMP nsFontMetricsXlib::GetInternalLeading(nscoord &aLeading) -{ - aLeading = mLeading; - return NS_OK; -} -NS_IMETHODIMP nsFontMetricsXlib::GetExternalLeading(nscoord &aLeading) -{ - aLeading = 0; - return NS_OK; -} -#else - -NS_IMETHODIMP nsFontMetricsXlib::GetNormalLineHeight(nscoord &aHeight) -{ - aHeight = mEmHeight + mLeading; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetLeading(nscoord &aLeading) -{ - aLeading = mLeading; - return NS_OK; -} -#endif - -NS_IMETHODIMP nsFontMetricsXlib::GetEmHeight(nscoord &aHeight) -{ - aHeight = mEmHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetEmAscent(nscoord &aAscent) -{ - aAscent = mEmAscent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetEmDescent(nscoord &aDescent) -{ - aDescent = mEmDescent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetMaxHeight(nscoord &aHeight) -{ - aHeight = mMaxHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetMaxAscent(nscoord &aAscent) -{ - aAscent = mMaxAscent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetMaxDescent(nscoord &aDescent) -{ - aDescent = mMaxDescent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetMaxAdvance(nscoord &aAdvance) -{ - aAdvance = mMaxAdvance; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetAveCharWidth(nscoord &aAveCharWidth) -{ - aAveCharWidth = mAveCharWidth; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetLangGroup(nsIAtom** aLangGroup) -{ - if (!aLangGroup) { - return NS_ERROR_NULL_POINTER; - } - - *aLangGroup = mLangGroup; - NS_IF_ADDREF(*aLangGroup); - - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsXlib::GetFontHandle(nsFontHandle &aHandle) -{ - aHandle = (nsFontHandle)mWesternFont; - return NS_OK; -} - -nsFontXlib* -nsFontMetricsXlib::LocateFont(PRUint32 aChar, PRInt32 & aCount) -{ - nsFontXlib *font; - PRInt32 i; - - // see if one of our loaded fonts can represent the character - for (i = 0; i < aCount; ++i) { - font = (nsFontXlib *)mLoadedFonts[i]; - if (CCMAP_HAS_CHAR(font->mCCMap, aChar)) - return font; - } - - font = FindFont(aChar); - aCount = mLoadedFontsCount; // update since FindFont() can change it - - return font; -} - -nsresult -nsFontMetricsXlib::ResolveForwards(const PRUnichar* aString, - PRUint32 aLength, - nsFontSwitchCallbackXlib aFunc, - void* aData) -{ - NS_ASSERTION(aString || !aLength, "invalid call"); - const PRUnichar* firstChar = aString; - const PRUnichar* currChar = firstChar; - const PRUnichar* lastChar = aString + aLength; - nsFontXlib* currFont; - nsFontXlib* nextFont; - PRInt32 count; - nsFontSwitchXlib fontSwitch; - - if (firstChar == lastChar) - return NS_OK; - - count = mLoadedFontsCount; - - if (NS_IS_HIGH_SURROGATE(*currChar) && (currChar+1) < lastChar && NS_IS_LOW_SURROGATE(*(currChar+1))) { - currFont = LocateFont(SURROGATE_TO_UCS4(*currChar, *(currChar+1)), count); - currChar += 2; - } - else { - currFont = LocateFont(*currChar, count); - ++currChar; - } - - //This if block is meant to speedup the process in normal situation, when - //most characters can be found in first font - if (currFont == mLoadedFonts[0]) { - while (currChar < lastChar && CCMAP_HAS_CHAR(currFont->mCCMap,*currChar)) - ++currChar; - fontSwitch.mFontXlib = currFont; - if (!(*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData)) - return NS_OK; - if (currChar == lastChar) - return NS_OK; - // continue with the next substring, re-using the available loaded fonts - firstChar = currChar; - if (NS_IS_HIGH_SURROGATE(*currChar) && (currChar+1) < lastChar && NS_IS_LOW_SURROGATE(*(currChar+1))) { - currFont = LocateFont(SURROGATE_TO_UCS4(*currChar, *(currChar+1)), count); - currChar += 2; - } - else { - currFont = LocateFont(*currChar, count); - ++currChar; - } - } - - // see if we can keep the same font for adjacent characters - PRInt32 lastCharLen; - while (currChar < lastChar) { - if (NS_IS_HIGH_SURROGATE(*currChar) && (currChar+1) < lastChar && NS_IS_LOW_SURROGATE(*(currChar+1))) { - nextFont = LocateFont(SURROGATE_TO_UCS4(*currChar, *(currChar+1)), count); - lastCharLen = 2; - } - else { - nextFont = LocateFont(*currChar, count); - lastCharLen = 1; - } - if (nextFont != currFont) { - // We have a substring that can be represented with the same font, and - // we are about to switch fonts, it is time to notify our caller. - fontSwitch.mFontXlib = currFont; - if (!(*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData)) - return NS_OK; - // continue with the next substring, re-using the available loaded fonts - firstChar = currChar; - - currFont = nextFont; // use the font found earlier for the char - } - currChar += lastCharLen; - } - - //do it for last part of the string - fontSwitch.mFontXlib = currFont; - (*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData); - return NS_OK; -} - -NS_IMETHODIMP -nsFontMetricsXlib::GetSpaceWidth(nscoord &aSpaceWidth) -{ - aSpaceWidth = mSpaceWidth; - return NS_OK; -} - -/* - * CSS2 "font properties": - * font-family - * font-style - * font-variant - * font-weight - * font-stretch - * font-size - * font-size-adjust - * font - */ - -/* - * CSS2 "font descriptors": - * font-family - * font-style - * font-variant - * font-weight - * font-stretch - * font-size - * unicode-range - * units-per-em - * src - * panose-1 - * stemv - * stemh - * slope - * cap-height - * x-height - * ascent - * descent - * widths - * bbox - * definition-src - * baseline - * centerline - * mathline - * topline - */ - -/* - * XLFD 1.5 "FontName fields": - * FOUNDRY - * FAMILY_NAME - * WEIGHT_NAME - * SLANT - * SETWIDTH_NAME - * ADD_STYLE_NAME - * PIXEL_SIZE - * POINT_SIZE - * RESOLUTION_X - * RESOLUTION_Y - * SPACING - * AVERAGE_WIDTH - * CHARSET_REGISTRY - * CHARSET_ENCODING - * XLFD example: - * -adobe-times-medium-r-normal--17-120-100-100-p-84-iso8859-1 - */ - -/* - * XLFD 1.5 "font properties": - * FOUNDRY - * FAMILY_NAME - * WEIGHT_NAME - * SLANT - * SETWIDTH_NAME - * ADD_STYLE_NAME - * PIXEL_SIZE - * POINT_SIZE - * RESOLUTION_X - * RESOLUTION_Y - * SPACING - * AVERAGE_WIDTH - * CHARSET_REGISTRY - * CHARSET_ENCODING - * MIN_SPACE - * NORM_SPACE - * MAX_SPACE - * END_SPACE - * AVG_CAPITAL_WIDTH - * AVG_LOWERCASE_WIDTH - * QUAD_WIDTH - * FIGURE_WIDTH - * SUPERSCRIPT_X - * SUPERSCRIPT_Y - * SUBSCRIPT_X - * SUBSCRIPT_Y - * SUPERSCRIPT_SIZE - * SUBSCRIPT_SIZE - * SMALL_CAP_SIZE - * UNDERLINE_POSITION - * UNDERLINE_THICKNESS - * STRIKEOUT_ASCENT - * STRIKEOUT_DESCENT - * ITALIC_ANGLE - * CAP_HEIGHT - * X_HEIGHT - * RELATIVE_SETWIDTH - * RELATIVE_WEIGHT - * WEIGHT - * RESOLUTION - * FONT - * FACE_NAME - * FULL_NAME - * COPYRIGHT - * NOTICE - * DESTINATION - * FONT_TYPE - * FONT_VERSION - * RASTERIZER_NAME - * RASTERIZER_VERSION - * RAW_ASCENT - * RAW_DESCENT - * RAW_* - * AXIS_NAMES - * AXIS_LIMITS - * AXIS_TYPES - */ - -/* - * XLFD 1.5 BDF 2.1 properties: - * FONT_ASCENT - * FONT_DESCENT - * DEFAULT_CHAR - */ - -/* - * CSS2 algorithm, in the following order: - * font-family: FAMILY_NAME (and FOUNDRY? (XXX)) - * font-style: SLANT (XXX: XLFD's RI and RO) - * font-variant: implemented in mozilla/layout/html/base/src/nsTextFrame.cpp - * font-weight: RELATIVE_WEIGHT (XXX), WEIGHT (XXX), WEIGHT_NAME - * font-size: XFontStruct.max_bounds.ascent + descent - * - * The following property is not specified in the algorithm spec. It will be - * inserted between the font-weight and font-size steps for now: - * font-stretch: RELATIVE_SETWIDTH (XXX), SETWIDTH_NAME - */ - -/* - * XXX: Things to investigate in the future: - * ADD_STYLE_NAME font-family's serif and sans-serif - * SPACING font-family's monospace; however, there are very few - * proportional fonts in non-Latin-1 charsets, so beware in - * font prefs dialog - * AVERAGE_WIDTH none (see SETWIDTH_NAME) - */ - -static int -SingleByteConvert(nsFontCharSetInfoXlib* aSelf, XFontStruct* aFont, - const PRUnichar* aSrcBuf, PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen) -{ - int count = 0; - if (aSelf->mConverter) { - aSelf->mConverter->Convert(aSrcBuf, &aSrcLen, aDestBuf, &aDestLen); - count = aDestLen; - } - - return count; -} - -/* -static void -ReverseBuffer(char* aBuf, int count) -{ - char *head, *tail, *med; - head = aBuf; - tail = &aBuf[count-1]; - med = &aBuf[count/2]; - - while(head < med) - { - char tmp = *head; - *head++ = *tail; - *tail-- = tmp; - } -} -*/ - -// the following code assume all the PRUnichar is draw in the same -// direction- left to right, without mixing with characters which should -// draw from right to left. This mean it should not be used untill the -// upper level code resolve bi-di and ensure this assumption. otherwise -// it may break non-bidi pages on a system which have hebrew/arabic fonts -/* -static int -SingleByteConvertReverse(nsFontCharSetInfoXlib* aSelf, const PRUnichar* aSrcBuf, - PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen) -{ - int count = SingleByteConvert(aSelf, aSrcBuf, - aSrcLen, aDestBuf, aDestLen); - ReverseBuffer(aDestBuf, count); - return count; -} -*/ - -static int -DoubleByteConvert(nsFontCharSetInfoXlib* aSelf, XFontStruct* aFont, - const PRUnichar* aSrcBuf, PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen) -{ - int count; - if (aSelf->mConverter) { - aSelf->mConverter->Convert(aSrcBuf, &aSrcLen, aDestBuf, &aDestLen); - count = aDestLen; - if (count > 0) { - if ((aDestBuf[0] & 0x80) && (!(aFont->max_byte1 & 0x80))) { - for (PRInt32 i = 0; i < aDestLen; i++) - aDestBuf[i] &= 0x7F; - } - // We're using a GL encoder (KSC5601 or GB2312) for a GR font - // (ksc5601.1987-1 or gb2312.1980-1) - else if ((!(aDestBuf[0] & 0x80)) && (aFont->min_byte1 & 0x80)) { - for (PRInt32 i = 0; i < aDestLen; i++) - aDestBuf[i] |= 0x80; - } - } - } - else { - count = 0; - } - - return count; -} - -static int -ISO10646Convert(nsFontCharSetInfoXlib* aSelf, XFontStruct* aFont, - const PRUnichar* aSrcBuf, PRInt32 aSrcLen, char* aDestBuf, PRInt32 aDestLen) -{ - aDestLen /= 2; - if (aSrcLen > aDestLen) { - aSrcLen = aDestLen; - } - if (aSrcLen < 0) { - aSrcLen = 0; - } - XChar2b* dest = (XChar2b*) aDestBuf; - for (PRInt32 i = 0; i < aSrcLen; i++) { - dest[i].byte1 = (aSrcBuf[i] >> 8); - dest[i].byte2 = (aSrcBuf[i] & 0xFF); - } - - return (int) aSrcLen * 2; -} - -#ifdef DEBUG - -static void -CheckMap(nsFontMetricsXlibContext *aFmctx, const nsFontCharSetMapXlib* aEntry) -{ - while (aEntry->mName) { - if (aEntry->mInfo->mCharSet) { - - nsresult res; - // used to use NS_NewAtom?? - nsCOMPtr converter; - res = aFmctx->mCharSetManager->GetUnicodeEncoderRaw(aEntry->mInfo->mCharSet, - getter_AddRefs(converter)); - if (NS_FAILED(res)) { - printf("=== %s failed (%s)\n", aEntry->mInfo->mCharSet, __FILE__); - } - } - aEntry++; - } -} - -static void -CheckSelf(nsFontMetricsXlibContext *aFmctx) -{ - CheckMap(aFmctx, aFmctx->mCharSetMap); - -#ifdef MOZ_MATHML - // For this to pass, the ucvmath module must be built as well - CheckMap(aFmctx, aFmctx->mSpecialCharSetMap); -#endif /* MOZ_MATHML */ -} - -#endif /* DEBUG */ - -static PRBool -SetUpFontCharSetInfo(nsFontMetricsXlibContext *aFmctx, nsFontCharSetInfoXlib* aSelf) -{ -#ifdef DEBUG - static PRBool checkedSelf = PR_FALSE; - if (!checkedSelf) { - CheckSelf(aFmctx); - checkedSelf = PR_TRUE; - } -#endif /* DEBUG */ - - nsresult res; - - nsIUnicodeEncoder* converter = nsnull; - res = aFmctx->mCharSetManager->GetUnicodeEncoderRaw(aSelf->mCharSet, &converter); - if (NS_SUCCEEDED(res)) { - aSelf->mConverter = converter; - res = converter->SetOutputErrorBehavior(converter->kOnError_Replace, - nsnull, '?'); - nsCOMPtr mapper = do_QueryInterface(converter); - if (mapper) { - aSelf->mCCMap = MapperToCCMap(mapper); - if (aSelf->mCCMap) { -#ifdef DEBUG - NS_WARNING(nsPrintfCString(256, "SetUpFontCharSetInfo: charset = '%s'", aSelf->mCharSet).get()); -#endif /* DEBUG */ - - /* - * We used to disable special characters like smart quotes - * in CJK fonts because if they are quite a bit larger than - * western glyphs and we did not want glyph fill-in to use them - * in single byte documents. - * - * Now, single byte documents find these special chars before - * the CJK fonts are searched so this is no longer needed - * but is useful when trying to determine which font(s) the - * special chars are found in. - */ - if ((aSelf->Convert == DoubleByteConvert) - && (!aFmctx->mAllowDoubleByteSpecialChars)) { - PRUint16* ccmap = aSelf->mCCMap; - PRUint32 page = CCMAP_BEGIN_AT_START_OF_MAP; - const PRUint16* specialmap = aFmctx->mDoubleByteSpecialCharsCCMap; - while (NextNonEmptyCCMapPage(specialmap, &page)) { - PRUint32 pagechar = page; - for (int i=0; i < CCMAP_BITS_PER_PAGE; i++) { - if (CCMAP_HAS_CHAR(specialmap, pagechar)) - CCMAP_UNSET_CHAR(ccmap, pagechar); - pagechar++; - } - } - } - return PR_TRUE; - } - } - else { - NS_WARNING("cannot get nsICharRepresentable"); - } - } - else { - NS_WARNING("cannot get Unicode converter"); - } - - // - // always try to return a map even if it is empty - // - nsCompressedCharMap empty_ccmapObj; - aSelf->mCCMap = empty_ccmapObj.NewCCMap(); - - // return false if unable to alloc a map - if (aSelf->mCCMap == nsnull) - return PR_FALSE; - - return PR_TRUE; -} - -#undef DEBUG_DUMP_TREE -#ifdef DEBUG_DUMP_TREE - -static char* gDumpStyles[3] = { "normal", "italic", "oblique" }; - -static PRIntn -DumpCharSet(PLHashEntry* he, PRIntn i, void* arg) -{ - printf(" %s\n", (char*) he->key); - nsFontCharSetXlib* charSet = (nsFontCharSetXlib*) he->value; - for (int sizeIndex = 0; sizeIndex < charSet->mSizesCount; sizeIndex++) { - nsFontXlib* size = &charSet->mSizes[sizeIndex]; - printf(" %d %s\n", size->mSize, size->mName); - } - return HT_ENUMERATE_NEXT; -} - -static void -DumpFamily(nsFontFamilyXlib* aFamily) -{ - for (int styleIndex = 0; styleIndex < 3; styleIndex++) { - nsFontStyleXlib* style = aFamily->mStyles[styleIndex]; - if (style) { - printf(" style: %s\n", gDumpStyles[styleIndex]); - for (int weightIndex = 0; weightIndex < 8; weightIndex++) { - nsFontWeightXlib* weight = style->mWeights[weightIndex]; - if (weight) { - printf(" weight: %d\n", (weightIndex + 1) * 100); - for (int stretchIndex = 0; stretchIndex < 9; stretchIndex++) { - nsFontStretchXlib* stretch = weight->mStretches[stretchIndex]; - if (stretch) { - printf(" stretch: %d\n", stretchIndex + 1); - PL_HashTableEnumerateEntries(stretch->mCharSets, DumpCharSet, - nsnull); - } - } - } - } - } - } -} - -// this existing debug code was broken and I have partly fixed it -static PRBool -DumpFamilyEnum(nsHashKey* hashKey, void *aData, void* closure) -{ - printf("family: %s\n", - NS_LossyConvertUTF16toASCII(*NS_STATIC_CAST(nsString*,he->key))); - nsFontFamilyXlib* family = (nsFontFamilyXlib*) he->value; - DumpFamily(family); - - return HT_ENUMERATE_NEXT; -} - -static void -DumpTree(void) -{ - aFmctx->mFamilies.Enumerate(DumpFamilyEnum, nsnull); -} -#endif /* DEBUG_DUMP_TREE */ - -struct nsFontSearch -{ - nsFontMetricsXlib *mMetrics; - PRUnichar mChar; - nsFontXlib *mFont; -}; - -#if 0 -static void -GetUnderlineInfo(nsXFont* aFont, unsigned long* aPositionX2, - unsigned long* aThickness) -{ - /* - * XLFD 1.5 says underline position defaults descent/2. - * Hence we return position*2 to avoid rounding error. - */ - if (aFont->GetXFontProperty(XA_UNDERLINE_POSITION, aPositionX2)) { - *aPositionX2 *= 2; - } - else { - *aPositionX2 = aFont->max_bounds.descent; - } - - /* - * XLFD 1.5 says underline thickness defaults to cap stem width. - * We don't know what that is, so we just take the thickness of "_". - * This way, we get thicker underlines for bold fonts. - */ - if (!xFont->GetXFontProperty(XA_UNDERLINE_THICKNESS, aThickness)) { - int dir, ascent, descent; - XCharStruct overall; - XTextExtents(aFont, "_", 1, &dir, &ascent, &descent, &overall); - *aThickness = (overall.ascent + overall.descent); - } -} -#endif /* 0 */ - -static PRUint16* -GetMapFor10646Font(XFontStruct* aFont) -{ - if (!aFont->per_char) - return nsnull; - - nsCompressedCharMap ccmapObj; - PRInt32 minByte1 = aFont->min_byte1; - PRInt32 maxByte1 = aFont->max_byte1; - PRInt32 minByte2 = aFont->min_char_or_byte2; - PRInt32 maxByte2 = aFont->max_char_or_byte2; - PRInt32 charsPerRow = maxByte2 - minByte2 + 1; - for (PRInt32 row = minByte1; row <= maxByte1; row++) { - PRInt32 offset = (((row - minByte1) * charsPerRow) - minByte2); - for (PRInt32 cell = minByte2; cell <= maxByte2; cell++) { - XCharStruct* bounds = &aFont->per_char[offset + cell]; - // From Section 8.5 Font Metrics in the Xlib programming manual: - // A nonexistent character is represented with all members of its XCharStruct set to zero. - if (bounds->ascent || - bounds->descent || - bounds->lbearing || - bounds->rbearing || - bounds->width || - bounds->attributes) { - ccmapObj.SetChar((row << 8) | cell); - } - } - } - PRUint16 *ccmap = ccmapObj.NewCCMap(); - return ccmap; -} - -PRBool -nsFontXlib::IsEmptyFont(XFontStruct* xFont) -{ - if (!xFont) - return PR_TRUE; - - // - // scan and see if we can find at least one glyph - // - if (xFont->per_char) { - PRInt32 minByte1 = xFont->min_byte1; - PRInt32 maxByte1 = xFont->max_byte1; - PRInt32 minByte2 = xFont->min_char_or_byte2; - PRInt32 maxByte2 = xFont->max_char_or_byte2; - PRInt32 charsPerRow = maxByte2 - minByte2 + 1; - for (PRInt32 row = minByte1; row <= maxByte1; row++) { - PRInt32 offset = (((row - minByte1) * charsPerRow) - minByte2); - for (PRInt32 cell = minByte2; cell <= maxByte2; cell++) { - XCharStruct* bounds = &xFont->per_char[offset + cell]; - if (bounds->ascent || bounds->descent) { - return PR_FALSE; - } - } - } - } - - return PR_TRUE; -} - -void -nsFontXlib::LoadFont(void) -{ - if (mAlreadyCalledLoadFont) - return; - - Display *aDisplay = xxlib_rgb_get_display(mFontMetricsContext->mXlibRgbHandle); - -#ifdef USE_XPRINT - if (mFontMetricsContext->mPrinterMode) - { - if (XpGetContext(aDisplay) == None) - { - /* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */ - NS_ERROR("Obtaining font information without a valid print context (XLoadQueryFont()) _before_ XpSetContext()\n"); -#ifdef DEBUG - abort(); -#else - return; -#endif /* DEBUG */ - } - } -#endif /* USE_XPRINT */ - - mAlreadyCalledLoadFont = PR_TRUE; - - XFontStruct *xlibFont = nsnull; - - NS_ASSERTION(!mFont, "mFont should not be loaded"); -#ifdef USE_AASB - if (mAABaseSize==0) -#endif /* USE_AASB */ - { - NS_ASSERTION(!mFontHolder, "mFontHolder should not be loaded"); - xlibFont = ::XLoadQueryFont(aDisplay, mName); - if(!xlibFont) - { -#ifdef DEBUG - printf("nsFontXlib::LoadFont(): loading of font '%s' failed\n", mName); -#endif /* DEBUG */ - return; - } - - mXFont = new nsXFontNormal(aDisplay, xlibFont); - } -#ifdef USE_AASB - else { - NS_ASSERTION(mFontHolder, "mFontHolder should be loaded"); - xlibFont = mFontHolder; - mXFont = new nsXFontAAScaledBitmap(xxlib_rgb_get_display(mFontMetricsContext->mXlibRgbHandle), - xxlib_rgb_get_screen(mFontMetricsContext->mXlibRgbHandle), - xlibFont, mSize, mAABaseSize); - } -#endif /* USE_AASB */ - - NS_ASSERTION(mXFont,"failed to load mXFont"); - if (!mXFont) - return; - if (!mXFont->LoadFont()) { - delete mXFont; - mXFont = nsnull; - return; - } - - if (xlibFont) { - XFontStruct* xFont = mXFont->GetXFontStruct(); - XFontStruct* xFont_with_per_char; -#ifdef USE_AASB - if (mAABaseSize==0) -#endif /* USE_AASB */ - xFont_with_per_char = xFont; -#ifdef USE_AASB - else - xFont_with_per_char = mFontHolder; -#endif /* #ifdef USE_AASB */ - - mMaxAscent = xFont->ascent; - mMaxDescent = xFont->descent; - - if (mCharSetInfo == mFontMetricsContext->mISO106461) { - mCCMap = GetMapFor10646Font(xFont_with_per_char); - if (!mCCMap) { - mXFont->UnloadFont(); - mXFont = nsnull; - ::XFreeFont(aDisplay, xlibFont); - mFontHolder = nsnull; - return; - } - } - - // Redhat 6.2 Japanese has invalid jisx201 fonts - // Solaris 2.6 has invalid cns11643 fonts for planes 4-7 - if ((mCharSetInfo == &JISX0201) - || (mCharSetInfo == &CNS116434) - || (mCharSetInfo == &CNS116435) - || (mCharSetInfo == &CNS116436) - || (mCharSetInfo == &CNS116437) - ) { - if (IsEmptyFont(xFont_with_per_char)) { -#ifdef NS_FONT_DEBUG_LOAD_FONT - if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) { - printf("\n"); - printf("***************************************\n"); - printf("invalid font \"%s\", %s %d\n", mName, __FILE__, __LINE__); - printf("***************************************\n"); - printf("\n"); - } -#endif - mXFont->UnloadFont(); - mXFont = nsnull; - ::XFreeFont(aDisplay, xlibFont); - mFontHolder = nsnull; - return; - } - } - mFont = xlibFont; - -#ifdef NS_FONT_DEBUG_LOAD_FONT - if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) { - printf("loaded %s\n", mName); - } -#endif - - } - -#ifdef NS_FONT_DEBUG_LOAD_FONT - else if (gFontDebug & NS_FONT_DEBUG_LOAD_FONT) { - printf("cannot load %s\n", mName); - } -#endif - -} - -XFontStruct * -nsFontXlib::GetXFontStruct(void) -{ - return mFont; -} - -nsXFont* -nsFontXlib::GetXFont(void) -{ - return mXFont; -} - -PRBool -nsFontXlib::GetXFontIs10646(void) -{ - return ((PRBool) (mCharSetInfo == mFontMetricsContext->mISO106461)); -} - -#ifdef MOZ_ENABLE_FREETYPE2 -PRBool -nsFontXlib::IsFreeTypeFont(void) -{ - return PR_FALSE; -} -#endif /* MOZ_ENABLE_FREETYPE2 */ - -nsFontXlib::nsFontXlib() -{ - MOZ_COUNT_CTOR(nsFontXlib); -} - -nsFontXlib::~nsFontXlib() -{ - MOZ_COUNT_DTOR(nsFontXlib); - if (mXFont) { - delete mXFont; - } - if (mFont -#ifdef USE_AASB - && (mAABaseSize==0) -#endif /* USE_AASB */ - ) { - XFreeFont(xxlib_rgb_get_display(mFontMetricsContext->mXlibRgbHandle), mFont); - } - if (mCharSetInfo == mFontMetricsContext->mISO106461) { - FreeCCMap(mCCMap); - } - if (mName) { - PR_smprintf_free(mName); - } -} - -class nsFontXlibNormal : public nsFontXlib -{ -public: - nsFontXlibNormal(nsFontMetricsXlibContext *aFontMetricsContext); - nsFontXlibNormal(nsFontXlib*); - virtual ~nsFontXlibNormal(); - - virtual int GetWidth(const PRUnichar* aString, PRUint32 aLength); - virtual int DrawString(nsRenderingContextXlib* aContext, - nsIDrawingSurfaceXlib* aSurface, nscoord aX, - nscoord aY, const PRUnichar* aString, - PRUint32 aLength); -#ifdef MOZ_MATHML - virtual nsresult GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics); -#endif /* MOZ_MATHML */ -}; - -nsFontXlibNormal::nsFontXlibNormal(nsFontMetricsXlibContext *aFontMetricsContext) -{ - mFontHolder = nsnull; - mFontMetricsContext = aFontMetricsContext; -} - -nsFontXlibNormal::nsFontXlibNormal(nsFontXlib *aFont) -{ - mFontMetricsContext = aFont->mFontMetricsContext; - -#ifdef USE_AASB - mAABaseSize = aFont->mSize; -#endif /* USE_AASB */ - mFontHolder = aFont->GetXFontStruct(); - if (!mFontHolder) { - aFont->LoadFont(); - mFontHolder = aFont->GetXFontStruct(); - } - NS_ASSERTION(mFontHolder, "font to copy not loaded"); -} - -nsFontXlibNormal::~nsFontXlibNormal() -{ -} - -int -nsFontXlibNormal::GetWidth(const PRUnichar* aString, PRUint32 aLength) -{ - if (!mFont) { - LoadFont(); - if (!mFont) { - return 0; - } - } - - XChar2b buf[512]; - char *p; - PRInt32 bufLen; - ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mCharSetInfo->mConverter, - aString, aLength, buf, sizeof(buf), bufLen); - int len = mCharSetInfo->Convert(mCharSetInfo, mXFont->GetXFontStruct(), - aString, aLength, p, bufLen); - int outWidth; - if (mXFont->IsSingleByte()) - outWidth = mXFont->TextWidth8(p, len); - else - outWidth = mXFont->TextWidth16((const XChar2b*)p, len/2); - ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); - return outWidth; -} - -int -nsFontXlibNormal::DrawString(nsRenderingContextXlib* aContext, - nsIDrawingSurfaceXlib* aSurface, - nscoord aX, nscoord aY, - const PRUnichar* aString, PRUint32 aLength) -{ - if (!mFont) { - LoadFont(); - if (!mFont) { - return 0; - } - } - - XChar2b buf[512]; - char *p; - PRInt32 bufLen; - ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mCharSetInfo->mConverter, - aString, aLength, buf, sizeof(buf), bufLen); - int len = mCharSetInfo->Convert(mCharSetInfo, mXFont->GetXFontStruct(), - aString, aLength, p, bufLen); - xGC *gc = aContext->GetGC(); - int outWidth; - if (mXFont->IsSingleByte()) { - mXFont->DrawText8(aSurface->GetDrawable(), *gc, aX, - aY + mBaselineAdjust, p, len); - outWidth = mXFont->TextWidth8(p, len); - } - else { - mXFont->DrawText16(aSurface->GetDrawable(), *gc, aX, aY + mBaselineAdjust, - (const XChar2b*)p, len/2); - outWidth = mXFont->TextWidth16((const XChar2b*)p, len/2); - } - gc->Release(); - ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); - return outWidth; -} - -#ifdef MOZ_MATHML -// bounding metrics for a string -// remember returned values are not in app units -nsresult -nsFontXlibNormal::GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics) -{ - aBoundingMetrics.Clear(); - - if (!mFont) { - LoadFont(); - if (!mFont) { - return NS_ERROR_FAILURE; - } - } - - if (aString && 0 < aLength) { - XFontStruct *fontInfo = mXFont->GetXFontStruct(); - XChar2b buf[512]; - char *p; - PRInt32 bufLen; - ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mCharSetInfo->mConverter, - aString, aLength, buf, sizeof(buf), bufLen); - int len = mCharSetInfo->Convert(mCharSetInfo, fontInfo, aString, aLength, - p, bufLen); - if (mXFont->IsSingleByte()) { - mXFont->TextExtents8(p, len, - &aBoundingMetrics.leftBearing, - &aBoundingMetrics.rightBearing, - &aBoundingMetrics.width, - &aBoundingMetrics.ascent, - &aBoundingMetrics.descent); - } - else { - mXFont->TextExtents16((const XChar2b*)p, len, - &aBoundingMetrics.leftBearing, - &aBoundingMetrics.rightBearing, - &aBoundingMetrics.width, - &aBoundingMetrics.ascent, - &aBoundingMetrics.descent); - } - ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); - } - - return NS_OK; -} -#endif /* MOZ_MATHML */ - -class nsFontXlibSubstitute : public nsFontXlib -{ -public: - nsFontXlibSubstitute(nsFontXlib* aFont); - virtual ~nsFontXlibSubstitute(); - - virtual XFontStruct *GetXFontStruct(void); - virtual nsXFont *GetXFont(void); - virtual PRBool GetXFontIs10646(void); - virtual int GetWidth(const PRUnichar* aString, PRUint32 aLength); - virtual int DrawString(nsRenderingContextXlib* aContext, - nsIDrawingSurfaceXlib* aSurface, nscoord aX, - nscoord aY, const PRUnichar* aString, - PRUint32 aLength); -#ifdef MOZ_MATHML - virtual nsresult GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics); -#endif /* MOZ_MATHML */ - virtual PRUint32 Convert(const PRUnichar* aSrc, PRUint32 aSrcLen, - PRUnichar* aDest, PRUint32 aDestLen); - - nsFontXlib* mSubstituteFont; -}; - -nsFontXlibSubstitute::nsFontXlibSubstitute(nsFontXlib* aFont) -{ - mSubstituteFont = aFont; - mFontMetricsContext = aFont->mFontMetricsContext; -} - -nsFontXlibSubstitute::~nsFontXlibSubstitute() -{ - // Do not free mSubstituteFont here. It is owned by somebody else. -} - -PRUint32 -nsFontXlibSubstitute::Convert(const PRUnichar* aSrc, PRUint32 aSrcLen, - PRUnichar* aDest, PRUint32 aDestLen) -{ - nsresult res; - if (!mFontMetricsContext->mFontSubConverter) { - mFontMetricsContext->mFontSubConverter = do_CreateInstance(NS_SAVEASCHARSET_CONTRACTID); - if (mFontMetricsContext->mFontSubConverter) { - res = mFontMetricsContext->mFontSubConverter->Init("ISO-8859-1", - nsISaveAsCharset::attr_FallbackQuestionMark + - nsISaveAsCharset::attr_EntityAfterCharsetConv + - nsISaveAsCharset::attr_IgnoreIgnorables, - nsIEntityConverter::transliterate); - if (NS_FAILED(res)) - mFontMetricsContext->mFontSubConverter = nsnull; // destroy converter - } - } - - if (mFontMetricsContext->mFontSubConverter) { - nsAutoString tmp(aSrc, aSrcLen); - char* conv = nsnull; - - /* timecop revisit with nsXPIDLCString */ - res = mFontMetricsContext->mFontSubConverter->Convert(tmp.get(), &conv); - if (NS_SUCCEEDED(res) && conv) { - char *p = conv; - PRUint32 i; - for (i = 0; i < aDestLen; i++) { - if (*p) { - aDest[i] = *p; - } - else { - break; - } - p++; - } - nsMemory::Free(conv); - conv = nsnull; - return i; - } - } - - if (aSrcLen > aDestLen) { - aSrcLen = aDestLen; - } - for (PRUint32 i = 0; i < aSrcLen; i++) - aDest[i] = '?'; - - return aSrcLen; -} - -int -nsFontXlibSubstitute::GetWidth(const PRUnichar* aString, PRUint32 aLength) -{ - PRUnichar buf[512]; - PRUnichar *p = buf; - PRUint32 bufLen = sizeof(buf)/sizeof(PRUnichar); - if ((aLength*2) > bufLen) { - PRUnichar *tmp; - tmp = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * (aLength*2)); - if (tmp) { - p = tmp; - bufLen = (aLength*2); - } - } - PRUint32 len = Convert(aString, aLength, p, bufLen); - int outWidth = mSubstituteFont->GetWidth(p, len); - if (p != buf) - nsMemory::Free(p); - return outWidth; - -} - -int -nsFontXlibSubstitute::DrawString(nsRenderingContextXlib* aContext, - nsIDrawingSurfaceXlib* aSurface, - nscoord aX, nscoord aY, - const PRUnichar* aString, PRUint32 aLength) -{ - PRUnichar buf[512]; - PRUnichar *p = buf; - PRUint32 bufLen = sizeof(buf)/sizeof(PRUnichar); - if ((aLength*2) > bufLen) { - PRUnichar *tmp; - tmp = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * (aLength*2)); - if (tmp) { - p = tmp; - bufLen = (aLength*2); - } - } - PRUint32 len = Convert(aString, aLength, p, bufLen); - int outWidth = mSubstituteFont->DrawString(aContext, aSurface, - aX, aY, p, len); - if (p != buf) - nsMemory::Free(p); - return outWidth; -} - -#ifdef MOZ_MATHML -// bounding metrics for a string -// remember returned values are not in app units -nsresult -nsFontXlibSubstitute::GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics) -{ - PRUnichar buf[512]; - PRUnichar *p = buf; - PRUint32 bufLen = sizeof(buf)/sizeof(PRUnichar); - if ((aLength*2) > bufLen) { - PRUnichar *tmp; - tmp = (PRUnichar*)nsMemory::Alloc(sizeof(PRUnichar) * (aLength*2)); - if (tmp) { - p = tmp; - bufLen = (aLength*2); - } - } - PRUint32 len = Convert(aString, aLength, p, bufLen); - nsresult res = mSubstituteFont->GetBoundingMetrics(p, len, - aBoundingMetrics); - if (p != buf) - nsMemory::Free(p); - return res; -} -#endif /* MOZ_MATHML */ - -XFontStruct * -nsFontXlibSubstitute::GetXFontStruct(void) -{ - return mSubstituteFont->GetXFontStruct(); -} - -nsXFont* -nsFontXlibSubstitute::GetXFont(void) -{ - return mSubstituteFont->GetXFont(); -} - -PRBool -nsFontXlibSubstitute::GetXFontIs10646(void) -{ - return mSubstituteFont->GetXFontIs10646(); -} - -class nsFontXlibUserDefined : public nsFontXlib -{ -public: - nsFontXlibUserDefined(nsFontMetricsXlibContext *aFontMetricsContext); - virtual ~nsFontXlibUserDefined(); - - virtual PRBool Init(nsFontXlib* aFont); - virtual int GetWidth(const PRUnichar* aString, PRUint32 aLength); - virtual int DrawString(nsRenderingContextXlib* aContext, - nsIDrawingSurfaceXlib* aSurface, nscoord aX, - nscoord aY, const PRUnichar* aString, - PRUint32 aLength); -#ifdef MOZ_MATHML - virtual nsresult GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics); -#endif /* MOZ_MATHML */ - virtual PRUint32 Convert(const PRUnichar* aSrc, PRInt32 aSrcLen, - char* aDest, PRInt32 aDestLen); -}; - -nsFontXlibUserDefined::nsFontXlibUserDefined(nsFontMetricsXlibContext *aFontMetricsContext) -{ - mFontMetricsContext = aFontMetricsContext; -} - -nsFontXlibUserDefined::~nsFontXlibUserDefined() -{ - // Do not free mFont here. It is owned by somebody else. -} - -PRBool -nsFontXlibUserDefined::Init(nsFontXlib* aFont) -{ - if (!aFont->GetXFont()) { - aFont->LoadFont(); - if (!aFont->GetXFont()) { - mCCMap = mFontMetricsContext->mEmptyCCMap; - return PR_FALSE; - } - } - mXFont = aFont->GetXFont(); - mCCMap = mFontMetricsContext->mUserDefinedCCMap; - mName = aFont->mName; - - return PR_TRUE; -} - -PRUint32 -nsFontXlibUserDefined::Convert(const PRUnichar* aSrc, PRInt32 aSrcLen, - char* aDest, PRInt32 aDestLen) -{ - if (aSrcLen > aDestLen) { - aSrcLen = aDestLen; - } - mFontMetricsContext->mUserDefinedConverter->Convert(aSrc, &aSrcLen, aDest, &aDestLen); - - return aSrcLen; -} - -int -nsFontXlibUserDefined::GetWidth(const PRUnichar* aString, PRUint32 aLength) -{ - char buf[1024]; - char *p; - PRInt32 bufLen; - ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mFontMetricsContext->mUserDefinedConverter, - aString, aLength, buf, sizeof(buf), bufLen); - PRUint32 len = Convert(aString, aLength, p, bufLen); - - int outWidth; - if (mXFont->IsSingleByte()) - outWidth = mXFont->TextWidth8(p, len); - else - outWidth = mXFont->TextWidth16((const XChar2b*)p, len/2); - ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); - return outWidth; -} - -int -nsFontXlibUserDefined::DrawString(nsRenderingContextXlib* aContext, - nsIDrawingSurfaceXlib* aSurface, - nscoord aX, nscoord aY, - const PRUnichar* aString, PRUint32 aLength) -{ - char buf[1024]; - char *p; - PRInt32 bufLen; - ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mFontMetricsContext->mUserDefinedConverter, - aString, aLength, buf, sizeof(buf), bufLen); - PRUint32 len = Convert(aString, aLength, p, bufLen); - xGC *gc = aContext->GetGC(); - - int outWidth; - if (mXFont->IsSingleByte()) { - mXFont->DrawText8(aSurface->GetDrawable(), *gc, aX, - aY + mBaselineAdjust, p, len); - outWidth = mXFont->TextWidth8(p, len); - } - else { - mXFont->DrawText16(aSurface->GetDrawable(), *gc, aX, aY + mBaselineAdjust, - (const XChar2b*)p, len); - outWidth = mXFont->TextWidth16((const XChar2b*)p, len/2); - } - gc->Release(); - ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); - return outWidth; -} - -#ifdef MOZ_MATHML -// bounding metrics for a string -// remember returned values are not in app units -nsresult -nsFontXlibUserDefined::GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics) -{ - aBoundingMetrics.Clear(); - - if (aString && 0 < aLength) { - char buf[1024]; - char *p; - PRInt32 bufLen; - ENCODER_BUFFER_ALLOC_IF_NEEDED(p, mFontMetricsContext->mUserDefinedConverter, - aString, aLength, buf, sizeof(buf), bufLen); - PRUint32 len = Convert(aString, aLength, p, bufLen); - if (mXFont->IsSingleByte()) { - mXFont->TextExtents8(p, len, - &aBoundingMetrics.leftBearing, - &aBoundingMetrics.rightBearing, - &aBoundingMetrics.width, - &aBoundingMetrics.ascent, - &aBoundingMetrics.descent); - } - else { - mXFont->TextExtents16((const XChar2b*)p, len, - &aBoundingMetrics.leftBearing, - &aBoundingMetrics.rightBearing, - &aBoundingMetrics.width, - &aBoundingMetrics.ascent, - &aBoundingMetrics.descent); - } - ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); - } - - return NS_OK; -} -#endif /* MOZ_MATHML */ - -nsFontXlib* -nsFontMetricsXlib::AddToLoadedFontsList(nsFontXlib* aFont) -{ - if (mLoadedFontsCount == mLoadedFontsAlloc) { - int newSize; - if (mLoadedFontsAlloc) { - newSize = (2 * mLoadedFontsAlloc); - } - else { - newSize = 1; - } - nsFontXlib** newPointer = (nsFontXlib**) - PR_Realloc(mLoadedFonts, newSize * sizeof(nsFontXlib*)); - if (newPointer) { - mLoadedFonts = newPointer; - mLoadedFontsAlloc = newSize; - } - else { - return nsnull; - } - } - mLoadedFonts[mLoadedFontsCount++] = aFont; - return aFont; -} - -// define a size such that a scaled font would always be closer -// to the desired size than this -#define NOT_FOUND_FONT_SIZE 1000*1000*1000 - -nsFontXlib* -nsFontMetricsXlib::FindNearestSize(nsFontStretchXlib* aStretch, PRUint16 aSize) -{ - nsFontXlib* font = nsnull; - if (aStretch->mSizes) { - nsFontXlib** begin = aStretch->mSizes; - nsFontXlib** end = &aStretch->mSizes[aStretch->mSizesCount]; - nsFontXlib** s; - // scan the list of sizes - for (s = begin; s < end; s++) { - // stop when we hit or overshoot the size - if ((*s)->mSize >= aSize) { - break; - } - } - // backup if we hit the end of the list - if (s == end) { - s--; - } - else if (s != begin) { - // if we overshot pick the closest size - if (((*s)->mSize - aSize) >= (aSize - (*(s - 1))->mSize)) { - s--; - } - } - // this is the nearest bitmap font - font = *s; - } - return font; -} - -static PRBool -SetFontCharsetInfo(nsFontXlib *aFont, nsFontCharSetInfoXlib* aCharSet, - PRUnichar aChar) -{ - if (aCharSet->mCharSet) { - aFont->mCCMap = aCharSet->mCCMap; - // check that the font is not empty - if (CCMAP_HAS_CHAR(aFont->mCCMap, aChar)) { - aFont->LoadFont(); - if (!aFont->GetXFont()) { - return PR_FALSE; - } - } - } - else { - if (aCharSet == aFont->mFontMetricsContext->mISO106461) { - aFont->LoadFont(); - if (!aFont->GetXFont()) { - return PR_FALSE; - } - } - } - return PR_TRUE; -} - -static nsFontXlib* -SetupUserDefinedFont(nsFontMetricsXlibContext *aFmctx, nsFontXlib *aFont) -{ - if (!aFont->mUserDefinedFont) { - aFont->mUserDefinedFont = new nsFontXlibUserDefined(aFmctx); - if (!aFont->mUserDefinedFont) { - return nsnull; - } - if (!aFont->mUserDefinedFont->Init(aFont)) { - return nsnull; - } - } - return aFont->mUserDefinedFont; -} - - -#ifdef USE_AASB -nsFontXlib* -nsFontMetricsXlib::GetAASBBaseFont(nsFontStretchXlib* aStretch, - nsFontCharSetInfoXlib* aCharSet) -{ - nsFontXlib* base_aafont; - PRInt32 scale_size; - PRUint32 aa_target_size; - - scale_size = PR_MAX(mPixelSize, aCharSet->mAABitmapScaleMin); - aa_target_size = PR_MAX((scale_size*2), 16); - base_aafont = FindNearestSize(aStretch, aa_target_size); - NS_ASSERTION(base_aafont, - "failed to find a base font for Anti-Aliased bitmap Scaling"); - return base_aafont; -} -#endif /* USE_AASB */ - -nsFontXlib* -nsFontMetricsXlib::PickASizeAndLoad(nsFontStretchXlib* aStretch, - nsFontCharSetInfoXlib* aCharSet, PRUnichar aChar, const char *aName) -{ -#ifdef MOZ_ENABLE_FREETYPE2 - if (aStretch->mFreeTypeFaceID) { - //FREETYPE_FONT_PRINTF(("mFreeTypeFaceID = 0x%p", aStretch->mFreeTypeFaceID)); - nsFreeTypeFont *ftfont = nsFreeTypeFont::NewFont(aStretch->mFreeTypeFaceID, - mPixelSize, - aName); - if (!ftfont) { - FREETYPE_FONT_PRINTF(("failed to create font")); - return nsnull; - } - //FREETYPE_FONT_PRINTF(("created ftfont")); - /* - * XXX Instead of passing pixel size, we ought to take underline - * into account. (Extra space for underline for Asian fonts.) - */ - ftfont->mName = PR_smprintf("%s", aName); - if (!ftfont->mName) { - FREETYPE_FONT_PRINTF(("failed to create mName")); - delete ftfont; - return nsnull; - } - SetCharsetLangGroup(mFontMetricsContext, aCharSet); - ftfont->mSize = mPixelSize; - ftfont->LoadFont(); - ftfont->mCharSetInfo = mFontMetricsContext->mISO106461; - //FREETYPE_FONT_PRINTF(("add the ftfont")); - return AddToLoadedFontsList(ftfont); - } -#endif /* MOZ_ENABLE_FREETYPE2 */ - - PRBool use_scaled_font = PR_FALSE; - PRBool have_nearly_rightsized_bitmap = PR_FALSE; -#ifdef USE_AASB - nsFontXlib *base_aafont = nsnull; -#endif /* USE_AASB */ - -#ifdef USE_XPRINT -#define ALWAYS_USE_SCALED_FONTS_FOR_XPRINT 1 -#endif /* USE_XPRINT */ - -#ifdef ALWAYS_USE_SCALED_FONTS_FOR_XPRINT -/* gisburn: Small hack for Xprint: - * Xprint usually operates at resolutions >= 300DPI. There are - * usually no "normal" bitmap fonts at those resolutions - only - * "scalable outline fonts" and "built-in printer fonts" (which - * usually look like scalable bitmap fonts) are available. - * Therefore: force use of scalable fonts to get rid of - * manually scaled bitmap fonts... - */ - if (mFontMetricsContext->mPrinterMode) - { - use_scaled_font = PR_TRUE; - } -#endif /* ALWAYS_USE_SCALED_FONTS_FOR_XPRINT */ - - PRInt32 bitmap_size = NOT_FOUND_FONT_SIZE; - PRInt32 scale_size = mPixelSize; - nsFontXlib* font = FindNearestSize(aStretch, mPixelSize); - if (font) { - bitmap_size = font->mSize; - if ( (bitmap_size >= mPixelSize-(mPixelSize/10)) - && (bitmap_size <= mPixelSize+(mPixelSize/10))) - // When the size of a hand tuned font is close to the desired size - // favor it over outline scaled font - have_nearly_rightsized_bitmap = PR_TRUE; - } - -#ifdef USE_AASB - // - // If the user says always try to aasb (anti alias scaled bitmap) scale - // - if (mFontMetricsContext->mAABitmapScaleEnabled && aCharSet->mAABitmapScaleAlways) { - base_aafont = GetAASBBaseFont(aStretch, aCharSet); - if (base_aafont) { - use_scaled_font = PR_TRUE; - SIZE_FONT_PRINTF(("anti-aliased bitmap scaled font: %s\n" - " desired=%d, aa-scaled=%d, bitmap=%d, " - "aa_bitmap=%d", - aName, mPixelSize, scale_size, bitmap_size, base_aafont->mSize)); - } - } -#endif /* USE_AASB */ - - // - // if not already aasb scaling and - // if we do not have a bitmap that is nearly the correct size - // - if (!use_scaled_font && !have_nearly_rightsized_bitmap) { - // check if we can use an outline scaled font - if (aStretch->mOutlineScaled) { - scale_size = PR_MAX(mPixelSize, aCharSet->mOutlineScaleMin); - - if (PR_ABS(mPixelSize-scale_size) < PR_ABS(mPixelSize-bitmap_size)) { - use_scaled_font = PR_TRUE; - SIZE_FONT_PRINTF(("outline font:______ %s\n" - " desired=%d, scaled=%d, bitmap=%d", - aStretch->mScalable, mPixelSize, scale_size, - (bitmap_size=NOT_FOUND_FONT_SIZE?0:bitmap_size))); - } - } -#ifdef USE_AASB - // see if we can aasb (anti alias scaled bitmap) - if (!use_scaled_font - && (bitmap_sizemAABitmapScaleEnabled) { - // if we do not have a near-the-right-size font or scalable font - // see if we can anti-alias bitmap scale one - scale_size = PR_MAX(mPixelSize, aCharSet->mAABitmapScaleMin); - double ratio = (bitmap_size / ((double) mPixelSize)); - if ( (ratio < aCharSet->mAABitmapUndersize) - || (ratio > aCharSet->mAABitmapOversize)) { - // - // Try to get a size font to scale that is 2x larger - // (but at least 16 pixel) - // - base_aafont = GetAASBBaseFont(aStretch, aCharSet); - if (base_aafont) { - use_scaled_font = PR_TRUE; - SIZE_FONT_PRINTF(("anti-aliased bitmap scaled font: %s\n" - " desired=%d, aa-scaled=%d, bitmap=%d, " - "aa_bitmap=%d", - aName, mPixelSize, scale_size, bitmap_size, base_aafont->mSize)); - } - } - } -#endif /* USE_AASB */ - - // last resort: consider a bitmap scaled font (ugly!) - if (!use_scaled_font && aStretch->mScalable) { - scale_size = PR_MAX(mPixelSize, aCharSet->mBitmapScaleMin); - double ratio = (bitmap_size / ((double) mPixelSize)); - if ((ratio < aCharSet->mBitmapUndersize) - || (ratio > aCharSet->mBitmapOversize)) { - if ((PR_ABS(mPixelSize-scale_size) < PR_ABS(mPixelSize-bitmap_size))) { - use_scaled_font = PR_TRUE; - SIZE_FONT_PRINTF(("bitmap scaled font: %s\n" - " desired=%d, scaled=%d, bitmap=%d", - aStretch->mScalable, mPixelSize, scale_size, - (bitmap_size=NOT_FOUND_FONT_SIZE?0:bitmap_size))); - } - } - } - } - - NS_ASSERTION((bitmap_sizemScalable -#endif /* ALWAYS_USE_SCALED_FONTS_FOR_XPRINT */ - ) { - SIZE_FONT_PRINTF(("scaled font:_______ %s\n" - " desired=%d, scaled=%d, bitmap=%d", - aName, mPixelSize, scale_size, bitmap_size)); - - PRInt32 i; - PRInt32 n = aStretch->mScaledFonts.Count(); - nsFontXlib* p = nsnull; - for (i = 0; i < n; i++) { - p = (nsFontXlib*) aStretch->mScaledFonts.ElementAt(i); - if (p->mSize == scale_size) { - break; - } - } - if (i == n) { -#ifdef USE_AASB - if (base_aafont) { - // setup the base font - if (!SetFontCharsetInfo(base_aafont, aCharSet, aChar)) - return nsnull; - if (mIsUserDefined) { - base_aafont = SetupUserDefinedFont(mFontMetricsContext, base_aafont); - if (!base_aafont) - return nsnull; - } - font = new nsFontXlibNormal(aFmctx, base_aafont); - } - else -#endif /* USE_AASB */ - { - font = new nsFontXlibNormal(mFontMetricsContext); - } - - if (font) { - /* - * XXX Instead of passing pixel size, we ought to take underline - * into account. (Extra space for underline for Asian fonts.) - */ -#ifdef USE_AASB - if (base_aafont) { - font->mName = PR_smprintf("%s", base_aafont->mName); - font->mAABaseSize = base_aafont->mSize; - } - else -#endif /* USE_AASB */ - { - font->mName = PR_smprintf(aStretch->mScalable, scale_size); -#ifdef USE_AASB - font->mAABaseSize = 0; -#endif /* USE_AASB */ - } - if (!font->mName) { - delete font; - return nsnull; - } - font->mSize = scale_size; - font->mCharSetInfo = aCharSet; - aStretch->mScaledFonts.AppendElement(font); - } - else { - return nsnull; - } - } - else { - font = p; - } - } - - if (!SetFontCharsetInfo(font, aCharSet, aChar)) - return nsnull; - - if (mIsUserDefined) { - font = SetupUserDefinedFont(mFontMetricsContext, font); - if (!font) - return nsnull; - } - - return AddToLoadedFontsList(font); -} - -PR_BEGIN_EXTERN_C -static int -CompareSizes(const void* aArg1, const void* aArg2, void *data) -{ - return (*((nsFontXlib**) aArg1))->mSize - (*((nsFontXlib**) aArg2))->mSize; -} -PR_END_EXTERN_C - -void -nsFontStretchXlib::SortSizes(void) -{ - NS_QuickSort(mSizes, mSizesCount, sizeof(*mSizes), CompareSizes, NULL); -} - -void -nsFontWeightXlib::FillStretchHoles(void) -{ - int i, j; - - for (i = 0; i < 9; i++) { - if (mStretches[i]) { - mStretches[i]->SortSizes(); - } - } - - if (!mStretches[4]) { - for (i = 5; i < 9; i++) { - if (mStretches[i]) { - mStretches[4] = mStretches[i]; - break; - } - } - if (!mStretches[4]) { - for (i = 3; i >= 0; i--) { - if (mStretches[i]) { - mStretches[4] = mStretches[i]; - break; - } - } - } - } - - for (i = 5; i < 9; i++) { - if (!mStretches[i]) { - for (j = i + 1; j < 9; j++) { - if (mStretches[j]) { - mStretches[i] = mStretches[j]; - break; - } - } - if (!mStretches[i]) { - for (j = i - 1; j >= 0; j--) { - if (mStretches[j]) { - mStretches[i] = mStretches[j]; - break; - } - } - } - } - } - for (i = 3; i >= 0; i--) { - if (!mStretches[i]) { - for (j = i - 1; j >= 0; j--) { - if (mStretches[j]) { - mStretches[i] = mStretches[j]; - break; - } - } - if (!mStretches[i]) { - for (j = i + 1; j < 9; j++) { - if (mStretches[j]) { - mStretches[i] = mStretches[j]; - break; - } - } - } - } - } -} - -void -nsFontStyleXlib::FillWeightHoles(void) -{ - int i, j; - - for (i = 0; i < 9; i++) { - if (mWeights[i]) { - mWeights[i]->FillStretchHoles(); - } - } - - if (!mWeights[3]) { - for (i = 4; i < 9; i++) { - if (mWeights[i]) { - mWeights[3] = mWeights[i]; - break; - } - } - if (!mWeights[3]) { - for (i = 2; i >= 0; i--) { - if (mWeights[i]) { - mWeights[3] = mWeights[i]; - break; - } - } - } - } - - // CSS2, section 15.5.1 - if (!mWeights[4]) { - mWeights[4] = mWeights[3]; - } - for (i = 5; i < 9; i++) { - if (!mWeights[i]) { - for (j = i + 1; j < 9; j++) { - if (mWeights[j]) { - mWeights[i] = mWeights[j]; - break; - } - } - if (!mWeights[i]) { - for (j = i - 1; j >= 0; j--) { - if (mWeights[j]) { - mWeights[i] = mWeights[j]; - break; - } - } - } - } - } - for (i = 2; i >= 0; i--) { - if (!mWeights[i]) { - for (j = i - 1; j >= 0; j--) { - if (mWeights[j]) { - mWeights[i] = mWeights[j]; - break; - } - } - if (!mWeights[i]) { - for (j = i + 1; j < 9; j++) { - if (mWeights[j]) { - mWeights[i] = mWeights[j]; - break; - } - } - } - } - } -} - -void -nsFontNodeXlib::FillStyleHoles(void) -{ - if (mHolesFilled) { - return; - } - mHolesFilled = 1; - -#ifdef DEBUG_DUMP_TREE - DumpFamily(this); -#endif - - for (int i = 0; i < 3; i++) { - if (mStyles[i]) { - mStyles[i]->FillWeightHoles(); - } - } - - // XXX If both italic and oblique exist, there is probably something - // wrong. Try counting the fonts, and removing the one that has less. - if (!mStyles[NS_FONT_STYLE_NORMAL]) { - if (mStyles[NS_FONT_STYLE_ITALIC]) { - mStyles[NS_FONT_STYLE_NORMAL] = mStyles[NS_FONT_STYLE_ITALIC]; - } - else { - mStyles[NS_FONT_STYLE_NORMAL] = mStyles[NS_FONT_STYLE_OBLIQUE]; - } - } - if (!mStyles[NS_FONT_STYLE_ITALIC]) { - if (mStyles[NS_FONT_STYLE_OBLIQUE]) { - mStyles[NS_FONT_STYLE_ITALIC] = mStyles[NS_FONT_STYLE_OBLIQUE]; - } - else { - mStyles[NS_FONT_STYLE_ITALIC] = mStyles[NS_FONT_STYLE_NORMAL]; - } - } - if (!mStyles[NS_FONT_STYLE_OBLIQUE]) { - if (mStyles[NS_FONT_STYLE_ITALIC]) { - mStyles[NS_FONT_STYLE_OBLIQUE] = mStyles[NS_FONT_STYLE_ITALIC]; - } - else { - mStyles[NS_FONT_STYLE_OBLIQUE] = mStyles[NS_FONT_STYLE_NORMAL]; - } - } - -#ifdef DEBUG_DUMP_TREE - DumpFamily(this); -#endif -} - -static void -SetCharsetLangGroup(nsFontMetricsXlibContext *aFmctx, nsFontCharSetInfoXlib* aCharSetInfo) -{ - if (!aCharSetInfo->mCharSet || aCharSetInfo->mLangGroup) - return; - - nsresult res; - - res = aFmctx->mCharSetManager->GetCharsetLangGroupRaw(aCharSetInfo->mCharSet, - &aCharSetInfo->mLangGroup); - if (NS_FAILED(res)) { - aCharSetInfo->mLangGroup = NS_NewAtom(""); -#ifdef NOISY_FONTS - printf("=== cannot get lang group for %s\n", aCharSetInfo->mCharSet); -#endif - } -} - -#define GET_WEIGHT_INDEX(index, weight) \ - do { \ - (index) = WEIGHT_INDEX(weight); \ - if ((index) < 0) { \ - (index) = 0; \ - } \ - else if ((index) > 8) { \ - (index) = 8; \ - } \ - } while (0) - -nsFontXlib* -nsFontMetricsXlib::SearchNode(nsFontNodeXlib* aNode, PRUnichar aChar) -{ - if (aNode->mDummy) { - return nsnull; - } - - nsFontCharSetInfoXlib* charSetInfo = aNode->mCharSetInfo; - - /* - * mCharSet is set if we know which glyphs will be found in these fonts. - * If mCCMap has already been created for this charset, we compare it with - * the mCCMaps of the previously loaded fonts. If it is the same as any of - * the previous ones, we return nsnull because there is no point in - * loading a font with the same map. - */ - if (charSetInfo->mCharSet) { - PRUint16* ccmap = charSetInfo->mCCMap; - if (ccmap) { - for (int i = 0; i < mLoadedFontsCount; i++) { - if (mLoadedFonts[i]->mCCMap == ccmap) { - return nsnull; - } - } - } - else { - if (!SetUpFontCharSetInfo(mFontMetricsContext, charSetInfo)) - return nsnull; - } - } - else { - if ((!mIsUserDefined) && (charSetInfo == mFontMetricsContext->mUnknown)) { - return nsnull; - } - } - - aNode->FillStyleHoles(); - nsFontStyleXlib* style = aNode->mStyles[mStyleIndex]; - - nsFontWeightXlib** weights = style->mWeights; - int weight = mFont.weight; - int steps = (weight % 100); - int weightIndex; - if (steps) { - if (steps < 10) { - int base = (weight - steps); - GET_WEIGHT_INDEX(weightIndex, base); - while (steps--) { - nsFontWeightXlib* prev = weights[weightIndex]; - for (weightIndex++; weightIndex < 9; weightIndex++) { - if (weights[weightIndex] != prev) { - break; - } - } - if (weightIndex >= 9) { - weightIndex = 8; - } - } - } - else if (steps > 90) { - steps = (100 - steps); - int base = (weight + steps); - GET_WEIGHT_INDEX(weightIndex, base); - while (steps--) { - nsFontWeightXlib* prev = weights[weightIndex]; - for (weightIndex--; weightIndex >= 0; weightIndex--) { - if (weights[weightIndex] != prev) { - break; - } - } - if (weightIndex < 0) { - weightIndex = 0; - } - } - } - else { - GET_WEIGHT_INDEX(weightIndex, weight); - } - } - else { - GET_WEIGHT_INDEX(weightIndex, weight); - } - - FIND_FONT_PRINTF((" load font %s", aNode->mName.get())); - return PickASizeAndLoad(weights[weightIndex]->mStretches[mStretchIndex], - charSetInfo, aChar, aNode->mName.get()); -} - -static void -SetFontLangGroupInfo(nsFontMetricsXlibContext *aFmctx, const nsFontCharSetMapXlib* aCharSetMap) -{ - nsFontLangGroupXlib *fontLangGroup = aCharSetMap->mFontLangGroup; - if (!fontLangGroup) - return; - - // get the atom for mFontLangGroup->mFontLangGroupName so we can - // apply fontLangGroup operations to it - // eg: search for related groups, check for scaling prefs - const char *langGroup = fontLangGroup->mFontLangGroupName; - - // the font.scale prefs don't make sense without a langGroup - // XXX FIX!!! if langGroup is "", we need to bypass the font.scale stuff - if (!langGroup) - langGroup = ""; - if (!fontLangGroup->mFontLangGroupAtom) { - fontLangGroup->mFontLangGroupAtom = NS_NewAtom(langGroup); - } - - // hack : map 'x-zh-TWHK' to 'zh-TW'. See nsFontMetricsGTK.cpp for details. - if (fontLangGroup->mFontLangGroupAtom == aFmctx->mZHTWHK) { - langGroup = "zh-TW"; - } - - // get the font scaling controls - nsFontCharSetInfoXlib *charSetInfo = aCharSetMap->mInfo; - if (!charSetInfo->mInitedSizeInfo) { - charSetInfo->mInitedSizeInfo = PR_TRUE; - - nsCAutoString name; - nsresult rv; - name.Assign("font.scale.outline.min."); - name.Append(langGroup); - rv = aFmctx->mPref->GetIntPref(name.get(), &charSetInfo->mOutlineScaleMin); - if (NS_SUCCEEDED(rv)) - SIZE_FONT_PRINTF(("%s = %d", name.get(), charSetInfo->mOutlineScaleMin)); - else - charSetInfo->mOutlineScaleMin = aFmctx->mOutlineScaleMinimum; - -#ifdef USE_AASB - name.Assign("font.scale.aa_bitmap.min."); - name.Append(langGroup); - rv = aFmctx->mPref->GetIntPref(name.get(), &charSetInfo->mAABitmapScaleMin); - if (NS_SUCCEEDED(rv)) - SIZE_FONT_PRINTF(("%s = %d", name.get(), charSetInfo->mAABitmapScaleMin)); - else - charSetInfo->mAABitmapScaleMin = aFmctx->mAABitmapScaleMinimum; -#endif /* USE_AASB */ - - name.Assign("font.scale.bitmap.min."); - name.Append(langGroup); - rv = aFmctx->mPref->GetIntPref(name.get(), &charSetInfo->mBitmapScaleMin); - if (NS_SUCCEEDED(rv)) - SIZE_FONT_PRINTF(("%s = %d", name.get(), charSetInfo->mBitmapScaleMin)); - else - charSetInfo->mBitmapScaleMin = aFmctx->mBitmapScaleMinimum; - - PRInt32 percent = 0; -#ifdef USE_AASB - name.Assign("font.scale.aa_bitmap.oversize."); - name.Append(langGroup); - percent = 0; - rv = mFontMetricsContext->mPref->GetIntPref(name.get(), &percent); - if (NS_SUCCEEDED(rv)) { - charSetInfo->mAABitmapOversize = percent/100.0; - SIZE_FONT_PRINTF(("%s = %g", name.get(), charSetInfo->mAABitmapOversize)); - } - else - charSetInfo->mAABitmapOversize = aFmctx->mAABitmapOversize; - - percent = 0; - name.Assign("font.scale.aa_bitmap.undersize."); - name.Append(langGroup); - rv = mFontMetricsContext->mPref->GetIntPref(name.get(), &percent); - if (NS_SUCCEEDED(rv)) { - charSetInfo->mAABitmapUndersize = percent/100.0; - SIZE_FONT_PRINTF(("%s = %g", name.get(),charSetInfo->mAABitmapUndersize)); - } - else - charSetInfo->mAABitmapUndersize = aFmctx->mAABitmapUndersize; - - PRBool val = PR_TRUE; - name.Assign("font.scale.aa_bitmap.always."); - name.Append(langGroup); - rv = mFontMetricsContext->mPref->GetBoolPref(name.get(), &val); - if (NS_SUCCEEDED(rv)) { - charSetInfo->mAABitmapScaleAlways = val; - SIZE_FONT_PRINTF(("%s = %d", name.get(),charSetInfo->mAABitmapScaleAlways)); - } - else - charSetInfo->mAABitmapScaleAlways = aFmctx->mAABitmapScaleAlways; -#endif /* USE_AASB */ - - percent = 0; - name.Assign("font.scale.bitmap.oversize."); - name.Append(langGroup); - rv = aFmctx->mPref->GetIntPref(name.get(), &percent); - if (NS_SUCCEEDED(rv)) { - charSetInfo->mBitmapOversize = percent/100.0; - SIZE_FONT_PRINTF(("%s = %g", name.get(), charSetInfo->mBitmapOversize)); - } - else - charSetInfo->mBitmapOversize = aFmctx->mBitmapOversize; - - percent = 0; - name.Assign("font.scale.bitmap.undersize."); - name.Append(langGroup); - rv = aFmctx->mPref->GetIntPref(name.get(), &percent); - if (NS_SUCCEEDED(rv)) { - charSetInfo->mBitmapUndersize = percent/100.0; - SIZE_FONT_PRINTF(("%s = %g", name.get(), charSetInfo->mBitmapUndersize)); - } - else - charSetInfo->mBitmapUndersize = aFmctx->mBitmapUndersize; - } -} - -static nsFontStyleXlib* -NodeGetStyle(nsFontNodeXlib* aNode, int aStyleIndex) -{ - nsFontStyleXlib* style = aNode->mStyles[aStyleIndex]; - if (!style) { - style = new nsFontStyleXlib; - if (!style) { - return nsnull; - } - aNode->mStyles[aStyleIndex] = style; - } - return style; -} - -static nsFontWeightXlib* -NodeGetWeight(nsFontStyleXlib* aStyle, int aWeightIndex) -{ - nsFontWeightXlib* weight = aStyle->mWeights[aWeightIndex]; - if (!weight) { - weight = new nsFontWeightXlib; - if (!weight) { - return nsnull; - } - aStyle->mWeights[aWeightIndex] = weight; - } - return weight; -} - -static nsFontStretchXlib* -NodeGetStretch(nsFontWeightXlib* aWeight, int aStretchIndex) -{ - nsFontStretchXlib* stretch = aWeight->mStretches[aStretchIndex]; - if (!stretch) { - stretch = new nsFontStretchXlib; - if (!stretch) { - return nsnull; - } - aWeight->mStretches[aStretchIndex] = stretch; - } - return stretch; -} - -static PRBool -NodeAddScalable(nsFontStretchXlib* aStretch, - PRBool aOutlineScaled, -#ifdef USE_XPRINT - PRBool aPrinterBuiltinFont, int aResX, int aResY, -#endif /* USE_XPRINT */ - const char *aDashFoundry, const char *aFamily, - const char *aWeight, const char * aSlant, - const char *aWidth, const char *aStyle, - const char *aSpacing, const char *aCharSet) -{ - // if we have both an outline scaled font and a bitmap - // scaled font pick the outline scaled font - if ((aStretch->mScalable) && (!aStretch->mOutlineScaled) - && (aOutlineScaled)) { - PR_smprintf_free(aStretch->mScalable); - aStretch->mScalable = nsnull; - } - if (!aStretch->mScalable) { - aStretch->mOutlineScaled = aOutlineScaled; -#ifdef USE_XPRINT - /* Xprint built-in printer fonts are outline-scaled fonts (except - * that we ask explicitly for X/Y resolution instead of using 0/0) - */ - if (aPrinterBuiltinFont) { - aStretch->mScalable = - PR_smprintf("%s-%s-%s-%s-%s-%s-%%d-*-%d-%d-%s-*-%s", - aDashFoundry, aFamily, aWeight, aSlant, aWidth, aStyle, - aResX, aResY, aSpacing, aCharSet); - if (!aStretch->mScalable) - return PR_FALSE; - } - else -#endif /* USE_XPRINT */ - if (aOutlineScaled) { - aStretch->mScalable = - PR_smprintf("%s-%s-%s-%s-%s-%s-%%d-*-0-0-%s-*-%s", - aDashFoundry, aFamily, aWeight, aSlant, aWidth, aStyle, - aSpacing, aCharSet); - if (!aStretch->mScalable) - return PR_FALSE; - } - else { - aStretch->mScalable = - PR_smprintf("%s-%s-%s-%s-%s-%s-%%d-*-*-*-%s-*-%s", - aDashFoundry, aFamily, aWeight, aSlant, aWidth, aStyle, - aSpacing, aCharSet); - if (!aStretch->mScalable) - return PR_FALSE; - } - } - return PR_TRUE; -} - -static PRBool -NodeAddSize(nsFontMetricsXlibContext *aFmctx, - nsFontStretchXlib* aStretch, - int aPixelSize, int aPointSize, - float scaler, - int aResX, int aResY, - const char *aDashFoundry, const char *aFamily, - const char *aWeight, const char * aSlant, - const char *aWidth, const char *aStyle, - const char *aSpacing, const char *aCharSet, - nsFontCharSetInfoXlib* aCharSetInfo) -{ - if (scaler!=1.0f) - { - aPixelSize = int(float(aPixelSize) * scaler); - aPointSize = int(float(aPointSize) * scaler); - aResX = 0; - aResY = 0; - } - - PRBool haveSize = PR_FALSE; - if (aStretch->mSizesCount) { - nsFontXlib** end = &aStretch->mSizes[aStretch->mSizesCount]; - nsFontXlib** s; - for (s = aStretch->mSizes; s < end; s++) { - if ((*s)->mSize == aPixelSize) { - haveSize = PR_TRUE; - break; - } - } - } - if (!haveSize) { - if (aStretch->mSizesCount == aStretch->mSizesAlloc) { - int newSize = 2 * (aStretch->mSizesAlloc ? aStretch->mSizesAlloc : 1); - nsFontXlib** newSizes = new nsFontXlib*[newSize]; - if (!newSizes) - return PR_FALSE; - for (int j = aStretch->mSizesAlloc - 1; j >= 0; j--) { - newSizes[j] = aStretch->mSizes[j]; - } - aStretch->mSizesAlloc = newSize; - delete [] aStretch->mSizes; - aStretch->mSizes = newSizes; - } - char *name = PR_smprintf("%s-%s-%s-%s-%s-%s-%d-%d-%d-%d-%s-*-%s", - aDashFoundry, aFamily, aWeight, aSlant, aWidth, aStyle, - aPixelSize, aPointSize, aResX, aResY, aSpacing, aCharSet); - - if (!name) { - return PR_FALSE; - } - nsFontXlib* size = new nsFontXlibNormal(aFmctx); - if (!size) { - return PR_FALSE; - } - aStretch->mSizes[aStretch->mSizesCount++] = size; - size->mName = name; - // size->mFont is initialized in the constructor - size->mSize = aPixelSize; - size->mBaselineAdjust = 0; - size->mCCMap = nsnull; - size->mCharSetInfo = aCharSetInfo; - } - return PR_TRUE; -} - -static void -GetFontNames(nsFontMetricsXlibContext *aFmctx, const char* aPattern, PRBool aAnyFoundry, PRBool aOnlyOutlineScaledFonts, nsFontNodeArrayXlib* aNodes) -{ - Display *dpy = xxlib_rgb_get_display(aFmctx->mXlibRgbHandle); - Screen *scr = xxlib_rgb_get_screen (aFmctx->mXlibRgbHandle); - -#ifdef NS_FONT_DEBUG_CALL_TRACE - if (gFontDebug & NS_FONT_DEBUG_CALL_TRACE) { - printf("GetFontNames %s\n", aPattern); - } -#endif - -#ifdef MOZ_ENABLE_FREETYPE2 - // get FreeType fonts - nsFT2FontCatalog::GetFontNames(aFmctx, aPattern, aNodes); -#endif /* MOZ_ENABLE_FREETYPE2 */ - - nsCAutoString previousNodeName; - nsHashtable* node_hash; - if (aAnyFoundry) { - NS_ASSERTION(aPattern[1] == '*', "invalid 'anyFoundry' pattern"); - node_hash = &aFmctx->mAFRENodes; - } - else { - node_hash = &aFmctx->mFFRENodes; - } - -#ifdef USE_XPRINT -#ifdef DEBUG - if (aFmctx->mPrinterMode) - { - if (!dpy) - { - NS_ERROR("Obtaining font information without having a |Display *|"); - abort(); /* DIE!! */ - } - - if (XpGetContext(dpy) == None) - { - /* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */ - NS_ERROR("Obtaining font information without valid print context (XListFonts()) _before_ XpSetContext()"); - abort(); /* DIE!! */ - } - } -#endif /* DEBUG */ -#endif /* USE_XPRINT */ - -#ifdef ENABLE_X_FONT_BANNING - int screen_xres, - screen_yres; - /* Get Xserver DPI. - * We cannot use Mozilla's API here because it may "override" the DPI - * got from the Xserver via prefs. But we want to filter ("ban") fonts - * we get from the Xserver which _it_(=Xserver) has "choosen" for us - * using its DPI value ... - */ -#ifdef USE_XPRINT - if (aFmctx->mPrinterMode) { - Bool success; - long x_dpi = 0, - y_dpi = 0; - success = XpuGetResolution(dpy, XpGetContext(dpy), &x_dpi, &y_dpi); - NS_ASSERTION(success, "XpuGetResolution(dpy, XpGetContext(dpy), &x_dpi, &y_dpi)!"); - screen_xres = x_dpi; - screen_yres = y_dpi; - } - else -#endif /* USE_XPRINT */ - { - screen_xres = int(((( double(::XWidthOfScreen(scr))) * 25.4 / double(::XWidthMMOfScreen(scr)) )) + 0.5); - screen_yres = int(((( double(::XHeightOfScreen(scr))) * 25.4 / double(::XHeightMMOfScreen(scr)) )) + 0.5); - } -#endif /* ENABLE_X_FONT_BANNING */ - - BANNED_FONT_PRINTF(("Loading font '%s'", aPattern)); - /* - * We do not use XListFontsWithInfo here, because it is very expensive. - * Instead, we get that info at the time when we actually load the font. - */ - int count; - char **list = ::XListFonts(dpy, aPattern, INT_MAX, &count); - if ((!list) || (count < 1)) { - return; - } - for (int i = 0; i < count; i++) { - char name[256]; /* X11 font names are never larger than 255 chars */ - - /* Check if we can handle the font name ('*' and '?' are only valid in - * input patterns passed as argument to |XListFont()|&co. but _not_ in - * font names returned by these functions (see bug 136743 ("xlib complains - * a lot about fonts with '*' in the XLFD string"))) */ - if ((!list[i]) || (list[i][0] != '-') || (PL_strpbrk(list[i], "*?") != nsnull)) { - continue; - } - - strcpy(name, list[i]); - - char *p = name + 1; - PRBool scalable = PR_FALSE, - outline_scaled = PR_FALSE; -#ifdef USE_XPRINT - PRBool builtin_printer_font = PR_FALSE; -#endif /* USE_XPRINT */ - int resX = -1, - resY = -1; - -#ifdef FIND_FIELD -#undef FIND_FIELD -#endif -#define FIND_FIELD(var) \ - char* var = p; \ - while ((*p) && ((*p) != '-')) { \ - p++; \ - } \ - if (*p) { \ - *p++ = 0; \ - } \ - else { \ - continue; \ - } - -#ifdef SKIP_FIELD -#undef SKIP_FIELD -#endif -#define SKIP_FIELD(var) \ - while ((*p) && ((*p) != '-')) { \ - p++; \ - } \ - if (*p) { \ - p++; \ - } \ - else { \ - continue; \ - } - - FIND_FIELD(foundry); - // XXX What to do about the many Applix fonts that start with "ax"? - FIND_FIELD(familyName); - FIND_FIELD(weightName); - FIND_FIELD(slant); - FIND_FIELD(setWidth); - FIND_FIELD(addStyle); - FIND_FIELD(pixelSize); - if (pixelSize[0] == '0') { - scalable = PR_TRUE; - } - FIND_FIELD(pointSize); - if (pointSize[0] == '0') { - scalable = PR_TRUE; - } - FIND_FIELD(resolutionX); - resX = atoi(resolutionX); - NS_ASSERTION(!(resolutionX[0] != '0' && resX == 0), "atoi(resolutionX) failure."); - if (resolutionX[0] == '0') { - scalable = PR_TRUE; - } - FIND_FIELD(resolutionY); - resY = atoi(resolutionY); - NS_ASSERTION(!(resolutionY[0] != '0' && resY == 0), "atoi(resolutionY) failure."); - if (resolutionY[0] == '0') { - scalable = PR_TRUE; - } - /* check if bitmap non-scaled font */ - if ((pixelSize[0] != '0') || (pointSize[0] != '0')) { - SCALED_FONT_PRINTF(("bitmap (non-scaled) font: %s", list[i])); - } - /* check if bitmap scaled font */ - else if ((pixelSize[0] == '0') && (pointSize[0] == '0') - && (resolutionX[0] != '0') && (resolutionY[0] != '0')) { - SCALED_FONT_PRINTF(("bitmap scaled font: %s", list[i])); - } - /* check if outline scaled font */ - else if ((pixelSize[0] == '0') && (pointSize[0] == '0') - && (resolutionX[0] == '0') && (resolutionY[0] == '0')) { - outline_scaled = PR_TRUE; - SCALED_FONT_PRINTF(("outline scaled font: %s", list[i])); - } - else { - SCALED_FONT_PRINTF(("unexpected font values: %s", list[i])); - SCALED_FONT_PRINTF((" pixelSize[0] = %c", pixelSize[0])); - SCALED_FONT_PRINTF((" pointSize[0] = %c", pointSize[0])); - SCALED_FONT_PRINTF((" resolutionX[0] = %c", resolutionX[0])); - SCALED_FONT_PRINTF((" resolutionY[0] = %c", resolutionY[0])); - static PRBool already_complained = PR_FALSE; - // only complaing once - if (!already_complained) { - already_complained = PR_TRUE; - NS_ASSERTION(pixelSize[0] == '0', "font scaler type test failed"); - NS_ASSERTION(pointSize[0] == '0', "font scaler type test failed"); - NS_ASSERTION(resolutionX[0] == '0', "font scaler type test failed"); - NS_ASSERTION(resolutionY[0] == '0', "font scaler type test failed"); - } - } - FIND_FIELD(spacing); - FIND_FIELD(averageWidth); - -#ifdef USE_XPRINT - /* I am not sure what Xprint built-in printer fonts exactly look like - * (usually '-adobe-helvetica-medium-r-normal--0-0-1200-1200-p-0-iso8859-1' - * for a 300DPI printer ("fonts.dir" entry in - * $XPCONFIGDIR/C/print/models/SPSPARC2/fonts/ for "Helvetica.pmf" - * (PMF=printer font metrics) looks like this: - * '-adobe-helvetica-medium-r-normal--199-120-1200-1200-p-1085-iso8859-1')) - * but this test is good enough (except when someone installs 1200DPI - * bitmap (!!) fonts on a system... =:-) - */ - if (aFmctx->mPrinterMode && - averageWidth[0] == '0' && - resX > screen_xres && - resY > screen_yres) { - builtin_printer_font = PR_TRUE; - /* Treat built-in printer fonts like outline-scaled ones... */ - outline_scaled = PR_TRUE; - - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("This may be a built-in printer font '%s'\n", list[i])); - } -#endif /* USE_XPRINT */ - - if (averageWidth[0] == '0') { - scalable = PR_TRUE; -/* Workaround for bug 103159 ("sorting fonts by foundry names cause font - * size of css ignored in some cases"). - * Hardcoded font ban until bug 104075 ("need X font banning") has been - * implemented. See http://bugzilla.mozilla.org/show_bug.cgi?id=94327#c34 - * for additional comments... - */ -#ifndef DISABLE_WORKAROUND_FOR_BUG_103159 - /* Skip 'mysterious' and 'spurious' cases like - * -adobe-times-medium-r-normal--17-120-100-100-p-0-iso8859-9 - * The only "legal" use for this type of XLFD are Xprint - * build-in printer fonts.like - * -adobe-times-medium-r-normal--50-120-300-300-p-0-iso8859-1 - * (300DPI printer) - */ - if ((pixelSize[0] != '0' || pointSize[0] != 0) && - (outline_scaled == PR_FALSE) -#ifdef USE_XPRINT - && (builtin_printer_font == PR_FALSE) -#endif /* USE_XPRINT */ - ) { - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("rejecting font '%s' (via hardcoded workaround for bug 103159)\n", list[i])); - BANNED_FONT_PRINTF(("rejecting font '%s' (via hardcoded workaround for bug 103159)", list[i])); - continue; - } -#endif /* DISABLE_WORKAROUND_FOR_BUG_103159 */ - } - char* charSetName = p; // CHARSET_REGISTRY & CHARSET_ENCODING - if (!*charSetName) { - continue; - } - - if (aOnlyOutlineScaledFonts && (outline_scaled == PR_FALSE)) { - continue; - } - -#ifdef ENABLE_X_FONT_BANNING -#define BOOL2STR(b) ((b)?("true"):("false")) - if (aFmctx->mFontRejectRegEx || aFmctx->mFontAcceptRegEx) { - char fmatchbuf[512]; /* See sprintf() below. */ - - sprintf(fmatchbuf, "fname=%s;scalable=%s;outline_scaled=%s;xdisplay=%s;xdpy=%d;ydpy=%d;xdevice=%s", - list[i], /* full font name */ - BOOL2STR(scalable), - BOOL2STR(outline_scaled), - XDisplayString(dpy), - screen_xres, - screen_yres, -#ifdef USE_XPRINT - aFmctx->mPrinterMode?("printer"): -#endif /* USE_XPRINT */ - ("display") - ); -#undef BOOL2STR - - if (aFmctx->mFontRejectRegEx) { - /* reject font if reject pattern matches it... */ - if (regexec(aFmctx->mFontRejectRegEx, fmatchbuf, 0, nsnull, 0) == REG_OK) { - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("rejecting font '%s' (via reject pattern)\n", fmatchbuf)); - BANNED_FONT_PRINTF(("rejecting font '%s' (via reject pattern)", fmatchbuf)); - continue; - } - } - - if (aFmctx->mFontAcceptRegEx) { - if (regexec(aFmctx->mFontAcceptRegEx, fmatchbuf, 0, nsnull, 0) == REG_NOMATCH) { - PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("rejecting font '%s' (via accept pattern)\n", fmatchbuf)); - BANNED_FONT_PRINTF(("rejecting font '%s' (via accept pattern)", fmatchbuf)); - continue; - } - } - } -#endif /* ENABLE_X_FONT_BANNING */ - - const nsFontCharSetMapXlib *charSetMap = GetCharSetMap(aFmctx, charSetName); - nsFontCharSetInfoXlib* charSetInfo = charSetMap->mInfo; - // indirection for font specific charset encoding - if (charSetInfo == aFmctx->mSpecial) { - nsCAutoString familyCharSetName(familyName); - familyCharSetName.Append('-'); - familyCharSetName.Append(charSetName); - nsCStringKey familyCharSetKey(familyCharSetName); - charSetMap = NS_STATIC_CAST(nsFontCharSetMapXlib*, aFmctx->mSpecialCharSets.Get(&familyCharSetKey)); - if (!charSetMap) - charSetMap = aFmctx->mNoneCharSetMap; - charSetInfo = charSetMap->mInfo; - } - if (!charSetInfo) { -#ifdef NOISY_FONTS - printf("cannot find charset %s\n", charSetName); -#endif - charSetInfo = aFmctx->mUnknown; - } - SetCharsetLangGroup(aFmctx, charSetInfo); - SetFontLangGroupInfo(aFmctx, charSetMap); - - nsCAutoString nodeName; - if (aAnyFoundry) - nodeName.Assign('*'); - else - nodeName.Assign(foundry); - nodeName.Append('-'); - nodeName.Append(familyName); - nodeName.Append('-'); - nodeName.Append(charSetName); - nsCStringKey key(nodeName); - nsFontNodeXlib* node = (nsFontNodeXlib*) node_hash->Get(&key); - if (!node) { - node = new nsFontNodeXlib; - if (!node) { - continue; - } - node_hash->Put(&key, node); - node->mName = nodeName; - node->mCharSetInfo = charSetInfo; - } - - int found = 0; - if (nodeName == previousNodeName) { - found = 1; - } - else { - found = (aNodes->IndexOf(node) >= 0); - } - previousNodeName = nodeName; - if (!found) { - aNodes->AppendElement(node); - } - - int styleIndex; - // XXX This does not cover the full XLFD spec for SLANT. - switch (slant[0]) { - case 'i': - styleIndex = NS_FONT_STYLE_ITALIC; - break; - case 'o': - styleIndex = NS_FONT_STYLE_OBLIQUE; - break; - case 'r': - default: - styleIndex = NS_FONT_STYLE_NORMAL; - break; - } - nsFontStyleXlib* style = NodeGetStyle(node, styleIndex); - if (!style) - continue; - - nsCStringKey weightKey(weightName); - int weightNumber = NS_PTR_TO_INT32(aFmctx->mWeights.Get(&weightKey)); - if (!weightNumber) { -#ifdef NOISY_FONTS - printf("cannot find weight %s\n", weightName); -#endif - weightNumber = NS_FONT_WEIGHT_NORMAL; - } - int weightIndex = WEIGHT_INDEX(weightNumber); - nsFontWeightXlib* weight = NodeGetWeight(style, weightIndex); - if (!weight) - continue; - - nsCStringKey setWidthKey(setWidth); - int stretchIndex = NS_PTR_TO_INT32(aFmctx->mStretches.Get(&setWidthKey)); - if (!stretchIndex) { -#ifdef NOISY_FONTS - printf("cannot find stretch %s\n", setWidth); -#endif - stretchIndex = 5; - } - stretchIndex--; - nsFontStretchXlib* stretch = NodeGetStretch(weight, stretchIndex); - if (!stretch) - continue; - - if (scalable) { - if (!NodeAddScalable(stretch, outline_scaled, -#ifdef USE_XPRINT - builtin_printer_font, resX, resY, -#endif /* USE_XPRINT */ - name, familyName, weightName, slant, setWidth, addStyle, spacing, charSetName)) - continue; - } - - // get pixel size before the string is changed - int pixels, - points; - - pixels = atoi(pixelSize); - points = atoi(pointSize); - - if (pixels) { - if (aFmctx->mScaleBitmapFontsWithDevScale && (aFmctx->mDevScale > 1.0f)) { - /* Add a font size which is exactly scaled as the scaling factor ... */ - if (!NodeAddSize(aFmctx, stretch, pixels, points, aFmctx->mDevScale, resX, resY, name, familyName, weightName, - slant, setWidth, addStyle, spacing, charSetName, charSetInfo)) - continue; - - /* ... and offer a range of scaled fonts with integer scaling factors - * (we're taking half steps between integers, too - to avoid too big - * steps between font sizes) */ - float minScaler = PR_MAX(aFmctx->mDevScale / 2.0f, 1.5f), - maxScaler = aFmctx->mDevScale * 2.f, - scaler; - for( scaler = minScaler ; scaler <= maxScaler ; scaler += 0.5f ) - { - if (!NodeAddSize(aFmctx, stretch, pixels, points, scaler, resX, resY, name, familyName, weightName, - slant, setWidth, addStyle, spacing, charSetName, charSetInfo)) - break; - } - if (scaler <= maxScaler) { - continue; /* |NodeAddSize| returned an error in the loop above... */ - } - } - else - { - if (!NodeAddSize(aFmctx, stretch, pixels, points, 1.0f, resX, resY, name, familyName, weightName, - slant, setWidth, addStyle, spacing, charSetName, charSetInfo)) - continue; - } - } - } - XFreeFontNames(list); - -#ifdef DEBUG_DUMP_TREE - DumpTree(); -#endif -} - -static nsresult -GetAllFontNames(nsFontMetricsXlibContext *aFmctx) -{ - if (!aFmctx->mGlobalListInitalised) { - aFmctx->mGlobalListInitalised = PR_TRUE; - // This may well expand further (families * sizes * styles?), but it's - // only created once. - - /* Using "-*" instead of the full-qualified "-*-*-*-*-*-*-*-*-*-*-*-*-*-*" - * because it's faster and "smarter" - see bug 34242 for details. */ - GetFontNames(aFmctx, "-*", PR_FALSE, PR_FALSE, &aFmctx->mGlobalList); - } - - return NS_OK; -} - -static nsFontFamilyXlib* -FindFamily(nsFontMetricsXlibContext *aFmctx, nsCString* aName) -{ - nsCStringKey key(*aName); - nsFontFamilyXlib* family = (nsFontFamilyXlib*) aFmctx->mFamilies.Get(&key); - if (!family) { - family = new nsFontFamilyXlib(); - if (family) { - char pattern[256]; - PR_snprintf(pattern, sizeof(pattern), "-*-%s-*-*-*-*-*-*-*-*-*-*-*-*", - aName->get()); - GetFontNames(aFmctx, pattern, PR_TRUE, aFmctx->mForceOutlineScaledFonts, &family->mNodes); - aFmctx->mFamilies.Put(&key, family); - } - } - - return family; -} - -nsresult -nsFontMetricsXlib::FamilyExists(nsFontMetricsXlibContext *aFontMetricsContext, const nsString& aName) -{ - if (!global_fmctx) { - global_fmctx = aFontMetricsContext; - } - - if (!IsASCIIFontName(aName)) { - return NS_ERROR_FAILURE; - } - - nsCAutoString name; - name.AssignWithConversion(aName.get()); - ToLowerCase(name); - nsFontFamilyXlib* family = FindFamily(aFontMetricsContext, &name); - if (family && family->mNodes.Count()) { - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -// -// convert a FFRE (Foundry-Family-Registry-Encoding) To XLFD Pattern -// -static void -FFREToXLFDPattern(nsACString &aFFREName, nsACString &oPattern) -{ - PRInt32 charsetHyphen; - - oPattern.Append("-"); - oPattern.Append(aFFREName); - /* Search for the 3rd appearance of '-' */ - charsetHyphen = oPattern.FindChar('-'); - charsetHyphen = oPattern.FindChar('-', charsetHyphen + 1); - charsetHyphen = oPattern.FindChar('-', charsetHyphen + 1); - oPattern.Insert("-*-*-*-*-*-*-*-*-*-*", charsetHyphen); -} - -// -// substitute the charset in a FFRE (Foundry-Family-Registry-Encoding) -// -static void -FFRESubstituteCharset(nsACString &aFFREName, - const char *aReplacementCharset) -{ - PRInt32 charsetHyphen = aFFREName.FindChar('-'); - charsetHyphen = aFFREName.FindChar('-', charsetHyphen + 1); - aFFREName.Truncate(charsetHyphen+1); - aFFREName.Append(aReplacementCharset); -} - -// -// substitute the encoding in a FFRE (Foundry-Family-Registry-Encoding) -// -static void -FFRESubstituteEncoding(nsACString &aFFREName, - const char *aReplacementEncoding) -{ - PRInt32 encodingHyphen; - /* Search for the 3rd apperance of '-' */ - encodingHyphen = aFFREName.FindChar('-'); - encodingHyphen = aFFREName.FindChar('-', encodingHyphen + 1); - encodingHyphen = aFFREName.FindChar('-', encodingHyphen + 1); - aFFREName.Truncate(encodingHyphen+1); - aFFREName.Append(aReplacementEncoding); -} - -nsFontXlib* -nsFontMetricsXlib::TryNodes(nsACString &aFFREName, PRUnichar aChar) -{ - const nsPromiseFlatCString& FFREName = PromiseFlatCString(aFFREName); - - FIND_FONT_PRINTF((" TryNodes aFFREName = %s", FFREName.get())); - nsCStringKey key(FFREName); - PRBool anyFoundry = (FFREName.First() == '*'); - nsFontNodeArrayXlib* nodes = (nsFontNodeArrayXlib*) mFontMetricsContext->mCachedFFRESearches.Get(&key); - if (!nodes) { - nsCAutoString pattern; - FFREToXLFDPattern(aFFREName, pattern); - nodes = new nsFontNodeArrayXlib; - if (!nodes) - return nsnull; - GetFontNames(mFontMetricsContext, pattern.get(), anyFoundry, mFontMetricsContext->mForceOutlineScaledFonts, nodes); - mFontMetricsContext->mCachedFFRESearches.Put(&key, nodes); - } - int i, cnt = nodes->Count(); - for (i=0; iGetElement(i); - nsFontXlib * font; - font = SearchNode(node, aChar); - if (font && font->SupportsChar(aChar)) - return font; - } - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::TryNode(nsCString* aName, PRUnichar aChar) -{ - FIND_FONT_PRINTF((" TryNode aName = %s", (*aName).get())); - // - // check the specified font (foundry-family-registry-encoding) - // - if (aName->IsEmpty()) { - return nsnull; - } - nsFontXlib* font; - - nsCStringKey key(*aName); - nsFontNodeXlib* node = (nsFontNodeXlib*) mFontMetricsContext->mFFRENodes.Get(&key); - if (!node) { - nsCAutoString pattern; - FFREToXLFDPattern(*aName, pattern); - nsFontNodeArrayXlib nodes; - GetFontNames(mFontMetricsContext, pattern.get(), PR_FALSE, mFontMetricsContext->mForceOutlineScaledFonts, &nodes); - // no need to call mFontMetricsContext->mFFRENodes.Put() since GetFontNames already did - if (nodes.Count() > 0) { - // This assertion is not spurious; when searching for an FFRE - // like -*-courier-iso8859-1 TryNodes should be called not TryNode - NS_ASSERTION((nodes.Count() == 1), "unexpected number of nodes"); - node = nodes.GetElement(0); - } - else { - // add a dummy node to the hash table to avoid calling XListFonts again - node = new nsFontNodeXlib(); - if (!node) { - return nsnull; - } - mFontMetricsContext->mFFRENodes.Put(&key, node); - node->mDummy = 1; - } - } - - if (node) { - font = SearchNode(node, aChar); - if (font && font->SupportsChar(aChar)) - return font; - } - - // - // do not check related sub-planes for UserDefined - // - if (mIsUserDefined) { - return nsnull; - } - // - // check related sub-planes (wild-card the encoding) - // - nsCAutoString ffreName(*aName); - FFRESubstituteEncoding(ffreName, "*"); - FIND_FONT_PRINTF((" TrySubplane: wild-card the encoding")); - font = TryNodes(ffreName, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::TryLangGroup(nsIAtom* aLangGroup, nsCString* aName, PRUnichar aChar) -{ - // - // for this family check related registry-encoding (for the language) - // - FIND_FONT_PRINTF((" TryLangGroup lang group = %s, aName = %s", - atomToName(aLangGroup), (*aName).get())); - if (aName->IsEmpty()) { - return nsnull; - } - nsFontXlib* font = FindLangGroupFont(aLangGroup, aChar, aName); - return font; -} - -nsFontXlib* -nsFontMetricsXlib::TryFamily(nsCString* aName, PRUnichar aChar) -{ - // - // check the patterh "*-familyname-registry-encoding" for language - // - nsFontFamilyXlib* family = FindFamily(mFontMetricsContext, aName); - if (family) { - // try family name of language group first - nsCAutoString FFREName("*-"); - FFREName.Append(*aName); - FFREName.Append("-*-*"); - FIND_FONT_PRINTF((" TryFamily %s with lang group = %s", (*aName).get(), - atomToName(mLangGroup))); - nsFontXlib* font = TryLangGroup(mLangGroup, &FFREName, aChar); - if(font) { - return font; - } - - // then try family name regardless of language group - nsFontNodeArrayXlib* nodes = &family->mNodes; - PRInt32 n = nodes->Count(); - for (PRInt32 i = 0; i < n; i++) { - FIND_FONT_PRINTF((" TryFamily %s", nodes->GetElement(i)->mName.get())); - nsFontXlib* font = SearchNode(nodes->GetElement(i), aChar); - if (font && font->SupportsChar(aChar)) { - return font; - } - } - } - - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::TryAliases(nsCString* aAlias, PRUnichar aChar) -{ - nsCStringKey key(*aAlias); - char* name = (char*) mFontMetricsContext->mAliases.Get(&key); - if (name) { - nsCAutoString str(name); - return TryFamily(&str, aChar); - } - - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::FindUserDefinedFont(PRUnichar aChar) -{ - if (mIsUserDefined) { - FIND_FONT_PRINTF((" FindUserDefinedFont")); - nsFontXlib* font = TryNode(&mUserDefined, aChar); - mIsUserDefined = PR_FALSE; - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::FindStyleSheetSpecificFont(PRUnichar aChar) -{ - FIND_FONT_PRINTF((" FindStyleSheetSpecificFont")); - while (mFontsIndex < mFonts.Count()) { - if (mFontIsGeneric[mFontsIndex]) { - return nsnull; - } - nsCString* familyName = mFonts.CStringAt(mFontsIndex); - - /* - * count hyphens - * XXX It might be good to try to pre-cache this information instead - * XXX of recalculating it on every font access! - */ - const char* str = familyName->get(); - FIND_FONT_PRINTF((" familyName = %s", str)); - PRUint32 len = familyName->Length(); - int hyphens = 0; - for (PRUint32 i = 0; i < len; i++) { - if (str[i] == '-') { - hyphens++; - } - } - - /* - * if there are 3 hyphens, the name is in FFRE form - * (foundry-family-registry-encoding) - * ie: something like this: - * - * adobe-times-iso8859-1 - * - * otherwise it is something like - * - * times new roman - */ - nsFontXlib* font; - if (hyphens == 3) { - font = TryNode(familyName, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - else { - font = TryFamily(familyName, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - font = TryAliases(familyName, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - // bug 42917: increment only after all of the above fails - mFontsIndex++; - } - - return nsnull; -} - -static void -PrefEnumCallback(const char* aName, void* aClosure) -{ - nsFontSearch* s = (nsFontSearch*) aClosure; - nsFontMetricsXlibContext *aFmctx = s->mMetrics->mFontMetricsContext; - - if (s->mFont) { - NS_ASSERTION(s->mFont->SupportsChar(s->mChar), "font supposed to support this char"); - return; - } - nsXPIDLCString value; - aFmctx->mPref->CopyCharPref(aName, getter_Copies(value)); - nsCAutoString name; - if (value.get()) { - name = value; - FIND_FONT_PRINTF((" PrefEnumCallback")); - s->mFont = s->mMetrics->TryNode(&name, s->mChar); - if (s->mFont) { - NS_ASSERTION(s->mFont->SupportsChar(s->mChar), "font supposed to support this char"); - return; - } - s->mFont = s->mMetrics->TryLangGroup(s->mMetrics->mLangGroup, &name, s->mChar); - if (s->mFont) { - NS_ASSERTION(s->mFont->SupportsChar(s->mChar), "font supposed to support this char"); - return; - } - } - aFmctx->mPref->CopyDefaultCharPref(aName, getter_Copies(value)); - if (value.get() && (!name.Equals(value))) { - name = value; - FIND_FONT_PRINTF((" PrefEnumCallback:default")); - s->mFont = s->mMetrics->TryNode(&name, s->mChar); - if (s->mFont) { - NS_ASSERTION(s->mFont->SupportsChar(s->mChar), "font supposed to support this char"); - return; - } - s->mFont = s->mMetrics->TryLangGroup(s->mMetrics->mLangGroup, &name, s->mChar); - NS_ASSERTION(s->mFont ? s->mFont->SupportsChar(s->mChar) : 1, "font supposed to support this char"); - } -} - -nsFontXlib* -nsFontMetricsXlib::FindStyleSheetGenericFont(PRUnichar aChar) -{ - FIND_FONT_PRINTF((" FindStyleSheetGenericFont")); - nsFontXlib* font; - - if (mTriedAllGenerics) { - return nsnull; - } - - // - // find font based on document's lang group - // - font = FindLangGroupPrefFont(mLangGroup, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - - // - // Asian smart quote glyphs are much too large for western - // documents so if this is a single byte document add a - // special "font" to tranliterate those chars rather than - // possibly find them in double byte fonts - // - // (risk management: since we are close to a ship point we have a - // control (mAllowDoubleByteSpecialChars) to disable this new feature) - // -if (mFontMetricsContext->mAllowDoubleByteSpecialChars) { - if (!mDocConverterType) { - if (mLoadedFontsCount) { - FIND_FONT_PRINTF(("just use the 1st converter type")); - nsFontXlib* first_font = mLoadedFonts[0]; - if (first_font->mCharSetInfo) { - mDocConverterType = first_font->mCharSetInfo->Convert; - if (mDocConverterType == SingleByteConvert ) { - FIND_FONT_PRINTF(("single byte converter for %s", atomToName(mLangGroup))); - } - else { - FIND_FONT_PRINTF(("double byte converter for %s", atomToName(mLangGroup))); - } - } - } - if (!mDocConverterType) { - mDocConverterType = SingleByteConvert; - } - if (mDocConverterType == SingleByteConvert) { - // before we put in the transliterator to disable double byte special chars - // add the x-western font before the early transliterator - // to get the EURO sign (hack) - - nsFontXlib* western_font = nsnull; - if (mLangGroup != mFontMetricsContext->mWesternLocale) - western_font = FindLangGroupPrefFont(mFontMetricsContext->mWesternLocale, aChar); - - // add the symbol font before the early transliterator - // to get the bullet (hack) - nsCAutoString symbol_ffre("*-symbol-adobe-fontspecific"); - nsFontXlib* symbol_font = TryNodes(symbol_ffre, 0x0030); - - // Add the Adobe Euro fonts before the early transliterator - nsCAutoString euro_ffre("*-euro*-adobe-fontspecific"); - nsFontXlib* euro_font = TryNodes(euro_ffre, 0x20AC); - - // add the early transliterator - // to avoid getting Japanese "special chars" such as smart - // since they are very oversized compared to western fonts - nsFontXlib* sub_font = FindSubstituteFont(aChar); - NS_ASSERTION(sub_font, "failed to get a special chars substitute font"); - if (sub_font) { - sub_font->mCCMap = mFontMetricsContext->mDoubleByteSpecialCharsCCMap; - AddToLoadedFontsList(sub_font); - } - if (western_font && CCMAP_HAS_CHAR(western_font->mCCMap, aChar)) { - return western_font; - } - else if (symbol_font && CCMAP_HAS_CHAR(symbol_font->mCCMap, aChar)) { - return symbol_font; - } - else if (euro_font && CCMAP_HAS_CHAR(euro_font->mCCMap, aChar)) { - return euro_font; - } - else if (sub_font && CCMAP_HAS_CHAR(sub_font->mCCMap, aChar)) { - FIND_FONT_PRINTF((" transliterate special chars for single byte docs")); - return sub_font; - } - } - } -} - - // - // find font based on user's locale's lang group - // if different from documents locale - if (mFontMetricsContext->mUsersLocale != mLangGroup) { - FIND_FONT_PRINTF((" find font based on user's locale's lang group")); - font = FindLangGroupPrefFont(mFontMetricsContext->mUsersLocale, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - - // - // Search all font prefs for generic - // - nsCAutoString prefix("font.name."); - prefix.Append(*mGeneric); - nsFontSearch search = { this, aChar, nsnull }; - FIND_FONT_PRINTF((" Search all font prefs for generic")); - mFontMetricsContext->mPref->EnumerateChildren(prefix.get(), PrefEnumCallback, &search); - if (search.mFont) { - NS_ASSERTION(search.mFont->SupportsChar(aChar), "font supposed to support this char"); - return search.mFont; - } - - // - // Search all font prefs - // - // find based on all prefs (no generic part (eg: sans-serif)) - nsCAutoString allPrefs("font.name."); - search.mFont = nsnull; - FIND_FONT_PRINTF((" Search all font prefs")); - mFontMetricsContext->mPref->EnumerateChildren(allPrefs.get(), PrefEnumCallback, &search); - if (search.mFont) { - NS_ASSERTION(search.mFont->SupportsChar(aChar), "font supposed to support this char"); - return search.mFont; - } - - mTriedAllGenerics = 1; - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::FindAnyFont(PRUnichar aChar) -{ - FIND_FONT_PRINTF((" FindAnyFont")); - - // XXX If we get to this point, that means that we have exhausted all the - // families in the lists. Maybe we should try a list of fonts that are - // specific to the vendor of the X server here. Because XListFonts for the - // whole list is very expensive on some Unixes. - - /* - * Try all the fonts on the system. - */ - nsresult res = GetAllFontNames(mFontMetricsContext); - if (NS_FAILED(res)) - return nsnull; - - PRInt32 n = mFontMetricsContext->mGlobalList.Count(); - for (PRInt32 i = 0; i < n; i++) { - nsFontXlib* font = SearchNode(mFontMetricsContext->mGlobalList.GetElement(i), aChar); - if (font && font->SupportsChar(aChar)) { - // XXX We should probably write this family name out to disk, so that - // we can use it next time. I.e. prefs file or something. - return font; - } - } - - // future work: - // to properly support the substitute font we - // need to indicate here that all fonts have been tried - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::FindSubstituteFont(PRUnichar aChar) -{ - if (!mSubstituteFont) { - for (int i = 0; i < mLoadedFontsCount; i++) { - if (CCMAP_HAS_CHAR(mLoadedFonts[i]->mCCMap, 'a')) { - mSubstituteFont = new nsFontXlibSubstitute(mLoadedFonts[i]); - break; - } - } - // Currently the substitute font does not have a glyph map. - // This means that even if we have already checked all fonts - // for a particular character the mLoadedFonts will not know it. - // Thus we reparse *all* font glyph maps every time we see - // a character that ends up using a substitute font. - // future work: - // create an empty mCCMap and every time we determine a - // character will get its "glyph" from the substitute font - // mark that character in the mCCMap. - } - // mark the mCCMap to indicate that this character has a "glyph" - - // If we know that mLoadedFonts has every font's glyph map loaded - // then we can now set all the bit in the substitute font's glyph map - // and thus direct all umapped characters to the substitute - // font (without the font search). - // if tried all glyphs { - // create a substitute font with all bits set - // set all bits in mCCMap - // } - - return mSubstituteFont; -} - -// -// find font based on lang group -// - -nsFontXlib* -nsFontMetricsXlib::FindLangGroupPrefFont(nsIAtom* aLangGroup, PRUnichar aChar) -{ - nsFontXlib* font; - // - // get the font specified in prefs - // - nsCAutoString prefix("font.name."); - prefix.Append(*mGeneric); - if (aLangGroup) { - // check user set pref - nsCAutoString pref = prefix; - pref.Append(char('.')); - const char* langGroup = nsnull; - aLangGroup->GetUTF8String(&langGroup); - pref.Append(langGroup); - nsXPIDLCString value; - mFontMetricsContext->mPref->CopyCharPref(pref.get(), getter_Copies(value)); - nsCAutoString str; - nsCAutoString str_user; - if (value.get()) { - str = value.get(); - str_user = value.get(); - FIND_FONT_PRINTF((" user pref %s = %s", pref.get(), str.get())); - font = TryNode(&str, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - font = TryLangGroup(aLangGroup, &str, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - // check factory set pref - mFontMetricsContext->mPref->CopyDefaultCharPref(pref.get(), getter_Copies(value)); - if (value.get()) { - str = value.get(); - // check if we already tried this name - if (str != str_user) { - FIND_FONT_PRINTF((" default pref %s = %s", pref.get(), str.get())); - font = TryNode(&str, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - font = TryLangGroup(aLangGroup, &str, aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - } - } - - // - // find any style font based on lang group - // - FIND_FONT_PRINTF((" find font based on lang group")); - font = FindLangGroupFont(aLangGroup, aChar, nsnull); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - - return nsnull; -} - -nsFontXlib* -nsFontMetricsXlib::FindLangGroupFont(nsIAtom* aLangGroup, PRUnichar aChar, nsCString *aName) -{ - nsFontXlib* font; - - FIND_FONT_PRINTF((" lang group = %s", atomToName(aLangGroup))); - - // scan mCharSetMap for encodings with matching lang groups - const nsFontCharSetMapXlib* charSetMap; - for (charSetMap=mFontMetricsContext->mCharSetMap; charSetMap->mName; charSetMap++) { - nsFontLangGroupXlib* fontLangGroup = charSetMap->mFontLangGroup; - - if ((!fontLangGroup) || (!fontLangGroup->mFontLangGroupName)) { - continue; - } - - if (!charSetMap->mInfo->mLangGroup) { - SetCharsetLangGroup(mFontMetricsContext, charSetMap->mInfo); - } - - if (!fontLangGroup->mFontLangGroupAtom) { - SetFontLangGroupInfo(mFontMetricsContext, charSetMap); - } - - // if font's langGroup is different from requested langGroup, continue. - // An exception is that font's langGroup ZHTWHK is regarded as matching - // both ZHTW and ZHHK (Freetype2 and Solaris). - if ((aLangGroup != fontLangGroup->mFontLangGroupAtom) && - (aLangGroup != charSetMap->mInfo->mLangGroup) && - (fontLangGroup->mFontLangGroupAtom != mFontMetricsContext->mZHTWHK || - (aLangGroup != mFontMetricsContext->mZHHK && aLangGroup != mFontMetricsContext->mZHTW))) { - continue; - } - // look for a font with this charset (registry-encoding) & char - // - nsCAutoString ffreName; - if(aName) { - // if aName was specified so call TryNode() not TryNodes() - ffreName.Assign(*aName); - FFRESubstituteCharset(ffreName, charSetMap->mName); - FIND_FONT_PRINTF((" %s ffre = %s", charSetMap->mName, ffreName.get())); - if(aName->First() == '*') { - // called from TryFamily() - font = TryNodes(ffreName, aChar); - } else { - font = TryNode(&ffreName, aChar); - } - NS_ASSERTION(font ? font->SupportsChar(aChar) : 1, "font supposed to support this char"); - } else { - // no name was specified so call TryNodes() for this charset - ffreName.Assign("*-*-*-*"); - FFRESubstituteCharset(ffreName, charSetMap->mName); - FIND_FONT_PRINTF((" %s ffre = %s", charSetMap->mName, ffreName.get())); - font = TryNodes(ffreName, aChar); - NS_ASSERTION(font ? font->SupportsChar(aChar) : 1, "font supposed to support this char"); - } - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - - return nsnull; -} - -/* - * First we try to load the user-defined font, if the user-defined charset - * has been selected in the menu. - * - * Next, we try the fonts listed in the font-family property (FindStyleSheetSpecificFont). - * - * Next, we try any CSS generic font encountered in the font-family list and - * all of the fonts specified by the user for the generic (FindStyleSheetGenericFont). - * - * Next, we try all of the fonts on the system (FindAnyFont). This is - * expensive on some Unixes. - * - * Finally, we try to create a substitute font that offers substitute glyphs - * for the characters (FindSubstituteFont). - */ -nsFontXlib* -nsFontMetricsXlib::FindFont(PRUnichar aChar) -{ - FIND_FONT_PRINTF(("\nFindFont(%c/0x%04x)", aChar, aChar)); - - // If this is is the 'unknown' char (ie: converter could not - // convert it) there is no sense in searching any further for - // a font. Just returning mWesternFont - if (aChar == UCS2_NOMAPPING) { - FIND_FONT_PRINTF((" ignore the 'UCS2_NOMAPPING' character, return mWesternFont")); - return mWesternFont; - } - - nsFontXlib* font = FindUserDefinedFont(aChar); - if (!font) { - font = FindStyleSheetSpecificFont(aChar); - if (!font) { - font = FindStyleSheetGenericFont(aChar); - if (!font) { - font = FindAnyFont(aChar); - if (!font) { - font = FindSubstituteFont(aChar); - } - } - } - } - -#ifdef NS_FONT_DEBUG_CALL_TRACE - if (gFontDebug & NS_FONT_DEBUG_CALL_TRACE) { - printf("FindFont(%04X)[", aChar); - for (PRInt32 i = 0; i < mFonts.Count(); i++) { - printf("%s, ", mFonts.CStringAt(i)->get()); - } - printf("]\nreturns "); - if (font) { - printf("%s\n", font->mName ? font->mName : "(substitute)"); - } - else { - printf("NULL\n"); - } - } -#endif - - return font; -} - - -// The Font Enumerator - -nsFontEnumeratorXlib::nsFontEnumeratorXlib() -{ -} - -NS_IMPL_ISUPPORTS1(nsFontEnumeratorXlib, nsIFontEnumerator) - -typedef struct EnumerateNodeInfo -{ - PRUnichar** mArray; - int mIndex; - nsIAtom* mLangGroup; - nsFontMetricsXlibContext *mFontMetricsContext; -} EnumerateNodeInfo; - -static PRIntn -EnumerateNode(void* aElement, void* aData) -{ - nsFontNodeXlib* node = (nsFontNodeXlib*) aElement; - EnumerateNodeInfo* info = (EnumerateNodeInfo*) aData; - nsFontMetricsXlibContext *aFmctx = info->mFontMetricsContext; - if (info->mLangGroup != aFmctx->mUserDefined) { - if (node->mCharSetInfo == aFmctx->mUnknown) { - return PR_TRUE; // continue - } - else if (info->mLangGroup != aFmctx->mUnicode) { - // if font's langGroup is different from requested langGroup, continue. - // An exception is that font's langGroup ZHTWHK(big5-1, big5-0) matches - // both ZHTW and ZHHK (Freetype2 and Solaris). - if (node->mCharSetInfo->mLangGroup != info->mLangGroup && - (node->mCharSetInfo->mLangGroup != aFmctx->mZHTWHK || - (info->mLangGroup != aFmctx->mZHHK && - info->mLangGroup != aFmctx->mZHTW))) { - return PR_TRUE; // continue - } - } - // else { - // if (lang == add-style-field) { - // consider it part of the lang group - // } - // else if (a Unicode font reports its lang group) { - // consider it part of the lang group - // } - // else if (lang's ranges in list of ranges) { - // consider it part of the lang group - // // Note: at present we have no way to do this test but we - // // could in the future and this would be the place to enable - // // to make the font show up in the preferences dialog - // } - // } - - } - PRUnichar** array = info->mArray; - int j = info->mIndex; - PRUnichar* str = ToNewUnicode(node->mName); - if (!str) { - for (j = j - 1; j >= 0; j--) { - nsMemory::Free(array[j]); - } - info->mIndex = 0; - return PR_FALSE; // stop - } - array[j] = str; - info->mIndex++; - - return PR_TRUE; // continue -} - -PR_BEGIN_EXTERN_C -static int -CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure) -{ - const PRUnichar* str1 = *((const PRUnichar**) aArg1); - const PRUnichar* str2 = *((const PRUnichar**) aArg2); - - // XXX add nsICollation stuff - - return nsCRT::strcmp(str1, str2); -} -PR_END_EXTERN_C - -static nsresult -EnumFonts(nsFontMetricsXlibContext *aFmctx, nsIAtom* aLangGroup, const char* aGeneric, PRUint32* aCount, - PRUnichar*** aResult) -{ - nsresult res = GetAllFontNames(aFmctx); - if (NS_FAILED(res)) - return res; - - PRUnichar** array = - (PRUnichar**) nsMemory::Alloc(aFmctx->mGlobalList.Count() * sizeof(PRUnichar*)); - if (!array) - return NS_ERROR_OUT_OF_MEMORY; - - EnumerateNodeInfo info = { array, 0, aLangGroup, aFmctx }; - if (!aFmctx->mGlobalList.EnumerateForwards(EnumerateNode, &info)) { - nsMemory::Free(array); - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_QuickSort(array, info.mIndex, sizeof(PRUnichar*), CompareFontNames, - nsnull); - - *aCount = info.mIndex; - if (*aCount) { - *aResult = array; - } - else { - nsMemory::Free(array); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsFontEnumeratorXlib::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - NS_ENSURE_ARG_POINTER(aCount); - *aCount = 0; - - return EnumFonts(global_fmctx, nsnull, nsnull, aCount, aResult); -} - -NS_IMETHODIMP -nsFontEnumeratorXlib::EnumerateFonts(const char* aLangGroup, - const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - NS_ENSURE_ARG_POINTER(aCount); - *aCount = 0; - - // aLangGroup=null or "" means any (i.e., don't care) - // aGeneric=null or "" means any (i.e, don't care) - nsCOMPtr langGroup; - if (aLangGroup && *aLangGroup) - langGroup = do_GetAtom(aLangGroup); - const char* generic = nsnull; - if (aGeneric && *aGeneric) - generic = aGeneric; - - // XXX still need to implement aLangGroup and aGeneric - return EnumFonts(global_fmctx, langGroup, generic, aCount, aResult); -} - -NS_IMETHODIMP -nsFontEnumeratorXlib::HaveFontFor(const char* aLangGroup, PRBool* aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = PR_FALSE; - NS_ENSURE_ARG_POINTER(aLangGroup); - - *aResult = PR_TRUE; // always return true for now. - // Finish me - ftang - return NS_OK; -} - -NS_IMETHODIMP -nsFontEnumeratorXlib::GetDefaultFont(const char *aLangGroup, - const char *aGeneric, PRUnichar **aResult) -{ - // aLangGroup=null or "" means any (i.e., don't care) - // aGeneric=null or "" means any (i.e, don't care) - - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsFontEnumeratorXlib::UpdateFontList(PRBool *updateFontList) -{ - *updateFontList = PR_FALSE; // always return false for now - return NS_OK; -} - -static -const nsFontCharSetMapXlib *GetCharSetMap(nsFontMetricsXlibContext *aFmctx, const char *aCharSetName) -{ - nsCStringKey charSetKey(aCharSetName); - const nsFontCharSetMapXlib* charSetMap = (const nsFontCharSetMapXlib *) aFmctx->mCharSetMaps.Get(&charSetKey); - if (!charSetMap) - charSetMap = aFmctx->mNoneCharSetMap; - return charSetMap; -} - -#ifdef MOZ_ENABLE_FREETYPE2 -static -void CharSetNameToCodeRangeBits(const char *aCharset, - PRUint32 *aCodeRange1, PRUint32 *aCodeRange2) -{ - nsFontCharSetMapXlib *charSetMap = GetCharSetMap(aFmctx, aCharset); - nsFontCharSetInfoXlib *charSetInfo = charSetMap->mInfo; - - *aCodeRange1 = charSetInfo->mCodeRange1Bits; - *aCodeRange2 = charSetInfo->mCodeRange2Bits; -} -#endif /* MOZ_ENABLE_FREETYPE2 */ diff --git a/mozilla/gfx/src/xlib/nsFontMetricsXlib.h b/mozilla/gfx/src/xlib/nsFontMetricsXlib.h deleted file mode 100644 index ecf5a5cccfe..00000000000 --- a/mozilla/gfx/src/xlib/nsFontMetricsXlib.h +++ /dev/null @@ -1,535 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Tony Tsui - * Tim Copperfield - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsFontMetricsXlib_h__ -#define nsFontMetricsXlib_h__ - -#include "nsIFontMetrics.h" -#include "nsIFontEnumerator.h" -#include "nsIDeviceContext.h" -#include "nsDeviceContextXlib.h" -#include "nsFont.h" -#include "nsString.h" -#include "nsUnitConversion.h" -#include "nsCRT.h" -#include "nsCOMPtr.h" -#include "nsRenderingContextXlib.h" -#include "nsICharRepresentable.h" -#include "nsCompressedCharMap.h" - -/* Undefine some CPP symbols which wrap not-yet-implemented code */ -#undef MOZ_ENABLE_FREETYPE2 -#undef USE_AASB -#undef USE_X11SHARED_CODE - -#ifdef USE_X11SHARED_CODE -/* XXX: I wish I would use the code in gfx/src/x11shared/ - unfortunately - * it is full of GDK/GTK+ dependices which makes it impossible to use it - * yet... ;-( - */ -#error not implemented yet -#include "nsXFontNormal.h" -#else -class nsX11FontNormal { -public: - nsX11FontNormal(Display *, XFontStruct *); - ~nsX11FontNormal(); - - void DrawText8(Drawable Drawable, GC GC, PRInt32, PRInt32, - const char *, PRUint32); - void DrawText16(Drawable Drawable, GC GC, PRInt32, PRInt32, - const XChar2b *, PRUint32); - PRBool GetXFontProperty(Atom, unsigned long *); - XFontStruct *GetXFontStruct(); - PRBool LoadFont(); - void TextExtents8(const char *, PRUint32, PRInt32*, PRInt32*, - PRInt32*, PRInt32*, PRInt32*); - void TextExtents16(const XChar2b *, PRUint32, PRInt32*, PRInt32*, - PRInt32*, PRInt32*, PRInt32*); - PRInt32 TextWidth8(const char *, PRUint32); - PRInt32 TextWidth16(const XChar2b *, PRUint32); - void UnloadFont(); - inline PRBool IsSingleByte() { return mIsSingleByte; }; -protected: - Display *mDisplay; /* Track |Display *| for this font - * (Xlib gfx supports multiple displays) */ - XFontStruct *mXFont; - PRBool mIsSingleByte; -}; - -/* XXX: Silly class rename hack to avoid issues with StaticBuild code and to - * keep the source clean until we can reuse the classes from gfx/src/x11shared/ - */ -#define nsXFont nsX11FontNormal -#define nsXFontNormal nsX11FontNormal -#endif /* USE_X11SHARED_CODE */ - -class nsFontXlib; -class nsXFont; -class nsRenderingContextXlib; -class nsIDrawingSurfaceXlib; - -/* nsFontMetricsXlibContext glue */ -class nsFontMetricsXlibContext; -nsresult CreateFontMetricsXlibContext(nsIDeviceContext *aDevice, PRBool printermode, nsFontMetricsXlibContext **aFontMetricsXlibContext); -void DeleteFontMetricsXlibContext(nsFontMetricsXlibContext *aFontMetricsXlibContext); - -#undef FONT_HAS_GLYPH -#define FONT_HAS_GLYPH(map, char) IS_REPRESENTABLE(map, char) -#define WEIGHT_INDEX(weight) (((weight) / 100) - 1) - -#define NS_FONT_DEBUG_LOAD_FONT 0x01 -#define NS_FONT_DEBUG_CALL_TRACE 0x02 -#define NS_FONT_DEBUG_FIND_FONT 0x04 -#define NS_FONT_DEBUG_SIZE_FONT 0x08 -#define NS_FONT_DEBUG_SCALED_FONT 0x10 -#define NS_FONT_DEBUG_BANNED_FONT 0x20 -#define NS_FONT_DEBUG_FONT_CATALOG 0x100 -#define NS_FONT_DEBUG_FONT_SCAN 0x200 -#define NS_FONT_DEBUG_FREETYPE_FONT 0x400 -#define NS_FONT_DEBUG_FREETYPE_GRAPHICS 0x800 - -#undef NS_FONT_DEBUG -#define NS_FONT_DEBUG 1 -#ifdef NS_FONT_DEBUG - -# define DEBUG_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, 0xFFFF) - -# define DEBUG_PRINTF_MACRO(x, type) \ - PR_BEGIN_MACRO \ - if (gFontDebug & (type)) { \ - printf x ; \ - printf(", %s %d\n", __FILE__, __LINE__); \ - } \ - PR_END_MACRO -#else -# define DEBUG_PRINTF_MACRO(x, type) \ - PR_BEGIN_MACRO \ - PR_END_MACRO -#endif - -#define FIND_FONT_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_FIND_FONT) - -#define SIZE_FONT_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_SIZE_FONT) - -#define SCALED_FONT_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_SCALED_FONT) - -#define BANNED_FONT_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_BANNED_FONT) - -#define FONT_CATALOG_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_FONT_CATALOG) - -#define FONT_SCAN_PRINTF(x) \ - PR_BEGIN_MACRO \ - if (gFontDebug & NS_FONT_DEBUG_FONT_SCAN) { \ - printf x ; \ - fflush(stdout); \ - } \ - PR_END_MACRO - -#define FREETYPE_FONT_PRINTF(x) \ - DEBUG_PRINTF_MACRO(x, NS_FONT_DEBUG_FREETYPE_FONT) - -typedef struct nsFontCharSetInfoXlib nsFontCharSetInfoXlib; - -typedef int (*nsFontCharSetConverterXlib)(nsFontCharSetInfoXlib* aSelf, - XFontStruct* aFont, const PRUnichar* aSrcBuf, PRInt32 aSrcLen, - char* aDestBuf, PRInt32 aDestLen); - -struct nsFontCharSetXlib; -struct nsFontFamilyXlib; -struct nsFontNodeXlib; -struct nsFontStretchXlib; -struct nsFontWeightXlib; - -class nsFontXlibUserDefined; -class nsFontMetricsXlib; -#ifdef MOZ_ENABLE_FREETYPE2 -class nsFreeTypeFace; -#endif /* MOZ_ENABLE_FREETYPE2 */ - -struct nsFontStretchXlib -{ - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - void SortSizes(void); - - nsFontXlib **mSizes; - PRUint16 mSizesAlloc; - PRUint16 mSizesCount; - - char* mScalable; - PRBool mOutlineScaled; - nsVoidArray mScaledFonts; -#ifdef MOZ_ENABLE_FREETYPE2 - nsFreeTypeFace *mFreeTypeFaceID; -#endif /* MOZ_ENABLE_FREETYPE2 */ -}; - -struct nsFontStyleXlib -{ - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - void FillWeightHoles(void); - - nsFontWeightXlib *mWeights[9]; -}; - -struct nsFontWeightXlib -{ - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - void FillStretchHoles(void); - - nsFontStretchXlib *mStretches[9]; -}; - -struct nsFontNodeXlib -{ - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - void FillStyleHoles(void); - - nsCAutoString mName; - nsFontCharSetInfoXlib *mCharSetInfo; - nsFontStyleXlib *mStyles[3]; - PRUint8 mHolesFilled; - PRUint8 mDummy; -}; - -class nsFontNodeArrayXlib : public nsAutoVoidArray -{ -public: - nsFontNodeArrayXlib() {}; - - nsFontNodeXlib *GetElement(PRInt32 aIndex) - { - return (nsFontNodeXlib *) ElementAt(aIndex); - }; -}; - -/* - * Font Language Groups - * - * These Font Language Groups (FLG) indicate other related - * encodings to look at when searching for glyphs - * - */ -typedef struct nsFontLangGroupXlib { - const char *mFontLangGroupName; - nsIAtom* mFontLangGroupAtom; -} nsFontLangGroup; - -struct nsFontCharSetMapXlib -{ - const char* mName; - nsFontLangGroupXlib* mFontLangGroup; - nsFontCharSetInfoXlib* mInfo; -}; - -class nsFontXlib -{ -public: - nsFontXlib(); - nsFontXlib(nsFontXlib *); - virtual ~nsFontXlib(); - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - nsFontMetricsXlibContext *mFontMetricsContext; - - void LoadFont(void); - PRBool IsEmptyFont(XFontStruct*); - - inline int SupportsChar(PRUnichar aChar) - { return mCCMap && CCMAP_HAS_CHAR(mCCMap, aChar); }; - - virtual XFontStruct *GetXFontStruct(void); - virtual nsXFont *GetXFont(void); - virtual PRBool GetXFontIs10646(void); -#ifdef MOZ_ENABLE_FREETYPE2 - virtual PRBool IsFreeTypeFont(void); -#endif /* MOZ_ENABLE_FREETYPE2 */ - virtual int GetWidth(const PRUnichar* aString, PRUint32 aLength) = 0; - virtual int DrawString(nsRenderingContextXlib *aContext, - nsIDrawingSurfaceXlib *aSurface, nscoord aX, - nscoord aY, const PRUnichar* aString, - PRUint32 aLength) = 0; -#ifdef MOZ_MATHML - // bounding metrics for a string - // remember returned values are not in app units - // - to emulate GetWidth () above - virtual nsresult - GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics) = 0; -#endif /* MOZ_MATHML */ - - PRUint16 *mCCMap; - nsFontCharSetInfoXlib *mCharSetInfo; - char *mName; - nsFontXlibUserDefined *mUserDefinedFont; - PRUint16 mSize; -#ifdef USE_AASB - PRUint16 mAABaseSize; -#endif /* USE_AASB */ - PRInt16 mBaselineAdjust; - - // these values are not in app units, they need to be scaled with - // nsIDeviceContext::DevUnitsToAppUnits() - PRInt16 mMaxAscent; - PRInt16 mMaxDescent; - -protected: - XFontStruct *mFont; - XFontStruct *mFontHolder; - nsXFont *mXFont; - PRPackedBool mAlreadyCalledLoadFont; -}; - -struct nsFontSwitchXlib { - // Simple wrapper on top of nsFontXlib for the moment - // Could hold other attributes of the font - nsFontXlib *mFontXlib; -}; - -typedef PRBool (*PR_CALLBACK nsFontSwitchCallbackXlib) - (const nsFontSwitchXlib *aFontSwitch, - const PRUnichar* aSubstring, - PRUint32 aSubstringLength, - void* aData); - -class nsFontMetricsXlib : public nsIFontMetrics -{ -public: - nsFontMetricsXlib(); - virtual ~nsFontMetricsXlib(); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup, - nsIDeviceContext* aContext); - NS_IMETHOD Destroy(); - - NS_IMETHOD GetXHeight(nscoord& aResult); - NS_IMETHOD GetSuperscriptOffset(nscoord& aResult); - NS_IMETHOD GetSubscriptOffset(nscoord& aResult); - NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize); - NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize); - - NS_IMETHOD GetHeight(nscoord &aHeight); -#ifdef FONT_LEADING_APIS_V2 - NS_IMETHOD GetInternalLeading(nscoord &aLeading); - NS_IMETHOD GetExternalLeading(nscoord &aLeading); -#else - NS_IMETHOD GetNormalLineHeight(nscoord &aHeight); - NS_IMETHOD GetLeading(nscoord &aLeading); -#endif - NS_IMETHOD GetEmHeight(nscoord &aHeight); - NS_IMETHOD GetEmAscent(nscoord &aAscent); - NS_IMETHOD GetEmDescent(nscoord &aDescent); - NS_IMETHOD GetMaxHeight(nscoord &aHeight); - NS_IMETHOD GetMaxAscent(nscoord &aAscent); - NS_IMETHOD GetMaxDescent(nscoord &aDescent); - NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); - NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); - NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); - NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); - // Xlib probably has string length limits, but I can't be bothered - virtual PRInt32 GetMaxStringLength() { return PR_INT32_MAX; } - - NS_IMETHOD GetSpaceWidth(nscoord &aSpaceWidth); - NS_IMETHOD ResolveForwards(const PRUnichar* aString, PRUint32 aLength, - nsFontSwitchCallbackXlib aFunc, void* aData); - nsFontXlib* FindFont(PRUnichar aChar); - nsFontXlib* FindUserDefinedFont(PRUnichar aChar); - nsFontXlib* FindStyleSheetSpecificFont(PRUnichar aChar); - nsFontXlib* FindStyleSheetGenericFont(PRUnichar aChar); - nsFontXlib* FindLangGroupPrefFont(nsIAtom* aLangGroup, PRUnichar aChar); - nsFontXlib* FindLangGroupFont(nsIAtom* aLangGroup, PRUnichar aChar, nsCString* aName); - nsFontXlib* FindAnyFont(PRUnichar aChar); - nsFontXlib* FindSubstituteFont(PRUnichar aChar); - - nsFontXlib* SearchNode(nsFontNodeXlib* aNode, PRUnichar aChar); - nsFontXlib* TryAliases(nsCString* aName, PRUnichar aChar); - nsFontXlib* TryFamily(nsCString* aName, PRUnichar aChar); - nsFontXlib* TryNode(nsCString* aName, PRUnichar aChar); - nsFontXlib* TryNodes(nsACString &aFFREName, PRUnichar aChar); - nsFontXlib* TryLangGroup(nsIAtom* aLangGroup, nsCString* aName, PRUnichar aChar); - - nsFontXlib* AddToLoadedFontsList(nsFontXlib* aFont); - nsFontXlib* FindNearestSize(nsFontStretchXlib* aStretch, PRUint16 aSize); -#ifdef USE_AASB - nsFontXlib* GetAASBBaseFont(nsFontStretchXlib *aStretch, - nsFontCharSetInfoXlib* aCharSet); -#endif /* USE_AASB */ - nsFontXlib* PickASizeAndLoad(nsFontStretchXlib *aStretch, - nsFontCharSetInfoXlib *aCharSet, - PRUnichar aChar, - const char *aName); - - static nsresult FamilyExists(nsFontMetricsXlibContext *aFontMetricsContext, const nsString& aName); - - //friend struct nsFontXlib; - - nsFontXlib **mLoadedFonts; - PRUint16 mLoadedFontsAlloc; - PRUint16 mLoadedFontsCount; - - nsFontXlib *mSubstituteFont; - - nsCStringArray mFonts; - PRInt32 mFontsIndex; - nsAutoVoidArray mFontIsGeneric; - - nsCAutoString mDefaultFont; - nsCString *mGeneric; - nsCOMPtr mLangGroup; - nsCAutoString mUserDefined; - - PRUint8 mTriedAllGenerics; - PRUint8 mIsUserDefined; - - nsFontMetricsXlibContext *mFontMetricsContext; - nsIDeviceContext *mDeviceContext; - -protected: - void RealizeFont(); - nsFontXlib *LocateFont(PRUint32 aChar, PRInt32 & aCount); - - nsFontXlib *mWesternFont; - - nscoord mLeading; - nscoord mEmHeight; - nscoord mEmAscent; - nscoord mEmDescent; - nscoord mMaxHeight; - nscoord mMaxAscent; - nscoord mMaxDescent; - nscoord mMaxAdvance; - nscoord mXHeight; - nscoord mSuperscriptOffset; - nscoord mSubscriptOffset; - nscoord mStrikeoutSize; - nscoord mStrikeoutOffset; - nscoord mUnderlineSize; - nscoord mUnderlineOffset; - nscoord mSpaceWidth; - nscoord mAveCharWidth; - - PRUint16 mPixelSize; - PRUint8 mStretchIndex; - PRUint8 mStyleIndex; - nsFontCharSetConverterXlib mDocConverterType; -}; - -class nsFontEnumeratorXlib : public nsIFontEnumerator -{ -public: - nsFontEnumeratorXlib(); - NS_DECL_ISUPPORTS - NS_DECL_NSIFONTENUMERATOR -}; - -class nsHashKey; - -/* XXX: We can't include gfx/src/x11shared/nsFreeType.h because it relies on - * GDK/GTK+ includes which are not available in Xlib builds (fix is to remove - * the GDK/GTK+ dependicy from the code in gfx/src/x11shared/ ...) - */ -#ifndef MOZ_ENABLE_FREETYPE2 -/* - * Defines for the TrueType codepage bits. - * Used as a hint for the languages supported in a TrueType font. - */ - -/* - * ulCodePageRange1 - */ -#define TT_OS2_CPR1_LATIN1 (0x00000001) /* Latin 1 */ -#define TT_OS2_CPR1_LATIN2 (0x00000002) /* Latin 2: Eastern Europe */ -#define TT_OS2_CPR1_CYRILLIC (0x00000004) /* Cyrillic */ -#define TT_OS2_CPR1_GREEK (0x00000008) /* Greek */ -#define TT_OS2_CPR1_TURKISH (0x00000010) /* Turkish */ -#define TT_OS2_CPR1_HEBREW (0x00000020) /* Hebrew */ -#define TT_OS2_CPR1_ARABIC (0x00000040) /* Arabic */ -#define TT_OS2_CPR1_BALTIC (0x00000080) /* Windows Baltic */ -#define TT_OS2_CPR1_VIETNAMESE (0x00000100) /* Vietnamese */ - /* 9-15 Reserved for Alternate ANSI */ -#define TT_OS2_CPR1_THAI (0x00010000) /* Thai */ -#define TT_OS2_CPR1_JAPANESE (0x00020000) /* JIS/Japan */ -#define TT_OS2_CPR1_CHINESE_SIMP (0x00040000) /* Chinese: Simplified */ -#define TT_OS2_CPR1_KO_WANSUNG (0x00080000) /* Korean Wansung */ -#define TT_OS2_CPR1_CHINESE_TRAD (0x00100000) /* Chinese: Traditional */ -#define TT_OS2_CPR1_KO_JOHAB (0x00200000) /* Korean Johab */ - /* 22-28 Reserved for Alternate ANSI&OEM */ -#define TT_OS2_CPR1_MAC_ROMAN (0x20000000) /* Mac (US Roman) */ -#define TT_OS2_CPR1_OEM (0x40000000) /* OEM Character Set */ -#define TT_OS2_CPR1_SYMBOL (0x80000000) /* Symbol Character Set */ - -/* - * ulCodePageRange2 - */ /* 32-47 Reserved for OEM */ -#define TT_OS2_CPR2_GREEK (0x00010000) /* IBM Greek */ -#define TT_OS2_CPR2_RUSSIAN (0x00020000) /* MS-DOS Russian */ -#define TT_OS2_CPR2_NORDIC (0x00040000) /* MS-DOS Nordic */ -#define TT_OS2_CPR2_ARABIC (0x00080000) /* Arabic */ -#define TT_OS2_CPR2_CA_FRENCH (0x00100000) /* MS-DOS Canadian French */ -#define TT_OS2_CPR2_HEBREW (0x00200000) /* Hebrew */ -#define TT_OS2_CPR2_ICELANDIC (0x00400000) /* MS-DOS Icelandic */ -#define TT_OS2_CPR2_PORTUGESE (0x00800000) /* MS-DOS Portuguese */ -#define TT_OS2_CPR2_TURKISH (0x01000000) /* IBM Turkish */ -#define TT_OS2_CPR2_CYRILLIC (0x02000000)/*IBM Cyrillic; primarily Russian*/ -#define TT_OS2_CPR2_LATIN2 (0x04000000) /* Latin 2 */ -#define TT_OS2_CPR2_BALTIC (0x08000000) /* MS-DOS Baltic */ -#define TT_OS2_CPR2_GREEK_437G (0x10000000) /* Greek; former 437 G */ -#define TT_OS2_CPR2_ARABIC_708 (0x20000000) /* Arabic; ASMO 708 */ -#define TT_OS2_CPR2_WE_LATIN1 (0x40000000) /* WE/Latin 1 */ -#define TT_OS2_CPR2_US (0x80000000) /* US */ -#endif /* !MOZ_ENABLE_FREETYPE2 */ - -#endif /* !nsFontMetricsXlib_h__ */ - diff --git a/mozilla/gfx/src/xlib/nsGCCache.cpp b/mozilla/gfx/src/xlib/nsGCCache.cpp deleted file mode 100644 index a90f5e5f6d1..00000000000 --- a/mozilla/gfx/src/xlib/nsGCCache.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the Mozilla browser. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Mike Shaver - * Tomi Leppikangas - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include "nsGCCache.h" - -#include -#include - -/* The GC cache is shared among all windows, since it doesn't hog - any scarce resources (like colormap entries.) */ - -Region nsGCCacheXlib::copyRegion = 0; - -nsGCCacheXlib::nsGCCacheXlib() -{ - PR_INIT_CLIST(&GCCache); - PR_INIT_CLIST(&GCFreeList); - for (int i = 0; i < GC_CACHE_SIZE; i++) { - GCCacheEntryXlib *entry = new GCCacheEntryXlib(); - entry->gc=NULL; - PR_INSERT_LINK(&entry->clist, &GCFreeList); - } - DEBUG_METER(memset(&GCCacheStats, 0, sizeof(GCCacheStats));) -} - -void -nsGCCacheXlib::move_cache_entry(PRCList *clist) -{ - /* thread on the freelist, at the front */ - PR_REMOVE_LINK(clist); - PR_INSERT_LINK(clist, &GCFreeList); -} - -void -nsGCCacheXlib::free_cache_entry(PRCList *clist) -{ - GCCacheEntryXlib *entry = (GCCacheEntryXlib *)clist; - entry->gc->Release(); - if (entry->clipRegion) - ::XDestroyRegion(entry->clipRegion); - - /* thread on the freelist, at the front */ - PR_REMOVE_LINK(clist); - memset(entry, 0, sizeof(*entry)); - PR_INSERT_LINK(clist, &GCFreeList); -} - -nsGCCacheXlib::~nsGCCacheXlib() -{ - PRCList *head; - - ReportStats(); - - while (!PR_CLIST_IS_EMPTY(&GCCache)) { - head = PR_LIST_HEAD(&GCCache); - if (head == &GCCache) - break; - free_cache_entry(head); - } - - while (!PR_CLIST_IS_EMPTY(&GCFreeList)) { - head = PR_LIST_HEAD(&GCFreeList); - if (head == &GCFreeList) - break; - PR_REMOVE_LINK(head); - delete (GCCacheEntryXlib *)head; - } -} - -void -nsGCCacheXlib::ReportStats() { - DEBUG_METER( - fprintf(stderr, "GC Cache:\n\thits:"); - int hits = 0; - for (int i = 0; i < GC_CACHE_SIZE; i++) { - fprintf(stderr, " %4d", GCCacheStats.hits[i]); - hits+=GCCacheStats.hits[i]; - } - int total = hits + GCCacheStats.misses; - float percent = float(float(hits) / float(total)); - percent *= 100; - fprintf(stderr, "\n\thits: %d, misses: %d, hit percent: %f%%\n", - hits, GCCacheStats.misses, percent); - ); -} - - -void -nsGCCacheXlib::XCopyRegion(Region srca, Region dr_return) -{ - if (!copyRegion) copyRegion = ::XCreateRegion(); - ::XUnionRegion(srca, copyRegion, dr_return); -} - -/* Dispose of entries matching the given flags, compressing the GC cache */ -void nsGCCacheXlib::Flush(unsigned long flags) -{ - while (!PR_CLIST_IS_EMPTY(&GCCache)) { - PRCList *head = PR_LIST_HEAD(&GCCache); - if (head == &GCCache) - break; - GCCacheEntryXlib *entry = (GCCacheEntryXlib *)head; - if (entry->flags & flags) - free_cache_entry(head); - } -} - -xGC *nsGCCacheXlib::GetGC(Display *display, Drawable drawable, unsigned long flags, XGCValues *gcv, Region clipRegion) -{ - PRCList *iter; - GCCacheEntryXlib *entry; - DEBUG_METER(int i = 0;) - - for (iter = PR_LIST_HEAD(&GCCache); iter != &GCCache; - iter = PR_NEXT_LINK(iter)) { - - entry = (GCCacheEntryXlib *)iter; - if (flags == entry->flags && - !memcmp (gcv, &entry->gcv, sizeof (*gcv))) { - /* if there's a clipRegion, we have to match */ - - if ((clipRegion && entry->clipRegion && - ::XEqualRegion(clipRegion, entry->clipRegion)) || - /* and if there isn't, we can't have one */ - (!clipRegion && !entry->clipRegion)) { - - /* move to the front of the list, if needed */ - if (iter != PR_LIST_HEAD(&GCCache)) { - PR_REMOVE_LINK(iter); - PR_INSERT_LINK(iter, &GCCache); - } - DEBUG_METER(GCCacheStats.hits[i]++;) - - entry->gc->AddRef(); - return entry->gc; - } - } - DEBUG_METER(++i;) - } - - /* might need to forcibly free the LRU cache entry */ - if (PR_CLIST_IS_EMPTY(&GCFreeList)) { - DEBUG_METER(GCCacheStats.reclaim++); - move_cache_entry(PR_LIST_TAIL(&GCCache)); - } - - DEBUG_METER(GCCacheStats.misses++;) - - iter = PR_LIST_HEAD(&GCFreeList); - PR_REMOVE_LINK(iter); - PR_INSERT_LINK(iter, &GCCache); - entry = (GCCacheEntryXlib *)iter; - - if (!entry->gc) { - // No old GC, greate new - entry->gc = new xGC(display, drawable, flags, gcv); - entry->gc->AddRef(); // addref the newly created xGC - entry->flags = flags; - entry->gcv = *gcv; - entry->clipRegion = NULL; - //printf("creating new gc=%X\n",entry->gc); - } - else if (entry->gc->mRefCnt > 0) { - // Old GC still in use, create new - entry->gc->Release(); - entry->gc = new xGC(display, drawable, flags, gcv); - entry->gc->AddRef(); // addref the newly created xGC - entry->flags = flags; - entry->gcv = *gcv; - if (entry->clipRegion) - XDestroyRegion(entry->clipRegion); - entry->clipRegion = NULL; - //printf("creating new (use)gc=%X\n",entry->gc); - } - else { - ReuseGC(entry, flags, gcv); - } - - if (clipRegion) { - entry->clipRegion = ::XCreateRegion(); - XCopyRegion(clipRegion, entry->clipRegion); - if (entry->clipRegion) - ::XSetRegion(display, entry->gc->mGC, entry->clipRegion); - /* XXX what if it fails? */ - } - - entry->gc->AddRef(); - return entry->gc; -} - -void nsGCCacheXlib::ReuseGC(GCCacheEntryXlib *entry, unsigned long flags, XGCValues *gcv) -{ - // We have old GC, reuse it and check what - // we have to change - - if (entry->clipRegion) { - // set it to none here and then set the clip region with - // gdk_gc_set_clip_region in GetGC() - gcv->clip_mask = None; - flags |= GCClipMask; - ::XDestroyRegion(entry->clipRegion); - entry->clipRegion = NULL; - } - - if (flags != 0) { - ::XChangeGC(entry->gc->mDisplay, entry->gc->mGC, - flags, gcv); - } - entry->flags = flags; entry->gcv = *gcv; -} diff --git a/mozilla/gfx/src/xlib/nsGCCache.h b/mozilla/gfx/src/xlib/nsGCCache.h deleted file mode 100644 index 16de97ceb05..00000000000 --- a/mozilla/gfx/src/xlib/nsGCCache.h +++ /dev/null @@ -1,148 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the Mozilla browser. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Mike Shaver - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#ifndef nsGCCacheXlib_h___ -#define nsGCCacheXlib_h___ - -#include -#include - -#include "nscore.h" -#include "nsDebug.h" -#include "prclist.h" -#include -#include - -#define countof(x) ((int)(sizeof(x) / sizeof (*x))) -#define GC_CACHE_SIZE 64 - -#ifdef DEBUG -#define DEBUG_METER(x) x -#else -#define DEBUG_METER(x) -#endif - -class nsGCCacheXlib; - -class xGC { - friend class nsGCCacheXlib; - -public: - xGC(Display *display, Drawable d, unsigned long valuemask, XGCValues *values) - { - mRefCnt = 0; - mDisplay = display; - mGC = ::XCreateGC(display, d, valuemask, values); - } - - virtual ~xGC() { - ::XFreeGC(mDisplay, mGC); - } - - PRInt32 AddRef(void) { -#ifdef DEBUG - if(mRefCnt>400) abort(); -#endif /* DEBUG */ - NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); - ++mRefCnt; - return mRefCnt; - } - PRInt32 Release(void) { - NS_PRECONDITION(0 != mRefCnt, "dup release"); - --mRefCnt; - if (mRefCnt == 0) { - mRefCnt = 1; /* stabilize */ - delete this; - return 0; - } - return mRefCnt; - } - - //operator GC() { return mGC; } - operator const GC() { return (const GC)mGC; } - -private: - PRInt32 mRefCnt; - Display *mDisplay; - GC mGC; -}; - - -struct GCCacheEntryXlib -{ - PRCList clist; - unsigned long flags; - XGCValues gcv; - Region clipRegion; - xGC *gc; -}; - -class nsGCCacheXlib -{ - public: - nsGCCacheXlib(); - virtual ~nsGCCacheXlib(); - - void Flush(unsigned long flags); - - xGC *GetGC(Display *display, Window window, unsigned long flags, XGCValues *gcv, Region clipRegion); - -private: - void ReuseGC(GCCacheEntryXlib *entry, unsigned long flags, XGCValues *gcv); - PRCList GCCache; - PRCList GCFreeList; - void free_cache_entry(PRCList *clist); - void move_cache_entry(PRCList *clist); - static void XCopyRegion(Region src, Region dr_return); - static Region copyRegion; - void ReportStats(); - - DEBUG_METER( - struct { - int hits[GC_CACHE_SIZE]; - int misses; - int reclaim; - } GCCacheStats; - ) - -}; - -#endif diff --git a/mozilla/gfx/src/xlib/nsGfxFactoryXlib.cpp b/mozilla/gfx/src/xlib/nsGfxFactoryXlib.cpp deleted file mode 100644 index 755e34deb00..00000000000 --- a/mozilla/gfx/src/xlib/nsGfxFactoryXlib.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Tony Tsui - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIGenericFactory.h" -#include "nsIModule.h" -#include "nsCOMPtr.h" -#include "nsGfxCIID.h" - -#include "nsBlender.h" -#include "nsFontMetricsXlib.h" -#include "nsRenderingContextXlib.h" -// aka nsDeviceContextSpecXlib.h -#include "nsDeviceContextSpecXlib.h" -#include "nsScriptableRegion.h" -#include "nsDeviceContextXlib.h" -#include "nsImageXlib.h" -#include "nsFontList.h" -#include "nsPrintOptionsXlib.h" -#include "nsPrintSession.h" -#include "gfxImageFrame.h" - -// objects that just require generic constructors - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsXlib, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorXlib) -NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) -NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame) - -// our custom constructors - -static nsresult nsScriptableRegionConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult) -{ - nsresult rv; - - nsIScriptableRegion *inst = nsnull; - - if ( NULL == aResult ) - { - rv = NS_ERROR_NULL_POINTER; - return rv; - } - *aResult = NULL; - if (NULL != aOuter) - { - rv = NS_ERROR_NO_AGGREGATION; - return rv; - } - // create an nsRegionXlib and get the scriptable region from it - nsCOMPtr rgn; - NS_NEWXPCOM(rgn, nsRegionXlib); - if (rgn != nsnull) - { - nsCOMPtr scriptableRgn = new nsScriptableRegion(rgn); - inst = scriptableRgn; - } - if (NULL == inst) - { - rv = NS_ERROR_OUT_OF_MEMORY; - return rv; - } - NS_ADDREF(inst); - rv = inst->QueryInterface(aIID, aResult); - NS_RELEASE(inst); - - return rv; -} - -static const nsModuleComponentInfo components[] = -{ - { "Xlib Font Metrics", - NS_FONT_METRICS_CID, - // "@mozilla.org/gfx/font_metrics/xlib;1", - "@mozilla.org/gfx/fontmetrics;1", - nsFontMetricsXlibConstructor }, - { "Xlib Device Context", - NS_DEVICE_CONTEXT_CID, - // "@mozilla.org/gfx/device_context/xlib;1", - "@mozilla.org/gfx/devicecontext;1", - nsDeviceContextXlibConstructor }, - { "Xlib Rendering Context", - NS_RENDERING_CONTEXT_CID, - // "@mozilla.org/gfx/rendering_context/xlib;1", - "@mozilla.org/gfx/renderingcontext;1", - nsRenderingContextXlibConstructor }, - { "Xlib Image", - NS_IMAGE_CID, - // "@mozilla.org/gfx/image/xlib;1", - "@mozilla.org/gfx/image;1", - nsImageXlibConstructor }, - { "Xlib Region", - NS_REGION_CID, - "@mozilla.org/gfx/region/xlib;1", - nsRegionXlibConstructor }, - { "Scriptable Region", - NS_SCRIPTABLE_REGION_CID, - // "@mozilla.org/gfx/scriptable_region;1", - "@mozilla.org/gfx/region;1", - nsScriptableRegionConstructor }, - { "Blender", - NS_BLENDER_CID, - // "@mozilla.org/gfx/blender;1", - "@mozilla.org/gfx/blender;1", - nsBlenderConstructor }, - { "Xlib Device Context Spec", - NS_DEVICE_CONTEXT_SPEC_CID, - // "@mozilla.org/gfx/device_context_spec/xlib;1", - "@mozilla.org/gfx/devicecontextspec;1", - nsDeviceContextSpecXlibConstructor }, - { "PrintSettings Service", - NS_PRINTSETTINGSSERVICE_CID, - // "@mozilla.org/gfx/printsettings-service;1", - "@mozilla.org/gfx/printsettings-service;1", - nsPrintOptionsXlibConstructor }, - { "Xlib Font Enumerator", - NS_FONT_ENUMERATOR_CID, - // "@mozilla.org/gfx/font_enumerator/xlib;1", - "@mozilla.org/gfx/fontenumerator;1", - nsFontEnumeratorXlibConstructor }, - { "Font List", - NS_FONTLIST_CID, - // "@mozilla.org/gfx/fontlist;1" - NS_FONTLIST_CONTRACTID, - nsFontListConstructor }, - { "Xlib Printer Enumerator", - NS_PRINTER_ENUMERATOR_CID, - // "@mozilla.org/gfx/printer_enumerator/xlib;1", - "@mozilla.org/gfx/printerenumerator;1", - nsPrinterEnumeratorXlibConstructor }, - { "windows image frame", - GFX_IMAGEFRAME_CID, - "@mozilla.org/gfx/image/frame;2", - gfxImageFrameConstructor, }, - { "Print Session", - NS_PRINTSESSION_CID, - "@mozilla.org/gfx/printsession;1", - nsPrintSessionConstructor } -}; - -PR_STATIC_CALLBACK(void) -nsGfxXlibModuleDtor(nsIModule *self) -{ -} - -NS_IMPL_NSGETMODULE_WITH_DTOR(nsGfxXlibModule, components, nsGfxXlibModuleDtor) diff --git a/mozilla/gfx/src/xlib/nsImageXlib.cpp b/mozilla/gfx/src/xlib/nsImageXlib.cpp deleted file mode 100644 index bce3d1fbcea..00000000000 --- a/mozilla/gfx/src/xlib/nsImageXlib.cpp +++ /dev/null @@ -1,1685 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Stuart Parmenter - * Tim Rowley -- 8bit alpha compositing - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsImageXlib.h" -#include "nsDrawingSurfaceXlib.h" -#include "nsRenderingContextXlib.h" -#include "xlibrgb.h" -#include "prlog.h" -#include "nsRect.h" -#include "drawers.h" -#include "imgScaler.h" - -#define IsFlagSet(a,b) ((a) & (b)) - -#ifdef PR_LOGGING -static PRLogModuleInfo *ImageXlibLM = PR_NewLogModule("ImageXlib"); -#endif /* PR_LOGGING */ - -/* XXX we are simply creating a GC and setting its function to Copy. - we shouldn't be doing this every time this method is called. this creates - way more trips to the server than we should be doing so we are creating a - static one. -*/ -static GC s1bitGC = 0; -static GC sXbitGC = 0; - -XlibRgbHandle *nsImageXlib::mXlibRgbHandle = nsnull; -Display *nsImageXlib::mDisplay = nsnull; - -nsImageXlib::nsImageXlib() -: mImageBits(nsnull) -, mAlphaBits(nsnull) -, mWidth(0) -, mHeight(0) -, mDepth(0) -, mRowBytes(0) -, mSizeImage(0) -, mNumBytesPixel(0) -, mImagePixmap(nsnull) -, mAlphaPixmap(nsnull) -, mAlphaDepth(0) -, mAlphaRowBytes(0) -, mAlphaValid(PR_FALSE) -, mIsSpacer(PR_TRUE) -, mGC(nsnull) -, mPendingUpdate(PR_FALSE) -, mDecodedX1(PR_INT32_MAX) -, mDecodedY1(PR_INT32_MAX) -, mDecodedX2(0) -, mDecodedY2(0) -{ - PR_LOG(ImageXlibLM, PR_LOG_DEBUG, ("nsImageXlib::nsImageXlib()\n")); - - if (!mXlibRgbHandle) { - mXlibRgbHandle = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE); - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - } - - if (!mXlibRgbHandle || !mDisplay) - abort(); -} - -nsImageXlib::~nsImageXlib() -{ - PR_LOG(ImageXlibLM, PR_LOG_DEBUG,("nsImageXlib::nsImageXlib()\n")); - if (nsnull != mImageBits) { - delete[] mImageBits; - mImageBits = nsnull; - } - if (nsnull != mAlphaBits) { - delete[] mAlphaBits; - mAlphaBits = nsnull; - - if (mAlphaPixmap != nsnull) - { - // The display can't be null. It gets fetched from the drawing - // surface used to create the pixmap. It gets assigned once - // in Draw() - NS_ASSERTION(nsnull != mDisplay,"display is null."); - -#ifdef XLIB_PIXMAP_DEBUG - printf("XFreePixmap(display = %p)\n",mDisplay); -#endif - - XFreePixmap(mDisplay, mAlphaPixmap); - - } - } - - if (mImagePixmap != 0) - { - NS_ASSERTION(nsnull != mDisplay,"display is null."); - -#ifdef XLIB_PIXMAP_DEBUG - printf("XFreePixmap(display = %p)\n",mDisplay); -#endif - - XFreePixmap(mDisplay, mImagePixmap); - } - - if(mGC) - { - XFreeGC(mDisplay, mGC); - mGC=nsnull; - } - if(sXbitGC && mDisplay) // Sometimes mDisplay is null, let orhers free - { - XFreeGC(mDisplay, sXbitGC); - sXbitGC=nsnull; - } - if(s1bitGC && mDisplay) // Sometimes mDisplay is null, let orhers free - { - XFreeGC(mDisplay, s1bitGC); - s1bitGC=nsnull; - } - -} - -NS_IMPL_ISUPPORTS1(nsImageXlib, nsIImage) - -nsresult nsImageXlib::Init(PRInt32 aWidth, PRInt32 aHeight, - PRInt32 aDepth, nsMaskRequirements aMaskRequirements) -{ - // gfxImageFrame makes sure nsImageXlib::Init gets called only once - if ((aWidth == 0) || (aHeight == 0)) - return NS_ERROR_FAILURE; - - if (24 == aDepth) { - mNumBytesPixel = 3; - } else { - NS_ASSERTION(PR_FALSE, "unexpected image depth"); - return NS_ERROR_UNEXPECTED; - } - - mWidth = aWidth; - mHeight = aHeight; - mDepth = aDepth; - - // Create the memory for the image - ComputeMetrics(); - - mImageBits = (PRUint8*)new PRUint8[mSizeImage]; - - switch(aMaskRequirements) { - case nsMaskRequirements_kNeeds1Bit: - mAlphaRowBytes = (aWidth + 7) / 8; - mAlphaDepth = 1; - - // 32-bit align each row - mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3; - - mAlphaBits = new unsigned char[mAlphaRowBytes * aHeight]; - break; - - case nsMaskRequirements_kNeeds8Bit: - mAlphaRowBytes = aWidth; - mAlphaDepth = 8; - - // 32-bit align each row - mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3; - mAlphaBits = new unsigned char[mAlphaRowBytes * aHeight]; - break; - - default: - break; // avoid compiler warning - } - return NS_OK; -} - -//--------------------------------------------------------------------- - -PRInt32 nsImageXlib::GetHeight() -{ - return mHeight; -} - -PRInt32 nsImageXlib::GetWidth() -{ - return mWidth; -} - -PRUint8 *nsImageXlib::GetBits() -{ - return mImageBits; -} - -void *nsImageXlib::GetBitInfo() -{ - return nsnull; -} - -PRInt32 nsImageXlib::GetLineStride() -{ - return mRowBytes; -} - -nsColorMap *nsImageXlib::GetColorMap() -{ - return nsnull; -} - -PRUint8 *nsImageXlib::GetAlphaBits() -{ - return mAlphaBits; -} - -PRInt32 nsImageXlib::GetAlphaLineStride() -{ - return mAlphaRowBytes; -} - -//----------------------------------------------------------------------- - -// Set up the palette to the passed in color array, RGB only in this array -void nsImageXlib::ImageUpdated(nsIDeviceContext *aContext, - PRUint8 aFlags, - nsRect *aUpdateRect) -{ - mPendingUpdate = PR_TRUE; - mUpdateRegion.Or(mUpdateRegion, *aUpdateRect); - - mDecodedX1 = PR_MIN(mDecodedX1, aUpdateRect->x); - mDecodedY1 = PR_MIN(mDecodedY1, aUpdateRect->y); - - if (aUpdateRect->YMost() > mDecodedY2) - mDecodedY2 = aUpdateRect->YMost(); - if (aUpdateRect->XMost() > mDecodedX2) - mDecodedX2 = aUpdateRect->XMost(); -} - -/** --------------------------------------------------- - * See documentation in nsIImage.h - */ -PRBool nsImageXlib::GetIsImageComplete() { - return mDecodedX1 == 0 && - mDecodedY1 == 0 && - mDecodedX2 == mWidth && - mDecodedY2 == mHeight; -} - -void nsImageXlib::UpdateCachedImage() -{ - nsRegionRectIterator ri(mUpdateRegion); - const nsRect *rect; - - while (rect = ri.Next()) { - -// fprintf(stderr, "ImageUpdated %p x,y=(%d %d) width,height=(%d %d)\n", -// this, rect->x, rect->y, rect->width, rect->height); - - unsigned bottom, left, right; - bottom = rect->y + rect->height; - left = rect->x; - right = left + rect->width; - - // check if the image has an all-opaque 8-bit alpha mask - if ((mAlphaDepth==8) && !mAlphaValid) { - for (unsigned y=rect->y; (y> (left & 0x7); - PRUint8 rightmask = 0xff << (7 - ((right-1) & 0x7)); - - // byte where the first/last bits of the update region are located - PRUint32 leftindex = left >> 3; - PRUint32 rightindex = (right-1) >> 3; - - // first/last bits in the same byte - combine mask into leftmask - // and fill rightmask so we don't try using it - if (leftindex == rightindex) { - leftmask &= rightmask; - rightmask = 0xff; - } - - // check the leading bits - if (leftmask != 0xff) { - PRUint8 *ptr = mAlphaBits + mAlphaRowBytes * rect->y + leftindex; - for (unsigned y=rect->y; yy + rightindex; - for (unsigned y=rect->y; yy; (yx, rect->y, - rect->width, rect->height, - XLIB_RGB_DITHER_MAX, - mImageBits + mRowBytes * rect->y + 3 * rect->x, - mRowBytes, - rect->x, rect->y); - } - } - - mUpdateRegion.SetEmpty(); - mPendingUpdate = PR_FALSE; - mFlags = nsImageUpdateFlags_kBitsChanged; // this should be 0'd out by Draw() -} - -NS_IMETHODIMP -nsImageXlib::DrawScaled(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, - PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, - PRInt32 aDWidth, PRInt32 aDHeight) -{ - - PRInt32 origSHeight = aSHeight, origDHeight = aDHeight; - PRInt32 origSWidth = aSWidth, origDWidth = aDWidth; - - if (aSWidth < 0 || aDWidth < 0 || aSHeight < 0 || aDHeight < 0) - return NS_ERROR_FAILURE; - - if (0 == aSWidth || 0 == aDWidth || 0 == aSHeight || 0 == aDHeight) - return NS_OK; - - if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1) - return NS_OK; - - // limit the size of the blit to the amount of the image read in - if (aSX + aSWidth > mDecodedX2) { - aDWidth -= ((aSX + aSWidth - mDecodedX2)*origDWidth)/origSWidth; - aSWidth -= (aSX + aSWidth) - mDecodedX2; - } - if (aSX < mDecodedX1) { - aDX += ((mDecodedX1 - aSX)*origDWidth)/origSWidth; - aSX = mDecodedX1; - } - - if (aSY + aSHeight > mDecodedY2) { - aDHeight -= ((aSY + aSHeight - mDecodedY2)*origDHeight)/origSHeight; - aSHeight -= (aSY + aSHeight) - mDecodedY2; - } - if (aSY < mDecodedY1) { - aDY += ((mDecodedY1 - aSY)*origDHeight)/origSHeight; - aSY = mDecodedY1; - } - - if ((aDWidth <= 0 || aDHeight <= 0) || (aSWidth <= 0 || aSHeight <= 0)) - return NS_OK; - - nsIDrawingSurfaceXlib *drawing = NS_STATIC_CAST(nsIDrawingSurfaceXlib *, aSurface); - - if (mAlphaDepth == 1) - CreateAlphaBitmap(mWidth, mHeight); - - if ((mAlphaDepth == 8) && mAlphaValid) { - DrawComposited(aContext, aSurface, - aSX, aSY, aSWidth, aSHeight, - aDX, aDY, aDWidth, aDHeight); - return NS_OK; - } - -#ifdef HAVE_XIE - /* XIE seriosly loses scaling images with alpha */ - if (!mAlphaDepth) { - /* Draw with XIE */ - PRBool succeeded = PR_FALSE; - - xGC *xiegc = ((nsRenderingContextXlib&)aContext).GetGC(); - Drawable drawable; drawing->GetDrawable(drawable); - succeeded = DrawScaledImageXIE(mDisplay, drawable, - *xiegc, - mImagePixmap, - mWidth, mHeight, - aSX, aSY, - aSWidth, aSHeight, - aDX, aDY, - aDWidth, aDHeight); - xiegc->Release(); - if (succeeded) - return NS_OK; - } -#endif - - /* the good scaling way, right from GTK */ - GC gc = 0; - Pixmap pixmap = 0; - - if (mAlphaDepth==1) { - PRUint32 scaledRowBytes = (origDWidth+7)>>3; // round to next byte - PRUint8 *scaledAlpha = (PRUint8 *)nsMemory::Alloc(origDHeight*scaledRowBytes); - - // code below attempts to draw the image without the mask if mask - // creation fails for some reason. thus no easy-out "return" - if (scaledAlpha) { - memset(scaledAlpha, 0, origDHeight*scaledRowBytes); - RectStretch(mWidth, mHeight, origDWidth, origDHeight, - 0, 0, aDWidth - 1, aDHeight - 1, - mAlphaBits, mAlphaRowBytes, scaledAlpha, scaledRowBytes, 1); - - pixmap = XCreatePixmap(mDisplay, DefaultRootWindow(mDisplay), - aDWidth, aDHeight, 1); - XImage *ximage = 0; - - if (pixmap) { - ximage = XCreateImage(mDisplay, xxlib_rgb_get_visual(mXlibRgbHandle), - 1, XYPixmap, 0, (char *)scaledAlpha, - aDWidth, aDHeight, - 8, scaledRowBytes); - } - if (ximage) { - ximage->bits_per_pixel=1; - ximage->bitmap_bit_order=MSBFirst; - ximage->byte_order = MSBFirst; - - GC tmpGC; - XGCValues gcv; - memset(&gcv, 0, sizeof(XGCValues)); - gcv.function = GXcopy; - tmpGC = XCreateGC(mDisplay, pixmap, GCFunction, &gcv); - if (tmpGC) { - XPutImage(mDisplay, pixmap, tmpGC, ximage, - 0, 0, 0, 0, aDWidth, aDHeight); - XFreeGC(mDisplay, tmpGC); - } else { - // can't write into the clip mask - destroy so we don't use it - if (pixmap) - XFreePixmap(mDisplay, pixmap); - pixmap = 0; - } - - ximage->data = 0; - XDestroyImage(ximage); - } - nsMemory::Free(scaledAlpha); - } - } - - xGC *imageGC = nsnull; - - if (pixmap) { - XGCValues values; - - memset(&values, 0, sizeof(XGCValues)); - values.clip_x_origin = aDX; - values.clip_y_origin = aDY; - values.clip_mask = pixmap; - Drawable drawable; drawing->GetDrawable(drawable); - gc = XCreateGC(mDisplay, drawable, - GCClipXOrigin | GCClipYOrigin | GCClipMask, - &values); - } else { - imageGC = ((nsRenderingContextXlib&)aContext).GetGC(); - gc = *imageGC; - } - - PRUint8 *scaledRGB = (PRUint8 *)nsMemory::Alloc(3*aDWidth*aDHeight); - if (scaledRGB && gc) { - RectStretch(mWidth, mHeight, origDWidth, origDHeight, - 0, 0, aDWidth - 1, aDHeight - 1, - mImageBits, mRowBytes, scaledRGB, 3*aDWidth, 24); - - Drawable drawable; drawing->GetDrawable(drawable); - xxlib_draw_rgb_image(mXlibRgbHandle, drawable, gc, - aDX, aDY, aDWidth, aDHeight, - XLIB_RGB_DITHER_MAX, - scaledRGB, 3*aDWidth); - nsMemory::Free(scaledRGB); - } - - if (imageGC) - imageGC->Release(); - else - if (gc) - XFreeGC(mDisplay, gc); - if (pixmap) - XFreePixmap(mDisplay, pixmap); - - mFlags = 0; - - return NS_OK; -} - -// Draw the bitmap, this method has a source and destination coordinates -NS_IMETHODIMP -nsImageXlib::Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight) -{ - if (aSurface == nsnull) - return NS_ERROR_FAILURE; - - if (mPendingUpdate) - UpdateCachedImage(); - - if ((mAlphaDepth == 1) && mIsSpacer) - return NS_OK; - - if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1) - return NS_OK; - - if (aSWidth != aDWidth || aSHeight != aDHeight) { - return DrawScaled(aContext, aSurface, aSX, aSY, aSWidth, aSHeight, - aDX, aDY, aDWidth, aDHeight); - } - - if (aSWidth <= 0 || aDWidth <= 0 || aSHeight <= 0 || aDHeight <= 0) { - NS_ASSERTION(aSWidth > 0 && aDWidth > 0 && aSHeight > 0 && aDHeight > 0, - "You can't draw an image with a 0 width or height!"); - return NS_OK; - } - - // limit the size of the blit to the amount of the image read in - PRInt32 j = aSX + aSWidth; - PRInt32 z; - if (j > mDecodedX2) { - z = j - mDecodedX2; - aDWidth -= z; - aSWidth -= z; - } - if (aSX < mDecodedX1) { - aDX += mDecodedX1 - aSX; - aSX = mDecodedX1; - } - - j = aSY + aSHeight; - if (j > mDecodedY2) { - z = j - mDecodedY2; - aDHeight -= z; - aSHeight -= z; - } - if (aSY < mDecodedY1) { - aDY += mDecodedY1 - aSY; - aSY = mDecodedY1; - } - - if (aDWidth <= 0 || aDHeight <= 0 || aSWidth <= 0 || aSHeight <= 0) - return NS_OK; - - if ((mAlphaDepth == 8) && mAlphaValid) { - DrawComposited(aContext, aSurface, - aSX, aSY, aSWidth, aSHeight, - aDX, aDY, aSWidth, aSHeight); - return NS_OK; - } - - nsIDrawingSurfaceXlib *drawing = NS_STATIC_CAST(nsIDrawingSurfaceXlib *, aSurface); - - if (mAlphaDepth == 1) - CreateAlphaBitmap(mWidth, mHeight); - - GC copyGC; - xGC *gc = ((nsRenderingContextXlib&)aContext).GetGC(); - - if (mAlphaPixmap) { - if (mGC) { /* reuse GC */ - copyGC = mGC; - SetupGCForAlpha(copyGC, aDX - aSX, aDY - aSY); - } else { /* make a new one */ - /* this repeats things done in SetupGCForAlpha */ - XGCValues xvalues; - memset(&xvalues, 0, sizeof(XGCValues)); - unsigned long xvalues_mask = 0; - xvalues.clip_x_origin = aDX - aSX; - xvalues.clip_y_origin = aDY - aSY; - if (IsFlagSet(nsImageUpdateFlags_kBitsChanged, mFlags)) { - xvalues_mask = GCClipXOrigin | GCClipYOrigin | GCClipMask; - xvalues.clip_mask = mAlphaPixmap; - } - Drawable drawable; drawing->GetDrawable(drawable); - mGC = XCreateGC(mDisplay, drawable, xvalues_mask , &xvalues); - copyGC = mGC; - } - } else { /* !mAlphaPixmap */ - copyGC = *gc; - } - - Drawable drawable; drawing->GetDrawable(drawable); - XCopyArea(mDisplay, mImagePixmap, drawable, - copyGC, aSX, aSY, aSWidth, aSHeight, aDX, aDY); - - gc->Release(); - mFlags = 0; - return NS_OK; -} - -// ----------------------------------------------------------------- -// 8-bit alpha composite drawing - -static unsigned -findIndex32(unsigned mask) -{ - switch (mask) - { - case 0xff: - return 3; - case 0xff00: - return 2; - case 0xff0000: - return 1; - default: - return 0; - } -} - -static unsigned -findIndex24(unsigned mask) -{ - switch(mask) - { - case 0xff: - return 2; - case 0xff00: - return 1; - default: - return 0; - } -} - - -// 32-bit (888) truecolor convert/composite function -void nsImageXlib::DrawComposited32(PRBool isLSB, PRBool flipBytes, - PRUint8 *imageOrigin, PRUint32 imageStride, - PRUint8 *alphaOrigin, PRUint32 alphaStride, - unsigned width, unsigned height, - XImage *ximage, unsigned char *readData) -{ - Visual *visual = xxlib_rgb_get_visual(mXlibRgbHandle); - unsigned redIndex = findIndex32(visual->red_mask); - unsigned greenIndex = findIndex32(visual->green_mask); - unsigned blueIndex = findIndex32(visual->blue_mask); - - if (flipBytes^isLSB) - { - redIndex = 3-redIndex; - greenIndex = 3-greenIndex; - blueIndex = 3-blueIndex; - } - - for (unsigned y=0; ydata - +y*ximage->bytes_per_line; - unsigned char *targetRow = readData +3*(y*ximage->width); - unsigned char *imageRow = imageOrigin +y*imageStride; - unsigned char *alphaRow = alphaOrigin +y*alphaStride; - - for (unsigned i=0; ired_mask); - unsigned greenIndex = findIndex24(visual->green_mask); - unsigned blueIndex = findIndex24(visual->blue_mask); - - if (flipBytes^isLSB) { - redIndex = 2-redIndex; - greenIndex = 2-greenIndex; - blueIndex = 2-blueIndex; - } - - for (unsigned y=0; ydata - +y*ximage->bytes_per_line; - unsigned char *targetRow = readData +3*(y*ximage->width); - unsigned char *imageRow = imageOrigin +y*imageStride; - unsigned char *alphaRow = alphaOrigin +y*alphaStride; - - for (unsigned i=0; ired_mask) == 5) - ? scaled5 : scaled6; - unsigned *greenScale = (xxlib_get_prec_from_mask(visual->green_mask) == 5) - ? scaled5 : scaled6; - unsigned *blueScale = (xxlib_get_prec_from_mask(visual->blue_mask) == 5) - ? scaled5 : scaled6; - - unsigned long redShift = xxlib_get_shift_from_mask(visual->red_mask); - unsigned long greenShift = xxlib_get_shift_from_mask(visual->green_mask); - unsigned long blueShift = xxlib_get_shift_from_mask(visual->blue_mask); - - for (unsigned y=0; ydata - +y*ximage->bytes_per_line; - unsigned char *targetRow = readData +3*(y*ximage->width); - unsigned char *imageRow = imageOrigin +y*imageStride; - unsigned char *alphaRow = alphaOrigin +y*alphaStride; - for (unsigned i=0; ired_mask) >> redShift], - imageRow[0], alpha); - MOZ_BLEND(targetRow[1], - greenScale[(pix&visual->green_mask) >> greenShift], - imageRow[1], alpha); - MOZ_BLEND(targetRow[2], - blueScale[(pix&visual->blue_mask) >> blueShift], - imageRow[2], alpha); - } - } -} - -// Generic convert/composite function -void -nsImageXlib::DrawCompositedGeneral(PRBool isLSB, PRBool flipBytes, - PRUint8 *imageOrigin, PRUint32 imageStride, - PRUint8 *alphaOrigin, PRUint32 alphaStride, - unsigned width, unsigned height, - XImage *ximage, unsigned char *readData) -{ - Visual *visual = xxlib_rgb_get_visual(mXlibRgbHandle); - - unsigned char *target = readData; - - // flip bytes - if (flipBytes && (ximage->bits_per_pixel>=16)) { - for (int row=0; rowheight; row++) { - unsigned char *ptr = - (unsigned char*)ximage->data + row*ximage->bytes_per_line; - if (ximage->bits_per_pixel==24) { // Aurgh.... - for (int col=0; - colbytes_per_line; - col+=(ximage->bits_per_pixel/8)) { - unsigned char tmp; - tmp = *ptr; - *ptr = *(ptr+2); - *(ptr+2) = tmp; - ptr+=3; - } - continue; - } - - for (int col=0; - colbytes_per_line; - col+=(ximage->bits_per_pixel/8)) { - unsigned char tmp; - switch (ximage->bits_per_pixel) { - case 16: - tmp = *ptr; - *ptr = *(ptr+1); - *(ptr+1) = tmp; - ptr+=2; - break; - case 32: - tmp = *ptr; - *ptr = *(ptr+3); - *(ptr+3) = tmp; - tmp = *(ptr+1); - *(ptr+1) = *(ptr+2); - *(ptr+2) = tmp; - ptr+=4; - break; - } - } - } - } - - unsigned redScale = 8 - xxlib_get_prec_from_mask(visual->red_mask); - unsigned greenScale = 8 - xxlib_get_prec_from_mask(visual->green_mask); - unsigned blueScale = 8 - xxlib_get_prec_from_mask(visual->blue_mask); - unsigned redFill = 0xff >> xxlib_get_prec_from_mask(visual->red_mask); - unsigned greenFill = 0xff >> xxlib_get_prec_from_mask(visual->green_mask); - unsigned blueFill = 0xff >> xxlib_get_prec_from_mask(visual->blue_mask); - - unsigned long redShift = xxlib_get_shift_from_mask(visual->red_mask); - unsigned long greenShift = xxlib_get_shift_from_mask(visual->green_mask); - unsigned long blueShift = xxlib_get_shift_from_mask(visual->blue_mask); - - for (int row=0; rowheight; row++) { - unsigned char *ptr = - (unsigned char *)ximage->data + row*ximage->bytes_per_line; - for (int col=0; colwidth; col++) { - unsigned pix = 0; - switch (ximage->bits_per_pixel) { - case 1: - pix = (*ptr>>(col%8))&1; - if ((col%8)==7) - ptr++; - break; - case 4: - pix = (col&1)?(*ptr>>4):(*ptr&0xf); - if (col&1) - ptr++; - break; - case 8: - pix = *ptr++; - break; - case 16: - pix = *((short *)ptr); - ptr+=2; - break; - case 24: - if (isLSB) - pix = (*(ptr+2)<<16) | (*(ptr+1)<<8) | *ptr; - else - pix = (*ptr<<16) | (*(ptr+1)<<8) | *(ptr+2); - ptr+=3; - break; - case 32: - pix = *((unsigned *)ptr); - ptr+=4; - break; - } - - *target++ = - redFill|((pix&visual->red_mask) >> redShift)<green_mask) >> greenShift)<blue_mask) >> blueShift)<GetDrawable(drawable); - Visual *visual = xxlib_rgb_get_visual(mXlibRgbHandle); - - // I hate clipping... too! - PRUint32 surfaceWidth, surfaceHeight; - drawing->GetDimensions(&surfaceWidth, &surfaceHeight); - - int readX, readY; - unsigned readWidth, readHeight, destX, destY; - - if ((aDY >= (int)surfaceHeight) || (aDX >= (int)surfaceWidth) || - (aDY + aDHeight <= 0) || (aDX + aDWidth <= 0)) { - // This should never happen if the layout engine is sane, - // as it means we're trying to draw an image which is outside - // the drawing surface. Bulletproof gfx for now... - return; - } - - if (aDX < 0) { - readX = 0; readWidth = aDWidth + aDX; destX = aSX - aDX; - } else { - readX = aDX; readWidth = aDWidth; destX = aSX; - } - if (aDY < 0) { - readY = 0; readHeight = aDHeight + aDY; destY = aSY - aDY; - } else { - readY = aDY; readHeight = aDHeight; destY = aSY; - } - - if (readX+readWidth > surfaceWidth) - readWidth = surfaceWidth-readX; - if (readY+readHeight > surfaceHeight) - readHeight = surfaceHeight-readY; - - if ((readHeight <= 0) || (readWidth <= 0)) - return; - - // fprintf(stderr, "aX=%d aY=%d, aWidth=%u aHeight=%u\n", aX, aY, aWidth, aHeight); - // fprintf(stderr, "surfaceWidth=%u surfaceHeight=%u\n", surfaceWidth, surfaceHeight); - // fprintf(stderr, "readX=%u readY=%u readWidth=%u readHeight=%u destX=%u destY=%u\n\n", - // readX, readY, readWidth, readHeight, destX, destY); - - XImage *ximage = XGetImage(mDisplay, drawable, - readX, readY, readWidth, readHeight, - AllPlanes, ZPixmap); - - NS_ASSERTION((ximage != NULL), "XGetImage() failed"); - if (!ximage) - return; - - unsigned char *readData = - (unsigned char *)nsMemory::Alloc(3*readWidth*readHeight); - - PRUint8 *scaledImage = 0; - PRUint8 *scaledAlpha = 0; - PRUint8 *imageOrigin, *alphaOrigin; - PRUint32 imageStride, alphaStride; - - /* image needs to be scaled */ - if ((aSWidth!=aDWidth) || (aSHeight!=aDHeight)) { - PRUint32 x1, y1, x2, y2; - x1 = (destX*aSWidth)/aDWidth; - y1 = (destY*aSHeight)/aDHeight; - x2 = ((destX+readWidth)*aSWidth)/aDWidth; - y2 = ((destY+readHeight)*aSHeight)/aDHeight; - - scaledImage = (PRUint8 *)nsMemory::Alloc(3*aDWidth*aDHeight); - scaledAlpha = (PRUint8 *)nsMemory::Alloc(aDWidth*aDHeight); - if (!scaledImage || !scaledAlpha) { - XDestroyImage(ximage); - nsMemory::Free(readData); - if (scaledImage) - nsMemory::Free(scaledImage); - if (scaledAlpha) - nsMemory::Free(scaledAlpha); - return; - } - RectStretch(aSWidth, aSHeight, aDWidth, aDHeight, - 0, 0, aDWidth-1, aDHeight-1, - mImageBits, mRowBytes, scaledImage, 3*readWidth, 24); - RectStretch(x1, y1, x2-1, y2-1, - 0, 0, aDWidth-1, aDHeight-1, - mAlphaBits, mAlphaRowBytes, scaledAlpha, readWidth, 8); - imageOrigin = scaledImage; - imageStride = 3*readWidth; - alphaOrigin = scaledAlpha; - alphaStride = readWidth; - } else { - imageOrigin = mImageBits + destY*mRowBytes + 3*destX; - imageStride = mRowBytes; - alphaOrigin = mAlphaBits + destY*mAlphaRowBytes + destX; - alphaStride = mAlphaRowBytes; - } - - PRBool isLSB; - unsigned int test = 1; - isLSB = (((char *)&test)[0]) ? 1 : 0; - int red_prec = xxlib_get_prec_from_mask(visual->red_mask); - int green_prec = xxlib_get_prec_from_mask(visual->green_mask); - int blue_prec = xxlib_get_prec_from_mask(visual->blue_mask); - - - PRBool flipBytes = - ( isLSB && ximage->byte_order != LSBFirst) || - (!isLSB && ximage->byte_order == LSBFirst); - - if ((ximage->bits_per_pixel==32) && - (red_prec == 8) && - (green_prec == 8) && - (blue_prec == 8)) - DrawComposited32(isLSB, flipBytes, - imageOrigin, imageStride, - alphaOrigin, alphaStride, - readWidth, readHeight, ximage, readData); - else if ((ximage->bits_per_pixel==24) && - (red_prec == 8) && - (green_prec == 8) && - (blue_prec == 8)) - DrawComposited24(isLSB, flipBytes, - imageOrigin, imageStride, - alphaOrigin, alphaStride, - readWidth, readHeight, ximage, readData); - else if ((ximage->bits_per_pixel==16) && - ((red_prec == 5) || (red_prec == 6)) && - ((green_prec == 5) || (green_prec == 6)) && - ((blue_prec == 5) || (blue_prec == 6))) - DrawComposited16(isLSB, flipBytes, - imageOrigin, imageStride, - alphaOrigin, alphaStride, - readWidth, readHeight, ximage, readData); - else - DrawCompositedGeneral(isLSB, flipBytes, - imageOrigin, imageStride, - alphaOrigin, alphaStride, - readWidth, readHeight, ximage, readData); - - xGC *imageGC = ((nsRenderingContextXlib&)aContext).GetGC(); - xxlib_draw_rgb_image(mXlibRgbHandle, drawable, *imageGC, - readX, readY, readWidth, readHeight, - XLIB_RGB_DITHER_MAX, - readData, 3*readWidth); - XDestroyImage(ximage); - imageGC->Release(); - nsMemory::Free(readData); - if (scaledImage) - nsMemory::Free(scaledImage); - if (scaledAlpha) - nsMemory::Free(scaledAlpha); - mFlags = 0; -} - -void nsImageXlib::CreateAlphaBitmap(PRInt32 aWidth, PRInt32 aHeight) -{ - XImage *x_image = nsnull; - XGCValues gcv; - - /* Create gc clip-mask on demand */ - if (mAlphaBits && IsFlagSet(nsImageUpdateFlags_kBitsChanged, mFlags)) { - - if (!mAlphaPixmap) - mAlphaPixmap = XCreatePixmap(mDisplay, DefaultRootWindow(mDisplay), - aWidth, aHeight, 1); - - // Make an image out of the alpha-bits created by the image library - x_image = XCreateImage(mDisplay, xxlib_rgb_get_visual(mXlibRgbHandle), - 1, /* visual depth...1 for bitmaps */ - XYPixmap, - 0, /* x offset, XXX fix this */ - (char *)mAlphaBits, /* cast away our sign. */ - aWidth, - aHeight, - 32, /* bitmap pad */ - mAlphaRowBytes); /* bytes per line */ - - x_image->bits_per_pixel=1; - - /* Image library always places pixels left-to-right MSB to LSB */ - x_image->bitmap_bit_order = MSBFirst; - - /* This definition doesn't depend on client byte ordering - because the image library ensures that the bytes in - bitmask data are arranged left to right on the screen, - low to high address in memory. */ - x_image->byte_order = MSBFirst; -#if defined(IS_LITTLE_ENDIAN) - // no, it's still MSB XXX check on this!! - // x_image->byte_order = LSBFirst; -#elif defined (IS_BIG_ENDIAN) - x_image->byte_order = MSBFirst; -#else -#error ERROR! Endianness is unknown; -#endif - - /* Copy the XImage to mAlphaPixmap */ - if (!s1bitGC) { - memset(&gcv, 0, sizeof(XGCValues)); - gcv.function = GXcopy; - s1bitGC = XCreateGC(mDisplay, mAlphaPixmap, GCFunction, &gcv); - } - - XPutImage(mDisplay, mAlphaPixmap, s1bitGC, x_image, 0, 0, 0, 0, - aWidth, aHeight); - - /* Now we are done with the temporary image */ - x_image->data = 0; /* Don't free the IL_Pixmap's bits. */ - XDestroyImage(x_image); - } -} - -void nsImageXlib::CreateOffscreenPixmap(PRInt32 aWidth, PRInt32 aHeight) -{ - if (mImagePixmap == nsnull) { - mImagePixmap = XCreatePixmap(mDisplay, XDefaultRootWindow(mDisplay), - aWidth, aHeight, - xxlib_rgb_get_depth(mXlibRgbHandle)); - } -} - -void nsImageXlib::SetupGCForAlpha(GC aGC, PRInt32 aX, PRInt32 aY) -{ - if (mAlphaPixmap) - { - XGCValues xvalues; - memset(&xvalues, 0, sizeof(XGCValues)); - unsigned long xvalues_mask = 0; - xvalues.clip_x_origin = aX; - xvalues.clip_y_origin = aY; - xvalues_mask = GCClipXOrigin | GCClipYOrigin | GCClipMask; - xvalues.function = GXcopy; - xvalues.clip_mask = mAlphaPixmap; - - XChangeGC(mDisplay, aGC, xvalues_mask, &xvalues); - } -} - -// Draw the bitmap. This draw just has destination coordinates -NS_IMETHODIMP -nsImageXlib::Draw(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight) -{ - if (mPendingUpdate) - UpdateCachedImage(); - - if ((mAlphaDepth == 1) && mIsSpacer) - return NS_OK; - - if (aSurface == nsnull) - return NS_ERROR_FAILURE; - - if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1) - return NS_OK; - - if ((mAlphaDepth == 8) && mAlphaValid) { - DrawComposited(aContext, aSurface, - 0, 0, aWidth, aHeight, - aX, aY, aWidth, aHeight); - return NS_OK; - } - - // XXX it is said that this is temporary code - if ((aWidth != mWidth) || (aHeight != mHeight)) { - aWidth = mWidth; - aHeight = mHeight; - } - - nsIDrawingSurfaceXlib *drawing = NS_STATIC_CAST(nsIDrawingSurfaceXlib *, aSurface); - - PRInt32 - validX = 0, - validY = 0, - validWidth = aWidth, - validHeight = aHeight; - - if ((mDecodedY2 < aHeight)) { - validHeight = mDecodedY2 - mDecodedY1; - } - if ((mDecodedX2 < aWidth)) { - validWidth = mDecodedX2 - mDecodedX1; - } - if ((mDecodedY1 > 0)) { - validHeight -= mDecodedY1; - validY = mDecodedY1; - } - if ((mDecodedX1 > 0)) { - validHeight -= mDecodedX1; - validX = mDecodedX1; - } - - CreateAlphaBitmap(aWidth, aHeight); - - GC copyGC; - xGC *gc = ((nsRenderingContextXlib&)aContext).GetGC(); - - if (mAlphaPixmap) { - if (mGC) { /* reuse GC */ - copyGC = mGC; - SetupGCForAlpha(copyGC, aX, aY); - } else { /* make a new one */ - /* this repeats things done in SetupGCForAlpha */ - XGCValues xvalues; - memset(&xvalues, 0, sizeof(XGCValues)); - unsigned long xvalues_mask = 0; - xvalues.clip_x_origin = aX; - xvalues.clip_y_origin = aY; - if (IsFlagSet(nsImageUpdateFlags_kBitsChanged, mFlags)) { - xvalues_mask = GCClipXOrigin | GCClipYOrigin | GCClipMask; - xvalues.clip_mask = mAlphaPixmap; - } - Drawable drawable; drawing->GetDrawable(drawable); - mGC = XCreateGC(mDisplay, drawable, xvalues_mask , &xvalues); - copyGC = mGC; - } - } else { /* !mAlphaPixmap */ - copyGC = *gc; - } - - Drawable drawable; drawing->GetDrawable(drawable); - XCopyArea(mDisplay, mImagePixmap, drawable, - copyGC, validX, validY, - validWidth, validHeight, - validX + aX, validY + aY); - - gc->Release(); - - mFlags = 0; - return NS_OK; -} - -void nsImageXlib::TilePixmap(Pixmap src, Pixmap dest, PRInt32 aSXOffset, - PRInt32 aSYOffset, const nsRect &destRect, - const nsRect &clipRect, PRBool useClip) -{ - GC gc; - XGCValues values; - unsigned long valuesMask; - memset(&values, 0, sizeof(XGCValues)); - values.fill_style = FillTiled; - values.tile = src; - values.ts_x_origin = destRect.x - aSXOffset; - values.ts_y_origin = destRect.y - aSYOffset; - valuesMask = GCTile | GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle; - gc = XCreateGC(mDisplay, src, valuesMask, &values); - - if (useClip) { - XRectangle xrectangle; - xrectangle.x = clipRect.x; - xrectangle.y = clipRect.y; - xrectangle.width = clipRect.width; - xrectangle.height = clipRect.height; - XSetClipRectangles(mDisplay, gc, 0, 0, &xrectangle, 1, Unsorted); - } - - XFillRectangle(mDisplay, dest, gc, destRect.x, destRect.y, - destRect.width, destRect.height); - - XFreeGC(mDisplay, gc); -} - -NS_IMETHODIMP nsImageXlib::DrawTile(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect) -{ - if (mPendingUpdate) - UpdateCachedImage(); - - if ((mAlphaDepth == 1) && mIsSpacer) - return NS_OK; - - if (aTileRect.width <= 0 || aTileRect.height <= 0) { - return NS_OK; - } - - if (mDecodedX2 < mDecodedX1 || mDecodedY2 < mDecodedY1) - return NS_OK; - - nsIDrawingSurfaceXlib *drawing = NS_STATIC_CAST(nsIDrawingSurfaceXlib *, aSurface); - - PRBool partial = PR_FALSE; - - PRInt32 - validX = 0, - validY = 0, - validWidth = mWidth, - validHeight = mHeight; - - // limit the image rectangle to the size of the image data which - // has been validated. - if (mDecodedY2 < mHeight) { - validHeight = mDecodedY2 - mDecodedY1; - partial = PR_TRUE; - } - if (mDecodedX2 < mWidth) { - validWidth = mDecodedX2 - mDecodedX1; - partial = PR_TRUE; - } - if (mDecodedY1 > 0) { - validHeight -= mDecodedY1; - validY = mDecodedY1; - partial = PR_TRUE; - } - if (mDecodedX1 > 0) { - validWidth -= mDecodedX1; - validX = mDecodedX1; - partial = PR_TRUE; - } - - if (validWidth == 0 || validHeight == 0) { - return NS_OK; - } - - if (partial || ((mAlphaDepth == 8) && mAlphaValid) || (aPadX || aPadY)) { - PRInt32 aY0 = aTileRect.y - aSYOffset, - aX0 = aTileRect.x - aSXOffset, - aY1 = aTileRect.y + aTileRect.height, - aX1 = aTileRect.x + aTileRect.width; - - // Set up clipping and call Draw(). - aContext.PushState(); - ((nsRenderingContextXlib&)aContext).SetClipRectInPixels( - aTileRect, nsClipCombine_kIntersect); - ((nsRenderingContextXlib&)aContext).UpdateGC(); - for (PRInt32 y = aY0; y < aY1; y += mHeight + aPadY) - for (PRInt32 x = aX0; x < aX1; x += mWidth + aPadX) - Draw(aContext,aSurface, x, y, - PR_MIN(validWidth, aX1 - x), - PR_MIN(validHeight, aY1 - y)); - - aContext.PopState(); - - return NS_OK; - } - - CreateOffscreenPixmap(mWidth, mHeight); - - if (mAlphaDepth == 1) { - Pixmap tileImg; - Pixmap tileMask; - - CreateAlphaBitmap(validWidth, validHeight); - - nsRect tmpRect(0,0,aTileRect.width, aTileRect.height); - - XlibRgbHandle *drawingXHandle; - drawing->GetXlibRgbHandle(drawingXHandle); - tileImg = XCreatePixmap(mDisplay, mImagePixmap, - aTileRect.width, aTileRect.height, - xxlib_rgb_get_depth(drawingXHandle)); - TilePixmap(mImagePixmap, tileImg, aSXOffset, aSYOffset, tmpRect, - tmpRect, PR_FALSE); - - // tile alpha mask - tileMask = XCreatePixmap(mDisplay, mAlphaPixmap, - aTileRect.width, aTileRect.height, mAlphaDepth); - TilePixmap(mAlphaPixmap, tileMask, aSXOffset, aSYOffset, tmpRect, - tmpRect, PR_FALSE); - - GC fgc; - XGCValues values; - unsigned long valuesMask; - - Drawable drawable; drawing->GetDrawable(drawable); - memset(&values, 0, sizeof(XGCValues)); - values.clip_mask = tileMask; - values.clip_x_origin = aTileRect.x; - values.clip_y_origin = aTileRect.y; - valuesMask = GCClipXOrigin | GCClipYOrigin | GCClipMask; - fgc = XCreateGC(mDisplay, drawable, valuesMask, &values); - - XCopyArea(mDisplay, tileImg, drawable, - fgc, 0,0, - aTileRect.width, aTileRect.height, - aTileRect.x, aTileRect.y); - - XFreePixmap(mDisplay, tileImg); - XFreePixmap(mDisplay, tileMask); - XFreeGC(mDisplay, fgc); - - } else { - // In the non-alpha case, xlib can tile for us - nsRect clipRect; - PRBool isValid; - - aContext.GetClipRect(clipRect, isValid); - - Drawable drawable; drawing->GetDrawable(drawable); - TilePixmap(mImagePixmap, drawable, aSXOffset, aSYOffset, - aTileRect, clipRect, PR_FALSE); - } - - mFlags = 0; - return NS_OK; -} - - -//---------------------------------------------------------------------- -nsresult nsImageXlib::Optimize(nsIDeviceContext *aContext) -{ - return NS_OK; -} - -//---------------------------------------------------------------------- -// Lock the image pixels. -NS_IMETHODIMP -nsImageXlib::LockImagePixels(PRBool aMaskPixels) -{ - return NS_OK; -} - -//--------------------------------------------------------------------- -// unlock the image pixels. Implement this if you need it. -NS_IMETHODIMP -nsImageXlib::UnlockImagePixels(PRBool aMaskPixels) -{ - return NS_OK; -} - -NS_IMETHODIMP nsImageXlib::DrawToImage(nsIImage* aDstImage, - nscoord aDX, nscoord aDY, - nscoord aDWidth, nscoord aDHeight) -{ - nsImageXlib *dest = NS_STATIC_CAST(nsImageXlib *, aDstImage); - if (!dest) - return NS_ERROR_FAILURE; - - if (aDX >= dest->mWidth || aDY >= dest->mHeight) - return NS_OK; - - if (mPendingUpdate) - UpdateCachedImage(); - - if (!dest->mImagePixmap) - dest->CreateOffscreenPixmap(dest->mWidth, dest->mHeight); - - if (!dest->mImagePixmap || !mImagePixmap) - return NS_ERROR_FAILURE; - - GC gc = XCreateGC(mDisplay, dest->mImagePixmap, 0, NULL); - - if (mAlphaDepth == 1) - CreateAlphaBitmap(mWidth, mHeight); - - if (mAlphaPixmap) - SetupGCForAlpha(gc, aDX, aDY); - - XCopyArea(dest->mDisplay, mImagePixmap, dest->mImagePixmap, gc, - 0, 0, mWidth, mHeight, aDX, aDY); - - XFreeGC(mDisplay, gc); - - if (!mIsSpacer || !mAlphaDepth) - dest->mIsSpacer = PR_FALSE; - - // need to copy the mImageBits in case we're rendered scaled - PRUint8 *scaledImage = 0, *scaledAlpha = 0; - PRUint8 *rgbPtr=0, *alphaPtr=0; - PRUint32 rgbStride, alphaStride = 0; - - if ((aDWidth != mWidth) || (aDHeight != mHeight)) { - // scale factor in DrawTo... start scaling - scaledImage = (PRUint8 *)nsMemory::Alloc(3*aDWidth*aDHeight); - if (!scaledImage) - return NS_ERROR_OUT_OF_MEMORY; - - RectStretch(mWidth, mHeight, aDWidth, aDHeight, - 0, 0, aDWidth-1, aDHeight-1, - mImageBits, mRowBytes, scaledImage, 3*aDWidth, 24); - - if (mAlphaDepth) { - if (mAlphaDepth==1) - alphaStride = (aDWidth+7)>>3; // round to next byte - else - alphaStride = aDWidth; - - scaledAlpha = (PRUint8 *)nsMemory::Alloc(alphaStride*aDHeight); - if (!scaledAlpha) { - nsMemory::Free(scaledImage); - return NS_ERROR_OUT_OF_MEMORY; - } - - RectStretch(mWidth, mHeight, aDWidth, aDHeight, - 0, 0, aDWidth-1, aDHeight-1, - mAlphaBits, mAlphaRowBytes, scaledAlpha, alphaStride, - mAlphaDepth); - } - rgbPtr = scaledImage; - rgbStride = 3*aDWidth; - alphaPtr = scaledAlpha; - } else { - rgbPtr = mImageBits; - rgbStride = mRowBytes; - alphaPtr = mAlphaBits; - alphaStride = mAlphaRowBytes; - } - - PRInt32 y; - PRInt32 ValidWidth = ( aDWidth < ( dest->mWidth - aDX ) ) ? aDWidth : ( dest->mWidth - aDX ); - PRInt32 ValidHeight = ( aDHeight < ( dest->mHeight - aDY ) ) ? aDHeight : ( dest->mHeight - aDY ); - - // now composite the two images together - switch (mAlphaDepth) { - case 1: - { - PRUint8 *dst = dest->mImageBits + aDY*dest->mRowBytes + 3*aDX; - PRUint8 *dstAlpha = dest->mAlphaBits + aDY*dest->mAlphaRowBytes; - PRUint8 *src = rgbPtr; - PRUint8 *alpha = alphaPtr; - PRUint8 offset = aDX & 0x7; // x starts at 0 - int iterations = (ValidWidth+7)/8; // round up - - for (y=0; y= ValidWidth) { - alphaPixels &= 0xff << (8 - (ValidWidth-x)); // no, mask off unused - if (alphaPixels == 0) - continue; // no 1 alpha pixels left - } - if (offset == 0) { - dstAlpha[(aDX+x)>>3] |= alphaPixels; // the cheap aligned case - } - else { - dstAlpha[(aDX+x)>>3] |= alphaPixels >> offset; - // avoid write if no 1's to write - also avoids going past end of array - PRUint8 alphaTemp = alphaPixels << (8U - offset); - if (alphaTemp & 0xff) - dstAlpha[((aDX+x)>>3) + 1] |= alphaTemp; - } - - if (alphaPixels == 0xff) { - // fix - could speed up by gathering a run of 0xff's and doing 1 memcpy - // all 8 pixels set; copy and jump forward - memcpy(dst,src,8*3); - continue; - } - else { - // else mix of 1's and 0's in alphaPixels, do 1 bit at a time - // Don't go past end of line! - PRUint8 *d = dst, *s = src; - for (PRUint8 aMask = 1<<7, j = 0; aMask && j < ValidWidth-x; aMask >>= 1, j++) { - // if this pixel is opaque then copy into the destination image - if (alphaPixels & aMask) { - // might be faster with *d++ = *s++ 3 times? - d[0] = s[0]; - d[1] = s[1]; - d[2] = s[2]; - // dstAlpha bit already set - } - d += 3; - s += 3; - } - } - } - // at end of each line, bump pointers. Use wordy code because of - // bug 127455 to avoid possibility of unsigned underflow - dst = (dst - 3*8*iterations) + dest->mRowBytes; - src = (src - 3*8*iterations) + rgbStride; - alpha = (alpha - iterations) + alphaStride; - dstAlpha += dest->mAlphaRowBytes; - } - } - break; - case 8: - // fix? Does this matter? GTK doesn't support this. Others? - for (y=0; ymImageBits + (y+aDY)*dest->mRowBytes + 3*aDX; - PRUint8 *dstAlpha = - dest->mAlphaBits + (y+aDY)*dest->mAlphaRowBytes + aDX; - PRUint8 *src = rgbPtr + y*rgbStride; - PRUint8 *alpha = alphaPtr + y*alphaStride; - for (int x=0; xmImageBits + (y+aDY)*dest->mRowBytes + 3*aDX, - rgbPtr + y*rgbStride, - 3*ValidWidth); - } - if (scaledAlpha) - nsMemory::Free(scaledAlpha); - if (scaledImage) - nsMemory::Free(scaledImage); - - return NS_OK; -} diff --git a/mozilla/gfx/src/xlib/nsImageXlib.h b/mozilla/gfx/src/xlib/nsImageXlib.h deleted file mode 100644 index 2012d08014b..00000000000 --- a/mozilla/gfx/src/xlib/nsImageXlib.h +++ /dev/null @@ -1,199 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsImageXlib_h__ -#define nsImageXlib_h__ - -#include "nsIImage.h" -#include "nsPoint.h" -#include "nsGCCache.h" -#include "nsRegion.h" -#include "xlibrgb.h" - -class nsImageXlib : public nsIImage { -public: - nsImageXlib(); - virtual ~nsImageXlib(); - - NS_DECL_ISUPPORTS - - virtual PRInt32 GetBytesPix() { return mNumBytesPixel; } - virtual PRInt32 GetHeight(); - virtual PRInt32 GetWidth(); - virtual PRUint8* GetBits(); - virtual void* GetBitInfo(); - virtual PRBool GetIsRowOrderTopToBottom() { return PR_TRUE; } - virtual PRInt32 GetLineStride(); - - virtual nsColorMap* GetColorMap(); - - NS_IMETHOD Draw(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD Draw(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight); - - NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY, - nscoord aDWidth, nscoord aDHeight); - - NS_IMETHOD DrawTile(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - PRInt32 aPadX, PRInt32 aPadY, - const nsRect &aTileRect); - - void UpdateCachedImage(); - virtual void ImageUpdated(nsIDeviceContext *aContext, - PRUint8 aFlags, nsRect *aUpdateRect); - virtual PRBool GetIsImageComplete(); - virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, - PRInt32 aDepth, - nsMaskRequirements aMaskRequirements); - - virtual nsresult Optimize(nsIDeviceContext* aContext); - - virtual PRBool GetHasAlphaMask() { return mAlphaBits != nsnull; } - virtual PRUint8* GetAlphaBits(); - virtual PRInt32 GetAlphaLineStride(); - /** - * Get the alpha depth for the image mask - * @update - lordpixel 2001/05/16 - * @return the alpha mask depth for the image, ie, 0, 1 or 8 - */ - virtual PRInt8 GetAlphaDepth() {return(mAlphaDepth);} - - NS_IMETHOD LockImagePixels(PRBool aMaskPixels); - NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels); - -private: - /** - * Calculate the amount of memory needed for the initialization of the image - */ - void ComputeMetrics() { - mRowBytes = (mWidth * mDepth) >> 5; - - if (((PRUint32)mWidth * mDepth) & 0x1F) - mRowBytes++; - mRowBytes <<= 2; - - mSizeImage = mRowBytes * mHeight; - }; - void ComputePaletteSize(PRIntn nBitCount); - -private: - NS_IMETHODIMP DrawScaled(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight); - - static unsigned scaled6[1<<6]; - static unsigned scaled5[1<<5]; - - void DrawComposited32(PRBool isLSB, PRBool flipBytes, - PRUint8 *imageOrigin, PRUint32 imageStride, - PRUint8 *alphaOrigin, PRUint32 alphaStride, - unsigned width, unsigned height, - XImage *ximage, unsigned char *readData); - void DrawComposited24(PRBool isLSB, PRBool flipBytes, - PRUint8 *imageOrigin, PRUint32 imageStride, - PRUint8 *alphaOrigin, PRUint32 alphaStride, - unsigned width, unsigned height, - XImage *ximage, unsigned char *readData); - void DrawComposited16(PRBool isLSB, PRBool flipBytes, - PRUint8 *imageOrigin, PRUint32 imageStride, - PRUint8 *alphaOrigin, PRUint32 alphaStride, - unsigned width, unsigned height, - XImage *ximage, unsigned char *readData); - void DrawCompositedGeneral(PRBool isLSB, PRBool flipBytes, - PRUint8 *imageOrigin, PRUint32 imageStride, - PRUint8 *alphaOrigin, PRUint32 alphaStride, - unsigned width, unsigned height, - XImage *ximage, unsigned char *readData); - inline void DrawComposited(nsIRenderingContext &aContext, - nsIDrawingSurface* aSurface, - PRInt32 aSX, PRInt32 aSY, - PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, - PRInt32 aDWidth, PRInt32 aDHeight); - - inline void TilePixmap(Pixmap src, Pixmap dest, PRInt32 aSXOffset, PRInt32 aSYOffset, - const nsRect &destRect, const nsRect &clipRect, PRBool useClip); - inline void CreateAlphaBitmap(PRInt32 aWidth, PRInt32 aHeight); - inline void CreateOffscreenPixmap(PRInt32 aWidth, PRInt32 aHeight); - inline void DrawImageOffscreen(PRInt32 aSX, PRInt32 aSY, - PRInt32 aWidth, PRInt32 aHeight); - inline void SetupGCForAlpha(GC aGC, PRInt32 aX, PRInt32 aY); - - // image bits - PRUint8 *mImageBits; - PRUint8 *mAlphaBits; - Pixmap mImagePixmap; - Pixmap mAlphaPixmap; - - PRInt32 mWidth; - PRInt32 mHeight; - PRInt32 mDepth; // bits per pixel - PRInt32 mRowBytes; - GC mGC; - - PRInt32 mSizeImage; - PRInt8 mNumBytesPixel; - - PRInt32 mDecodedX1; //Keeps track of what part of image - PRInt32 mDecodedY1; // has been decoded. - PRInt32 mDecodedX2; - PRInt32 mDecodedY2; - - nsRegion mUpdateRegion; - - static XlibRgbHandle *mXlibRgbHandle; - static Display *mDisplay; - - // alpha layer members - PRInt8 mAlphaDepth; // alpha layer depth - PRInt16 mAlphaRowBytes; // alpha bytes per row - PRPackedBool mAlphaValid; - PRPackedBool mIsSpacer; - PRPackedBool mPendingUpdate; - - PRUint8 mFlags; // flags set by ImageUpdated -}; - -#endif /* !nsImageXlib_h__ */ diff --git a/mozilla/gfx/src/xlib/nsPrintOptionsXlib.cpp b/mozilla/gfx/src/xlib/nsPrintOptionsXlib.cpp deleted file mode 100644 index 659a1c87e13..00000000000 --- a/mozilla/gfx/src/xlib/nsPrintOptionsXlib.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Xlib toolkit. - * - * The Initial Developer of the Original Code is - * Roland Mainz. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsPrintOptionsXlib.h" - - - -/** --------------------------------------------------- - * See documentation in nsPrintOptionsWin.h - * @update 6/21/00 dwc - */ -nsPrintOptionsXlib::nsPrintOptionsXlib() -{ -} - -/** --------------------------------------------------- - * See documentation in nsPrintOptionsImpl.h - * @update 6/21/00 dwc - */ -nsPrintOptionsXlib::~nsPrintOptionsXlib() -{ -} diff --git a/mozilla/gfx/src/xlib/nsPrintOptionsXlib.h b/mozilla/gfx/src/xlib/nsPrintOptionsXlib.h deleted file mode 100644 index 634370660cc..00000000000 --- a/mozilla/gfx/src/xlib/nsPrintOptionsXlib.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Xlib toolkit. - * - * The Initial Developer of the Original Code is - * Roland Mainz. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsPrintOptionsXlib_h__ -#define nsPrintOptionsXlib_h__ - -#include "nsPrintOptionsImpl.h" - - -// ***************************************************************************** -// *** nsPrintOptions -// ***************************************************************************** -class nsPrintOptionsXlib : public nsPrintOptions -{ -public: - nsPrintOptionsXlib(); - virtual ~nsPrintOptionsXlib(); - - -}; -#endif /* !nsPrintOptionsXlib_h__ */ - diff --git a/mozilla/gfx/src/xlib/nsPrintdXlib.cpp b/mozilla/gfx/src/xlib/nsPrintdXlib.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/mozilla/gfx/src/xlib/nsPrintdXlib.h b/mozilla/gfx/src/xlib/nsPrintdXlib.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/mozilla/gfx/src/xlib/nsRegionXlib.cpp b/mozilla/gfx/src/xlib/nsRegionXlib.cpp deleted file mode 100644 index 03685089135..00000000000 --- a/mozilla/gfx/src/xlib/nsRegionXlib.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "prmem.h" -#include "nsRegionXlib.h" -#include "xregion.h" - -// #define DEBUG_REGIONS 1 - -#ifdef DEBUG_REGIONS -static int nRegions; -#endif - -Region nsRegionXlib::copyRegion = 0; - - -nsRegionXlib::nsRegionXlib() -{ -#ifdef DEBUG_REGIONS - ++nRegions; - printf("REGIONS+ = %i\n", nRegions); -#endif - - mRegion = nsnull; -} - -nsRegionXlib::~nsRegionXlib() -{ -#ifdef DEBUG_REGIONS - --nRegions; - printf("REGIONS- = %i\n", nRegions); -#endif - - if (mRegion) - ::XDestroyRegion(mRegion); - mRegion = nsnull; -} - -NS_IMPL_ISUPPORTS1(nsRegionXlib, nsIRegion) - -Region -nsRegionXlib::GetCopyRegion() -{ - if (!copyRegion) - copyRegion = ::XCreateRegion(); - return copyRegion; -} - -Region -nsRegionXlib::xlib_region_copy(Region region) -{ - Region nRegion; - nRegion = XCreateRegion(); - - XUnionRegion(region, GetCopyRegion(), nRegion); - - return nRegion; -} - -Region nsRegionXlib::xlib_region_from_rect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - XRectangle rect; - Region nRegion; - - rect.x = aX; - rect.y = aY; - rect.width = aWidth; - rect.height = aHeight; - - nRegion = XCreateRegion(); - - XUnionRectWithRegion(&rect, GetCopyRegion(), nRegion); - - return nRegion; -} - -nsresult -nsRegionXlib::Init() -{ - if (mRegion) { - ::XDestroyRegion(mRegion); - mRegion = nsnull; - } - - return NS_OK; -} - -void -nsRegionXlib::SetTo(const nsIRegion &aRegion) -{ - Init(); - nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion; - - mRegion = xlib_region_copy(pRegion->mRegion); -} - -void -nsRegionXlib::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - Init(); - mRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight); -} - -void -nsRegionXlib::Intersect(const nsIRegion &aRegion) -{ - nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion; - - Region nRegion = XCreateRegion(); - ::XIntersectRegion(mRegion, pRegion->mRegion, nRegion); - ::XDestroyRegion(mRegion); - mRegion = nRegion; -} - -void -nsRegionXlib::Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - Region tRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight); - - Region nRegion = XCreateRegion(); - - ::XIntersectRegion(mRegion, tRegion, nRegion); - ::XDestroyRegion(tRegion); - ::XDestroyRegion(mRegion); - mRegion = nRegion; -} - -void -nsRegionXlib::Union(const nsIRegion &aRegion) -{ - nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion; - - if (pRegion->mRegion && !::XEmptyRegion(pRegion->mRegion)) { - if (mRegion) { - if (::XEmptyRegion(mRegion)) { - ::XDestroyRegion(mRegion); - mRegion = xlib_region_copy(pRegion->mRegion); - } else { - Region nRegion = ::XCreateRegion(); - ::XUnionRegion(mRegion, pRegion->mRegion, nRegion); - ::XDestroyRegion(mRegion); - mRegion = nRegion; - } - } else - mRegion = xlib_region_copy(pRegion->mRegion); - } -} - -void -nsRegionXlib::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - if (mRegion) { - XRectangle rect; - - rect.x = aX; - rect.y = aY; - rect.width = aWidth; - rect.height = aHeight; - - if (rect.width > 0 && rect.height > 0) { - if (::XEmptyRegion(mRegion)) { - ::XDestroyRegion(mRegion); - mRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight); - } else { - Region nRegion = ::XCreateRegion(); - ::XUnionRectWithRegion(&rect, mRegion, nRegion); - ::XDestroyRegion(mRegion); - mRegion = nRegion; - } - } - } else { - mRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight); - } -} - -void -nsRegionXlib::Subtract(const nsIRegion &aRegion) -{ -#ifdef DEBUG_REGIONS - printf("nsRegionXlib::Subtract "); -#endif - nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion; - - if (pRegion->mRegion) { - if (mRegion) { -#ifdef DEBUG_REGIONS - printf("-"); -#endif - Region nRegion = ::XCreateRegion(); - ::XSubtractRegion(mRegion, pRegion->mRegion, nRegion); - ::XDestroyRegion(mRegion); - mRegion = nRegion; - } else { -#ifdef DEBUG_REGIONS - printf("+"); -#endif - mRegion = ::XCreateRegion(); - ::XSubtractRegion(GetCopyRegion(), pRegion->mRegion, mRegion); - } - } -#ifdef DEBUG_REGIONS - printf("\n"); -#endif -} - -void -nsRegionXlib::Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) -{ - if (mRegion) { - Region tRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight); - - Region nRegion = ::XCreateRegion(); - ::XSubtractRegion(mRegion, tRegion, nRegion); - ::XDestroyRegion(mRegion); - ::XDestroyRegion(tRegion); - mRegion = nRegion; - } else { - Region tRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight); - mRegion = XCreateRegion(); - ::XSubtractRegion(GetCopyRegion(), tRegion, mRegion); - ::XDestroyRegion(tRegion); - } -} - -PRBool -nsRegionXlib::IsEmpty(void) -{ - if (!mRegion) - return PR_TRUE; - return ::XEmptyRegion(mRegion); -} - -PRBool -nsRegionXlib::IsEqual(const nsIRegion &aRegion) -{ - nsRegionXlib *pRegion = (nsRegionXlib *)&aRegion; - - if (mRegion && pRegion->mRegion) { - return ::XEqualRegion(mRegion, pRegion->mRegion); - } else if (!mRegion && !pRegion->mRegion) { - return PR_TRUE; - } else if ((mRegion && !pRegion->mRegion) || - (!mRegion && pRegion->mRegion)) { - return PR_FALSE; - } - - return PR_FALSE; -} - -void -nsRegionXlib::GetBoundingBox(PRInt32 *aX, PRInt32 *aY, - PRInt32 *aWidth, PRInt32 *aHeight) -{ - if (mRegion) { - XRectangle r; - - ::XClipBox(mRegion, &r); - - *aX = r.x; - *aY = r.y; - *aWidth = r.width; - *aHeight = r.height; - } else { - *aX = 0; - *aY = 0; - *aWidth = 0; - *aHeight = 0; - } -} - -void -nsRegionXlib::Offset(PRInt32 aXOffset, PRInt32 aYOffset) -{ - if (mRegion) { - ::XOffsetRegion(mRegion, aXOffset, aYOffset); - } -} - -PRBool -nsRegionXlib::ContainsRect(PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight) -{ - return (::XRectInRegion(mRegion, aX, aY, aWidth, aHeight) == RectangleIn) ? - PR_TRUE : PR_FALSE; -} - -NS_IMETHODIMP -nsRegionXlib::GetRects(nsRegionRectSet **aRects) -{ - *aRects = nsnull; - - if (!mRegion) - return NS_OK; - - nsRegionRectSet *rects; - int nbox; - BOX *pbox; - nsRegionRect *rect; - - NS_ASSERTION(!(nsnull == aRects), "bad ptr"); - - //code lifted from old xfe. MMP - - pbox = mRegion->rects; - nbox = mRegion->numRects; - - rects = *aRects; - - if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox)) { - void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + - (sizeof(nsRegionRect) * (nbox - 1))); - - if (nsnull == buf) { - if (nsnull != rects) - rects->mNumRects = 0; - - return NS_OK; - } - - rects = (nsRegionRectSet *)buf; - rects->mRectsLen = nbox; - } - - rects->mNumRects = nbox; - rects->mArea = 0; - rect = &rects->mRects[0]; - - while (nbox--) { - rect->x = pbox->x1; - rect->width = (pbox->x2 - pbox->x1); - rect->y = pbox->y1; - rect->height = (pbox->y2 - pbox->y1); - - rects->mArea += rect->width * rect->height; - - pbox++; - rect++; - } - - *aRects = rects; - - return NS_OK; -} - -NS_IMETHODIMP -nsRegionXlib::FreeRects(nsRegionRectSet *aRects) -{ - if (nsnull != aRects) - PR_Free((void *)aRects); - - return NS_OK; -} - -NS_IMETHODIMP -nsRegionXlib::GetNativeRegion(void *&aRegion) const -{ - aRegion = (void *)mRegion; - return NS_OK; -} - -NS_IMETHODIMP -nsRegionXlib::GetRegionComplexity(nsRegionComplexity &aComplexity) const -{ - // cast to avoid const-ness problems on some compilers - if (((nsRegionXlib*)this)->IsEmpty()) - aComplexity = eRegionComplexity_empty; - else - aComplexity = eRegionComplexity_rect; - - return NS_OK; -} - -void nsRegionXlib::SetRegionEmpty() -{ - if (!IsEmpty()) { - ::XDestroyRegion(mRegion); - } -} - -NS_IMETHODIMP -nsRegionXlib::GetNumRects(PRUint32 *aRects) const -{ - if (!mRegion) - *aRects = 0; - - *aRects = mRegion->numRects; - - return NS_OK; -} diff --git a/mozilla/gfx/src/xlib/nsRegionXlib.h b/mozilla/gfx/src/xlib/nsRegionXlib.h deleted file mode 100644 index d89a27801b4..00000000000 --- a/mozilla/gfx/src/xlib/nsRegionXlib.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRegionXlib_h___ -#define nsRegionXlib_h___ - -#include "nsIRegion.h" - -#include -#include -#include - -class nsRegionXlib : public nsIRegion -{ - public: - nsRegionXlib(); - virtual ~nsRegionXlib(); - - NS_DECL_ISUPPORTS - - nsresult Init(); - - void SetTo(const nsIRegion &aRegion); - void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - void Intersect(const nsIRegion &aRegion); - void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - void Union(const nsIRegion &aRegion); - void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - void Subtract(const nsIRegion &aRegion); - void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - PRBool IsEmpty(void); - PRBool IsEqual(const nsIRegion &aRegion); - void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight); - void Offset(PRInt32 aXOffset, PRInt32 aYOffset); - PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD GetRects(nsRegionRectSet **aRects); - NS_IMETHOD FreeRects(nsRegionRectSet *aRects); - NS_IMETHOD GetNativeRegion(void *&aRegion) const; - NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; - NS_IMETHOD GetNumRects(PRUint32 *aRects) const; - -protected: - Region xlib_region_copy(Region region); - Region xlib_region_from_rect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - -private: - Region mRegion; - static Region copyRegion; - - inline Region GetCopyRegion(); - inline void SetRegionEmpty(); -}; - -#endif diff --git a/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp b/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp deleted file mode 100644 index f765d3f4c04..00000000000 --- a/mozilla/gfx/src/xlib/nsRenderingContextXlib.cpp +++ /dev/null @@ -1,2505 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * Tony Tsui - * Tomi Leppikangas - * Tim Copperfield - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsRenderingContextXlib.h" -#include "nsFontMetricsXlib.h" -#include "nsCompressedCharMap.h" -#include "xlibrgb.h" -#include "prprf.h" -#include "prmem.h" -#include "prlog.h" -#include "prenv.h" -#include "nsGCCache.h" -#include "imgIContainer.h" -#include "gfxIImageFrame.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" - -#define NS_TO_XLIBRGB_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff) - -NS_IMPL_ISUPPORTS1(nsRenderingContextXlib, nsIRenderingContext) - -#ifdef PR_LOGGING -static PRLogModuleInfo * RenderingContextXlibLM = PR_NewLogModule("RenderingContextXlib"); -#endif /* PR_LOGGING */ - -/* Handle drawing 8 bit data with a 16 bit font */ -static void Widen8To16AndDraw(Drawable drawable, - nsXFont *font, - GC gc, - int x, - int y, - const char *text, - int text_length); - - -nsresult CreateRenderingContextXlibContext(nsIDeviceContext *aDevice, nsRenderingContextXlibContext **aContext) -{ - nsRenderingContextXlibContext *rcctx; - - *aContext = nsnull; - - rcctx = new nsRenderingContextXlibContext(); - if (!rcctx) - return NS_ERROR_OUT_OF_MEMORY; - - /* No |Init()|-function to call (yet) */ - *aContext = rcctx; - - return NS_OK; -} - -void DeleteRenderingContextXlibContext(nsRenderingContextXlibContext *aContext) -{ - if (aContext) { - delete aContext; - } -} - -class GraphicsState -{ -public: - GraphicsState(); - ~GraphicsState(); - - nsTransform2D *mMatrix; - nsCOMPtr mClipRegion; - nscolor mColor; - nsLineStyle mLineStyle; - nsCOMPtr mFontMetrics; -}; - -GraphicsState::GraphicsState() : - mMatrix(nsnull), - mColor(NS_RGB(0, 0, 0)), - mLineStyle(nsLineStyle_kSolid), - mFontMetrics(nsnull) -{ - MOZ_COUNT_CTOR(GraphicsState); - -} - -GraphicsState::~GraphicsState() -{ - MOZ_COUNT_DTOR(GraphicsState); -} - - -nsRenderingContextXlib::nsRenderingContextXlib() : - nsRenderingContextImpl(), - mP2T(1.0f), - mGC(nsnull), - mFunction(GXcopy), - mCurrentColor(NS_RGB(0, 0, 0)), /* X11 intial bg color is always _black_... - * ...but we should query that from - * Xserver instead of guessing that... - */ - mCurrentFont(nsnull), - mCurrentLineStyle(nsLineStyle_kSolid) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::nsRenderingContextXlib()\n")); - - PushState(); -} - -nsRenderingContextXlib::~nsRenderingContextXlib() -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::~nsRenderingContextXlib()\n")); - /* Destroy the State Machine */ - PRInt32 cnt = mStateCache.Count(); - - while (--cnt >= 0) - PopState(); - - if (mTranMatrix) - delete mTranMatrix; - - if (mGC) - mGC->Release(); -} - -NS_IMETHODIMP -nsRenderingContextXlib::Init(nsIDeviceContext* aContext, nsIWidget *aWindow) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::Init(DeviceContext, Widget)\n")); - nsDrawingSurfaceXlibImpl *surf; // saves some cast stunts - - NS_ENSURE_TRUE(aContext != nsnull, NS_ERROR_NULL_POINTER); - NS_ENSURE_TRUE(aWindow != nsnull, NS_ERROR_NULL_POINTER); - mContext = aContext; - - nsIDeviceContext *dc = mContext; - NS_STATIC_CAST(nsDeviceContextX *, dc)->GetXlibRgbHandle(mXlibRgbHandle); - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - - surf = new nsDrawingSurfaceXlibImpl(); - - if (surf) { - Drawable win = (Drawable)aWindow->GetNativeData(NS_NATIVE_WINDOW); - xGC *gc = (xGC *)aWindow->GetNativeData(NS_NATIVE_GRAPHIC); - - surf->Init(mXlibRgbHandle, - win, - gc); - - mOffscreenSurface = mSurface = surf; - /* aWindow->GetNativeData() ref'd the gc */ - gc->Release(); - } - - return CommonInit(); -} - -NS_IMETHODIMP -nsRenderingContextXlib::Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContxtXlib::Init(DeviceContext, DrawingSurface)\n")); - - NS_ENSURE_TRUE(nsnull != aContext, NS_ERROR_NULL_POINTER); - mContext = aContext; - - nsIDeviceContext *dc = mContext; - NS_STATIC_CAST(nsDeviceContextX *, dc)->GetXlibRgbHandle(mXlibRgbHandle); - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - - mSurface = (nsIDrawingSurfaceXlib *)aSurface; - mOffscreenSurface = mSurface; - - return CommonInit(); -} - -nsresult nsRenderingContextXlib::CommonInit(void) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContxtXlib::CommonInit()\n")); - // put common stuff in here. - int x, y; - unsigned int width, height, border, depth; - Window root_win; - - Drawable drawable; mSurface->GetDrawable(drawable); - - ::XGetGeometry(mDisplay, - drawable, - &root_win, - &x, - &y, - &width, - &height, - &border, - &depth); - - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, - ("XGetGeometry(display=%lx,drawable=%lx) =" - " {root_win=%lx, x=%d, y=%d, width=%d, height=%d. border=%d, depth=%d}\n", - (long)mDisplay, (long)drawable, - (long)root_win, (int)x, (int)y, (int)width, (int)height, (int)border, (int)depth)); - - mClipRegion = new nsRegionXlib(); - if (!mClipRegion) - return NS_ERROR_OUT_OF_MEMORY; - mClipRegion->Init(); - mClipRegion->SetTo(0, 0, width, height); - - mP2T = mContext->DevUnitsToAppUnits(); - float app2dev; - app2dev = mContext->AppUnitsToDevUnits(); - mTranMatrix->AddScale(app2dev, app2dev); - return NS_OK; -} - - -NS_IMETHODIMP -nsRenderingContextXlib::GetHints(PRUint32& aResult) -{ - PRUint32 result = 0; - - // Most X servers implement 8 bit text rendering a lot faster than - // XChar2b rendering. In addition, we can avoid the PRUnichar to - // XChar2b conversion. So we set this bit... - result |= NS_RENDERING_HINT_FAST_8BIT_TEXT; - -/* We can't enable fast text measuring (yet) on platforms - * which force natural alignment of datatypes (see - * http://bugzilla.mozilla.org/show_bug.cgi?id=36146#c46) ... ;-( - */ -#ifndef CPU_DOES_NOT_REQUIRE_NATURAL_ALIGNMENT -#if defined(__i386) -#define CPU_DOES_NOT_REQUIRE_NATURAL_ALIGNMENT 1 -#endif /* __i386 */ -#endif /* !CPU_DOES_NOT_REQUIRE_NATURAL_ALIGNMENT */ - - static PRBool enable_fast_measure; - static PRBool getenv_done = PR_FALSE; - - /* Check for the env vars "MOZILLA_GFX_ENABLE_FAST_MEASURE" and - * "MOZILLA_GFX_DISABLE_FAST_MEASURE" to enable/disable fast text - * measuring (for debugging the feature and doing regression tests). - * This code will be removed one all issues around this new feature have - * been fixed. */ - if (!getenv_done) - { -#ifdef CPU_DOES_NOT_REQUIRE_NATURAL_ALIGNMENT - enable_fast_measure = PR_TRUE; -#else - enable_fast_measure = PR_FALSE; -#endif /* CPU_DOES_NOT_REQUIRE_NATURAL_ALIGNMENT */ - - if (PR_GetEnv("MOZILLA_GFX_ENABLE_FAST_MEASURE")) - { - enable_fast_measure = PR_TRUE; - } - - if (PR_GetEnv("MOZILLA_GFX_DISABLE_FAST_MEASURE")) - { - enable_fast_measure = PR_FALSE; - } - - getenv_done = PR_TRUE; - } - - if (enable_fast_measure) { - // We have GetTextDimensions() - result |= NS_RENDERING_HINT_FAST_MEASURE; - } - - // XXX see if we are rendering to the local display or to a remote - // dispaly and set the NS_RENDERING_HINT_REMOTE_RENDERING accordingly - - aResult = result; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::LockDrawingSurface(PRInt32 aX, PRInt32 aY, - PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, - PRInt32 *aWidthBytes, PRUint32 aFlags) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::LockDrawingSurface()\n")); - PushState(); - - return mSurface->Lock(aX, aY, aWidth, aHeight, - aBits, aStride, aWidthBytes, aFlags); -} - -NS_IMETHODIMP -nsRenderingContextXlib::UnlockDrawingSurface(void) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::UnlockDrawingSurface()\n")); - PopState(); - - mSurface->Unlock(); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SelectOffScreenDrawingSurface()\n")); - if (nsnull == aSurface) - mSurface = mOffscreenSurface; - else - mSurface = (nsIDrawingSurfaceXlib *)aSurface; - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetDrawingSurface(nsIDrawingSurface* *aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetDrawingSurface()\n")); - *aSurface = mSurface; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::Reset() -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::Reset()\n")); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextXlib::GetDeviceContext(nsIDeviceContext *&aContext) -{ - aContext = mContext; - NS_IF_ADDREF(aContext); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::PushState(void) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::PushState()\n")); - GraphicsState *state = new GraphicsState(); - - if (!state) - return NS_ERROR_OUT_OF_MEMORY; - - state->mMatrix = mTranMatrix; - - mStateCache.AppendElement(state); - - if (nsnull == mTranMatrix) - mTranMatrix = new nsTransform2D(); - else - mTranMatrix = new nsTransform2D(mTranMatrix); - - if (mClipRegion) { - state->mClipRegion = mClipRegion; - mClipRegion = new nsRegionXlib(); - if (!mClipRegion) - return NS_ERROR_OUT_OF_MEMORY; - mClipRegion->Init(); - mClipRegion->SetTo(*state->mClipRegion); - } - - state->mFontMetrics = mFontMetrics; - state->mColor = mCurrentColor; - state->mLineStyle = mCurrentLineStyle; - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::PopState(void) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::PopState()\n")); - - PRUint32 cnt = mStateCache.Count(); - GraphicsState *state; - - if (cnt > 0) { - state = (GraphicsState *)mStateCache.ElementAt(cnt - 1); - mStateCache.RemoveElementAt(cnt - 1); - - if (mTranMatrix) - delete mTranMatrix; - mTranMatrix = state->mMatrix; - - mClipRegion = state->mClipRegion; - if (mFontMetrics != state->mFontMetrics) - SetFont(state->mFontMetrics); - - if (state->mColor != mCurrentColor) - SetColor(state->mColor); - if (state->mLineStyle != mCurrentLineStyle) - SetLineStyle(state->mLineStyle); - - delete state; - } - - return NS_OK; -} - -#ifdef DEBUG -#undef TRACE_SET_CLIP -#endif - -#ifdef TRACE_SET_CLIP -static char * -nsClipCombine_to_string(nsClipCombine aCombine) -{ -#ifdef TRACE_SET_CLIP - printf("nsRenderingContextXlib::SetClipRect(x=%d,y=%d,w=%d,h=%d,%s)\n", - trect.x, - trect.y, - trect.width, - trect.height, - nsClipCombine_to_string(aCombine)); -#endif // TRACE_SET_CLIP - - switch(aCombine) - { - case nsClipCombine_kIntersect: - return "nsClipCombine_kIntersect"; - break; - - case nsClipCombine_kUnion: - return "nsClipCombine_kUnion"; - break; - - case nsClipCombine_kSubtract: - return "nsClipCombine_kSubtract"; - break; - - case nsClipCombine_kReplace: - return "nsClipCombine_kReplace"; - break; - } - - return "something got screwed"; -} -#endif // TRACE_SET_CLIP - -NS_IMETHODIMP -nsRenderingContextXlib::IsVisibleRect(const nsRect& aRect, PRBool &aVisible) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::IsVisibleRect()\n")); - aVisible = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::SetClipRect(const nsRect& aRect, - nsClipCombine aCombine) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SetClipRect()\n")); - nsRect trect = aRect; - mTranMatrix->TransformCoord(&trect.x, &trect.y, - &trect.width, &trect.height); - SetClipRectInPixels(trect, aCombine); - return NS_OK; -} - -void nsRenderingContextXlib::SetClipRectInPixels(const nsRect& aRect, - nsClipCombine aCombine) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SetClipRectInPixels()\n")); - - switch(aCombine) - { - case nsClipCombine_kIntersect: - mClipRegion->Intersect(aRect.x,aRect.y,aRect.width,aRect.height); - break; - case nsClipCombine_kUnion: - mClipRegion->Union(aRect.x,aRect.y,aRect.width,aRect.height); - break; - case nsClipCombine_kSubtract: - mClipRegion->Subtract(aRect.x,aRect.y,aRect.width,aRect.height); - break; - case nsClipCombine_kReplace: - mClipRegion->SetTo(aRect.x,aRect.y,aRect.width,aRect.height); - break; - } -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetClipRect(nsRect &aRect, PRBool &aClipState) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetClipRext()\n")); - PRInt32 x, y, w, h; - if (!mClipRegion->IsEmpty()) { - mClipRegion->GetBoundingBox(&x,&y,&w,&h); - aRect.SetRect(x,y,w,h); - aClipState = PR_TRUE; - } else { - aRect.SetRect(0,0,0,0); - aClipState = PR_FALSE; - } - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SetClipRegion()\n")); - switch(aCombine) - { - case nsClipCombine_kIntersect: - mClipRegion->Intersect(aRegion); - break; - case nsClipCombine_kUnion: - mClipRegion->Union(aRegion); - break; - case nsClipCombine_kSubtract: - mClipRegion->Subtract(aRegion); - break; - case nsClipCombine_kReplace: - mClipRegion->SetTo(aRegion); - break; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::CopyClipRegion(nsIRegion &aRegion) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::CopyClipRegion()\n")); - aRegion.SetTo(*mClipRegion); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetClipRegion(nsIRegion **aRegion) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetClipRegion()\n")); - nsresult rv = NS_OK; - - NS_ASSERTION(!(nsnull == aRegion), "no region ptr"); - - if (*aRegion) { - (*aRegion)->SetTo(*mClipRegion); - } - return rv; -} - -void nsRenderingContextXlib::UpdateGC() -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::UpdateGC()\n")); - XGCValues values; - unsigned long valuesMask = 0; - - Drawable drawable; mOffscreenSurface->GetDrawable(drawable); - - if (mGC) - mGC->Release(); - - memset(&values, 0, sizeof(XGCValues)); - - unsigned long color; - color = xxlib_rgb_xpixel_from_rgb (mXlibRgbHandle, - NS_RGB(NS_GET_B(mCurrentColor), - NS_GET_G(mCurrentColor), - NS_GET_R(mCurrentColor))); - values.foreground = color; - valuesMask |= GCForeground; - - if (mCurrentFont && mCurrentFont->GetXFontStruct()) { - valuesMask |= GCFont; - values.font = mCurrentFont->GetXFontStruct()->fid; - } - - values.line_style = mLineStyle; - valuesMask |= GCLineStyle; - - values.function = mFunction; - valuesMask |= GCFunction; - - Region rgn = nsnull; - if (mClipRegion) { - mClipRegion->GetNativeRegion((void*&)rgn); - } - - nsRenderingContextXlibContext *rcContext; - nsIDeviceContext *dc = mContext; - NS_STATIC_CAST(nsDeviceContextX *, dc)->GetRCContext(rcContext); - - mGC = rcContext->mGcCache.GetGC(mDisplay, drawable, - valuesMask, &values, rgn); -} - -NS_IMETHODIMP -nsRenderingContextXlib::SetColor(nscolor aColor) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SetColor(nscolor)\n")); - NS_ENSURE_TRUE(mContext != nsnull, NS_ERROR_FAILURE); - - mCurrentColor = aColor; - - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("Setting color to %d %d %d\n", NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor))); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetColor(nscolor &aColor) const -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetColor()\n")); - - aColor = mCurrentColor; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::SetFont(const nsFont& aFont, nsIAtom* aLangGroup) -{ - nsCOMPtr newMetrics; - nsresult rv = mContext->GetMetricsFor( aFont, aLangGroup, *getter_AddRefs(newMetrics) ); - - if (NS_SUCCEEDED(rv)) { - rv = SetFont(newMetrics); - } - return rv; -} - -NS_IMETHODIMP -nsRenderingContextXlib::SetFont(nsIFontMetrics *aFontMetrics) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SetFont()\n")); - - mFontMetrics = aFontMetrics; - - if (mFontMetrics) - { - nsFontHandle fontHandle; - mFontMetrics->GetFontHandle(fontHandle); - mCurrentFont = (nsFontXlib *)fontHandle; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::SetLineStyle(nsLineStyle aLineStyle) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SetLineStyle()\n")); - - if (aLineStyle != mCurrentLineStyle) { - /* XXX this isn't done in gtk, copy from there when ready - switch(aLineStyle) - { - case nsLineStyle_kSolid: - mLineStyle = LineSolid; - mDashes = 0; - break; - case nsLineStyle_kDashed: - static char dashed[2] = {4,4}; - mDashList = dashed; - mDashes = 2; - break; - case nsLineStyle_kDotted: - static char dotted[2] = {3,1}; - mDashList = dotted; - mDashes = 2; - break; - default: - break; - - } - */ - mCurrentLineStyle = aLineStyle ; - } - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetLineStyle(nsLineStyle &aLineStyle) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetLineStyle()\n")); - aLineStyle = mCurrentLineStyle; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetFontMetrics(nsIFontMetrics *&aFontMetrics) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetFontMetrics()\n")); - - aFontMetrics = mFontMetrics; - NS_IF_ADDREF(aFontMetrics); - return NS_OK; -} - -// add the passed in translation to the current translation -NS_IMETHODIMP -nsRenderingContextXlib::Translate(nscoord aX, nscoord aY) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::Translate()\n")); - mTranMatrix->AddTranslation((float)aX,(float)aY); - return NS_OK; -} - -// add the passed in scale to the current scale -NS_IMETHODIMP -nsRenderingContextXlib::Scale(float aSx, float aSy) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::Scale()\n")); - mTranMatrix->AddScale(aSx, aSy); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetCurrentTransform(nsTransform2D *&aTransform) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetCurrentTransform()\n")); - aTransform = mTranMatrix; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::CreateDrawingSurface(const nsRect& aBounds, - PRUint32 aSurfFlags, - nsIDrawingSurface* &aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::CreateDrawingSurface()\n")); - - if (nsnull == mSurface) { - aSurface = nsnull; - return NS_ERROR_FAILURE; - } - - NS_ENSURE_TRUE((aBounds.width > 0) && (aBounds.height > 0), NS_ERROR_FAILURE); - - nsresult rv = NS_ERROR_FAILURE; - nsDrawingSurfaceXlibImpl *surf = new nsDrawingSurfaceXlibImpl(); - - if (surf) - { - NS_ADDREF(surf); - UpdateGC(); - rv = surf->Init(mXlibRgbHandle, mGC, aBounds.width, aBounds.height, aSurfFlags); - } - - aSurface = surf; - - return rv; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DestroyDrawingSurface(nsIDrawingSurface* aDS) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DestroyDrawingSurface()\n")); - nsIDrawingSurfaceXlib *surf = NS_STATIC_CAST(nsIDrawingSurfaceXlib *, aDS);; - - NS_ENSURE_TRUE(surf != nsnull, NS_ERROR_FAILURE); - - NS_IF_RELEASE(surf); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawLine()\n")); - - nscoord diffX, diffY; - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - mTranMatrix->TransformCoord(&aX0,&aY0); - mTranMatrix->TransformCoord(&aX1,&aY1); - - diffX = aX1-aX0; - diffY = aY1-aY0; - - if (0!=diffX) { - diffX = (diffX>0?1:-1); - } - if (0!=diffY) { - diffY = (diffY>0?1:-1); - } - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XDrawLine(mDisplay, drawable, - *mGC, aX0, aY0, aX1 - diffX, aY1 - diffY); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawPolyLine()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - PRInt32 i; - XPoint * xpoints; - XPoint * thispoint; - - xpoints = (XPoint *) malloc(sizeof(XPoint) * aNumPoints); - NS_ENSURE_TRUE(xpoints != nsnull, NS_ERROR_OUT_OF_MEMORY); - - for (i = 0; i < aNumPoints; i++){ - thispoint = (xpoints+i); - thispoint->x = aPoints[i].x; - thispoint->y = aPoints[i].y; - mTranMatrix->TransformCoord((PRInt32*)&thispoint->x,(PRInt32*)&thispoint->y); - } - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XDrawLines(mDisplay, - drawable, - *mGC, - xpoints, aNumPoints, CoordModeOrigin); - - free((void *)xpoints); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawRect(const nsRect& aRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawRext(const nsRect& aRect)\n")); - return DrawRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawRect(aX, aY, aWidth, aHeight)\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - nscoord x, y, w, h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - // After the transform, if the numbers are huge, chop them, because - // they're going to be converted from 32 bit to 16 bit. - // It's all way off the screen anyway. - ConditionRect(x,y,w,h); - - // Don't draw empty rectangles; also, w/h are adjusted down by one - // so that the right number of pixels are drawn. - if (w && h) - { - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XDrawRectangle(mDisplay, - drawable, - *mGC, - x, - y, - w-1, - h-1); - } - - return NS_OK; -} - - -NS_IMETHODIMP -nsRenderingContextXlib::FillRect(const nsRect& aRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillRect()\n")); - return FillRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP -nsRenderingContextXlib::FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillRect()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - nscoord x,y,w,h; - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - // After the transform, if the numbers are huge, chop them, because - // they're going to be converted from 32 bit to 16 bit. - // It's all way off the screen anyway. - ConditionRect(x,y,w,h); - - Drawable drawable; mSurface->GetDrawable(drawable); - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("About to fill window 0x%lxd with rect %d %d %d %d\n", - drawable, x, y, w, h)); - UpdateGC(); - ::XFillRectangle(mDisplay, - drawable, - *mGC, - x,y,w,h); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::InvertRect(const nsRect& aRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::InvertRect()\n")); - return InvertRect(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP -nsRenderingContextXlib::InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::InvertRect()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - // Back up the current color, and use GXxor against white to get a - // visible result. - nscolor backupColor = mCurrentColor; - mCurrentColor = NS_RGB(255, 255, 255); - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - // After the transform, if the numbers are huge, chop them, because - // they're going to be converted from 32 bit to 16 bit. - // It's all way off the screen anyway. - ConditionRect(x,y,w,h); - - mFunction = GXxor; - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XFillRectangle(mDisplay, - drawable, - *mGC, - x, - y, - w, - h); - - mFunction = GXcopy; - - // Restore current color - mCurrentColor = backupColor; - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawPolygon()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - PRInt32 i ; - XPoint * xpoints; - XPoint * thispoint; - - xpoints = (XPoint *) malloc(sizeof(XPoint) * aNumPoints); - NS_ENSURE_TRUE(xpoints != nsnull, NS_ERROR_OUT_OF_MEMORY); - - for (i = 0; i < aNumPoints; i++){ - thispoint = (xpoints+i); - thispoint->x = aPoints[i].x; - thispoint->y = aPoints[i].y; - mTranMatrix->TransformCoord((PRInt32*)&thispoint->x,(PRInt32*)&thispoint->y); - } - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XDrawLines(mDisplay, - drawable, - *mGC, - xpoints, aNumPoints, CoordModeOrigin); - - free((void *)xpoints); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillPolygon()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - PRInt32 i ; - XPoint * xpoints; - - xpoints = (XPoint *) malloc(sizeof(XPoint) * aNumPoints); - NS_ENSURE_TRUE(xpoints != nsnull, NS_ERROR_OUT_OF_MEMORY); - - for (i = 0; i < aNumPoints; ++i) { - nsPoint p = aPoints[i]; - mTranMatrix->TransformCoord(&p.x, &p.y); - xpoints[i].x = p.x; - xpoints[i].y = p.y; - } - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XFillPolygon(mDisplay, - drawable, - *mGC, - xpoints, aNumPoints, Complex, CoordModeOrigin); - - free((void *)xpoints); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawEllipse(const nsRect& aRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawEllipse(const nsRect& aRect)\n")); - return DrawEllipse(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawEllipse(aX, aY, aWidth, aHeight)\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - nscoord x, y, w, h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XDrawArc(mDisplay, - drawable, - *mGC, - x, y, w, h, 0, 360*64); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::FillEllipse(const nsRect& aRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillEllipse()\n")); - return FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height); -} - -NS_IMETHODIMP -nsRenderingContextXlib::FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillEllipse()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - if (w < 16 || h < 16) { - /* Fix for bug 91816 ("bullets are not displayed correctly on certain text zooms") - * De-uglify bullets on some X servers: - * 1st: Draw... */ - ::XDrawArc(mDisplay, - drawable, - *mGC, - x, y, w, h, 0, 360*64); - /* ...then fill. */ - } - ::XFillArc(mDisplay, - drawable, - *mGC, - x, y, w, h, 0, 360*64); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawArc(const nsRect& aRect, - float aStartAngle, float aEndAngle) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawArc()\n")); - return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle); -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, - float aStartAngle, float aEndAngle) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawArc()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - nscoord x, y, w, h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XDrawArc(mDisplay, - drawable, - *mGC, - x,y,w,h, NSToIntRound(aStartAngle * 64.0f), - NSToIntRound(aEndAngle * 64.0f)); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::FillArc(const nsRect& aRect, - float aStartAngle, float aEndAngle) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillArc()\n")); - return FillArc(aRect.x, aRect.y, aRect.width, aRect.height, aStartAngle, aEndAngle); -} - -NS_IMETHODIMP -nsRenderingContextXlib::FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, - float aStartAngle, float aEndAngle) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::FillArc()\n")); - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - - mTranMatrix->TransformCoord(&x,&y,&w,&h); - - UpdateGC(); - Drawable drawable; mSurface->GetDrawable(drawable); - ::XFillArc(mDisplay, - drawable, - *mGC, - x,y,w,h, NSToIntRound(aStartAngle * 64.0f), - NSToIntRound(aEndAngle * 64.0f)); - - return NS_OK; -} - -// do the 8 to 16 bit conversion on the stack -// if the data is less than this size -#define WIDEN_8_TO_16_BUF_SIZE (1024) - -// handle 8 bit data with a 16 bit font -static -int Widen8To16AndMove(const char *char_p, - int char_len, - XChar2b *xchar2b_p) -{ - int i; - for (i=0; ibyte1 = 0; - (xchar2b_p++)->byte2 = *char_p++; - } - return(char_len*2); -} - -// handle 8 bit data with a 16 bit font -static -int Widen8To16AndGetWidth(nsXFont *xFont, - const char *text, - int text_length) -{ - NS_ASSERTION(!xFont->IsSingleByte(), "Widen8To16AndGetWidth: wrong string/font size"); - XChar2b buf[WIDEN_8_TO_16_BUF_SIZE]; - XChar2b *p = buf; - int uchar_size; - int rawWidth; - - if (text_length > WIDEN_8_TO_16_BUF_SIZE) { - p = (XChar2b*)malloc(text_length*sizeof(XChar2b)); - if (!p) - return(0); // handle malloc failure - } - - uchar_size = Widen8To16AndMove(text, text_length, p); - rawWidth = xFont->TextWidth16(p, uchar_size/2); - - if (text_length > WIDEN_8_TO_16_BUF_SIZE) { - free((char*)p); - } - return(rawWidth); -} - -static -void Widen8To16AndDraw(Drawable drawable, - nsXFont *xFont, - GC gc, - int x, - int y, - const char *text, - int text_length) -{ - NS_ASSERTION(!xFont->IsSingleByte(), "Widen8To16AndDraw: wrong string/font size"); - XChar2b buf[WIDEN_8_TO_16_BUF_SIZE]; - XChar2b *p = buf; - int uchar_size; - - if (text_length > WIDEN_8_TO_16_BUF_SIZE) { - p = (XChar2b*)malloc(text_length*sizeof(XChar2b)); - if (!p) - return; // handle malloc failure - } - - uchar_size = Widen8To16AndMove(text, text_length, p); - xFont->DrawText16(drawable, gc, x, y, p, uchar_size/2); - - if (text_length > WIDEN_8_TO_16_BUF_SIZE) { - free((char*)p); - } -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetWidth(char aC, nscoord &aWidth) -{ - // Check for the very common case of trying to get the width of a single - // space. - if ((aC == ' ') && (nsnull != mFontMetrics)) { - return mFontMetrics->GetSpaceWidth(aWidth); - } - return GetWidth(&aC, 1, aWidth); -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetWidth(PRUnichar aC, nscoord& aWidth, - PRInt32* aFontID) -{ - return GetWidth(&aC, 1, aWidth, aFontID); -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetWidth(const nsString& aString, - nscoord& aWidth, PRInt32* aFontID) -{ - return GetWidth(aString.get(), aString.Length(), aWidth, aFontID); -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetWidth(const char* aString, nscoord& aWidth) -{ - return GetWidth(aString, strlen(aString), aWidth); -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetWidth(const char* aString, PRUint32 aLength, - nscoord& aWidth) -{ - if (0 == aLength) { - aWidth = 0; - } - else { - NS_ENSURE_TRUE(aString != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mCurrentFont != nsnull, NS_ERROR_FAILURE); - int rawWidth; - nsXFont *xFont = mCurrentFont->GetXFont(); -#ifdef USE_FREETYPE - if (mCurrentFont->IsFreeTypeFont()) { - // this function is only supposed to be called for ascii data - rawWidth = mCurrentFont-> - GetWidth(NS_ConvertASCIItoUTF16(aString, aLength).get(), aLength); - } - else -#endif /* USE_FREETYPE */ - if (!mCurrentFont->GetXFontIs10646()) { - NS_ASSERTION(xFont->IsSingleByte(), "wrong string/font size"); - // 8 bit data with an 8 bit font - rawWidth = xFont->TextWidth8(aString, aLength); - } - else { - NS_ASSERTION(!xFont->IsSingleByte(), "wrong string/font size"); - // we have 8 bit data but a 16 bit font - rawWidth = Widen8To16AndGetWidth (mCurrentFont->GetXFont(), aString, aLength); - } - aWidth = NSToCoordRound(rawWidth * mP2T); - } - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetWidth(const PRUnichar* aString, PRUint32 aLength, - nscoord& aWidth, PRInt32* aFontID) -{ - if (0 == aLength) { - aWidth = 0; - } - else { - NS_ENSURE_TRUE(aString != nsnull, NS_ERROR_FAILURE); - - nsFontMetricsXlib *metrics = NS_REINTERPRET_CAST(nsFontMetricsXlib *, mFontMetrics.get()); - - NS_ENSURE_TRUE(metrics != nsnull, NS_ERROR_FAILURE); - - nsFontXlib *prevFont = nsnull; - int rawWidth = 0; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontXlib *currFont = nsnull; - nsFontXlib **font = metrics->mLoadedFonts; - nsFontXlib **end = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < end) { - if (CCMAP_HAS_CHAR((*font)->mCCMap, c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; - } - currFont = metrics->FindFont(c); -FoundFont: - // XXX avoid this test by duplicating code -- erik - if (prevFont) { - if (currFont != prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - prevFont = currFont; - start = i; - } - } - else { - prevFont = currFont; - start = i; - } - } - - if (prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - } - - aWidth = NSToCoordRound(rawWidth * mP2T); - } - if (nsnull != aFontID) - *aFontID = 0; - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetTextDimensions(const char* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID) -{ - NS_PRECONDITION(aBreaks[aNumBreaks - 1] == aLength, "invalid break array"); - - if (nsnull != mFontMetrics) { - // If we need to back up this state represents the last place we could - // break. We can use this to avoid remeasuring text - PRInt32 prevBreakState_BreakIndex = -1; // not known (hasn't been computed) - nscoord prevBreakState_Width = 0; // accumulated width to this point - - // Initialize OUT parameters - mFontMetrics->GetMaxAscent(aLastWordDimensions.ascent); - mFontMetrics->GetMaxDescent(aLastWordDimensions.descent); - aLastWordDimensions.width = -1; - aNumCharsFit = 0; - - // Iterate each character in the string and determine which font to use - nscoord width = 0; - PRInt32 start = 0; - nscoord aveCharWidth; - mFontMetrics->GetAveCharWidth(aveCharWidth); - - while (start < aLength) { - // Estimate how many characters will fit. Do that by diving the available - // space by the average character width. Make sure the estimated number - // of characters is at least 1 - PRInt32 estimatedNumChars = 0; - if (aveCharWidth > 0) { - estimatedNumChars = (aAvailWidth - width) / aveCharWidth; - } - if (estimatedNumChars < 1) { - estimatedNumChars = 1; - } - - // Find the nearest break offset - PRInt32 estimatedBreakOffset = start + estimatedNumChars; - PRInt32 breakIndex; - nscoord numChars; - - // Find the nearest place to break that is less than or equal to - // the estimated break offset - if (aLength <= estimatedBreakOffset) { - // All the characters should fit - numChars = aLength - start; - breakIndex = aNumBreaks - 1; - } - else { - breakIndex = prevBreakState_BreakIndex; - while (((breakIndex + 1) < aNumBreaks) && - (aBreaks[breakIndex + 1] <= estimatedBreakOffset)) { - ++breakIndex; - } - if (breakIndex == prevBreakState_BreakIndex) { - ++breakIndex; // make sure we advanced past the previous break index - } - numChars = aBreaks[breakIndex] - start; - } - - // Measure the text - nscoord twWidth = 0; - if ((1 == numChars) && (aString[start] == ' ')) { - mFontMetrics->GetSpaceWidth(twWidth); - } - else if (numChars > 0) - GetWidth( &aString[start], numChars, twWidth); - - // See if the text fits - PRBool textFits = (twWidth + width) <= aAvailWidth; - - // If the text fits then update the width and the number of - // characters that fit - if (textFits) { - aNumCharsFit += numChars; - width += twWidth; - start += numChars; - - // This is a good spot to back up to if we need to so remember - // this state - prevBreakState_BreakIndex = breakIndex; - prevBreakState_Width = width; - } - else { - // See if we can just back up to the previous saved state and not - // have to measure any text - if (prevBreakState_BreakIndex > 0) { - // If the previous break index is just before the current break index - // then we can use it - if (prevBreakState_BreakIndex == (breakIndex - 1)) { - aNumCharsFit = aBreaks[prevBreakState_BreakIndex]; - width = prevBreakState_Width; - break; - } - } - - // We can't just revert to the previous break state - if (0 == breakIndex) { - // There's no place to back up to, so even though the text doesn't fit - // return it anyway - aNumCharsFit += numChars; - width += twWidth; - break; - } - - // Repeatedly back up until we get to where the text fits or we're all - // the way back to the first word - width += twWidth; - while ((breakIndex >= 1) && (width > aAvailWidth)) { - twWidth = 0; - start = aBreaks[breakIndex - 1]; - numChars = aBreaks[breakIndex] - start; - - if ((1 == numChars) && (aString[start] == ' ')) { - mFontMetrics->GetSpaceWidth(twWidth); - } - else if (numChars > 0) - GetWidth( &aString[start], numChars, twWidth); - - width -= twWidth; - aNumCharsFit = start; - breakIndex--; - } - break; - } - } - - aDimensions.width = width; - mFontMetrics->GetMaxAscent(aDimensions.ascent); - mFontMetrics->GetMaxDescent(aDimensions.descent); - - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -struct BreakGetTextDimensionsData { - float mP2T; // IN - PRInt32 mAvailWidth; // IN - PRInt32* mBreaks; // IN - PRInt32 mNumBreaks; // IN - nscoord mSpaceWidth; // IN - nscoord mAveCharWidth; // IN - PRInt32 mEstimatedNumChars; // IN (running -- to handle the edge case of one word) - - PRInt32 mNumCharsFit; // IN/OUT -- accumulated number of chars that fit so far - nscoord mWidth; // IN/OUT -- accumulated width so far - - // If we need to back up, this state represents the last place - // we could break. We can use this to avoid remeasuring text - PRInt32 mPrevBreakState_BreakIndex; // IN/OUT, initialized as -1, i.e., not yet computed - nscoord mPrevBreakState_Width; // IN/OUT, initialized as 0 - - // Remember the fonts that we use so that we can deal with - // line-breaking in-between fonts later. mOffsets[0] is also used - // to initialize the current offset from where to start measuring - nsVoidArray* mFonts; // IN/OUT - nsVoidArray* mOffsets; // IN/OUT -}; - -static PRBool PR_CALLBACK -do_BreakGetTextDimensions(const nsFontSwitchXlib *aFontSwitch, - const PRUnichar* aSubstring, - PRUint32 aSubstringLength, - void* aData) -{ - nsFontXlib *fontXlib = aFontSwitch->mFontXlib; - - // Make sure the font is selected - BreakGetTextDimensionsData* data = (BreakGetTextDimensionsData*)aData; - - // Our current state relative to the _full_ string... - // This allows emulation of the previous code... - const PRUnichar* pstr = (const PRUnichar*)data->mOffsets->ElementAt(0); - PRInt32 numCharsFit = data->mNumCharsFit; - nscoord width = data->mWidth; - PRInt32 start = (PRInt32)(aSubstring - pstr); - PRInt32 end = start + aSubstringLength; - PRBool allDone = PR_FALSE; - - while (start < end) { - // Estimate how many characters will fit. Do that by dividing the - // available space by the average character width - PRInt32 estimatedNumChars = data->mEstimatedNumChars; - if (!estimatedNumChars && data->mAveCharWidth > 0) { - estimatedNumChars = (data->mAvailWidth - width) / data->mAveCharWidth; - } - // Make sure the estimated number of characters is at least 1 - if (estimatedNumChars < 1) { - estimatedNumChars = 1; - } - - // Find the nearest break offset - PRInt32 estimatedBreakOffset = start + estimatedNumChars; - PRInt32 breakIndex = -1; // not yet computed - PRBool inMiddleOfSegment = PR_FALSE; - nscoord numChars; - - // Avoid scanning the break array in the case where we think all - // the text should fit - if (end <= estimatedBreakOffset) { - // Everything should fit - numChars = end - start; - } - else { - // Find the nearest place to break that is less than or equal to - // the estimated break offset - breakIndex = data->mPrevBreakState_BreakIndex; - while (breakIndex + 1 < data->mNumBreaks && - data->mBreaks[breakIndex + 1] <= estimatedBreakOffset) { - ++breakIndex; - } - - if (breakIndex == -1) - breakIndex = 0; - - // We found a place to break that is before the estimated break - // offset. Where we break depends on whether the text crosses a - // segment boundary - if (start < data->mBreaks[breakIndex]) { - // The text crosses at least one segment boundary so measure to the - // break point just before the estimated break offset - numChars = PR_MIN(data->mBreaks[breakIndex], end) - start; - } - else { - // See whether there is another segment boundary between this one - // and the end of the text - if ((breakIndex < (data->mNumBreaks - 1)) && (data->mBreaks[breakIndex] < end)) { - ++breakIndex; - numChars = PR_MIN(data->mBreaks[breakIndex], end) - start; - } - else { - NS_ASSERTION(end != data->mBreaks[breakIndex], "don't expect to be at segment boundary"); - - // The text is all within the same segment - numChars = end - start; - - // Remember we're in the middle of a segment and not between - // two segments - inMiddleOfSegment = PR_TRUE; - } - } - } - - // Measure the text - nscoord twWidth, pxWidth; - if ((1 == numChars) && (pstr[start] == ' ')) { - twWidth = data->mSpaceWidth; - } - else { - pxWidth = fontXlib->GetWidth(&pstr[start], numChars); - twWidth = NSToCoordRound(float(pxWidth) * data->mP2T); - } - - // See if the text fits - PRBool textFits = (twWidth + width) <= data->mAvailWidth; - - // If the text fits then update the width and the number of - // characters that fit - if (textFits) { - numCharsFit += numChars; - width += twWidth; - - // If we computed the break index and we're not in the middle - // of a segment then this is a spot that we can back up to if - // we need to, so remember this state - if ((breakIndex != -1) && !inMiddleOfSegment) { - data->mPrevBreakState_BreakIndex = breakIndex; - data->mPrevBreakState_Width = width; - } - } - else { - // The text didn't fit. If we're out of room then we're all done - allDone = PR_TRUE; - - // See if we can just back up to the previous saved state and not - // have to measure any text - if (data->mPrevBreakState_BreakIndex != -1) { - PRBool canBackup; - - // If we're in the middle of a word then the break index - // must be the same if we can use it. If we're at a segment - // boundary, then if the saved state is for the previous - // break index then we can use it - if (inMiddleOfSegment) { - canBackup = data->mPrevBreakState_BreakIndex == breakIndex; - } else { - canBackup = data->mPrevBreakState_BreakIndex == (breakIndex - 1); - } - - if (canBackup) { - numCharsFit = data->mBreaks[data->mPrevBreakState_BreakIndex]; - width = data->mPrevBreakState_Width; - break; - } - } - - // We can't just revert to the previous break state. Find the break - // index just before the end of the text - end = start + numChars; - breakIndex = 0; - if (data->mBreaks[breakIndex] < end) { - while ((breakIndex + 1 < data->mNumBreaks) && (data->mBreaks[breakIndex + 1] < end)) { - ++breakIndex; - } - } - - if ((0 == breakIndex) && (end <= data->mBreaks[0])) { - // There's no place to back up to, so even though the text doesn't fit - // return it anyway - numCharsFit += numChars; - width += twWidth; - - // Edge case of one word: it could be that we just measured a fragment of the - // first word and its remainder involves other fonts, so we want to keep going - // until we at least measure the entire first word - if (numCharsFit < data->mBreaks[0]) { - allDone = PR_FALSE; - // From now on we don't care anymore what is the _real_ estimated - // number of characters that fits. Rather, we have no where to break - // and have to measure one word fully, but the real estimate is less - // than that one word. However, since the other bits of code rely on - // what is in "data->mEstimatedNumChars", we want to override - // "data->mEstimatedNumChars" and pass in what _has_ to be measured - // so that it is transparent to the other bits that depend on it. - data->mEstimatedNumChars = data->mBreaks[0] - numCharsFit; - start += numChars; - } - - break; - } - - // Repeatedly back up until we get to where the text fits or we're - // all the way back to the first word - width += twWidth; - while ((breakIndex >= 0) && (width > data->mAvailWidth)) { - start = data->mBreaks[breakIndex]; - numChars = end - start; - numCharsFit = start; - if ((1 == numChars) && (pstr[start] == ' ')) { - width -= data->mSpaceWidth; - } - else if (pstr + start >= aSubstring) { - // The entire fragment to chop is within the current font. - pxWidth = fontXlib->GetWidth(&pstr[start], numChars); - width -= NSToCoordRound(float(pxWidth) * data->mP2T); - } - else { - // The fragment that we want to chop extends back into previous fonts. - // We need to reverse into previous fonts. Fortunately, - // data->mFonts[] and data->mOffsets[] tell us which fonts are used - // and when. - end = data->mNumCharsFit; // same as aSubstring - pstr - data->mNumCharsFit = numCharsFit; // has got shorter... - PRInt32 k = data->mFonts->Count() - 1; - for ( ; k >= 0 && start < end; --k, end -= numChars) { - fontXlib = (nsFontXlib*)data->mFonts->ElementAt(k); - const PRUnichar* ps = (const PRUnichar*)data->mOffsets->ElementAt(k); - if (ps < pstr + start) - ps = pstr + start; - - numChars = pstr + end - ps; - NS_ASSERTION(numChars > 0, "empty string"); - - pxWidth = fontXlib->GetWidth(ps, numChars); - data->mWidth -= NSToCoordRound(float(pxWidth) * data->mP2T); - - // By construction, mFonts[k] is the last font, and - // mOffsets[k+1] is the last offset. - data->mFonts->RemoveElementAt(k); - data->mOffsets->RemoveElementAt(k+1); - } - - // We are done, update the data now because we won't do it later. - // The |if (data->mNumCharsFit != numCharsFit)| won't apply below - data->mFonts->AppendElement(fontXlib); - data->mOffsets->AppendElement((void*)&pstr[numCharsFit]); - break; - } - - --breakIndex; - end = start; - } - } - - start += numChars; - } - -#ifdef DEBUG_rbs - NS_ASSERTION(allDone || start == end, "internal error"); - NS_ASSERTION(allDone || data->mNumCharsFit != numCharsFit, "internal error"); -#endif /* DEBUG_rbs */ - - if (data->mNumCharsFit != numCharsFit) { - // some text was actually retained - data->mWidth = width; - data->mNumCharsFit = numCharsFit; - data->mFonts->AppendElement(fontXlib); - data->mOffsets->AppendElement((void*)&pstr[numCharsFit]); - } - - if (allDone) { - // stop now - return PR_FALSE; - } - - return PR_TRUE; // don't stop if we still need to measure more characters -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetTextDimensions(const PRUnichar* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID) -{ - if (!mFontMetrics) - return NS_ERROR_FAILURE; - - nsFontMetricsXlib *metrics = NS_REINTERPRET_CAST(nsFontMetricsXlib *, mFontMetrics.get()); - - nscoord spaceWidth, aveCharWidth; - metrics->GetSpaceWidth(spaceWidth); - metrics->GetAveCharWidth(aveCharWidth); - - // Note: aBreaks[] is supplied to us so that the first word is located - // at aString[0 .. aBreaks[0]-1] and more generally, the k-th word is - // located at aString[aBreaks[k-1] .. aBreaks[k]-1]. Whitespace can - // be included and each of them counts as a word in its own right. - - // Upon completion of glyph resolution, characters that can be - // represented with fonts[i] are at offsets[i] .. offsets[i+1]-1 - - nsAutoVoidArray fonts, offsets; - offsets.AppendElement((void*)aString); - - BreakGetTextDimensionsData data = { mP2T, aAvailWidth, aBreaks, aNumBreaks, - spaceWidth, aveCharWidth, 0, 0, 0, -1, 0, &fonts, &offsets - }; - - metrics->ResolveForwards(aString, aLength, do_BreakGetTextDimensions, &data); - - if (aFontID) *aFontID = 0; - - aNumCharsFit = data.mNumCharsFit; - aDimensions.width = data.mWidth; - - /////////////////// - // Post-processing for the ascent and descent: - // - // The width of the last word is included in the final width, but its - // ascent and descent are kept aside for the moment. The problem is that - // line-breaking may occur _before_ the last word, and we don't want its - // ascent and descent to interfere. We can re-measure the last word and - // substract its width later. However, we need a special care for the ascent - // and descent at the break-point. The idea is to keep the ascent and descent - // of the last word separate, and let layout consider them later when it has - // determined that line-breaking doesn't occur before the last word. - // - // Therefore, there are two things to do: - // 1. Determine the ascent and descent up to where line-breaking may occur. - // 2. Determine the ascent and descent of the remainder. - // For efficiency however, it is okay to bail out early if there is only - // one font (in this case, the height of the last word has no special - // effect on the total height). - - // aLastWordDimensions.width should be set to -1 to reply that we don't - // know the width of the last word since we measure multiple words - aLastWordDimensions.Clear(); - aLastWordDimensions.width = -1; - - PRInt32 count = fonts.Count(); - if (!count) - return NS_OK; - nsFontXlib *fontXlib = (nsFontXlib *)fonts[0]; - NS_ASSERTION(fontXlib, "internal error in do_BreakGetTextDimensions"); - aDimensions.ascent = fontXlib->mMaxAscent; - aDimensions.descent = fontXlib->mMaxDescent; - - // fast path - normal case, quick return if there is only one font - if (count == 1) - return NS_OK; - - // get the last break index. - // If there is only one word, we end up with lastBreakIndex = 0. We don't - // need to worry about aLastWordDimensions in this case too. But if we didn't - // return earlier, it would mean that the unique word needs several fonts - // and we will still have to loop over the fonts to return the final height - PRInt32 lastBreakIndex = 0; - while (aBreaks[lastBreakIndex] < aNumCharsFit) - ++lastBreakIndex; - - const PRUnichar* lastWord = (lastBreakIndex > 0) - ? aString + aBreaks[lastBreakIndex-1] - : aString + aNumCharsFit; // let it point outside to play nice with the loop - - // now get the desired ascent and descent information... this is however - // a very fast loop of the order of the number of additional fonts - - PRInt32 currFont = 0; - const PRUnichar* pstr = aString; - const PRUnichar* last = aString + aNumCharsFit; - - while (pstr < last) { - fontXlib = (nsFontXlib*)fonts[currFont]; - PRUnichar* nextOffset = (PRUnichar*)offsets[++currFont]; - - // For consistent word-wrapping, we are going to handle the whitespace - // character with special care because a whitespace character can come - // from a font different from that of the previous word. If 'x', 'y', 'z', - // are Unicode points that require different fonts, we want 'xyz
' - // and 'xyz
' to have the same height because it gives a more stable - // rendering, especially when the window is resized at the edge of the word. - // If we don't do this, a 'tall' trailing whitespace, i.e., if the whitespace - // happens to come from a font with a bigger ascent and/or descent than all - // current fonts on the line, this can cause the next lines to be shifted - // down when the window is slowly resized to fit that whitespace. - if (*pstr == ' ') { - // skip pass the whitespace to ignore the height that it may contribute - ++pstr; - // get out if we reached the end - if (pstr == last) { - break; - } - // switch to the next font if we just passed the current font - if (pstr == nextOffset) { - fontXlib = (nsFontXlib*)fonts[currFont]; - nextOffset = (PRUnichar*)offsets[++currFont]; - } - } - - // see if the last word intersects with the current font - // (we are testing for 'nextOffset-1 >= lastWord' since the - // current font ends at nextOffset-1) - if (nextOffset > lastWord) { - if (aLastWordDimensions.ascent < fontXlib->mMaxAscent) { - aLastWordDimensions.ascent = fontXlib->mMaxAscent; - } - if (aLastWordDimensions.descent < fontXlib->mMaxDescent) { - aLastWordDimensions.descent = fontXlib->mMaxDescent; - } - } - - // see if we have not reached the last word yet - if (pstr < lastWord) { - if (aDimensions.ascent < fontXlib->mMaxAscent) { - aDimensions.ascent = fontXlib->mMaxAscent; - } - if (aDimensions.descent < fontXlib->mMaxDescent) { - aDimensions.descent = fontXlib->mMaxDescent; - } - } - - // advance to where the next font starts - pstr = nextOffset; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetTextDimensions(const char* aString, PRUint32 aLength, - nsTextDimensions& aDimensions) -{ - mFontMetrics->GetMaxAscent(aDimensions.ascent); - mFontMetrics->GetMaxDescent(aDimensions.descent); - return GetWidth(aString, aLength, aDimensions.width); -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetTextDimensions(const PRUnichar* aString, PRUint32 aLength, - nsTextDimensions& aDimensions, PRInt32* aFontID) -{ - aDimensions.Clear(); - if (0 < aLength) { - NS_ENSURE_TRUE(aString != nsnull, NS_ERROR_FAILURE); - - nsFontMetricsXlib *metrics = NS_REINTERPRET_CAST(nsFontMetricsXlib *, mFontMetrics.get()); - - NS_ENSURE_TRUE(metrics != nsnull, NS_ERROR_FAILURE); - - nsFontXlib* prevFont = nsnull; - int rawWidth = 0, rawAscent = 0, rawDescent = 0; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontXlib *currFont = nsnull; - nsFontXlib **font = metrics->mLoadedFonts; - nsFontXlib **end = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < end) { - if (CCMAP_HAS_CHAR((*font)->mCCMap, c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; - } - currFont = metrics->FindFont(c); -FoundFont: - // XXX avoid this test by duplicating code -- erik - if (prevFont) { - if (currFont != prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - if (rawAscent < prevFont->mMaxAscent) - rawAscent = prevFont->mMaxAscent; - if (rawDescent < prevFont->mMaxDescent) - rawDescent = prevFont->mMaxDescent; - prevFont = currFont; - start = i; - } - } - else { - prevFont = currFont; - start = i; - } - } - - if (prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - if (rawAscent < prevFont->mMaxAscent) - rawAscent = prevFont->mMaxAscent; - if (rawDescent < prevFont->mMaxDescent) - rawDescent = prevFont->mMaxDescent; - } - - aDimensions.width = NSToCoordRound(rawWidth * mP2T); - aDimensions.ascent = NSToCoordRound(rawAscent * mP2T); - aDimensions.descent = NSToCoordRound(rawDescent * mP2T); - } - if (nsnull != aFontID) - *aFontID = 0; - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawString(const char *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - const nscoord* aSpacing) -{ - nsresult res = NS_OK; - - if (aLength) { - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(aString != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mCurrentFont != nsnull, NS_ERROR_FAILURE); - - nscoord x = aX; - nscoord y = aY; - - UpdateGC(); - - nsXFont *xFont = mCurrentFont->GetXFont(); - if (nsnull != aSpacing) { - // Render the string, one character at a time... - const char* end = aString + aLength; - while (aString < end) { - char ch = *aString++; - nscoord xx = x; - nscoord yy = y; - mTranMatrix->TransformCoord(&xx, &yy); -#ifdef USE_FREETYPE - if (mCurrentFont->IsFreeTypeFont()) { - // this function is only supposed to be called for ascii data - res = mCurrentFont->DrawString(this, mSurface, xx, yy, - NS_ConvertASCIItoUTF16(aString, aLength).get(), - aLength); - } - else -#endif /* USE_FREETYPE */ - if (!mCurrentFont->GetXFontIs10646()) { - // 8 bit data with an 8 bit font - NS_ASSERTION(xFont->IsSingleByte(),"wrong string/font size"); - xFont->DrawText8(mSurface->GetDrawable(), *mGC, xx, yy, &ch, 1); - } - else { - // we have 8 bit data but a 16 bit font - NS_ASSERTION(!xFont->IsSingleByte(),"wrong string/font size"); - Widen8To16AndDraw(mSurface->GetDrawable(), xFont, *mGC, - xx, yy, &ch, 1); - } - x += *aSpacing++; - } - } - else { - mTranMatrix->TransformCoord(&x, &y); -#ifdef USE_FREETYPE - if (mCurrentFont->IsFreeTypeFont()) { - // this function is only supposed to be called for ascii data - res = mCurrentFont->DrawString(this, mSurface, x, y, - NS_ConvertASCIItoUTF16(aString, aLength).get(), - aLength); - } - else -#endif /* USE_FREETYPE */ - if (!mCurrentFont->GetXFontIs10646()) { // keep 8 bit path fast - // 8 bit data with an 8 bit font - NS_ASSERTION(xFont->IsSingleByte(),"wrong string/font size"); - xFont->DrawText8(mSurface->GetDrawable(), *mGC, x, y, aString, aLength); - } - else { - // we have 8 bit data but a 16 bit font - NS_ASSERTION(!xFont->IsSingleByte(),"wrong string/font size"); - Widen8To16AndDraw(mSurface->GetDrawable(), xFont, *mGC, - x, y, aString, aLength); - } - } - } - -#ifdef DISABLED_FOR_NOW - //this is no longer to be done by this API, but another - //will take it's place that will need this code again. MMP - if (mFontMetrics) - { - PRUint8 deco = mFontMetrics->Font().decorations; - - if (deco & NS_FONT_DECORATION_OVERLINE) - DrawLine(aX, aY, aX + aWidth, aY); - - if (deco & NS_FONT_DECORATION_UNDERLINE) - { - nscoord ascent,descent; - - mFontMetrics->GetMaxAscent(ascent); - mFontMetrics->GetMaxDescent(descent); - - DrawLine(aX, aY + ascent + (descent >> 1), - aX + aWidth, aY + ascent + (descent >> 1)); - } - - if (deco & NS_FONT_DECORATION_LINE_THROUGH) - { - nscoord height; - - mFontMetrics->GetHeight(height); - - DrawLine(aX, aY + (height >> 1), aX + aWidth, aY + (height >> 1)); - } - } -#endif /* DISABLED_FOR_NOW */ - - return res; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawString(const PRUnichar* aString, PRUint32 aLength, - nscoord aX, nscoord aY, - PRInt32 aFontID, - const nscoord* aSpacing) -{ - if (aLength && mFontMetrics) { - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(aString != nsnull, NS_ERROR_FAILURE); - - nscoord x = aX; - nscoord y = aY; - - mTranMatrix->TransformCoord(&x, &y); - - nsFontMetricsXlib *metrics = NS_REINTERPRET_CAST(nsFontMetricsXlib *, mFontMetrics.get()); - nsFontXlib *prevFont = nsnull; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontXlib* currFont = nsnull; - nsFontXlib** font = metrics->mLoadedFonts; - nsFontXlib** lastFont = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < lastFont) { - if (CCMAP_HAS_CHAR((*font)->mCCMap, c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; - } - currFont = metrics->FindFont(c); -FoundFont: - // XXX avoid this test by duplicating code -- erik - if (prevFont) { - if (currFont != prevFont) { - if (aSpacing) { - const PRUnichar* str = &aString[start]; - const PRUnichar* end = &aString[i]; - - // save off mCurrentFont and set it so that we cache the GC's font correctly - nsFontXlib *oldFont = mCurrentFont; - mCurrentFont = prevFont; - UpdateGC(); - - while (str < end) { - x = aX; - y = aY; - mTranMatrix->TransformCoord(&x, &y); - prevFont->DrawString(this, mSurface, x, y, str, 1); - aX += *aSpacing++; - str++; - } - mCurrentFont = oldFont; - } - else { - nsFontXlib *oldFont = mCurrentFont; - mCurrentFont = prevFont; - UpdateGC(); - x += prevFont->DrawString(this, mSurface, x, y, &aString[start], - i - start); - mCurrentFont = oldFont; - } - prevFont = currFont; - start = i; - } - } - else { - prevFont = currFont; - start = i; - } - } - - if (prevFont) { - nsFontXlib *oldFont = mCurrentFont; - mCurrentFont = prevFont; - UpdateGC(); - - if (aSpacing) { - const PRUnichar* str = &aString[start]; - const PRUnichar* end = &aString[i]; - while (str < end) { - x = aX; - y = aY; - mTranMatrix->TransformCoord(&x, &y); - prevFont->DrawString(this, mSurface, x, y, str, 1); - aX += *aSpacing++; - str++; - } - } - else { - prevFont->DrawString(this, mSurface, x, y, &aString[start], i - start); - } - - mCurrentFont = oldFont; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXlib::DrawString(const nsString& aString, - nscoord aX, nscoord aY, - PRInt32 aFontID, - const nscoord* aSpacing) -{ - return DrawString(aString.get(), aString.Length(), - aX, aY, aFontID, aSpacing); -} - -NS_IMETHODIMP -nsRenderingContextXlib::CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, PRUint32 aCopyFlags) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::CopyOffScreenBits()\n")); - - PRInt32 srcX = aSrcX; - PRInt32 srcY = aSrcY; - nsRect drect = aDestBounds; - nsIDrawingSurfaceXlib *destsurf; - - NS_ENSURE_TRUE(mTranMatrix != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(mSurface != nsnull, NS_ERROR_FAILURE); - NS_ENSURE_TRUE(aSrcSurf != nsnull, NS_ERROR_FAILURE); - - if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER) { - destsurf = mSurface; - } - else - { - NS_ENSURE_TRUE(mOffscreenSurface != nsnull, NS_ERROR_FAILURE); - destsurf = mOffscreenSurface; - } - - if (aCopyFlags & NS_COPYBITS_XFORM_SOURCE_VALUES) - mTranMatrix->TransformCoord(&srcX, &srcY); - - if (aCopyFlags & NS_COPYBITS_XFORM_DEST_VALUES) - mTranMatrix->TransformCoord(&drect.x, &drect.y, &drect.width, &drect.height); - - //XXX flags are unused. that would seem to mean that there is - //inefficiency somewhere... MMP - - UpdateGC(); - Drawable destdrawable; destsurf->GetDrawable(destdrawable); - Drawable srcdrawable; ((nsIDrawingSurfaceXlib *)aSrcSurf)->GetDrawable(srcdrawable); - - ::XCopyArea(mDisplay, - srcdrawable, - destdrawable, - *mGC, - srcX, srcY, - drect.width, drect.height, - drect.x, drect.y); - - return NS_OK; -} - -#ifdef MOZ_MATHML -static -void Widen8To16AndGetTextExtents(nsXFont *xFont, - const char *text, - int text_length, - int *lbearing, - int *rbearing, - int *width, - int *ascent, - int *descent) -{ - NS_ASSERTION(!xFont->IsSingleByte(),"wrong string/font size"); - XChar2b buf[WIDEN_8_TO_16_BUF_SIZE]; - XChar2b *p = buf; - int uchar_size; - - if (text_length > WIDEN_8_TO_16_BUF_SIZE) { - p = (XChar2b*)malloc(text_length*sizeof(XChar2b)); - if (!p) { // handle malloc failure - *lbearing = 0; - *rbearing = 0; - *width = 0; - *ascent = 0; - *descent = 0; - return; - } - } - - uchar_size = Widen8To16AndMove(text, text_length, p); - xFont->TextExtents16(p, uchar_size/2, - lbearing, - rbearing, - width, - ascent, - descent); - - if (text_length > WIDEN_8_TO_16_BUF_SIZE) { - free((char*)p); - } -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetBoundingMetrics(const char* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics) -{ - nsresult res = NS_OK; - aBoundingMetrics.Clear(); - if (aString && 0 < aLength) { - NS_ENSURE_TRUE(mCurrentFont != nsnull, NS_ERROR_FAILURE); - nsXFont *xFont = mCurrentFont->GetXFont(); -#ifdef USE_FREETYPE - if (mCurrentFont->IsFreeTypeFont()) { - // this function is only supposed to be called for ascii data - res = mCurrentFont->GetBoundingMetrics( - NS_ConvertASCIItoUTF16(aString, aLength).get(), - aLength, aBoundingMetrics); - } - else -#endif /* USE_FREETYPE */ - if (!mCurrentFont->GetXFontIs10646()) { - // 8 bit data with an 8 bit font - NS_ASSERTION(xFont->IsSingleByte(), "GetBoundingMetrics: wrong string/font size"); - xFont->TextExtents8(aString, aLength, - &aBoundingMetrics.leftBearing, - &aBoundingMetrics.rightBearing, - &aBoundingMetrics.width, - &aBoundingMetrics.ascent, - &aBoundingMetrics.descent); - } - else { - // we have 8 bit data but a 16 bit font - NS_ASSERTION(!xFont->IsSingleByte(), "GetBoundingMetrics: wrong string/font size"); - Widen8To16AndGetTextExtents(mCurrentFont->GetXFont(), aString, aLength, - &aBoundingMetrics.leftBearing, - &aBoundingMetrics.rightBearing, - &aBoundingMetrics.width, - &aBoundingMetrics.ascent, - &aBoundingMetrics.descent); - } - - aBoundingMetrics.leftBearing = NSToCoordRound(aBoundingMetrics.leftBearing * mP2T); - aBoundingMetrics.rightBearing = NSToCoordRound(aBoundingMetrics.rightBearing * mP2T); - aBoundingMetrics.width = NSToCoordRound(aBoundingMetrics.width * mP2T); - aBoundingMetrics.ascent = NSToCoordRound(aBoundingMetrics.ascent * mP2T); - aBoundingMetrics.descent = NSToCoordRound(aBoundingMetrics.descent * mP2T); - } - - return res; -} - -NS_IMETHODIMP -nsRenderingContextXlib::GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics, - PRInt32* aFontID) -{ - aBoundingMetrics.Clear(); - if (0 < aLength) { - NS_ENSURE_TRUE(aString != nsnull, NS_ERROR_FAILURE); - - nsFontMetricsXlib *metrics = NS_REINTERPRET_CAST(nsFontMetricsXlib *, mFontMetrics.get()); - nsFontXlib *prevFont = nsnull; - - nsBoundingMetrics rawbm; - PRBool firstTime = PR_TRUE; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontXlib *currFont = nsnull; - nsFontXlib **font = metrics->mLoadedFonts; - nsFontXlib **end = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < end) { - if (CCMAP_HAS_CHAR((*font)->mCCMap, c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; - } - currFont = metrics->FindFont(c); - FoundFont: - // XXX avoid this test by duplicating code -- erik - if (prevFont) { - if (currFont != prevFont) { - prevFont->GetBoundingMetrics((const PRUnichar*) &aString[start], - i - start, rawbm); - if (firstTime) { - firstTime = PR_FALSE; - aBoundingMetrics = rawbm; - } - else { - aBoundingMetrics += rawbm; - } - prevFont = currFont; - start = i; - } - } - else { - prevFont = currFont; - start = i; - } - } - - if (prevFont) { - prevFont->GetBoundingMetrics((const PRUnichar*) &aString[start], - i - start, rawbm); - if (firstTime) { - aBoundingMetrics = rawbm; - } - else { - aBoundingMetrics += rawbm; - } - } - // convert to app units - aBoundingMetrics.leftBearing = NSToCoordRound(aBoundingMetrics.leftBearing * mP2T); - aBoundingMetrics.rightBearing = NSToCoordRound(aBoundingMetrics.rightBearing * mP2T); - aBoundingMetrics.width = NSToCoordRound(aBoundingMetrics.width * mP2T); - aBoundingMetrics.ascent = NSToCoordRound(aBoundingMetrics.ascent * mP2T); - aBoundingMetrics.descent = NSToCoordRound(aBoundingMetrics.descent * mP2T); - } - if (nsnull != aFontID) - *aFontID = 0; - - return NS_OK; -} -#endif /* MOZ_MATHML */ - -NS_IMETHODIMP -nsRenderingContextXlib::DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawImage()\n")); - UpdateGC(); - return nsRenderingContextImpl::DrawImage(aImage, aSrcRect, aDestRect); -} diff --git a/mozilla/gfx/src/xlib/nsRenderingContextXlib.h b/mozilla/gfx/src/xlib/nsRenderingContextXlib.h deleted file mode 100644 index 4e4cdc89ce8..00000000000 --- a/mozilla/gfx/src/xlib/nsRenderingContextXlib.h +++ /dev/null @@ -1,280 +0,0 @@ -/* -*- Mode: C++; tab-width: 1; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Tim Copperfield - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRenderingContextXlib_h___ -#define nsRenderingContextXlib_h___ - -#include "nsIDeviceContext.h" -#include "nsIWidget.h" -#include "nsRenderingContextImpl.h" -#include "nsUnitConversion.h" -#include "nsFont.h" -#include "nsFontMetricsXlib.h" -#include "nsPoint.h" -#include "nsString.h" -#include "nsCRT.h" -#include "nsTransform2D.h" -#include "nsRect.h" -#include "nsVoidArray.h" -#include "nsGfxCIID.h" -#include "nsDrawingSurfaceXlib.h" -#include "nsRegionXlib.h" - -class nsFontXlib; - -class nsRenderingContextXlibContext -{ -public: - nsGCCacheXlib mGcCache; -}; - -/* Note |nsRenderingContextXp| may override some of these methods here */ -class nsRenderingContextXlib : public nsRenderingContextImpl -{ -public: - nsRenderingContextXlib(); - virtual ~nsRenderingContextXlib(); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow); - NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface); - - NS_IMETHOD Reset(void); - - NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext); - - NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, - PRUint32 aFlags); - NS_IMETHOD UnlockDrawingSurface(void); - - NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface); - NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface); - NS_IMETHOD GetHints(PRUint32& aResult); - - NS_IMETHOD PushState(void); - NS_IMETHOD PopState(void); - - NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible); - - NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine); - NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid); - NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine); - NS_IMETHOD CopyClipRegion(nsIRegion &aRegion); - NS_IMETHOD GetClipRegion(nsIRegion **aRegion); - - NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle); - NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle); - - NS_IMETHOD SetColor(nscolor aColor); - NS_IMETHOD GetColor(nscolor &aColor) const; - - NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup); - NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics); - - NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics); - - NS_IMETHOD Translate(nscoord aX, nscoord aY); - NS_IMETHOD Scale(float aSx, float aSy); - NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform); - - NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface); - NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS); - - NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); - NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints); - - NS_IMETHOD DrawRect(const nsRect& aRect); - NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - - NS_IMETHOD FillRect(const nsRect& aRect); - NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - - NS_IMETHOD InvertRect(const nsRect& aRect); - NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - - NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints); - NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints); - - NS_IMETHOD DrawEllipse(const nsRect& aRect); - NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - NS_IMETHOD FillEllipse(const nsRect& aRect); - NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - - NS_IMETHOD DrawArc(const nsRect& aRect, - float aStartAngle, float aEndAngle); - NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, - float aStartAngle, float aEndAngle); - NS_IMETHOD FillArc(const nsRect& aRect, - float aStartAngle, float aEndAngle); - NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, - float aStartAngle, float aEndAngle); - - NS_IMETHOD GetWidth(char aC, nscoord &aWidth); - NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, - PRInt32 *aFontID); - NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth, - PRInt32 *aFontID); - NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth); - NS_IMETHOD GetWidth(const char *aString, PRUint32 aLength, nscoord &aWidth); - NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, - PRInt32 *aFontID); - - NS_IMETHOD DrawString(const char *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - const nscoord* aSpacing); - NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength, - nscoord aX, nscoord aY, - PRInt32 aFontID, - const nscoord* aSpacing); - NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY, - PRInt32 aFontID, - const nscoord* aSpacing); - - NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength, - nsTextDimensions& aDimensions); - NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength, - nsTextDimensions& aDimensions, PRInt32 *aFontID); - NS_IMETHOD GetTextDimensions(const char* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID = nsnull); - NS_IMETHOD GetTextDimensions(const PRUnichar* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID = nsnull); - - NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, PRUint32 aCopyFlags); - - NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect); - -#ifdef MOZ_MATHML - /** - * Returns metrics (in app units) of an 8-bit character string - */ - NS_IMETHOD GetBoundingMetrics(const char* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics); - - /** - * Returns metrics (in app units) of a Unicode character string - */ - NS_IMETHOD GetBoundingMetrics(const PRUnichar* aString, - PRUint32 aLength, - nsBoundingMetrics& aBoundingMetrics, - PRInt32* aFontID = nsnull); - -#endif /* MOZ_MATHML */ - - void SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine); - - xGC *GetGC() { mGC->AddRef(); return mGC; } - void UpdateGC(); - - /* Use UpdateGC() to update GC-cache !! */ - void SetCurrentFont(nsFontXlib *cf) { mCurrentFont = cf; }; - nsFontXlib *GetCurrentFont() { return mCurrentFont; }; - -protected: - /* This is a common init function for all of the |Init()| functions.*/ - nsresult CommonInit(void); - - nsCOMPtr mContext; - nsCOMPtr mOffscreenSurface; - nsCOMPtr mSurface; - nsCOMPtr mFontMetrics; - nsCOMPtr mClipRegion; - float mP2T; - - // graphic state stack (GraphicsState) - nsAutoVoidArray mStateCache; - - xGC *mGC; - int mFunction; - int mLineStyle; - char *mDashList; - int mDashes; - nscolor mCurrentColor; - XlibRgbHandle *mXlibRgbHandle; - Display *mDisplay; - - nsFontXlib *mCurrentFont; - nsLineStyle mCurrentLineStyle; - - // ConditionRect is used to fix coordinate overflow problems for - // rectangles after they are transformed to screen coordinates - void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h) { - if ( y < -32766 ) { - y = -32766; - } - - if ( y + h > 32766 ) { - h = 32766 - y; - } - - if ( x < -32766 ) { - x = -32766; - } - - if ( x + w > 32766 ) { - w = 32766 - x; - } - } -}; - -/* Prototypes */ -nsresult CreateRenderingContextXlibContext(nsIDeviceContext *aDevice, nsRenderingContextXlibContext **aContext); -void DeleteRenderingContextXlibContext(nsRenderingContextXlibContext *aContext); - -#endif /* !nsRenderingContextXlib_h___ */ diff --git a/mozilla/gfx/src/xlib/xlib.pkg b/mozilla/gfx/src/xlib/xlib.pkg deleted file mode 100644 index faf3766ff50..00000000000 --- a/mozilla/gfx/src/xlib/xlib.pkg +++ /dev/null @@ -1,6 +0,0 @@ -[gecko] -#if SHARED_LIBRARY -dist/bin/components/@SHARED_LIBRARY@ -#else -!staticcomp @LIBRARY@ @MODULE_NAME@ -#endif diff --git a/mozilla/gfx/src/xlib/xregion.h b/mozilla/gfx/src/xlib/xregion.h deleted file mode 100644 index 1d6207f9060..00000000000 --- a/mozilla/gfx/src/xlib/xregion.h +++ /dev/null @@ -1,177 +0,0 @@ -/* $XConsortium: region.h,v 11.13 91/09/10 08:21:49 rws Exp $ */ -/************************************************************************ -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts, -and the Massachusetts Institute of Technology, Cambridge, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -provided that the above copyright notice appear in all copies and that -both that copyright notice and this permission notice appear in -supporting documentation, and that the names of Digital or MIT not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR -ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, -WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, -ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. - -************************************************************************/ - -#ifndef _XREGION_H -#define _XREGION_H - -typedef struct { - short x1, x2, y1, y2; -} Box, BOX, BoxRec, *BoxPtr; - -typedef struct { - short x, y, width, height; -}RECTANGLE, RectangleRec, *RectanglePtr; - -#ifdef TRUE -#undef TRUE -#endif - -#define TRUE 1 -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef MAXSHORT -#define MAXSHORT 32767 -#endif -#ifndef MINSHORT -#define MINSHORT -MAXSHORT -#endif -#ifndef MAX -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) -#endif -#ifndef MIN -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) -#endif - - -/* - * clip region - */ - -typedef struct _XRegion { - long size; - long numRects; - BOX *rects; - BOX extents; -} REGION; - -/* Xutil.h contains the declaration: - * typedef struct _XRegion *Region; - */ - -/* 1 if two BOXs overlap. - * 0 if two BOXs do not overlap. - * Remember, x2 and y2 are not in the region - */ -#define EXTENTCHECK(r1, r2) \ - ((r1)->x2 > (r2)->x1 && \ - (r1)->x1 < (r2)->x2 && \ - (r1)->y2 > (r2)->y1 && \ - (r1)->y1 < (r2)->y2) - -/* - * update region extents - */ -#define EXTENTS(r,idRect){\ - if((r)->x1 < (idRect)->extents.x1)\ - (idRect)->extents.x1 = (r)->x1;\ - if((r)->y1 < (idRect)->extents.y1)\ - (idRect)->extents.y1 = (r)->y1;\ - if((r)->x2 > (idRect)->extents.x2)\ - (idRect)->extents.x2 = (r)->x2;\ - if((r)->y2 > (idRect)->extents.y2)\ - (idRect)->extents.y2 = (r)->y2;\ - } - -/* - * Check to see if there is enough memory in the present region. - */ -#define MEMCHECK(reg, rect, firstrect){\ - if ((reg)->numRects >= ((reg)->size - 1)){\ - (firstrect) = (BOX *) Xrealloc \ - ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\ - if ((firstrect) == 0)\ - return(0);\ - (reg)->size *= 2;\ - (rect) = &(firstrect)[(reg)->numRects];\ - }\ - } - -/* this routine checks to see if the previous rectangle is the same - * or subsumes the new rectangle to add. - */ - -#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\ - (!(((Reg)->numRects > 0)&&\ - ((R-1)->y1 == (Ry1)) &&\ - ((R-1)->y2 == (Ry2)) &&\ - ((R-1)->x1 <= (Rx1)) &&\ - ((R-1)->x2 >= (Rx2)))) - -/* add a rectangle to the given Region */ -#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\ - if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\ - CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ - (r)->x1 = (rx1);\ - (r)->y1 = (ry1);\ - (r)->x2 = (rx2);\ - (r)->y2 = (ry2);\ - EXTENTS((r), (reg));\ - (reg)->numRects++;\ - (r)++;\ - }\ - } - - - -/* add a rectangle to the given Region */ -#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\ - if ((rx1 < rx2) && (ry1 < ry2) &&\ - CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\ - (r)->x1 = (rx1);\ - (r)->y1 = (ry1);\ - (r)->x2 = (rx2);\ - (r)->y2 = (ry2);\ - (reg)->numRects++;\ - (r)++;\ - }\ - } - -#define EMPTY_REGION(pReg) pReg->numRects = 0 - -#define REGION_NOT_EMPTY(pReg) pReg->numRects - -#define INBOX(r, x, y) \ - ( ( ((r).x2 > x)) && \ - ( ((r).x1 <= x)) && \ - ( ((r).y2 > y)) && \ - ( ((r).y1 <= y)) ) - -/* - * number of points to buffer before sending them off - * to scanlines() : Must be an even number - */ -#define NUMPTSTOBUFFER 200 - -/* - * used to allocate buffers for points and link - * the buffers together - */ -typedef struct _POINTBLOCK { - XPoint pts[NUMPTSTOBUFFER]; - struct _POINTBLOCK *next; -} POINTBLOCK; - -#endif diff --git a/mozilla/widget/public/nsIDragSessionXlib.h b/mozilla/widget/public/nsIDragSessionXlib.h deleted file mode 100644 index 79fee217d14..00000000000 --- a/mozilla/widget/public/nsIDragSessionXlib.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard . - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher Blizzard - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIDragSessionXLIB_h_ -#define nsIDragSessionXLIB_h_ - -#include "nsISupports.h" -#include "nsIWidget.h" - -#define NS_IDRAGSESSIONXLIB_IID \ -{ 0xa6b49c42, 0x1dd1, 0x11b2, { 0xb2, 0xdf, 0xc1, 0xd6, 0x1d, 0x67, 0x45, 0xcf } }; - -class nsIDragSessionXlib : public nsISupports { - public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDRAGSESSIONXLIB_IID) - - NS_IMETHOD IsDragging(PRBool *result) = 0; - NS_IMETHOD UpdatePosition(PRInt32 x, PRInt32 y) = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIDragSessionXlib, NS_IDRAGSESSIONXLIB_IID) - -#endif /* nsIDragSessionXLIB_h_ */ diff --git a/mozilla/widget/src/gtk/Makefile.in b/mozilla/widget/src/gtk/Makefile.in deleted file mode 100644 index c778e69f9e7..00000000000 --- a/mozilla/widget/src/gtk/Makefile.in +++ /dev/null @@ -1,160 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org Code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = widget -LIBRARY_NAME = widget_gtk -EXPORT_LIBRARY = 1 -IS_COMPONENT = 1 -MODULE_NAME = nsWidgetGTKModule -GRE_MODULE = 1 -LIBXUL_LIBRARY = 1 - -PACKAGE_FILE = widget_gtk.pkg - -NATIVE_THEME_SUPPORT = 1 - -REQUIRES = xpcom \ - string \ - appshell \ - gfx \ - pref \ - dom \ - uconv \ - necko \ - view \ - util \ - unicharutil \ - content \ - layout \ - locale \ - $(NULL) - -ifdef NS_TRACE_MALLOC -REQUIRES += tracemalloc -endif - -CSRCS = \ - keysym2ucs.c - -CPPSRCS = \ - nsAppShell.cpp \ - nsBidiKeyboard.cpp \ - nsClipboard.cpp \ - nsDragService.cpp \ - nsGtkEventHandler.cpp \ - nsGtkUtils.cpp \ - nsKeyboardUtils.cpp \ - nsLookAndFeel.cpp \ - nsSound.cpp \ - nsToolkit.cpp \ - nsWidget.cpp \ - nsWidgetFactory.cpp \ - nsWindow.cpp \ - nsGtkIMEHelper.cpp \ - nsScreenGtk.cpp \ - nsScreenManagerGtk.cpp \ - $(NULL) - -SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a - -EXTRA_DSO_LIBS = gkgfx - -ifdef NS_TRACE_MALLOC -EXTRA_DSO_LIBS += tracemalloc -endif - -EXTRA_DSO_LDOPTS = \ - $(LIBS_DIR) \ - $(EXTRA_DSO_LIBS) \ - $(MOZ_COMPONENT_LIBS) \ - $(MOZ_JS_LIBS) \ - $(NULL) - -EXTRA_DSO_LDOPTS += -L$(DIST)/lib -lgtksuperwin $(MOZ_GTK_LDFLAGS) - -ifdef NATIVE_THEME_SUPPORT -CSRCS += gtkdrawing.c -CPPSRCS += nsNativeThemeGTK.cpp -DEFINES += -DNATIVE_THEME_SUPPORT -endif - -include $(topsrcdir)/config/rules.mk - -CXXFLAGS += $(MOZ_GTK_CFLAGS) -CFLAGS += $(MOZ_GTK_CFLAGS) - -DEFINES += -D_IMPL_NS_WIDGET -DUSE_XIM - -ifeq ($(OS_ARCH), SunOS) -ifndef GNU_CC -# When using Sun's WorkShop compiler, including -# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h -# causes most of these compiles to fail with: -# line 29: Error: Multiple declaration for std::tm. -# So, this gets around the problem. -DEFINES += -D_TIME_H=1 -endif -endif - -ifeq ($(OS_ARCH), OpenVMS) -DEFINES += -DGENERIC_MOTIF_REDEFINES -endif - -LOCAL_INCLUDES = \ - -I$(srcdir)/../xpwidgets \ - -I$(srcdir) \ - -I$(topsrcdir)/gfx/src/gtk \ - $(NULL) - -ICON_FILES = \ - $(srcdir)/mozicon50.xpm \ - $(srcdir)/mozicon16.xpm \ - $(NULL) - -libs:: - $(INSTALL) $(ICON_FILES) $(DIST)/bin/icons - -install:: - $(SYSINSTALL) $(IFLAGS1) $(ICON_FILES) $(DESTDIR)$(mozappdir)/icons - diff --git a/mozilla/widget/src/gtk/gtkdrawing.c b/mozilla/widget/src/gtk/gtkdrawing.c deleted file mode 100644 index 91a30ac1b25..00000000000 --- a/mozilla/widget/src/gtk/gtkdrawing.c +++ /dev/null @@ -1,1252 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * This file contains painting functions for each of the gtk widgets. - * Adapted from the gtk+ 1.2.10 source. - */ - -#include -#include -#include -#include "gtkdrawing.h" - -static GtkWidget* gButtonWidget; -static GtkWidget* gProtoWindow; -static GtkWidget* gCheckboxWidget; -static GtkWidget* gScrollbarWidget; -static GtkWidget* gSpinWidget; -static GtkWidget* gHScaleWidget; -static GtkWidget* gVScaleWidget; -static GtkWidget* gEntryWidget; -static GtkWidget* gArrowWidget; -static GtkWidget* gDropdownButtonWidget; -static GtkWidget* gHandleBoxWidget; -static GtkWidget* gFrameWidget; -static GtkWidget* gProgressWidget; -static GtkWidget* gTabWidget; -static GtkTooltips* gTooltipWidget; - -static style_prop_t style_prop_func; - -typedef struct GtkThemeEnginePrivate { - GtkThemeEngine engine; - void* library; - char* name; -} GtkThemeEnginePrivate; - -static const char* sDisabledEngines[] = { - "xeno", /* xenophilia */ - NULL -}; - -gint -moz_gtk_enable_style_props(style_prop_t styleGetProp) -{ - style_prop_func = styleGetProp; - return MOZ_GTK_SUCCESS; -} - -static gint -setup_widget_prototype(GtkWidget* widget) -{ - static GtkWidget* protoLayout; - - if (!gProtoWindow) { - gProtoWindow = gtk_window_new(GTK_WINDOW_POPUP); - protoLayout = gtk_fixed_new(); - gtk_container_add(GTK_CONTAINER(gProtoWindow), protoLayout); - } - - gtk_container_add(GTK_CONTAINER(protoLayout), widget); - gtk_widget_set_rc_style(widget); - gtk_widget_realize(widget); - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_button_widget() -{ - if (!gButtonWidget) { - gButtonWidget = gtk_button_new_with_label("M"); - setup_widget_prototype(gButtonWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_checkbox_widget() -{ - if (!gCheckboxWidget) { - gCheckboxWidget = gtk_check_button_new_with_label("M"); - setup_widget_prototype(gCheckboxWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_scrollbar_widget() -{ - if (!gScrollbarWidget) { - gScrollbarWidget = gtk_vscrollbar_new(NULL); - setup_widget_prototype(gScrollbarWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_spin_widget() -{ - if (!gSpinWidget) { - gSpinWidget = gtk_spin_button_new(NULL, 1, 0); - setup_widget_prototype(gSpinWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_scale_widget() -{ - if (!gHScaleWidget) { - gHScaleWidget = gtk_hscale_new(NULL); - setup_widget_prototype(gHScaleWidget); - } - if (!gVScaleWidget) { - gVScaleWidget = gtk_vscale_new(NULL); - setup_widget_prototype(gVScaleWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_entry_widget() -{ - if (!gEntryWidget) { - gEntryWidget = gtk_entry_new(); - setup_widget_prototype(gEntryWidget); -#ifdef _AIX - /* On AIX, calling gdk_widget_realize on a gtk entry with an - * input context style of type GDK_IM_STATUS_NOTHING causes a - * root status window to come up. It remains up until the widget - * is destroyed (which is never in this case). To work around - * this problem, we destroy its XIC here to prevent the root - * status window from remaining on the screen. */ - if (GTK_EDITABLE(gEntryWidget)->ic && - GTK_EDITABLE(gEntryWidget)->ic_attr->style & GDK_IM_STATUS_NOTHING) { - gdk_ic_destroy(GTK_EDITABLE(gEntryWidget)->ic); - GTK_EDITABLE(gEntryWidget)->ic = NULL; - } -#endif - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_arrow_widget() -{ - if (!gArrowWidget) { - gDropdownButtonWidget = gtk_button_new(); - setup_widget_prototype(gDropdownButtonWidget); - gArrowWidget = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_container_add(GTK_CONTAINER(gDropdownButtonWidget), gArrowWidget); - gtk_widget_set_rc_style(gArrowWidget); - gtk_widget_realize(gArrowWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_handlebox_widget() -{ - if (!gHandleBoxWidget) { - gHandleBoxWidget = gtk_handle_box_new(); - setup_widget_prototype(gHandleBoxWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_tooltip_widget() -{ - if (!gTooltipWidget) { - gTooltipWidget = gtk_tooltips_new(); - gtk_tooltips_force_window(gTooltipWidget); - gtk_widget_set_rc_style(gTooltipWidget->tip_window); - gtk_widget_realize(gTooltipWidget->tip_window); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_tab_widget() -{ - if (!gTabWidget) { - gTabWidget = gtk_notebook_new(); - setup_widget_prototype(gTabWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_progress_widget() -{ - if (!gProgressWidget) { - gProgressWidget = gtk_progress_bar_new(); - setup_widget_prototype(gProgressWidget); - } - return MOZ_GTK_SUCCESS; -} - -static gint -ensure_frame_widget() -{ - if (!gFrameWidget) { - gFrameWidget = gtk_frame_new(NULL); - setup_widget_prototype(gFrameWidget); - } - return MOZ_GTK_SUCCESS; -} - -static GtkStateType -ConvertGtkState(GtkWidgetState* state) -{ - if (state->disabled) - return GTK_STATE_INSENSITIVE; - else if (state->inHover) - return (state->active ? GTK_STATE_ACTIVE : GTK_STATE_PRELIGHT); - else - return GTK_STATE_NORMAL; -} - -static gint -TSOffsetStyleGCArray(GdkGC** gcs, gint xorigin, gint yorigin) -{ - int i; - /* there are 5 gc's in each array, for each of the widget states */ - for (i = 0; i < 5; ++i) - gdk_gc_set_ts_origin(gcs[i], xorigin, yorigin); - return MOZ_GTK_SUCCESS; -} - -static gint -TSOffsetStyleGCs(GtkStyle* style, gint xorigin, gint yorigin) -{ - TSOffsetStyleGCArray(style->fg_gc, xorigin, yorigin); - TSOffsetStyleGCArray(style->bg_gc, xorigin, yorigin); - TSOffsetStyleGCArray(style->light_gc, xorigin, yorigin); - TSOffsetStyleGCArray(style->dark_gc, xorigin, yorigin); - TSOffsetStyleGCArray(style->mid_gc, xorigin, yorigin); - TSOffsetStyleGCArray(style->text_gc, xorigin, yorigin); - TSOffsetStyleGCArray(style->base_gc, xorigin, yorigin); - gdk_gc_set_ts_origin(style->black_gc, xorigin, yorigin); - gdk_gc_set_ts_origin(style->white_gc, xorigin, yorigin); - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_button_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state, - GtkReliefStyle relief, GtkWidget* widget) -{ - GtkShadowType shadow_type; - GtkStyle* style = widget->style; - gint default_spacing = 7; /* xxx fix me */ - GtkStateType button_state = ConvertGtkState(state); - gint x = rect->x, y=rect->y, width=rect->width, height=rect->height; - - if (((GdkWindowPrivate*)drawable)->mapped) { - gdk_window_set_back_pixmap(drawable, NULL, TRUE); - gdk_window_clear_area(drawable, cliprect->x, cliprect->y, cliprect->width, - cliprect->height); - } - - gtk_widget_set_state(widget, button_state); - if (state->isDefault) { - TSOffsetStyleGCs(style, x, y); - gtk_paint_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, cliprect, - widget, "buttondefault", x, y, width, height); - } - - if (state->canDefault) { - x += style->klass->xthickness; - y += style->klass->ythickness; - width -= 2 * x + default_spacing; - height -= 2 * y + default_spacing; - x += (1 + default_spacing) / 2; - y += (1 + default_spacing) / 2; - } - - if (state->focused) { - x += 1; - y += 1; - width -= 2; - height -= 2; - } - - shadow_type = (state->active && state->inHover && !state->disabled) ? GTK_SHADOW_IN : GTK_SHADOW_OUT; - - if (relief != GTK_RELIEF_NONE || (button_state != GTK_STATE_NORMAL && - button_state != GTK_STATE_INSENSITIVE)) { - TSOffsetStyleGCs(style, x, y); - gtk_paint_box(style, drawable, button_state, shadow_type, cliprect, - widget, "button", x, y, width, height); - } - - if (state->focused) { - x -= 1; - y -= 1; - width += 2; - height += 2; - - TSOffsetStyleGCs(style, x, y); - gtk_paint_focus(style, drawable, cliprect, widget, "button", x, y, - width - 1, height - 1); - } - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_init() -{ - /* Check for a blacklisted theme engine */ - GtkThemeEngine* gtkThemeEng; - ensure_button_widget(); - gtkThemeEng = gButtonWidget->style->engine; - if (gtkThemeEng) { - const char* curEngine = ((GtkThemeEnginePrivate*) gtkThemeEng)->name; - const char* eng; - int i = 0; - while ((eng = sDisabledEngines[i++])) { - if (!strcmp(eng, curEngine)) { - g_warning("gtkdrawing found unsafe theme engine: %s\n", eng); - return MOZ_GTK_UNSAFE_THEME; - } - } - } - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_checkbox_get_metrics(gint* indicator_size, gint* indicator_spacing) -{ - GtkCheckButtonClass* klass; - - ensure_checkbox_widget(); - klass = GTK_CHECK_BUTTON_CLASS(GTK_OBJECT(gCheckboxWidget)->klass); - - if (style_prop_func) { - /* - * This API is supported only in GTK+ >= 1.2.9, and gives per-theme values. - */ - - GtkStyle* style = gCheckboxWidget->style; - - *indicator_size = style_prop_func(style, - "GtkCheckButton::indicator_size", - klass->indicator_size); - *indicator_spacing = style_prop_func(style, - "GtkCheckButton::indicator_spacing", - klass->indicator_spacing); - } else { - *indicator_size = klass->indicator_size; - *indicator_spacing = klass->indicator_spacing; - } - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_radio_get_metrics(gint* indicator_size, gint* indicator_spacing) -{ - return moz_gtk_checkbox_get_metrics(indicator_size, indicator_spacing); -} - -gint -moz_gtk_checkbox_get_focus(gboolean* interior_focus, - gint* focus_width, gint* focus_pad) -{ - /* These values are hardcoded in gtk1. */ - *interior_focus = FALSE; - *focus_width = 1; - *focus_pad = 0; - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_radio_get_focus(gboolean* interior_focus, - gint* focus_width, gint* focus_pad) -{ - return moz_gtk_checkbox_get_focus(interior_focus, focus_width, focus_pad); -} - -static gint -moz_gtk_toggle_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state, - gboolean selected, gboolean isradio) -{ - GtkStateType state_type; - GtkShadowType shadow_type; - gint indicator_size, indicator_spacing; - gint x, y, width, height; - GtkStyle* style; - - moz_gtk_checkbox_get_metrics(&indicator_size, &indicator_spacing); - style = gCheckboxWidget->style; - - /* offset by indicator_spacing, and centered vertically within the rect */ - x = rect->x + indicator_spacing; - y = rect->y + (rect->height - indicator_size) / 2; - width = indicator_size; - height = indicator_size; - - if (selected) { - state_type = GTK_STATE_ACTIVE; - shadow_type = GTK_SHADOW_IN; - } - else { - shadow_type = GTK_SHADOW_OUT; - state_type = ConvertGtkState(state); - } - - TSOffsetStyleGCs(style, x, y); - - /* Some themes check the widget state themselves. */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gCheckboxWidget), selected); - - if (isradio) - gtk_paint_option(style, drawable, state_type, shadow_type, cliprect, - gCheckboxWidget, "radiobutton", x, y, width, height); - else - gtk_paint_check(style, drawable, state_type, shadow_type, cliprect, - gCheckboxWidget, "checkbutton", x, y, width, height); - - return MOZ_GTK_SUCCESS; -} - -static gint -calculate_arrow_dimensions(GdkRectangle* rect, GdkRectangle* arrow_rect) -{ - GtkMisc* misc = GTK_MISC(gArrowWidget); - - gint extent = MIN(rect->width - misc->xpad * 2, rect->height - misc->ypad * 2); - arrow_rect->x = ((rect->x + misc->xpad) * (1.0 - misc->xalign) + - (rect->x + rect->width - extent - misc->xpad) * misc->xalign); - arrow_rect->y = ((rect->y + misc->ypad) * (1.0 - misc->yalign) + - (rect->y + rect->height - extent - misc->ypad) * misc->yalign); - - arrow_rect->width = arrow_rect->height = extent; - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_scrollbar_button_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state, - GtkArrowType type) -{ - GtkStateType state_type = ConvertGtkState(state); - GtkShadowType shadow_type = (state->active && !state->disabled) ? GTK_SHADOW_IN : GTK_SHADOW_OUT; - GdkRectangle arrow_rect; - GtkStyle* style; - - ensure_scrollbar_widget(); - style = gScrollbarWidget->style; - - ensure_arrow_widget(); - calculate_arrow_dimensions(rect, &arrow_rect); - TSOffsetStyleGCs(style, arrow_rect.x, arrow_rect.y); - gtk_paint_arrow(style, drawable, state_type, shadow_type, cliprect, - gScrollbarWidget, (type < 2) ? "vscrollbar" : "hscrollbar", - type, TRUE, arrow_rect.x, arrow_rect.y, arrow_rect.width, - arrow_rect.height); - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_scrollbar_trough_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state) -{ - GtkStyle* style; - - ensure_scrollbar_widget(); - style = gScrollbarWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_style_apply_default_background(style, drawable, TRUE, GTK_STATE_ACTIVE, - cliprect, rect->x, rect->y, - rect->width, rect->height); - - gtk_paint_box(style, drawable, GTK_STATE_ACTIVE, GTK_SHADOW_IN, cliprect, - gScrollbarWidget, "trough", rect->x, rect->y, rect->width, - rect->height); - - if (state->focused) - gtk_paint_focus(style, drawable, cliprect, gScrollbarWidget, "trough", - rect->x, rect->y, rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_scrollbar_thumb_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state) -{ - GtkStateType state_type = (state->inHover || state->active) ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL; - GtkStyle* style; - - ensure_scrollbar_widget(); - style = gScrollbarWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_box(style, drawable, state_type, GTK_SHADOW_OUT, cliprect, - gScrollbarWidget, "slider", rect->x, rect->y, rect->width, - rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_spin_paint(GdkDrawable* drawable, GdkRectangle* rect, gboolean isDown, - GtkWidgetState* state) -{ - GdkRectangle arrow_rect; - GtkStateType state_type = ConvertGtkState(state); - GtkShadowType shadow_type = state_type == GTK_STATE_ACTIVE ? GTK_SHADOW_IN : GTK_SHADOW_OUT; - GtkStyle* style; - - ensure_spin_widget(); - style = gSpinWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_box(style, drawable, state_type, shadow_type, NULL, gSpinWidget, - isDown ? "spinbutton_down" : "spinbutton_up", - rect->x, rect->y, rect->width, rect->height); - - /* hard code these values */ - arrow_rect.width = 6; - arrow_rect.height = 6; - arrow_rect.x = rect->x + (rect->width - arrow_rect.width) / 2; - arrow_rect.y = rect->y + (rect->height - arrow_rect.height) / 2; - arrow_rect.y += isDown ? -1 : 1; - - gtk_paint_arrow(style, drawable, state_type, shadow_type, NULL, - gSpinWidget, "spinbutton", - isDown ? GTK_ARROW_DOWN : GTK_ARROW_UP, TRUE, - arrow_rect.x, arrow_rect.y, - arrow_rect.width, arrow_rect.height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_scale_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state, - GtkOrientation flags) -{ - gint x = 0, y = 0; - GtkStateType state_type = ConvertGtkState(state); - GtkStyle* style; - GtkWidget* widget; - - ensure_scale_widget(); - widget = ((flags == GTK_ORIENTATION_HORIZONTAL) ? gHScaleWidget : gVScaleWidget); - style = widget->style; - - if (flags == GTK_ORIENTATION_HORIZONTAL) { - x = style->klass->xthickness; - y++; - } - else { - x++; - y = style->klass->ythickness; - } - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_style_apply_default_background(style, drawable, TRUE, GTK_STATE_NORMAL, - cliprect, rect->x, rect->y, - rect->width, rect->height); - - gtk_paint_box(style, drawable, GTK_STATE_ACTIVE, GTK_SHADOW_IN, cliprect, - widget, "trough", rect->x + x, rect->y + y, - rect->width - 2*x, rect->height - 2*y); - - if (state->focused) - gtk_paint_focus(style, drawable, cliprect, widget, "trough", - rect->x, rect->y, rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_scale_thumb_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state, - GtkOrientation flags) -{ - GtkStateType state_type = ConvertGtkState(state); - GtkStyle* style; - GtkWidget* widget; - gint thumb_width, thumb_height, x, y; - - ensure_scale_widget(); - widget = ((flags == GTK_ORIENTATION_HORIZONTAL) ? gHScaleWidget : gVScaleWidget); - style = widget->style; - - /* determine the thumb size, and position the thumb in the center in the opposite axis */ - if (flags == GTK_ORIENTATION_HORIZONTAL) { - moz_gtk_get_scalethumb_metrics(GTK_ORIENTATION_HORIZONTAL, &thumb_width, &thumb_height); - x = rect->x; - y = rect->y + (rect->height - thumb_height) / 2; - } - else { - moz_gtk_get_scalethumb_metrics(GTK_ORIENTATION_VERTICAL, &thumb_height, &thumb_width); - x = rect->x + (rect->width - thumb_width) / 2; - y = rect->y; - } - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_slider(style, drawable, state_type, GTK_SHADOW_OUT, cliprect, - widget, (flags == GTK_ORIENTATION_HORIZONTAL) ? "hscale" : "vscale", - rect->x, rect->y, thumb_width, thumb_height, flags); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_gripper_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state) -{ - GtkStateType state_type = ConvertGtkState(state); - GtkShadowType shadow_type; - GtkStyle* style; - - ensure_handlebox_widget(); - style = gHandleBoxWidget->style; - shadow_type = GTK_HANDLE_BOX(gHandleBoxWidget)->shadow_type; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_box(style, drawable, state_type, shadow_type, cliprect, - gHandleBoxWidget, "handlebox_bin", rect->x, rect->y, - rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_entry_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state) -{ - gint x = rect->x, y = rect->y, width = rect->width, height = rect->height; - GtkStyle* style; - - ensure_entry_widget(); - style = gEntryWidget->style; - - /* - * gtk+ is able to draw over top of the entry when it gains focus, - * so the non-focused text border is implicitly already drawn when - * the entry is drawn in a focused state. - * - * Gecko doesn't quite work this way, so always draw the non-focused - * shadow, then draw the shadow again, inset, if we're focused. - */ - - TSOffsetStyleGCs(style, x, y); - gtk_paint_shadow(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, cliprect, - gEntryWidget, "entry", x, y, width, height); - - - if (state->focused) { - x += 1; - y += 1; - width -= 2; - height -= 2; - TSOffsetStyleGCs(style, x, y); - gtk_paint_shadow(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, - cliprect, gEntryWidget, "entry", x, y, width, height); - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_focus(style, drawable, cliprect, gEntryWidget, "entry", - rect->x, rect->y, rect->width - 1, rect->height - 1); - } - - x = style->klass->xthickness; - y = style->klass->ythickness; - - TSOffsetStyleGCs(style, rect->x + x, rect->y + y); - gtk_paint_flat_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_NONE, - cliprect, gEntryWidget, "entry_bg", rect->x + x, - rect->y + y, rect->width - 2*x, rect->height - 2*y); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_dropdown_arrow_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state) -{ - GdkRectangle arrow_rect, real_arrow_rect; - GtkStateType state_type = ConvertGtkState(state); - GtkShadowType shadow_type = (state->active && !state->disabled) ? GTK_SHADOW_IN : GTK_SHADOW_OUT; - GtkStyle* style; - - ensure_arrow_widget(); - moz_gtk_button_paint(drawable, rect, cliprect, state, GTK_RELIEF_NORMAL, - gDropdownButtonWidget); - - /* This mirrors gtkbutton's child positioning */ - style = gDropdownButtonWidget->style; - arrow_rect.x = rect->x + 1 + gDropdownButtonWidget->style->klass->xthickness; - arrow_rect.y = rect->y + 1 + gDropdownButtonWidget->style->klass->ythickness; - arrow_rect.width = MAX(1, rect->width - (arrow_rect.x - rect->x) * 2); - arrow_rect.height = MAX(1, rect->height - (arrow_rect.y - rect->y) * 2); - - calculate_arrow_dimensions(&arrow_rect, &real_arrow_rect); - style = gArrowWidget->style; - TSOffsetStyleGCs(style, real_arrow_rect.x, real_arrow_rect.y); - gtk_paint_arrow(style, drawable, state_type, shadow_type, cliprect, - gScrollbarWidget, "arrow", GTK_ARROW_DOWN, TRUE, - real_arrow_rect.x, real_arrow_rect.y, - real_arrow_rect.width, real_arrow_rect.height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_container_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, GtkWidgetState* state, - gboolean isradio) -{ - GtkStateType state_type = ConvertGtkState(state); - GtkStyle* style; - - ensure_checkbox_widget(); - style = gCheckboxWidget->style; - - if (state_type != GTK_STATE_NORMAL && state_type != GTK_STATE_PRELIGHT) - state_type = GTK_STATE_NORMAL; - - TSOffsetStyleGCs(style, rect->x, rect->y); - - if (state_type != GTK_STATE_NORMAL) /* this is for drawing a prelight box */ - gtk_paint_flat_box(style, drawable, state_type, GTK_SHADOW_ETCHED_OUT, - cliprect, gCheckboxWidget, - isradio ? "radiobutton" : "checkbutton", - rect->x, rect->y, rect->width, rect->height); - - if (state->focused) - gtk_paint_focus(style, drawable, cliprect, gCheckboxWidget, "checkbutton", - rect->x, rect->y, rect->width - 1, rect->height - 1); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_toolbar_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect) -{ - GtkStyle* style; - - ensure_handlebox_widget(); - style = gHandleBoxWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - if (style->bg_pixmap[GTK_STATE_NORMAL]) - gtk_style_apply_default_background(style, drawable, TRUE, GTK_STATE_NORMAL, - cliprect, rect->x, rect->y, - rect->width, rect->height); - else - gtk_paint_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT, cliprect, - gHandleBoxWidget, "dockitem_bin", - rect->x, rect->y, rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_tooltip_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect) -{ - GtkStyle* style; - - ensure_tooltip_widget(); - style = gTooltipWidget->tip_window->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_flat_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - cliprect, gTooltipWidget->tip_window, "tooltip", rect->x, - rect->y, rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_frame_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect) -{ - GtkStyle* style = gProtoWindow->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_flat_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_NONE, NULL, - gProtoWindow, "base", rect->x, rect->y, rect->width, - rect->height); - - ensure_frame_widget(); - style = gFrameWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_shadow(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, cliprect, - gFrameWidget, "frame", rect->x, rect->y, rect->width, - rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_progressbar_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect) -{ - GtkStyle* style; - - ensure_progress_widget(); - style = gProgressWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_IN, - cliprect, gProgressWidget, "trough", rect->x, rect->y, - rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_progress_chunk_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect) -{ - GtkStyle* style; - - ensure_progress_widget(); - style = gProgressWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_box(style, drawable, GTK_STATE_PRELIGHT, GTK_SHADOW_OUT, - cliprect, gProgressWidget, "bar", rect->x, rect->y, - rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_tab_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect, gint flags) -{ - /* - * In order to get the correct shadows and highlights, GTK paints tabs - * right-to-left (end-to-beginning, to be generic), leaving out the - * active tab, and then paints the current tab once everything else is - * painted. In addition, GTK uses a 2-pixel overlap between adjacent tabs - * (this value is hard-coded in gtknotebook.c). For purposes of mapping to - * gecko's frame positions, we put this overlap on the far edge of the frame - * (i.e., for a horizontal/top tab strip, we shift the left side of each tab - * 2px to the left, into the neighboring tab's frame rect. The right 2px - * of a tab's frame will be referred to as the "overlap area". - * - * Since we can't guarantee painting order with gecko, we need to manage - * the overlap area manually. There are three types of tab boundaries we need - * to handle: - * - * * two non-active tabs: In this case, we just have both tabs paint - * normally. - * - * * non-active to active tab: Here, we need the tab on the left to paint - * itself normally, then paint the edge of the - * active tab in its overlap area. - * - * * active to non-active tab: In this case, we just have both tabs paint - * normally. - * - * We need to make an exception for the first tab - since there is no tab to - * the left to paint the overlap area, we do _not_ shift the tab left by 2px. - */ - - GtkStyle* style; - ensure_tab_widget(); - - if (!(flags & MOZ_GTK_TAB_FIRST)) { - rect->x -= 2; - rect->width += 2; - } - - style = gTabWidget->style; - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_extension(style, drawable, - ((flags & MOZ_GTK_TAB_SELECTED) ? GTK_STATE_NORMAL : GTK_STATE_ACTIVE), - GTK_SHADOW_OUT, cliprect, gTabWidget, "tab", rect->x, - rect->y, rect->width, rect->height, GTK_POS_BOTTOM); - - if (flags & MOZ_GTK_TAB_BEFORE_SELECTED) { - gboolean before_selected = ((flags & MOZ_GTK_TAB_BEFORE_SELECTED) != 0); - cliprect->y -= 2; - cliprect->height += 2; - TSOffsetStyleGCs(style, rect->x + rect->width - 2, rect->y - (2 * before_selected)); - gtk_paint_extension(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - cliprect, gTabWidget, "tab", rect->x + rect->width - 2, - rect->y - (2 * before_selected), rect->width, - rect->height + (2 * before_selected), GTK_POS_BOTTOM); - } - - return MOZ_GTK_SUCCESS; -} - -static gint -moz_gtk_tabpanels_paint(GdkDrawable* drawable, GdkRectangle* rect, - GdkRectangle* cliprect) -{ - GtkStyle* style; - - ensure_tab_widget(); - style = gTabWidget->style; - - TSOffsetStyleGCs(style, rect->x, rect->y); - gtk_paint_box(style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT, - cliprect, gTabWidget, "notebook", rect->x, rect->y, - rect->width, rect->height); - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* xthickness, - gint* ythickness) -{ - GtkWidget* w; - switch (widget) { - case MOZ_GTK_BUTTON: - ensure_button_widget(); - w = gButtonWidget; - break; - case MOZ_GTK_TOOLBAR: - ensure_handlebox_widget(); - w = gHandleBoxWidget; - break; - case MOZ_GTK_ENTRY: - ensure_entry_widget(); - w = gEntryWidget; - break; - case MOZ_GTK_DROPDOWN_ARROW: - ensure_arrow_widget(); - w = gDropdownButtonWidget; - break; - case MOZ_GTK_TABPANELS: - ensure_tab_widget(); - w = gTabWidget; - break; - case MOZ_GTK_PROGRESSBAR: - ensure_progress_widget(); - w = gProgressWidget; - break; - case MOZ_GTK_SPINBUTTON_UP: - case MOZ_GTK_SPINBUTTON_DOWN: - ensure_spin_widget(); - w = gSpinWidget; - break; - case MOZ_GTK_SCALE_HORIZONTAL: - ensure_scale_widget(); - w = gHScaleWidget; - break; - case MOZ_GTK_SCALE_VERTICAL: - ensure_scale_widget(); - w = gVScaleWidget; - break; - case MOZ_GTK_FRAME: - ensure_frame_widget(); - w = gFrameWidget; - break; - case MOZ_GTK_CHECKBUTTON_CONTAINER: - case MOZ_GTK_RADIOBUTTON_CONTAINER: - ensure_checkbox_widget(); - *xthickness = *ythickness = - GTK_CONTAINER(gCheckboxWidget)->border_width + 1; - - return MOZ_GTK_SUCCESS; - - case MOZ_GTK_CHECKBUTTON_LABEL: - case MOZ_GTK_RADIOBUTTON_LABEL: - *xthickness = *ythickness = 0; - return MOZ_GTK_SUCCESS; - - case MOZ_GTK_CHECKBUTTON: - case MOZ_GTK_RADIOBUTTON: - case MOZ_GTK_SCROLLBAR_BUTTON: - case MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL: - case MOZ_GTK_SCROLLBAR_TRACK_VERTICAL: - case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL: - case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL: - case MOZ_GTK_SCALE_THUMB_HORIZONTAL: - case MOZ_GTK_SCALE_THUMB_VERTICAL: - case MOZ_GTK_GRIPPER: - case MOZ_GTK_TOOLTIP: - case MOZ_GTK_PROGRESS_CHUNK: - case MOZ_GTK_TAB: - /* These widgets have no borders, since they are not containers. */ - *xthickness = 0; - *ythickness = 0; - return MOZ_GTK_SUCCESS; - default: - g_warning("Unsupported widget type: %d", widget); - return MOZ_GTK_UNKNOWN_WIDGET; - } - - *xthickness = w->style->klass->xthickness; - *ythickness = w->style->klass->ythickness; - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_get_dropdown_arrow_size(gint* width, gint* height) -{ - ensure_arrow_widget(); - - /* - * First get the border of the dropdown arrow, then add in the requested - * size of the arrow. Note that the minimum arrow size is fixed at - * 11 pixels. - */ - - *width = 2 * (1 + gDropdownButtonWidget->style->klass->xthickness); - *width += 11 + GTK_MISC(gArrowWidget)->xpad * 2; - - *height = 2 * (1 + gDropdownButtonWidget->style->klass->ythickness); - *height += 11 + GTK_MISC(gArrowWidget)->ypad * 2; - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_get_scalethumb_metrics(GtkOrientation orient, gint* thumb_length, gint* thumb_height) -{ - GtkRangeClass* rangeklass; - GtkScaleClass* scaleklass; - GtkStyle* style; - GtkWidget* widget; - - ensure_scale_widget(); - widget = ((orient == GTK_ORIENTATION_HORIZONTAL) ? gHScaleWidget : gVScaleWidget); - - rangeklass = GTK_RANGE_CLASS(GTK_OBJECT(widget)->klass); - scaleklass = GTK_SCALE_CLASS(GTK_OBJECT(widget)->klass); - style = widget->style; - - if (style_prop_func) { - /* - * This API is supported only in GTK+ >= 1.2.9, and gives per-theme values. - */ - - *thumb_length = style_prop_func(style, "GtkRange::slider_length", - scaleklass->slider_length); - *thumb_height = style_prop_func(style, "GtkRange::slider_width", - rangeklass->slider_width); - } else { - /* - * This is the older method, which gives per-engine values. - */ - - *thumb_length = scaleklass->slider_length; - *thumb_height = rangeklass->slider_width; - } - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_get_scrollbar_metrics(MozGtkScrollbarMetrics *metrics) -{ - GtkRangeClass* klass; - GtkStyle* style; - - ensure_scrollbar_widget(); - klass = GTK_RANGE_CLASS(GTK_OBJECT(gScrollbarWidget)->klass); - style = gScrollbarWidget->style; - - if (style_prop_func) { - /* - * This API is supported only in GTK+ >= 1.2.9, and gives per-theme values. - */ - - metrics->slider_width = style_prop_func(style, "GtkRange::slider_width", - klass->slider_width); - - metrics->trough_border = style_prop_func(style, "GtkRange::trough_border", - style->klass->xthickness); - - metrics->stepper_size = style_prop_func(style, "GtkRange::stepper_size", - klass->stepper_size); - - metrics->stepper_spacing = style_prop_func(style, - "GtkRange::stepper_spacing", - klass->stepper_slider_spacing); - } else { - /* - * This is the older method, which gives per-engine values. - */ - - metrics->slider_width = klass->slider_width; - metrics->trough_border = style->klass->xthickness; - metrics->stepper_size = klass->stepper_size; - metrics->stepper_spacing = klass->stepper_slider_spacing; - } - - metrics->min_slider_size = klass->min_slider_size; - - return MOZ_GTK_SUCCESS; -} - -gint -moz_gtk_widget_paint(GtkThemeWidgetType widget, GdkDrawable* drawable, - GdkRectangle* rect, GdkRectangle* cliprect, - GtkWidgetState* state, gint flags) -{ - switch (widget) { - case MOZ_GTK_BUTTON: - ensure_button_widget(); - return moz_gtk_button_paint(drawable, rect, cliprect, state, - (GtkReliefStyle) flags, gButtonWidget); - break; - case MOZ_GTK_CHECKBUTTON: - case MOZ_GTK_RADIOBUTTON: - return moz_gtk_toggle_paint(drawable, rect, cliprect, state, - (gboolean) flags, - (widget == MOZ_GTK_RADIOBUTTON)); - break; - case MOZ_GTK_SCROLLBAR_BUTTON: - return moz_gtk_scrollbar_button_paint(drawable, rect, cliprect, - state, (GtkArrowType) flags); - break; - case MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL: - case MOZ_GTK_SCROLLBAR_TRACK_VERTICAL: - return moz_gtk_scrollbar_trough_paint(drawable, rect, cliprect, state); - break; - case MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL: - case MOZ_GTK_SCROLLBAR_THUMB_VERTICAL: - return moz_gtk_scrollbar_thumb_paint(drawable, rect, cliprect, state); - break; - case MOZ_GTK_SCALE_HORIZONTAL: - case MOZ_GTK_SCALE_VERTICAL: - return moz_gtk_scale_paint(drawable, rect, cliprect, state, (GtkOrientation) flags); - break; - case MOZ_GTK_SCALE_THUMB_HORIZONTAL: - case MOZ_GTK_SCALE_THUMB_VERTICAL: - return moz_gtk_scale_thumb_paint(drawable, rect, cliprect, state, (GtkOrientation) flags); - break; - case MOZ_GTK_SPINBUTTON_UP: - case MOZ_GTK_SPINBUTTON_DOWN: - return moz_gtk_spin_paint(drawable, rect, - (widget == MOZ_GTK_SPINBUTTON_DOWN), state); - break; - case MOZ_GTK_GRIPPER: - return moz_gtk_gripper_paint(drawable, rect, cliprect, state); - break; - case MOZ_GTK_ENTRY: - return moz_gtk_entry_paint(drawable, rect, cliprect, state); - break; - case MOZ_GTK_DROPDOWN_ARROW: - return moz_gtk_dropdown_arrow_paint(drawable, rect, cliprect, state); - break; - case MOZ_GTK_CHECKBUTTON_CONTAINER: - case MOZ_GTK_RADIOBUTTON_CONTAINER: - return moz_gtk_container_paint(drawable, rect, cliprect, state, - (widget == MOZ_GTK_RADIOBUTTON_CONTAINER)); - break; - case MOZ_GTK_TOOLBAR: - return moz_gtk_toolbar_paint(drawable, rect, cliprect); - break; - case MOZ_GTK_TOOLTIP: - return moz_gtk_tooltip_paint(drawable, rect, cliprect); - break; - case MOZ_GTK_FRAME: - return moz_gtk_frame_paint(drawable, rect, cliprect); - break; - case MOZ_GTK_PROGRESSBAR: - return moz_gtk_progressbar_paint(drawable, rect, cliprect); - break; - case MOZ_GTK_PROGRESS_CHUNK: - return moz_gtk_progress_chunk_paint(drawable, rect, cliprect); - break; - case MOZ_GTK_TAB: - return moz_gtk_tab_paint(drawable, rect, cliprect, flags); - break; - case MOZ_GTK_TABPANELS: - return moz_gtk_tabpanels_paint(drawable, rect, cliprect); - break; - case MOZ_GTK_CHECKBUTTON_LABEL: - case MOZ_GTK_RADIOBUTTON_LABEL: - /* We only support these so that we can prevent the CSS border - from being drawn. */ - return MOZ_GTK_SUCCESS; - default: - g_warning("Unknown widget type: %d", widget); - } - - return MOZ_GTK_UNKNOWN_WIDGET; -} - -gint -moz_gtk_shutdown() -{ - if (gTooltipWidget) - gtk_object_unref(GTK_OBJECT(gTooltipWidget)); - /* This will destroy all of our widgets */ - if (gProtoWindow) - gtk_widget_destroy(gProtoWindow); - - gButtonWidget = NULL; - gProtoWindow = NULL; - gCheckboxWidget = NULL; - gScrollbarWidget = NULL; - gEntryWidget = NULL; - gArrowWidget = NULL; - gDropdownButtonWidget = NULL; - gHandleBoxWidget = NULL; - gFrameWidget = NULL; - gProgressWidget = NULL; - gTabWidget = NULL; - gTooltipWidget = NULL; - - return MOZ_GTK_SUCCESS; -} diff --git a/mozilla/widget/src/gtk/gtkdrawing.h b/mozilla/widget/src/gtk/gtkdrawing.h deleted file mode 100644 index 4a39e4afed7..00000000000 --- a/mozilla/widget/src/gtk/gtkdrawing.h +++ /dev/null @@ -1,293 +0,0 @@ -/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * gtkdrawing.h: GTK widget rendering utilities - * - * gtkdrawing provides an API for rendering GTK widgets in the - * current theme to a pixmap or window, without requiring an actual - * widget instantiation, similar to the Macintosh Appearance Manager - * or Windows XP's DrawThemeBackground() API. - */ - -#ifndef _GTK_DRAWING_H_ -#define _GTK_DRAWING_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/*** type definitions ***/ -typedef struct { - guint8 active; - guint8 focused; - guint8 inHover; - guint8 disabled; - guint8 isDefault; - guint8 canDefault; - gint32 curpos; /* curpos and maxpos are used for scrollbars */ - gint32 maxpos; -} GtkWidgetState; - -typedef struct { - gint slider_width; - gint trough_border; - gint stepper_size; - gint stepper_spacing; - gint min_slider_size; -} MozGtkScrollbarMetrics; - -/** flags for tab state **/ -typedef enum { - /* the first tab in the group */ - MOZ_GTK_TAB_FIRST = 1 << 0, - /* the tab just before the selected tab */ - MOZ_GTK_TAB_BEFORE_SELECTED = 1 << 1, - /* the selected tab */ - MOZ_GTK_TAB_SELECTED = 1 << 2 -} GtkTabFlags; - -/* function type for moz_gtk_enable_style_props */ -typedef gint (*style_prop_t)(GtkStyle*, const gchar*, gint); - -/*** result/error codes ***/ -#define MOZ_GTK_SUCCESS 0 -#define MOZ_GTK_UNKNOWN_WIDGET -1 -#define MOZ_GTK_UNSAFE_THEME -2 - -/*** widget type constants ***/ -typedef enum { - /* Paints a GtkButton. flags is a GtkReliefStyle. */ - MOZ_GTK_BUTTON, - /* Paints a GtkCheckButton. flags is a boolean, 1=checked, 0=not checked. */ - MOZ_GTK_CHECKBUTTON, - /* Paints a GtkRadioButton. flags is a boolean, 1=checked, 0=not checked. */ - MOZ_GTK_RADIOBUTTON, - /** - * Paints the button of a GtkScrollbar. flags is a GtkArrowType giving - * the arrow direction. - */ - MOZ_GTK_SCROLLBAR_BUTTON, - /* Paints the trough (track) of a GtkScrollbar. */ - MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL, - MOZ_GTK_SCROLLBAR_TRACK_VERTICAL, - /* Paints the slider (thumb) of a GtkScrollbar. */ - MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL, - MOZ_GTK_SCROLLBAR_THUMB_VERTICAL, - /* Paints a GtkScale. */ - MOZ_GTK_SCALE_HORIZONTAL, - MOZ_GTK_SCALE_VERTICAL, - /* Paints a GtkScale thumb. */ - MOZ_GTK_SCALE_THUMB_HORIZONTAL, - MOZ_GTK_SCALE_THUMB_VERTICAL, - /* Paints a GtkSpinButton */ - MOZ_GTK_SPINBUTTON_UP, - MOZ_GTK_SPINBUTTON_DOWN, - /* Paints the gripper of a GtkHandleBox. */ - MOZ_GTK_GRIPPER, - /* Paints a GtkEntry. */ - MOZ_GTK_ENTRY, - /* Paints a GtkOptionMenu. */ - MOZ_GTK_DROPDOWN, - /* Paints a dropdown arrow (a GtkButton containing a down GtkArrow). */ - MOZ_GTK_DROPDOWN_ARROW, - /* Paints the container part of a GtkCheckButton. */ - MOZ_GTK_CHECKBUTTON_CONTAINER, - /* Paints the container part of a GtkRadioButton. */ - MOZ_GTK_RADIOBUTTON_CONTAINER, - /* Paints the label of a GtkCheckButton (focus outline) */ - MOZ_GTK_CHECKBUTTON_LABEL, - /* Paints the label of a GtkRadioButton (focus outline) */ - MOZ_GTK_RADIOBUTTON_LABEL, - /* Paints the background of a GtkHandleBox. */ - MOZ_GTK_TOOLBAR, - /* Paints a GtkToolTip */ - MOZ_GTK_TOOLTIP, - /* Paints a GtkFrame (e.g. a status bar panel). */ - MOZ_GTK_FRAME, - /* Paints a GtkProgressBar. */ - MOZ_GTK_PROGRESSBAR, - /* Paints a progress chunk of a GtkProgressBar. */ - MOZ_GTK_PROGRESS_CHUNK, - /* Paints a tab of a GtkNotebook. flags is a GtkTabFlags, defined above. */ - MOZ_GTK_TAB, - /* Paints the background and border of a GtkNotebook. */ - MOZ_GTK_TABPANELS, - /* Paints the background of the menu bar. */ - MOZ_GTK_MENUBAR, - /* Paints the background of menus, context menus. */ - MOZ_GTK_MENUPOPUP, - /* Paints items of menubar and popups. */ - MOZ_GTK_MENUITEM, - MOZ_GTK_CHECKMENUITEM, - MOZ_GTK_RADIOMENUITEM, - /* Paints the background of a window, dialog or page. */ - MOZ_GTK_WINDOW -} GtkThemeWidgetType; - -/*** General library functions ***/ -/** - * Initializes the drawing library. You must call this function - * prior to using any other functionality. - * returns: MOZ_GTK_SUCCESS if there were no errors - * MOZ_GTK_UNSAFE_THEME if the current theme engine is known - * to crash with gtkdrawing. - */ -gint moz_gtk_init(); - -/** - * Enable GTK+ 1.2.9+ theme enhancements. You must provide a pointer - * to the GTK+ 1.2.9+ function "gtk_style_get_prop_experimental". - * styleGetProp: pointer to gtk_style_get_prop_experimental - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint moz_gtk_enable_style_props(style_prop_t styleGetProp); - -/** - * Perform cleanup of the drawing library. You should call this function - * when your program exits, or you no longer need the library. - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint moz_gtk_shutdown(); - - -/*** Widget drawing ***/ -/** - * Paint a widget in the current theme. - * widget: a constant giving the widget to paint - * rect: the bounding rectangle for the widget - * cliprect: a clipprect rectangle for this painting operation - * state: the state of the widget. ignored for some widgets. - * flags: widget-dependant flags; see the GtkThemeWidgetType definition. - */ -gint -moz_gtk_widget_paint(GtkThemeWidgetType widget, GdkDrawable* drawable, - GdkRectangle* rect, GdkRectangle* cliprect, - GtkWidgetState* state, gint flags); - - -/*** Widget metrics ***/ -/** - * Get the border size of a widget - * xthickness: [OUT] the widget's left/right border - * ythickness: [OUT] the widget's top/bottom border - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint moz_gtk_get_widget_border(GtkThemeWidgetType widget, gint* xthickness, - gint* ythickness); - -/** - * Get the desired size of a GtkCheckButton - * indicator_size: [OUT] the indicator size - * indicator_spacing: [OUT] the spacing between the indicator and its - * container - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint -moz_gtk_checkbox_get_metrics(gint* indicator_size, gint* indicator_spacing); - -/** - * Get the desired size of a GtkRadioButton - * indicator_size: [OUT] the indicator size - * indicator_spacing: [OUT] the spacing between the indicator and its - * container - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint -moz_gtk_radio_get_metrics(gint* indicator_size, gint* indicator_spacing); - -/** Get the focus metrics for a button, checkbox, or radio button. - * interior_focus: [OUT] whether the focus is drawn around the - * label (TRUE) or around the whole container (FALSE) - * focus_width: [OUT] the width of the focus line - * focus_pad: [OUT] the padding between the focus line and children - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint -moz_gtk_button_get_focus(gboolean* interior_focus, - gint* focus_width, gint* focus_pad); -gint -moz_gtk_checkbox_get_focus(gboolean* interior_focus, - gint* focus_width, gint* focus_pad); -gint -moz_gtk_radio_get_focus(gboolean* interior_focus, - gint* focus_width, gint* focus_pad); - -/** - * Get the desired size of a GtkScale thumb - * orient: [IN] the scale orientation - * thumb_length: [OUT] the length of the thumb - * thumb_height: [OUT] the height of the thumb - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint -moz_gtk_get_scalethumb_metrics(GtkOrientation orient, gint* thumb_length, gint* thumb_height); - -/** - * Get the desired metrics for a GtkScrollbar - * metrics: [IN] struct which will contain the metrics - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint -moz_gtk_get_scrollbar_metrics(MozGtkScrollbarMetrics* metrics); - -/** - * Get the desired size of a dropdown arrow button - * width: [OUT] the desired width - * height: [OUT] the desired height - * - * returns: MOZ_GTK_SUCCESS if there was no error, an error code otherwise - */ -gint moz_gtk_get_dropdown_arrow_size(gint* width, gint* height); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif diff --git a/mozilla/widget/src/gtk/keysym2ucs.c b/mozilla/widget/src/gtk/keysym2ucs.c deleted file mode 100644 index 8107dad169a..00000000000 --- a/mozilla/widget/src/gtk/keysym2ucs.c +++ /dev/null @@ -1,894 +0,0 @@ -/* - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is from xterm-122 source XFree86: xc/programs/xterm/keysym2ucs.c,v 1.3 1999/07/11 08:49:37 dawes Exp. - * - * The Initial Developer of the Original Code is - * Markus G. Kuhn and Richard Verhoeven . - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Frank Tang adopt into mozilla - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -/* - * This module converts keysym values into the corresponding ISO 10646-1 - * (UCS, Unicode) values. - * - * The array keysymtab[] contains pairs of X11 keysym values for graphical - * characters and the corresponding Unicode value. The function - * keysym2ucs() maps a keysym onto a Unicode value using a binary search, - * therefore keysymtab[] must remain SORTED by keysym value. - * - * The keysym -> UTF-8 conversion will hopefully one day be provided - * by Xlib via XmbLookupString() and should ideally not have to be - * done in X applications. But we are not there yet. - * - * We allow to represent any UCS character in the range U+00000000 to - * U+00FFFFFF by a keysym value in the range 0x01000000 to 0x01ffffff. - * This admittedly does not cover the entire 31-bit space of UCS, but - * it does cover all of the characters up to U+10FFFF, which can be - * represented by UTF-16, and more, and it is very unlikely that higher - * UCS codes will ever be assigned by ISO. So to get Unicode character - * U+ABCD you can directly use keysym 0x1000abcd. - * - * NOTE: The comments in the table below contain the actual character - * encoded in UTF-8, so for viewing and editing best use an editor in - * UTF-8 mode. - * - * Author: Markus G. Kuhn , University of Cambridge, June 1999 - * - * Special thanks to Richard Verhoeven for preparing - * an initial draft of the mapping table. - * - * This software is in the public domain. Share and enjoy! - */ - -#include "keysym2ucs.h" - -struct codepair { - unsigned short keysym; - unsigned short ucs; -} keysymtab[] = { - { 0x01a1, 0x0104 }, /* Aogonek Ą LATIN CAPITAL LETTER A WITH OGONEK */ - { 0x01a2, 0x02d8 }, /* breve ˘ BREVE */ - { 0x01a3, 0x0141 }, /* Lstroke Ł LATIN CAPITAL LETTER L WITH STROKE */ - { 0x01a5, 0x013d }, /* Lcaron Ľ LATIN CAPITAL LETTER L WITH CARON */ - { 0x01a6, 0x015a }, /* Sacute Ś LATIN CAPITAL LETTER S WITH ACUTE */ - { 0x01a9, 0x0160 }, /* Scaron Š LATIN CAPITAL LETTER S WITH CARON */ - { 0x01aa, 0x015e }, /* Scedilla Ş LATIN CAPITAL LETTER S WITH CEDILLA */ - { 0x01ab, 0x0164 }, /* Tcaron Ť LATIN CAPITAL LETTER T WITH CARON */ - { 0x01ac, 0x0179 }, /* Zacute Ź LATIN CAPITAL LETTER Z WITH ACUTE */ - { 0x01ae, 0x017d }, /* Zcaron Ž LATIN CAPITAL LETTER Z WITH CARON */ - { 0x01af, 0x017b }, /* Zabovedot Ż LATIN CAPITAL LETTER Z WITH DOT ABOVE */ - { 0x01b1, 0x0105 }, /* aogonek ą LATIN SMALL LETTER A WITH OGONEK */ - { 0x01b2, 0x02db }, /* ogonek ˛ OGONEK */ - { 0x01b3, 0x0142 }, /* lstroke ł LATIN SMALL LETTER L WITH STROKE */ - { 0x01b5, 0x013e }, /* lcaron ľ LATIN SMALL LETTER L WITH CARON */ - { 0x01b6, 0x015b }, /* sacute ś LATIN SMALL LETTER S WITH ACUTE */ - { 0x01b7, 0x02c7 }, /* caron ˇ CARON */ - { 0x01b9, 0x0161 }, /* scaron š LATIN SMALL LETTER S WITH CARON */ - { 0x01ba, 0x015f }, /* scedilla ş LATIN SMALL LETTER S WITH CEDILLA */ - { 0x01bb, 0x0165 }, /* tcaron ť LATIN SMALL LETTER T WITH CARON */ - { 0x01bc, 0x017a }, /* zacute ź LATIN SMALL LETTER Z WITH ACUTE */ - { 0x01bd, 0x02dd }, /* doubleacute ˝ DOUBLE ACUTE ACCENT */ - { 0x01be, 0x017e }, /* zcaron ž LATIN SMALL LETTER Z WITH CARON */ - { 0x01bf, 0x017c }, /* zabovedot ż LATIN SMALL LETTER Z WITH DOT ABOVE */ - { 0x01c0, 0x0154 }, /* Racute Ŕ LATIN CAPITAL LETTER R WITH ACUTE */ - { 0x01c3, 0x0102 }, /* Abreve Ă LATIN CAPITAL LETTER A WITH BREVE */ - { 0x01c5, 0x0139 }, /* Lacute Ĺ LATIN CAPITAL LETTER L WITH ACUTE */ - { 0x01c6, 0x0106 }, /* Cacute Ć LATIN CAPITAL LETTER C WITH ACUTE */ - { 0x01c8, 0x010c }, /* Ccaron Č LATIN CAPITAL LETTER C WITH CARON */ - { 0x01ca, 0x0118 }, /* Eogonek Ę LATIN CAPITAL LETTER E WITH OGONEK */ - { 0x01cc, 0x011a }, /* Ecaron Ě LATIN CAPITAL LETTER E WITH CARON */ - { 0x01cf, 0x010e }, /* Dcaron Ď LATIN CAPITAL LETTER D WITH CARON */ - { 0x01d0, 0x0110 }, /* Dstroke Đ LATIN CAPITAL LETTER D WITH STROKE */ - { 0x01d1, 0x0143 }, /* Nacute Ń LATIN CAPITAL LETTER N WITH ACUTE */ - { 0x01d2, 0x0147 }, /* Ncaron Ň LATIN CAPITAL LETTER N WITH CARON */ - { 0x01d5, 0x0150 }, /* Odoubleacute Ő LATIN CAPITAL LETTER O WITH DOUBLE ACUTE */ - { 0x01d8, 0x0158 }, /* Rcaron Ř LATIN CAPITAL LETTER R WITH CARON */ - { 0x01d9, 0x016e }, /* Uring Ů LATIN CAPITAL LETTER U WITH RING ABOVE */ - { 0x01db, 0x0170 }, /* Udoubleacute Ű LATIN CAPITAL LETTER U WITH DOUBLE ACUTE */ - { 0x01de, 0x0162 }, /* Tcedilla Ţ LATIN CAPITAL LETTER T WITH CEDILLA */ - { 0x01e0, 0x0155 }, /* racute ŕ LATIN SMALL LETTER R WITH ACUTE */ - { 0x01e3, 0x0103 }, /* abreve ă LATIN SMALL LETTER A WITH BREVE */ - { 0x01e5, 0x013a }, /* lacute ĺ LATIN SMALL LETTER L WITH ACUTE */ - { 0x01e6, 0x0107 }, /* cacute ć LATIN SMALL LETTER C WITH ACUTE */ - { 0x01e8, 0x010d }, /* ccaron č LATIN SMALL LETTER C WITH CARON */ - { 0x01ea, 0x0119 }, /* eogonek ę LATIN SMALL LETTER E WITH OGONEK */ - { 0x01ec, 0x011b }, /* ecaron ě LATIN SMALL LETTER E WITH CARON */ - { 0x01ef, 0x010f }, /* dcaron ď LATIN SMALL LETTER D WITH CARON */ - { 0x01f0, 0x0111 }, /* dstroke đ LATIN SMALL LETTER D WITH STROKE */ - { 0x01f1, 0x0144 }, /* nacute ń LATIN SMALL LETTER N WITH ACUTE */ - { 0x01f2, 0x0148 }, /* ncaron ň LATIN SMALL LETTER N WITH CARON */ - { 0x01f5, 0x0151 }, /* odoubleacute ő LATIN SMALL LETTER O WITH DOUBLE ACUTE */ - { 0x01f8, 0x0159 }, /* rcaron ř LATIN SMALL LETTER R WITH CARON */ - { 0x01f9, 0x016f }, /* uring ů LATIN SMALL LETTER U WITH RING ABOVE */ - { 0x01fb, 0x0171 }, /* udoubleacute ű LATIN SMALL LETTER U WITH DOUBLE ACUTE */ - { 0x01fe, 0x0163 }, /* tcedilla ţ LATIN SMALL LETTER T WITH CEDILLA */ - { 0x01ff, 0x02d9 }, /* abovedot ˙ DOT ABOVE */ - { 0x02a1, 0x0126 }, /* Hstroke Ħ LATIN CAPITAL LETTER H WITH STROKE */ - { 0x02a6, 0x0124 }, /* Hcircumflex Ĥ LATIN CAPITAL LETTER H WITH CIRCUMFLEX */ - { 0x02a9, 0x0130 }, /* Iabovedot İ LATIN CAPITAL LETTER I WITH DOT ABOVE */ - { 0x02ab, 0x011e }, /* Gbreve Ğ LATIN CAPITAL LETTER G WITH BREVE */ - { 0x02ac, 0x0134 }, /* Jcircumflex Ĵ LATIN CAPITAL LETTER J WITH CIRCUMFLEX */ - { 0x02b1, 0x0127 }, /* hstroke ħ LATIN SMALL LETTER H WITH STROKE */ - { 0x02b6, 0x0125 }, /* hcircumflex ĥ LATIN SMALL LETTER H WITH CIRCUMFLEX */ - { 0x02b9, 0x0131 }, /* idotless ı LATIN SMALL LETTER DOTLESS I */ - { 0x02bb, 0x011f }, /* gbreve ğ LATIN SMALL LETTER G WITH BREVE */ - { 0x02bc, 0x0135 }, /* jcircumflex ĵ LATIN SMALL LETTER J WITH CIRCUMFLEX */ - { 0x02c5, 0x010a }, /* Cabovedot Ċ LATIN CAPITAL LETTER C WITH DOT ABOVE */ - { 0x02c6, 0x0108 }, /* Ccircumflex Ĉ LATIN CAPITAL LETTER C WITH CIRCUMFLEX */ - { 0x02d5, 0x0120 }, /* Gabovedot Ġ LATIN CAPITAL LETTER G WITH DOT ABOVE */ - { 0x02d8, 0x011c }, /* Gcircumflex Ĝ LATIN CAPITAL LETTER G WITH CIRCUMFLEX */ - { 0x02dd, 0x016c }, /* Ubreve Ŭ LATIN CAPITAL LETTER U WITH BREVE */ - { 0x02de, 0x015c }, /* Scircumflex Ŝ LATIN CAPITAL LETTER S WITH CIRCUMFLEX */ - { 0x02e5, 0x010b }, /* cabovedot ċ LATIN SMALL LETTER C WITH DOT ABOVE */ - { 0x02e6, 0x0109 }, /* ccircumflex ĉ LATIN SMALL LETTER C WITH CIRCUMFLEX */ - { 0x02f5, 0x0121 }, /* gabovedot ġ LATIN SMALL LETTER G WITH DOT ABOVE */ - { 0x02f8, 0x011d }, /* gcircumflex ĝ LATIN SMALL LETTER G WITH CIRCUMFLEX */ - { 0x02fd, 0x016d }, /* ubreve ŭ LATIN SMALL LETTER U WITH BREVE */ - { 0x02fe, 0x015d }, /* scircumflex ŝ LATIN SMALL LETTER S WITH CIRCUMFLEX */ - { 0x03a2, 0x0138 }, /* kra ĸ LATIN SMALL LETTER KRA */ - { 0x03a3, 0x0156 }, /* Rcedilla Ŗ LATIN CAPITAL LETTER R WITH CEDILLA */ - { 0x03a5, 0x0128 }, /* Itilde Ĩ LATIN CAPITAL LETTER I WITH TILDE */ - { 0x03a6, 0x013b }, /* Lcedilla Ļ LATIN CAPITAL LETTER L WITH CEDILLA */ - { 0x03aa, 0x0112 }, /* Emacron Ē LATIN CAPITAL LETTER E WITH MACRON */ - { 0x03ab, 0x0122 }, /* Gcedilla Ģ LATIN CAPITAL LETTER G WITH CEDILLA */ - { 0x03ac, 0x0166 }, /* Tslash Ŧ LATIN CAPITAL LETTER T WITH STROKE */ - { 0x03b3, 0x0157 }, /* rcedilla ŗ LATIN SMALL LETTER R WITH CEDILLA */ - { 0x03b5, 0x0129 }, /* itilde ĩ LATIN SMALL LETTER I WITH TILDE */ - { 0x03b6, 0x013c }, /* lcedilla ļ LATIN SMALL LETTER L WITH CEDILLA */ - { 0x03ba, 0x0113 }, /* emacron ē LATIN SMALL LETTER E WITH MACRON */ - { 0x03bb, 0x0123 }, /* gcedilla ģ LATIN SMALL LETTER G WITH CEDILLA */ - { 0x03bc, 0x0167 }, /* tslash ŧ LATIN SMALL LETTER T WITH STROKE */ - { 0x03bd, 0x014a }, /* ENG Ŋ LATIN CAPITAL LETTER ENG */ - { 0x03bf, 0x014b }, /* eng ŋ LATIN SMALL LETTER ENG */ - { 0x03c0, 0x0100 }, /* Amacron Ā LATIN CAPITAL LETTER A WITH MACRON */ - { 0x03c7, 0x012e }, /* Iogonek Į LATIN CAPITAL LETTER I WITH OGONEK */ - { 0x03cc, 0x0116 }, /* Eabovedot Ė LATIN CAPITAL LETTER E WITH DOT ABOVE */ - { 0x03cf, 0x012a }, /* Imacron Ī LATIN CAPITAL LETTER I WITH MACRON */ - { 0x03d1, 0x0145 }, /* Ncedilla Ņ LATIN CAPITAL LETTER N WITH CEDILLA */ - { 0x03d2, 0x014c }, /* Omacron Ō LATIN CAPITAL LETTER O WITH MACRON */ - { 0x03d3, 0x0136 }, /* Kcedilla Ķ LATIN CAPITAL LETTER K WITH CEDILLA */ - { 0x03d9, 0x0172 }, /* Uogonek Ų LATIN CAPITAL LETTER U WITH OGONEK */ - { 0x03dd, 0x0168 }, /* Utilde Ũ LATIN CAPITAL LETTER U WITH TILDE */ - { 0x03de, 0x016a }, /* Umacron Ū LATIN CAPITAL LETTER U WITH MACRON */ - { 0x03e0, 0x0101 }, /* amacron ā LATIN SMALL LETTER A WITH MACRON */ - { 0x03e7, 0x012f }, /* iogonek į LATIN SMALL LETTER I WITH OGONEK */ - { 0x03ec, 0x0117 }, /* eabovedot ė LATIN SMALL LETTER E WITH DOT ABOVE */ - { 0x03ef, 0x012b }, /* imacron ī LATIN SMALL LETTER I WITH MACRON */ - { 0x03f1, 0x0146 }, /* ncedilla ņ LATIN SMALL LETTER N WITH CEDILLA */ - { 0x03f2, 0x014d }, /* omacron ō LATIN SMALL LETTER O WITH MACRON */ - { 0x03f3, 0x0137 }, /* kcedilla ķ LATIN SMALL LETTER K WITH CEDILLA */ - { 0x03f9, 0x0173 }, /* uogonek ų LATIN SMALL LETTER U WITH OGONEK */ - { 0x03fd, 0x0169 }, /* utilde ũ LATIN SMALL LETTER U WITH TILDE */ - { 0x03fe, 0x016b }, /* umacron ū LATIN SMALL LETTER U WITH MACRON */ - { 0x047e, 0x203e }, /* overline ‾ OVERLINE */ - { 0x04a1, 0x3002 }, /* kana_fullstop 。 IDEOGRAPHIC FULL STOP */ - { 0x04a2, 0x300c }, /* kana_openingbracket 「 LEFT CORNER BRACKET */ - { 0x04a3, 0x300d }, /* kana_closingbracket 」 RIGHT CORNER BRACKET */ - { 0x04a4, 0x3001 }, /* kana_comma 、 IDEOGRAPHIC COMMA */ - { 0x04a5, 0x30fb }, /* kana_conjunctive ・ KATAKANA MIDDLE DOT */ - { 0x04a6, 0x30f2 }, /* kana_WO ヲ KATAKANA LETTER WO */ - { 0x04a7, 0x30a1 }, /* kana_a ァ KATAKANA LETTER SMALL A */ - { 0x04a8, 0x30a3 }, /* kana_i ィ KATAKANA LETTER SMALL I */ - { 0x04a9, 0x30a5 }, /* kana_u ゥ KATAKANA LETTER SMALL U */ - { 0x04aa, 0x30a7 }, /* kana_e ェ KATAKANA LETTER SMALL E */ - { 0x04ab, 0x30a9 }, /* kana_o ォ KATAKANA LETTER SMALL O */ - { 0x04ac, 0x30e3 }, /* kana_ya ャ KATAKANA LETTER SMALL YA */ - { 0x04ad, 0x30e5 }, /* kana_yu ュ KATAKANA LETTER SMALL YU */ - { 0x04ae, 0x30e7 }, /* kana_yo ョ KATAKANA LETTER SMALL YO */ - { 0x04af, 0x30c3 }, /* kana_tsu ッ KATAKANA LETTER SMALL TU */ - { 0x04b0, 0x30fc }, /* prolongedsound ー KATAKANA-HIRAGANA PROLONGED SOUND MARK */ - { 0x04b1, 0x30a2 }, /* kana_A ア KATAKANA LETTER A */ - { 0x04b2, 0x30a4 }, /* kana_I イ KATAKANA LETTER I */ - { 0x04b3, 0x30a6 }, /* kana_U ウ KATAKANA LETTER U */ - { 0x04b4, 0x30a8 }, /* kana_E エ KATAKANA LETTER E */ - { 0x04b5, 0x30aa }, /* kana_O オ KATAKANA LETTER O */ - { 0x04b6, 0x30ab }, /* kana_KA カ KATAKANA LETTER KA */ - { 0x04b7, 0x30ad }, /* kana_KI キ KATAKANA LETTER KI */ - { 0x04b8, 0x30af }, /* kana_KU ク KATAKANA LETTER KU */ - { 0x04b9, 0x30b1 }, /* kana_KE ケ KATAKANA LETTER KE */ - { 0x04ba, 0x30b3 }, /* kana_KO コ KATAKANA LETTER KO */ - { 0x04bb, 0x30b5 }, /* kana_SA サ KATAKANA LETTER SA */ - { 0x04bc, 0x30b7 }, /* kana_SHI シ KATAKANA LETTER SI */ - { 0x04bd, 0x30b9 }, /* kana_SU ス KATAKANA LETTER SU */ - { 0x04be, 0x30bb }, /* kana_SE セ KATAKANA LETTER SE */ - { 0x04bf, 0x30bd }, /* kana_SO ソ KATAKANA LETTER SO */ - { 0x04c0, 0x30bf }, /* kana_TA タ KATAKANA LETTER TA */ - { 0x04c1, 0x30c1 }, /* kana_CHI チ KATAKANA LETTER TI */ - { 0x04c2, 0x30c4 }, /* kana_TSU ツ KATAKANA LETTER TU */ - { 0x04c3, 0x30c6 }, /* kana_TE テ KATAKANA LETTER TE */ - { 0x04c4, 0x30c8 }, /* kana_TO ト KATAKANA LETTER TO */ - { 0x04c5, 0x30ca }, /* kana_NA ナ KATAKANA LETTER NA */ - { 0x04c6, 0x30cb }, /* kana_NI ニ KATAKANA LETTER NI */ - { 0x04c7, 0x30cc }, /* kana_NU ヌ KATAKANA LETTER NU */ - { 0x04c8, 0x30cd }, /* kana_NE ネ KATAKANA LETTER NE */ - { 0x04c9, 0x30ce }, /* kana_NO ノ KATAKANA LETTER NO */ - { 0x04ca, 0x30cf }, /* kana_HA ハ KATAKANA LETTER HA */ - { 0x04cb, 0x30d2 }, /* kana_HI ヒ KATAKANA LETTER HI */ - { 0x04cc, 0x30d5 }, /* kana_FU フ KATAKANA LETTER HU */ - { 0x04cd, 0x30d8 }, /* kana_HE ヘ KATAKANA LETTER HE */ - { 0x04ce, 0x30db }, /* kana_HO ホ KATAKANA LETTER HO */ - { 0x04cf, 0x30de }, /* kana_MA マ KATAKANA LETTER MA */ - { 0x04d0, 0x30df }, /* kana_MI ミ KATAKANA LETTER MI */ - { 0x04d1, 0x30e0 }, /* kana_MU ム KATAKANA LETTER MU */ - { 0x04d2, 0x30e1 }, /* kana_ME メ KATAKANA LETTER ME */ - { 0x04d3, 0x30e2 }, /* kana_MO モ KATAKANA LETTER MO */ - { 0x04d4, 0x30e4 }, /* kana_YA ヤ KATAKANA LETTER YA */ - { 0x04d5, 0x30e6 }, /* kana_YU ユ KATAKANA LETTER YU */ - { 0x04d6, 0x30e8 }, /* kana_YO ヨ KATAKANA LETTER YO */ - { 0x04d7, 0x30e9 }, /* kana_RA ラ KATAKANA LETTER RA */ - { 0x04d8, 0x30ea }, /* kana_RI リ KATAKANA LETTER RI */ - { 0x04d9, 0x30eb }, /* kana_RU ル KATAKANA LETTER RU */ - { 0x04da, 0x30ec }, /* kana_RE レ KATAKANA LETTER RE */ - { 0x04db, 0x30ed }, /* kana_RO ロ KATAKANA LETTER RO */ - { 0x04dc, 0x30ef }, /* kana_WA ワ KATAKANA LETTER WA */ - { 0x04dd, 0x30f3 }, /* kana_N ン KATAKANA LETTER N */ - { 0x04de, 0x309b }, /* voicedsound ゛ KATAKANA-HIRAGANA VOICED SOUND MARK */ - { 0x04df, 0x309c }, /* semivoicedsound ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK */ - { 0x05ac, 0x060c }, /* Arabic_comma ، ARABIC COMMA */ - { 0x05bb, 0x061b }, /* Arabic_semicolon ؛ ARABIC SEMICOLON */ - { 0x05bf, 0x061f }, /* Arabic_question_mark ؟ ARABIC QUESTION MARK */ - { 0x05c1, 0x0621 }, /* Arabic_hamza ء ARABIC LETTER HAMZA */ - { 0x05c2, 0x0622 }, /* Arabic_maddaonalef آ ARABIC LETTER ALEF WITH MADDA ABOVE */ - { 0x05c3, 0x0623 }, /* Arabic_hamzaonalef أ ARABIC LETTER ALEF WITH HAMZA ABOVE */ - { 0x05c4, 0x0624 }, /* Arabic_hamzaonwaw ؤ ARABIC LETTER WAW WITH HAMZA ABOVE */ - { 0x05c5, 0x0625 }, /* Arabic_hamzaunderalef إ ARABIC LETTER ALEF WITH HAMZA BELOW */ - { 0x05c6, 0x0626 }, /* Arabic_hamzaonyeh ئ ARABIC LETTER YEH WITH HAMZA ABOVE */ - { 0x05c7, 0x0627 }, /* Arabic_alef ا ARABIC LETTER ALEF */ - { 0x05c8, 0x0628 }, /* Arabic_beh ب ARABIC LETTER BEH */ - { 0x05c9, 0x0629 }, /* Arabic_tehmarbuta ة ARABIC LETTER TEH MARBUTA */ - { 0x05ca, 0x062a }, /* Arabic_teh ت ARABIC LETTER TEH */ - { 0x05cb, 0x062b }, /* Arabic_theh ث ARABIC LETTER THEH */ - { 0x05cc, 0x062c }, /* Arabic_jeem ج ARABIC LETTER JEEM */ - { 0x05cd, 0x062d }, /* Arabic_hah ح ARABIC LETTER HAH */ - { 0x05ce, 0x062e }, /* Arabic_khah خ ARABIC LETTER KHAH */ - { 0x05cf, 0x062f }, /* Arabic_dal د ARABIC LETTER DAL */ - { 0x05d0, 0x0630 }, /* Arabic_thal ذ ARABIC LETTER THAL */ - { 0x05d1, 0x0631 }, /* Arabic_ra ر ARABIC LETTER REH */ - { 0x05d2, 0x0632 }, /* Arabic_zain ز ARABIC LETTER ZAIN */ - { 0x05d3, 0x0633 }, /* Arabic_seen س ARABIC LETTER SEEN */ - { 0x05d4, 0x0634 }, /* Arabic_sheen ش ARABIC LETTER SHEEN */ - { 0x05d5, 0x0635 }, /* Arabic_sad ص ARABIC LETTER SAD */ - { 0x05d6, 0x0636 }, /* Arabic_dad ض ARABIC LETTER DAD */ - { 0x05d7, 0x0637 }, /* Arabic_tah ط ARABIC LETTER TAH */ - { 0x05d8, 0x0638 }, /* Arabic_zah ظ ARABIC LETTER ZAH */ - { 0x05d9, 0x0639 }, /* Arabic_ain ع ARABIC LETTER AIN */ - { 0x05da, 0x063a }, /* Arabic_ghain غ ARABIC LETTER GHAIN */ - { 0x05e0, 0x0640 }, /* Arabic_tatweel ـ ARABIC TATWEEL */ - { 0x05e1, 0x0641 }, /* Arabic_feh ف ARABIC LETTER FEH */ - { 0x05e2, 0x0642 }, /* Arabic_qaf ق ARABIC LETTER QAF */ - { 0x05e3, 0x0643 }, /* Arabic_kaf ك ARABIC LETTER KAF */ - { 0x05e4, 0x0644 }, /* Arabic_lam ل ARABIC LETTER LAM */ - { 0x05e5, 0x0645 }, /* Arabic_meem م ARABIC LETTER MEEM */ - { 0x05e6, 0x0646 }, /* Arabic_noon ن ARABIC LETTER NOON */ - { 0x05e7, 0x0647 }, /* Arabic_ha ه ARABIC LETTER HEH */ - { 0x05e8, 0x0648 }, /* Arabic_waw و ARABIC LETTER WAW */ - { 0x05e9, 0x0649 }, /* Arabic_alefmaksura ى ARABIC LETTER ALEF MAKSURA */ - { 0x05ea, 0x064a }, /* Arabic_yeh ي ARABIC LETTER YEH */ - { 0x05eb, 0x064b }, /* Arabic_fathatan ً ARABIC FATHATAN */ - { 0x05ec, 0x064c }, /* Arabic_dammatan ٌ ARABIC DAMMATAN */ - { 0x05ed, 0x064d }, /* Arabic_kasratan ٍ ARABIC KASRATAN */ - { 0x05ee, 0x064e }, /* Arabic_fatha َ ARABIC FATHA */ - { 0x05ef, 0x064f }, /* Arabic_damma ُ ARABIC DAMMA */ - { 0x05f0, 0x0650 }, /* Arabic_kasra ِ ARABIC KASRA */ - { 0x05f1, 0x0651 }, /* Arabic_shadda ّ ARABIC SHADDA */ - { 0x05f2, 0x0652 }, /* Arabic_sukun ْ ARABIC SUKUN */ - { 0x06a1, 0x0452 }, /* Serbian_dje ђ CYRILLIC SMALL LETTER DJE */ - { 0x06a2, 0x0453 }, /* Macedonia_gje ѓ CYRILLIC SMALL LETTER GJE */ - { 0x06a3, 0x0451 }, /* Cyrillic_io ё CYRILLIC SMALL LETTER IO */ - { 0x06a4, 0x0454 }, /* Ukrainian_ie є CYRILLIC SMALL LETTER UKRAINIAN IE */ - { 0x06a5, 0x0455 }, /* Macedonia_dse ѕ CYRILLIC SMALL LETTER DZE */ - { 0x06a6, 0x0456 }, /* Ukrainian_i і CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I */ - { 0x06a7, 0x0457 }, /* Ukrainian_yi ї CYRILLIC SMALL LETTER YI */ - { 0x06a8, 0x0458 }, /* Cyrillic_je ј CYRILLIC SMALL LETTER JE */ - { 0x06a9, 0x0459 }, /* Cyrillic_lje љ CYRILLIC SMALL LETTER LJE */ - { 0x06aa, 0x045a }, /* Cyrillic_nje њ CYRILLIC SMALL LETTER NJE */ - { 0x06ab, 0x045b }, /* Serbian_tshe ћ CYRILLIC SMALL LETTER TSHE */ - { 0x06ac, 0x045c }, /* Macedonia_kje ќ CYRILLIC SMALL LETTER KJE */ - { 0x06ae, 0x045e }, /* Byelorussian_shortu ў CYRILLIC SMALL LETTER SHORT U */ - { 0x06af, 0x045f }, /* Cyrillic_dzhe џ CYRILLIC SMALL LETTER DZHE */ - { 0x06b0, 0x2116 }, /* numerosign № NUMERO SIGN */ - { 0x06b1, 0x0402 }, /* Serbian_DJE Ђ CYRILLIC CAPITAL LETTER DJE */ - { 0x06b2, 0x0403 }, /* Macedonia_GJE Ѓ CYRILLIC CAPITAL LETTER GJE */ - { 0x06b3, 0x0401 }, /* Cyrillic_IO Ё CYRILLIC CAPITAL LETTER IO */ - { 0x06b4, 0x0404 }, /* Ukrainian_IE Є CYRILLIC CAPITAL LETTER UKRAINIAN IE */ - { 0x06b5, 0x0405 }, /* Macedonia_DSE Ѕ CYRILLIC CAPITAL LETTER DZE */ - { 0x06b6, 0x0406 }, /* Ukrainian_I І CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I */ - { 0x06b7, 0x0407 }, /* Ukrainian_YI Ї CYRILLIC CAPITAL LETTER YI */ - { 0x06b8, 0x0408 }, /* Cyrillic_JE Ј CYRILLIC CAPITAL LETTER JE */ - { 0x06b9, 0x0409 }, /* Cyrillic_LJE Љ CYRILLIC CAPITAL LETTER LJE */ - { 0x06ba, 0x040a }, /* Cyrillic_NJE Њ CYRILLIC CAPITAL LETTER NJE */ - { 0x06bb, 0x040b }, /* Serbian_TSHE Ћ CYRILLIC CAPITAL LETTER TSHE */ - { 0x06bc, 0x040c }, /* Macedonia_KJE Ќ CYRILLIC CAPITAL LETTER KJE */ - { 0x06be, 0x040e }, /* Byelorussian_SHORTU Ў CYRILLIC CAPITAL LETTER SHORT U */ - { 0x06bf, 0x040f }, /* Cyrillic_DZHE Џ CYRILLIC CAPITAL LETTER DZHE */ - { 0x06c0, 0x044e }, /* Cyrillic_yu ю CYRILLIC SMALL LETTER YU */ - { 0x06c1, 0x0430 }, /* Cyrillic_a а CYRILLIC SMALL LETTER A */ - { 0x06c2, 0x0431 }, /* Cyrillic_be б CYRILLIC SMALL LETTER BE */ - { 0x06c3, 0x0446 }, /* Cyrillic_tse ц CYRILLIC SMALL LETTER TSE */ - { 0x06c4, 0x0434 }, /* Cyrillic_de д CYRILLIC SMALL LETTER DE */ - { 0x06c5, 0x0435 }, /* Cyrillic_ie е CYRILLIC SMALL LETTER IE */ - { 0x06c6, 0x0444 }, /* Cyrillic_ef ф CYRILLIC SMALL LETTER EF */ - { 0x06c7, 0x0433 }, /* Cyrillic_ghe г CYRILLIC SMALL LETTER GHE */ - { 0x06c8, 0x0445 }, /* Cyrillic_ha х CYRILLIC SMALL LETTER HA */ - { 0x06c9, 0x0438 }, /* Cyrillic_i и CYRILLIC SMALL LETTER I */ - { 0x06ca, 0x0439 }, /* Cyrillic_shorti й CYRILLIC SMALL LETTER SHORT I */ - { 0x06cb, 0x043a }, /* Cyrillic_ka к CYRILLIC SMALL LETTER KA */ - { 0x06cc, 0x043b }, /* Cyrillic_el л CYRILLIC SMALL LETTER EL */ - { 0x06cd, 0x043c }, /* Cyrillic_em м CYRILLIC SMALL LETTER EM */ - { 0x06ce, 0x043d }, /* Cyrillic_en н CYRILLIC SMALL LETTER EN */ - { 0x06cf, 0x043e }, /* Cyrillic_o о CYRILLIC SMALL LETTER O */ - { 0x06d0, 0x043f }, /* Cyrillic_pe п CYRILLIC SMALL LETTER PE */ - { 0x06d1, 0x044f }, /* Cyrillic_ya я CYRILLIC SMALL LETTER YA */ - { 0x06d2, 0x0440 }, /* Cyrillic_er р CYRILLIC SMALL LETTER ER */ - { 0x06d3, 0x0441 }, /* Cyrillic_es с CYRILLIC SMALL LETTER ES */ - { 0x06d4, 0x0442 }, /* Cyrillic_te т CYRILLIC SMALL LETTER TE */ - { 0x06d5, 0x0443 }, /* Cyrillic_u у CYRILLIC SMALL LETTER U */ - { 0x06d6, 0x0436 }, /* Cyrillic_zhe ж CYRILLIC SMALL LETTER ZHE */ - { 0x06d7, 0x0432 }, /* Cyrillic_ve в CYRILLIC SMALL LETTER VE */ - { 0x06d8, 0x044c }, /* Cyrillic_softsign ь CYRILLIC SMALL LETTER SOFT SIGN */ - { 0x06d9, 0x044b }, /* Cyrillic_yeru ы CYRILLIC SMALL LETTER YERU */ - { 0x06da, 0x0437 }, /* Cyrillic_ze з CYRILLIC SMALL LETTER ZE */ - { 0x06db, 0x0448 }, /* Cyrillic_sha ш CYRILLIC SMALL LETTER SHA */ - { 0x06dc, 0x044d }, /* Cyrillic_e э CYRILLIC SMALL LETTER E */ - { 0x06dd, 0x0449 }, /* Cyrillic_shcha щ CYRILLIC SMALL LETTER SHCHA */ - { 0x06de, 0x0447 }, /* Cyrillic_che ч CYRILLIC SMALL LETTER CHE */ - { 0x06df, 0x044a }, /* Cyrillic_hardsign ъ CYRILLIC SMALL LETTER HARD SIGN */ - { 0x06e0, 0x042e }, /* Cyrillic_YU Ю CYRILLIC CAPITAL LETTER YU */ - { 0x06e1, 0x0410 }, /* Cyrillic_A А CYRILLIC CAPITAL LETTER A */ - { 0x06e2, 0x0411 }, /* Cyrillic_BE Б CYRILLIC CAPITAL LETTER BE */ - { 0x06e3, 0x0426 }, /* Cyrillic_TSE Ц CYRILLIC CAPITAL LETTER TSE */ - { 0x06e4, 0x0414 }, /* Cyrillic_DE Д CYRILLIC CAPITAL LETTER DE */ - { 0x06e5, 0x0415 }, /* Cyrillic_IE Е CYRILLIC CAPITAL LETTER IE */ - { 0x06e6, 0x0424 }, /* Cyrillic_EF Ф CYRILLIC CAPITAL LETTER EF */ - { 0x06e7, 0x0413 }, /* Cyrillic_GHE Г CYRILLIC CAPITAL LETTER GHE */ - { 0x06e8, 0x0425 }, /* Cyrillic_HA Х CYRILLIC CAPITAL LETTER HA */ - { 0x06e9, 0x0418 }, /* Cyrillic_I И CYRILLIC CAPITAL LETTER I */ - { 0x06ea, 0x0419 }, /* Cyrillic_SHORTI Й CYRILLIC CAPITAL LETTER SHORT I */ - { 0x06eb, 0x041a }, /* Cyrillic_KA К CYRILLIC CAPITAL LETTER KA */ - { 0x06ec, 0x041b }, /* Cyrillic_EL Л CYRILLIC CAPITAL LETTER EL */ - { 0x06ed, 0x041c }, /* Cyrillic_EM М CYRILLIC CAPITAL LETTER EM */ - { 0x06ee, 0x041d }, /* Cyrillic_EN Н CYRILLIC CAPITAL LETTER EN */ - { 0x06ef, 0x041e }, /* Cyrillic_O О CYRILLIC CAPITAL LETTER O */ - { 0x06f0, 0x041f }, /* Cyrillic_PE П CYRILLIC CAPITAL LETTER PE */ - { 0x06f1, 0x042f }, /* Cyrillic_YA Я CYRILLIC CAPITAL LETTER YA */ - { 0x06f2, 0x0420 }, /* Cyrillic_ER Р CYRILLIC CAPITAL LETTER ER */ - { 0x06f3, 0x0421 }, /* Cyrillic_ES С CYRILLIC CAPITAL LETTER ES */ - { 0x06f4, 0x0422 }, /* Cyrillic_TE Т CYRILLIC CAPITAL LETTER TE */ - { 0x06f5, 0x0423 }, /* Cyrillic_U У CYRILLIC CAPITAL LETTER U */ - { 0x06f6, 0x0416 }, /* Cyrillic_ZHE Ж CYRILLIC CAPITAL LETTER ZHE */ - { 0x06f7, 0x0412 }, /* Cyrillic_VE В CYRILLIC CAPITAL LETTER VE */ - { 0x06f8, 0x042c }, /* Cyrillic_SOFTSIGN Ь CYRILLIC CAPITAL LETTER SOFT SIGN */ - { 0x06f9, 0x042b }, /* Cyrillic_YERU Ы CYRILLIC CAPITAL LETTER YERU */ - { 0x06fa, 0x0417 }, /* Cyrillic_ZE З CYRILLIC CAPITAL LETTER ZE */ - { 0x06fb, 0x0428 }, /* Cyrillic_SHA Ш CYRILLIC CAPITAL LETTER SHA */ - { 0x06fc, 0x042d }, /* Cyrillic_E Э CYRILLIC CAPITAL LETTER E */ - { 0x06fd, 0x0429 }, /* Cyrillic_SHCHA Щ CYRILLIC CAPITAL LETTER SHCHA */ - { 0x06fe, 0x0427 }, /* Cyrillic_CHE Ч CYRILLIC CAPITAL LETTER CHE */ - { 0x06ff, 0x042a }, /* Cyrillic_HARDSIGN Ъ CYRILLIC CAPITAL LETTER HARD SIGN */ - { 0x07a1, 0x0386 }, /* Greek_ALPHAaccent Ά GREEK CAPITAL LETTER ALPHA WITH TONOS */ - { 0x07a2, 0x0388 }, /* Greek_EPSILONaccent Έ GREEK CAPITAL LETTER EPSILON WITH TONOS */ - { 0x07a3, 0x0389 }, /* Greek_ETAaccent Ή GREEK CAPITAL LETTER ETA WITH TONOS */ - { 0x07a4, 0x038a }, /* Greek_IOTAaccent Ί GREEK CAPITAL LETTER IOTA WITH TONOS */ - { 0x07a5, 0x03aa }, /* Greek_IOTAdiaeresis Ϊ GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */ - { 0x07a7, 0x038c }, /* Greek_OMICRONaccent Ό GREEK CAPITAL LETTER OMICRON WITH TONOS */ - { 0x07a8, 0x038e }, /* Greek_UPSILONaccent Ύ GREEK CAPITAL LETTER UPSILON WITH TONOS */ - { 0x07a9, 0x03ab }, /* Greek_UPSILONdieresis Ϋ GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA */ - { 0x07ab, 0x038f }, /* Greek_OMEGAaccent Ώ GREEK CAPITAL LETTER OMEGA WITH TONOS */ - { 0x07ae, 0x0385 }, /* Greek_accentdieresis ΅ GREEK DIALYTIKA TONOS */ - { 0x07af, 0x2015 }, /* Greek_horizbar ― HORIZONTAL BAR */ - { 0x07b1, 0x03ac }, /* Greek_alphaaccent ά GREEK SMALL LETTER ALPHA WITH TONOS */ - { 0x07b2, 0x03ad }, /* Greek_epsilonaccent έ GREEK SMALL LETTER EPSILON WITH TONOS */ - { 0x07b3, 0x03ae }, /* Greek_etaaccent ή GREEK SMALL LETTER ETA WITH TONOS */ - { 0x07b4, 0x03af }, /* Greek_iotaaccent ί GREEK SMALL LETTER IOTA WITH TONOS */ - { 0x07b5, 0x03ca }, /* Greek_iotadieresis ϊ GREEK SMALL LETTER IOTA WITH DIALYTIKA */ - { 0x07b6, 0x0390 }, /* Greek_iotaaccentdieresis ΐ GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS */ - { 0x07b7, 0x03cc }, /* Greek_omicronaccent ό GREEK SMALL LETTER OMICRON WITH TONOS */ - { 0x07b8, 0x03cd }, /* Greek_upsilonaccent ύ GREEK SMALL LETTER UPSILON WITH TONOS */ - { 0x07b9, 0x03cb }, /* Greek_upsilondieresis ϋ GREEK SMALL LETTER UPSILON WITH DIALYTIKA */ - { 0x07ba, 0x03b0 }, /* Greek_upsilonaccentdieresis ΰ GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS */ - { 0x07bb, 0x03ce }, /* Greek_omegaaccent ώ GREEK SMALL LETTER OMEGA WITH TONOS */ - { 0x07c1, 0x0391 }, /* Greek_ALPHA Α GREEK CAPITAL LETTER ALPHA */ - { 0x07c2, 0x0392 }, /* Greek_BETA Β GREEK CAPITAL LETTER BETA */ - { 0x07c3, 0x0393 }, /* Greek_GAMMA Γ GREEK CAPITAL LETTER GAMMA */ - { 0x07c4, 0x0394 }, /* Greek_DELTA Δ GREEK CAPITAL LETTER DELTA */ - { 0x07c5, 0x0395 }, /* Greek_EPSILON Ε GREEK CAPITAL LETTER EPSILON */ - { 0x07c6, 0x0396 }, /* Greek_ZETA Ζ GREEK CAPITAL LETTER ZETA */ - { 0x07c7, 0x0397 }, /* Greek_ETA Η GREEK CAPITAL LETTER ETA */ - { 0x07c8, 0x0398 }, /* Greek_THETA Θ GREEK CAPITAL LETTER THETA */ - { 0x07c9, 0x0399 }, /* Greek_IOTA Ι GREEK CAPITAL LETTER IOTA */ - { 0x07ca, 0x039a }, /* Greek_KAPPA Κ GREEK CAPITAL LETTER KAPPA */ - { 0x07cb, 0x039b }, /* Greek_LAMBDA Λ GREEK CAPITAL LETTER LAMDA */ - { 0x07cc, 0x039c }, /* Greek_MU Μ GREEK CAPITAL LETTER MU */ - { 0x07cd, 0x039d }, /* Greek_NU Ν GREEK CAPITAL LETTER NU */ - { 0x07ce, 0x039e }, /* Greek_XI Ξ GREEK CAPITAL LETTER XI */ - { 0x07cf, 0x039f }, /* Greek_OMICRON Ο GREEK CAPITAL LETTER OMICRON */ - { 0x07d0, 0x03a0 }, /* Greek_PI Π GREEK CAPITAL LETTER PI */ - { 0x07d1, 0x03a1 }, /* Greek_RHO Ρ GREEK CAPITAL LETTER RHO */ - { 0x07d2, 0x03a3 }, /* Greek_SIGMA Σ GREEK CAPITAL LETTER SIGMA */ - { 0x07d4, 0x03a4 }, /* Greek_TAU Τ GREEK CAPITAL LETTER TAU */ - { 0x07d5, 0x03a5 }, /* Greek_UPSILON Υ GREEK CAPITAL LETTER UPSILON */ - { 0x07d6, 0x03a6 }, /* Greek_PHI Φ GREEK CAPITAL LETTER PHI */ - { 0x07d7, 0x03a7 }, /* Greek_CHI Χ GREEK CAPITAL LETTER CHI */ - { 0x07d8, 0x03a8 }, /* Greek_PSI Ψ GREEK CAPITAL LETTER PSI */ - { 0x07d9, 0x03a9 }, /* Greek_OMEGA Ω GREEK CAPITAL LETTER OMEGA */ - { 0x07e1, 0x03b1 }, /* Greek_alpha α GREEK SMALL LETTER ALPHA */ - { 0x07e2, 0x03b2 }, /* Greek_beta β GREEK SMALL LETTER BETA */ - { 0x07e3, 0x03b3 }, /* Greek_gamma γ GREEK SMALL LETTER GAMMA */ - { 0x07e4, 0x03b4 }, /* Greek_delta δ GREEK SMALL LETTER DELTA */ - { 0x07e5, 0x03b5 }, /* Greek_epsilon ε GREEK SMALL LETTER EPSILON */ - { 0x07e6, 0x03b6 }, /* Greek_zeta ζ GREEK SMALL LETTER ZETA */ - { 0x07e7, 0x03b7 }, /* Greek_eta η GREEK SMALL LETTER ETA */ - { 0x07e8, 0x03b8 }, /* Greek_theta θ GREEK SMALL LETTER THETA */ - { 0x07e9, 0x03b9 }, /* Greek_iota ι GREEK SMALL LETTER IOTA */ - { 0x07ea, 0x03ba }, /* Greek_kappa κ GREEK SMALL LETTER KAPPA */ - { 0x07eb, 0x03bb }, /* Greek_lambda λ GREEK SMALL LETTER LAMDA */ - { 0x07ec, 0x03bc }, /* Greek_mu μ GREEK SMALL LETTER MU */ - { 0x07ed, 0x03bd }, /* Greek_nu ν GREEK SMALL LETTER NU */ - { 0x07ee, 0x03be }, /* Greek_xi ξ GREEK SMALL LETTER XI */ - { 0x07ef, 0x03bf }, /* Greek_omicron ο GREEK SMALL LETTER OMICRON */ - { 0x07f0, 0x03c0 }, /* Greek_pi π GREEK SMALL LETTER PI */ - { 0x07f1, 0x03c1 }, /* Greek_rho ρ GREEK SMALL LETTER RHO */ - { 0x07f2, 0x03c3 }, /* Greek_sigma σ GREEK SMALL LETTER SIGMA */ - { 0x07f3, 0x03c2 }, /* Greek_finalsmallsigma ς GREEK SMALL LETTER FINAL SIGMA */ - { 0x07f4, 0x03c4 }, /* Greek_tau τ GREEK SMALL LETTER TAU */ - { 0x07f5, 0x03c5 }, /* Greek_upsilon υ GREEK SMALL LETTER UPSILON */ - { 0x07f6, 0x03c6 }, /* Greek_phi φ GREEK SMALL LETTER PHI */ - { 0x07f7, 0x03c7 }, /* Greek_chi χ GREEK SMALL LETTER CHI */ - { 0x07f8, 0x03c8 }, /* Greek_psi ψ GREEK SMALL LETTER PSI */ - { 0x07f9, 0x03c9 }, /* Greek_omega ω GREEK SMALL LETTER OMEGA */ -/* 0x08a1 leftradical ? ??? */ -/* 0x08a2 topleftradical ? ??? */ -/* 0x08a3 horizconnector ? ??? */ - { 0x08a4, 0x2320 }, /* topintegral ⌠ TOP HALF INTEGRAL */ - { 0x08a5, 0x2321 }, /* botintegral ⌡ BOTTOM HALF INTEGRAL */ - { 0x08a6, 0x2502 }, /* vertconnector │ BOX DRAWINGS LIGHT VERTICAL */ -/* 0x08a7 topleftsqbracket ? ??? */ -/* 0x08a8 botleftsqbracket ? ??? */ -/* 0x08a9 toprightsqbracket ? ??? */ -/* 0x08aa botrightsqbracket ? ??? */ -/* 0x08ab topleftparens ? ??? */ -/* 0x08ac botleftparens ? ??? */ -/* 0x08ad toprightparens ? ??? */ -/* 0x08ae botrightparens ? ??? */ -/* 0x08af leftmiddlecurlybrace ? ??? */ -/* 0x08b0 rightmiddlecurlybrace ? ??? */ -/* 0x08b1 topleftsummation ? ??? */ -/* 0x08b2 botleftsummation ? ??? */ -/* 0x08b3 topvertsummationconnector ? ??? */ -/* 0x08b4 botvertsummationconnector ? ??? */ -/* 0x08b5 toprightsummation ? ??? */ -/* 0x08b6 botrightsummation ? ??? */ -/* 0x08b7 rightmiddlesummation ? ??? */ - { 0x08bc, 0x2264 }, /* lessthanequal ≤ LESS-THAN OR EQUAL TO */ - { 0x08bd, 0x2260 }, /* notequal ≠ NOT EQUAL TO */ - { 0x08be, 0x2265 }, /* greaterthanequal ≥ GREATER-THAN OR EQUAL TO */ - { 0x08bf, 0x222b }, /* integral ∫ INTEGRAL */ - { 0x08c0, 0x2234 }, /* therefore ∴ THEREFORE */ - { 0x08c1, 0x221d }, /* variation ∝ PROPORTIONAL TO */ - { 0x08c2, 0x221e }, /* infinity ∞ INFINITY */ - { 0x08c5, 0x2207 }, /* nabla ∇ NABLA */ - { 0x08c8, 0x2245 }, /* approximate ≅ APPROXIMATELY EQUAL TO */ -/* 0x08c9 similarequal ? ??? */ - { 0x08cd, 0x21d4 }, /* ifonlyif ⇔ LEFT RIGHT DOUBLE ARROW */ - { 0x08ce, 0x21d2 }, /* implies ⇒ RIGHTWARDS DOUBLE ARROW */ - { 0x08cf, 0x2261 }, /* identical ≡ IDENTICAL TO */ - { 0x08d6, 0x221a }, /* radical √ SQUARE ROOT */ - { 0x08da, 0x2282 }, /* includedin ⊂ SUBSET OF */ - { 0x08db, 0x2283 }, /* includes ⊃ SUPERSET OF */ - { 0x08dc, 0x2229 }, /* intersection ∩ INTERSECTION */ - { 0x08dd, 0x222a }, /* union ∪ UNION */ - { 0x08de, 0x2227 }, /* logicaland ∧ LOGICAL AND */ - { 0x08df, 0x2228 }, /* logicalor ∨ LOGICAL OR */ - { 0x08ef, 0x2202 }, /* partialderivative ∂ PARTIAL DIFFERENTIAL */ - { 0x08f6, 0x0192 }, /* function ƒ LATIN SMALL LETTER F WITH HOOK */ - { 0x08fb, 0x2190 }, /* leftarrow ← LEFTWARDS ARROW */ - { 0x08fc, 0x2191 }, /* uparrow ↑ UPWARDS ARROW */ - { 0x08fd, 0x2192 }, /* rightarrow → RIGHTWARDS ARROW */ - { 0x08fe, 0x2193 }, /* downarrow ↓ DOWNWARDS ARROW */ - { 0x09df, 0x2422 }, /* blank ␢ BLANK SYMBOL */ - { 0x09e0, 0x25c6 }, /* soliddiamond ◆ BLACK DIAMOND */ - { 0x09e1, 0x2592 }, /* checkerboard ▒ MEDIUM SHADE */ - { 0x09e2, 0x2409 }, /* ht ␉ SYMBOL FOR HORIZONTAL TABULATION */ - { 0x09e3, 0x240c }, /* ff ␌ SYMBOL FOR FORM FEED */ - { 0x09e4, 0x240d }, /* cr ␍ SYMBOL FOR CARRIAGE RETURN */ - { 0x09e5, 0x240a }, /* lf ␊ SYMBOL FOR LINE FEED */ - { 0x09e8, 0x2424 }, /* nl ␤ SYMBOL FOR NEWLINE */ - { 0x09e9, 0x240b }, /* vt ␋ SYMBOL FOR VERTICAL TABULATION */ - { 0x09ea, 0x2518 }, /* lowrightcorner ┘ BOX DRAWINGS LIGHT UP AND LEFT */ - { 0x09eb, 0x2510 }, /* uprightcorner ┐ BOX DRAWINGS LIGHT DOWN AND LEFT */ - { 0x09ec, 0x250c }, /* upleftcorner ┌ BOX DRAWINGS LIGHT DOWN AND RIGHT */ - { 0x09ed, 0x2514 }, /* lowleftcorner └ BOX DRAWINGS LIGHT UP AND RIGHT */ - { 0x09ee, 0x253c }, /* crossinglines ┼ BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */ -/* 0x09ef horizlinescan1 ? ??? */ -/* 0x09f0 horizlinescan3 ? ??? */ - { 0x09f1, 0x2500 }, /* horizlinescan5 ─ BOX DRAWINGS LIGHT HORIZONTAL */ -/* 0x09f2 horizlinescan7 ? ??? */ -/* 0x09f3 horizlinescan9 ? ??? */ - { 0x09f4, 0x251c }, /* leftt ├ BOX DRAWINGS LIGHT VERTICAL AND RIGHT */ - { 0x09f5, 0x2524 }, /* rightt ┤ BOX DRAWINGS LIGHT VERTICAL AND LEFT */ - { 0x09f6, 0x2534 }, /* bott ┴ BOX DRAWINGS LIGHT UP AND HORIZONTAL */ - { 0x09f7, 0x252c }, /* topt ┬ BOX DRAWINGS LIGHT DOWN AND HORIZONTAL */ - { 0x09f8, 0x2502 }, /* vertbar │ BOX DRAWINGS LIGHT VERTICAL */ - { 0x0aa1, 0x2003 }, /* emspace   EM SPACE */ - { 0x0aa2, 0x2002 }, /* enspace   EN SPACE */ - { 0x0aa3, 0x2004 }, /* em3space   THREE-PER-EM SPACE */ - { 0x0aa4, 0x2005 }, /* em4space   FOUR-PER-EM SPACE */ - { 0x0aa5, 0x2007 }, /* digitspace   FIGURE SPACE */ - { 0x0aa6, 0x2008 }, /* punctspace   PUNCTUATION SPACE */ - { 0x0aa7, 0x2009 }, /* thinspace   THIN SPACE */ - { 0x0aa8, 0x200a }, /* hairspace   HAIR SPACE */ - { 0x0aa9, 0x2014 }, /* emdash — EM DASH */ - { 0x0aaa, 0x2013 }, /* endash – EN DASH */ -/* 0x0aac signifblank ? ??? */ - { 0x0aae, 0x2026 }, /* ellipsis … HORIZONTAL ELLIPSIS */ -/* 0x0aaf doubbaselinedot ? ??? */ - { 0x0ab0, 0x2153 }, /* onethird ⅓ VULGAR FRACTION ONE THIRD */ - { 0x0ab1, 0x2154 }, /* twothirds ⅔ VULGAR FRACTION TWO THIRDS */ - { 0x0ab2, 0x2155 }, /* onefifth ⅕ VULGAR FRACTION ONE FIFTH */ - { 0x0ab3, 0x2156 }, /* twofifths ⅖ VULGAR FRACTION TWO FIFTHS */ - { 0x0ab4, 0x2157 }, /* threefifths ⅗ VULGAR FRACTION THREE FIFTHS */ - { 0x0ab5, 0x2158 }, /* fourfifths ⅘ VULGAR FRACTION FOUR FIFTHS */ - { 0x0ab6, 0x2159 }, /* onesixth ⅙ VULGAR FRACTION ONE SIXTH */ - { 0x0ab7, 0x215a }, /* fivesixths ⅚ VULGAR FRACTION FIVE SIXTHS */ - { 0x0ab8, 0x2105 }, /* careof ℅ CARE OF */ - { 0x0abb, 0x2012 }, /* figdash ‒ FIGURE DASH */ - { 0x0abc, 0x2329 }, /* leftanglebracket 〈 LEFT-POINTING ANGLE BRACKET */ - { 0x0abd, 0x002e }, /* decimalpoint . FULL STOP */ - { 0x0abe, 0x232a }, /* rightanglebracket 〉 RIGHT-POINTING ANGLE BRACKET */ -/* 0x0abf marker ? ??? */ - { 0x0ac3, 0x215b }, /* oneeighth ⅛ VULGAR FRACTION ONE EIGHTH */ - { 0x0ac4, 0x215c }, /* threeeighths ⅜ VULGAR FRACTION THREE EIGHTHS */ - { 0x0ac5, 0x215d }, /* fiveeighths ⅝ VULGAR FRACTION FIVE EIGHTHS */ - { 0x0ac6, 0x215e }, /* seveneighths ⅞ VULGAR FRACTION SEVEN EIGHTHS */ - { 0x0ac9, 0x2122 }, /* trademark ™ TRADE MARK SIGN */ - { 0x0aca, 0x2613 }, /* signaturemark ☓ SALTIRE */ -/* 0x0acb trademarkincircle ? ??? */ - { 0x0acc, 0x25c1 }, /* leftopentriangle ◁ WHITE LEFT-POINTING TRIANGLE */ - { 0x0acd, 0x25b7 }, /* rightopentriangle ▷ WHITE RIGHT-POINTING TRIANGLE */ - { 0x0ace, 0x25cb }, /* emopencircle ○ WHITE CIRCLE */ - { 0x0acf, 0x25a1 }, /* emopenrectangle □ WHITE SQUARE */ - { 0x0ad0, 0x2018 }, /* leftsinglequotemark ‘ LEFT SINGLE QUOTATION MARK */ - { 0x0ad1, 0x2019 }, /* rightsinglequotemark ’ RIGHT SINGLE QUOTATION MARK */ - { 0x0ad2, 0x201c }, /* leftdoublequotemark “ LEFT DOUBLE QUOTATION MARK */ - { 0x0ad3, 0x201d }, /* rightdoublequotemark ” RIGHT DOUBLE QUOTATION MARK */ - { 0x0ad4, 0x211e }, /* prescription ℞ PRESCRIPTION TAKE */ - { 0x0ad6, 0x2032 }, /* minutes ′ PRIME */ - { 0x0ad7, 0x2033 }, /* seconds ″ DOUBLE PRIME */ - { 0x0ad9, 0x271d }, /* latincross ✝ LATIN CROSS */ -/* 0x0ada hexagram ? ??? */ - { 0x0adb, 0x25ac }, /* filledrectbullet ▬ BLACK RECTANGLE */ - { 0x0adc, 0x25c0 }, /* filledlefttribullet ◀ BLACK LEFT-POINTING TRIANGLE */ - { 0x0add, 0x25b6 }, /* filledrighttribullet ▶ BLACK RIGHT-POINTING TRIANGLE */ - { 0x0ade, 0x25cf }, /* emfilledcircle ● BLACK CIRCLE */ - { 0x0adf, 0x25a0 }, /* emfilledrect ■ BLACK SQUARE */ - { 0x0ae0, 0x25e6 }, /* enopencircbullet ◦ WHITE BULLET */ - { 0x0ae1, 0x25ab }, /* enopensquarebullet ▫ WHITE SMALL SQUARE */ - { 0x0ae2, 0x25ad }, /* openrectbullet ▭ WHITE RECTANGLE */ - { 0x0ae3, 0x25b3 }, /* opentribulletup △ WHITE UP-POINTING TRIANGLE */ - { 0x0ae4, 0x25bd }, /* opentribulletdown ▽ WHITE DOWN-POINTING TRIANGLE */ - { 0x0ae5, 0x2606 }, /* openstar ☆ WHITE STAR */ - { 0x0ae6, 0x2022 }, /* enfilledcircbullet • BULLET */ - { 0x0ae7, 0x25aa }, /* enfilledsqbullet ▪ BLACK SMALL SQUARE */ - { 0x0ae8, 0x25b2 }, /* filledtribulletup ▲ BLACK UP-POINTING TRIANGLE */ - { 0x0ae9, 0x25bc }, /* filledtribulletdown ▼ BLACK DOWN-POINTING TRIANGLE */ - { 0x0aea, 0x261c }, /* leftpointer ☜ WHITE LEFT POINTING INDEX */ - { 0x0aeb, 0x261e }, /* rightpointer ☞ WHITE RIGHT POINTING INDEX */ - { 0x0aec, 0x2663 }, /* club ♣ BLACK CLUB SUIT */ - { 0x0aed, 0x2666 }, /* diamond ♦ BLACK DIAMOND SUIT */ - { 0x0aee, 0x2665 }, /* heart ♥ BLACK HEART SUIT */ - { 0x0af0, 0x2720 }, /* maltesecross ✠ MALTESE CROSS */ - { 0x0af1, 0x2020 }, /* dagger † DAGGER */ - { 0x0af2, 0x2021 }, /* doubledagger ‡ DOUBLE DAGGER */ - { 0x0af3, 0x2713 }, /* checkmark ✓ CHECK MARK */ - { 0x0af4, 0x2717 }, /* ballotcross ✗ BALLOT X */ - { 0x0af5, 0x266f }, /* musicalsharp ♯ MUSIC SHARP SIGN */ - { 0x0af6, 0x266d }, /* musicalflat ♭ MUSIC FLAT SIGN */ - { 0x0af7, 0x2642 }, /* malesymbol ♂ MALE SIGN */ - { 0x0af8, 0x2640 }, /* femalesymbol ♀ FEMALE SIGN */ - { 0x0af9, 0x260e }, /* telephone ☎ BLACK TELEPHONE */ - { 0x0afa, 0x2315 }, /* telephonerecorder ⌕ TELEPHONE RECORDER */ - { 0x0afb, 0x2117 }, /* phonographcopyright ℗ SOUND RECORDING COPYRIGHT */ - { 0x0afc, 0x2038 }, /* caret ‸ CARET */ - { 0x0afd, 0x201a }, /* singlelowquotemark ‚ SINGLE LOW-9 QUOTATION MARK */ - { 0x0afe, 0x201e }, /* doublelowquotemark „ DOUBLE LOW-9 QUOTATION MARK */ -/* 0x0aff cursor ? ??? */ - { 0x0ba3, 0x003c }, /* leftcaret < LESS-THAN SIGN */ - { 0x0ba6, 0x003e }, /* rightcaret > GREATER-THAN SIGN */ - { 0x0ba8, 0x2228 }, /* downcaret ∨ LOGICAL OR */ - { 0x0ba9, 0x2227 }, /* upcaret ∧ LOGICAL AND */ - { 0x0bc0, 0x00af }, /* overbar ¯ MACRON */ - { 0x0bc2, 0x22a4 }, /* downtack ⊤ DOWN TACK */ - { 0x0bc3, 0x2229 }, /* upshoe ∩ INTERSECTION */ - { 0x0bc4, 0x230a }, /* downstile ⌊ LEFT FLOOR */ - { 0x0bc6, 0x005f }, /* underbar _ LOW LINE */ - { 0x0bca, 0x2218 }, /* jot ∘ RING OPERATOR */ - { 0x0bcc, 0x2395 }, /* quad ⎕ APL FUNCTIONAL SYMBOL QUAD (Unicode 3.0) */ - { 0x0bce, 0x22a5 }, /* uptack ⊥ UP TACK */ - { 0x0bcf, 0x25cb }, /* circle ○ WHITE CIRCLE */ - { 0x0bd3, 0x2308 }, /* upstile ⌈ LEFT CEILING */ - { 0x0bd6, 0x222a }, /* downshoe ∪ UNION */ - { 0x0bd8, 0x2283 }, /* rightshoe ⊃ SUPERSET OF */ - { 0x0bda, 0x2282 }, /* leftshoe ⊂ SUBSET OF */ - { 0x0bdc, 0x22a3 }, /* lefttack ⊣ LEFT TACK */ - { 0x0bfc, 0x22a2 }, /* righttack ⊢ RIGHT TACK */ - { 0x0cdf, 0x2017 }, /* hebrew_doublelowline ‗ DOUBLE LOW LINE */ - { 0x0ce0, 0x05d0 }, /* hebrew_aleph א HEBREW LETTER ALEF */ - { 0x0ce1, 0x05d1 }, /* hebrew_bet ב HEBREW LETTER BET */ - { 0x0ce2, 0x05d2 }, /* hebrew_gimel ג HEBREW LETTER GIMEL */ - { 0x0ce3, 0x05d3 }, /* hebrew_dalet ד HEBREW LETTER DALET */ - { 0x0ce4, 0x05d4 }, /* hebrew_he ה HEBREW LETTER HE */ - { 0x0ce5, 0x05d5 }, /* hebrew_waw ו HEBREW LETTER VAV */ - { 0x0ce6, 0x05d6 }, /* hebrew_zain ז HEBREW LETTER ZAYIN */ - { 0x0ce7, 0x05d7 }, /* hebrew_chet ח HEBREW LETTER HET */ - { 0x0ce8, 0x05d8 }, /* hebrew_tet ט HEBREW LETTER TET */ - { 0x0ce9, 0x05d9 }, /* hebrew_yod י HEBREW LETTER YOD */ - { 0x0cea, 0x05da }, /* hebrew_finalkaph ך HEBREW LETTER FINAL KAF */ - { 0x0ceb, 0x05db }, /* hebrew_kaph כ HEBREW LETTER KAF */ - { 0x0cec, 0x05dc }, /* hebrew_lamed ל HEBREW LETTER LAMED */ - { 0x0ced, 0x05dd }, /* hebrew_finalmem ם HEBREW LETTER FINAL MEM */ - { 0x0cee, 0x05de }, /* hebrew_mem מ HEBREW LETTER MEM */ - { 0x0cef, 0x05df }, /* hebrew_finalnun ן HEBREW LETTER FINAL NUN */ - { 0x0cf0, 0x05e0 }, /* hebrew_nun נ HEBREW LETTER NUN */ - { 0x0cf1, 0x05e1 }, /* hebrew_samech ס HEBREW LETTER SAMEKH */ - { 0x0cf2, 0x05e2 }, /* hebrew_ayin ע HEBREW LETTER AYIN */ - { 0x0cf3, 0x05e3 }, /* hebrew_finalpe ף HEBREW LETTER FINAL PE */ - { 0x0cf4, 0x05e4 }, /* hebrew_pe פ HEBREW LETTER PE */ - { 0x0cf5, 0x05e5 }, /* hebrew_finalzade ץ HEBREW LETTER FINAL TSADI */ - { 0x0cf6, 0x05e6 }, /* hebrew_zade צ HEBREW LETTER TSADI */ - { 0x0cf7, 0x05e7 }, /* hebrew_qoph ק HEBREW LETTER QOF */ - { 0x0cf8, 0x05e8 }, /* hebrew_resh ר HEBREW LETTER RESH */ - { 0x0cf9, 0x05e9 }, /* hebrew_shin ש HEBREW LETTER SHIN */ - { 0x0cfa, 0x05ea }, /* hebrew_taw ת HEBREW LETTER TAV */ - { 0x0da1, 0x0e01 }, /* Thai_kokai ก THAI CHARACTER KO KAI */ - { 0x0da2, 0x0e02 }, /* Thai_khokhai ข THAI CHARACTER KHO KHAI */ - { 0x0da3, 0x0e03 }, /* Thai_khokhuat ฃ THAI CHARACTER KHO KHUAT */ - { 0x0da4, 0x0e04 }, /* Thai_khokhwai ค THAI CHARACTER KHO KHWAI */ - { 0x0da5, 0x0e05 }, /* Thai_khokhon ฅ THAI CHARACTER KHO KHON */ - { 0x0da6, 0x0e06 }, /* Thai_khorakhang ฆ THAI CHARACTER KHO RAKHANG */ - { 0x0da7, 0x0e07 }, /* Thai_ngongu ง THAI CHARACTER NGO NGU */ - { 0x0da8, 0x0e08 }, /* Thai_chochan จ THAI CHARACTER CHO CHAN */ - { 0x0da9, 0x0e09 }, /* Thai_choching ฉ THAI CHARACTER CHO CHING */ - { 0x0daa, 0x0e0a }, /* Thai_chochang ช THAI CHARACTER CHO CHANG */ - { 0x0dab, 0x0e0b }, /* Thai_soso ซ THAI CHARACTER SO SO */ - { 0x0dac, 0x0e0c }, /* Thai_chochoe ฌ THAI CHARACTER CHO CHOE */ - { 0x0dad, 0x0e0d }, /* Thai_yoying ญ THAI CHARACTER YO YING */ - { 0x0dae, 0x0e0e }, /* Thai_dochada ฎ THAI CHARACTER DO CHADA */ - { 0x0daf, 0x0e0f }, /* Thai_topatak ฏ THAI CHARACTER TO PATAK */ - { 0x0db0, 0x0e10 }, /* Thai_thothan ฐ THAI CHARACTER THO THAN */ - { 0x0db1, 0x0e11 }, /* Thai_thonangmontho ฑ THAI CHARACTER THO NANGMONTHO */ - { 0x0db2, 0x0e12 }, /* Thai_thophuthao ฒ THAI CHARACTER THO PHUTHAO */ - { 0x0db3, 0x0e13 }, /* Thai_nonen ณ THAI CHARACTER NO NEN */ - { 0x0db4, 0x0e14 }, /* Thai_dodek ด THAI CHARACTER DO DEK */ - { 0x0db5, 0x0e15 }, /* Thai_totao ต THAI CHARACTER TO TAO */ - { 0x0db6, 0x0e16 }, /* Thai_thothung ถ THAI CHARACTER THO THUNG */ - { 0x0db7, 0x0e17 }, /* Thai_thothahan ท THAI CHARACTER THO THAHAN */ - { 0x0db8, 0x0e18 }, /* Thai_thothong ธ THAI CHARACTER THO THONG */ - { 0x0db9, 0x0e19 }, /* Thai_nonu น THAI CHARACTER NO NU */ - { 0x0dba, 0x0e1a }, /* Thai_bobaimai บ THAI CHARACTER BO BAIMAI */ - { 0x0dbb, 0x0e1b }, /* Thai_popla ป THAI CHARACTER PO PLA */ - { 0x0dbc, 0x0e1c }, /* Thai_phophung ผ THAI CHARACTER PHO PHUNG */ - { 0x0dbd, 0x0e1d }, /* Thai_fofa ฝ THAI CHARACTER FO FA */ - { 0x0dbe, 0x0e1e }, /* Thai_phophan พ THAI CHARACTER PHO PHAN */ - { 0x0dbf, 0x0e1f }, /* Thai_fofan ฟ THAI CHARACTER FO FAN */ - { 0x0dc0, 0x0e20 }, /* Thai_phosamphao ภ THAI CHARACTER PHO SAMPHAO */ - { 0x0dc1, 0x0e21 }, /* Thai_moma ม THAI CHARACTER MO MA */ - { 0x0dc2, 0x0e22 }, /* Thai_yoyak ย THAI CHARACTER YO YAK */ - { 0x0dc3, 0x0e23 }, /* Thai_rorua ร THAI CHARACTER RO RUA */ - { 0x0dc4, 0x0e24 }, /* Thai_ru ฤ THAI CHARACTER RU */ - { 0x0dc5, 0x0e25 }, /* Thai_loling ล THAI CHARACTER LO LING */ - { 0x0dc6, 0x0e26 }, /* Thai_lu ฦ THAI CHARACTER LU */ - { 0x0dc7, 0x0e27 }, /* Thai_wowaen ว THAI CHARACTER WO WAEN */ - { 0x0dc8, 0x0e28 }, /* Thai_sosala ศ THAI CHARACTER SO SALA */ - { 0x0dc9, 0x0e29 }, /* Thai_sorusi ษ THAI CHARACTER SO RUSI */ - { 0x0dca, 0x0e2a }, /* Thai_sosua ส THAI CHARACTER SO SUA */ - { 0x0dcb, 0x0e2b }, /* Thai_hohip ห THAI CHARACTER HO HIP */ - { 0x0dcc, 0x0e2c }, /* Thai_lochula ฬ THAI CHARACTER LO CHULA */ - { 0x0dcd, 0x0e2d }, /* Thai_oang อ THAI CHARACTER O ANG */ - { 0x0dce, 0x0e2e }, /* Thai_honokhuk ฮ THAI CHARACTER HO NOKHUK */ - { 0x0dcf, 0x0e2f }, /* Thai_paiyannoi ฯ THAI CHARACTER PAIYANNOI */ - { 0x0dd0, 0x0e30 }, /* Thai_saraa ะ THAI CHARACTER SARA A */ - { 0x0dd1, 0x0e31 }, /* Thai_maihanakat ั THAI CHARACTER MAI HAN-AKAT */ - { 0x0dd2, 0x0e32 }, /* Thai_saraaa า THAI CHARACTER SARA AA */ - { 0x0dd3, 0x0e33 }, /* Thai_saraam ำ THAI CHARACTER SARA AM */ - { 0x0dd4, 0x0e34 }, /* Thai_sarai ิ THAI CHARACTER SARA I */ - { 0x0dd5, 0x0e35 }, /* Thai_saraii ี THAI CHARACTER SARA II */ - { 0x0dd6, 0x0e36 }, /* Thai_saraue ึ THAI CHARACTER SARA UE */ - { 0x0dd7, 0x0e37 }, /* Thai_sarauee ื THAI CHARACTER SARA UEE */ - { 0x0dd8, 0x0e38 }, /* Thai_sarau ุ THAI CHARACTER SARA U */ - { 0x0dd9, 0x0e39 }, /* Thai_sarauu ู THAI CHARACTER SARA UU */ - { 0x0dda, 0x0e3a }, /* Thai_phinthu ฺ THAI CHARACTER PHINTHU */ - { 0x0dde, 0x0e3e }, /* Thai_maihanakat_maitho ฾ ??? */ - { 0x0ddf, 0x0e3f }, /* Thai_baht ฿ THAI CURRENCY SYMBOL BAHT */ - { 0x0de0, 0x0e40 }, /* Thai_sarae เ THAI CHARACTER SARA E */ - { 0x0de1, 0x0e41 }, /* Thai_saraae แ THAI CHARACTER SARA AE */ - { 0x0de2, 0x0e42 }, /* Thai_sarao โ THAI CHARACTER SARA O */ - { 0x0de3, 0x0e43 }, /* Thai_saraaimaimuan ใ THAI CHARACTER SARA AI MAIMUAN */ - { 0x0de4, 0x0e44 }, /* Thai_saraaimaimalai ไ THAI CHARACTER SARA AI MAIMALAI */ - { 0x0de5, 0x0e45 }, /* Thai_lakkhangyao ๅ THAI CHARACTER LAKKHANGYAO */ - { 0x0de6, 0x0e46 }, /* Thai_maiyamok ๆ THAI CHARACTER MAIYAMOK */ - { 0x0de7, 0x0e47 }, /* Thai_maitaikhu ็ THAI CHARACTER MAITAIKHU */ - { 0x0de8, 0x0e48 }, /* Thai_maiek ่ THAI CHARACTER MAI EK */ - { 0x0de9, 0x0e49 }, /* Thai_maitho ้ THAI CHARACTER MAI THO */ - { 0x0dea, 0x0e4a }, /* Thai_maitri ๊ THAI CHARACTER MAI TRI */ - { 0x0deb, 0x0e4b }, /* Thai_maichattawa ๋ THAI CHARACTER MAI CHATTAWA */ - { 0x0dec, 0x0e4c }, /* Thai_thanthakhat ์ THAI CHARACTER THANTHAKHAT */ - { 0x0ded, 0x0e4d }, /* Thai_nikhahit ํ THAI CHARACTER NIKHAHIT */ - { 0x0df0, 0x0e50 }, /* Thai_leksun ๐ THAI DIGIT ZERO */ - { 0x0df1, 0x0e51 }, /* Thai_leknung ๑ THAI DIGIT ONE */ - { 0x0df2, 0x0e52 }, /* Thai_leksong ๒ THAI DIGIT TWO */ - { 0x0df3, 0x0e53 }, /* Thai_leksam ๓ THAI DIGIT THREE */ - { 0x0df4, 0x0e54 }, /* Thai_leksi ๔ THAI DIGIT FOUR */ - { 0x0df5, 0x0e55 }, /* Thai_lekha ๕ THAI DIGIT FIVE */ - { 0x0df6, 0x0e56 }, /* Thai_lekhok ๖ THAI DIGIT SIX */ - { 0x0df7, 0x0e57 }, /* Thai_lekchet ๗ THAI DIGIT SEVEN */ - { 0x0df8, 0x0e58 }, /* Thai_lekpaet ๘ THAI DIGIT EIGHT */ - { 0x0df9, 0x0e59 }, /* Thai_lekkao ๙ THAI DIGIT NINE */ - { 0x0ea1, 0x3131 }, /* Hangul_Kiyeog ㄱ HANGUL LETTER KIYEOK */ - { 0x0ea2, 0x3132 }, /* Hangul_SsangKiyeog ㄲ HANGUL LETTER SSANGKIYEOK */ - { 0x0ea3, 0x3133 }, /* Hangul_KiyeogSios ㄳ HANGUL LETTER KIYEOK-SIOS */ - { 0x0ea4, 0x3134 }, /* Hangul_Nieun ㄴ HANGUL LETTER NIEUN */ - { 0x0ea5, 0x3135 }, /* Hangul_NieunJieuj ㄵ HANGUL LETTER NIEUN-CIEUC */ - { 0x0ea6, 0x3136 }, /* Hangul_NieunHieuh ㄶ HANGUL LETTER NIEUN-HIEUH */ - { 0x0ea7, 0x3137 }, /* Hangul_Dikeud ㄷ HANGUL LETTER TIKEUT */ - { 0x0ea8, 0x3138 }, /* Hangul_SsangDikeud ㄸ HANGUL LETTER SSANGTIKEUT */ - { 0x0ea9, 0x3139 }, /* Hangul_Rieul ㄹ HANGUL LETTER RIEUL */ - { 0x0eaa, 0x313a }, /* Hangul_RieulKiyeog ㄺ HANGUL LETTER RIEUL-KIYEOK */ - { 0x0eab, 0x313b }, /* Hangul_RieulMieum ㄻ HANGUL LETTER RIEUL-MIEUM */ - { 0x0eac, 0x313c }, /* Hangul_RieulPieub ㄼ HANGUL LETTER RIEUL-PIEUP */ - { 0x0ead, 0x313d }, /* Hangul_RieulSios ㄽ HANGUL LETTER RIEUL-SIOS */ - { 0x0eae, 0x313e }, /* Hangul_RieulTieut ㄾ HANGUL LETTER RIEUL-THIEUTH */ - { 0x0eaf, 0x313f }, /* Hangul_RieulPhieuf ㄿ HANGUL LETTER RIEUL-PHIEUPH */ - { 0x0eb0, 0x3140 }, /* Hangul_RieulHieuh ㅀ HANGUL LETTER RIEUL-HIEUH */ - { 0x0eb1, 0x3141 }, /* Hangul_Mieum ㅁ HANGUL LETTER MIEUM */ - { 0x0eb2, 0x3142 }, /* Hangul_Pieub ㅂ HANGUL LETTER PIEUP */ - { 0x0eb3, 0x3143 }, /* Hangul_SsangPieub ㅃ HANGUL LETTER SSANGPIEUP */ - { 0x0eb4, 0x3144 }, /* Hangul_PieubSios ㅄ HANGUL LETTER PIEUP-SIOS */ - { 0x0eb5, 0x3145 }, /* Hangul_Sios ㅅ HANGUL LETTER SIOS */ - { 0x0eb6, 0x3146 }, /* Hangul_SsangSios ㅆ HANGUL LETTER SSANGSIOS */ - { 0x0eb7, 0x3147 }, /* Hangul_Ieung ㅇ HANGUL LETTER IEUNG */ - { 0x0eb8, 0x3148 }, /* Hangul_Jieuj ㅈ HANGUL LETTER CIEUC */ - { 0x0eb9, 0x3149 }, /* Hangul_SsangJieuj ㅉ HANGUL LETTER SSANGCIEUC */ - { 0x0eba, 0x314a }, /* Hangul_Cieuc ㅊ HANGUL LETTER CHIEUCH */ - { 0x0ebb, 0x314b }, /* Hangul_Khieuq ㅋ HANGUL LETTER KHIEUKH */ - { 0x0ebc, 0x314c }, /* Hangul_Tieut ㅌ HANGUL LETTER THIEUTH */ - { 0x0ebd, 0x314d }, /* Hangul_Phieuf ㅍ HANGUL LETTER PHIEUPH */ - { 0x0ebe, 0x314e }, /* Hangul_Hieuh ㅎ HANGUL LETTER HIEUH */ - { 0x0ebf, 0x314f }, /* Hangul_A ㅏ HANGUL LETTER A */ - { 0x0ec0, 0x3150 }, /* Hangul_AE ㅐ HANGUL LETTER AE */ - { 0x0ec1, 0x3151 }, /* Hangul_YA ㅑ HANGUL LETTER YA */ - { 0x0ec2, 0x3152 }, /* Hangul_YAE ㅒ HANGUL LETTER YAE */ - { 0x0ec3, 0x3153 }, /* Hangul_EO ㅓ HANGUL LETTER EO */ - { 0x0ec4, 0x3154 }, /* Hangul_E ㅔ HANGUL LETTER E */ - { 0x0ec5, 0x3155 }, /* Hangul_YEO ㅕ HANGUL LETTER YEO */ - { 0x0ec6, 0x3156 }, /* Hangul_YE ㅖ HANGUL LETTER YE */ - { 0x0ec7, 0x3157 }, /* Hangul_O ㅗ HANGUL LETTER O */ - { 0x0ec8, 0x3158 }, /* Hangul_WA ㅘ HANGUL LETTER WA */ - { 0x0ec9, 0x3159 }, /* Hangul_WAE ㅙ HANGUL LETTER WAE */ - { 0x0eca, 0x315a }, /* Hangul_OE ㅚ HANGUL LETTER OE */ - { 0x0ecb, 0x315b }, /* Hangul_YO ㅛ HANGUL LETTER YO */ - { 0x0ecc, 0x315c }, /* Hangul_U ㅜ HANGUL LETTER U */ - { 0x0ecd, 0x315d }, /* Hangul_WEO ㅝ HANGUL LETTER WEO */ - { 0x0ece, 0x315e }, /* Hangul_WE ㅞ HANGUL LETTER WE */ - { 0x0ecf, 0x315f }, /* Hangul_WI ㅟ HANGUL LETTER WI */ - { 0x0ed0, 0x3160 }, /* Hangul_YU ㅠ HANGUL LETTER YU */ - { 0x0ed1, 0x3161 }, /* Hangul_EU ㅡ HANGUL LETTER EU */ - { 0x0ed2, 0x3162 }, /* Hangul_YI ㅢ HANGUL LETTER YI */ - { 0x0ed3, 0x3163 }, /* Hangul_I ㅣ HANGUL LETTER I */ - { 0x0ed4, 0x11a8 }, /* Hangul_J_Kiyeog ᆨ HANGUL JONGSEONG KIYEOK */ - { 0x0ed5, 0x11a9 }, /* Hangul_J_SsangKiyeog ᆩ HANGUL JONGSEONG SSANGKIYEOK */ - { 0x0ed6, 0x11aa }, /* Hangul_J_KiyeogSios ᆪ HANGUL JONGSEONG KIYEOK-SIOS */ - { 0x0ed7, 0x11ab }, /* Hangul_J_Nieun ᆫ HANGUL JONGSEONG NIEUN */ - { 0x0ed8, 0x11ac }, /* Hangul_J_NieunJieuj ᆬ HANGUL JONGSEONG NIEUN-CIEUC */ - { 0x0ed9, 0x11ad }, /* Hangul_J_NieunHieuh ᆭ HANGUL JONGSEONG NIEUN-HIEUH */ - { 0x0eda, 0x11ae }, /* Hangul_J_Dikeud ᆮ HANGUL JONGSEONG TIKEUT */ - { 0x0edb, 0x11af }, /* Hangul_J_Rieul ᆯ HANGUL JONGSEONG RIEUL */ - { 0x0edc, 0x11b0 }, /* Hangul_J_RieulKiyeog ᆰ HANGUL JONGSEONG RIEUL-KIYEOK */ - { 0x0edd, 0x11b1 }, /* Hangul_J_RieulMieum ᆱ HANGUL JONGSEONG RIEUL-MIEUM */ - { 0x0ede, 0x11b2 }, /* Hangul_J_RieulPieub ᆲ HANGUL JONGSEONG RIEUL-PIEUP */ - { 0x0edf, 0x11b3 }, /* Hangul_J_RieulSios ᆳ HANGUL JONGSEONG RIEUL-SIOS */ - { 0x0ee0, 0x11b4 }, /* Hangul_J_RieulTieut ᆴ HANGUL JONGSEONG RIEUL-THIEUTH */ - { 0x0ee1, 0x11b5 }, /* Hangul_J_RieulPhieuf ᆵ HANGUL JONGSEONG RIEUL-PHIEUPH */ - { 0x0ee2, 0x11b6 }, /* Hangul_J_RieulHieuh ᆶ HANGUL JONGSEONG RIEUL-HIEUH */ - { 0x0ee3, 0x11b7 }, /* Hangul_J_Mieum ᆷ HANGUL JONGSEONG MIEUM */ - { 0x0ee4, 0x11b8 }, /* Hangul_J_Pieub ᆸ HANGUL JONGSEONG PIEUP */ - { 0x0ee5, 0x11b9 }, /* Hangul_J_PieubSios ᆹ HANGUL JONGSEONG PIEUP-SIOS */ - { 0x0ee6, 0x11ba }, /* Hangul_J_Sios ᆺ HANGUL JONGSEONG SIOS */ - { 0x0ee7, 0x11bb }, /* Hangul_J_SsangSios ᆻ HANGUL JONGSEONG SSANGSIOS */ - { 0x0ee8, 0x11bc }, /* Hangul_J_Ieung ᆼ HANGUL JONGSEONG IEUNG */ - { 0x0ee9, 0x11bd }, /* Hangul_J_Jieuj ᆽ HANGUL JONGSEONG CIEUC */ - { 0x0eea, 0x11be }, /* Hangul_J_Cieuc ᆾ HANGUL JONGSEONG CHIEUCH */ - { 0x0eeb, 0x11bf }, /* Hangul_J_Khieuq ᆿ HANGUL JONGSEONG KHIEUKH */ - { 0x0eec, 0x11c0 }, /* Hangul_J_Tieut ᇀ HANGUL JONGSEONG THIEUTH */ - { 0x0eed, 0x11c1 }, /* Hangul_J_Phieuf ᇁ HANGUL JONGSEONG PHIEUPH */ - { 0x0eee, 0x11c2 }, /* Hangul_J_Hieuh ᇂ HANGUL JONGSEONG HIEUH */ - { 0x0eef, 0x316d }, /* Hangul_RieulYeorinHieuh ㅭ HANGUL LETTER RIEUL-YEORINHIEUH */ - { 0x0ef0, 0x3171 }, /* Hangul_SunkyeongeumMieum ㅱ HANGUL LETTER KAPYEOUNMIEUM */ - { 0x0ef1, 0x3178 }, /* Hangul_SunkyeongeumPieub ㅸ HANGUL LETTER KAPYEOUNPIEUP */ - { 0x0ef2, 0x317f }, /* Hangul_PanSios ㅿ HANGUL LETTER PANSIOS */ -/* 0x0ef3 Hangul_KkogjiDalrinIeung ? ??? */ - { 0x0ef4, 0x3184 }, /* Hangul_SunkyeongeumPhieuf ㆄ HANGUL LETTER KAPYEOUNPHIEUPH */ - { 0x0ef5, 0x3186 }, /* Hangul_YeorinHieuh ㆆ HANGUL LETTER YEORINHIEUH */ - { 0x0ef6, 0x318d }, /* Hangul_AraeA ㆍ HANGUL LETTER ARAEA */ - { 0x0ef7, 0x318e }, /* Hangul_AraeAE ㆎ HANGUL LETTER ARAEAE */ - { 0x0ef8, 0x11eb }, /* Hangul_J_PanSios ᇫ HANGUL JONGSEONG PANSIOS */ -/* 0x0ef9 Hangul_J_KkogjiDalrinIeung ? ??? */ - { 0x0efa, 0x11f9 }, /* Hangul_J_YeorinHieuh ᇹ HANGUL JONGSEONG YEORINHIEUH */ - { 0x0eff, 0x20a9 }, /* Korean_Won ₩ WON SIGN */ - { 0x13bc, 0x0152 }, /* OE Œ LATIN CAPITAL LIGATURE OE */ - { 0x13bd, 0x0153 }, /* oe œ LATIN SMALL LIGATURE OE */ - { 0x13be, 0x0178 }, /* Ydiaeresis Ÿ LATIN CAPITAL LETTER Y WITH DIAERESIS */ - { 0x20a0, 0x20a0 }, /* EcuSign ₠ EURO-CURRENCY SIGN */ - { 0x20a1, 0x20a1 }, /* ColonSign ₡ COLON SIGN */ - { 0x20a2, 0x20a2 }, /* CruzeiroSign ₢ CRUZEIRO SIGN */ - { 0x20a3, 0x20a3 }, /* FFrancSign ₣ FRENCH FRANC SIGN */ - { 0x20a4, 0x20a4 }, /* LiraSign ₤ LIRA SIGN */ - { 0x20a5, 0x20a5 }, /* MillSign ₥ MILL SIGN */ - { 0x20a6, 0x20a6 }, /* NairaSign ₦ NAIRA SIGN */ - { 0x20a7, 0x20a7 }, /* PesetaSign ₧ PESETA SIGN */ - { 0x20a8, 0x20a8 }, /* RupeeSign ₨ RUPEE SIGN */ - { 0x20a9, 0x20a9 }, /* WonSign ₩ WON SIGN */ - { 0x20aa, 0x20aa }, /* NewSheqelSign ₪ NEW SHEQEL SIGN */ - { 0x20ab, 0x20ab }, /* DongSign ₫ DONG SIGN */ - { 0x20ac, 0x20ac }, /* EuroSign € EURO SIGN */ -}; - -long keysym2ucs(KeySym keysym) -{ - int min = 0; - int max = sizeof(keysymtab) / sizeof(struct codepair) - 1; - int mid; - - /* first check for Latin-1 characters (1:1 mapping) */ - if ((keysym >= 0x0020 && keysym <= 0x007e) || - (keysym >= 0x00a0 && keysym <= 0x00ff)) - return keysym; - - /* also check for directly encoded 24-bit UCS characters */ - if ((keysym & 0xff000000) == 0x01000000) - return keysym & 0x00ffffff; - - /* binary search in table */ - while (max >= min) { - mid = (min + max) / 2; - if (keysymtab[mid].keysym < keysym) - min = mid + 1; - else if (keysymtab[mid].keysym > keysym) - max = mid - 1; - else { - /* found it */ - return keysymtab[mid].ucs; - } - } - - /* no matching Unicode value found */ - return -1; -} diff --git a/mozilla/widget/src/gtk/keysym2ucs.h b/mozilla/widget/src/gtk/keysym2ucs.h deleted file mode 100644 index 6fc23d26184..00000000000 --- a/mozilla/widget/src/gtk/keysym2ucs.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is from xterm-122 source XFree86: - * xc/programs/xterm/keysym2ucs.h,v 1.1 1999/06/12 15:37:18 dawes Exp. - * - * The Initial Developer of the Original Code is - * Markus G. Kuhn and Richard Verhoeven . - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Frank Tang adopt into mozilla - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -/* - * This module converts keysym values into the corresponding ISO 10646-1 - * (UCS, Unicode) values. - */ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -long keysym2ucs(KeySym keysym); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - - - diff --git a/mozilla/widget/src/gtk/mozicon.xpm b/mozilla/widget/src/gtk/mozicon.xpm deleted file mode 100644 index 0b1bb10ec32..00000000000 --- a/mozilla/widget/src/gtk/mozicon.xpm +++ /dev/null @@ -1,292 +0,0 @@ -/* XPM */ -static char * mozilla_icon_xpm[] = { -"32 32 257 2", -" c None", -". c #AA7303", -"+ c #A67003", -"@ c #B77C03", -"# c #8D6003", -"$ c #8D6004", -"% c #6C4A04", -"& c #3A2804", -"* c #6B4802", -"= c #9B6903", -"- c #5A2C04", -"; c #411B04", -"> c #9D6A03", -", c #7A5203", -"' c #510D04", -") c #6B1104", -"! c #7D5503", -"~ c #674604", -"{ c #C21E04", -"] c #C21D04", -"^ c #523804", -"/ c #513702", -"( c #552904", -"_ c #DD2204", -": c #DF2204", -"< c #582904", -"[ c #5F3F02", -"} c #6B2504", -"| c #FE2604", -"1 c #AB7303", -"2 c #9B6904", -"3 c #C31F04", -"4 c #FE2704", -"5 c #A81904", -"6 c #926304", -"7 c #4D3302", -"8 c #483104", -"9 c #C61E04", -"0 c #B11B04", -"a c #891604", -"b c #761204", -"c c #614304", -"d c #775102", -"e c #795102", -"f c #785102", -"g c #C58603", -"h c #642404", -"i c #B21A04", -"j c #1F0604", -"k c #550E04", -"l c #631004", -"m c #402404", -"n c #AF7703", -"o c #3D2902", -"p c #7F5602", -"q c #805604", -"r c #0C0904", -"s c #080604", -"t c #080706", -"u c #090604", -"v c #060404", -"w c #620F04", -"x c #7A1304", -"y c #030204", -"z c #570E04", -"A c #721204", -"B c #270704", -"C c #080504", -"D c #0A0604", -"E c #533804", -"F c #A56F02", -"G c #B87C03", -"H c #3B2804", -"I c #A51904", -"J c #FC2704", -"K c #D62004", -"L c #691004", -"M c #C01E04", -"N c #6D1004", -"O c #9C1804", -"P c #B31C04", -"Q c #150404", -"R c #801404", -"S c #DD2304", -"T c #120404", -"U c #130404", -"V c #500C04", -"W c #CC1E04", -"X c #AA1A04", -"Y c #100904", -"Z c #B47A03", -"` c #A77103", -" . c #513704", -".. c #891704", -"+. c #F62604", -"@. c #BA1D04", -"#. c #3C0A04", -"$. c #EB2304", -"%. c #DE2304", -"&. c #560E04", -"*. c #E82304", -"=. c #FE2804", -"-. c #BE1D04", -";. c #F12404", -">. c #661004", -",. c #020204", -"'. c #5E0F04", -"). c #A61A04", -"!. c #4A3204", -"~. c #BC7E03", -"{. c #8E6002", -"]. c #684604", -"^. c #390D04", -"/. c #EE2404", -"(. c #FE2904", -"_. c #7D1304", -":. c #8C1504", -"<. c #200604", -"[. c #A81A04", -"}. c #E72204", -"|. c #DA2004", -"1. c #070204", -"2. c #280704", -"3. c #543904", -"4. c #9F6C02", -"5. c #674602", -"6. c #B47B04", -"7. c #311004", -"8. c #B11C04", -"9. c #AA1B04", -"0. c #6A1104", -"a. c #801504", -"b. c #2B0704", -"c. c #09090A", -"d. c #450B04", -"e. c #360904", -"f. c #DC2204", -"g. c #EE2504", -"h. c #C11D04", -"i. c #6F1104", -"j. c #704B04", -"k. c #9C6902", -"l. c #A56F03", -"m. c #5F4004", -"n. c #8D1604", -"o. c #440A04", -"p. c #1A0504", -"q. c #931604", -"r. c #621004", -"s. c #7F1404", -"t. c #921704", -"u. c #F82504", -"v. c #F52504", -"w. c #981804", -"x. c #241804", -"y. c #5B3E04", -"z. c #D82204", -"A. c #D02004", -"B. c #DA2104", -"C. c #D52104", -"D. c #2A1A04", -"E. c #AC7403", -"F. c #2B1C04", -"G. c #D04004", -"H. c #FC3C04", -"I. c #F94E04", -"J. c #881504", -"K. c #FC2604", -"L. c #792804", -"M. c #AC7503", -"N. c #9A6803", -"O. c #782804", -"P. c #F66504", -"Q. c #F94B04", -"R. c #F46804", -"S. c #F46604", -"T. c #F76504", -"U. c #FB4204", -"V. c #C13D04", -"W. c #5D0E04", -"X. c #DA2204", -"Y. c #741604", -"Z. c #8C5E03", -"`. c #885B03", -" + c #8B1904", -".+ c #DE2204", -"++ c #D22D04", -"@+ c #C42D04", -"#+ c #580E04", -"$+ c #9F1804", -"%+ c #895D04", -"&+ c #D62204", -"*+ c #371904", -"=+ c #2C1A04", -"-+ c #4A0C04", -";+ c #140404", -">+ c #AB1A04", -",+ c #DA2304", -"'+ c #6A4702", -")+ c #754F02", -"!+ c #821404", -"~+ c #462B04", -"{+ c #B37A03", -"]+ c #B17803", -"^+ c #714C04", -"/+ c #580F04", -"(+ c #E32204", -"_+ c #DD2104", -":+ c #611D04", -"<+ c #BA7F03", -"[+ c #B27803", -"}+ c #6F1D04", -"|+ c #FD2704", -"1+ c #F22504", -"2+ c #634304", -"3+ c #875B03", -"4+ c #734F02", -"5+ c #805704", -"6+ c #1D0504", -"7+ c #DB2204", -"8+ c #EA2404", -"9+ c #2E0804", -"0+ c #815803", -"a+ c #941704", -"b+ c #C11E04", -"c+ c #391B04", -"d+ c #A77104", -"e+ c #B67C04", -"f+ c #371D04", -"g+ c #360A04", -"h+ c #573A04", -"i+ c #372604", -"j+ c #3E2104", -"k+ c #B57A03", -"l+ c #B57B03", -"m+ c #603F04", -"n+ c #430A04", -"o+ c #351904", -"p+ c #A36E03", -"q+ c #BE8103", -"r+ c #1D1404", -"s+ c #483004", -"t+ c #A26E03", -"u+ c #6D4B02", -"v+ c #825804", -"w+ c #0B0804", -"x+ c #976603", -"y+ c #815703", -"z+ c #926404", -"A+ c #895D03", -"B+ c #614202", -"C+ c #9A6804", -"D+ c #C88704", -"E+ c #C18303", -"F+ c #654302", -"G+ c #744F02", -"H+ c #704B02", -" ", -" . ", -" + @ ", -" # $ ", -" % & * ", -" = - ; > ", -" , ' ) ! ", -" ~ { ] ^ ", -" / ( _ : < [ ", -" . } | | } 1 ", -" 2 3 | 4 5 6 ", -" 7 8 9 0 a b c ", -" d e f f f d d d d d d g h i j k l m n d d d d d d d d d d d o ", -" p q r s s s s t s s u v w x y z A B C D D D D D s s s s E F ", -" G H I J 4 | 4 | K L L M N O P Q R | S T U V W X Y Z ", -" ` ...+.| 4 @.#.$.4 | %.&.*.4 =.-.;.>.,.'.).!.~. ", -" {.].^./.(.X _.;.| :.T <.[.| }.z | |.1.2.3.4. ", -" 5.6.7.8.9.0.a.b.c.d.e.f.g.h.&.| i.u j.k. ", -" l.m.n.o.p.q._.r.a.s.t.u.v.w.x.Z ", -" {.y.P z.R A.v.x j B.| C.D.E. ", -" F.G.H.I.4 | 4 t.J.f.K.L.M. ", -" N.O.P.Q.R.S.T.U.V.W.X.4 Y.Z. ", -" `. +4 =.| | .+++@+#+$+| K %+ ", -" %+&+| | | I *+=+-+;+>+,+&+x.'+ ", -" )+=+X.=.| !+~+{+]+^+,./+(+_+:+<+ ", -" [+}+|+1+) 2+3+ 4+5+6+7+8+9+0+ ", -" $ a+b+c+d+ e+f+0.g+h+ ", -" i+A j+k+ l+m+n+o+p+ ", -" q+r+s+t+ u+v+w+x+ ", -" y+z+A+ B+C+2 ", -" D+ E+F+ ", -" G+ H+ "}; diff --git a/mozilla/widget/src/gtk/mozicon16.xpm b/mozilla/widget/src/gtk/mozicon16.xpm deleted file mode 100644 index ce8fecaa3f8..00000000000 --- a/mozilla/widget/src/gtk/mozicon16.xpm +++ /dev/null @@ -1,105 +0,0 @@ -/* XPM */ -static char * minimozicon_xpm[] = { -"16 16 86 1", -" c None", -". c #9A6803", -"+ c #A26E04", -"@ c #764A04", -"# c #613D03", -"$ c #7D3104", -"% c #7F2F04", -"& c #7E5502", -"* c #A72604", -"= c #A82604", -"- c #855902", -"; c #654403", -"> c #CE2004", -", c #A91A04", -"' c #7A5304", -") c #7B5402", -"! c #5F4003", -"~ c #402C03", -"{ c #402C04", -"] c #642F04", -"^ c #540D04", -"/ c #601004", -"( c #482A04", -"_ c #523803", -": c #734E02", -"< c #763A04", -"[ c #DE2304", -"} c #FE2604", -"| c #B21B04", -"1 c #AF1A04", -"2 c #C21E04", -"3 c #A31904", -"4 c #A41A04", -"5 c #E22204", -"6 c #230604", -"7 c #881504", -"8 c #703504", -"9 c #6F4504", -"0 c #B41E04", -"a c #8F1604", -"b c #A61A04", -"c c #3B0B06", -"d c #761304", -"e c #E52204", -"f c #AA1A04", -"g c #560E04", -"h c #623D04", -"i c #865A03", -"j c #781E04", -"k c #811404", -"l c #661004", -"m c #D82104", -"n c #A31E04", -"o c #815703", -"p c #9A3A04", -"q c #F84F04", -"r c #FA4604", -"s c #D32F04", -"t c #A71A04", -"u c #BA2304", -"v c #9C6A03", -"w c #885C04", -"x c #D72204", -"y c #AE1E04", -"z c #832004", -"A c #6E1104", -"B c #E12304", -"C c #5D3F03", -"D c #704003", -"E c #F22604", -"F c #942404", -"G c #805503", -"H c #875C03", -"I c #3E1B04", -"J c #E12204", -"K c #723F04", -"L c #722C04", -"M c #7B3504", -"N c #6E3A04", -"O c #411A04", -"P c #A06C03", -"Q c #604104", -"R c #624204", -"S c #996804", -"T c #9E6B03", -"U c #875B02", -" ", -" .+ ", -" @# ", -" $% ", -" &*=- ", -" ;>,' ", -")!~~{~]^/(~~~~_:", -" <[}|12345678 ", -" 90abcdefgh ", -" ijk,lmno ", -" pqrstuv ", -" wx}yzABC ", -" DEFGHIJK ", -" LM NO ", -" PQ RS ", -" T U "}; diff --git a/mozilla/widget/src/gtk/mozicon50.xpm b/mozilla/widget/src/gtk/mozicon50.xpm deleted file mode 100644 index 449317632ce..00000000000 --- a/mozilla/widget/src/gtk/mozicon50.xpm +++ /dev/null @@ -1,63 +0,0 @@ -/* XPM */ -static char * mozicon50_xpm[] = { -"50 51 9 1", -" c None", -". c #000000", -"+ c #FF0000", -"@ c #808000", -"# c #800000", -"$ c #FF6633", -"% c #990066", -"& c #FF00FF", -"* c #222222", -" ", -" @ ", -" $@ ", -" @@ ", -" @@$ ", -" $@*@ ", -" @@.@ ", -" @..@ ", -" $@..@@ ", -" $@##*@ ", -" @*#+.@ ", -" @.++.@$ ", -" $@.++.@$ ", -" @*#++#*@ ", -" @.++++.@ ", -" $@.++++.@$ ", -" @*#++++**@ ", -" @.#++++#.@ ", -" $@.++####.@ ", -" @@*+#*##*.@@ ", -"*@@@@@@@@@@@@@@@@@@@.#+..*##*#@@@@@@@@@@@@@@@@@@@*", -" *@@*................+#..*###.................@@* ", -" %@@@.#++++++++++++#**#*#++.###++*...#+++#.*@@* ", -" *@@.#+++++++++#.##++#+#+*.#+++#..##++#.@@@% ", -" $@..+++++++.#++++++##++++#++#...++*.@@$ ", -" @@*.#+++++.#+++++*.#++++##++#.*...@@ ", -" $@@.#+++#*++++#....#+++*#+++...*@$ ", -" *@@..++#*++#**.*.*+++#.#++*..@@$ ", -" $@*.++******#+++++#+#+++..@@ ", -" $@@.##..*$#**#+#*#++++..@@ ", -" $@@.#+#***##...#++++.*@@ ", -" %@@*++++++++#.#++++.@@ ", -" @.#+++++++++.##+++.@$ ", -" @.+$$$$$+$$$#*#+++*@@ ", -" $@*+$$$$$$$+$#.#+++#.@ ", -" @*#+++++++++++.#++++.@ ", -" @.#+++++++#*++.##+++.@$ ", -" $@.+++++++....#..+#++*@@ ", -" @@*+++++#.*@@@...*+++#.@ ", -" @.#++++#.@@@ @@..#++++.@ ", -" @.++++*.@@$ %@@..+++#.@@ ", -" $@.+++..@@* $@*.#+#**@ ", -" @@#+#.*@$% $@@.##..@ ", -" @.##.@@ @@..#.@$ ", -" $@.*.@@$ @@**.@$ ", -" $@.*@@ %$@@.*@ ", -" @.@@$ *@@.@ ", -" @@@$ %@@@$ ", -" $@@% %@@@ ", -" @@ $@ ", -" $ * "}; diff --git a/mozilla/widget/src/gtk/nsAppShell.cpp b/mozilla/widget/src/gtk/nsAppShell.cpp deleted file mode 100644 index 70a015ab78e..00000000000 --- a/mozilla/widget/src/gtk/nsAppShell.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Christopher Blizzard - * . Portions created by the Initial Developer - * are Copyright (C) 2001 the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include - -#include -#include -#include -#include -#include -#include "nsAppShell.h" -#include "prlog.h" -#include "prenv.h" - -#define NOTIFY_TOKEN 0xFA - -/*static*/ gboolean -nsAppShell::EventProcessorCallback(GIOChannel *source, - GIOCondition condition, - gpointer data) -{ - nsAppShell *self = NS_STATIC_CAST(nsAppShell *, data); - - unsigned char c; - read(self->mPipeFDs[0], &c, 1); - NS_ASSERTION(c == (unsigned char) NOTIFY_TOKEN, "wrong token"); - - self->NativeEventCallback(); - return TRUE; -} - -nsAppShell::~nsAppShell() -{ - if (mTag) - g_source_remove(mTag); - if (mPipeFDs[0]) - close(mPipeFDs[0]); - if (mPipeFDs[1]) - close(mPipeFDs[1]); -} - -nsresult -nsAppShell::Init() -{ - GIOChannel *ioc; - - int err = pipe(mPipeFDs); - if (err) - return NS_ERROR_OUT_OF_MEMORY; - - // make the pipe nonblocking - - int flags = fcntl(mPipeFDs[0], F_GETFL, 0); - if (flags == -1) - goto failed; - err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK); - if (err == -1) - goto failed; - flags = fcntl(mPipeFDs[1], F_GETFL, 0); - if (flags == -1) - goto failed; - err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK); - if (err == -1) - goto failed; - - ioc = g_io_channel_unix_new(mPipeFDs[0]); - mTag = g_io_add_watch_full(ioc, G_PRIORITY_DEFAULT, G_IO_IN, - EventProcessorCallback, this, nsnull); - g_io_channel_unref(ioc); - - return nsBaseAppShell::Init(); -failed: - close(mPipeFDs[0]); - close(mPipeFDs[1]); - mPipeFDs[0] = mPipeFDs[1] = 0; - return NS_ERROR_FAILURE; -} - -void -nsAppShell::ScheduleNativeEventCallback() -{ - unsigned char buf[] = { NOTIFY_TOKEN }; - write(mPipeFDs[1], buf, 1); -} - -PRBool -nsAppShell::ProcessNextNativeEvent(PRBool mayWait) -{ - PRBool hasEvents = gtk_events_pending(); - gtk_main_iteration_do(mayWait); - return hasEvents || mayWait; -} diff --git a/mozilla/widget/src/gtk/nsAppShell.h b/mozilla/widget/src/gtk/nsAppShell.h deleted file mode 100644 index 4ed9bedacf6..00000000000 --- a/mozilla/widget/src/gtk/nsAppShell.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* vim:expandtab:shiftwidth=4:tabstop=4: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Christopher Blizzard - * . Portions created by the Initial Developer - * are Copyright (C) 2001 the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsAppShell_h__ -#define nsAppShell_h__ - -#include -#include "nsBaseAppShell.h" -#include "nsCOMPtr.h" - -class nsAppShell : public nsBaseAppShell { -public: - nsAppShell() - : mTag(0), mRunningMain(0) - { - mPipeFDs[0] = mPipeFDs[1] = 0; - } - - // nsBaseAppShell overrides: - nsresult Init(); - virtual void ScheduleNativeEventCallback(); - virtual PRBool ProcessNextNativeEvent(PRBool mayWait); - -private: - virtual ~nsAppShell(); - - static gboolean EventProcessorCallback(GIOChannel *source, - GIOCondition condition, - gpointer data); - - int mPipeFDs[2]; - PRUintn mTag; - PRInt32 mRunningMain; -}; - -#endif /* nsAppShell_h__ */ diff --git a/mozilla/widget/src/gtk/nsBidiKeyboard.cpp b/mozilla/widget/src/gtk/nsBidiKeyboard.cpp deleted file mode 100644 index c1e4b61b7b4..00000000000 --- a/mozilla/widget/src/gtk/nsBidiKeyboard.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is IBM code. - * - * The Initial Developer of the Original Code is - * IBM. Portions created by IBM are Copyright (C) International Business Machines Corporation, 2000. All Rights Reserved. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Simon Montagu - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsBidiKeyboard.h" - -NS_IMPL_ISUPPORTS1(nsBidiKeyboard, nsIBidiKeyboard) - -nsBidiKeyboard::nsBidiKeyboard() : nsIBidiKeyboard() -{ -} - -nsBidiKeyboard::~nsBidiKeyboard() -{ -} - -NS_IMETHODIMP nsBidiKeyboard::IsLangRTL(PRBool *aIsRTL) -{ - *aIsRTL = PR_FALSE; - // XXX Insert platform specific code to determine keyboard direction - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) -{ - // XXX Insert platform specific code to set keyboard language - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/mozilla/widget/src/gtk/nsBidiKeyboard.h b/mozilla/widget/src/gtk/nsBidiKeyboard.h deleted file mode 100644 index 3011affdd16..00000000000 --- a/mozilla/widget/src/gtk/nsBidiKeyboard.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is IBM code. - * - * The Initial Developer of the Original Code is - * IBM. Portions created by IBM are Copyright (C) International Business Machines Corporation, 2000. All Rights Reserved. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Simon Montagu - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsBidiKeyboard -#define __nsBidiKeyboard -#include "nsIBidiKeyboard.h" - -class nsBidiKeyboard : public nsIBidiKeyboard -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIBIDIKEYBOARD - - nsBidiKeyboard(); - virtual ~nsBidiKeyboard(); - /* additional members */ -}; - - -#endif // __nsBidiKeyboard diff --git a/mozilla/widget/src/gtk/nsClipboard.cpp b/mozilla/widget/src/gtk/nsClipboard.cpp deleted file mode 100644 index 30047edd7cf..00000000000 --- a/mozilla/widget/src/gtk/nsClipboard.cpp +++ /dev/null @@ -1,1562 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Mike Pinkerton - * Dan Rosen - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsClipboard.h" - -#include -#include - -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsISupportsArray.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsReadableUtils.h" - -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" -#include "nsWidgetsCID.h" -#include "nsXPIDLString.h" -#include "nsReadableUtils.h" -#include "nsUnicharUtils.h" -#include "nsPrimitiveHelpers.h" - -#include "nsTextFormatter.h" - -#include "nsIServiceManager.h" - -#include "prtime.h" -#include "prthread.h" - -// For manipulation of the X event queue -#include -#include -#include -#ifdef POLL_WITH_XCONNECTIONNUMBER -#include -#endif - -// unicode conversion -#include "nsIPlatformCharset.h" -#include "nsICharsetConverterManager.h" - -static void ConvertHTMLtoUCS2(char* data, PRInt32 dataLength, - PRUnichar** unicodeData, PRInt32& outUnicodeLen); -static void GetHTMLCharset (char* data, PRInt32 dataLength, nsACString& str); - -// The class statics: -GtkWidget* nsClipboard::sWidget = 0; - -// Define this to enable the obsolete X cut buffer mechanism -// In general, a bad idea (see http://www.jwz.org/doc/x-cut-and-paste.html) -// but it might have its uses for backwards compatibility. -#undef USE_CUTBUFFERS - - -static GdkAtom GDK_SELECTION_CLIPBOARD; - -NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard) - -//------------------------------------------------------------------------- -// -// nsClipboard constructor -// -//------------------------------------------------------------------------- -nsClipboard::nsClipboard() -{ -#ifdef DEBUG_CLIPBOARD - g_print("nsClipboard::nsClipboard()\n"); -#endif /* DEBUG_CLIPBOARD */ - - mIgnoreEmptyNotification = PR_FALSE; - mGlobalTransferable = nsnull; - mSelectionTransferable = nsnull; - mGlobalOwner = nsnull; - mSelectionOwner = nsnull; - mSelectionData.data = nsnull; - mSelectionData.length = 0; - - // initialize the widget, etc we're binding to - Init(); -} - -// XXX if GTK's internal code changes this isn't going to work -// copied from gtk code because it is a static function we can't get to it. -// need to bug owen taylor about getting this code public. - -typedef struct _GtkSelectionTargetList GtkSelectionTargetList; - -struct _GtkSelectionTargetList { - GdkAtom selection; - GtkTargetList *list; -}; - -static const char *gtk_selection_handler_key = "gtk-selection-handlers"; - -void __gtk_selection_target_list_remove (GtkWidget *widget, GdkAtom selection) -{ - GtkSelectionTargetList *sellist; - GList *tmp_list, *tmp_list2; - GList *lists; - lists = (GList*)gtk_object_get_data (GTK_OBJECT (widget), gtk_selection_handler_key); - tmp_list = lists; - while (tmp_list) { - sellist = (GtkSelectionTargetList*)tmp_list->data; - if (sellist->selection == selection) { - gtk_target_list_unref (sellist->list); - g_free (sellist); - tmp_list->data = nsnull; - tmp_list2 = tmp_list->prev; - lists = g_list_remove_link(lists, tmp_list); - g_list_free_1(tmp_list); - tmp_list = tmp_list2; - } - if (tmp_list) - tmp_list = tmp_list->next; - } - gtk_object_set_data(GTK_OBJECT(widget), gtk_selection_handler_key, lists); -} - -//------------------------------------------------------------------------- -// -// nsClipboard destructor -// -//------------------------------------------------------------------------- -nsClipboard::~nsClipboard() -{ -#ifdef DEBUG_CLIPBOARD - g_print("nsClipboard::~nsClipboard()\n"); -#endif /* DEBUG_CLIPBOARD */ - - // Remove all our event handlers: - if (sWidget) { - if (gdk_selection_owner_get(GDK_SELECTION_PRIMARY) == sWidget->window) - gtk_selection_remove_all(sWidget); - - if (gdk_selection_owner_get(GDK_SELECTION_CLIPBOARD) == sWidget->window) - gtk_selection_remove_all(sWidget); - } - - // free the selection data, if any - if (mSelectionData.data != nsnull) - nsMemory::Free(mSelectionData.data); - - gtk_object_remove_data(GTK_OBJECT(sWidget), "cb"); - - if (sWidget) { - gtk_widget_unref(sWidget); - sWidget = nsnull; - } -} - - -//------------------------------------------------------------------------- -void nsClipboard::Init(void) -{ -#ifdef DEBUG_CLIPBOARD - g_print("nsClipboard::Init\n"); -#endif - - GDK_SELECTION_CLIPBOARD = gdk_atom_intern("CLIPBOARD", FALSE); - - // create invisible widget to use for the clipboard - sWidget = gtk_invisible_new(); - - // add the clipboard pointer to the widget so we can get it. - gtk_object_set_data(GTK_OBJECT(sWidget), "cb", this); - - // Handle selection requests if we called gtk_selection_add_target: - gtk_signal_connect(GTK_OBJECT(sWidget), "selection_get", - GTK_SIGNAL_FUNC(nsClipboard::SelectionGetCB), - nsnull); - - // When someone else takes the selection away: - gtk_signal_connect(GTK_OBJECT(sWidget), "selection_clear_event", - GTK_SIGNAL_FUNC(nsClipboard::SelectionClearCB), - nsnull); - - // Set up the paste handler: - gtk_signal_connect(GTK_OBJECT(sWidget), "selection_received", - GTK_SIGNAL_FUNC(nsClipboard::SelectionReceivedCB), - nsnull); -} - - - - -/** - * Sets the transferable object - * - */ -NS_IMETHODIMP nsClipboard::SetData(nsITransferable * aTransferable, - nsIClipboardOwner * anOwner, - PRInt32 aWhichClipboard) -{ - - if ((aTransferable == mGlobalTransferable.get() && - anOwner == mGlobalOwner.get() && - aWhichClipboard == kGlobalClipboard ) || - (aTransferable == mSelectionTransferable.get() && - anOwner == mSelectionOwner.get() && - aWhichClipboard == kSelectionClipboard) - ) - { - return NS_OK; - } - - EmptyClipboard(aWhichClipboard); - - switch(aWhichClipboard) { - case kSelectionClipboard: - mSelectionOwner = anOwner; - mSelectionTransferable = aTransferable; - break; - case kGlobalClipboard: - mGlobalOwner = anOwner; - mGlobalTransferable = aTransferable; - SetCutBuffer(); - break; - } - - return SetNativeClipboardData(aWhichClipboard); -} - -/** - * Gets the transferable object - * - */ -NS_IMETHODIMP nsClipboard::GetData(nsITransferable * aTransferable, PRInt32 aWhichClipboard) -{ - if (nsnull != aTransferable) { - return GetNativeClipboardData(aTransferable, aWhichClipboard); - } else { -#ifdef DEBUG_CLIPBOARD - printf(" nsClipboard::GetData(), aTransferable is NULL.\n"); -#endif - } - - return NS_ERROR_FAILURE; -} - - -/** - * - * - */ -NS_IMETHODIMP nsClipboard::EmptyClipboard(PRInt32 aWhichClipboard) -{ - if (mIgnoreEmptyNotification) { - return NS_OK; - } - - switch(aWhichClipboard) { - case kSelectionClipboard: - if (mSelectionOwner) { - mSelectionOwner->LosingOwnership(mSelectionTransferable); - mSelectionOwner = nsnull; - } - mSelectionTransferable = nsnull; - break; - case kGlobalClipboard: - if (mGlobalOwner) { - mGlobalOwner->LosingOwnership(mGlobalTransferable); - mGlobalOwner = nsnull; - } - mGlobalTransferable = nsnull; - break; - } - - return NS_OK; -} - -NS_IMETHODIMP nsClipboard::SupportsSelectionClipboard(PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - - *_retval = PR_TRUE; // we support the selection clipboard on unix. - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_IMETHODIMP nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard) -{ - mIgnoreEmptyNotification = PR_TRUE; - -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::SetNativeClipboardData(%i)\n", aWhichClipboard); -#endif /* DEBUG_CLIPBOARD */ - - - GdkAtom selectionAtom = GetSelectionAtom(aWhichClipboard); - nsCOMPtr transferable(GetTransferable(aWhichClipboard)); - - // make sure we have a good transferable - if (nsnull == transferable) { -#ifdef DEBUG_CLIPBOARD - printf("nsClipboard::SetNativeClipboardData(): no transferable!\n"); -#endif - return NS_ERROR_FAILURE; - } - - // are we already the owner? - if (gdk_selection_owner_get(selectionAtom) == sWidget->window) - { - // if so, clear all the targets - __gtk_selection_target_list_remove(sWidget, selectionAtom); - // gtk_selection_remove_all(sWidget); - } - - // we arn't already the owner, so we will become it - gint have_selection = gtk_selection_owner_set(sWidget, - selectionAtom, - GDK_CURRENT_TIME); - if (have_selection == 0) - return NS_ERROR_FAILURE; - - // get flavor list that includes all flavors that can be written (including ones - // obtained through conversion) - nsCOMPtr flavorList; - nsresult errCode = transferable->FlavorsTransferableCanExport ( getter_AddRefs(flavorList) ); - if ( NS_FAILED(errCode) ) - return NS_ERROR_FAILURE; - - PRUint32 cnt; - flavorList->Count(&cnt); - for ( PRUint32 i=0; i genericFlavor; - flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) ); - nsCOMPtr currentFlavor ( do_QueryInterface(genericFlavor) ); - if ( currentFlavor ) { - nsXPIDLCString flavorStr; - currentFlavor->ToString(getter_Copies(flavorStr)); - - // add these types as selection targets - RegisterFormat(flavorStr, selectionAtom); - } - } - - mIgnoreEmptyNotification = PR_FALSE; - - return NS_OK; -} - - -PRBool nsClipboard::DoRealConvert(GdkAtom type, GdkAtom aSelectionAtom) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::DoRealConvert(%li)\n {\n", type); -#endif - - // Set a flag saying that we're blocking waiting for the callback: - mBlocking = PR_TRUE; - - // - // ask X what kind of data we can get - // -#ifdef DEBUG_CLIPBOARD - g_print(" Doing real conversion of atom type '%s'\n", gdk_atom_name(type)); -#endif - gtk_selection_convert(sWidget, - aSelectionAtom, - type, - GDK_CURRENT_TIME); - - - /* because Gtk is smart, it checks in gtk_selection_convert to see if - the widget we are converting owns the selection, and if it does it - doesn't bother going to X, so it will be done and mBlocking will be - set to FALSE by this point, so only poll X if we have to. (pav) - */ - if (mBlocking) { - // Now we need to wait until the callback comes in ... - // i is in case we get a runaway (yuck). -#ifdef DEBUG_CLIPBOARD - g_print(" Waiting for the callback... mBlocking = %d\n", mBlocking); -#endif /* DEBUG_CLIPBOARD */ - - if (!FindSelectionNotifyEvent()) - return PR_FALSE; - -#ifdef DEBUG_CLIPBOARD - g_print(" }\n"); -#endif - } - - if (mSelectionData.length > 0) - return PR_TRUE; - - return PR_FALSE; -} - - -//------------------------------------------------------------------------- -// -// The blocking Paste routine -// -//------------------------------------------------------------------------- -NS_IMETHODIMP -nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable, - PRInt32 aWhichClipboard) -{ - GdkAtom selectionAtom = GetSelectionAtom(aWhichClipboard); - -#ifdef DEBUG_CLIPBOARD - g_print("nsClipboard::GetNativeClipboardData(%i)\n", aWhichClipboard); -#endif /* DEBUG_CLIPBOARD */ - - // make sure we have a good transferable - if (nsnull == aTransferable) { -#ifdef DEBUG_CLIPBOARD - printf(" GetNativeClipboardData: Transferable is null!\n"); -#endif - return NS_ERROR_FAILURE; - } - - // get flavor list that includes all acceptable flavors (including ones obtained through - // conversion) - nsCOMPtr flavorList; - nsresult errCode = aTransferable->FlavorsTransferableCanImport ( getter_AddRefs(flavorList) ); - if ( NS_FAILED(errCode) ) - return NS_ERROR_FAILURE; - - // Walk through flavors and see which flavor matches the one being pasted: - PRUint32 cnt; - flavorList->Count(&cnt); - nsCAutoString foundFlavor; - PRBool foundData = PR_FALSE; - for ( PRUint32 i = 0; i < cnt; ++i ) { - nsCOMPtr genericFlavor; - flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) ); - nsCOMPtr currentFlavor ( do_QueryInterface(genericFlavor) ); - if ( currentFlavor ) { - nsXPIDLCString flavorStr; - currentFlavor->ToString ( getter_Copies(flavorStr) ); - if (DoConvert(flavorStr, selectionAtom)) { - foundFlavor = flavorStr; - foundData = PR_TRUE; - break; - } - } - } - -#ifdef DEBUG_CLIPBOARD - g_print(" Got the callback: '%s', %d\n", - mSelectionData.data, mSelectionData.length); -#endif /* DEBUG_CLIPBOARD */ - - // We're back from the callback, no longer blocking: - mBlocking = PR_FALSE; - - // - // Now we have data in mSelectionData.data. - // We just have to copy it to the transferable. - // - - if ( foundData ) { - nsCOMPtr genericDataWrapper; - nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor.get(), mSelectionData.data, - mSelectionData.length, getter_AddRefs(genericDataWrapper)); - aTransferable->SetTransferData(foundFlavor.get(), - genericDataWrapper, - mSelectionData.length); - } - - // transferable is now owning the data, so we can free it. - nsMemory::Free(mSelectionData.data); - mSelectionData.data = nsnull; - mSelectionData.length = 0; - - return NS_OK; -} - -/** - * Called when the data from a paste comes in (received from gdk_selection_convert) - * - * @param aWidget the widget - * @param aSelectionData gtk selection stuff - * @param aTime time the selection was requested - */ -void -nsClipboard::SelectionReceivedCB (GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - guint aTime) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::SelectionReceivedCB\n {\n"); -#endif /* DEBUG_CLIPBOARD */ - nsClipboard *cb =(nsClipboard *)gtk_object_get_data(GTK_OBJECT(aWidget), - "cb"); - if (!cb) - { -#ifdef DEBUG_CLIPBOARD - g_print("no clipboard found.. this is bad.\n"); -#endif - return; - } - cb->SelectionReceiver(aWidget, aSelectionData); -#ifdef DEBUG_CLIPBOARD - g_print(" }\n"); -#endif -} - - -/** - * local method (called from nsClipboard::SelectionReceivedCB) - * - * @param aWidget the widget - * @param aSelectionData gtk selection stuff - */ -void -nsClipboard::SelectionReceiver (GtkWidget *aWidget, - GtkSelectionData *aSD) -{ - mBlocking = PR_FALSE; - - if (aSD->length <= 0) - { -#ifdef DEBUG_CLIPBOARD - g_print(" Error retrieving selection: length was %d\n", aSD->length); -#endif - mSelectionData.length = aSD->length; - return; - } - - char *str = gdk_atom_name(aSD->type); - nsCAutoString type(str); - g_free(str); - -#ifdef DEBUG_CLIPBOARD - g_print(" Type is %s\n", type.mBuffer); - - if (type.Equals("ATOM")) { - g_print(" Asked for TARGETS\n"); - } -#endif - - if (type.Equals("COMPOUND_TEXT")) { -#ifdef DEBUG_CLIPBOARD - g_print(" Copying mSelectionData pointer -- \n"); -#endif - mSelectionData = *aSD; - - char *data = (char*)aSD->data; - PRInt32 len = (PRInt32)aSD->length; - - int status = 0; - XTextProperty prop; - -#ifdef DEBUG_CLIPBOARD - g_print(" Converted text from COMPOUND_TEXT to platform locale\n"); - g_print(" data is %s\n", data); - g_print(" len is %d\n", len); -#endif - - prop.value = (unsigned char *)data; - prop.nitems = len; - prop.encoding = XInternAtom(GDK_DISPLAY(), "COMPOUND_TEXT", FALSE); - prop.format = 8; - - char **tmpData; - int foo; - status = XmbTextPropertyToTextList(GDK_DISPLAY(), &prop, &tmpData, &foo); - -#ifdef DEBUG_CLIPBOARD - if (foo > 1) - printf("Got multiple strings from XmbTextPropertyToTextList.. don't know how to handle this yet\n"); -#endif - - PRInt32 numberOfBytes = 0; - - if (status == XNoMemory || status == XLocaleNotSupported || - status == XConverterNotFound) { -#ifdef DEBUG_CLIPBOARD - g_print("\n XmbTextListToTextProperty failed. returned %d\n", status); - g_print(" text is \"%s\"\n", tmpData[0]); -#endif - numberOfBytes = strlen(NS_REINTERPRET_CAST(const char *, data)); - } else { - if (foo > 0 && tmpData[0] != 0 && (*tmpData[0]) != 0) { - data = tmpData[0]; - } - numberOfBytes = strlen(NS_REINTERPRET_CAST(const char *, data)); -#ifdef DEBUG_CLIPBOARD - g_print("\n XmbTextListToTextProperty succeeded\n"); - g_print(" text is \"%s\"\n", data); - g_print(" numberOfBytes is %d\n", numberOfBytes); -#endif - } - - nsresult rv; - PRInt32 outUnicodeLen; - PRUnichar *unicodeData = nsnull; - -#ifdef DEBUG_CLIPBOARD - g_print(" Converting from current locale to unicode\n"); -#endif - - nsCOMPtr decoder; - // get the charset - nsCAutoString platformCharset; - nsCOMPtr platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) - rv = platformCharsetService->GetCharset(kPlatformCharsetSel_Menu, platformCharset); - if (NS_FAILED(rv)) - platformCharset.AssignLiteral("ISO-8859-1"); - - // get the decoder - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - rv = ccm->GetUnicodeDecoderRaw(platformCharset.get(), - getter_AddRefs(decoder)); - NS_ASSERTION(NS_SUCCEEDED(rv), "GetUnicodeEncoderRaw failed"); - if (NS_FAILED(rv)) { - if (tmpData) XFreeStringList(tmpData); - return; - } - - // Estimate out length and allocate the buffer based on a worst-case estimate, then do - // the conversion. - decoder->GetMaxLength(data, numberOfBytes, &outUnicodeLen); // |outUnicodeLen| is number of chars - if (outUnicodeLen) { - unicodeData = NS_REINTERPRET_CAST(PRUnichar*, nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar))); - if ( unicodeData ) { - PRInt32 numberTmp = numberOfBytes; - rv = decoder->Convert(data, &numberTmp, unicodeData, &outUnicodeLen); -#ifdef DEBUG_CLIPBOARD - if (numberTmp != numberOfBytes) - printf("didn't consume all the bytes\n"); -#endif - - (unicodeData)[outUnicodeLen] = '\0'; // null terminate. Convert() doesn't do it for us - } - } // if valid length - - - mSelectionData.data = NS_REINTERPRET_CAST(guchar*,unicodeData); - mSelectionData.length = outUnicodeLen * 2; - if (tmpData) XFreeStringList(tmpData); - } - else if (type.Equals("UTF8_STRING")) { - mSelectionData = *aSD; - - nsresult rv; - PRInt32 outUnicodeLen; - PRUnichar *unicodeData = nsnull; - - char *data = (char*)aSD->data; - PRInt32 numberOfBytes = (PRInt32)aSD->length; - -#ifdef DEBUG_CLIPBOARD - printf("UTF8_STRING is %s\nlength is %i\n", aSD->data, aSD->length); -#endif - - // get the decoder - nsCOMPtr decoder; - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - rv = ccm->GetUnicodeDecoderRaw("UTF-8", getter_AddRefs(decoder)); - - g_return_if_fail(NS_SUCCEEDED(rv)); - - decoder->GetMaxLength(data, numberOfBytes, &outUnicodeLen); // |outUnicodeLen| is number of chars - if (outUnicodeLen) { - unicodeData = NS_REINTERPRET_CAST(PRUnichar*, nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar))); - if ( unicodeData ) { - PRInt32 numberTmp = numberOfBytes; - rv = decoder->Convert(data, &numberTmp, unicodeData, &outUnicodeLen); -#ifdef DEBUG_CLIPBOARD - if (numberTmp != numberOfBytes) - printf("didn't consume all the bytes\n"); -#endif - - (unicodeData)[outUnicodeLen] = '\0'; // null terminate. Convert() doesn't do it for us - } - } // if valid length - - - mSelectionData.data = NS_REINTERPRET_CAST(guchar*,unicodeData); - mSelectionData.length = outUnicodeLen * 2; - mSelectionData.type = gdk_atom_intern(kUnicodeMime, FALSE); - - } else if (type.Equals("STRING")) { -#ifdef DEBUG_CLIPBOARD - g_print(" Copying mSelectionData pointer -- \n"); - g_print(" Data = %s\n Length = %i\n", aSD->data, aSD->length); -#endif - mSelectionData = *aSD; - - // convert our plain text to unicode - const char* castedText = NS_REINTERPRET_CAST(char*, mSelectionData.data); - PRUnichar* convertedText = nsnull; - PRInt32 convertedTextLen = 0; - nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode (castedText, mSelectionData.length, - &convertedText, &convertedTextLen); - if (convertedText) { - // out with the old, in with the new - mSelectionData.data = NS_REINTERPRET_CAST(guchar*, convertedText); - mSelectionData.length = convertedTextLen * 2; - } - } else if (type.Equals(kHTMLMime)) { - mSelectionData = *aSD; - PRUnichar* htmlBody= nsnull; - PRInt32 htmlBodyLen = 0; - ConvertHTMLtoUCS2((char*)aSD->data, aSD->length, &htmlBody, htmlBodyLen); - if (htmlBodyLen) { - mSelectionData.data = NS_REINTERPRET_CAST(guchar*, htmlBody); - mSelectionData.length = htmlBodyLen * 2; - } - } else { - mSelectionData = *aSD; - mSelectionData.data = g_new(guchar, aSD->length + 1); - memcpy(mSelectionData.data, - aSD->data, - aSD->length); - mSelectionData.length = aSD->length; - } -} - -NS_IMETHODIMP -nsClipboard::HasDataMatchingFlavors(nsISupportsArray* aFlavorList, - PRInt32 aWhichClipboard, - PRBool * outResult) -{ - // XXX this doesn't work right. need to fix it. - - // Note to implementor...(from pink the clipboard bitch). - // - // If a client asks for unicode, first check if unicode is present. If not, then - // check for plain text. If it's there, say "yes" as we will do the conversion - // in GetNativeClipboardData(). From this point on, no client will - // ever ask for text/plain explicitly. If they do, you must ASSERT! -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::HasDataMatchingFlavors()\n {\n"); -#endif - - - GetTargets(GetSelectionAtom(aWhichClipboard)); - - guchar *data = mSelectionData.data; - PRInt32 dataLength = mSelectionData.length; - int position = 0; - gchar *str; - - - *outResult = PR_FALSE; - PRUint32 length; - aFlavorList->Count(&length); - for ( PRUint32 i = 0; i < length; ++i ) { - nsCOMPtr genericFlavor; - aFlavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) ); - nsCOMPtr flavorWrapper ( do_QueryInterface(genericFlavor) ); - if ( flavorWrapper ) { - nsCAutoString flavorStr; - nsXPIDLCString myStr; - flavorWrapper->ToString(getter_Copies(myStr)); - flavorStr = nsCAutoString(myStr); - - position = 0; - while (position < dataLength) { - str = gdk_atom_name(*(GdkAtom*)(data+position)); - position += sizeof(GdkAtom); - nsCAutoString atomName(str); - g_free(str); - - if (flavorStr.Equals(kUnicodeMime)) { - if (atomName.Equals("COMPOUND_TEXT") || - atomName.Equals("UTF8_STRING") || - atomName.Equals("STRING")) { -#ifdef DEBUG_CLIPBOARD - g_print(" Selection owner has matching type: %s\n", atomName.mBuffer); -#endif - *outResult = PR_TRUE; - break; - } - } - if (flavorStr.Equals(atomName)) { -#ifdef DEBUG_CLIPBOARD - g_print(" Selection owner has matching type: %s\n", atomName.mBuffer); -#endif - *outResult = PR_TRUE; - break; - } - } - } - } -#ifdef DEBUG_CLIPBOARD - g_print(" returning %i\n }\n", *outResult); -#endif - - nsMemory::Free(mSelectionData.data); - mSelectionData.data = nsnull; - mSelectionData.length = 0; - - return NS_OK; - -} - -/** - * This is the callback which is called when another app - * requests the selection. - * - * @param widget The widget - * @param aSelectionData Selection data - * @param the type being asked for - * @param time Time when the selection request came in - */ -void nsClipboard::SelectionGetCB(GtkWidget *widget, - GtkSelectionData *aSelectionData, - guint aInfo, - guint aTime) -{ -#ifdef DEBUG_CLIPBOARD - g_print("nsClipboard::SelectionGetCB\n"); -#endif - nsClipboard *cb = (nsClipboard *)gtk_object_get_data(GTK_OBJECT(widget), - "cb"); - - void *clipboardData; - PRUint32 dataLength; - nsresult rv; - - PRInt32 whichClipboard = -1; - - if (aSelectionData->selection == GDK_SELECTION_PRIMARY) - whichClipboard = kSelectionClipboard; - else if (aSelectionData->selection == GDK_SELECTION_CLIPBOARD) - whichClipboard = kGlobalClipboard; - -#ifdef DEBUG_CLIPBOARD - g_print(" whichClipboard = %d\n", whichClipboard); -#endif - nsCOMPtr transferable(cb->GetTransferable(whichClipboard)); - - // Make sure we have a transferable: - if (!transferable) { -#ifdef DEBUG_CLIPBOARD - g_print("Clipboard has no transferable!\n"); -#endif - return; - } -#ifdef DEBUG_CLIPBOARD - g_print(" aInfo == %s\n transferable == %p\n", gdk_atom_name(aInfo), transferable.get()); - g_print(" aSD->type == %s\n aSD->target == %s\n", gdk_atom_name(aSelectionData->type), - gdk_atom_name(aSelectionData->target)); -#endif - const char *dataFlavor = nsnull; - char *tstr = gdk_atom_name(aInfo); - nsCAutoString type(tstr); - g_free(tstr); - - if (type.Equals("STRING") || - type.Equals("UTF8_STRING") || - type.Equals("COMPOUND_TEXT") || - type.Equals("TEXT")) - { - dataFlavor = kUnicodeMime; - } else { - dataFlavor = type.get(); - } - - // Get data out of transferable. - nsCOMPtr genericDataWrapper; - rv = transferable->GetTransferData(dataFlavor, - getter_AddRefs(genericDataWrapper), - &dataLength); - nsPrimitiveHelpers::CreateDataFromPrimitive ( dataFlavor, genericDataWrapper, &clipboardData, dataLength ); - if (NS_SUCCEEDED(rv) && clipboardData && dataLength > 0) { - size_t size = 1; - // find the number of bytes in the data for the below thing - // size_t size = sizeof((void*)((unsigned char)clipboardData[0])); - // g_print("************ ***************** ******************* %i\n", size); - - -#ifdef DEBUG_CLIPBOARD - printf("got data from transferable\n"); - printf("clipboardData is %s\n", clipboardData); - printf("length is %d\n", dataLength); -#endif - - if (type.Equals("STRING")) { - // if someone was asking for text/plain, lookup unicode instead so we can convert it. - char* plainTextData = nsnull; - PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData); - PRInt32 plainTextLen = 0; - nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText (castedUnicode, dataLength / 2, - &plainTextData, &plainTextLen); - if (clipboardData) { - nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData)); - clipboardData = plainTextData; - dataLength = plainTextLen; - } - } else if (type.Equals("UTF8_STRING")) { - if (clipboardData) { - PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData); - char *utf8String = - ToNewUTF8String(nsDependentString(castedUnicode, dataLength/2)); - nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData)); - clipboardData = utf8String; - dataLength = strlen(utf8String); - } - } else if (type.Equals(kHTMLMime)) { - if (clipboardData) { - /* - * "text/html" can be encoded UCS2. It is recommended that - * documents transmitted as UCS2 always begin with a ZERO-WIDTH - * NON-BREAKING SPACE character (hexadecimal FEFF, also called - * Byte Order Mark (BOM)). Adding BOM can help other app to - * detect mozilla use UCS2 encoding when copy-paste. - */ - - char *buffer = NS_STATIC_CAST(char *, - nsMemory::Alloc((dataLength + 2) * sizeof(char))); - if (buffer) { - PRUnichar prefix = 0xFEFF; - memcpy(buffer, &prefix, 2); - memcpy(buffer + 2, clipboardData, dataLength); - nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData)); - clipboardData = NS_REINTERPRET_CAST(char*, buffer); - dataLength = dataLength + 2; - } - } - } else if (type.Equals("COMPOUND_TEXT") || type.Equals("TEXT")) { - if (type.Equals("TEXT")) { - // if we get a request for TEXT, return COMPOUND_TEXT - aInfo = gdk_atom_intern("COMPOUND_TEXT", FALSE); - } - char *platformText; - PRInt32 platformLen; - // Get the appropriate unicode encoder. We're guaranteed that this won't change - // through the life of the app so we can cache it. - - nsCOMPtr encoder; - // get the charset - nsCAutoString platformCharset; - nsCOMPtr platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) - rv = platformCharsetService->GetCharset(kPlatformCharsetSel_Menu, platformCharset); - if (NS_FAILED(rv)) - platformCharset.AssignLiteral("ISO-8859-1"); - - // get the encoder - nsCOMPtr ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - rv = ccm->GetUnicodeEncoderRaw(platformCharset.get(), getter_AddRefs(encoder)); - NS_ASSERTION(NS_SUCCEEDED(rv), "GetUnicodeEncoderRaw failed"); - if (NS_FAILED(rv)) { - nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData)); - return; - } - - encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); - - // Estimate out length and allocate the buffer based on a worst-case estimate, then do - // the conversion. - PRUnichar *castedData = NS_REINTERPRET_CAST(PRUnichar*, clipboardData); - encoder->GetMaxLength(castedData, dataLength/2, &platformLen); - if ( platformLen ) { - platformText = NS_REINTERPRET_CAST(char*, nsMemory::Alloc(platformLen + sizeof(char))); - if ( platformText ) { - PRInt32 len = (PRInt32)dataLength/2; - rv = encoder->Convert(castedData, &len, platformText, &platformLen); - (platformText)[platformLen] = '\0'; // null terminate. Convert() doesn't do it for us - } - } // if valid length - - if (platformLen > 0) { - int status = 0; - XTextProperty prop; - -#ifdef DEBUG_CLIPBOARD - g_print("\nConverted text from unicode to platform locale\n"); - g_print("platformText is %s\n", platformText); - g_print("platformLen is %d\n", platformLen); -#endif - - status = XmbTextListToTextProperty(GDK_DISPLAY(), &platformText, 1, XCompoundTextStyle, - &prop); - - if (status == Success) { -#ifdef DEBUG_CLIPBOARD - g_print("\nXmbTextListToTextProperty succeeded\n text is %s\n length is %d\n", prop.value, - prop.nitems); -#endif - nsMemory::Free(platformText); - platformText = (char *)prop.value; - platformLen = prop.nitems; - } - } - -#ifdef DEBUG_CLIPBOARD - g_print("\nFinished trying to convert to platform charset\n"); -#endif - - if (clipboardData) { - nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData)); - clipboardData = platformText; - dataLength = platformLen; - } - } -#ifdef DEBUG_CLIPBOARD - g_print("\nPutting data on clipboard:\n"); - g_print(" clipboardData is %s\n", clipboardData); - g_print(" length is %d\n", dataLength); -#endif - if (clipboardData && dataLength > 0) - gtk_selection_data_set(aSelectionData, - aInfo, size*8, - NS_REINTERPRET_CAST(unsigned char *, clipboardData), - dataLength); - else - gtk_selection_data_set(aSelectionData, - gdk_atom_intern("NULL", FALSE), 8, - nsnull, 0); - nsMemory::Free ( NS_REINTERPRET_CAST(char*, clipboardData) ); - } -#ifdef DEBUG_pavlov - else - printf("Transferable didn't support data flavor %s (type = %d)\n", - dataFlavor ? dataFlavor : "None", aInfo); -#endif -} - - -/** - * Called when another app requests selection ownership - * - * @param aWidget the widget - * @param aEvent the GdkEvent for the selection - * @param aData value passed in from the callback init - */ -void nsClipboard::SelectionClearCB(GtkWidget *aWidget, - GdkEventSelection *aEvent, - gpointer aData) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::SelectionClearCB\n"); -#endif /* DEBUG_CLIPBOARD */ - - if (!aWidget) { - NS_ASSERTION(PR_FALSE, "Null widget passed to SelectionClearCB)\n"); - return; - } - - if (!aEvent) { - NS_ASSERTION(PR_FALSE, "Null event passed to SelectionClearCB)\n"); - return; - } - - nsClipboard *cb = (nsClipboard *)gtk_object_get_data(GTK_OBJECT(aWidget), - "cb"); - - if (aEvent->selection == GDK_SELECTION_PRIMARY) { -#ifdef DEBUG_CLIPBOARD - g_print("clearing PRIMARY clipboard\n"); -#endif - cb->EmptyClipboard(kSelectionClipboard); - } else if (aEvent->selection == GDK_SELECTION_CLIPBOARD) { -#ifdef DEBUG_CLIPBOARD - g_print("clearing CLIPBOARD clipboard\n"); -#endif - cb->EmptyClipboard(kGlobalClipboard); - } -} - - -/** - * The routine called when another app asks for the content of the selection - * - * @param aWidget the widget - * @param aSelectionData gtk selection stuff - * @param aData value passed in from the callback init - */ -void -nsClipboard::SelectionRequestCB (GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - gpointer aData) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::SelectionRequestCB\n"); -#endif /* DEBUG_CLIPBOARD */ -} - -/** - * ... - * - * @param aWidget the widget - * @param aSelectionData gtk selection stuff - * @param aData value passed in from the callback init - */ -void -nsClipboard::SelectionNotifyCB (GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - gpointer aData) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::SelectionNotifyCB\n"); -#endif /* DEBUG_CLIPBOARD */ -} - -/* helper functions*/ - -/* inline */ -GdkAtom nsClipboard::GetSelectionAtom(PRInt32 aWhichClipboard) -{ - switch (aWhichClipboard) - { - case kGlobalClipboard: - return GDK_SELECTION_CLIPBOARD; - case kSelectionClipboard: - default: - return GDK_SELECTION_PRIMARY; - } -} - -/* inline */ -nsITransferable *nsClipboard::GetTransferable(PRInt32 aWhichClipboard) -{ - nsITransferable *transferable = nsnull; - switch (aWhichClipboard) - { - case kGlobalClipboard: - transferable = mGlobalTransferable; - break; - case kSelectionClipboard: - transferable = mSelectionTransferable; - break; - } - return transferable; -} - -/* inline */ -void nsClipboard::AddTarget(GdkAtom aAtom, GdkAtom aSelectionAtom) -{ - gtk_selection_add_target(sWidget, aSelectionAtom, aAtom, aAtom); -} - -void nsClipboard::RegisterFormat(const char *aMimeStr, GdkAtom aSelectionAtom) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::RegisterFormat(%s)\n", aMimeStr); -#endif - nsCAutoString mimeStr(aMimeStr); - - GdkAtom atom = gdk_atom_intern(aMimeStr, FALSE); - - // for Text and Unicode we want to add some extra types to the X clipboard - if (mimeStr.Equals(kUnicodeMime)) { - // we will do the conversions to and from unicode internally - // anyone asking for TEXT will get COMPOUND_TEXT - AddTarget(gdk_atom_intern("TEXT", FALSE), aSelectionAtom); - AddTarget(gdk_atom_intern("COMPOUND_TEXT", FALSE), aSelectionAtom); - AddTarget(gdk_atom_intern("UTF8_STRING", FALSE), aSelectionAtom); - AddTarget(GDK_SELECTION_TYPE_STRING, aSelectionAtom); - } - - AddTarget(atom, aSelectionAtom); -} - -/* return PR_TRUE if we have converted or PR_FALSE if we havn't and need to keep being called */ -PRBool nsClipboard::DoConvert(const char *aMimeStr, GdkAtom aSelectionAtom) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::DoConvert(%s, %s)\n", aMimeStr, gdk_atom_name(aSelectionAtom)); -#endif - /* when doing the selection_add_target, each case should have the same last parameter - which matches the case match */ - PRBool r = PR_FALSE; - - nsCAutoString mimeStr(aMimeStr); - - if (mimeStr.Equals(kUnicodeMime)) { - r = DoRealConvert(gdk_atom_intern("UTF8_STRING", FALSE), aSelectionAtom); - if (r) return r; - r = DoRealConvert(gdk_atom_intern("COMPOUND_TEXT", FALSE), aSelectionAtom); - if (r) return r; - r = DoRealConvert(GDK_SELECTION_TYPE_STRING, aSelectionAtom); - if (r) return r; - } - - GdkAtom atom = gdk_atom_intern(aMimeStr, FALSE); - r = DoRealConvert(atom, aSelectionAtom); - if (r) return r; - - return r; -} - -PRBool nsClipboard::GetTargets(GdkAtom aSelectionAtom) -{ -#ifdef DEBUG_CLIPBOARD - g_print(" nsClipboard::GetTargets(%d)\n {\n", aSelectionAtom); -#endif - - // Set a flag saying that we're blocking waiting for the callback: - mBlocking = PR_TRUE; - - // - // ask X what kind of data we can get - // - static GdkAtom targetsAtom = gdk_atom_intern("TARGETS", PR_FALSE); - - gtk_selection_convert(sWidget, - aSelectionAtom, - targetsAtom, - GDK_CURRENT_TIME); - - /* see comment in DoRealConvert for why we check for mBlocking here */ - if (mBlocking) { - // Now we need to wait until the callback comes in ... -#ifdef DEBUG_CLIPBOARD - g_print(" Waiting for the callback... mBlocking = %d\n", mBlocking); -#endif /* DEBUG_CLIPBOARD */ - - if (!FindSelectionNotifyEvent()) - return PR_FALSE; - - } - -#ifdef DEBUG_CLIPBOARD - g_print(" }\n"); -#endif - - if (mSelectionData.length <= 0) - return PR_FALSE; - - return PR_TRUE; -} - -void nsClipboard::SetCutBuffer() -{ -#ifdef USE_CUTBUFFERS - void *clipboardData; - PRUint32 dataLength; - nsresult rv; - - nsCOMPtr transferable(GetTransferable(kGlobalClipboard)); - - // Make sure we have a transferable: - if (!transferable) { -#ifdef DEBUG_CLIPBOARD - g_print("Clipboard has no transferable!\n"); -#endif - return; - } - - nsCOMPtr genericDataWrapper; - rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(genericDataWrapper), &dataLength); - nsPrimitiveHelpers::CreateDataFromPrimitive(kUnicodeMime, genericDataWrapper, &clipboardData, dataLength); - if (NS_SUCCEEDED(rv) && clipboardData && dataLength > 0) { - char* plainTextData = nsnull; - PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData); - PRInt32 plainTextLen = 0; - nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText (castedUnicode, dataLength / 2, - &plainTextData, &plainTextLen); - if (clipboardData) { - nsMemory::Free(NS_REINTERPRET_CAST(char*, clipboardData)); - clipboardData = plainTextData; - dataLength = plainTextLen; - } - } - - XRotateBuffers(GDK_DISPLAY(), 1); - XStoreBytes(GDK_DISPLAY(), (const char *) clipboardData, nsCRT::strlen((const char *)clipboardData)); -#endif -} - -static void -DispatchSelectionNotifyEvent(GtkWidget *widget, XEvent *xevent) -{ - GdkEvent event; - event.selection.type = GDK_SELECTION_NOTIFY; - event.selection.window = widget->window; - event.selection.selection = xevent->xselection.selection; - event.selection.target = xevent->xselection.target; - event.selection.property = xevent->xselection.property; - event.selection.time = xevent->xselection.time; - - gtk_widget_event(widget, &event); -} - -static void -DispatchPropertyNotifyEvent(GtkWidget *widget, XEvent *xevent) -{ - if (gdk_window_get_events(widget->window) & GDK_PROPERTY_CHANGE_MASK) { - GdkEvent event; - event.property.type = GDK_PROPERTY_NOTIFY; - event.property.window = widget->window; - event.property.atom = xevent->xproperty.atom; - event.property.time = xevent->xproperty.time; - event.property.state = xevent->xproperty.state; - - gtk_widget_event(widget, &event); - } -} - -struct checkEventContext -{ - GtkWidget *cbWidget; - Atom selAtom; -}; - -static Bool -checkEventProc(Display *display, XEvent *event, XPointer arg) -{ - checkEventContext *context = (checkEventContext *) arg; - - if (event->xany.type == SelectionNotify || - (event->xany.type == PropertyNotify && - event->xproperty.atom == context->selAtom)) { - - GdkWindow *cbWindow = gdk_window_lookup(event->xany.window); - if (cbWindow) { - GtkWidget *cbWidget = nsnull; - gdk_window_get_user_data(cbWindow, (gpointer *)&cbWidget); - if (cbWidget && GTK_IS_WIDGET(cbWidget)) { - context->cbWidget = cbWidget; - return True; - } - } - } - - return False; -} - -// Idle timeout for receiving selection and property notify events (microsec) -static const int kClipboardTimeout = 500000; - -PRBool nsClipboard::FindSelectionNotifyEvent() -{ - Display *xDisplay = GDK_DISPLAY(); - checkEventContext context; - context.cbWidget = nsnull; - context.selAtom = gdk_atom_intern("GDK_SELECTION", FALSE); - - // Send X events which are relevant to the ongoing selection retrieval - // to the clipboard widget. Wait until either the operation completes, or - // we hit our timeout. All other X events remain queued. - - int select_result; - -#ifdef POLL_WITH_XCONNECTIONNUMBER - struct pollfd fds[1]; - fds[0].fd = XConnectionNumber(xDisplay); - fds[0].events = POLLIN; -#else - int cnumber = ConnectionNumber(xDisplay); - fd_set select_set; - FD_ZERO(&select_set); - FD_SET(cnumber, &select_set); - ++cnumber; - struct timeval tv; -#endif - - do { - XEvent xevent; - - while (XCheckIfEvent(xDisplay, &xevent, checkEventProc, - (XPointer) &context)) { - - if (xevent.xany.type == SelectionNotify) - DispatchSelectionNotifyEvent(context.cbWidget, &xevent); - else - DispatchPropertyNotifyEvent(context.cbWidget, &xevent); - - if (!mBlocking) - return PR_TRUE; - } - -#ifdef POLL_WITH_XCONNECTIONNUMBER - select_result = poll(fds, 1, kClipboardTimeout / 1000); -#else - tv.tv_sec = 0; - tv.tv_usec = kClipboardTimeout; - select_result = select(cnumber, &select_set, nsnull, nsnull, &tv); -#endif - } while (select_result == 1); - -#ifdef DEBUG_CLIPBOARD - printf("exceeded clipboard timeout\n"); -#endif - return PR_FALSE; -} - -/* - * when copy-paste, mozilla wants data encoded using UCS2, - * other app such as StarOffice use "text/html"(RFC2854). - * This function convert data(got from GTK clipboard) - * to data mozilla wanted. - * - * data from GTK clipboard can be 3 forms: - * 1. From current mozilla - * "text/html", charset = utf-16 - * 2. From old version mozilla or mozilla-based app - * content("body" only), charset = utf-16 - * 3. From other app who use "text/html" when copy-paste - * "text/html", has "charset" info - * - * data : got from GTK clipboard - * dataLength: got from GTK clipboard - * body : pass to Mozilla - * bodyLength: pass to Mozilla - */ -void ConvertHTMLtoUCS2(char* data, PRInt32 dataLength, - PRUnichar** unicodeData, PRInt32& outUnicodeLen) -{ - nsCAutoString charset; - GetHTMLCharset(data, dataLength, charset);// get charset of HTML - if (charset.EqualsLiteral("UTF-16")) {//current mozilla - outUnicodeLen = dataLength / 2 - 1; - *unicodeData = NS_REINTERPRET_CAST(PRUnichar*, - nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar))); - if ( unicodeData ) { - memcpy(*unicodeData, data + sizeof(PRUnichar), - outUnicodeLen * sizeof(PRUnichar)); - (*unicodeData)[outUnicodeLen] = '\0'; - } - } - else if (charset.EqualsLiteral("OLD-MOZILLA")) {// old mozilla - outUnicodeLen = dataLength / 2; - *unicodeData = NS_REINTERPRET_CAST(PRUnichar*, - nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar))); - if ( unicodeData ) { - memcpy(*unicodeData, data, outUnicodeLen * sizeof(PRUnichar)); - (*unicodeData)[outUnicodeLen] = '\0'; - } - } - else {// app which use "text/html" to copy&paste - nsCOMPtr decoder; - nsresult rv; - // get the decoder - nsCOMPtr ccm = - do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) { -#ifdef DEBUG_CLIPBOARD - g_print(" can't get CHARSET CONVERTER MANAGER service\n"); -#endif - outUnicodeLen = 0; - return; - } - rv = ccm->GetUnicodeDecoder(charset.get(), getter_AddRefs(decoder)); - if (NS_FAILED(rv)) { -#ifdef DEBUG_CLIPBOARD - g_print(" get unicode decoder error\n"); -#endif - outUnicodeLen = 0; - return; - } - // converting - decoder->GetMaxLength(data, dataLength, &outUnicodeLen); - // |outUnicodeLen| is number of chars - if (outUnicodeLen) { - *unicodeData = NS_REINTERPRET_CAST(PRUnichar*, - nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar))); - if ( unicodeData ) { - PRInt32 numberTmp = dataLength; - decoder->Convert(data, &numberTmp, *unicodeData, &outUnicodeLen); -#ifdef DEBUG_CLIPBOARD - if (numberTmp != dataLength) - printf("didn't consume all the bytes\n"); -#endif - // null terminate. Convert() doesn't do it for us - (*unicodeData)[outUnicodeLen] = '\0'; - } - } // if valid length - } -} - -/* - * get "charset" information from clipboard data - * return value can be: - * 1. "UTF-16": current mozilla or "text/html" with "charset=utf-16" - * 2. "OLD-MOZILLA": UCS2 encoded data - * 3. other: "text/html" with other charset than utf-16 - */ -void GetHTMLCharset(char* data, PRInt32 dataLength, nsACString& str) -{ - // if detect "FFFE" or "FEFF", assume utf-16 - PRUnichar* beginChar = (PRUnichar*)data; - if ((beginChar[0] == 0xFFFE) || (beginChar[0] == 0xFEFF)) { - str.AssignLiteral("UTF-16"); - return; - } - // no "FFFE" and "FEFF", assume ASCII first to find "charset" info - nsDependentCString htmlStr = nsDependentCString(data, dataLength); - nsACString::const_iterator start, end, valueStart, valueEnd; - - htmlStr.BeginReading(start); - htmlStr.EndReading(end); - htmlStr.BeginReading(valueStart); - htmlStr.BeginReading(valueEnd); - - if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("CONTENT=\"text/html;"), - start, end)) { - start = end; - htmlStr.EndReading(end); - - if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("charset="), - start, end)) { - valueStart = end; - start = end; - htmlStr.EndReading(end); - - if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("\""), start, end)) - valueEnd = start; - } - } - // find "charset" in HTML - if (valueStart != valueEnd) { - const nsACString & charsetStr = Substring(valueStart, valueEnd); - if ( !charsetStr.IsEmpty() ) { - nsCString charsetUpperStr; - ToUpperCase(charsetStr, charsetUpperStr); -#ifdef DEBUG_CLIPBOARD - printf("Charset of HTML = %s\n", charsetUpperStr.get()); -#endif - str.Assign(charsetUpperStr); - return; - } - } - // no "charset" info, assume data come from old-version mozilla - // [UCS2 encoding (without "FFFE" or "FEFF" at the beginning)] - // - // TODO: it may also be "text/html" without "charset". - // can't distinguish between them. Sochoose OLD-MOZILLA here to - // make compitable with old-version mozilla - str.AssignLiteral("OLD-MOZILLA"); -} - diff --git a/mozilla/widget/src/gtk/nsClipboard.h b/mozilla/widget/src/gtk/nsClipboard.h deleted file mode 100644 index 8b3b39a45ca..00000000000 --- a/mozilla/widget/src/gtk/nsClipboard.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999-2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Mike Pinkerton - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsClipboard_h__ -#define nsClipboard_h__ - -#include -#include - -#include "nsIClipboard.h" -#include "nsITransferable.h" -#include "nsIClipboardOwner.h" -#include - -class nsITransferable; -class nsIClipboardOwner; -class nsIWidget; - -/** - * Native Gtk Clipboard wrapper - */ - -class nsClipboard : public nsIClipboard -{ - -public: - nsClipboard(); - virtual ~nsClipboard(); - - //nsISupports - NS_DECL_ISUPPORTS - - // nsIClipboard - NS_DECL_NSICLIPBOARD - -protected: - void Init(void); - - NS_IMETHOD SetNativeClipboardData(PRInt32 aWhichClipboard); - NS_IMETHOD GetNativeClipboardData(nsITransferable * aTransferable, - PRInt32 aWhichClipboard ); - - inline nsITransferable *GetTransferable(PRInt32 aWhichClipboard); - - - PRBool mIgnoreEmptyNotification; - -private: - inline GdkAtom GetSelectionAtom(PRInt32 aWhichClipboard); - inline void AddTarget(GdkAtom aAtom, GdkAtom aSelectionAtom); - void RegisterFormat(const char *aMimeStr, GdkAtom aSelectionAtom); - PRBool DoRealConvert(GdkAtom type, GdkAtom aSelectionAtom); - PRBool DoConvert(const char *aMimeStr, GdkAtom aSelectionAtom); - PRBool GetTargets(GdkAtom aSelectionAtom); - - nsCOMPtr mSelectionOwner; - nsCOMPtr mGlobalOwner; - nsCOMPtr mSelectionTransferable; - nsCOMPtr mGlobalTransferable; - - // Used for communicating pasted data - // from the asynchronous X routines back to a blocking paste: - GtkSelectionData mSelectionData; - PRBool mBlocking; - - // invisible widget. also used by dragndrop - static GtkWidget *sWidget; - - void SelectionReceiver(GtkWidget *aWidget, - GtkSelectionData *aSD); - - /** - * This is the callback which is called when another app - * requests the selection. - * - * @param widget The widget - * @param aSelectionData Selection data - * @param info Value passed in from the callback init - * @param time Time when the selection request came in - */ - static void SelectionGetCB(GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - guint /*info*/, - guint /*time*/); - - /** - * Called when another app requests selection ownership - * - * @param aWidget the widget - * @param aEvent the GdkEvent for the selection - * @param aData value passed in from the callback init - */ - static void SelectionClearCB(GtkWidget *aWidget, - GdkEventSelection *aEvent, - gpointer aData); - - /** - * The routine called when another app asks for the content of the selection - * - * @param aWidget the widget - * @param aSelectionData gtk selection stuff - * @param aData value passed in from the callback init - */ - static void SelectionRequestCB(GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - gpointer data); - - /** - * Called when the data from a paste comes in - * - * @param aWidget the widget - * @param aSelectionData gtk selection stuff - * @param aTime time the selection was requested - */ - static void SelectionReceivedCB(GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - guint aTime); - - - static void SelectionNotifyCB(GtkWidget *aWidget, - GtkSelectionData *aSelectionData, - gpointer aData); - - - /* functions to do blocking when trying to get info from another client */ - PRBool FindSelectionNotifyEvent(); - - - void SetCutBuffer(); -}; - -#endif // nsClipboard_h__ diff --git a/mozilla/widget/src/gtk/nsDragService.cpp b/mozilla/widget/src/gtk/nsDragService.cpp deleted file mode 100644 index e0f7bf6be9b..00000000000 --- a/mozilla/widget/src/gtk/nsDragService.cpp +++ /dev/null @@ -1,1162 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard . - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher Blizzard - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDragService.h" -#include "nsWidgetsCID.h" -#include "nsIServiceManager.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsIObserverService.h" -#include "prlog.h" -#include "nsVoidArray.h" -#include "nsXPIDLString.h" -#include "nsPrimitiveHelpers.h" -#include "nsWidget.h" -#include -#include -#include "nsCRT.h" - - -#ifdef PR_LOGGING -static PRLogModuleInfo *sDragLm = NULL; -#endif - -static const char gMimeListType[] = "application/x-moz-internal-item-list"; -static const char gMozUrlType[] = "_NETSCAPE_URL"; -static const char gTextUriListType[] = "text/uri-list"; - -NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService) -NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService) -NS_IMPL_QUERY_INTERFACE4(nsDragService, - nsIDragService, - nsIDragSession, - nsIDragSessionGTK, - nsIObserver) - -static void -invisibleSourceDragEnd (GtkWidget *aWidget, - GdkDragContext *aContext, - gpointer aData); - -static void -invisibleSourceDragDataGet (GtkWidget *aWidget, - GdkDragContext *aContext, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime, - gpointer aData); - -nsDragService::nsDragService() -{ - // We have to destroy the hidden widget before the event loop stops running. - nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); - obsServ->AddObserver(this, "quit-application", PR_FALSE); - - // our hidden source widget - mHiddenWidget = gtk_invisible_new(); - // make sure that the widget is realized so that - // we can use it as a drag source. - gtk_widget_realize(mHiddenWidget); - // hook up our internal signals so that we can get some feedback - // from our drag source - gtk_signal_connect(GTK_OBJECT(mHiddenWidget), "drag_data_get", - GTK_SIGNAL_FUNC(invisibleSourceDragDataGet), this); - gtk_signal_connect(GTK_OBJECT(mHiddenWidget), "drag_end", - GTK_SIGNAL_FUNC(invisibleSourceDragEnd), this); - - // set up our logging module -#ifdef PR_LOGGING - if (!sDragLm) - sDragLm = PR_NewLogModule("nsDragService"); -#endif - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::nsDragService")); - mTargetWidget = 0; - mTargetDragContext = 0; - mTargetTime = 0; - mCanDrop = PR_FALSE; - mTimeCB = 0; - mTargetDragDataReceived = PR_FALSE; - mTargetDragData = 0; - mTargetDragDataLen = 0; -} - -nsDragService::~nsDragService() -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::~nsDragService")); -} - -// nsIObserver - -NS_IMETHODIMP -nsDragService::Observe(nsISupports *aSubject, const char *aTopic, - const PRUnichar *aData) -{ - if (!nsCRT::strcmp(aTopic, "quit-application")) { - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("nsDragService::Observe(\"quit-application\")")); - gtk_widget_unref(mHiddenWidget); - TargetResetData(); - } else { - NS_NOTREACHED("unexpected topic"); - return NS_ERROR_UNEXPECTED; - } - - return NS_OK; -} - -// nsIDragService - -NS_IMETHODIMP -nsDragService::InvokeDragSession (nsIDOMNode *aDOMNode, - nsISupportsArray * aArrayTransferables, - nsIScriptableRegion * aRegion, - PRUint32 aActionType) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::InvokeDragSession")); - nsBaseDragService::InvokeDragSession (aDOMNode, aArrayTransferables, - aRegion, aActionType); - // make sure that we have an array of transferables to use - if (!aArrayTransferables) - return NS_ERROR_INVALID_ARG; - // set our reference to the transferables. this will also addref - // the transferables since we're going to hang onto this beyond the - // length of this call - mSourceDataItems = aArrayTransferables; - // get the list of items we offer for drags - GtkTargetList *sourceList = 0; - - sourceList = GetSourceList(); - - if (sourceList) { - // get the last time event. we do this because if we don't then - // gdk_drag_begin() will use the current time as the arg for the - // grab. if you happen to do a drag really quickly and release - // the mouse button before the drag begins ( really easy to do, by - // the way ) then the server ungrab from the mouse button release - // will actually have a time that is _before_ the server grab that - // we are about to cause and it will leave the server in a grabbed - // state after the drag has ended. - guint32 lastTime = 0; - mTimeCB(&lastTime); - // synth an event so that that fun bug in the gtk dnd code doesn't - // rear its ugly head - GdkEvent gdk_event; - gdk_event.type = GDK_BUTTON_PRESS; - gdk_event.button.window = mHiddenWidget->window; - gdk_event.button.send_event = 0; - gdk_event.button.time = lastTime; - gdk_event.button.x = 0; - gdk_event.button.y = 0; - gdk_event.button.pressure = 0; - gdk_event.button.xtilt = 0; - gdk_event.button.ytilt = 0; - gdk_event.button.state = 0; - gdk_event.button.button = 0; - gdk_event.button.source = (GdkInputSource)0; - gdk_event.button.deviceid = 0; - gdk_event.button.x_root = 0; - gdk_event.button.y_root = 0; - - // before we start our drag, give the widget code a chance to - // clean up any state. - nsWidget::DragStarted(); - - // save our action type - GdkDragAction action = GDK_ACTION_DEFAULT; - - if (aActionType & DRAGDROP_ACTION_COPY) - action = (GdkDragAction)(action | GDK_ACTION_COPY); - if (aActionType & DRAGDROP_ACTION_MOVE) - action = (GdkDragAction)(action | GDK_ACTION_MOVE); - if (aActionType & DRAGDROP_ACTION_LINK) - action = (GdkDragAction)(action | GDK_ACTION_LINK); - - // start our drag. - GdkDragContext *context = gtk_drag_begin(mHiddenWidget, - sourceList, - action, - 1, - &gdk_event); - // make sure to set our default icon - gtk_drag_set_icon_default (context); - gtk_target_list_unref(sourceList); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDragService::StartDragSession() -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::StartDragSession")); - return nsBaseDragService::StartDragSession(); -} - -NS_IMETHODIMP -nsDragService::EndDragSession(PRBool aDoneDrag) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::EndDragSession")); - // unset our drag action - SetDragAction(DRAGDROP_ACTION_NONE); - return nsBaseDragService::EndDragSession(aDoneDrag); -} - -// nsIDragSession -NS_IMETHODIMP -nsDragService::SetCanDrop (PRBool aCanDrop) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::SetCanDrop %d", - aCanDrop)); - mCanDrop = aCanDrop; - return NS_OK; -} - -NS_IMETHODIMP -nsDragService::GetCanDrop (PRBool *aCanDrop) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::GetCanDrop")); - *aCanDrop = mCanDrop; - return NS_OK; -} - -// count the number of URIs in some text/uri-list format data. -static PRUint32 -CountTextUriListItems (const char *data, - PRUint32 datalen) -{ - const char *p = data; - const char *endPtr = p + datalen; - PRUint32 count = 0; - - while (p < endPtr) { - // skip whitespace (if any) - while (p < endPtr && *p != '\0' && isspace(*p)) - p++; - - // if we aren't at the end of the line ... - if (p != endPtr && *p != '\0' && *p != '\n' && *p != '\r') - count++; - - // skip to the end of the line - while (p < endPtr && *p != '\0' && *p != '\n') - p++; - p++; // skip the actual newline as well. - } - return count; -} - -// extract an item from text/uri-list formatted data and convert it to -// unicode. -static void -GetTextUriListItem(const char *data, - PRUint32 datalen, - PRUint32 aItemIndex, - PRUnichar **convertedText, - PRInt32 *convertedTextLen) -{ - const char *p = data; - const char *endPtr = p + datalen; - unsigned int count = 0; - - *convertedText = nsnull; - while (p < endPtr) { - // skip whitespace (if any) - while (p < endPtr && *p != '\0' && isspace(*p)) - p++; - - // if we aren't at the end of the line, we have a url - if (p != endPtr && *p != '\0' && *p != '\n' && *p != '\r') - count++; - - // this is the item we are after ... - if (aItemIndex + 1 == count) { - const char *q = p; - - while (q < endPtr && *q != '\0' && *q != '\n' && *q != '\r') - q++; - - nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(p, - q - p, - convertedText, - convertedTextLen); - break; - } - - // skip to the end of the line - while (p < endPtr && *p != '\0' && *p != '\n') - p++; - p++; // skip the actual newline as well. - } - - // didn't find the desired item, so just pass the whole lot - if (!*convertedText) { - nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(data, - datalen, - convertedText, - convertedTextLen); - } -} - -NS_IMETHODIMP -nsDragService::GetNumDropItems (PRUint32 * aNumItems) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::GetNumDropItems")); - PRBool isList = IsTargetContextList(); - if (isList) - mSourceDataItems->Count(aNumItems); - else { - GdkAtom gdkFlavor = gdk_atom_intern(gTextUriListType, FALSE); - GetTargetDragData(gdkFlavor); - if (mTargetDragData) { - const char *data = NS_REINTERPRET_CAST(char*, mTargetDragData); - - *aNumItems = CountTextUriListItems(data, mTargetDragDataLen); - } else - *aNumItems = 1; - } - PR_LOG(sDragLm, PR_LOG_DEBUG, ("%d items", *aNumItems)); - return NS_OK; -} - - -NS_IMETHODIMP -nsDragService::GetData (nsITransferable * aTransferable, - PRUint32 aItemIndex) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::GetData %d", aItemIndex)); - - // make sure that we have a transferable - if (!aTransferable) - return NS_ERROR_INVALID_ARG; - - // get flavor list that includes all acceptable flavors (including - // ones obtained through conversion). Flavors are nsISupportsCStrings - // so that they can be seen from JS. - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr flavorList; - rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList)); - if (NS_FAILED(rv)) - return rv; - - // count the number of flavors - PRUint32 cnt; - flavorList->Count (&cnt); - unsigned int i; - - // check to see if this is an internal list - PRBool isList = IsTargetContextList(); - - if (isList) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("it's a list...")); - nsCOMPtr genericWrapper; - // there is always one element if it's a list - flavorList->GetElementAt(0, getter_AddRefs(genericWrapper)); - nsCOMPtr currentFlavor; - currentFlavor = do_QueryInterface(genericWrapper); - if (currentFlavor) { - nsXPIDLCString flavorStr; - currentFlavor->ToString(getter_Copies(flavorStr)); - PR_LOG(sDragLm, PR_LOG_DEBUG, ("flavor is %s\n", (const char *)flavorStr)); - // get the item with the right index - nsCOMPtr genericItem; - mSourceDataItems->GetElementAt(aItemIndex, getter_AddRefs(genericItem)); - nsCOMPtr item (do_QueryInterface(genericItem)); - if (item) { - nsCOMPtr data; - PRUint32 tmpDataLen = 0; - PR_LOG(sDragLm, PR_LOG_DEBUG, ("trying to get transfer data for %s\n", - (const char *)flavorStr)); - rv = item->GetTransferData(flavorStr, getter_AddRefs(data), &tmpDataLen); - if (NS_FAILED(rv)) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("failed.\n")); - return NS_ERROR_FAILURE; - } - PR_LOG(sDragLm, PR_LOG_DEBUG, ("succeeded.\n")); - rv = aTransferable->SetTransferData(flavorStr, data, tmpDataLen); - if (NS_FAILED(rv)) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("failed to set transfer data into transferable!\n")); - return NS_ERROR_FAILURE; - } - // ok, we got the data - return NS_OK; - } - } - // if we got this far, we failed - return NS_ERROR_FAILURE; - } - - // Now walk down the list of flavors. When we find one that is - // actually present, copy out the data into the transferable in that - // format. SetTransferData() implicitly handles conversions. - for ( i = 0; i < cnt; ++i ) { - nsCOMPtr genericWrapper; - flavorList->GetElementAt(i,getter_AddRefs(genericWrapper)); - nsCOMPtr currentFlavor; - currentFlavor = do_QueryInterface(genericWrapper); - if (currentFlavor) { - // find our gtk flavor - nsXPIDLCString flavorStr; - currentFlavor->ToString ( getter_Copies(flavorStr) ); - GdkAtom gdkFlavor = gdk_atom_intern(flavorStr, FALSE); - PR_LOG(sDragLm, PR_LOG_DEBUG, ("looking for data in type %s, gdk flavor %ld\n", - NS_STATIC_CAST(const char*,flavorStr), gdkFlavor)); - PRBool dataFound = PR_FALSE; - if (gdkFlavor) { - GetTargetDragData(gdkFlavor); - } - if (mTargetDragData) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("dataFound = PR_TRUE\n")); - dataFound = PR_TRUE; - } - else { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("dataFound = PR_FALSE\n")); - // if we are looking for text/unicode and we fail to find it - // on the clipboard first, try again with text/plain. If that - // is present, convert it to unicode. - if ( strcmp(flavorStr, kUnicodeMime) == 0 ) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("we were looking for text/unicode...trying again with text/plain\n")); - gdkFlavor = gdk_atom_intern(kTextMime, FALSE); - GetTargetDragData(gdkFlavor); - if (mTargetDragData) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("Got text/plain data\n")); - const char* castedText = NS_REINTERPRET_CAST(char*, mTargetDragData); - PRUnichar* convertedText = nsnull; - PRInt32 convertedTextLen = 0; - nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(castedText, - mTargetDragDataLen, - &convertedText, - &convertedTextLen); - if ( convertedText ) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("successfully converted plain text to unicode.\n")); - // out with the old, in with the new - g_free(mTargetDragData); - mTargetDragData = convertedText; - mTargetDragDataLen = convertedTextLen * 2; - dataFound = PR_TRUE; - } // if plain text data on clipboard - } // if plain text flavor present - } // if looking for text/unicode - - // if we are looking for text/x-moz-url and we failed to find - // it on the clipboard, try again with text/uri-list, and then - // _NETSCAPE_URL - if (strcmp(flavorStr, kURLMime) == 0) { - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("we were looking for text/x-moz-url...trying again with text/uri-list\n")); - gdkFlavor = gdk_atom_intern(gTextUriListType, FALSE); - GetTargetDragData(gdkFlavor); - if (mTargetDragData) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("Got text/uri-list data\n")); - const char *data = NS_REINTERPRET_CAST(char*, mTargetDragData); - PRUnichar* convertedText = nsnull; - PRInt32 convertedTextLen = 0; - - GetTextUriListItem(data, mTargetDragDataLen, aItemIndex, - &convertedText, &convertedTextLen); - - if ( convertedText ) { - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("successfully converted _NETSCAPE_URL to unicode.\n")); - // out with the old, in with the new - g_free(mTargetDragData); - mTargetDragData = convertedText; - mTargetDragDataLen = convertedTextLen * 2; - dataFound = PR_TRUE; - } - } - else { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("failed to get text/uri-list data\n")); - } - if (!dataFound) { - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("we were looking for text/x-moz-url...trying again with _NETSCAP_URL\n")); - gdkFlavor = gdk_atom_intern(gMozUrlType, FALSE); - GetTargetDragData(gdkFlavor); - if (mTargetDragData) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("Got _NETSCAPE_URL data\n")); - const char* castedText = NS_REINTERPRET_CAST(char*, mTargetDragData); - PRUnichar* convertedText = nsnull; - PRInt32 convertedTextLen = 0; - nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(castedText, - mTargetDragDataLen, - &convertedText, - &convertedTextLen); - if ( convertedText ) { - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("successfully converted _NETSCAPE_URL to unicode.\n")); - // out with the old, in with the new - g_free(mTargetDragData); - mTargetDragData = convertedText; - mTargetDragDataLen = convertedTextLen * 2; - dataFound = PR_TRUE; - } - } - else { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("failed to get _NETSCAPE_URL data\n")); - } - } - } - - } // else we try one last ditch effort to find our data - - if (dataFound) { - // the DOM only wants LF, so convert from MacOS line endings - // to DOM line endings. - nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, - &mTargetDragData, - NS_REINTERPRET_CAST(int*, - &mTargetDragDataLen)); - - // put it into the transferable. - nsCOMPtr genericDataWrapper; - nsPrimitiveHelpers::CreatePrimitiveForData(flavorStr, mTargetDragData, - mTargetDragDataLen, - getter_AddRefs(genericDataWrapper)); - aTransferable->SetTransferData(flavorStr, genericDataWrapper, mTargetDragDataLen); - // we found one, get out of this loop! - PR_LOG(sDragLm, PR_LOG_DEBUG, ("dataFound and converted!\n")); - break; - } - } - } // foreach flavor - - return NS_OK; - -} - -NS_IMETHODIMP -nsDragService::IsDataFlavorSupported (const char *aDataFlavor, - PRBool *_retval) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::IsDataFlavorSupported %s", - aDataFlavor)); - if (!_retval) - return NS_ERROR_INVALID_ARG; - - // set this to no by default - *_retval = PR_FALSE; - - // check to make sure that we have a drag object set, here - if (!mTargetDragContext) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("*** warning: IsDataFlavorSupported called without a valid drag context!\n")); - return NS_OK; - } - - // check to see if the target context is a list. - PRBool isList = IsTargetContextList(); - // if it is, just look in the internal data since we are the source - // for it. - if (isList) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("It's a list..")); - PRUint32 numDragItems = 0; - // if we don't have mDataItems we didn't start this drag so it's - // an external client trying to fool us. - if (!mSourceDataItems) - return NS_OK; - mSourceDataItems->Count(&numDragItems); - for (PRUint32 itemIndex = 0; itemIndex < numDragItems; ++itemIndex) { - nsCOMPtr genericItem; - mSourceDataItems->GetElementAt(itemIndex, getter_AddRefs(genericItem)); - nsCOMPtr currItem (do_QueryInterface(genericItem)); - if (currItem) { - nsCOMPtr flavorList; - currItem->FlavorsTransferableCanExport(getter_AddRefs(flavorList)); - if (flavorList) { - PRUint32 numFlavors; - flavorList->Count( &numFlavors ); - for ( PRUint32 flavorIndex = 0; flavorIndex < numFlavors ; ++flavorIndex ) { - nsCOMPtr genericWrapper; - flavorList->GetElementAt (flavorIndex, getter_AddRefs(genericWrapper)); - nsCOMPtr currentFlavor; - currentFlavor = do_QueryInterface(genericWrapper); - if (currentFlavor) { - nsXPIDLCString flavorStr; - currentFlavor->ToString ( getter_Copies(flavorStr) ); - PR_LOG(sDragLm, PR_LOG_DEBUG, ("checking %s against %s\n", - (const char *)flavorStr, aDataFlavor)); - if (strcmp(flavorStr, aDataFlavor) == 0) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("boioioioiooioioioing!\n")); - *_retval = PR_TRUE; - } - } - } - } - } - } - return NS_OK; - } - - // check the target context vs. this flavor, one at a time - GList *tmp; - for (tmp = mTargetDragContext->targets; tmp; tmp = tmp->next) { - GdkAtom atom = GPOINTER_TO_INT(tmp->data); - gchar *name = NULL; - name = gdk_atom_name(atom); - PR_LOG(sDragLm, PR_LOG_DEBUG, ("checking %s against %s\n", name, aDataFlavor)); - if (name && (strcmp(name, aDataFlavor) == 0)) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("good!\n")); - *_retval = PR_TRUE; - } - // check for automatic text/uri-list -> text/x-moz-url mapping - if (*_retval == PR_FALSE && name && (strcmp(name, gTextUriListType) == 0) && - (strcmp(aDataFlavor, kURLMime) == 0)) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("good! ( it's text/uri-list and we're checking against text/x-moz-url )\n")); - *_retval = PR_TRUE; - } - // check for automatic _NETSCAPE_URL -> text/x-moz-url mapping - if (*_retval == PR_FALSE && name && (strcmp(name, gMozUrlType) == 0) && - (strcmp(aDataFlavor, kURLMime) == 0)) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("good! ( it's _NETSCAPE_URL and we're checking against text/x-moz-url )\n")); - *_retval = PR_TRUE; - } - // check for auto text/plain -> text/unicode mapping - if (*_retval == PR_FALSE && name && (strcmp(name, kTextMime) == 0) && - (strcmp(aDataFlavor, kUnicodeMime) == 0)) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("good! ( it's text plain and we're checking against text/unicode )\n")); - *_retval = PR_TRUE; - } - g_free(name); - } - return NS_OK; -} - -// nsIDragSessionGTK - -NS_IMETHODIMP -nsDragService::TargetSetLastContext (GtkWidget *aWidget, - GdkDragContext *aContext, - guint aTime) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::TargetSetLastContext")); - mTargetWidget = aWidget; - mTargetDragContext = aContext; - mTargetTime = aTime; - return NS_OK; -} - -NS_IMETHODIMP -nsDragService::TargetStartDragMotion (void) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::TargetStartDragMotion")); - mCanDrop = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsDragService::TargetEndDragMotion (GtkWidget *aWidget, - GdkDragContext *aContext, - guint aTime) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::TargetEndDragMotion %d", mCanDrop)); - - if (mCanDrop) { - GdkDragAction action; - // notify the dragger if we can drop - switch (mDragAction) { - case DRAGDROP_ACTION_COPY: - action = GDK_ACTION_COPY; - break; - case DRAGDROP_ACTION_LINK: - action = GDK_ACTION_LINK; - break; - default: - action = GDK_ACTION_MOVE; - break; - } - gdk_drag_status(aContext, action, aTime); - } - else { - gdk_drag_status(aContext, (GdkDragAction)0, aTime); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDragService::TargetDataReceived (GtkWidget *aWidget, - GdkDragContext *aContext, - gint aX, - gint aY, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::TargetDataReceived")); - TargetResetData(); - mTargetDragDataReceived = PR_TRUE; - if (aSelectionData->length > 0) { - mTargetDragDataLen = aSelectionData->length; - mTargetDragData = g_malloc(mTargetDragDataLen); - memcpy(mTargetDragData, aSelectionData->data, mTargetDragDataLen); - } - else { - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("Failed to get data. selection data len was %d\n", - aSelectionData->length)); - } - return NS_OK; -} - -NS_IMETHODIMP -nsDragService::TargetSetTimeCallback (nsIDragSessionGTKTimeCB aCallback) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::TargetSetTimeCallback")); - mTimeCB = aCallback; - return NS_OK; -} - -PRBool -nsDragService::IsTargetContextList(void) -{ - PRBool retval = PR_FALSE; - - if (!mTargetDragContext) - return retval; - - // gMimeListType drags only work for drags within a single process. - // The gtk_drag_get_source_widget() function will return NULL if the - // source of the drag is another app, so we use it to check if a - // gMimeListType drop will work or not. - if (gtk_drag_get_source_widget(mTargetDragContext) == NULL) - return retval; - - GList *tmp; - - // walk the list of context targets and see if one of them is a list - // of items. - for (tmp = mTargetDragContext->targets; tmp; tmp = tmp->next) { - GdkAtom atom = GPOINTER_TO_INT(tmp->data); - gchar *name = NULL; - name = gdk_atom_name(atom); - if (strcmp(name, gMimeListType) == 0) - retval = PR_TRUE; - g_free(name); - if (retval) - break; - } - return retval; -} - -void -nsDragService::GetTargetDragData(GdkAtom aFlavor) -{ - gtk_grab_add(mHiddenWidget); - PR_LOG(sDragLm, PR_LOG_DEBUG, ("getting data flavor %d\n", aFlavor)); - PR_LOG(sDragLm, PR_LOG_DEBUG, ("mLastWidget is %p and mLastContext is %p\n", - mTargetWidget, mTargetDragContext)); - // reset our target data areas - TargetResetData(); - gtk_drag_get_data(mTargetWidget, mTargetDragContext, aFlavor, mTargetTime); - // Make sure to set the mDataReceived to PR_FALSE since we're about - // to try to get the data. It might have been left set to PR_TRUE - // if this is another request in the same drag session where the - // previous one failed. However, there are cases where we can get - // the data received signal before we get to this point so only set - // it if there isn't any drag data. - PR_LOG(sDragLm, PR_LOG_DEBUG, ("about to start inner iteration.")); - while (!mTargetDragDataReceived && mDoingDrag) { - // XXX check the number of iterations...we could grab forever and - // that would make me sad. - PR_LOG(sDragLm, PR_LOG_DEBUG, ("doing iteration...\n")); - gtk_main_iteration(); - } - PR_LOG(sDragLm, PR_LOG_DEBUG, ("finished inner iteration\n")); - gtk_grab_remove(mHiddenWidget); -} - -void -nsDragService::TargetResetData(void) -{ - mTargetDragDataReceived = PR_FALSE; - // make sure to free old data if we have to - if (mTargetDragData) - g_free(mTargetDragData); - mTargetDragData = 0; - mTargetDragDataLen = 0; -} - -GtkTargetList * -nsDragService::GetSourceList(void) -{ - if (!mSourceDataItems) - return NULL; - nsVoidArray targetArray; - GtkTargetEntry *targets; - GtkTargetList *targetList = 0; - PRUint32 targetCount = 0; - unsigned int numDragItems = 0; - - mSourceDataItems->Count(&numDragItems); - - // Check to see if we're dragging > 1 item. - if (numDragItems > 1) { - // as the Xdnd protocol only supports a single item (or is it just - // gtk's implementation?), we don't advertise all flavours listed - // in the nsITransferable. - - // the application/x-moz-internal-item-list format, which preserves - // all information for drags within the same mozilla instance. - GdkAtom listAtom = gdk_atom_intern(gMimeListType, FALSE); - GtkTargetEntry *listTarget = (GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry)); - listTarget->target = g_strdup(gMimeListType); - listTarget->flags = 0; - listTarget->info = listAtom; - PR_LOG(sDragLm, PR_LOG_DEBUG, ("automatically adding target %s with id %ld\n", - listTarget->target, listAtom)); - targetArray.AppendElement(listTarget); - - // check what flavours are supported so we can decide what other - // targets to advertise. - nsCOMPtr genericItem; - mSourceDataItems->GetElementAt(0, getter_AddRefs(genericItem)); - nsCOMPtr currItem (do_QueryInterface(genericItem)); - - if (currItem) { - nsCOMPtr flavorList; - currItem->FlavorsTransferableCanExport(getter_AddRefs(flavorList)); - if (flavorList) { - PRUint32 numFlavors; - flavorList->Count( &numFlavors ); - for (PRUint32 flavorIndex = 0; flavorIndex < numFlavors ; - ++flavorIndex ) { - nsCOMPtr genericWrapper; - flavorList->GetElementAt(flavorIndex, getter_AddRefs(genericWrapper)); - nsCOMPtr currentFlavor; - currentFlavor = do_QueryInterface(genericWrapper); - if (currentFlavor) { - nsXPIDLCString flavorStr; - currentFlavor->ToString ( getter_Copies(flavorStr) ); - - // check if text/x-moz-url is supported. If so, advertise - // text/uri-list. - if (strcmp(flavorStr, kURLMime) == 0) { - listAtom = gdk_atom_intern(gTextUriListType, FALSE); - listTarget = (GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry)); - listTarget->target = g_strdup(gTextUriListType); - listTarget->flags = 0; - listTarget->info = listAtom; - PR_LOG(sDragLm, PR_LOG_DEBUG, ("automatically adding target %s with id %ld\n", - listTarget->target, listAtom)); - targetArray.AppendElement(listTarget); - } - - } - } // foreach flavor in item - } // if valid flavor list - } // if item is a transferable - } else if (numDragItems == 1) { - nsCOMPtr genericItem; - mSourceDataItems->GetElementAt(0, getter_AddRefs(genericItem)); - nsCOMPtr currItem (do_QueryInterface(genericItem)); - if (currItem) { - nsCOMPtr flavorList; - currItem->FlavorsTransferableCanExport(getter_AddRefs(flavorList)); - if (flavorList) { - PRUint32 numFlavors; - flavorList->Count( &numFlavors ); - for (PRUint32 flavorIndex = 0; flavorIndex < numFlavors ; - ++flavorIndex ) { - nsCOMPtr genericWrapper; - flavorList->GetElementAt(flavorIndex, getter_AddRefs(genericWrapper)); - nsCOMPtr currentFlavor; - currentFlavor = do_QueryInterface(genericWrapper); - if (currentFlavor) { - nsXPIDLCString flavorStr; - currentFlavor->ToString ( getter_Copies(flavorStr) ); - // get the atom - GdkAtom atom = gdk_atom_intern(flavorStr, FALSE); - GtkTargetEntry *target = (GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry)); - target->target = g_strdup(flavorStr); - target->flags = 0; - target->info = atom; - PR_LOG(sDragLm, PR_LOG_DEBUG, - ("adding target %s with id %ld\n", target->target, atom)); - targetArray.AppendElement(target); - // Check to see if this is text/unicode. If it is, add - // text/plain since we automatically support text/plain if - // we support text/unicode. - if (strcmp(flavorStr, kUnicodeMime) == 0) { - // get the atom for the unicode string - GdkAtom plainAtom = gdk_atom_intern(kTextMime, FALSE); - GtkTargetEntry *plainTarget = (GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry)); - plainTarget->target = g_strdup(kTextMime); - plainTarget->flags = 0; - plainTarget->info = plainAtom; - PR_LOG(sDragLm, PR_LOG_DEBUG, ("automatically adding target %s with id %ld\n", - plainTarget->target, plainAtom)); - targetArray.AppendElement(plainTarget); - } - // Check to see if this is the x-moz-url type. If it is, - // add _NETSCAPE_URL this is a type used by everybody. - if (strcmp(flavorStr, kURLMime) == 0) { - // get the atom name for it - GdkAtom urlAtom = gdk_atom_intern(gMozUrlType, FALSE); - GtkTargetEntry *urlTarget = (GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry)); - urlTarget->target = g_strdup(gMozUrlType); - urlTarget->flags = 0; - urlTarget->info = urlAtom; - PR_LOG(sDragLm, PR_LOG_DEBUG, ("automatically adding target %s with id %ld\n", - urlTarget->target, urlAtom)); - targetArray.AppendElement(urlTarget); - } - } - } // foreach flavor in item - } // if valid flavor list - } // if item is a transferable - } // if it is a single item drag - - // get all the elements that we created. - targetCount = targetArray.Count(); - if (targetCount) { - // allocate space to create the list of valid targets - targets = (GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry) * targetCount); - for (PRUint32 targetIndex = 0; targetIndex < targetCount; ++targetIndex) { - GtkTargetEntry *disEntry = (GtkTargetEntry *)targetArray.ElementAt(targetIndex); - // this is a string reference but it will be freed later. - targets[targetIndex].target = disEntry->target; - targets[targetIndex].flags = disEntry->flags; - targets[targetIndex].info = disEntry->info; - } - targetList = gtk_target_list_new(targets, targetCount); - // clean up the target list - for (PRUint32 cleanIndex = 0; cleanIndex < targetCount; ++cleanIndex) { - GtkTargetEntry *thisTarget = (GtkTargetEntry *)targetArray.ElementAt(cleanIndex); - g_free(thisTarget->target); - g_free(thisTarget); - } - g_free(targets); - } - - return targetList; -} - -void -nsDragService::SourceEndDrag(void) -{ - // this just releases the list of data items that we provide - mSourceDataItems = 0; - - // Inform the drag session that we're ending the drag. - EndDragSession(PR_TRUE); -} - -static void -CreateUriList(nsISupportsArray *items, gchar **text, gint *length) -{ - PRUint32 i, count; - GString *uriList = g_string_new(NULL); - - items->Count(&count); - for (i = 0; i < count; i++) { - nsCOMPtr genericItem; - items->GetElementAt(i, getter_AddRefs(genericItem)); - nsCOMPtr item; - item = do_QueryInterface(genericItem); - - if (item) { - PRUint32 tmpDataLen = 0; - void *tmpData = NULL; - nsresult rv = 0; - nsCOMPtr data; - rv = item->GetTransferData(kURLMime, getter_AddRefs(data), &tmpDataLen); - - if (NS_SUCCEEDED(rv)) { - nsPrimitiveHelpers::CreateDataFromPrimitive (kURLMime, data, - &tmpData, tmpDataLen); - char* plainTextData = nsnull; - PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, tmpData); - PRInt32 plainTextLen = 0; - nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText(castedUnicode, - tmpDataLen / 2, - &plainTextData, - &plainTextLen); - if (plainTextData) { - PRInt32 j; - - // text/x-moz-url is of form url + "\n" + title. We just - // want the url. - for (j = 0; j < plainTextLen; j++) - if (plainTextData[j] == '\n' || plainTextData[j] == '\r') { - plainTextData[j] = '\0'; - break; - } - g_string_append(uriList, plainTextData); - g_string_append(uriList, "\r\n"); - // this wasn't allocated with glib - free(plainTextData); - } - if (tmpData) { - // this wasn't allocated with glib - free(tmpData); - } - } - } - } - - *text = uriList->str; - *length = uriList->len + 1; - g_string_free(uriList, FALSE); // don't free the data -} - - -void -nsDragService::SourceDataGet(GtkWidget *aWidget, - GdkDragContext *aContext, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::SourceDataGet")); - GdkAtom atom = aInfo; - nsXPIDLCString mimeFlavor; - gchar *typeName = 0; - typeName = gdk_atom_name(atom); - if (!typeName) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("failed to get atom name.\n")); - return; - } - - PR_LOG(sDragLm, PR_LOG_DEBUG, ("Type is %s\n", typeName)); - // make a copy since |nsXPIDLCString| won't use |g_free|... - mimeFlavor.Adopt(nsCRT::strdup(typeName)); - g_free(typeName); - // check to make sure that we have data items to return. - if (!mSourceDataItems) { - PR_LOG(sDragLm, PR_LOG_DEBUG, ("Failed to get our data items\n")); - return; - } - - if (strcmp(mimeFlavor, gTextUriListType) == 0) { - // fall back for text/uri-list - gchar *uriList; - gint length; - - CreateUriList(mSourceDataItems, &uriList, &length); - - gtk_selection_data_set(aSelectionData, aSelectionData->target, - 8, (guchar *)uriList, length); - g_free(uriList); - return; - } - - nsCOMPtr genericItem; - mSourceDataItems->GetElementAt(0, getter_AddRefs(genericItem)); - nsCOMPtr item; - item = do_QueryInterface(genericItem); - if (item) { - // if someone was asking for text/plain, lookup unicode instead so - // we can convert it. - PRBool needToDoConversionToPlainText = PR_FALSE; - const char* actualFlavor = mimeFlavor; - if (strcmp(mimeFlavor,kTextMime) == 0) { - actualFlavor = kUnicodeMime; - needToDoConversionToPlainText = PR_TRUE; - } - // if someone was asking for _NETSCAPE_URL we need to convert to - // plain text but we also need to look for x-moz-url - else if (strcmp(mimeFlavor, gMozUrlType) == 0) { - actualFlavor = kURLMime; - needToDoConversionToPlainText = PR_TRUE; - } - else - actualFlavor = mimeFlavor; - - PRUint32 tmpDataLen = 0; - void *tmpData = NULL; - nsresult rv; - nsCOMPtr data; - rv = item->GetTransferData(actualFlavor, getter_AddRefs(data), &tmpDataLen); - if (NS_SUCCEEDED(rv)) { - nsPrimitiveHelpers::CreateDataFromPrimitive (actualFlavor, data, - &tmpData, tmpDataLen); - // if required, do the extra work to convert unicode to plain - // text and replace the output values with the plain text. - if (needToDoConversionToPlainText) { - char* plainTextData = nsnull; - PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, tmpData); - PRInt32 plainTextLen = 0; - nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText(castedUnicode, - tmpDataLen / 2, - &plainTextData, - &plainTextLen); - if (tmpData) { - // this was not allocated using glib - free(tmpData); - tmpData = plainTextData; - tmpDataLen = plainTextLen; - } - } - if (tmpData) { - // this copies the data - gtk_selection_data_set(aSelectionData, aSelectionData->target, - 8, (guchar *)tmpData, tmpDataLen); - // this wasn't allocated with glib - free(tmpData); - } - } - } -} - -/* static */ -void -invisibleSourceDragDataGet (GtkWidget *aWidget, - GdkDragContext *aContext, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime, - gpointer aData) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("invisibleDragDataGet")); - nsDragService *dragService = (nsDragService *)aData; - dragService->SourceDataGet(aWidget, aContext, aSelectionData, - aInfo, aTime); -} - -/* static */ -void -invisibleSourceDragEnd (GtkWidget *aWidget, - GdkDragContext *aContext, - gpointer aData) -{ - PR_LOG(sDragLm, PR_LOG_DEBUG, ("invisibleDragEnd")); - nsDragService *dragService = (nsDragService *)aData; - // The drag has ended. Release the hostages! - dragService->SourceEndDrag(); -} diff --git a/mozilla/widget/src/gtk/nsDragService.h b/mozilla/widget/src/gtk/nsDragService.h deleted file mode 100644 index 82fa11abc34..00000000000 --- a/mozilla/widget/src/gtk/nsDragService.h +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard . - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher Blizzard - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDragService_h__ -#define nsDragService_h__ - -#include "nsBaseDragService.h" -#include "nsIDragSessionGTK.h" -#include "nsIObserver.h" -#include - - -/** - * Native GTK DragService wrapper - */ - -class nsDragService : public nsBaseDragService, - public nsIDragSessionGTK, - public nsIObserver -{ - -public: - nsDragService(); - virtual ~nsDragService(); - - NS_DECL_ISUPPORTS_INHERITED - - NS_DECL_NSIOBSERVER - - // nsIDragService - NS_IMETHOD InvokeDragSession (nsIDOMNode *aDOMNode, - nsISupportsArray * anArrayTransferables, - nsIScriptableRegion * aRegion, - PRUint32 aActionType); - NS_IMETHOD StartDragSession(); - NS_IMETHOD EndDragSession(PRBool aDragDone); - - // nsIDragSession - NS_IMETHOD SetCanDrop (PRBool aCanDrop); - NS_IMETHOD GetCanDrop (PRBool *aCanDrop); - NS_IMETHOD GetNumDropItems (PRUint32 * aNumItems); - NS_IMETHOD GetData (nsITransferable * aTransferable, - PRUint32 aItemIndex); - NS_IMETHOD IsDataFlavorSupported (const char *aDataFlavor, PRBool *_retval); - - // nsIDragSessionGTK - - NS_IMETHOD TargetSetLastContext (GtkWidget *aWidget, - GdkDragContext *aContext, - guint aTime); - NS_IMETHOD TargetStartDragMotion (void); - NS_IMETHOD TargetEndDragMotion (GtkWidget *aWidget, - GdkDragContext *aContext, - guint aTime); - NS_IMETHOD TargetDataReceived (GtkWidget *aWidget, - GdkDragContext *aContext, - gint aX, - gint aY, - GtkSelectionData *aSelection_data, - guint aInfo, - guint32 aTime); - - NS_IMETHOD TargetSetTimeCallback (nsIDragSessionGTKTimeCB aCallback); - - // This is called when the drag started with the invisible widget - // finishes. It's called from within the drag service code but from - // a callback - it needs to be public. - void SourceEndDrag(void); - void SourceDataGet(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint32 aTime); - - // END PUBLIC API - -private: - - // target side vars - - // the last widget that was the target of a drag - GtkWidget *mTargetWidget; - GdkDragContext *mTargetDragContext; - guint mTargetTime; - // is it OK to drop on us? - PRBool mCanDrop; - // have we received our drag data? - PRBool mTargetDragDataReceived; - // last data received and its length - void *mTargetDragData; - PRUint32 mTargetDragDataLen; - // is the current target drag context contain a list? - PRBool IsTargetContextList(void); - // this will get the native data from the last target given a - // specific flavor - void GetTargetDragData(GdkAtom aFlavor); - // this will reset all of the target vars - void TargetResetData(void); - - // source side vars - - // the source of our drags - GtkWidget *mHiddenWidget; - // our source data items - nsCOMPtr mSourceDataItems; - // get a list of the sources in gtk's format - GtkTargetList *GetSourceList(void); - - // this is our callback to get the most recent event's time - nsIDragSessionGTKTimeCB mTimeCB; - -}; - -#endif // nsDragService_h__ diff --git a/mozilla/widget/src/gtk/nsGtkCursors.h b/mozilla/widget/src/gtk/nsGtkCursors.h deleted file mode 100644 index 1f678fcae65..00000000000 --- a/mozilla/widget/src/gtk/nsGtkCursors.h +++ /dev/null @@ -1,493 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:expandtab:shiftwidth=2:tabstop=2: - */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Tim Copperfield. Portions created by Tim Copperfield are Copyright (C) Tim Copperfield. All Rights Reserved. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Tim Copperfield - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsGtkCursors_h__ -#define nsGtkCursors_h__ - -typedef struct { - const unsigned char *bits; - const unsigned char *mask_bits; - int hot_x; - int hot_y; -} nsGtkCursor; - -/* MOZ_CURSOR_QUESTION_ARROW */ -static const unsigned char moz_question_arrow_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0xe3, 0x00, 0x00, 0x7c, 0xb0, 0x01, 0x00, 0x6c, 0x80, 0x01, 0x00, - 0xc4, 0xc0, 0x00, 0x00, 0xc0, 0x60, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, - 0x80, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_question_arrow_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0xe3, 0x00, 0x00, - 0xfe, 0xf7, 0x01, 0x00, 0xfe, 0xfb, 0x03, 0x00, 0xfe, 0xf0, 0x03, 0x00, - 0xee, 0xe1, 0x01, 0x00, 0xe4, 0xf1, 0x00, 0x00, 0xc0, 0x63, 0x00, 0x00, - 0xc0, 0xf3, 0x00, 0x00, 0x80, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_HAND_GRAB */ -static const unsigned char moz_hand_grab_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, - 0x60, 0x39, 0x00, 0x00, 0x90, 0x49, 0x00, 0x00, 0x90, 0x49, 0x01, 0x00, - 0x20, 0xc9, 0x02, 0x00, 0x20, 0x49, 0x02, 0x00, 0x58, 0x40, 0x02, 0x00, - 0x64, 0x00, 0x02, 0x00, 0x44, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, - 0x10, 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, - 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_hand_grab_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x60, 0x3f, 0x00, 0x00, - 0xf0, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf8, 0xff, 0x03, 0x00, - 0xf0, 0xff, 0x07, 0x00, 0xf8, 0xff, 0x07, 0x00, 0xfc, 0xff, 0x07, 0x00, - 0xfe, 0xff, 0x07, 0x00, 0xfe, 0xff, 0x03, 0x00, 0xfc, 0xff, 0x03, 0x00, - 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x01, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_HAND_GRABBING */ -static const unsigned char moz_hand_grabbing_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x36, 0x00, 0x00, 0x20, 0xc9, 0x00, 0x00, 0x20, 0x40, 0x01, 0x00, - 0x40, 0x00, 0x01, 0x00, 0x60, 0x00, 0x01, 0x00, 0x10, 0x00, 0x01, 0x00, - 0x10, 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, - 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_hand_grabbing_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x36, 0x00, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x03, 0x00, - 0xe0, 0xff, 0x03, 0x00, 0xf0, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x03, 0x00, - 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x01, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_COPY */ -static const unsigned char moz_copy_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x03, 0x00, 0x00, 0x7c, 0x30, 0x00, 0x00, 0x6c, 0x30, 0x00, 0x00, - 0xc4, 0xfc, 0x00, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, - 0x80, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_copy_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, - 0xfe, 0x37, 0x00, 0x00, 0xfe, 0x7b, 0x00, 0x00, 0xfe, 0xfc, 0x00, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x00, 0x00, - 0xc0, 0x7b, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ALIAS */ -static const unsigned char moz_alias_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x03, 0x00, 0x00, 0x7c, 0xf0, 0x00, 0x00, 0x6c, 0xe0, 0x00, 0x00, - 0xc4, 0xf0, 0x00, 0x00, 0xc0, 0xb0, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, - 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_alias_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, - 0xfe, 0xf7, 0x00, 0x00, 0xfe, 0xfb, 0x01, 0x00, 0xfe, 0xf0, 0x01, 0x00, - 0xee, 0xf9, 0x01, 0x00, 0xe4, 0xf9, 0x01, 0x00, 0xc0, 0xbf, 0x00, 0x00, - 0xc0, 0x3f, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_CONTEXT_MENU */ -static const unsigned char moz_menu_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0xfd, 0x00, 0x00, - 0xfc, 0xff, 0x00, 0x00, 0x7c, 0x84, 0x00, 0x00, 0x6c, 0xfc, 0x00, 0x00, - 0xc4, 0x84, 0x00, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0x80, 0x85, 0x00, 0x00, - 0x80, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_menu_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0xfd, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, - 0xfe, 0xff, 0x01, 0x00, 0xfe, 0xff, 0x01, 0x00, 0xfe, 0xfe, 0x01, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0xc0, 0xff, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_SPINNING */ -static const unsigned char moz_spinning_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00, - 0xc4, 0xdc, 0x00, 0x00, 0xc0, 0x44, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, - 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_spinning_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x3b, 0x00, 0x00, - 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0xc0, 0x7f, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ZOOM_IN */ -static const unsigned char moz_zoom_in_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x62, 0x04, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00, - 0xf9, 0x09, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0x62, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_zoom_in_mask_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ZOOM_OUT */ -static const unsigned char moz_zoom_out_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00, - 0xf9, 0x09, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_zoom_out_mask_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_NOT_ALLOWED */ -static const unsigned char moz_not_allowed_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, - 0xf0, 0xf0, 0x00, 0x00, 0x38, 0xc0, 0x01, 0x00, 0x7c, 0x80, 0x03, 0x00, - 0xec, 0x00, 0x03, 0x00, 0xce, 0x01, 0x07, 0x00, 0x86, 0x03, 0x06, 0x00, - 0x06, 0x07, 0x06, 0x00, 0x06, 0x0e, 0x06, 0x00, 0x06, 0x1c, 0x06, 0x00, - 0x0e, 0x38, 0x07, 0x00, 0x0c, 0x70, 0x03, 0x00, 0x1c, 0xe0, 0x03, 0x00, - 0x38, 0xc0, 0x01, 0x00, 0xf0, 0xf0, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, - 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_not_allowed_mask_bits[] = { - 0x80, 0x1f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, - 0xf8, 0xff, 0x01, 0x00, 0xfc, 0xf0, 0x03, 0x00, 0xfe, 0xc0, 0x07, 0x00, - 0xfe, 0x81, 0x07, 0x00, 0xff, 0x83, 0x0f, 0x00, 0xcf, 0x07, 0x0f, 0x00, - 0x8f, 0x0f, 0x0f, 0x00, 0x0f, 0x1f, 0x0f, 0x00, 0x0f, 0x3e, 0x0f, 0x00, - 0x1f, 0xfc, 0x0f, 0x00, 0x1e, 0xf8, 0x07, 0x00, 0x3e, 0xf0, 0x07, 0x00, - 0xfc, 0xf0, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x00, 0x00, - 0xe0, 0x7f, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_COL_RESIZE */ -static const unsigned char moz_col_resize_bits[] = { - 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x05, 0x00, 0x00, 0x10, 0x45, 0x00, 0x00, 0x18, 0xc5, 0x00, 0x00, - 0x1c, 0xc5, 0x01, 0x00, 0x7e, 0xf5, 0x03, 0x00, 0x1c, 0xc5, 0x01, 0x00, - 0x18, 0xc5, 0x00, 0x00, 0x10, 0x45, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_col_resize_mask_bits[] = { - 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, - 0x90, 0x4f, 0x00, 0x00, 0xb8, 0xef, 0x00, 0x00, 0xbc, 0xef, 0x01, 0x00, - 0xbe, 0xef, 0x03, 0x00, 0xff, 0xff, 0x07, 0x00, 0xbe, 0xef, 0x03, 0x00, - 0xbc, 0xef, 0x01, 0x00, 0xb8, 0xef, 0x00, 0x00, 0x90, 0x4f, 0x00, 0x00, - 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_ROW_RESIZE */ -static const unsigned char moz_row_resize_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, - 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, - 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_row_resize_mask_bits[] = { - 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, - 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, - 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, - 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_VERTICAL_TEXT */ -static const unsigned char moz_vertical_text_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, - 0x06, 0x60, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_vertical_text_mask_bits[] = { - 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, - 0xff, 0xff, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, - 0x0f, 0xf0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_NESW_RESIZE */ -static const unsigned char moz_nesw_resize_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0xbe, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, - 0x02, 0xb4, 0x00, 0x00, 0x02, 0xa2, 0x00, 0x00, 0x02, 0x81, 0x00, 0x00, - 0x8a, 0x80, 0x00, 0x00, 0x5a, 0x80, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, - 0x7a, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_nesw_resize_mask_bits[] = { - 0xc0, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0x00, 0xff, 0x01, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfc, 0x01, 0x00, - 0x07, 0xfe, 0x01, 0x00, 0x07, 0xf7, 0x01, 0x00, 0x8f, 0xe3, 0x01, 0x00, - 0xdf, 0xc1, 0x01, 0x00, 0xff, 0xc0, 0x01, 0x00, 0x7f, 0x00, 0x00, 0x00, - 0xff, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, - 0xff, 0x07, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* MOZ_CURSOR_NWSE_RESIZE */ -static const unsigned char moz_nwse_resize_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xfa, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, - 0x5a, 0x80, 0x00, 0x00, 0x8a, 0x80, 0x00, 0x00, 0x02, 0x81, 0x00, 0x00, - 0x02, 0xa2, 0x00, 0x00, 0x02, 0xb4, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, - 0x00, 0xbc, 0x00, 0x00, 0x00, 0xbe, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char moz_nwse_resize_mask_bits[] = { - 0xff, 0x07, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, - 0xff, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, - 0xff, 0xc0, 0x01, 0x00, 0xdf, 0xc1, 0x01, 0x00, 0x8f, 0xe3, 0x01, 0x00, - 0x07, 0xf7, 0x01, 0x00, 0x07, 0xfe, 0x01, 0x00, 0x00, 0xfc, 0x01, 0x00, - 0x00, 0xfe, 0x01, 0x00, 0x00, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0xc0, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -enum { - MOZ_CURSOR_QUESTION_ARROW = 0, - MOZ_CURSOR_HAND_GRAB, - MOZ_CURSOR_HAND_GRABBING, - MOZ_CURSOR_COPY, - MOZ_CURSOR_ALIAS, - MOZ_CURSOR_CONTEXT_MENU, - MOZ_CURSOR_SPINNING, - MOZ_CURSOR_ZOOM_IN, - MOZ_CURSOR_ZOOM_OUT, - MOZ_CURSOR_NOT_ALLOWED, - MOZ_CURSOR_COL_RESIZE, - MOZ_CURSOR_ROW_RESIZE, - MOZ_CURSOR_VERTICAL_TEXT, - MOZ_CURSOR_NESW_RESIZE, - MOZ_CURSOR_NWSE_RESIZE -}; - -// create custom pixmap cursor from cursors in nsGTKCursorData.h -static const nsGtkCursor GtkCursors[] = { - { moz_question_arrow_bits, moz_question_arrow_mask_bits, 2, 2 }, - { moz_hand_grab_bits, moz_hand_grab_mask_bits, 10, 10 }, - { moz_hand_grabbing_bits, moz_hand_grabbing_mask_bits, 10, 10 }, - { moz_copy_bits, moz_copy_mask_bits, 2, 2 }, - { moz_alias_bits, moz_alias_mask_bits, 2, 2 }, - { moz_menu_bits, moz_menu_mask_bits, 2, 2 }, - { moz_spinning_bits, moz_spinning_mask_bits, 2, 2 }, - { moz_zoom_in_bits, moz_zoom_in_mask_bits, 6, 6 }, - { moz_zoom_out_bits, moz_zoom_out_mask_bits, 6, 6 }, - { moz_not_allowed_bits, moz_not_allowed_mask_bits, 9, 9 }, - { moz_col_resize_bits, moz_col_resize_mask_bits, 9, 7 }, - { moz_row_resize_bits, moz_row_resize_mask_bits, 7, 9 }, - { moz_vertical_text_bits, moz_vertical_text_mask_bits, 8, 4 }, - { moz_nesw_resize_bits, moz_nesw_resize_mask_bits, 8, 8 }, - { moz_nwse_resize_bits, moz_nwse_resize_mask_bits, 8, 8 } -}; - -#endif /* nsGtkCursors_h__ */ diff --git a/mozilla/widget/src/gtk/nsGtkEventHandler.cpp b/mozilla/widget/src/gtk/nsGtkEventHandler.cpp deleted file mode 100644 index 02e34d33b76..00000000000 --- a/mozilla/widget/src/gtk/nsGtkEventHandler.cpp +++ /dev/null @@ -1,899 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Annema - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsWidget.h" -#include "keysym2ucs.h" -#include "nsWindow.h" -#include "nsAppShell.h" - -#include "nsGUIEvent.h" - -#include "nsGtkIMEHelper.h" - - -#include - -#include -#include -#include "nsGtkEventHandler.h" - -#include -#include -#include - -#ifdef DEBUG_pavlov -//#define DEBUG_EVENTS 1 -#endif - -//#define DEBUG_MOVE - -static void -dispatch_superwin_event(GdkEvent *event, nsWindow *window); - -static PRBool -gdk_window_child_of_gdk_window(GdkWindow *window, GdkWindow *ancestor); - -// This is a flag that says if we should suppress the next key down -// event. This is used when that last key release event was -// suppressed and we want the next key press event to not generate the -// key down event since it is part of a key repeat sequence. -static PRBool suppressNextKeyDown = PR_FALSE; - -//============================================================== -void InitAllocationEvent(GtkAllocation *aAlloc, - nsSizeEvent &anEvent) -{ - if (aAlloc != nsnull) { - // HACK - // nsRect *foo = new nsRect(aAlloc->x, aAlloc->y, aAlloc->width, aAlloc->height); - nsRect *foo = new nsRect(0, 0, aAlloc->width, aAlloc->height); - anEvent.windowSize = foo; - // anEvent.point.x = aAlloc->x; - // anEvent.point.y = aAlloc->y; - // HACK - anEvent.mWinWidth = aAlloc->width; - anEvent.mWinHeight = aAlloc->height; - } - - anEvent.time = PR_IntervalNow(); -} - -//============================================================== -struct nsKeyConverter { - int vkCode; // Platform independent key code - int keysym; // GDK keysym key code -}; - -// -// Netscape keycodes are defined in widget/public/nsGUIEvent.h -// GTK keycodes are defined in -// -struct nsKeyConverter nsKeycodes[] = { - { NS_VK_CANCEL, GDK_Cancel }, - { NS_VK_BACK, GDK_BackSpace }, - { NS_VK_TAB, GDK_Tab }, - { NS_VK_TAB, GDK_ISO_Left_Tab }, - { NS_VK_CLEAR, GDK_Clear }, - { NS_VK_RETURN, GDK_Return }, - { NS_VK_SHIFT, GDK_Shift_L }, - { NS_VK_SHIFT, GDK_Shift_R }, - { NS_VK_CONTROL, GDK_Control_L }, - { NS_VK_CONTROL, GDK_Control_R }, - { NS_VK_ALT, GDK_Alt_L }, - { NS_VK_ALT, GDK_Alt_R }, - { NS_VK_META, GDK_Meta_L }, - { NS_VK_META, GDK_Meta_R }, - { NS_VK_PAUSE, GDK_Pause }, - { NS_VK_CAPS_LOCK, GDK_Caps_Lock }, - { NS_VK_ESCAPE, GDK_Escape }, - { NS_VK_SPACE, GDK_space }, - { NS_VK_PAGE_UP, GDK_Page_Up }, - { NS_VK_PAGE_DOWN, GDK_Page_Down }, - { NS_VK_END, GDK_End }, - { NS_VK_HOME, GDK_Home }, - { NS_VK_LEFT, GDK_Left }, - { NS_VK_UP, GDK_Up }, - { NS_VK_RIGHT, GDK_Right }, - { NS_VK_DOWN, GDK_Down }, - { NS_VK_PRINTSCREEN, GDK_Print }, - { NS_VK_INSERT, GDK_Insert }, - { NS_VK_DELETE, GDK_Delete }, - - // keypad keys - { NS_VK_LEFT, GDK_KP_Left }, - { NS_VK_RIGHT, GDK_KP_Right }, - { NS_VK_UP, GDK_KP_Up }, - { NS_VK_DOWN, GDK_KP_Down }, - { NS_VK_PAGE_UP, GDK_KP_Page_Up }, - // Not sure what these are - //{ NS_VK_, GDK_KP_Prior }, - //{ NS_VK_, GDK_KP_Next }, - // GDK_KP_Begin is the 5 on the non-numlock keypad - //{ NS_VK_, GDK_KP_Begin }, - { NS_VK_PAGE_DOWN, GDK_KP_Page_Down }, - { NS_VK_HOME, GDK_KP_Home }, - { NS_VK_END, GDK_KP_End }, - { NS_VK_INSERT, GDK_KP_Insert }, - { NS_VK_DELETE, GDK_KP_Delete }, - - { NS_VK_MULTIPLY, GDK_KP_Multiply }, - { NS_VK_ADD, GDK_KP_Add }, - { NS_VK_SEPARATOR, GDK_KP_Separator }, - { NS_VK_SUBTRACT, GDK_KP_Subtract }, - { NS_VK_DECIMAL, GDK_KP_Decimal }, - { NS_VK_DIVIDE, GDK_KP_Divide }, - { NS_VK_RETURN, GDK_KP_Enter }, - { NS_VK_NUM_LOCK, GDK_Num_Lock }, - { NS_VK_SCROLL_LOCK,GDK_Scroll_Lock }, - - { NS_VK_COMMA, GDK_comma }, - { NS_VK_PERIOD, GDK_period }, - { NS_VK_SLASH, GDK_slash }, - { NS_VK_BACK_SLASH, GDK_backslash }, - { NS_VK_BACK_QUOTE, GDK_grave }, - { NS_VK_OPEN_BRACKET, GDK_bracketleft }, - { NS_VK_CLOSE_BRACKET, GDK_bracketright }, - { NS_VK_SEMICOLON, GDK_colon }, - { NS_VK_QUOTE, GDK_apostrophe }, - - // context menu key, keysym 0xff67, typically keycode 117 on 105-key (Microsoft) - // x86 keyboards, located between right 'Windows' key and right Ctrl key - { NS_VK_CONTEXT_MENU, GDK_Menu }, - - // NS doesn't have dash or equals distinct from the numeric keypad ones, - // so we'll use those for now. See bug 17008: - { NS_VK_SUBTRACT, GDK_minus }, - { NS_VK_EQUALS, GDK_equal }, - - // Some shifted keys, see bug 15463 as well as 17008. - // These should be subject to different keyboard mappings. - { NS_VK_QUOTE, GDK_quotedbl }, - { NS_VK_OPEN_BRACKET, GDK_braceleft }, - { NS_VK_CLOSE_BRACKET, GDK_braceright }, - { NS_VK_BACK_SLASH, GDK_bar }, - { NS_VK_SEMICOLON, GDK_semicolon }, - { NS_VK_BACK_QUOTE, GDK_asciitilde }, - { NS_VK_COMMA, GDK_less }, - { NS_VK_PERIOD, GDK_greater }, - { NS_VK_SLASH, GDK_question }, - { NS_VK_1, GDK_exclam }, - { NS_VK_2, GDK_at }, - { NS_VK_3, GDK_numbersign }, - { NS_VK_4, GDK_dollar }, - { NS_VK_5, GDK_percent }, - { NS_VK_6, GDK_asciicircum }, - { NS_VK_7, GDK_ampersand }, - { NS_VK_8, GDK_asterisk }, - { NS_VK_9, GDK_parenleft }, - { NS_VK_0, GDK_parenright }, - { NS_VK_SUBTRACT, GDK_underscore }, - { NS_VK_EQUALS, GDK_plus } -}; - -#define IS_XSUN_XSERVER(dpy) \ - (strstr(XServerVendor(dpy), "Sun Microsystems") != NULL) - -// map Sun Keyboard special keysyms on to NS_VK keys -struct nsKeyConverter nsSunKeycodes[] = { - {NS_VK_ESCAPE, GDK_F11 }, //bug 57262, Sun Stop key generates F11 keysym - {NS_VK_F11, 0x1005ff10 }, //Sun F11 key generates SunF36(0x1005ff10) keysym - {NS_VK_F12, 0x1005ff11 }, //Sun F12 key generates SunF37(0x1005ff11) keysym - {NS_VK_PAGE_UP, GDK_F29 }, //KP_Prior - {NS_VK_PAGE_DOWN, GDK_F35 }, //KP_Next - {NS_VK_HOME, GDK_F27 }, //KP_Home - {NS_VK_END, GDK_F33 }, //KP_End -}; - -//============================================================== - -// Input keysym is in gtk format; output is in NS_VK format -int nsPlatformToDOMKeyCode(GdkEventKey *aGEK) -{ - int i, length = 0; - int keysym = aGEK->keyval; - - // First, try to handle alphanumeric input, not listed in nsKeycodes: - // most likely, more letters will be getting typed in than things in - // the key list, so we will look through these first. - - // since X has different key symbols for upper and lowercase letters and - // mozilla does not, convert gdk's to mozilla's - if (keysym >= GDK_a && keysym <= GDK_z) - return keysym - GDK_a + NS_VK_A; - if (keysym >= GDK_A && keysym <= GDK_Z) - return keysym - GDK_A + NS_VK_A; - - // numbers - if (keysym >= GDK_0 && keysym <= GDK_9) - return keysym - GDK_0 + NS_VK_0; - - // keypad numbers - if (keysym >= GDK_KP_0 && keysym <= GDK_KP_9) - return keysym - GDK_KP_0 + NS_VK_NUMPAD0; - - // map Sun Keyboard special keysyms - if (IS_XSUN_XSERVER(GDK_DISPLAY())) { - length = sizeof(nsSunKeycodes) / sizeof(struct nsKeyConverter); - for (i = 0; i < length; i++) { - if (nsSunKeycodes[i].keysym == keysym) - return(nsSunKeycodes[i].vkCode); - } - } - - // misc other things - length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter); - for (i = 0; i < length; i++) { - if (nsKeycodes[i].keysym == keysym) - return(nsKeycodes[i].vkCode); - } - - if (keysym >= GDK_F1 && keysym <= GDK_F24) - return keysym - GDK_F1 + NS_VK_F1; - -#if defined(DEBUG_akkana) || defined(DEBUG_ftang) - printf("No match in nsPlatformToDOMKeyCode: keysym is 0x%x, string is '%s', keyval = %d\n", keysym, aGEK->string, aGEK->keyval); -#endif - - return((int)0); -} - -//============================================================== - -// Convert gdk key event keyvals to char codes if printable, 0 otherwise -PRUint32 nsConvertCharCodeToUnicode(GdkEventKey* aGEK) -{ - // Anything above 0xf000 is considered a non-printable - // Exception: directly encoded UCS characters - if (aGEK->keyval > 0xf000 && (aGEK->keyval & 0xff000000) != 0x01000000) { - // Keypad keys are an exception: they return a value different - // from their non-keypad equivalents, but mozilla doesn't distinguish. - switch (aGEK->keyval) - { - case GDK_KP_Space: - return ' '; - case GDK_KP_Equal: - return '='; - case GDK_KP_Multiply: - return '*'; - case GDK_KP_Add: - return '+'; - case GDK_KP_Separator: - return ','; - case GDK_KP_Subtract: - return '-'; - case GDK_KP_Decimal: - return '.'; - case GDK_KP_Divide: - return '/'; - case GDK_KP_0: - return '0'; - case GDK_KP_1: - return '1'; - case GDK_KP_2: - return '2'; - case GDK_KP_3: - return '3'; - case GDK_KP_4: - return '4'; - case GDK_KP_5: - return '5'; - case GDK_KP_6: - return '6'; - case GDK_KP_7: - return '7'; - case GDK_KP_8: - return '8'; - case GDK_KP_9: - return '9'; - } - - // non-printables - return 0; - } - -#if defined(USE_XIM) && defined(_AIX) - // On AIX, GDK doesn't get correct keysyms from XIM. Follow GDK - // reference recommending to use the 'string' member of GdkEventKey - // instead. See: - // - // developer.gnome.org/doc/API/gdk/gdk-event-structures.html#GDKEVENTKEY - - PRBool controlChar = (aGEK->state & GDK_CONTROL_MASK || - aGEK->state & GDK_MOD1_MASK || - aGEK->state & GDK_MOD4_MASK); - - // Use 'string' as opposed to 'keyval' when control, alt, or meta is - // not pressed. This allows keyboard shortcuts to continue to function - // properly, while fixing input problems and mode switching in certain - // locales where the 'keyval' does not correspond to the actual input. - // See Bug #157397 and Bug #161581 for more details. - - if (!controlChar && gdk_im_ready() && aGEK->length > 0 - && aGEK->keyval != (guint)*aGEK->string) { - nsGtkIMEHelper* IMEHelper = nsGtkIMEHelper::GetSingleton(); - if (IMEHelper != nsnull) { - PRUnichar* unichars = IMEHelper->GetUnichars(); - PRInt32 unilen = IMEHelper->GetUnicharsSize(); - PRInt32 unichar_size = IMEHelper->MultiByteToUnicode( - aGEK->string, aGEK->length, - &unichars, &unilen); - if (unichar_size > 0) { - IMEHelper->SetUnichars(unichars); - IMEHelper->SetUnicharsSize(unilen); - return (long)*unichars; - } - } - } -#endif - // we're supposedly printable, let's try to convert - long ucs = keysym2ucs(aGEK->keyval); - if ((ucs != -1) && (ucs < 0x10000)) - return ucs; - - // I guess we couldn't convert - return 0; -} - -//============================================================== -void InitKeyEvent(GdkEventKey *aGEK, - nsKeyEvent &anEvent) -{ - if (aGEK != nsnull) { - anEvent.keyCode = nsPlatformToDOMKeyCode(aGEK); - anEvent.time = aGEK->time; - anEvent.isShift = (aGEK->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isControl = (aGEK->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isAlt = (aGEK->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isMeta = (aGEK->state & GDK_MOD4_MASK) ? PR_TRUE : PR_FALSE; - } -} - -void InitKeyPressEvent(GdkEventKey *aGEK, - nsKeyEvent &anEvent) -{ - // - // init the basic event fields - // - - if (aGEK!=nsnull) { - anEvent.isShift = (aGEK->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isControl = (aGEK->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isAlt = (aGEK->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isMeta = (aGEK->state & GDK_MOD4_MASK) ? PR_TRUE : PR_FALSE; - - anEvent.charCode = nsConvertCharCodeToUnicode(aGEK); - if (anEvent.charCode) { - // if the control, meta, or alt key is down, then we should leave - // the isShift flag alone (probably not a printable character) - // if none of the other modifier keys are pressed then we need to - // clear isShift so the character can be inserted in the editor - - if ( anEvent.isControl || anEvent.isAlt || anEvent.isMeta ) { - // make Ctrl+uppercase functional as same as Ctrl+lowercase - // when Ctrl+uppercase(eg.Ctrl+C) is pressed,convert the charCode - // from uppercase to lowercase(eg.Ctrl+c),so do Alt and Meta Key - // It is hack code for bug 61355, there is same code snip for - // Windows platform in widget/src/windows/nsWindow.cpp: See bug 16486 - // Note: if Shift is pressed at the same time, do not to_lower() - // Because Ctrl+Shift has different function with Ctrl - if ( (anEvent.charCode >= GDK_A && anEvent.charCode <= GDK_Z) || - (anEvent.charCode >= GDK_a && anEvent.charCode <= GDK_z) ) { - anEvent.charCode = (anEvent.isShift) ? - gdk_keyval_to_upper(anEvent.charCode) : - gdk_keyval_to_lower(anEvent.charCode); - } - } - } else { - anEvent.keyCode = nsPlatformToDOMKeyCode(aGEK); - } - -#if defined(DEBUG_akkana_not) || defined (DEBUG_ftang) - if (!aGEK->length) printf("!length, "); - printf("Key Press event: gtk string = '%s', keyval = '%c' = %d,\n", - aGEK->string, aGEK->keyval, aGEK->keyval); - printf(" --> keyCode = 0x%x, char code = '%c'", - anEvent.keyCode, anEvent.charCode); - if (anEvent.isShift) - printf(" [shift]"); - if (anEvent.isControl) - printf(" [ctrl]"); - if (anEvent.isAlt) - printf(" [alt]"); - if (anEvent.isMeta) - printf(" [meta]"); - printf("\n"); -#endif - - anEvent.time = aGEK->time; - } -} - -/*============================================================== - ============================================================== - ============================================================= - ==============================================================*/ - -void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p) -{ - nsWindow *widget = (nsWindow *)p; - nsSizeEvent event(PR_TRUE, NS_SIZE, widget); - - InitAllocationEvent(alloc, event); - NS_ADDREF(widget); - widget->OnResize(&event); - NS_RELEASE(widget); - - delete event.windowSize; -} - -//============================================================== -gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p) -{ - nsWidget *win = (nsWidget*)p; - - // if there's a focused window rewrite the event to use that window. - if (nsWidget::sFocusWindow) - win = nsWidget::sFocusWindow; - - // work around for annoying things. - if (event->keyval == GDK_Tab) - if (event->state & GDK_CONTROL_MASK) - if (event->state & GDK_MOD1_MASK) - return PR_FALSE; - - - NS_ADDREF(win); - - // - // First, dispatch the Key event as a virtual key down event - // but lie about where it came from and say it is from the - // window that currently has focus inside our app... - // - PRBool noDefault = PR_FALSE; - nsKeyEvent keyDownEvent(PR_TRUE, NS_KEY_DOWN, win); - InitKeyEvent(event, keyDownEvent); - // if we need to suppress this NS_KEY_DOWN event, reset the flag - if (suppressNextKeyDown == PR_TRUE) - suppressNextKeyDown = PR_FALSE; - else - noDefault = win->OnKey(keyDownEvent); - - // Don't pass Shift, Alt, Control and Meta as NS_KEY_PRESS events. - if (event->keyval == GDK_Shift_L - || event->keyval == GDK_Shift_R - || event->keyval == GDK_Control_L - || event->keyval == GDK_Control_R - || event->keyval == GDK_Alt_L - || event->keyval == GDK_Alt_R - || event->keyval == GDK_Meta_L - || event->keyval == GDK_Meta_R) - return PR_TRUE; - - // - // Second, dispatch the Key event as a key press event w/ a Unicode - // character code. Note we have to check for modifier keys, since - // gtk returns a character value for them - // - - // Call nsConvertCharCodeToUnicode() here to get kevent.charCode - nsKeyEvent keyPressEvent(PR_TRUE, NS_KEY_PRESS, win); - InitKeyPressEvent(event, keyPressEvent); - if (noDefault) { // If prevent default set for onkeydown, do the same for onkeypress - keyPressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT; - } - - if (event->length) { - if (keyPressEvent.charCode || keyPressEvent.keyCode) { - // keyPressEvent.charCode or keyPressEvent.keyCode is valid, just - // pass to OnKey() - win->OnKey(keyPressEvent); - } else if (nsGtkIMEHelper::GetSingleton()) { - // commit request from IME - win->IMECommitEvent(event); - } - } else { // for Home/End/Up/Down/Left/Right/PageUp/PageDown key - win->OnKey(keyPressEvent); - } - - NS_RELEASE(win); - - if (w) - { - gtk_signal_emit_stop_by_name (GTK_OBJECT(w), "key_press_event"); - } - - return PR_TRUE; -} - -//============================================================== -gint handle_key_release_event(GtkObject *w, GdkEventKey* event, gpointer p) -{ - XEvent nextEvent; - PRBool shouldDrop = PR_FALSE; - // According to the DOM spec if this is the result of a key repeat - // event we don't let it through since the DOM wants the event - // stream to look like this: press press press press release. The - // way that X does things is to do press release press release, etc. - // We check to see if this is a key release by checking to see if - // the next event in the queue is a key press event and it has the - // exact same timestamp as the current event. - - // have a look in the X queue to see if there's another event in the - // queue. - - if (XPending(GDK_DISPLAY())) { - // get a copy of the next event - XPeekEvent(GDK_DISPLAY(), &nextEvent); - - // see if it's a key press event and if it has the same time as - // the last event. - if ((nextEvent.xany.type == KeyPress) && - (nextEvent.xkey.time == event->time)) - { - shouldDrop = PR_TRUE; - // the next key press event shouldn't generate a key down event. - // this is a global variable - suppressNextKeyDown = PR_TRUE; - } - } - - // should we drop this event? - if (shouldDrop) - return PR_TRUE; - - nsWidget *win = (nsWidget *)p; - if (nsWidget::sFocusWindow) - win = nsWidget::sFocusWindow; - - nsKeyEvent kevent(PR_TRUE, NS_KEY_UP, win); - InitKeyEvent(event, kevent); - - NS_ADDREF(win); - win->OnKey(kevent); - NS_RELEASE(win); - - if (w) - { - gtk_signal_emit_stop_by_name (GTK_OBJECT(w), "key_release_event"); - } - - return PR_TRUE; -} - -//============================================================== -void -handle_gdk_event (GdkEvent *event, gpointer data) -{ - GtkObject *eventObject = nsnull; - - // set the last time that we got an event. we need this for drag - // and drop if you can believe that. - guint32 event_time = gdk_event_get_time(event); - if (event_time) - nsWidget::SetLastEventTime(event_time); - - // Get the next X event serial ID and save it for later for event - // processing. If it stays zero then events won't be processed - // later. We're using this as a flag too but with a number this big - // we're probably not going to overflow and even if we did there - // wouldn't be any harm. - unsigned long serial = 0; - - if (XPending(GDK_DISPLAY())) { - XEvent temp_event; - XPeekEvent(GDK_DISPLAY(), &temp_event); - serial = temp_event.xany.serial - 1; - } - - // try to get the user data for the event window. - if (event->any.window) - gdk_window_get_user_data (event->any.window, (void **)&eventObject); - - // If there is an event object and it's a superwin then we need to - // make sure that the event either is handled locally or is passed - // on with a legitimate GtkWidget object associated with it so the - // Gtk mainloop doesn't go spastic. - - if (eventObject && GDK_IS_SUPERWIN(eventObject)) { - // try to find the nsWindow object associated with this superwin - nsWindow *window = (nsWindow *)gtk_object_get_data (eventObject, - "nsWindow"); - - // If we don't have a window here anymore, we are probably in - // the process of being or have been destroyed. give up now. - if (!window) - goto end; - - // Find out if there's a grabbing widget. If there is and it's a - // regular gtk widget, and our current event window is not the - // child of that grab widget, we need to rewrite the event to that - // gtk grabbing widget. - PRBool rewriteEvent = PR_FALSE; - GtkWidget *grabWidget = gtk_grab_get_current(); - GtkWidget *owningWidget = window->GetOwningWidget(); - - if (grabWidget && - !GTK_IS_MOZAREA(grabWidget) && - !gdk_window_child_of_gdk_window(owningWidget->window, - grabWidget->window)) { - rewriteEvent = PR_TRUE; - } - - - // There are a lot of events that are always dispatched to our - // internal handler, no matter if there is a grab or not. - switch(event->type) - { - case GDK_NOTHING: - break; - - case GDK_DESTROY: - case GDK_DELETE: - case GDK_PROPERTY_NOTIFY: - case GDK_EXPOSE: - case GDK_NO_EXPOSE: - case GDK_FOCUS_CHANGE: - case GDK_CONFIGURE: - case GDK_MAP: - case GDK_UNMAP: - case GDK_SELECTION_CLEAR: - case GDK_SELECTION_REQUEST: - case GDK_SELECTION_NOTIFY: - case GDK_CLIENT_EVENT: - case GDK_VISIBILITY_NOTIFY: - dispatch_superwin_event(event, window); - break; - - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - // If we need to rewrite this to the nearest real gtk widget, - // do it here. - if (rewriteEvent) { - gdk_window_unref(event->any.window); - event->any.window = owningWidget->window; - gdk_window_ref(event->any.window); - gtk_main_do_event(event); - break; - } - - // Otherwise, just send it to our event handler - if (GTK_WIDGET_IS_SENSITIVE(owningWidget)) - dispatch_superwin_event(event, window); - break; - - case GDK_MOTION_NOTIFY: - case GDK_BUTTON_RELEASE: - case GDK_PROXIMITY_IN: - case GDK_PROXIMITY_OUT: - // See above. - if (rewriteEvent) { - gdk_window_unref(event->any.window); - event->any.window = owningWidget->window; - gdk_window_ref(event->any.window); - gtk_propagate_event(grabWidget, event); - break; - } - - if (GTK_WIDGET_IS_SENSITIVE(owningWidget)) - dispatch_superwin_event(event, window); - break; - - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - // Always dispatch enter and leave notify events to the - // windows that they happened on so that state can be properly - // tracked. The code that handles the enter and leave events - // tracks sensitivity as well. - dispatch_superwin_event(event, window); - break; - - default: - // XXX lots of DND events not handled? I don't think that we have to. - NS_WARNING("Odd, hit default case in handle_gdk_event()\n"); - break; - } - } - else { - nsWindow *grabbingWindow = nsWindow::GetGrabWindow(); - - nsCOMPtr grabbingWindowGuard(grabbingWindow); - GtkWidget *tempWidget = NULL; - - if (grabbingWindow) { - // get the GdkWindow that we are grabbing on - GdkWindow *grabbingGdkWindow = - NS_STATIC_CAST(GdkWindow *, - grabbingWindow->GetNativeData(NS_NATIVE_WINDOW)); - - // If the object getting the event in question is a GtkWidget - // and it's a child of the grabbing window, we need to put a - // grab on that window before dispatching the event. We do this - // so that the gtk mainloop will recognize the widget in - // question as having the grab. If we didn't the mainloop - // wouldn't think that the widget that got the event is the - // child of the grabbing window, due to the superwin(s) in the - // middle. - if (GTK_IS_WIDGET(eventObject)) { - tempWidget = GTK_WIDGET(eventObject); - if (gdk_window_child_of_gdk_window(tempWidget->window, - grabbingGdkWindow)) { - // this is so awesome. gtk_grab_add/gtk_grab_remove don't - // have exact push and pop semantics. if we call grab_add - // on the object and as part of the dispatching of this - // event another grab_add is called on it, we can end up - // releasing the grab early because we always call - // grab_remove on the object after dispatching the event. - // we can end up with a widget that doesn't have a grab on - // it, even though it should. the scrollbar does this. - // - // so, what we do here is to check and see if the widget in - // question has a parent. if it does and it's a mozbox - // object we slam a grab on that instead of the widget - // itself. we know that no one is doing grabs on those. - if (tempWidget->parent) { - if (GTK_IS_MOZBOX(tempWidget->parent)) { - tempWidget = tempWidget->parent; - } - } - gtk_grab_add(tempWidget); - } - else { - // if the gtk widget in question wasn't the child of the - // grabbing window then the grabbing window gets it. - dispatch_superwin_event(event, grabbingWindow); - goto end; - } - } - } - - gtk_main_do_event(event); - - if (tempWidget) - gtk_grab_remove(tempWidget); - - if (event->type == GDK_BUTTON_RELEASE) { - // Always clear the button motion target when sending a - // button release event to a real gtk widget, otherwise - // mozilla will still think it has the grab. This happens - // when there's a native gtk widget popup over a Mozilla - // area. - nsWidget::DropMotionTarget(); - } - } - - end: - ; - -#if 0 - // use the saved serial to process any pending events, now that all - // the window events have been processed - if (serial) - nsAppShell::ProcessBeforeID(serial); -#endif - -} - -void -dispatch_superwin_event(GdkEvent *event, nsWindow *window) -{ - if (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE) - { - // Check to see whether or not we need to send this to the - // toplevel window to get passed to the GtkWidget with focus. - // This happens in the embedding case. - if (!nsWidget::sFocusWindow) - { - GtkWidget *mozArea = window->GetOwningWidget(); - NS_ASSERTION(mozArea, "Failed to get GtkMozArea for superwin event!\n"); - // get the toplevel window for that widget - GtkWidget *toplevel = gtk_widget_get_toplevel(mozArea); - // pass it off to gtk's event system and return - gboolean handled = gtk_widget_event(toplevel, event); - if (handled) - return; - } - } - - switch (event->type) - { - case GDK_KEY_PRESS: - handle_key_press_event (NULL, &event->key, window); - break; - case GDK_KEY_RELEASE: - handle_key_release_event (NULL, &event->key, window); - break; - default: - window->HandleGDKEvent (event); - break; - } -} - -PRBool -gdk_window_child_of_gdk_window(GdkWindow *window, GdkWindow *ancestor) -{ - GdkWindow *this_window = window; - while (this_window) - { - if (this_window == ancestor) - return PR_TRUE; - this_window = gdk_window_get_parent(this_window); - } - return PR_FALSE; -} - - -//============================================================== -void -handle_xlib_shell_event(GdkSuperWin *superwin, XEvent *event, gpointer p) -{ - nsWindow *window = (nsWindow *)p; - switch(event->xany.type) { - case ConfigureNotify: - window->HandleXlibConfigureNotifyEvent(event); - break; - default: - break; - } -} - -//============================================================== -void -handle_superwin_paint(gint aX, gint aY, - gint aWidth, gint aHeight, gpointer aData) -{ - nsWindow *window = (nsWindow *)aData; - nsRect rect; - rect.x = aX; - rect.y = aY; - rect.width = aWidth; - rect.height = aHeight; - window->Invalidate(rect, PR_FALSE); -} - -void -handle_superwin_flush(gpointer aData) -{ - nsWindow *window = (nsWindow *)aData; - window->Update(); -} - - - diff --git a/mozilla/widget/src/gtk/nsGtkEventHandler.h b/mozilla/widget/src/gtk/nsGtkEventHandler.h deleted file mode 100644 index c54df1d71d4..00000000000 --- a/mozilla/widget/src/gtk/nsGtkEventHandler.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsGtkEventHandler_h -#define __nsGtkEventHandler_h - -#include -#include -#include "gdksuperwin.h" - -void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p); - -gint handle_key_release_event(GtkObject *w, GdkEventKey* event, gpointer p); -gint handle_key_press_event(GtkObject *w, GdkEventKey* event, gpointer p); - -//---------------------------------------------------- - -void handle_xlib_shell_event(GdkSuperWin *superwin, XEvent *event, gpointer p); -void handle_superwin_paint(gint aX, gint aY, - gint aWidth, gint aHeight, gpointer aData); -void handle_superwin_flush(gpointer aData); -void handle_gdk_event (GdkEvent *event, gpointer data); - -#endif // __nsGtkEventHandler.h diff --git a/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp b/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp deleted file mode 100644 index f8f022a08f9..00000000000 --- a/mozilla/widget/src/gtk/nsGtkIMEHelper.cpp +++ /dev/null @@ -1,1642 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Frank Tang - * IBM Corporation - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#include - -#include "nsGUIEvent.h" -#include "nsGtkIMEHelper.h" -#include "nsIUnicodeDecoder.h" -#include "nsIPlatformCharset.h" -#include "nsICharsetConverterManager.h" -#include "nsIServiceManager.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include -#include "nsCRT.h" - -#include "nsWindow.h" - -#ifdef USE_XIM - -nsIMEStatus *nsIMEGtkIC::gStatus = 0; -nsWindow *nsIMEGtkIC::gGlobalFocusWindow = 0; - -#endif // USE_XIM - -nsGtkIMEHelper* nsGtkIMEHelper::gSingleton = nsnull; - -nsGtkIMEHelper* nsGtkIMEHelper::GetSingleton() -{ - if(! gSingleton) - gSingleton = new nsGtkIMEHelper(); - NS_ASSERTION(gSingleton, "do not have singleton"); - return gSingleton; -} - -/*static*/ void nsGtkIMEHelper::Shutdown() -{ - if (gSingleton) { - delete gSingleton; - gSingleton = nsnull; - } -} -//----------------------------------------------------------------------- - -nsGtkIMEHelper::nsGtkIMEHelper() -{ - MOZ_COUNT_CTOR(nsGtkIMEHelper); - SetupUnicodeDecoder(); - -#if defined(USE_XIM) && defined (_AIX) - mUnicharsSize = 2; - mUnichars = new PRUnichar[mUnicharsSize]; -#endif -} -nsGtkIMEHelper::~nsGtkIMEHelper() -{ - MOZ_COUNT_DTOR(nsGtkIMEHelper); - NS_IF_RELEASE(mDecoder); - -#if defined(USE_XIM) && defined(_AIX) - if (mUnichars) { - delete[] mUnichars; - mUnichars = nsnull; - } -#endif -} -//----------------------------------------------------------------------- -nsresult -nsGtkIMEHelper::ConvertToUnicode( const char* aSrc, PRInt32* aSrcLen, - PRUnichar* aDest, PRInt32* aDestLen) -{ - NS_ASSERTION(mDecoder, "do not have mDecoder"); - if(! mDecoder) - return NS_ERROR_ABORT; - return mDecoder->Convert(aSrc, aSrcLen, aDest, aDestLen); -} - -void -nsGtkIMEHelper::ResetDecoder() -{ - NS_ASSERTION(mDecoder, "do not have mDecoder"); - if(mDecoder) { - mDecoder->Reset(); - } -} - -//----------------------------------------------------------------------- -void nsGtkIMEHelper::SetupUnicodeDecoder() -{ - mDecoder = nsnull; - nsresult result = NS_ERROR_FAILURE; - nsCOMPtr platform = - do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &result); - if (platform && NS_SUCCEEDED(result)) { - nsCAutoString charset; - charset.Truncate(); - result = platform->GetCharset(kPlatformCharsetSel_Menu, charset); - if (NS_FAILED(result) || charset.IsEmpty()) { - charset.AssignLiteral("ISO-8859-1"); // default - } - nsICharsetConverterManager* manager = nsnull; - nsresult res = CallGetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &manager); - if (manager && NS_SUCCEEDED(res)) { - manager->GetUnicodeDecoderRaw(charset.get(), &mDecoder); - NS_RELEASE(manager); - } - } - NS_ASSERTION(mDecoder, "cannot get decoder"); -} - -PRInt32 -nsGtkIMEHelper::MultiByteToUnicode(const char *aMbSrc, - const PRInt32 aMbSrcLen, - PRUnichar **aUniDes, - PRInt32 *aUniDesLen) -{ - nsresult res; - PRInt32 srcLeft; - PRUnichar *uniCharLeft; - PRInt32 uniCharSize = 0; - - if (nsGtkIMEHelper::GetSingleton()) { - if (!*aUniDes || *aUniDesLen == 0) { - *aUniDesLen = 128; - *aUniDes = new PRUnichar[*aUniDesLen]; - } - for (;;) { - if (*aUniDes == nsnull) { - uniCharSize = 0; - break; - } - uniCharLeft = *aUniDes; - uniCharSize = *aUniDesLen - 1; - srcLeft = aMbSrcLen; - res = nsGtkIMEHelper::GetSingleton()->ConvertToUnicode( - (char *)aMbSrc, &srcLeft, uniCharLeft, &uniCharSize); - if (NS_ERROR_ABORT == res) { - uniCharSize = 0; - break; - } - if (srcLeft == aMbSrcLen && uniCharSize < *aUniDesLen - 1) { - break; - } - nsGtkIMEHelper::GetSingleton()->ResetDecoder(); - *aUniDesLen += 32; - if (aUniDes) { - delete[] *aUniDes; - } - *aUniDes = new PRUnichar[*aUniDesLen]; - } - } - return uniCharSize; -} - -#ifdef USE_XIM -nsIMEPreedit::nsIMEPreedit() -{ - mCaretPosition = 0; - mIMECompUnicode = new nsAutoString(); - mIMECompAttr = new nsCAutoString(); - mCompositionUniString = 0; - mCompositionUniStringSize = 0; -} - -nsIMEPreedit::~nsIMEPreedit() -{ - mCaretPosition = 0; - delete mIMECompUnicode; - delete mIMECompAttr; - if (mCompositionUniString) { - delete[] mCompositionUniString; - } - mCompositionUniString = 0; - mCompositionUniStringSize = 0; -} - -void nsIMEPreedit::Reset() -{ - mCaretPosition = 0; - mIMECompUnicode->SetCapacity(0); - mIMECompAttr->SetCapacity(0); -} - -const PRUnichar* -nsIMEPreedit::GetPreeditString() const { - return mIMECompUnicode->get(); -} - -const char* -nsIMEPreedit::GetPreeditFeedback() const { - return mIMECompAttr->get(); -} - -int nsIMEPreedit::GetPreeditLength() const { - return mIMECompUnicode->Length(); -} - -void nsIMEPreedit::SetPreeditString(const XIMText *aText, - const PRInt32 aChangeFirst, - const PRInt32 aChangeLength) -{ - PRInt32 composeUniStringLen = 0; - char *preeditStr = 0; - int preeditLen = 0; - XIMFeedback *preeditFeedback = 0; - - if (aText){ - if (aText->encoding_is_wchar) { - if (aText->string.wide_char) { - int len = wcstombs(NULL, aText->string.wide_char, aText->length); - if (len != -1) { - preeditStr = new char [len + 1]; - wcstombs(preeditStr, aText->string.wide_char, len); - preeditStr[len] = 0; - } - } - } else { - preeditStr = aText->string.multi_byte; - } - preeditLen = aText->length; - preeditFeedback = aText->feedback; - } - - if (preeditStr && nsGtkIMEHelper::GetSingleton()) { - composeUniStringLen = - nsGtkIMEHelper::GetSingleton()->MultiByteToUnicode( - preeditStr, - strlen(preeditStr), - &(mCompositionUniString), - &(mCompositionUniStringSize)); - if (aText && aText->encoding_is_wchar) { - delete [] preeditStr; - } - } - - if (composeUniStringLen != preeditLen) { - Reset(); - return; - } - - if (aChangeLength && mIMECompUnicode->Length()) { - mIMECompUnicode->Cut(aChangeFirst, aChangeLength); - mIMECompAttr->Cut(aChangeFirst, aChangeLength); - } - - if (composeUniStringLen) { - mIMECompUnicode->Insert(mCompositionUniString, - aChangeFirst, - composeUniStringLen); - char *feedbackAttr = new char[composeUniStringLen]; - char *pFeedbackAttr; - for (pFeedbackAttr = feedbackAttr; - pFeedbackAttr < &feedbackAttr[composeUniStringLen]; - pFeedbackAttr++) { - switch (*preeditFeedback++) { - case XIMReverse: - *pFeedbackAttr = NS_TEXTRANGE_SELECTEDRAWTEXT; - break; - case XIMUnderline: - *pFeedbackAttr = NS_TEXTRANGE_CONVERTEDTEXT; - break; - default: - *pFeedbackAttr = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT; - } - } - mIMECompAttr->Insert((const char*)feedbackAttr, - aChangeFirst, - composeUniStringLen); - delete [] feedbackAttr; - } -} - -#define START_OFFSET(I) \ - (*aTextRangeListResult)[I].mStartOffset - -#define END_OFFSET(I) \ - (*aTextRangeListResult)[I].mEndOffset - -#define SET_FEEDBACK(F, I) (*aTextRangeListResult)[I].mRangeType = F - -void -nsIMEPreedit::IMSetTextRange(const PRInt32 aLen, - const char *aFeedback, - PRUint32 *aTextRangeListLengthResult, - nsTextRangeArray *aTextRangeListResult) -{ - int i; - char *feedbackPtr = (char*)aFeedback; - - int count = 1; - - /* count number of feedback */ - char f = *feedbackPtr; - for (i = 0; i < aLen; i++, feedbackPtr++) { - if (f != *feedbackPtr) { - f = *feedbackPtr; - count++; - } - } - - /* for NS_TEXTRANGE_CARETPOSITION */ - count++; - - /* alloc nsTextRange */ - feedbackPtr = (char*)aFeedback; - *aTextRangeListLengthResult = count; - *aTextRangeListResult = new nsTextRange[count]; - - count = 0; - - /* Set NS_TEXTRANGE_CARETPOSITION */ - (*aTextRangeListResult)[count].mRangeType = NS_TEXTRANGE_CARETPOSITION; - START_OFFSET(count) = aLen; - END_OFFSET(count) = aLen; - - if (aLen == 0){ - return; - } - - count++; - - f = *feedbackPtr; - SET_FEEDBACK(f, count); - - START_OFFSET(count) = 0; - (*aTextRangeListResult)[count].mStartOffset = 0; - - /* set TextRange */ - for (i = 0; i < aLen; i++, feedbackPtr++) { - if (f != *feedbackPtr) { - END_OFFSET(count) = i; - f = *feedbackPtr; - count++; - SET_FEEDBACK(f, count); - START_OFFSET(count) = i; - } - } - END_OFFSET(count) = aLen; - -#ifdef NOISY_XIM - printf("IMSetTextRange()\n"); - for (i = 0; i < *textRangeListLengthResult; i++) { - printf(" i=%d start=%d end=%d attr=%d\n", - i, - (*textRangeListResult)[i].mStartOffset, - (*textRangeListResult)[i].mEndOffset, - (*textRangeListResult)[i].mRangeType); - } -#endif /* NOISY_XIM */ -} - -extern "C" { - extern void - _XRegisterFilterByType(Display *display, Window window, - int start_type, int end_type, - Bool (*filter)(Display*, Window, - XEvent*, XPointer), - XPointer client_data); - extern void - _XUnregisterFilter(Display *display, Window window, - Bool (*filter)(Display*, Window, - XEvent*, XPointer), - XPointer client_data); - extern int _XDefaultError(Display*, XErrorEvent*); -} - -void -nsIMEStatus::DestroyNative() { -} - -nsIMEStatus::nsIMEStatus() { - mWidth = 0; - mHeight = 0; - mFontset = 0; - CreateNative(); -} - -nsIMEStatus::nsIMEStatus(GdkFont *aFontset) { - mWidth = 0; - mHeight = 0; - mFontset = 0; - if (aFontset->type == GDK_FONT_FONTSET) { - mFontset = (XFontSet) GDK_FONT_XFONT(aFontset); - } - CreateNative(); -} - -nsIMEStatus::~nsIMEStatus() { - DestroyNative(); -} - -void -nsIMEStatus::SetFont(GdkFont *aFontset) { - if (!mAttachedWindow) { - return; - } - nsIMEGtkIC *xic = mAttachedWindow->IMEGetInputContext(PR_FALSE); - if (xic && xic->mStatusText) { - if (aFontset->type == GDK_FONT_FONTSET) { - mFontset = (XFontSet) GDK_FONT_XFONT(aFontset); - resize(xic->mStatusText); - } - } -} - -void -AdjustPlacementInsideScreen(Display * dpy, Window win, - int x, int y, - int width, int height, - int * ret_x, int * ret_y) { - XWindowAttributes attr; - int dpy_width; - int dpy_height; - int screen_num; - - width += 20; - height += 20; - - if (XGetWindowAttributes(dpy, win, &attr) > 0) { - screen_num = XScreenNumberOfScreen(attr.screen); - } else { - screen_num = 0; - } - - dpy_width = DisplayWidth(dpy, screen_num); - dpy_height = DisplayHeight(dpy, screen_num); - - if (dpy_width < (x + width)) { - if (width <= dpy_width) { - *ret_x = (dpy_width - width); - } else { - *ret_x = 0; - } - } else { - *ret_x = x; - } - - if (dpy_height < (y + height)) { - if (height <= dpy_height) { - *ret_y = (dpy_height - height); - } else { - *ret_y = 0; - } - } else { - *ret_y = y; - } -} - -int -validateCoordinates(Display * display, Window w, - int *x, int *y) { - XWindowAttributes attr; - int newx, newy; - if (XGetWindowAttributes(display, w, &attr) > 0) { - AdjustPlacementInsideScreen(display, w, *x, *y, - attr.width, attr.height, - &newx, &newy); - *x = newx; - *y = newy; - } - return 0; -} - -void -nsIMEStatus::hide() { - Display *display = GDK_DISPLAY(); - int screen = DefaultScreen(display); - XWindowAttributes win_att; - if (XGetWindowAttributes(display, mIMStatusWindow, - &win_att) > 0) { - if (win_att.map_state != IsUnmapped) { - XWithdrawWindow(display, mIMStatusWindow, screen); - } - } - return; -} - -void -nsIMEStatus::UnregisterClientFilter(Window aWindow) { - Display *display = GDK_DISPLAY(); - _XUnregisterFilter(display, aWindow, - client_filter, (XPointer)this); -} - -void -nsIMEStatus::RegisterClientFilter(Window aWindow) { - Display *display = GDK_DISPLAY(); - _XRegisterFilterByType(display, aWindow, - ConfigureNotify, ConfigureNotify, - client_filter, - (XPointer)this); - _XRegisterFilterByType(display, aWindow, - DestroyNotify, DestroyNotify, - client_filter, - (XPointer)this); -} - -// when referred nsWindow is destroyed, reset to 0 -void -nsIMEStatus::resetParentWindow(nsWindow *aWindow) { - if (mAttachedWindow == aWindow) { - mAttachedWindow = 0; - } -} - -void -nsIMEStatus::setParentWindow(nsWindow *aWindow) { - GdkWindow *gdkWindow = (GdkWindow*)aWindow->GetNativeData(NS_NATIVE_WINDOW); - GdkWindow *newParentGdk = gdk_window_get_toplevel(gdkWindow); - - // mAttachedWindow is set to 0 when target window is destroyed - // set aWindow to this even if newParentGdk == mParent case - // keep focused (target) Window as mAttachedWindow - mAttachedWindow = aWindow; - - if (newParentGdk != mParent) { - hide(); - if (mParent) { - UnregisterClientFilter(GDK_WINDOW_XWINDOW(mParent)); - } - mParent = newParentGdk; - if (mIMStatusWindow) { - Display *display = GDK_DISPLAY(); - XSetTransientForHint(display, mIMStatusWindow, - GDK_WINDOW_XWINDOW(newParentGdk)); - RegisterClientFilter(GDK_WINDOW_XWINDOW(newParentGdk)); - } - } -} - -Bool -nsIMEStatus::client_filter(Display *aDisplay, Window aWindow, - XEvent *aEvent, XPointer aClientData) { - nsIMEStatus *thiswindow = (nsIMEStatus*)aClientData; - if (thiswindow && NULL != aEvent) { - if (ConfigureNotify == aEvent->type) { - thiswindow->show(); - } else if (DestroyNotify == aEvent->type) { - thiswindow->UnregisterClientFilter(aWindow); - thiswindow->hide(); - thiswindow->mAttachedWindow = 0; - } - } - return False; -} - -Bool -nsIMEStatus::repaint_filter(Display *aDisplay, Window aWindow, - XEvent *aEvent, XPointer aClientData) { - if (aEvent->xexpose.count != 0) return True; - nsIMEStatus *thiswindow = (nsIMEStatus*)aClientData; - if (thiswindow && thiswindow->mAttachedWindow) { - nsIMEGtkIC *xic = thiswindow->mAttachedWindow->IMEGetInputContext(PR_FALSE); - if (xic && xic->mStatusText) { - if(!*xic->mStatusText) { - thiswindow->hide(); - } else { - thiswindow->setText(xic->mStatusText); - } - } - } - return True; -} - -// referring to gdk_wm_protocols_filter in gtk+/gdk/gdkevent.c -Bool -nsIMEStatus::clientmessage_filter(Display *aDisplay, Window aWindow, - XEvent *aEvent, XPointer aClientData) { - Atom wm_delete_window = XInternAtom(aDisplay, "WM_DELETE_WINDOW", False); - if ((Atom)aEvent->xclient.data.l[0] == wm_delete_window) { - // The delete window request specifies a window - // to delete. We don't actually destroy the - // window because "it is only a request" - return True; - } - return False; -} - -void -nsIMEStatus::CreateNative() { - mGC = 0; - mParent = 0; - mAttachedWindow = 0; - - Display *display = GDK_DISPLAY(); - - if (!mFontset) { - const char *base_font_name = "-*-*-*-*-*-*-16-*-*-*-*-*-*-*"; - char **missing_list; - int missing_count; - char *def_string; - mFontset = XCreateFontSet(display, base_font_name, &missing_list, - &missing_count, &def_string); - } - - if (!mFontset) { -#ifdef DEBUG - printf("Error : XCreateFontSet() !\n"); -#endif - return; - } - int screen = DefaultScreen(display); - unsigned long bpixel = BlackPixel(display, screen); - unsigned long fpixel = WhitePixel(display, screen); - Window root = RootWindow(display, screen); - - XFontSetExtents *fse; - fse = XExtentsOfFontSet(mFontset); - mHeight = fse->max_logical_extent.height; - mHeight += (fse->max_ink_extent.height + fse->max_ink_extent.y); - - if (mWidth == 0) mWidth = 1; - if (mHeight == 0) mHeight = 1; - mIMStatusWindow = XCreateSimpleWindow(display, root, 0, 0, - mWidth, mHeight, 2, - bpixel, fpixel); - if (!mIMStatusWindow) return; - - _XRegisterFilterByType(display, mIMStatusWindow, - Expose, Expose, - repaint_filter, - (XPointer)this); - _XRegisterFilterByType(display, mIMStatusWindow, - ClientMessage, ClientMessage, - clientmessage_filter, - (XPointer)this); - - // For XIM status window, we must watch wm_delete_window only, - // but not wm_take_focus, since the window shoud not take focus. - // - // gdk_window_new forces all toplevel windows to watch both of wm - // protocols, which is one of the reasons we cannot use gdk for - // creating and managing the XIM status window. - Atom wm_window_protocols[1]; - Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", False); - wm_window_protocols[0] = wm_delete_window; - XSetWMProtocols(display, mIMStatusWindow, - wm_window_protocols, 1); - remove_decoration(); - - // The XIM status window does not expect keyboard input, so we need to - // set wm_input_hint of XWMhints to False. However, gdk_window_new() - // always set it to True, and there is no way to override it. The attempt - // to set input hint to False after we do gdk_window_new() did not work - // well either in GNOME or CDE environment. - XWMHints wm_hints; - wm_hints.flags = InputHint; - wm_hints.input = False; - XSetWMHints(display, mIMStatusWindow, &wm_hints); - - XStoreName(display, mIMStatusWindow, "Mozilla IM Status"); - - XClassHint class_hint; - class_hint.res_name = "mozilla-im-status"; - class_hint.res_class = "MozillaImStatus"; - XSetClassHint(display, mIMStatusWindow, &class_hint); - - long mask = ExposureMask; - XSelectInput(display, mIMStatusWindow, mask); -} - -void -nsIMEStatus::resize(const char *aString) { - Display *display = GDK_DISPLAY(); - if (!aString || !aString[0]) return; - int len = strlen(aString); - - int width = XmbTextEscapement(mFontset, aString, len); - - if (!width) return; - - XWindowChanges changes; - int mask = CWWidth; - changes.width = width; - XConfigureWindow(display, mIMStatusWindow, - mask, &changes); - mWidth = width; - return; -} - -// public -void -nsIMEStatus::show() { - if (!mAttachedWindow) { - return; - } - - nsIMEGtkIC *xic = mAttachedWindow->IMEGetInputContext(PR_FALSE); - - if (!xic || !xic->mStatusText || !strlen(xic->mStatusText)) { - // don't map if text is "" - return; - } - - Display *display = GDK_DISPLAY(); - - if (!mIMStatusWindow) { - CreateNative(); - } - - XWindowAttributes win_att; - int wx, wy; - Window w_none; - Window parent = GDK_WINDOW_XWINDOW(mParent); - - // parent window is destroyed - if (!parent || ((GdkWindowPrivate*)mParent)->destroyed) { - return; - } - - // parent window exists but isn't mapped yet - if (XGetWindowAttributes(display, parent, - &win_att) > 0) { - if (win_att.map_state == IsUnmapped) { - return; - } - } - - if (XGetWindowAttributes(display, parent, &win_att) > 0) { - XTranslateCoordinates(display, parent, - win_att.root, - -(win_att.border_width), - -(win_att.border_width), - &wx, &wy, &w_none); - wy += win_att.height; - - // adjust position - validateCoordinates(display,mIMStatusWindow, - &wx, &wy); - - // set position - // Linux window manager doesn't work properly - // when only XConfigureWindow() is called - XSizeHints xsh; - (void) memset(&xsh, 0, sizeof(xsh)); - xsh.flags |= USPosition; - xsh.x = wx; - xsh.y = wy; - XSetWMNormalHints(display, mIMStatusWindow, &xsh); - - XWindowChanges changes; - int mask = CWX|CWY; - changes.x = wx; - changes.y = wy; - XConfigureWindow(display, mIMStatusWindow, - mask, &changes); - } - - if (XGetWindowAttributes(display, mIMStatusWindow, - &win_att) > 0) { - if (win_att.map_state == IsUnmapped) { - XMapWindow(display, mIMStatusWindow); - } - } - return; -} - -void -nsIMEStatus::setText(const char *aText) { - Display *display = GDK_DISPLAY(); - if (!aText) return; - - int len = strlen(aText); - - if (mGC == 0) { - XGCValues values; - unsigned long values_mask; - - int screen = DefaultScreen(display); - unsigned long bpixel = BlackPixel(display, screen); - unsigned long fpixel = WhitePixel(display, screen); - values.foreground = bpixel; - values.background = fpixel; - values_mask = GCBackground | GCForeground; - mGC = XCreateGC(display, mIMStatusWindow, values_mask, &values); - } - XClearArea(display, mIMStatusWindow, 0, 0, 0, 0, False); - - resize(aText); - - XFontSetExtents *fse; - fse = XExtentsOfFontSet(mFontset); - int bottom_margin = fse->max_logical_extent.height/6; - int y = fse->max_logical_extent.height - bottom_margin; - XmbDrawString(display, mIMStatusWindow, mFontset, mGC, - 0, y, aText, len); - return; -} - -static Atom ol_del_atom = (Atom)0; -static Atom ol_del_atom_list[3]; -static int ol_atom_inx = 0; -static Atom mwm_del_atom = (Atom)0; - -void -nsIMEStatus::getAtoms() { - Display *display = GDK_DISPLAY(); - if (!mwm_del_atom) { - mwm_del_atom = XInternAtom(display, "_MOTIF_WM_HINTS", True); - } - if (!ol_del_atom) { - ol_del_atom = XInternAtom(display, "_OL_DECOR_DEL", True); - ol_del_atom_list[ol_atom_inx++] = - XInternAtom(display, "_OL_DECOR_RESIZE", True); - ol_del_atom_list[ol_atom_inx++] = - XInternAtom(display, "_OL_DECOR_HEADER", True); - } -} - -#define MWM_DECOR_BORDER (1L << 1) - -void -nsIMEStatus::remove_decoration() { - Display *display = GDK_DISPLAY(); - struct _mwmhints { - unsigned long flags, func, deco; - long input_mode; - unsigned long status; - } mwm_del_hints; - - getAtoms(); - - if (mwm_del_atom != None) { - mwm_del_hints.flags = 1L << 1; /* flags for decoration */ - mwm_del_hints.deco = MWM_DECOR_BORDER; - XChangeProperty(display, mIMStatusWindow, - mwm_del_atom, mwm_del_atom, 32, - PropModeReplace, - (unsigned char *)&mwm_del_hints, 5); - } - if (ol_del_atom != None) { - XChangeProperty(display, mIMStatusWindow, ol_del_atom, XA_ATOM, 32, - PropModeReplace, (unsigned char*)ol_del_atom_list, - ol_atom_inx); - } -} - - -/* callbacks */ -int -nsIMEGtkIC::preedit_start_cbproc(XIC xic, XPointer client_data, - XPointer call_data) -{ - nsIMEGtkIC *thisXIC = (nsIMEGtkIC*)client_data; - if (!thisXIC) return 0; - nsWindow *fwin = thisXIC->mFocusWindow; - if (!fwin) return 0; - - if (!thisXIC->mPreedit) { - thisXIC->mPreedit = new nsIMEPreedit(); - } - thisXIC->mPreedit->Reset(); - fwin->ime_preedit_start(); - return 0; -} - -int -nsIMEGtkIC::preedit_draw_cbproc(XIC xic, XPointer client_data, - XPointer call_data_p) -{ - nsIMEGtkIC *thisXIC = (nsIMEGtkIC*)client_data; - if (!thisXIC) return 0; - nsWindow *fwin = thisXIC->mFocusWindow; - if (!fwin) return 0; - - XIMPreeditDrawCallbackStruct *call_data = - (XIMPreeditDrawCallbackStruct *) call_data_p; - XIMText *text = (XIMText *) call_data->text; - - if (!thisXIC->mPreedit) { - thisXIC->mPreedit = new nsIMEPreedit(); - } - thisXIC->mPreedit->SetPreeditString(text, - call_data->chg_first, - call_data->chg_length); - fwin->ime_preedit_draw(thisXIC); - return 0; -} - -int -nsIMEGtkIC::preedit_done_cbproc(XIC xic, XPointer client_data, - XPointer call_data_p) -{ - nsIMEGtkIC *thisXIC = (nsIMEGtkIC*)client_data; - if (!thisXIC) return 0; - nsWindow *fwin = thisXIC->mFocusWindow; - if (!fwin) return 0; - - fwin->ime_preedit_done(); - return 0; -} - -int -nsIMEGtkIC::status_draw_cbproc(XIC xic, XPointer client_data, - XPointer call_data_p) -{ - nsIMEGtkIC *thisXIC = (nsIMEGtkIC*)client_data; - if (!thisXIC) return 0; - nsWindow *fwin = thisXIC->mFocusWindow; - if (!fwin) return 0; - if (!gStatus) return 0; - nsWindow *win = gStatus->mAttachedWindow; - if (!win) return 0; - nsIMEGtkIC *ic = win->IMEGetInputContext(PR_FALSE); - PRBool update = PR_TRUE; - - // sometimes the focused IC != this IC happens when focus - // is changed. To avoid this case, check current IC of - // gStatus and thisXIC - if (thisXIC != ic) { - // do not update status, just store status string - // for the correct IC - update = PR_FALSE; - } - - XIMStatusDrawCallbackStruct *call_data = - (XIMStatusDrawCallbackStruct *) call_data_p; - - if (call_data->type == XIMTextType) { - XIMText *text = (XIMText *) call_data->data.text; - if (!text || !text->length) { - // turn conversion off - thisXIC->SetStatusText(""); - if (update) { - gStatus->setText(""); - gStatus->hide(); - } - } else { - char *statusStr = 0; - if (text->encoding_is_wchar) { - if (text->string.wide_char) { - int len = wcstombs(NULL, text->string.wide_char, text->length); - if (len != -1) { - statusStr = new char [len + 1]; - wcstombs(statusStr, text->string.wide_char, len); - statusStr[len] = 0; - } - } - } else { - statusStr = text->string.multi_byte; - } - // turn conversion on - thisXIC->SetStatusText(statusStr); - if (update) { - gStatus->setText(statusStr); - gStatus->show(); - } - if (statusStr && text->encoding_is_wchar) { - delete [] statusStr; - } - } - } - return 0; -} - -nsWindow * -nsIMEGtkIC::GetFocusWindow() -{ - return mFocusWindow; -} - -nsWindow * -nsIMEGtkIC::GetGlobalFocusWindow() -{ - return gGlobalFocusWindow; -} - -// workaround for kinput2/over-the-spot/ic-per-shell -// http://bugzilla.mozilla.org/show_bug.cgi?id=28022 -// -// When ic is created with focusWindow is shell widget -// (not per widget), kinput2 never updates the pre-edit -// position until -// - focusWindow is changed -// Unfortunately it does not affect to the position of -// status window. -// -// we don't have any solution for status window position because -// kinput2 updates only when -// - client window is changed -// - turn conversion on/off -// we don't have any interface to do those from here. -// there is one workaround for status window that to set -// the following -// *OverTheSpotConversion.modeLocation: bottomleft - -void -nsIMEGtkIC::SetFocusWindow(nsWindow * aFocusWindow) -{ - mFocusWindow = aFocusWindow; - gGlobalFocusWindow = aFocusWindow; - - GdkWindow *gdkWindow = (GdkWindow*)aFocusWindow->GetNativeData(NS_NATIVE_WINDOW); - if (!gdkWindow) return; - - if (mInputStyle & GDK_IM_STATUS_CALLBACKS) { - if (gStatus) { - gStatus->setParentWindow(aFocusWindow); - } - } - - gdk_im_begin((GdkIC *) mIC, gdkWindow); - - if (mInputStyle & GDK_IM_PREEDIT_POSITION) { - static int oldw=0; - static int oldh=0; - int neww=(int)((GdkWindowPrivate*)gdkWindow)->width; - int newh=(int)((GdkWindowPrivate*)gdkWindow)->height; - if (oldw != neww || oldh != newh) { - SetPreeditArea(0, 0, neww, newh); - oldw = neww; - oldh = newh; - } - } - - if (mInputStyle & GDK_IM_STATUS_CALLBACKS) { - if (gStatus && mStatusText) { - gStatus->setText(mStatusText); - gStatus->show(); - } - } -} - -void -nsIMEGtkIC::ResetStatusWindow(nsWindow *aWindow) -{ - if (gStatus) { - gStatus->resetParentWindow(aWindow); - } -} - -void -nsIMEGtkIC::UnsetFocusWindow() -{ - gdk_im_end(); -} - -nsIMEGtkIC *nsIMEGtkIC::GetXIC(nsWindow * aFocusWindow, GdkFont *aFontSet) -{ - return nsIMEGtkIC::GetXIC(aFocusWindow, aFontSet, 0); -} - -nsIMEGtkIC *nsIMEGtkIC::GetXIC(nsWindow * aFocusWindow, - GdkFont *aFontSet, GdkFont *aStatusFontSet) -{ - nsIMEGtkIC *newic = new nsIMEGtkIC(aFocusWindow, aFontSet, aStatusFontSet); - if (!newic->mIC || !newic->mIC->xic) { - delete newic; - return nsnull; - } - return newic; -} - -nsIMEGtkIC::~nsIMEGtkIC() -{ - /* XSetTransientForHint does not work for popup-shell, workaround */ - if (gStatus) { - gStatus->hide(); - } - - if (mPreedit) { - delete mPreedit; - } - - if (mIC) { - // destroy a real XIC - gdk_ic_destroy((GdkIC *) mIC); - } - - if (mIC_backup) { - // destroy a dummy XIC, see the comment in nsIMEGtkIC constructor. - gdk_ic_destroy((GdkIC *) mIC_backup); - } - - if (mStatusText) { - nsCRT::free(mStatusText); - } - - mIC = 0; - mIC_backup = 0; - mPreedit = 0; - mFocusWindow = 0; - mStatusText = 0; -} - -// xim.input_style: -// -// "xim.input_style" preference is for switching XIM input style. -// We can use the easy understanding and well-known words like -// "on-the-spot" - -#define PREF_XIM_INPUTSTYLE "xim.input_style" -#define VAL_INPUTSTYLE_ONTHESPOT "on-the-spot" /* default */ -#define VAL_INPUTSTYLE_OVERTHESPOT "over-the-spot" -#define VAL_INPUTSTYLE_SEPARATE "separate" -#define VAL_INPUTSTYLE_NONE "none" - -// xim.preedit.input_style -// xim.status.input_style -// -// "xim.status.input_style" and "xim.preedit.input_style" preferences -// will be overwritten by the setting of PREF_XIM_INPUTSTYLE when specified. -// These preferences are only for special purpose. e.g. debugging - -#define PREF_XIM_PREEDIT "xim.preedit.input_style" -#define PREF_XIM_STATUS "xim.status.input_style" - -#define VAL_PREEDIT_CALLBACKS "callbacks" /* default */ -#define VAL_PREEDIT_POSITION "position" -#define VAL_PREEDIT_NOTHING "nothing" -#define VAL_PREEDIT_NONE "none" -#define VAL_STATUS_CALLBACKS "callbacks" /* default */ -#define VAL_STATUS_NOTHING "nothing" -#define VAL_STATUS_NONE "none" - -#define SUPPORTED_PREEDIT (GDK_IM_PREEDIT_CALLBACKS | \ - GDK_IM_PREEDIT_POSITION | \ - GDK_IM_PREEDIT_NOTHING | \ - GDK_IM_PREEDIT_NONE) - -#define SUPPORTED_STATUS (GDK_IM_STATUS_CALLBACKS | \ - GDK_IM_STATUS_NOTHING | \ - GDK_IM_STATUS_NONE) - -#ifdef sun -static XErrorHandler gdk_error_handler = (XErrorHandler)nsnull; - -static int -XIMErrorHandler(Display *dpy, XErrorEvent *event) { - if (event->error_code == BadWindow) { - char buffer[128]; - char number[32]; - if (event->request_code < 128) { - sprintf(number, "%d", event->request_code); - XGetErrorDatabaseText(dpy, "XRequest", number, - "", buffer, 128); - if (!strcmp(buffer, "X_SendEvent") || - /* - The below conditions should only happen when ic is - destroyed after focus_window has been already - destroyed. - */ - !strcmp(buffer, "X_ChangeWindowAttributes") || - !strcmp(buffer, "X_GetWindowAttributes")) - return 0; - } - } - _XDefaultError(dpy, event); - return 0; -} -#endif - -GdkIMStyle -nsIMEGtkIC::GetInputStyle() { -#ifdef sun - // set error handler only once - if (gdk_error_handler == (XErrorHandler)NULL) - gdk_error_handler = XSetErrorHandler(XIMErrorHandler); -#endif - GdkIMStyle style; - GdkIMStyle ret_style = (GdkIMStyle)0; - - PRInt32 ivalue = 0; - nsresult rv; - - GdkIMStyle preferred_preedit_style = (GdkIMStyle) SUPPORTED_PREEDIT; - GdkIMStyle preferred_status_style = (GdkIMStyle) SUPPORTED_STATUS; - -#ifdef HPUX - preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_POSITION; - preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_NOTHING; - style = gdk_im_decide_style((GdkIMStyle)(preferred_preedit_style | preferred_status_style)); - if (style) { - ret_style = style; - } else { - style = gdk_im_decide_style((GdkIMStyle) (SUPPORTED_PREEDIT | SUPPORTED_STATUS)); - if (style) { - ret_style = style; - } else { - ret_style = (GdkIMStyle)(GDK_IM_PREEDIT_NONE|GDK_IM_STATUS_NONE); - } - } - return ret_style; -#endif - - nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv) && (prefs)) { - nsXPIDLCString input_style; - rv = prefs->GetCharPref(PREF_XIM_INPUTSTYLE, getter_Copies(input_style)); - if (NS_SUCCEEDED(rv) && !input_style.IsEmpty()) { - if (!nsCRT::strcmp(input_style, VAL_INPUTSTYLE_ONTHESPOT)) { - preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_CALLBACKS; - preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_CALLBACKS; - } else if (!nsCRT::strcmp(input_style, VAL_INPUTSTYLE_OVERTHESPOT)) { - preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_POSITION; - preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_NOTHING; - } else if (!nsCRT::strcmp(input_style, VAL_INPUTSTYLE_SEPARATE)) { - preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_NOTHING; - preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_NOTHING; - } else if (!nsCRT::strcmp(input_style, VAL_INPUTSTYLE_NONE)) { - preferred_preedit_style = (GdkIMStyle) GDK_IM_PREEDIT_NONE; - preferred_status_style = (GdkIMStyle) GDK_IM_STATUS_NONE; - } - } - /* if PREF_XIM_PREEDIT and PREF_XIM_STATUS are defined, use - those values */ - nsXPIDLCString preeditstyle_type; - rv = prefs->GetCharPref(PREF_XIM_PREEDIT, getter_Copies(preeditstyle_type)); - if (NS_SUCCEEDED(rv) && !preeditstyle_type.IsEmpty()) { - if (!nsCRT::strcmp(preeditstyle_type, VAL_PREEDIT_CALLBACKS)) { - ivalue = GDK_IM_PREEDIT_CALLBACKS; - } else if (!nsCRT::strcmp(preeditstyle_type, VAL_PREEDIT_POSITION)) { - ivalue = GDK_IM_PREEDIT_POSITION; - } else if (!nsCRT::strcmp(preeditstyle_type, VAL_PREEDIT_NOTHING)) { - ivalue = GDK_IM_PREEDIT_NOTHING; - } else if (!nsCRT::strcmp(preeditstyle_type, VAL_PREEDIT_NONE)) { - ivalue = GDK_IM_PREEDIT_NONE; - } else { - ivalue = 0; - } - if (ivalue) { - preferred_preedit_style = (GdkIMStyle) ivalue; - } - } - nsXPIDLCString statusstyle_type; - rv = prefs->GetCharPref(PREF_XIM_STATUS, getter_Copies(statusstyle_type)); - if (NS_SUCCEEDED(rv) && !statusstyle_type.IsEmpty()) { - if (!nsCRT::strcmp(statusstyle_type, VAL_STATUS_CALLBACKS)) { - ivalue = GDK_IM_STATUS_CALLBACKS; - } else if (!nsCRT::strcmp(statusstyle_type, VAL_STATUS_NOTHING)) { - ivalue = GDK_IM_STATUS_NOTHING; - } else if (!nsCRT::strcmp(statusstyle_type, VAL_STATUS_NONE)) { - ivalue = GDK_IM_STATUS_NONE; - } else { - ivalue = 0; - } - if (ivalue) { - preferred_status_style = (GdkIMStyle) ivalue; - } - } - } - style = gdk_im_decide_style((GdkIMStyle)(preferred_preedit_style | preferred_status_style)); - if (style) { - ret_style = style; - } else { - style = gdk_im_decide_style((GdkIMStyle) (SUPPORTED_PREEDIT | SUPPORTED_STATUS)); - if (style) { - ret_style = style; - } else { - ret_style = (GdkIMStyle)(GDK_IM_PREEDIT_NONE|GDK_IM_STATUS_NONE); - } - } - return ret_style; -} - -PRInt32 -nsIMEGtkIC::ResetIC(PRUnichar **aUnichar, PRInt32 *aUnisize) -{ - if (IsPreeditComposing() == PR_FALSE) { - return 0; - } - - if (!mPreedit) { - mPreedit = new nsIMEPreedit(); - } - mPreedit->Reset(); - - if (!gdk_im_ready()) { - return 0; - } - -#if XlibSpecificationRelease >= 6 - /* restore conversion state after resetting ic later */ - XIMPreeditState preedit_state = XIMPreeditUnKnown; - XVaNestedList preedit_attr; - - PRBool is_preedit_state = PR_FALSE; - preedit_attr = XVaCreateNestedList(0, - XNPreeditState, &preedit_state, - 0); - if (!XGetICValues(mIC->xic, - XNPreeditAttributes, preedit_attr, - NULL)) { - is_preedit_state = PR_TRUE; - } - XFree(preedit_attr); -#endif - - PRInt32 uniCharSize = 0; - char *uncommitted_text = XmbResetIC(mIC->xic); - if (uncommitted_text && uncommitted_text[0]) { - PRInt32 uncommitted_len = strlen(uncommitted_text); - uniCharSize = nsGtkIMEHelper::GetSingleton()->MultiByteToUnicode( - uncommitted_text, uncommitted_len, - aUnichar, - aUnisize); - } -#if XlibSpecificationRelease >= 6 - preedit_attr = XVaCreateNestedList(0, - XNPreeditState, preedit_state, - 0); - if (is_preedit_state) { - XSetICValues(mIC->xic, - XNPreeditAttributes, preedit_attr, - NULL); - } - XFree(preedit_attr); -#endif - return uniCharSize; -} - -PRBool -nsIMEGtkIC::IsPreeditComposing() -{ - if (mInputStyle & GDK_IM_PREEDIT_CALLBACKS) { - if (mPreedit && mPreedit->GetPreeditLength()) { - return PR_TRUE; - } else { - return PR_FALSE; - } - } - return PR_TRUE; -} - -void -nsIMEGtkIC::SetPreeditFont(GdkFont *aFontset) { - if (!gdk_im_ready()) { - return; - } - GdkICAttr *attr = gdk_ic_attr_new(); - if (attr) { - attr->preedit_fontset = aFontset; - GdkICAttributesType attrMask = GDK_IC_PREEDIT_FONTSET; - gdk_ic_set_attr((GdkIC*)mIC, attr, attrMask); - gdk_ic_attr_destroy(attr); - } -} - -void -nsIMEGtkIC::SetStatusText(const char *aText) { - if (!aText) { - return; - } - if (mStatusText) { - if (!nsCRT::strcmp(aText, mStatusText)) { - return; - } - nsCRT::free(mStatusText); - } - mStatusText = nsCRT::strdup(aText); -} - -void -nsIMEGtkIC::SetStatusFont(GdkFont *aFontset) { - if (!gdk_im_ready()) { - return; - } - if (mInputStyle & GDK_IM_STATUS_CALLBACKS) { - if (!gStatus) { - gStatus = new nsIMEStatus(aFontset); - } else { - gStatus->SetFont(aFontset); - } - } else { - GdkICAttr *attr = gdk_ic_attr_new(); - if (attr) { - attr->preedit_fontset = aFontset; - GdkICAttributesType attrMask = GDK_IC_STATUS_FONTSET; - gdk_ic_set_attr((GdkIC*)mIC, attr, attrMask); - gdk_ic_attr_destroy(attr); - } - } -} - -void -nsIMEGtkIC::SetPreeditSpotLocation(unsigned long aX, unsigned long aY) { - if (!gdk_im_ready()) { - return; - } - GdkICAttr *attr = gdk_ic_attr_new(); - if (attr) { - GdkICAttributesType attrMask = GDK_IC_SPOT_LOCATION; - attr->spot_location.x = aX; - attr->spot_location.y = aY; - gdk_ic_set_attr((GdkIC*)mIC, attr, attrMask); - gdk_ic_attr_destroy(attr); - } -} - -void -nsIMEGtkIC::SetPreeditArea(int aX, int aY, int aW, int aH) { - if (!gdk_im_ready()) { - return; - } - GdkICAttr *attr = gdk_ic_attr_new(); - if (attr) { - GdkICAttributesType attrMask = GDK_IC_PREEDIT_AREA; - attr->preedit_area.x = aX; - attr->preedit_area.y = aY; - attr->preedit_area.width = aW; - attr->preedit_area.height = aH; - gdk_ic_set_attr((GdkIC*)mIC, attr, attrMask); - gdk_ic_attr_destroy(attr); - } -} - -nsIMEGtkIC::nsIMEGtkIC(nsWindow *aFocusWindow, GdkFont *aFontSet) -{ - ::nsIMEGtkIC(aFocusWindow, aFontSet, 0); -} - -nsIMEGtkIC::nsIMEGtkIC(nsWindow *aFocusWindow, GdkFont *aFontSet, - GdkFont *aStatusFontSet) -{ - mFocusWindow = 0; - mIC = 0; - mIC_backup = 0; - mPreedit = 0; - mStatusText = 0; - - XIMCallback1 preedit_start_cb; - XIMCallback1 preedit_draw_cb; - XIMCallback1 preedit_done_cb; - XIMCallback1 preedit_caret_cb; - XIMCallback1 status_draw_cb; - XIMCallback1 status_start_cb; - XIMCallback1 status_done_cb; - - status_draw_cb.client_data = (char *)this; - status_draw_cb.callback = status_draw_cbproc; - status_start_cb.client_data = (char *)this; - status_start_cb.callback = status_start_cbproc; - status_done_cb.client_data = (char *)this; - status_done_cb.callback = status_done_cbproc; - - preedit_start_cb.client_data = (char *)this; - preedit_start_cb.callback = preedit_start_cbproc; - preedit_draw_cb.client_data = (char *)this; - preedit_draw_cb.callback = preedit_draw_cbproc; - preedit_done_cb.client_data = (char *)this; - preedit_done_cb.callback = preedit_done_cbproc; - preedit_caret_cb.client_data = (char *)this; - preedit_caret_cb.callback = preedit_caret_cbproc; - - GdkWindow *gdkWindow = (GdkWindow *) aFocusWindow->GetNativeData(NS_NATIVE_WINDOW); - if (!gdkWindow) { - return; - } - if (!gdk_im_ready()) return; // nothing to do - - mInputStyle = GetInputStyle(); - if (!mInputStyle) { - return; - } - - GdkICAttr *attr = gdk_ic_attr_new(); - GdkICAttributesType attrmask = GDK_IC_ALL_REQ; - - attr->style = mInputStyle; - attr->client_window = gdkWindow; - - attrmask = (GdkICAttributesType)(attrmask | GDK_IC_PREEDIT_COLORMAP); - attr->preedit_colormap = ((GdkWindowPrivate*)gdkWindow)->colormap; - attrmask = (GdkICAttributesType) (attrmask | GDK_IC_PREEDIT_POSITION_REQ); - - if (!(mInputStyle & GDK_IM_PREEDIT_CALLBACKS)) { - attr->preedit_area.width = ((GdkWindowPrivate*)gdkWindow)->width; - attr->preedit_area.height = ((GdkWindowPrivate*)gdkWindow)->height; - attr->preedit_area.x = 0; - attr->preedit_area.y = 0; - attrmask = (GdkICAttributesType) (attrmask | GDK_IC_PREEDIT_AREA); - } - if (aFontSet) { - attr->preedit_fontset = aFontSet; - attrmask = (GdkICAttributesType) (attrmask | GDK_IC_PREEDIT_FONTSET); - } - - if (aStatusFontSet) { - if (mInputStyle & GDK_IM_STATUS_CALLBACKS) { - if (!gStatus) { - gStatus = new nsIMEStatus(aStatusFontSet); - } - } else { - attr->status_fontset = aStatusFontSet; - attrmask = (GdkICAttributesType) (attrmask | GDK_IC_STATUS_FONTSET); - } - } - -#ifdef _AIX - // If GDK_IM_STATUS_CALLBACKS and GDK_IM_PREEDIT_CALLBACKS are set, then - // we will create a dummy GdkIC with style GDK_IM_STATUS_AREA and - // GDK_IM_PREEDIT_POSITION. This is due to the limitation in Gtk 1.2 which - // prevents setting the callback functions before creating an input - // context. AIX requires that all callbacks be specified at the time - // XCreateIC is defined, so this allows us to create a valid GdkIC and - // swap out its dummy XIC below. - if (mInputStyle & GDK_IM_STATUS_CALLBACKS && - mInputStyle & GDK_IM_PREEDIT_CALLBACKS) { - attr->style = (GdkIMStyle)(GDK_IM_STATUS_AREA | GDK_IM_PREEDIT_POSITION); - attrmask = (GdkICAttributesType)(attrmask | GDK_IC_STATUS_AREA); - if (aStatusFontSet) { - attr->status_fontset = aStatusFontSet; - attrmask = (GdkICAttributesType)(attrmask | GDK_IC_STATUS_FONTSET); - } - } -#endif // _AIX - - GdkICPrivate *IC = (GdkICPrivate *)gdk_ic_new(attr, attrmask); - -#ifdef _AIX - // Here we acquire the dummy XIC created in the above gdk_ic_new call, - // look up its XIM, destroy it, and then create a valid XIC with all - // of the callback functions defined. - if (IC && IC->xic && - mInputStyle & GDK_IM_STATUS_CALLBACKS && - mInputStyle & GDK_IM_PREEDIT_CALLBACKS) { - attr->style = mInputStyle; - XIM xim = XIMOfIC(IC->xic); - XDestroyIC(IC->xic); - XVaNestedList preedit_attr = - XVaCreateNestedList(0, - XNPreeditStartCallback, &preedit_start_cb, - XNPreeditDrawCallback, &preedit_draw_cb, - XNPreeditDoneCallback, &preedit_done_cb, - XNPreeditCaretCallback, &preedit_caret_cb, - 0); - XVaNestedList status_attr = - XVaCreateNestedList(0, - XNStatusDrawCallback, &status_draw_cb, - XNStatusStartCallback, &status_start_cb, - XNStatusDoneCallback, &status_done_cb, - 0); - - IC->attr->style = mInputStyle; - IC->xic = XCreateIC (xim, - XNInputStyle, - attr->style, - XNClientWindow, - GDK_WINDOW_XWINDOW(attr->client_window), - XNPreeditAttributes, - preedit_attr, - XNStatusAttributes, - status_attr, - NULL); - XFree(preedit_attr); - XFree(status_attr); - } -#else - // If we destroy on-the-spot XIC during the conversion ON mode, - // kinput2 never turns conversion ON for any other XIC. This seems - // to be a bug of kinput2. - // To prevent this problem, we create a dummy XIC here, which - // never becomes conversion ON, and is only used to be destroyed after - // the real active XIC is destroyed in ~nsIMEGtkIC. - - if (mInputStyle & GDK_IM_PREEDIT_CALLBACKS || - mInputStyle & GDK_IM_STATUS_CALLBACKS) { - // don't need to set actuall callbacks for this xic - mIC_backup = (GdkICPrivate *)gdk_ic_new(attr, attrmask); - } -#endif - - gdk_ic_attr_destroy(attr); - - if (!IC || !IC->xic) { - return; - } - mIC = IC; - -#ifndef _AIX - /* set callbacks here */ - if (mInputStyle & GDK_IM_PREEDIT_CALLBACKS) { - XVaNestedList preedit_attr = - XVaCreateNestedList(0, - XNPreeditStartCallback, &preedit_start_cb, - XNPreeditDrawCallback, &preedit_draw_cb, - XNPreeditDoneCallback, &preedit_done_cb, - XNPreeditCaretCallback, &preedit_caret_cb, - 0); - XSetICValues(IC->xic, - XNPreeditAttributes, preedit_attr, - 0); - XFree(preedit_attr); - } -#endif - - if (mInputStyle & GDK_IM_STATUS_CALLBACKS) { -#ifndef _AIX - XVaNestedList status_attr = - XVaCreateNestedList(0, - XNStatusDrawCallback, &status_draw_cb, - XNStatusStartCallback, &status_start_cb, - XNStatusDoneCallback, &status_done_cb, - 0); - XSetICValues(IC->xic, - XNStatusAttributes, status_attr, - 0); - XFree(status_attr); -#endif - - if (!gStatus) { - gStatus = new nsIMEStatus(); - } - SetStatusText(""); - } -} -#endif // USE_XIM diff --git a/mozilla/widget/src/gtk/nsGtkIMEHelper.h b/mozilla/widget/src/gtk/nsGtkIMEHelper.h deleted file mode 100644 index 6f9dc048363..00000000000 --- a/mozilla/widget/src/gtk/nsGtkIMEHelper.h +++ /dev/null @@ -1,191 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Frank Tang - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsGtkIMEHelper_h__ -#define nsGtkIMEHelper_h__ -#include "nsIUnicodeDecoder.h" -#include "nsString.h" -#include - -/* - * We are gradually moving IME related function into this class - */ -class nsGtkIMEHelper { -public: - ~nsGtkIMEHelper(); - nsresult ConvertToUnicode(const char* aSrc, PRInt32* aSrcLen, - PRUnichar* aDes, PRInt32* aDesLen); - static nsGtkIMEHelper *GetSingleton(); - void ResetDecoder(); - static void Shutdown(); - PRInt32 MultiByteToUnicode(const char*, const PRInt32, - PRUnichar**, PRInt32*); -#if defined(USE_XIM) && defined(_AIX) - PRUnichar* GetUnichars() const { return mUnichars; } - PRInt32 GetUnicharsSize() const { return mUnicharsSize; } - - // It is the caller's responsibility to free any data in - // mUnichars prior to calling SetUnichars() - void SetUnichars(PRUnichar *aUnichars) { mUnichars = aUnichars; } - void SetUnicharsSize(PRInt32 aUnicharsSize) - { mUnicharsSize = aUnicharsSize; } -#endif - -private: - nsGtkIMEHelper(); - nsIUnicodeDecoder* mDecoder; - void SetupUnicodeDecoder(); - static nsGtkIMEHelper *gSingleton; -#if defined(USE_XIM) && defined(_AIX) - PRUnichar* mUnichars; - PRInt32 mUnicharsSize; -#endif -}; - -#ifdef USE_XIM -class nsIMEPreedit { - private: - PRInt32 mCaretPosition; - nsString* mIMECompUnicode; - nsCString* mIMECompAttr; - PRUnichar* mCompositionUniString; - PRInt32 mCompositionUniStringSize; - public: - nsIMEPreedit(); - ~nsIMEPreedit(); - void Reset(); - const PRUnichar* GetPreeditString() const; - const char* GetPreeditFeedback() const; - int GetPreeditLength() const; - void SetPreeditString(const XIMText* aText, - const PRInt32 aChangeFirst, - const PRInt32 aChangeLength); - static void IMSetTextRange(const PRInt32 aLen, - const char *aFeedback, - PRUint32 *, - nsTextRangeArray*); -}; - -class nsWindow; - -class nsIMEStatus { - private: - Window mIMStatusWindow; - Window mIMStatusLabel; - XFontSet mFontset; - int mWidth; - int mHeight; - GC mGC; - void resize(const char *); - void remove_decoration(); - void getAtoms(); - static Bool client_filter(Display *d, Window w, XEvent *ev, - XPointer client_data); - static Bool repaint_filter(Display *d, Window w, XEvent *ev, - XPointer client_data); - static Bool clientmessage_filter(Display *d, Window w, XEvent *ev, - XPointer client_data); - void CreateNative(); - void DestroyNative(); - public: - nsIMEStatus(); - nsIMEStatus(GdkFont*); - void SetFont(GdkFont*); - ~nsIMEStatus(); - void UnregisterClientFilter(Window); - void RegisterClientFilter(Window); - void setText(const char*); - void setParentWindow(nsWindow*); - void resetParentWindow(nsWindow*); - void show(); - void hide(); - - nsWindow *mAttachedWindow; - GdkWindow *mParent; -}; - -/* for XIM callback */ -typedef int (*XIMProc1)(XIC, XPointer, XPointer); -typedef struct { - XPointer client_data; - XIMProc1 callback; -} XIMCallback1; - -class nsIMEGtkIC { - private: - static int preedit_start_cbproc(XIC, XPointer, XPointer); - static int preedit_draw_cbproc(XIC, XPointer, XPointer); - static int preedit_done_cbproc(XIC, XPointer, XPointer); - static int preedit_caret_cbproc(XIC, XPointer, XPointer) { return 0; }; - static int status_draw_cbproc(XIC, XPointer, XPointer); - static int status_start_cbproc(XIC, XPointer, XPointer) { return 0; }; - static int status_done_cbproc(XIC, XPointer, XPointer) { return 0; }; - static nsIMEStatus *gStatus; - nsWindow *mClientWindow; - nsWindow *mFocusWindow; - static nsWindow *gGlobalFocusWindow; - nsIMEGtkIC(nsWindow*, GdkFont*, GdkFont*); - nsIMEGtkIC(nsWindow*, GdkFont*); - GdkICPrivate *mIC; - GdkICPrivate *mIC_backup; - nsIMEPreedit *mPreedit; - GdkFont *mStatusFontset; - - public: - nsIMEPreedit *GetPreedit() {return mPreedit;} - ~nsIMEGtkIC(); - static nsIMEGtkIC *GetXIC(nsWindow*, GdkFont*, GdkFont*); - static nsIMEGtkIC *GetXIC(nsWindow*, GdkFont*); - void SetFocusWindow(nsWindow * aFocusWindow); - nsWindow* GetFocusWindow(); - nsWindow* GetGlobalFocusWindow(); - static void UnsetFocusWindow(); - static GdkIMStyle GetInputStyle(); - - GdkIMStyle mInputStyle; - char *mStatusText; - void SetStatusText(const char*); - void SetPreeditFont(GdkFont*); - void SetStatusFont(GdkFont*); - void SetPreeditSpotLocation(unsigned long, unsigned long); - void SetPreeditArea(int, int, int, int); - void ResetStatusWindow(nsWindow * aWindow); - PRBool IsPreeditComposing(); - PRInt32 ResetIC(PRUnichar **aUnichar, PRInt32 *aUnisize); -}; -#endif // USE_XIM -#endif // nsGtkIMEHelper_h__ diff --git a/mozilla/widget/src/gtk/nsGtkUtils.cpp b/mozilla/widget/src/gtk/nsGtkUtils.cpp deleted file mode 100644 index fafa083dda8..00000000000 --- a/mozilla/widget/src/gtk/nsGtkUtils.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "nsGtkUtils.h" - -#include -#include - -#ifdef NEED_USLEEP_PROTOTYPE -extern "C" int usleep(unsigned int); -#endif -#if defined(__QNX__) -#define usleep(s) sleep(s) -#endif - -////////////////////////////////////////////////////////////////// -#if 0 -/* staitc */ gint -nsGtkUtils::gdk_query_pointer(GdkWindow * window, - gint * x_out, - gint * y_out) -{ - g_return_val_if_fail(NULL != window, FALSE); - g_return_val_if_fail(NULL != x_out, FALSE); - g_return_val_if_fail(NULL != y_out, FALSE); - - Window root; - Window child; - int rootx, rooty; - int winx = 0; - int winy = 0; - unsigned int xmask = 0; - gint result = FALSE; - - *x_out = -1; - *y_out = -1; - - result = XQueryPointer(GDK_WINDOW_XDISPLAY(window), - GDK_WINDOW_XWINDOW(window), - &root, - &child, - &rootx, - &rooty, - &winx, - &winy, - &xmask); - - if (result) - { - *x_out = rootx; - *y_out = rooty; - } - - return result; -} -#endif -////////////////////////////////////////////////////////////////// -/* static */ void -nsGtkUtils::gtk_widget_set_color(GtkWidget * widget, - GtkRcFlags flags, - GtkStateType state, - GdkColor * color) -{ - GtkRcStyle * rc_style; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (color != NULL); - g_return_if_fail (flags == 0); - - rc_style = (GtkRcStyle *) gtk_object_get_data (GTK_OBJECT (widget), - "modify-style"); - - if (!rc_style) - { - rc_style = gtk_rc_style_new (); - - gtk_widget_modify_style (widget, rc_style); - - gtk_object_set_data (GTK_OBJECT (widget), "modify-style", rc_style); - } - - if (flags & GTK_RC_FG) - { - rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_FG); - rc_style->fg[state] = *color; - } - - if (flags & GTK_RC_BG) - { - rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_BG); - rc_style->bg[state] = *color; - } - - if (flags & GTK_RC_TEXT) - { - rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_TEXT); - rc_style->text[state] = *color; - } - - if (flags & GTK_RC_BASE) - { - rc_style->color_flags[state] = GtkRcFlags(rc_style->color_flags[state] | GTK_RC_BASE); - rc_style->base[state] = *color; - } -} -////////////////////////////////////////////////////////////////// -/* static */ GdkModifierType -nsGtkUtils::gdk_keyboard_get_modifiers() -{ - GdkModifierType m = (GdkModifierType) 0; - - gdk_window_get_pointer(NULL,NULL,NULL,&m); - - return m; -} -////////////////////////////////////////////////////////////////// -/* static */ void -nsGtkUtils::gdk_window_flash(GdkWindow * aGdkWindow, - unsigned int aTimes, - unsigned long aInterval, - GdkRegion * aRegion) -{ - gint x; - gint y; - gint width; - gint height; - guint i; - GdkGC * gc = 0; - GdkColor white; - - gdk_window_get_geometry(aGdkWindow, - NULL, - NULL, - &width, - &height, - NULL); - - gdk_window_get_origin (aGdkWindow, - &x, - &y); - - gc = gdk_gc_new(GDK_ROOT_PARENT()); - - white.pixel = WhitePixel(gdk_display,DefaultScreen(gdk_display)); - - gdk_gc_set_foreground(gc,&white); - gdk_gc_set_function(gc,GDK_XOR); - gdk_gc_set_subwindow(gc,GDK_INCLUDE_INFERIORS); - - gdk_region_offset(aRegion, x, y); - gdk_gc_set_clip_region(gc, aRegion); - - /* - * Need to do this twice so that the XOR effect can replace - * the original window contents. - */ - for (i = 0; i < aTimes * 2; i++) - { - gdk_draw_rectangle(GDK_ROOT_PARENT(), - gc, - TRUE, - x, - y, - width, - height); - - gdk_flush(); - - usleep(aInterval); - } - - gdk_gc_destroy(gc); - - gdk_region_offset(aRegion, -x, -y); -} -////////////////////////////////////////////////////////////////// diff --git a/mozilla/widget/src/gtk/nsGtkUtils.h b/mozilla/widget/src/gtk/nsGtkUtils.h deleted file mode 100644 index 745f32189d3..00000000000 --- a/mozilla/widget/src/gtk/nsGtkUtils.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsGtkUtils_h -#define __nsGtkUtils_h - -#include - -struct nsGtkUtils -{ - // - // Wrapper for XQueryPointer - // -#if 0 - static gint gdk_query_pointer(GdkWindow * window, - gint * x_out, - gint * y_out); -#endif - - // - // Change a widget's background - // - // flags isa bit mask of the following bits: - // - // GTK_RC_FG - // GTK_RC_BG - // GTK_RC_TEXT - // GTK_RC_BASE - // - // state is an enum: - // - // GTK_STATE_NORMAL, - // GTK_STATE_ACTIVE, - // GTK_STATE_PRELIGHT, - // GTK_STATE_SELECTED, - // GTK_STATE_INSENSITIVE - // - static void gtk_widget_set_color(GtkWidget * widget, - GtkRcFlags flags, - GtkStateType state, - GdkColor * color); - - /** - * Return the current keyboard modifier state. - * - * @return the current keyboard modifier state. - * - */ - static GdkModifierType gdk_keyboard_get_modifiers(); - - /** - * Flash an area within a GDK window (or the whole window) - * - * @param aGdkWindow The GDK window to flash. - * @param aTimes Number of times to flash the area. - * @param aInterval Interval between flashes in milliseconds. - * @param aArea The area to flash. The whole window if NULL. - * - */ - static void gdk_window_flash(GdkWindow * aGdkWindow, - unsigned int aTimes, - unsigned long aInterval, - GdkRegion * aArea); -}; - -#endif // __nsGtkEventHandler.h diff --git a/mozilla/widget/src/gtk/nsKeyboardUtils.cpp b/mozilla/widget/src/gtk/nsKeyboardUtils.cpp deleted file mode 100644 index c67c293c722..00000000000 --- a/mozilla/widget/src/gtk/nsKeyboardUtils.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Brian Stell . - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#ifdef HAVE_X11_XKBLIB_H -# if (defined (__digital__) && defined (__unix__)) || defined(_AIX) || defined(__hpux) || defined (__osf__) -# define explicit Explicit -# include -# undef explicit -#else -# include -#endif -#endif -#include -#include -#include -#include "nsKeyboardUtils.h" -#include "nspr.h" -#include "nsWindow.h" -#include "nsPrintfCString.h" - -// -// xkbms: X KeyBoard Mode Switch -// -// Mode_switch during XGrabKeyboard workaround -// -// During a keyboard grab some (all?) X servers do not -// set the Mode_switch bit in the XKeyEvent state value -// even if the user is pressing the Mode_switch key. -// Thus some important keysym mappings are not available -// during a keyboard grab; eg: German keyboards use -// Mode_switch (AltGr) and Q for '@' which is an -// important key for entering email addresses. -// Finnish keyboards use dead_tilde for '~' which is an -// important key for entering user's home page URLs -// -// This workaround turns off the keyboard grab when -// the Mode_switch down. -// -// Note: -// Mode_switch MappingNotify should be called when the -// keyboard mapping changes (a MappingNotify event) but -// the XMappingNotify event has a null window and gdk only allows an -// application to filter events with a non-null window -// - -// Xlib should define this! -#define MODIFIERMAP_ROW_SIZE 8 - -PRUint32 nsXKBModeSwitch::gModeSwitchKeycode1 = 0; -PRUint32 nsXKBModeSwitch::gModeSwitchKeycode2 = 0; -PRBool nsXKBModeSwitch::gGrabDuringPopup = PR_TRUE; -PRBool nsXKBModeSwitch::gUnGrabDuringModeSwitch = PR_TRUE; -PRBool nsXKBModeSwitch::gModeSwitchDown = PR_FALSE; -gint nsXKBModeSwitch::gOwnerEvents; -guint32 nsXKBModeSwitch::gGrabTime; - - -void -nsXKBModeSwitch::ControlWorkaround(gboolean grab_during_popup, - gboolean ungrab_during_mode_switch) -{ -#ifdef DEBUG_bzbarsky - NS_WARNING("nsXKBModeSwitch::ControlWorkaround:"); - NS_WARNING(nsPrintfCString(" grab_during_popup = %d", grab_during_popup).get()); - NS_WARNING(nsPrintfCString(" ungrab_during_mode_switch = %d", ungrab_during_mode_switch).get()); -#endif - gGrabDuringPopup = grab_during_popup; - gUnGrabDuringModeSwitch = ungrab_during_mode_switch; - - // - // This really should be called whenever a MappingNotify - // event happens but gdk does not support that. - // - HandleMappingNotify(); -} - -gint -nsXKBModeSwitch::GrabKeyboard(GdkWindow *win, gint owner_events, guint32 time) -{ - // if grab is disabled pretend it succeeded - if (!gGrabDuringPopup) { - return GrabSuccess; - } - - gint retval; - retval = gdk_keyboard_grab(win, owner_events, time); - if (retval == GrabSuccess) { - gOwnerEvents = owner_events; - gGrabTime = time; - } - else { - gOwnerEvents = 0; - gGrabTime = 0; - } - - return retval; -} - -void -nsXKBModeSwitch::HandleMappingNotify() -{ - XModifierKeymap *xmodmap; - int i, j, max_keypermod; - - // since the mapping could change we (re)initialize variables - Init(); - - Display *lGdkDisplay = GDK_DISPLAY(); - if (!lGdkDisplay) - return; - xmodmap = XGetModifierMapping(lGdkDisplay); - if (!xmodmap) - return; - - max_keypermod = MIN(xmodmap->max_keypermod,5); - for (i=0; imodifiermap)+(i*MODIFIERMAP_ROW_SIZE)+j); - if (!keycode) - continue; - keysym = XKeycodeToKeysym(GDK_DISPLAY(), keycode, 0); - if (!keysym) - continue; - keysymName = XKeysymToString(keysym); - if (!keysymName) - continue; - if (!strcmp(keysymName,"Mode_switch")) { - if (!gModeSwitchKeycode1) - gModeSwitchKeycode1 = keycode; - else if (!gModeSwitchKeycode2) - gModeSwitchKeycode2 = keycode; - } - } - } - XFreeModifiermap(xmodmap); - -#ifdef DEBUG_bzbarsky - if (!gModeSwitchKeycode1) { - NS_WARNING("\n\nnsXKBModeSwitch::HandleMappingNotify: no Mode_switch\n\n"); - } - NS_WARNING("\n\nnsXKBModeSwitch::HandleMappingNotify:"); - NS_WARNING(nsPrintfCString(" gModeSwitchKeycode1 = %d", gModeSwitchKeycode1).get()); - NS_WARNING(nsPrintfCString(" gModeSwitchKeycode2 = %d", gModeSwitchKeycode2).get()); -#endif - -#if defined(HAVE_X11_XKBLIB_H) && \ - defined(XkbMajorVersion) && defined(XbMinorVersion) - { - gint xkb_major = XkbMajorVersion; - gint xkb_minor = XkbMinorVersion; - if (XkbLibraryVersion (&xkb_major, &xkb_minor)) { - xkb_major = XkbMajorVersion; - xkb_minor = XkbMinorVersion; - if (XkbQueryExtension (gdk_display, NULL, NULL, NULL, - &xkb_major, &xkb_minor)) { - } - } - } -#endif - -} - -void -nsXKBModeSwitch::Init() -{ - gModeSwitchKeycode1 = 0; - gModeSwitchKeycode2 = 0; - gModeSwitchDown = FALSE; -} - -void -nsXKBModeSwitch::HandleKeyPress(XKeyEvent *xke) -{ - // if grab is completely disabled then there is nothing to do - if (!gGrabDuringPopup) { - return; - } - - // check for a Mode_switch keypress - if ((xke->keycode == gModeSwitchKeycode1) - || (xke->keycode == gModeSwitchKeycode2)) { - gModeSwitchDown = TRUE; - NS_WARNING("nsXKBModeSwitch::HandleKeyPress: Mode_switch is down"); - nsWindow *win = nsWindow::GetGrabWindow(); - if (!win) - return; - if (win->GrabInProgress()) { - if (gUnGrabDuringModeSwitch) { - gdk_keyboard_ungrab(GDK_CURRENT_TIME); - NS_WARNING("\n\n*** ungrab keyboard ***\n\n"); - } - } - } -} - -void -nsXKBModeSwitch::HandleKeyRelease(XKeyEvent *xke) -{ - // if grab is completely disabled then there is nothing to do - if (!gGrabDuringPopup) { - return; - } - - // check for a Mode_switch keyrelease - if ((xke->keycode == gModeSwitchKeycode1) - || (xke->keycode == gModeSwitchKeycode2)) { - gModeSwitchDown = FALSE; - NS_WARNING("nsXKBModeSwitch::HandleKeyPress: Mode_switch is up"); - nsWindow *win = nsWindow::GetGrabWindow(); - if (!win) - return; - if (win->GrabInProgress()) { - if (gUnGrabDuringModeSwitch) { - if (!win->GetGdkGrabWindow()) - return; - gdk_keyboard_grab(win->GetGdkGrabWindow(), gOwnerEvents, gGrabTime); - NS_WARNING("\n\n*** re-grab keyboard ***\n\n"); - } - } - } -} - -void -nsXKBModeSwitch::UnGrabKeyboard(guint32 time) -{ - // if grab is completely disabled then there is nothing to do - if (!gGrabDuringPopup) { - return; - } - - gdk_keyboard_ungrab(time); - gOwnerEvents = 0; - gGrabTime = 0; -} - diff --git a/mozilla/widget/src/gtk/nsKeyboardUtils.h b/mozilla/widget/src/gtk/nsKeyboardUtils.h deleted file mode 100644 index 6bab5f2cdd8..00000000000 --- a/mozilla/widget/src/gtk/nsKeyboardUtils.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Brian Stell . - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef _NSKEYBOARDUTILS_H_ -#define _NSKEYBOARDUTILS_H_ - -extern "C" { -#include -#include -} -#include "prtypes.h" - -class nsXKBModeSwitch { - public: - static void ControlWorkaround(gboolean grab_during_popup, - gboolean ungrab_during_mode_switch); - static gint GrabKeyboard(GdkWindow *win, gint owner_events, guint32 time); - static void UnGrabKeyboard(guint32 time); - static void HandleKeyPress(XKeyEvent *xke); - static void HandleKeyRelease(XKeyEvent *xke); - static void HandleMappingNotify(); - - private: - static void Init(); - - static PRUint32 gModeSwitchKeycode1; - static PRUint32 gModeSwitchKeycode2; - static PRBool gGrabDuringPopup; - static PRBool gUnGrabDuringModeSwitch; - static PRBool gModeSwitchDown; - static gint gOwnerEvents; - static guint32 gGrabTime; - -}; - -#endif /* _NSKEYBOARDUTILS_H_ */ diff --git a/mozilla/widget/src/gtk/nsLookAndFeel.cpp b/mozilla/widget/src/gtk/nsLookAndFeel.cpp deleted file mode 100644 index 31ef2b6042e..00000000000 --- a/mozilla/widget/src/gtk/nsLookAndFeel.cpp +++ /dev/null @@ -1,543 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsLookAndFeel.h" -#include - -#define GDK_COLOR_TO_NS_RGB(c) \ - ((nscolor) NS_RGB(c.red>>8, c.green>>8, c.blue>>8)) - -nscolor nsLookAndFeel::sInfoText = 0; -nscolor nsLookAndFeel::sInfoBackground = 0; -nscolor nsLookAndFeel::sMenuText = 0; -nscolor nsLookAndFeel::sMenuBackground = 0; -nscolor nsLookAndFeel::sButtonBackground = 0; -nscolor nsLookAndFeel::sButtonText = 0; -nscolor nsLookAndFeel::sButtonOuterLightBorder = 0; -nscolor nsLookAndFeel::sButtonInnerDarkBorder = 0; -PRBool nsLookAndFeel::sColorsInitialized = PR_FALSE; - -//------------------------------------------------------------------------- -// -// Query interface implementation -// -//------------------------------------------------------------------------- -nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() -{ - mWidget = gtk_invisible_new(); - gtk_widget_ensure_style(mWidget); - mStyle = gtk_widget_get_style(mWidget); - - if (!sColorsInitialized) - InitColors(); -} - -nsLookAndFeel::~nsLookAndFeel() -{ - // gtk_widget_destroy(mWidget); - gtk_widget_unref(mWidget); -} - -nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor& aColor) -{ - nsresult res = NS_OK; - aColor = 0; // default color black - - switch (aID) { - // These colors don't seem to be used for anything anymore - // in Mozilla. The CSS2 colors below are used. - case eColor_WindowBackground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_WindowForeground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - case eColor_WidgetBackground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_WidgetForeground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - case eColor_WidgetSelectBackground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]); - break; - case eColor_WidgetSelectForeground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_SELECTED]); - break; - case eColor_Widget3DHighlight: - aColor = NS_RGB(0xa0,0xa0,0xa0); - break; - case eColor_Widget3DShadow: - aColor = NS_RGB(0x40,0x40,0x40); - break; - case eColor_TextBackground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_TextForeground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - case eColor_TextSelectBackground: - case eColor_IMESelectedRawTextBackground: - case eColor_IMESelectedConvertedTextBackground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]); - break; - case eColor_TextSelectForeground: - case eColor_IMESelectedRawTextForeground: - case eColor_IMESelectedConvertedTextForeground: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_SELECTED]); - break; - case eColor_IMERawInputBackground: - case eColor_IMEConvertedTextBackground: - aColor = NS_TRANSPARENT; - break; - case eColor_IMERawInputForeground: - case eColor_IMEConvertedTextForeground: - aColor = NS_SAME_AS_FOREGROUND_COLOR; - break; - case eColor_IMERawInputUnderline: - case eColor_IMEConvertedTextUnderline: - aColor = NS_SAME_AS_FOREGROUND_COLOR; - break; - case eColor_IMESelectedRawTextUnderline: - case eColor_IMESelectedConvertedTextUnderline: - aColor = NS_TRANSPARENT; - break; - - // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors - case eColor_activeborder: - // active window border - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_activecaption: - // active window caption background - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_appworkspace: - // MDI background color - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_background: - // desktop background - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_captiontext: - // text in active window caption, size box, and scrollbar arrow box (!) - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - case eColor_graytext: - // disabled text - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]); - // or maybe mStyle->text? - break; - case eColor_highlight: - case eColor__moz_menuhover: - // background of selected item - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]); - break; - case eColor_highlighttext: - case eColor__moz_menuhovertext: - // text of selected item - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_SELECTED]); - break; - case eColor_inactiveborder: - // inactive window border - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor_inactivecaption: - // inactive window caption - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_INSENSITIVE]); - break; - case eColor_inactivecaptiontext: - // text in inactive window caption - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_INSENSITIVE]); - break; - case eColor_infobackground: - // tooltip background color - aColor = sInfoBackground; - break; - case eColor_infotext: - // tooltip text color - aColor = sInfoText; - break; - case eColor_menu: - // menu background - aColor = sMenuBackground; - break; - case eColor_menutext: - // menu text - aColor = sMenuText; - break; - case eColor_scrollbar: - // scrollbar gray area - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_ACTIVE]); - break; - - case eColor_threedface: - case eColor_buttonface: - case eColor__moz_buttonhoverface: - // 3-D face color - aColor = sButtonBackground; - break; - - case eColor_buttontext: - case eColor__moz_buttonhovertext: - // text on push buttons - aColor = sButtonText; - break; - - case eColor_buttonhighlight: - // 3-D highlighted edge color - case eColor_threedhighlight: - // 3-D highlighted outer edge color - aColor = sButtonOuterLightBorder; - break; - - case eColor_threedlightshadow: - // 3-D highlighted inner edge color - aColor = sButtonBackground; // always same as background in GTK code - break; - - case eColor_buttonshadow: - // 3-D shadow edge color - case eColor_threedshadow: - // 3-D shadow inner edge color - aColor = sButtonInnerDarkBorder; - break; - - case eColor_threeddarkshadow: - // 3-D shadow outer edge color - aColor = GDK_COLOR_TO_NS_RGB(mStyle->black); - break; - - case eColor_window: - case eColor_windowframe: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - - case eColor_windowtext: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - - // from the CSS3 working draft (not yet finalized) - // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color - - case eColor__moz_field: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->base[GTK_STATE_NORMAL]); - break; - case eColor__moz_fieldtext: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - case eColor__moz_dialog: - case eColor__moz_cellhighlight: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_NORMAL]); - break; - case eColor__moz_dialogtext: - case eColor__moz_cellhighlighttext: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->fg[GTK_STATE_NORMAL]); - break; - case eColor__moz_dragtargetzone: - aColor = GDK_COLOR_TO_NS_RGB(mStyle->bg[GTK_STATE_SELECTED]); - break; - case eColor__moz_buttondefault: - // default button border color - aColor = GDK_COLOR_TO_NS_RGB(mStyle->black); - break; - default: - /* default color is BLACK */ - aColor = 0; - res = NS_ERROR_FAILURE; - break; - } - - // printf("%i, %i, %i\n", NS_GET_R(aColor), NS_GET_B(aColor), NS_GET_G(aColor)); - - return res; -} - -NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric) -{ - nsresult res = NS_OK; - - res = nsXPLookAndFeel::GetMetric(aID, aMetric); - if (NS_SUCCEEDED(res)) - return res; - res = NS_OK; - - switch (aID) { - case eMetric_WindowTitleHeight: - aMetric = 0; - break; - case eMetric_WindowBorderWidth: - // XXXldb Why is this commented out? - // aMetric = mStyle->klass->xthickness; - break; - case eMetric_WindowBorderHeight: - // XXXldb Why is this commented out? - // aMetric = mStyle->klass->ythickness; - break; - case eMetric_Widget3DBorder: - // XXXldb Why is this commented out? - // aMetric = 4; - break; - case eMetric_TextFieldHeight: - { - GtkRequisition req; - GtkWidget *text = gtk_entry_new(); - // needed to avoid memory leak - gtk_widget_ref(text); - gtk_object_sink(GTK_OBJECT(text)); - gtk_widget_size_request(text,&req); - aMetric = req.height; - gtk_widget_destroy(text); - gtk_widget_unref(text); - } - break; - case eMetric_TextFieldBorder: - aMetric = 2; - break; - case eMetric_TextVerticalInsidePadding: - aMetric = 0; - break; - case eMetric_TextShouldUseVerticalInsidePadding: - aMetric = 0; - break; - case eMetric_TextHorizontalInsideMinimumPadding: - aMetric = 15; - break; - case eMetric_TextShouldUseHorizontalInsideMinimumPadding: - aMetric = 1; - break; - case eMetric_ButtonHorizontalInsidePaddingNavQuirks: - aMetric = 10; - break; - case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks: - aMetric = 8; - break; - case eMetric_CheckboxSize: - aMetric = 15; - break; - case eMetric_RadioboxSize: - aMetric = 15; - break; - case eMetric_ListShouldUseHorizontalInsideMinimumPadding: - aMetric = 15; - break; - case eMetric_ListHorizontalInsideMinimumPadding: - aMetric = 15; - break; - case eMetric_ListShouldUseVerticalInsidePadding: - aMetric = 1; - break; - case eMetric_ListVerticalInsidePadding: - aMetric = 1; - break; - case eMetric_CaretBlinkTime: - aMetric = 500; - break; - case eMetric_CaretWidth: - aMetric = 1; - break; - case eMetric_ShowCaretDuringSelection: - aMetric = 0; - break; - case eMetric_SelectTextfieldsOnKeyFocus: - // Select textfield content when focused by kbd - // used by nsEventStateManager::sTextfieldSelectModel - aMetric = 1; - break; - case eMetric_SubmenuDelay: - aMetric = 200; - break; - case eMetric_MenusCanOverlapOSBar: - // we want XUL popups to be able to overlap the task bar. - aMetric = 1; - break; - case eMetric_SkipNavigatingDisabledMenuItem: - aMetric = 1; - break; - case eMetric_DragFullWindow: - aMetric = 1; - break; - case eMetric_DragThresholdX: - case eMetric_DragThresholdY: - // hardcoded in gtkdnd.c - aMetric = 3; - break; - case eMetric_ScrollArrowStyle: - aMetric = eMetric_ScrollArrowStyleSingle; - break; - case eMetric_ScrollSliderStyle: - aMetric = eMetric_ScrollThumbStyleProportional; - break; - case eMetric_TreeOpenDelay: - aMetric = 1000; - break; - case eMetric_TreeCloseDelay: - aMetric = 1000; - break; - case eMetric_TreeLazyScrollDelay: - aMetric = 150; - break; - case eMetric_TreeScrollDelay: - aMetric = 100; - break; - case eMetric_TreeScrollLinesMax: - aMetric = 3; - break; - - default: - aMetric = 0; - res = NS_ERROR_FAILURE; - } - - return res; -} - -NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric) -{ - nsresult res = NS_OK; - res = nsXPLookAndFeel::GetMetric(aID, aMetric); - if (NS_SUCCEEDED(res)) - return res; - res = NS_OK; - - switch (aID) { - case eMetricFloat_TextFieldVerticalInsidePadding: - aMetric = 0.25f; - break; - case eMetricFloat_TextFieldHorizontalInsidePadding: - aMetric = 0.95f; // large number on purpose so minimum padding is used - break; - case eMetricFloat_TextAreaVerticalInsidePadding: - aMetric = 0.40f; - break; - case eMetricFloat_TextAreaHorizontalInsidePadding: - aMetric = 0.40f; // large number on purpose so minimum padding is used - break; - case eMetricFloat_ListVerticalInsidePadding: - aMetric = 0.10f; - break; - case eMetricFloat_ListHorizontalInsidePadding: - aMetric = 0.40f; - break; - case eMetricFloat_ButtonVerticalInsidePadding: - aMetric = 0.25f; - break; - case eMetricFloat_ButtonHorizontalInsidePadding: - aMetric = 0.25f; - break; - case eMetricFloat_IMEUnderlineRelativeSize: - aMetric = 1.0f; - break; - default: - aMetric = -1.0; - res = NS_ERROR_FAILURE; - } - return res; -} - -void -nsLookAndFeel::InitColors() -{ - sColorsInitialized = PR_TRUE; - GtkStyle *style; - - // tooltip foreground and background - GtkTooltips *tooltips = gtk_tooltips_new(); - gtk_tooltips_force_window(tooltips); - GtkWidget *tip_window = tooltips->tip_window; - gtk_widget_set_rc_style(tip_window); - - style = gtk_widget_get_style(tip_window); - sInfoBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); - sInfoText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); - - gtk_object_unref(GTK_OBJECT(tooltips)); - - - // menu foreground & menu background - GtkWidget *accel_label = gtk_accel_label_new("M"); - GtkWidget *menuitem = gtk_menu_item_new(); - GtkWidget *menu = gtk_menu_new(); - - gtk_container_add(GTK_CONTAINER(menuitem), accel_label); - gtk_menu_append(GTK_MENU(menu), menuitem); - - gtk_widget_set_rc_style(accel_label); - gtk_widget_set_rc_style(menu); - gtk_widget_realize(menu); - gtk_widget_realize(accel_label); - - style = gtk_widget_get_style(accel_label); - sMenuText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); - - style = gtk_widget_get_style(menu); - sMenuBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); - - gtk_widget_unref(menu); - - - // button styles - GtkWidget *parent = gtk_fixed_new(); - GtkWidget *button = gtk_button_new(); - GtkWidget *label = gtk_label_new("M"); - GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP); - - gtk_container_add(GTK_CONTAINER(button), label); - gtk_container_add(GTK_CONTAINER(parent), button); - gtk_container_add(GTK_CONTAINER(window), parent); - - gtk_widget_set_rc_style(button); - gtk_widget_set_rc_style(label); - - gtk_widget_realize(button); - gtk_widget_realize(label); - - style = gtk_widget_get_style(label); - sButtonText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]); - - style = gtk_widget_get_style(button); - sButtonBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]); - sButtonOuterLightBorder = - GDK_COLOR_TO_NS_RGB(style->light[GTK_STATE_NORMAL]); - sButtonInnerDarkBorder = - GDK_COLOR_TO_NS_RGB(style->dark[GTK_STATE_NORMAL]); - - gtk_widget_destroy(window); - -} diff --git a/mozilla/widget/src/gtk/nsLookAndFeel.h b/mozilla/widget/src/gtk/nsLookAndFeel.h deleted file mode 100644 index ca7b28acae7..00000000000 --- a/mozilla/widget/src/gtk/nsLookAndFeel.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsLookAndFeel -#define __nsLookAndFeel -#include "nsXPLookAndFeel.h" -#include "nsCOMPtr.h" -#include - -class nsLookAndFeel: public nsXPLookAndFeel { -public: - nsLookAndFeel(); - virtual ~nsLookAndFeel(); - - nsresult NativeGetColor(const nsColorID aID, nscolor &aColor); - NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric); - NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric); - -protected: - GtkStyle *mStyle; - GtkWidget *mWidget; - - // Cached colors, we have to create a dummy widget to actually - // get the style - static PRBool sColorsInitialized; - static nscolor sInfoBackground; - static nscolor sInfoText; - static nscolor sMenuBackground; - static nscolor sMenuText; - static nscolor sButtonBackground; - static nscolor sButtonText; - static nscolor sButtonOuterLightBorder; - static nscolor sButtonInnerDarkBorder; - - static void InitColors(); -}; - -#endif diff --git a/mozilla/widget/src/gtk/nsNativeThemeGTK.cpp b/mozilla/widget/src/gtk/nsNativeThemeGTK.cpp deleted file mode 100644 index a35030262ba..00000000000 --- a/mozilla/widget/src/gtk/nsNativeThemeGTK.cpp +++ /dev/null @@ -1,872 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsNativeThemeGTK.h" -#include "nsThemeConstants.h" -#include "gtkdrawing.h" - -#include "nsIObserverService.h" -#include "nsIServiceManager.h" -#include "nsIFrame.h" -#include "nsIPresShell.h" -#include "nsIDocument.h" -#include "nsIContent.h" -#include "nsIEventStateManager.h" -#include "nsIViewManager.h" -#include "nsINameSpaceManager.h" -#include "nsILookAndFeel.h" -#include "nsIDeviceContext.h" -#include "nsGfxCIID.h" -#include "nsTransform2D.h" -#include "nsIMenuFrame.h" -#include "nsIMenuParent.h" -#include "nsWidgetAtoms.h" -#include "prlink.h" - -#include - -#include - -NS_IMPL_ISUPPORTS2(nsNativeThemeGTK, nsITheme, nsIObserver) - -static int gLastXError; - -nsNativeThemeGTK::nsNativeThemeGTK() -{ - if (moz_gtk_init() != MOZ_GTK_SUCCESS) { - memset(mDisabledWidgetTypes, 0xff, sizeof(mDisabledWidgetTypes)); - return; - } - - // We have to call moz_gtk_shutdown before the event loop stops running. - nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); - obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE); - - memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes)); - memset(mSafeWidgetStates, 0, sizeof(mSafeWidgetStates)); - -#ifdef MOZ_WIDGET_GTK - // Look up the symbol for gtk_style_get_prop_experimental - PRLibrary* gtkLibrary; - PRFuncPtr stylePropFunc = PR_FindFunctionSymbolAndLibrary("gtk_style_get_prop_experimental", >kLibrary); - if (stylePropFunc) { - moz_gtk_enable_style_props((style_prop_t) stylePropFunc); - PR_UnloadLibrary(gtkLibrary); - } -#endif -} - -nsNativeThemeGTK::~nsNativeThemeGTK() { -} - -NS_IMETHODIMP -nsNativeThemeGTK::Observe(nsISupports *aSubject, const char *aTopic, - const PRUnichar *aData) -{ - if (!nsCRT::strcmp(aTopic, "xpcom-shutdown")) { - moz_gtk_shutdown(); - } else { - NS_NOTREACHED("unexpected topic"); - return NS_ERROR_UNEXPECTED; - } - - return NS_OK; -} - -void -nsNativeThemeGTK::RefreshWidgetWindow(nsIFrame* aFrame) -{ - nsIPresShell *shell = GetPresShell(aFrame); - if (!shell) - return; - - nsIViewManager* vm = shell->GetViewManager(); - if (!vm) - return; - - vm->UpdateAllViews(NS_VMREFRESH_NO_SYNC); -} - -static PRBool IsWidgetTypeDisabled(PRUint8* aDisabledVector, PRUint8 aWidgetType) { - return aDisabledVector[aWidgetType >> 3] & (1 << (aWidgetType & 7)); -} - -static void SetWidgetTypeDisabled(PRUint8* aDisabledVector, PRUint8 aWidgetType) { - aDisabledVector[aWidgetType >> 3] |= (1 << (aWidgetType & 7)); -} - -static inline PRUint16 -GetWidgetStateKey(PRUint8 aWidgetType, GtkWidgetState *aWidgetState) -{ - return (aWidgetState->active | - aWidgetState->focused << 1 | - aWidgetState->inHover << 2 | - aWidgetState->disabled << 3 | - aWidgetState->isDefault << 4 | - aWidgetType << 5); -} - -static PRBool IsWidgetStateSafe(PRUint8* aSafeVector, - PRUint8 aWidgetType, - GtkWidgetState *aWidgetState) -{ - PRUint8 key = GetWidgetStateKey(aWidgetType, aWidgetState); - return aSafeVector[key >> 3] & (1 << (key & 7)); -} - -static void SetWidgetStateSafe(PRUint8 *aSafeVector, - PRUint8 aWidgetType, - GtkWidgetState *aWidgetState) -{ - PRUint8 key = GetWidgetStateKey(aWidgetType, aWidgetState); - aSafeVector[key >> 3] |= (1 << (key & 7)); -} - -PRBool -nsNativeThemeGTK::GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame, - GtkThemeWidgetType& aGtkWidgetType, - GtkWidgetState* aState, - gint* aWidgetFlags) -{ - if (aState) { - if (!aFrame) { - // reset the entire struct to zero - memset(aState, 0, sizeof(GtkWidgetState)); - } else { - - // for dropdown textfields, look at the parent frame (textbox or menulist) - if (aWidgetType == NS_THEME_DROPDOWN_TEXTFIELD) - aFrame = aFrame->GetParent(); - - // For XUL checkboxes and radio buttons, the state of the parent - // determines our state. - nsIFrame *stateFrame = aFrame; - if (aFrame && ((aWidgetFlags && (aWidgetType == NS_THEME_CHECKBOX || - aWidgetType == NS_THEME_RADIO)) || - aWidgetType == NS_THEME_CHECKBOX_LABEL || - aWidgetType == NS_THEME_RADIO_LABEL)) { - - nsIAtom* atom = nsnull; - nsIContent *content = aFrame->GetContent(); - if (content->IsNodeOfType(nsINode::eXUL)) { - if (aWidgetType == NS_THEME_CHECKBOX_LABEL || - aWidgetType == NS_THEME_RADIO_LABEL) { - // Adjust stateFrame so GetContentState finds the correct state. - stateFrame = aFrame = aFrame->GetParent()->GetParent(); - } else { - // GetContentState knows to look one frame up for radio/checkbox - // widgets, so don't adjust stateFrame here. - aFrame = aFrame->GetParent(); - } - } else if (content->Tag() == nsWidgetAtoms::input) { - atom = nsWidgetAtoms::mozinputchecked; - } - - if (aWidgetFlags) { - if (!atom) { - atom = (aWidgetType == NS_THEME_CHECKBOX || - aWidgetType == NS_THEME_CHECKBOX_LABEL) ? nsWidgetAtoms::checked - : nsWidgetAtoms::selected; - } - *aWidgetFlags = CheckBooleanAttr(aFrame, atom); - } - } - - PRInt32 eventState = GetContentState(stateFrame, aWidgetType); - - aState->disabled = IsDisabled(aFrame); - aState->active = (eventState & NS_EVENT_STATE_ACTIVE) == NS_EVENT_STATE_ACTIVE; - aState->focused = (eventState & NS_EVENT_STATE_FOCUS) == NS_EVENT_STATE_FOCUS; - aState->inHover = (eventState & NS_EVENT_STATE_HOVER) == NS_EVENT_STATE_HOVER; - aState->isDefault = FALSE; // XXX fix me - aState->canDefault = FALSE; // XXX fix me - - // For these widget types, some element (either a child or parent) - // actually has element focus, so we check the focused attribute - // to see whether to draw in the focused state. - if (aWidgetType == NS_THEME_TEXTFIELD || - aWidgetType == NS_THEME_DROPDOWN_TEXTFIELD || - aWidgetType == NS_THEME_RADIO_CONTAINER || - aWidgetType == NS_THEME_RADIO_LABEL || - aWidgetType == NS_THEME_RADIO) { - aState->focused = IsFocused(aFrame); - } - - if (aWidgetType == NS_THEME_SCROLLBAR_THUMB_VERTICAL || - aWidgetType == NS_THEME_SCROLLBAR_THUMB_HORIZONTAL) { - // for scrollbars we need to go up two to go from the thumb to - // the slider to the actual scrollbar object - nsIFrame *tmpFrame = aFrame->GetParent()->GetParent(); - - aState->curpos = CheckIntAttr(tmpFrame, nsWidgetAtoms::curpos); - aState->maxpos = CheckIntAttr(tmpFrame, nsWidgetAtoms::maxpos); - } - - // menu item state is determined by the attribute "_moz-menuactive", - // and not by the mouse hovering (accessibility). as a special case, - // menus which are children of a menu bar are only marked as prelight - // if they are open, not on normal hover. - - if (aWidgetType == NS_THEME_MENUITEM || - aWidgetType == NS_THEME_CHECKMENUITEM || - aWidgetType == NS_THEME_RADIOMENUITEM) { - PRBool isTopLevel = PR_FALSE; - nsIMenuFrame *menuFrame; - CallQueryInterface(aFrame, &menuFrame); - - if (menuFrame) { - nsIMenuParent *menuParent = menuFrame->GetMenuParent(); - if (menuParent) - menuParent->IsMenuBar(isTopLevel); - } - - if (isTopLevel) { - PRBool isOpen; - menuFrame->MenuIsOpen(isOpen); - aState->inHover = isOpen; - } else { - aState->inHover = CheckBooleanAttr(aFrame, nsWidgetAtoms::mozmenuactive); - } - - aState->active = FALSE; - - if (aWidgetType == NS_THEME_CHECKMENUITEM || - aWidgetType == NS_THEME_RADIOMENUITEM) { - *aWidgetFlags = aFrame && aFrame->GetContent()-> - AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked, - nsWidgetAtoms::_true, eIgnoreCase); - } - } - } - } - - switch (aWidgetType) { - case NS_THEME_BUTTON: - case NS_THEME_TOOLBAR_BUTTON: - case NS_THEME_TOOLBAR_DUAL_BUTTON: - if (aWidgetFlags) - *aWidgetFlags = (aWidgetType == NS_THEME_BUTTON) ? GTK_RELIEF_NORMAL : GTK_RELIEF_NONE; - aGtkWidgetType = MOZ_GTK_BUTTON; - break; - case NS_THEME_CHECKBOX: - case NS_THEME_RADIO: - aGtkWidgetType = (aWidgetType == NS_THEME_RADIO) ? MOZ_GTK_RADIOBUTTON : MOZ_GTK_CHECKBUTTON; - break; - case NS_THEME_SCROLLBAR_BUTTON_UP: - case NS_THEME_SCROLLBAR_BUTTON_DOWN: - case NS_THEME_SCROLLBAR_BUTTON_LEFT: - case NS_THEME_SCROLLBAR_BUTTON_RIGHT: - if (aWidgetFlags) - *aWidgetFlags = GtkArrowType(aWidgetType - NS_THEME_SCROLLBAR_BUTTON_UP); - aGtkWidgetType = MOZ_GTK_SCROLLBAR_BUTTON; - break; - case NS_THEME_SCROLLBAR_TRACK_VERTICAL: - aGtkWidgetType = MOZ_GTK_SCROLLBAR_TRACK_VERTICAL; - break; - case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: - aGtkWidgetType = MOZ_GTK_SCROLLBAR_TRACK_HORIZONTAL; - break; - case NS_THEME_SCROLLBAR_THUMB_VERTICAL: - aGtkWidgetType = MOZ_GTK_SCROLLBAR_THUMB_VERTICAL; - break; - case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: - aGtkWidgetType = MOZ_GTK_SCROLLBAR_THUMB_HORIZONTAL; - break; - case NS_THEME_SPINNER_UP_BUTTON: - aGtkWidgetType = MOZ_GTK_SPINBUTTON_UP; - break; - case NS_THEME_SPINNER_DOWN_BUTTON: - aGtkWidgetType = MOZ_GTK_SPINBUTTON_DOWN; - break; - case NS_THEME_SCALE_HORIZONTAL: - if (aWidgetFlags) - *aWidgetFlags = GTK_ORIENTATION_HORIZONTAL; - aGtkWidgetType = MOZ_GTK_SCALE_HORIZONTAL; - break; - case NS_THEME_SCALE_THUMB_HORIZONTAL: - if (aWidgetFlags) - *aWidgetFlags = GTK_ORIENTATION_HORIZONTAL; - aGtkWidgetType = MOZ_GTK_SCALE_THUMB_HORIZONTAL; - break; - case NS_THEME_SCALE_VERTICAL: - if (aWidgetFlags) - *aWidgetFlags = GTK_ORIENTATION_VERTICAL; - aGtkWidgetType = MOZ_GTK_SCALE_VERTICAL; - break; - case NS_THEME_SCALE_THUMB_VERTICAL: - if (aWidgetFlags) - *aWidgetFlags = GTK_ORIENTATION_VERTICAL; - aGtkWidgetType = MOZ_GTK_SCALE_THUMB_VERTICAL; - break; - case NS_THEME_TOOLBAR_GRIPPER: - aGtkWidgetType = MOZ_GTK_GRIPPER; - break; - case NS_THEME_TEXTFIELD: - case NS_THEME_DROPDOWN_TEXTFIELD: - aGtkWidgetType = MOZ_GTK_ENTRY; - break; - case NS_THEME_DROPDOWN: - aGtkWidgetType = MOZ_GTK_DROPDOWN; - break; - case NS_THEME_DROPDOWN_TEXT: - return PR_FALSE; // nothing to do, but prevents the bg from being drawn - case NS_THEME_DROPDOWN_BUTTON: - aGtkWidgetType = MOZ_GTK_DROPDOWN_ARROW; - break; - case NS_THEME_CHECKBOX_CONTAINER: - aGtkWidgetType = MOZ_GTK_CHECKBUTTON_CONTAINER; - break; - case NS_THEME_RADIO_CONTAINER: - aGtkWidgetType = MOZ_GTK_RADIOBUTTON_CONTAINER; - break; - case NS_THEME_CHECKBOX_LABEL: - aGtkWidgetType = MOZ_GTK_CHECKBUTTON_LABEL; - break; - case NS_THEME_RADIO_LABEL: - aGtkWidgetType = MOZ_GTK_RADIOBUTTON_LABEL; - break; - case NS_THEME_TOOLBAR: - aGtkWidgetType = MOZ_GTK_TOOLBAR; - break; - case NS_THEME_TOOLTIP: - aGtkWidgetType = MOZ_GTK_TOOLTIP; - break; - case NS_THEME_STATUSBAR_PANEL: - aGtkWidgetType = MOZ_GTK_FRAME; - break; - case NS_THEME_PROGRESSBAR: - case NS_THEME_PROGRESSBAR_VERTICAL: - aGtkWidgetType = MOZ_GTK_PROGRESSBAR; - break; - case NS_THEME_PROGRESSBAR_CHUNK: - case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL: - aGtkWidgetType = MOZ_GTK_PROGRESS_CHUNK; - break; - case NS_THEME_TAB_PANELS: - aGtkWidgetType = MOZ_GTK_TABPANELS; - break; - case NS_THEME_TAB: - case NS_THEME_TAB_LEFT_EDGE: - case NS_THEME_TAB_RIGHT_EDGE: - { - if (aWidgetFlags) { - *aWidgetFlags = 0; - - if (aWidgetType == NS_THEME_TAB && - CheckBooleanAttr(aFrame, nsWidgetAtoms::selected)) - *aWidgetFlags |= MOZ_GTK_TAB_SELECTED; - else if (aWidgetType == NS_THEME_TAB_LEFT_EDGE) - *aWidgetFlags |= MOZ_GTK_TAB_BEFORE_SELECTED; - - if (aFrame->GetContent()->HasAttr(kNameSpaceID_None, - nsWidgetAtoms::firsttab)) - *aWidgetFlags |= MOZ_GTK_TAB_FIRST; - } - - aGtkWidgetType = MOZ_GTK_TAB; - } - break; - case NS_THEME_MENUBAR: - aGtkWidgetType = MOZ_GTK_MENUBAR; - break; - case NS_THEME_MENUPOPUP: - aGtkWidgetType = MOZ_GTK_MENUPOPUP; - break; - case NS_THEME_MENUITEM: - aGtkWidgetType = MOZ_GTK_MENUITEM; - break; - case NS_THEME_CHECKMENUITEM: - aGtkWidgetType = MOZ_GTK_CHECKMENUITEM; - break; - case NS_THEME_RADIOMENUITEM: - aGtkWidgetType = MOZ_GTK_RADIOMENUITEM; - break; - case NS_THEME_WINDOW: - case NS_THEME_DIALOG: - aGtkWidgetType = MOZ_GTK_WINDOW; - break; - default: - return PR_FALSE; - } - - return PR_TRUE; -} - -static int -NativeThemeErrorHandler(Display* dpy, XErrorEvent* error) { - gLastXError = error->error_code; - return 0; -} - -NS_IMETHODIMP -nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext, - nsIFrame* aFrame, - PRUint8 aWidgetType, - const nsRect& aRect, - const nsRect& aClipRect) -{ - GtkWidgetState state; - GtkThemeWidgetType gtkWidgetType; - gint flags; - if (!GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, &state, - &flags)) - return NS_OK; - - GdkWindow* window = NS_STATIC_CAST(GdkWindow*, - aContext->GetNativeGraphicData(nsIRenderingContext::NATIVE_GDK_DRAWABLE)); - - nsTransform2D* transformMatrix; - aContext->GetCurrentTransform(transformMatrix); - - nsRect tr(aRect); - transformMatrix->TransformCoord(&tr.x, &tr.y, &tr.width, &tr.height); - GdkRectangle gdk_rect = {tr.x, tr.y, tr.width, tr.height}; - - nsRect cr(aClipRect); - transformMatrix->TransformCoord(&cr.x, &cr.y, &cr.width, &cr.height); - GdkRectangle gdk_clip = {cr.x, cr.y, cr.width, cr.height}; - - NS_ASSERTION(!IsWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType), - "Trying to render an unsafe widget!"); - - PRBool safeState = IsWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state); - XErrorHandler oldHandler = nsnull; - if (!safeState) { - gLastXError = 0; - oldHandler = XSetErrorHandler(NativeThemeErrorHandler); - } - - moz_gtk_widget_paint(gtkWidgetType, window, &gdk_rect, &gdk_clip, &state, - flags); - - if (!safeState) { - gdk_flush(); - XSetErrorHandler(oldHandler); - - if (gLastXError) { -#ifdef DEBUG - printf("GTK theme failed for widget type %d, error was %d, state was " - "[active=%d,focused=%d,inHover=%d,disabled=%d]\n", - aWidgetType, gLastXError, state.active, state.focused, - state.inHover, state.disabled); -#endif - NS_WARNING("GTK theme failed; disabling unsafe widget"); - SetWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType); - // force refresh of the window, because the widget was not - // successfully drawn it must be redrawn using the default look - RefreshWidgetWindow(aFrame); - } else { - SetWidgetStateSafe(mSafeWidgetStates, aWidgetType, &state); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsNativeThemeGTK::GetWidgetBorder(nsIDeviceContext* aContext, nsIFrame* aFrame, - PRUint8 aWidgetType, nsMargin* aResult) -{ - aResult->top = aResult->left = 0; - switch (aWidgetType) { - case NS_THEME_SCROLLBAR_TRACK_VERTICAL: - case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: - { - MozGtkScrollbarMetrics metrics; - moz_gtk_get_scrollbar_metrics(&metrics); - aResult->top = aResult->left = metrics.trough_border; - } - break; - case NS_THEME_TOOLBOX: - // gtk has no toolbox equivalent. So, although we map toolbox to - // gtk's 'toolbar' for purposes of painting the widget background, - // we don't use the toolbar border for toolbox. - break; - case NS_THEME_TOOLBAR_DUAL_BUTTON: - // TOOLBAR_DUAL_BUTTON is an interesting case. We want a border to draw - // around the entire button + dropdown, and also an inner border if you're - // over the button part. But, we want the inner button to be right up - // against the edge of the outer button so that the borders overlap. - // To make this happen, we draw a button border for the outer button, - // but don't reserve any space for it. - break; - default: - { - GtkThemeWidgetType gtkWidgetType; - if (GetGtkWidgetAndState(aWidgetType, aFrame, gtkWidgetType, nsnull, - nsnull)) - moz_gtk_get_widget_border(gtkWidgetType, &aResult->left, - &aResult->top); - } - } - - aResult->right = aResult->left; - aResult->bottom = aResult->top; - - return NS_OK; -} - -PRBool -nsNativeThemeGTK::GetWidgetPadding(nsIDeviceContext* aContext, - nsIFrame* aFrame, PRUint8 aWidgetType, - nsMargin* aResult) -{ - if (aWidgetType == NS_THEME_BUTTON_FOCUS || - aWidgetType == NS_THEME_TOOLBAR_BUTTON || - aWidgetType == NS_THEME_TOOLBAR_DUAL_BUTTON) { - aResult->SizeTo(0, 0, 0, 0); - return PR_TRUE; - } - - return PR_FALSE; -} - -PRBool -nsNativeThemeGTK::GetWidgetOverflow(nsIDeviceContext* aContext, - nsIFrame* aFrame, PRUint8 aWidgetType, - nsRect* aResult) -{ - nsIntMargin extraSize(0,0,0,0); - // Allow an extra one pixel above and below the thumb for certain - // GTK2 themes (Ximian Industrial, Bluecurve, Misty, at least); - // see moz_gtk_scrollbar_thumb_paint in gtk2drawing.c - switch (aWidgetType) { - case NS_THEME_SCROLLBAR_THUMB_VERTICAL: - extraSize.top = extraSize.bottom = 1; - break; - case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: - extraSize.left = extraSize.right = 1; - break; - default: - return PR_FALSE; - } - - float p2t = aContext->DevUnitsToAppUnits(); - nsMargin m(NSIntPixelsToTwips(extraSize.left, p2t), - NSIntPixelsToTwips(extraSize.top, p2t), - NSIntPixelsToTwips(extraSize.right, p2t), - NSIntPixelsToTwips(extraSize.bottom, p2t)); - nsRect r(nsPoint(0, 0), aFrame->GetSize()); - r.Inflate(m); - *aResult = r; - return PR_TRUE; -} - -NS_IMETHODIMP -nsNativeThemeGTK::GetMinimumWidgetSize(nsIRenderingContext* aContext, - nsIFrame* aFrame, PRUint8 aWidgetType, - nsSize* aResult, PRBool* aIsOverridable) -{ - aResult->width = aResult->height = 0; - *aIsOverridable = PR_TRUE; - - switch (aWidgetType) { - case NS_THEME_SCROLLBAR_BUTTON_UP: - case NS_THEME_SCROLLBAR_BUTTON_DOWN: - { - MozGtkScrollbarMetrics metrics; - moz_gtk_get_scrollbar_metrics(&metrics); - - aResult->width = metrics.slider_width; - aResult->height = metrics.stepper_size; - *aIsOverridable = PR_FALSE; - } - break; - case NS_THEME_SCROLLBAR_BUTTON_LEFT: - case NS_THEME_SCROLLBAR_BUTTON_RIGHT: - { - MozGtkScrollbarMetrics metrics; - moz_gtk_get_scrollbar_metrics(&metrics); - - aResult->width = metrics.stepper_size; - aResult->height = metrics.slider_width; - *aIsOverridable = PR_FALSE; - } - break; - case NS_THEME_SCROLLBAR_THUMB_VERTICAL: - case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: - { - MozGtkScrollbarMetrics metrics; - moz_gtk_get_scrollbar_metrics(&metrics); - - if (aWidgetType == NS_THEME_SCROLLBAR_THUMB_VERTICAL) { - aResult->width = metrics.slider_width; - aResult->height = metrics.min_slider_size; - } else { - aResult->width = metrics.min_slider_size; - aResult->height = metrics.slider_width; - } - - *aIsOverridable = PR_FALSE; - } - break; - case NS_THEME_SCALE_THUMB_HORIZONTAL: - case NS_THEME_SCALE_THUMB_VERTICAL: - { - gint thumb_length, thumb_height; - - if (aWidgetType == NS_THEME_SCALE_THUMB_VERTICAL) { - moz_gtk_get_scalethumb_metrics(GTK_ORIENTATION_VERTICAL, &thumb_length, &thumb_height); - aResult->width = thumb_height; - aResult->height = thumb_length; - } else { - moz_gtk_get_scalethumb_metrics(GTK_ORIENTATION_HORIZONTAL, &thumb_length, &thumb_height); - aResult->width = thumb_length; - aResult->height = thumb_height; - } - - *aIsOverridable = PR_FALSE; - } - break; - case NS_THEME_DROPDOWN_BUTTON: - { - moz_gtk_get_dropdown_arrow_size(&aResult->width, &aResult->height); - *aIsOverridable = PR_FALSE; - } - break; - case NS_THEME_CHECKBOX: - case NS_THEME_RADIO: - { - gint indicator_size, indicator_spacing; - - if (aWidgetType == NS_THEME_CHECKBOX) { - moz_gtk_checkbox_get_metrics(&indicator_size, &indicator_spacing); - } else { - moz_gtk_radio_get_metrics(&indicator_size, &indicator_spacing); - } - - // Include space for the indicator and the padding around it. - aResult->width = indicator_size + 3 * indicator_spacing; - aResult->height = indicator_size + 2 * indicator_spacing; - *aIsOverridable = PR_FALSE; - } - break; - - case NS_THEME_CHECKBOX_CONTAINER: - case NS_THEME_RADIO_CONTAINER: - case NS_THEME_CHECKBOX_LABEL: - case NS_THEME_RADIO_LABEL: - case NS_THEME_BUTTON: - case NS_THEME_TOOLBAR_BUTTON: - { - // Just include our border, and let the box code augment the size. - - nsCOMPtr dc; - aContext->GetDeviceContext(*getter_AddRefs(dc)); - - nsMargin border; - nsNativeThemeGTK::GetWidgetBorder(dc, aFrame, aWidgetType, &border); - aResult->width = border.left + border.right; - aResult->height = border.top + border.bottom; - } - break; - case NS_THEME_SPINNER_UP_BUTTON: - case NS_THEME_SPINNER_DOWN_BUTTON: - // hard-code these sizes - aResult->width = 14; - aResult->height = 13; - break; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsNativeThemeGTK::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType, - nsIAtom* aAttribute, PRBool* aShouldRepaint) -{ - // Some widget types just never change state. - if (aWidgetType == NS_THEME_TOOLBOX || - aWidgetType == NS_THEME_TOOLBAR || - aWidgetType == NS_THEME_STATUSBAR || - aWidgetType == NS_THEME_STATUSBAR_PANEL || - aWidgetType == NS_THEME_STATUSBAR_RESIZER_PANEL || - aWidgetType == NS_THEME_PROGRESSBAR_CHUNK || - aWidgetType == NS_THEME_PROGRESSBAR_CHUNK_VERTICAL || - aWidgetType == NS_THEME_PROGRESSBAR || - aWidgetType == NS_THEME_PROGRESSBAR_VERTICAL || - aWidgetType == NS_THEME_MENUBAR || - aWidgetType == NS_THEME_MENUPOPUP || - aWidgetType == NS_THEME_TOOLTIP || - aWidgetType == NS_THEME_WINDOW || - aWidgetType == NS_THEME_DIALOG) { - *aShouldRepaint = PR_FALSE; - return NS_OK; - } - - // XXXdwh Not sure what can really be done here. Can at least guess for - // specific widgets that they're highly unlikely to have certain states. - // For example, a toolbar doesn't care about any states. - if (!aAttribute) { - // Hover/focus/active changed. Always repaint. - *aShouldRepaint = PR_TRUE; - } - else { - // Check the attribute to see if it's relevant. - // disabled, checked, dlgtype, default, etc. - *aShouldRepaint = PR_FALSE; - if (aAttribute == nsWidgetAtoms::disabled || - aAttribute == nsWidgetAtoms::checked || - aAttribute == nsWidgetAtoms::selected || - aAttribute == nsWidgetAtoms::focused || - aAttribute == nsWidgetAtoms::mozmenuactive) - *aShouldRepaint = PR_TRUE; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsNativeThemeGTK::ThemeChanged() -{ - // this totally sucks. this method is really supposed to be - // static, which is why we can call it without any initialization. - static NS_DEFINE_CID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); - nsCOMPtr dctx = do_CreateInstance(kDeviceContextCID); - dctx->ClearCachedSystemFonts(); - - memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes)); - return NS_OK; -} - -NS_IMETHODIMP_(PRBool) -nsNativeThemeGTK::ThemeSupportsWidget(nsPresContext* aPresContext, - nsIFrame* aFrame, - PRUint8 aWidgetType) -{ - if (aFrame) { - // For now don't support HTML. - if (aFrame->GetContent()->IsNodeOfType(nsINode::eHTML)) - return PR_FALSE; - } - - if (IsWidgetTypeDisabled(mDisabledWidgetTypes, aWidgetType)) - return PR_FALSE; - - switch (aWidgetType) { - case NS_THEME_BUTTON: - case NS_THEME_BUTTON_FOCUS: - case NS_THEME_RADIO: - case NS_THEME_CHECKBOX: - case NS_THEME_TOOLBOX: // N/A - case NS_THEME_TOOLBAR: - case NS_THEME_TOOLBAR_BUTTON: - case NS_THEME_TOOLBAR_DUAL_BUTTON: // so we can override the border with 0 - // case NS_THEME_TOOLBAR_DUAL_BUTTON_DROPDOWN: - // case NS_THEME_TOOLBAR_SEPARATOR: - case NS_THEME_TOOLBAR_GRIPPER: - case NS_THEME_STATUSBAR: - case NS_THEME_STATUSBAR_PANEL: - // case NS_THEME_RESIZER: (n/a for gtk) - // case NS_THEME_LISTBOX: - // case NS_THEME_LISTBOX_LISTITEM: - // case NS_THEME_TREEVIEW: - // case NS_THEME_TREEVIEW_TREEITEM: - // case NS_THEME_TREEVIEW_TWISTY: - // case NS_THEME_TREEVIEW_LINE: - // case NS_THEME_TREEVIEW_HEADER: - // case NS_THEME_TREEVIEW_HEADER_CELL: - // case NS_THEME_TREEVIEW_HEADER_SORTARROW: - // case NS_THEME_TREEVIEW_TWISTY_OPEN: - case NS_THEME_PROGRESSBAR: - case NS_THEME_PROGRESSBAR_CHUNK: - case NS_THEME_PROGRESSBAR_VERTICAL: - case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL: - case NS_THEME_TAB: - // case NS_THEME_TAB_PANEL: - case NS_THEME_TAB_LEFT_EDGE: - case NS_THEME_TAB_RIGHT_EDGE: - case NS_THEME_TAB_PANELS: - case NS_THEME_TOOLTIP: - // case NS_THEME_SPINNER: - case NS_THEME_SPINNER_UP_BUTTON: - case NS_THEME_SPINNER_DOWN_BUTTON: - // case NS_THEME_SCROLLBAR: (n/a for gtk) - case NS_THEME_SCROLLBAR_BUTTON_UP: - case NS_THEME_SCROLLBAR_BUTTON_DOWN: - case NS_THEME_SCROLLBAR_BUTTON_LEFT: - case NS_THEME_SCROLLBAR_BUTTON_RIGHT: - case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: - case NS_THEME_SCROLLBAR_TRACK_VERTICAL: - case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: - case NS_THEME_SCROLLBAR_THUMB_VERTICAL: - // case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: (n/a for gtk) - // case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: (n/a for gtk) - case NS_THEME_TEXTFIELD: - // case NS_THEME_TEXTFIELD_CARET: - case NS_THEME_DROPDOWN_BUTTON: - case NS_THEME_DROPDOWN_TEXTFIELD: - case NS_THEME_SCALE_HORIZONTAL: - case NS_THEME_SCALE_THUMB_HORIZONTAL: - case NS_THEME_SCALE_VERTICAL: - case NS_THEME_SCALE_THUMB_VERTICAL: - // case NS_THEME_SCALE_THUMB_START: - // case NS_THEME_SCALE_THUMB_END: - // case NS_THEME_SCALE_TICK: - case NS_THEME_CHECKBOX_CONTAINER: - case NS_THEME_RADIO_CONTAINER: - case NS_THEME_CHECKBOX_LABEL: - case NS_THEME_RADIO_LABEL: -#ifdef MOZ_WIDGET_GTK2 - case NS_THEME_MENUBAR: - case NS_THEME_MENUPOPUP: - case NS_THEME_MENUITEM: - case NS_THEME_CHECKMENUITEM: - case NS_THEME_RADIOMENUITEM: - case NS_THEME_WINDOW: - case NS_THEME_DIALOG: - case NS_THEME_DROPDOWN: - case NS_THEME_DROPDOWN_TEXT: -#endif - return !IsWidgetStyled(aPresContext, aFrame, aWidgetType); - } - - return PR_FALSE; -} - -NS_IMETHODIMP_(PRBool) -nsNativeThemeGTK::WidgetIsContainer(PRUint8 aWidgetType) -{ - // XXXdwh At some point flesh all of this out. - if (aWidgetType == NS_THEME_DROPDOWN_BUTTON || - aWidgetType == NS_THEME_RADIO || - aWidgetType == NS_THEME_CHECKBOX) - return PR_FALSE; - return PR_TRUE; -} diff --git a/mozilla/widget/src/gtk/nsNativeThemeGTK.h b/mozilla/widget/src/gtk/nsNativeThemeGTK.h deleted file mode 100644 index 51d4bd7ba00..00000000000 --- a/mozilla/widget/src/gtk/nsNativeThemeGTK.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2002 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsITheme.h" -#include "nsCOMPtr.h" -#include "nsIAtom.h" -#include "nsIObserver.h" -#include "nsNativeTheme.h" - -#include -#include "gtkdrawing.h" - -class nsNativeThemeGTK: private nsNativeTheme, - public nsITheme, - public nsIObserver { -public: - NS_DECL_ISUPPORTS - - NS_DECL_NSIOBSERVER - - // The nsITheme interface. - NS_IMETHOD DrawWidgetBackground(nsIRenderingContext* aContext, - nsIFrame* aFrame, PRUint8 aWidgetType, - const nsRect& aRect, - const nsRect& aClipRect); - - NS_IMETHOD GetWidgetBorder(nsIDeviceContext* aContext, nsIFrame* aFrame, - PRUint8 aWidgetType, nsMargin* aResult); - - virtual NS_HIDDEN_(PRBool) GetWidgetPadding(nsIDeviceContext* aContext, - nsIFrame* aFrame, - PRUint8 aWidgetType, - nsMargin* aResult); - - virtual NS_HIDDEN_(PRBool) GetWidgetOverflow(nsIDeviceContext* aContext, - nsIFrame* aFrame, - PRUint8 aWidgetType, - nsRect* aResult); - - NS_IMETHOD GetMinimumWidgetSize(nsIRenderingContext* aContext, - nsIFrame* aFrame, PRUint8 aWidgetType, - nsSize* aResult, PRBool* aIsOverridable); - - NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType, - nsIAtom* aAttribute, PRBool* aShouldRepaint); - - NS_IMETHOD ThemeChanged(); - - NS_IMETHOD_(PRBool) ThemeSupportsWidget(nsPresContext* aPresContext, - nsIFrame* aFrame, - PRUint8 aWidgetType); - - NS_IMETHOD_(PRBool) WidgetIsContainer(PRUint8 aWidgetType); - - nsNativeThemeGTK(); - virtual ~nsNativeThemeGTK(); - -private: - PRBool GetGtkWidgetAndState(PRUint8 aWidgetType, nsIFrame* aFrame, - GtkThemeWidgetType& aGtkWidgetType, - GtkWidgetState* aState, gint* aWidgetFlags); - - void RefreshWidgetWindow(nsIFrame* aFrame); - - PRUint8 mDisabledWidgetTypes[32]; - PRUint8 mSafeWidgetStates[1024]; // 256 widgets * 32 bits per widget - static const char* sDisabledEngines[]; -}; diff --git a/mozilla/widget/src/gtk/nsPointerService.cpp b/mozilla/widget/src/gtk/nsPointerService.cpp deleted file mode 100644 index 0fe4f312974..00000000000 --- a/mozilla/widget/src/gtk/nsPointerService.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include - -#include "nsPointerService.h" -#include "nsWindow.h" - -NS_IMPL_ADDREF_INHERITED(nsPointerService, nsBasePointerService) -NS_IMPL_RELEASE_INHERITED(nsPointerService, nsBasePointerService) -NS_IMPL_QUERY_INTERFACE_INHERITED0(nsPointerService, nsBasePointerService) - - -NS_IMETHODIMP -nsPointerService::WidgetUnderPointer(nsIWidget **_retval, - PRUint32 *aXOffset, PRUint32 *aYOffset) -{ - *_retval = nsnull; - *aXOffset = 0; - *aYOffset = 0; - - Bool retval; - Window root_return; - Window child_return = None; - int root_x_return, root_y_return; - int win_x_return, win_y_return; - unsigned int mask_return; - - // Flush the queue to get any pending destroys out the door. If we - // don't then we can end up with a sitution where the XQueryPointer - // flushes the queue and then the XTranslateCoordinates will cause - // an X error since the window doesn't exist anymore. God, - // sometimes I just hate X. - XSync(GDK_DISPLAY(), False); - - // Query the pointer - retval = XQueryPointer(GDK_DISPLAY(), - GDK_WINDOW_XWINDOW(GDK_ROOT_PARENT()), - &root_return, &child_return, - &root_x_return, &root_y_return, - &win_x_return, &win_y_return, - &mask_return); - - // the pointer is on a different window - if (!retval || child_return == None) - return NS_OK; - - int done = 0; - Window dest_w = child_return; - int xlate_x_return; - int xlate_y_return; - - // loop to find the inner most window - while (!done) { - Window xlate_return = None; - retval = XTranslateCoordinates(GDK_DISPLAY(), - GDK_WINDOW_XWINDOW(GDK_ROOT_PARENT()), - dest_w, - win_x_return, win_y_return, - &xlate_x_return, &xlate_y_return, - &xlate_return); - - // the pointer is on a different screen - if (!retval) - return NS_OK; - - // if xlate_return was None then we've reached the inner most window - if (xlate_return == None) - done = 1; - // otherwise set our new destination window to the return from the - // translation - else - dest_w = xlate_return; - } - - GdkWindow *window; - nsWindow *widget; - - // get the gdk window under the pointer - window = gdk_window_lookup(dest_w); - // it's not a gdk window - if (!window) - return NS_OK; - - // is that an nsWindow window? - gpointer data = NULL; - gdk_window_get_user_data(window, &data); - // nope - if (!data) - return NS_OK; - - // downcast - widget = (nsWindow *)gtk_object_get_data(GTK_OBJECT(data), "nsWindow"); - if (!widget) - return NS_OK; - - *_retval = NS_STATIC_CAST(nsIWidget *, widget); - *aXOffset = xlate_x_return; - *aYOffset = xlate_y_return; - - NS_ADDREF(*_retval); - - return NS_OK; -} diff --git a/mozilla/widget/src/gtk/nsPointerService.h b/mozilla/widget/src/gtk/nsPointerService.h deleted file mode 100644 index e27e8ff3d50..00000000000 --- a/mozilla/widget/src/gtk/nsPointerService.h +++ /dev/null @@ -1,48 +0,0 @@ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsBasePointerService.h" - -class nsPointerService : public nsBasePointerService { - public: - - NS_DECL_ISUPPORTS_INHERITED - - NS_IMETHOD WidgetUnderPointer(nsIWidget **_retval, - PRUint32 *aXOffset, PRUint32 *aYOffset); -}; - - diff --git a/mozilla/widget/src/gtk/nsScreenGtk.cpp b/mozilla/widget/src/gtk/nsScreenGtk.cpp deleted file mode 100644 index 741186176d3..00000000000 --- a/mozilla/widget/src/gtk/nsScreenGtk.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher A. Aillon - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScreenGtk.h" - -#include -#include -#include -#include - -nsScreenGtk :: nsScreenGtk ( ) - : mScreenNum(0), - mRect(0, 0, 0, 0), - mAvailRect(0, 0, 0, 0) -{ -} - - -nsScreenGtk :: ~nsScreenGtk() -{ -} - - -// addref, release, QI -NS_IMPL_ISUPPORTS1(nsScreenGtk, nsIScreen) - - -NS_IMETHODIMP -nsScreenGtk :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight) -{ - *outLeft = mRect.x; - *outTop = mRect.y; - *outWidth = mRect.width; - *outHeight = mRect.height; - - return NS_OK; - -} // GetRect - - -NS_IMETHODIMP -nsScreenGtk :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight) -{ - *outLeft = mAvailRect.x; - *outTop = mAvailRect.y; - *outWidth = mAvailRect.width; - *outHeight = mAvailRect.height; - - return NS_OK; - -} // GetAvailRect - - -NS_IMETHODIMP -nsScreenGtk :: GetPixelDepth(PRInt32 *aPixelDepth) -{ - GdkVisual * rgb_visual = gdk_rgb_get_visual(); - *aPixelDepth = rgb_visual->depth; - - return NS_OK; - -} // GetPixelDepth - - -NS_IMETHODIMP -nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth) -{ - return GetPixelDepth ( aColorDepth ); - -} // GetColorDepth - - -void -nsScreenGtk :: Init () -{ - mAvailRect = mRect = nsRect(0, 0, gdk_screen_width(), gdk_screen_height()); - - // We need to account for the taskbar, etc in the available rect. - // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771 - - // XXX It doesn't change that often, but we should probably - // listen for changes to _NET_WORKAREA. - // XXX do we care about _NET_WM_STRUT_PARTIAL? That will - // add much more complexity to the code here (our screen - // could have a non-rectangular shape), but should - // lead to greater accuracy. - -#if GTK_CHECK_VERSION(2,2,0) - GdkWindow *root_window = gdk_get_default_root_window(); -#else - GdkWindow *root_window = GDK_ROOT_PARENT(); -#endif // GTK_CHECK_VERSION(2,2,0) - - long *workareas; - GdkAtom type_returned; - int format_returned; - int length_returned; - -#if GTK_CHECK_VERSION(2,0,0) - GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL); -#else - GdkAtom cardinal_atom = (GdkAtom) XA_CARDINAL; -#endif - - gdk_error_trap_push(); - - // gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here. - if (!gdk_property_get(root_window, - gdk_atom_intern ("_NET_WORKAREA", FALSE), - cardinal_atom, - 0, G_MAXLONG - 3, FALSE, - &type_returned, - &format_returned, - &length_returned, - (guchar **) &workareas)) { - // This window manager doesn't support the freedesktop standard. - // Nothing we can do about it, so assume full screen size. - return; - } - - // Flush the X queue to catch errors now. - gdk_flush(); - - if (!gdk_error_trap_pop() && - type_returned == cardinal_atom && - length_returned && (length_returned % 4) == 0 && - format_returned == 32) { - int num_items = length_returned / sizeof(long); - - for (int i = 0; i < num_items; i += 4) { - nsRect workarea(workareas[i], workareas[i + 1], - workareas[i + 2], workareas[i + 3]); - if (!mRect.Contains(workarea)) { - NS_WARNING("Invalid bounds"); - continue; - } - - mAvailRect.IntersectRect(mAvailRect, workarea); - } - } - g_free (workareas); -} - -#ifdef MOZ_ENABLE_XINERAMA -void -nsScreenGtk :: Init (XineramaScreenInfo *aScreenInfo) -{ - nsRect xineRect(aScreenInfo->x_org, aScreenInfo->y_org, - aScreenInfo->width, aScreenInfo->height); - - mScreenNum = aScreenInfo->screen_number; - - mAvailRect = mRect = xineRect; -} -#endif // MOZ_ENABLE_XINERAMA diff --git a/mozilla/widget/src/gtk/nsScreenGtk.h b/mozilla/widget/src/gtk/nsScreenGtk.h deleted file mode 100644 index 2ef0144b0c5..00000000000 --- a/mozilla/widget/src/gtk/nsScreenGtk.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsScreenGtk_h___ -#define nsScreenGtk_h___ - -#include "nsIScreen.h" -#include "nsRect.h" - -#ifdef MOZ_ENABLE_XINERAMA -#include -#include -#endif // MOZ_ENABLE_XINERAMA - -//------------------------------------------------------------------------ - -class nsScreenGtk : public nsIScreen -{ -public: - nsScreenGtk(); - ~nsScreenGtk(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCREEN - - void Init(); -#ifdef MOZ_ENABLE_XINERAMA - void Init(XineramaScreenInfo *aScreenInfo); -#endif - -private: - PRUint32 mScreenNum; - nsRect mRect; // in pixels, not twips - nsRect mAvailRect; // in pixels, not twips -}; - -#endif // nsScreenGtk_h___ diff --git a/mozilla/widget/src/gtk/nsScreenManagerGtk.cpp b/mozilla/widget/src/gtk/nsScreenManagerGtk.cpp deleted file mode 100644 index 7638a6c8eeb..00000000000 --- a/mozilla/widget/src/gtk/nsScreenManagerGtk.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScreenManagerGtk.h" -#include "nsScreenGtk.h" -#include "nsIComponentManager.h" -#include "nsRect.h" -#include "nsAutoPtr.h" - -#include - -#ifdef MOZ_ENABLE_XINERAMA -// this header rocks! -extern "C" -{ -#include -} -#endif /* MOZ_ENABLE_XINERAMA */ - -nsScreenManagerGtk :: nsScreenManagerGtk ( ) -{ - // nothing else to do. I guess we could cache a bunch of information - // here, but we want to ask the device at runtime in case anything - // has changed. - mNumScreens = 0; -} - - -nsScreenManagerGtk :: ~nsScreenManagerGtk() -{ - // nothing to see here. -} - - -// addref, release, QI -NS_IMPL_ISUPPORTS1(nsScreenManagerGtk, nsIScreenManager) - - -// this function will make sure that everything has been initialized. -nsresult -nsScreenManagerGtk :: EnsureInit(void) -{ - if (!mCachedScreenArray) { - mCachedScreenArray = do_CreateInstance("@mozilla.org/supports-array;1"); - if (!mCachedScreenArray) { - return NS_ERROR_OUT_OF_MEMORY; - } -#ifdef MOZ_ENABLE_XINERAMA - // get the number of screens via xinerama - XineramaScreenInfo *screenInfo; - if (XineramaIsActive(GDK_DISPLAY())) { - screenInfo = XineramaQueryScreens(GDK_DISPLAY(), &mNumScreens); - } - else { - screenInfo = NULL; - mNumScreens = 1; - } -#else - mNumScreens = 1; -#endif - // there will be < 2 screens if we are either not building with - // xinerama support or xinerama isn't running on the current - // display. - if (mNumScreens < 2) { - mNumScreens = 1; - nsRefPtr screen = new nsScreenGtk(); - if (!screen) - return NS_ERROR_OUT_OF_MEMORY; - - screen->Init(); - - nsISupports *supportsScreen = screen; - mCachedScreenArray->AppendElement(supportsScreen); - } - // If Xinerama is enabled and there's more than one screen, fill - // in the info for all of the screens. If that's not the case - // then nsScreenGTK() defaults to the screen width + height -#ifdef MOZ_ENABLE_XINERAMA - else { -#ifdef DEBUG - printf("Xinerama superpowers activated for %d screens!\n", mNumScreens); -#endif - int i; - for (i=0; i < mNumScreens; i++) { - nsRefPtr screen = new nsScreenGtk(); - if (!screen) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // initialize this screen object - screen->Init(&screenInfo[i]); - - nsISupports *screenSupports = screen; - mCachedScreenArray->AppendElement(screenSupports); - } - } - - if (screenInfo) { - XFree(screenInfo); - } -#endif /* MOZ_ENABLE_XINERAMA */ - } - - return NS_OK;; -} - - -// -// ScreenForRect -// -// Returns the screen that contains the rectangle. If the rect overlaps -// multiple screens, it picks the screen with the greatest area of intersection. -// -// The coordinates are in pixels (not twips) and in screen coordinates. -// -NS_IMETHODIMP -nsScreenManagerGtk :: ScreenForRect ( PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight, - nsIScreen **aOutScreen ) -{ - nsresult rv; - rv = EnsureInit(); - if (NS_FAILED(rv)) { - NS_ERROR("nsScreenManagerGtk::EnsureInit() failed from ScreenForRect\n"); - return rv; - } - // which screen ( index from zero ) should we return? - PRUint32 which = 0; - // Optimize for the common case. If the number of screens is only - // one then this will fall through with which == 0 and will get the - // primary screen. - if (mNumScreens > 1) { - // walk the list of screens and find the one that has the most - // surface area. - PRUint32 count; - mCachedScreenArray->Count(&count); - PRUint32 i; - PRUint32 area = 0; - nsRect windowRect(aX, aY, aWidth, aHeight); - for (i=0; i < count; i++) { - PRInt32 x, y, width, height; - x = y = width = height = 0; - nsCOMPtr screen; - mCachedScreenArray->GetElementAt(i, getter_AddRefs(screen)); - screen->GetRect(&x, &y, &width, &height); - // calculate the surface area - nsRect screenRect(x, y, width, height); - screenRect.IntersectRect(screenRect, windowRect); - PRUint32 tempArea = screenRect.width * screenRect.height; - if (tempArea >= area) { - which = i; - area = tempArea; - } - } - } - nsCOMPtr outScreen; - mCachedScreenArray->GetElementAt(which, getter_AddRefs(outScreen)); - *aOutScreen = outScreen.get(); - NS_IF_ADDREF(*aOutScreen); - return NS_OK; - -} // ScreenForRect - - -// -// GetPrimaryScreen -// -// The screen with the menubar/taskbar. This shouldn't be needed very -// often. -// -NS_IMETHODIMP -nsScreenManagerGtk :: GetPrimaryScreen(nsIScreen * *aPrimaryScreen) -{ - nsresult rv; - rv = EnsureInit(); - if (NS_FAILED(rv)) { - NS_ERROR("nsScreenManagerGtk::EnsureInit() failed from GetPrimaryScreen\n"); - return rv; - } - nsCOMPtr screen; - mCachedScreenArray->GetElementAt(0, getter_AddRefs(screen)); - *aPrimaryScreen = screen.get(); - NS_IF_ADDREF(*aPrimaryScreen); - return NS_OK; - -} // GetPrimaryScreen - - -// -// GetNumberOfScreens -// -// Returns how many physical screens are available. -// -NS_IMETHODIMP -nsScreenManagerGtk :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) -{ - nsresult rv; - rv = EnsureInit(); - if (NS_FAILED(rv)) { - NS_ERROR("nsScreenManagerGtk::EnsureInit() failed from GetNumberOfScreens\n"); - return rv; - } - *aNumberOfScreens = mNumScreens; - return NS_OK; - -} // GetNumberOfScreens - -NS_IMETHODIMP -nsScreenManagerGtk :: ScreenForNativeWidget(void *nativeWidget, nsIScreen **aScreen) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/mozilla/widget/src/gtk/nsScreenManagerGtk.h b/mozilla/widget/src/gtk/nsScreenManagerGtk.h deleted file mode 100644 index 57b4ba1130d..00000000000 --- a/mozilla/widget/src/gtk/nsScreenManagerGtk.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsScreenManagerGtk_h___ -#define nsScreenManagerGtk_h___ - -#include "nsIScreenManager.h" -#include "nsIScreen.h" -#include "nsCOMPtr.h" -#include "nsISupportsArray.h" - -//------------------------------------------------------------------------ - -class nsScreenManagerGtk : public nsIScreenManager -{ -public: - nsScreenManagerGtk ( ); - virtual ~nsScreenManagerGtk(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCREENMANAGER - -private: - - nsresult EnsureInit(void); - - // cache the primary screen object to avoid memory allocation every - // time - nsCOMPtr mCachedScreenArray; - // how many screens do we have? - int mNumScreens; - -}; - -#endif // nsScreenManagerGtk_h___ diff --git a/mozilla/widget/src/gtk/nsSound.cpp b/mozilla/widget/src/gtk/nsSound.cpp deleted file mode 100644 index fc3823406c5..00000000000 --- a/mozilla/widget/src/gtk/nsSound.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include - -#include "nscore.h" -#include "plstr.h" -#include "prlink.h" - -#include "nsSound.h" - -#include "nsIURL.h" -#include "nsIFileURL.h" -#include "nsNetUtil.h" -#include "nsCOMPtr.h" - -#include -#include - -#include -/* used with esd_open_sound */ -static int esdref = -1; -static PRLibrary *elib = nsnull; - -// the following from esd.h - -#define ESD_BITS8 (0x0000) -#define ESD_BITS16 (0x0001) -#define ESD_MONO (0x0010) -#define ESD_STEREO (0x0020) -#define ESD_STREAM (0x0000) -#define ESD_PLAY (0x1000) - -#define WAV_MIN_LENGTH 44 - -typedef int (PR_CALLBACK *EsdOpenSoundType)(const char *host); -typedef int (PR_CALLBACK *EsdCloseType)(int); - -/* used to play the sounds from the find symbol call */ -typedef int (PR_CALLBACK *EsdPlayStreamFallbackType)(int, int, const char *, const char *); - -NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver) - -//////////////////////////////////////////////////////////////////////// -nsSound::nsSound() -{ - mInited = PR_FALSE; -} - -nsSound::~nsSound() -{ - /* see above comment */ - - if (esdref != -1) { - EsdCloseType EsdClose = (EsdCloseType) PR_FindSymbol(elib, "esd_close"); - (*EsdClose)(esdref); - esdref = -1; - } -} - -NS_IMETHODIMP -nsSound::Init() -{ - /* we don't need to do esd_open_sound if we are only going to play files - but we will if we want to do things like streams, etc - */ - if (mInited) return NS_OK; - if (elib) return NS_OK; - - - EsdOpenSoundType EsdOpenSound; - - elib = PR_LoadLibrary("libesd.so.0"); - if (!elib) return NS_ERROR_FAILURE; - - EsdOpenSound = (EsdOpenSoundType) PR_FindSymbol(elib, "esd_open_sound"); - - if (!EsdOpenSound) - return NS_ERROR_FAILURE; - - esdref = (*EsdOpenSound)("localhost"); - - if (!esdref) - return NS_ERROR_FAILURE; - - mInited = PR_TRUE; - - return NS_OK; -} - -/* static */ void -nsSound::Shutdown() -{ - if (elib) { - PR_UnloadLibrary(elib) - elib = nsnull; - } -} - -#define GET_WORD(s, i) (s[i+1] << 8) | s[i] -#define GET_DWORD(s, i) (s[i+3] << 24) | (s[i+2] << 16) | (s[i+1] << 8) | s[i] - -NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader, - nsISupports *context, - nsresult aStatus, - PRUint32 dataLen, - const PRUint8 *data) -{ - - // print a load error on bad status - if (NS_FAILED(aStatus)) { -#ifdef DEBUG - if (aLoader) { - nsCOMPtr request; - aLoader->GetRequest(getter_AddRefs(request)); - if (request) { - nsCOMPtr uri; - nsCOMPtr channel = do_QueryInterface(request); - if (channel) { - channel->GetURI(getter_AddRefs(uri)); - if (uri) { - nsCAutoString uriSpec; - uri->GetSpec(uriSpec); - printf("Failed to load %s\n", uriSpec.get()); - } - } - } - } -#endif - return aStatus; - } - - int fd, mask = 0; - - unsigned long samples_per_sec=0, avg_bytes_per_sec=0; - unsigned long rate=0; - unsigned short format, channels = 1, block_align, bits_per_sample=0; - - - if (memcmp(data, "RIFF", 4)) { -#ifdef DEBUG - printf("We only support WAV files currently.\n"); -#endif - return NS_ERROR_FAILURE; - } - - if (dataLen <= WAV_MIN_LENGTH) { - NS_WARNING("WAV files should be longer than 44 bytes."); - return NS_ERROR_FAILURE; - } - - PRUint32 i; - for (i= 0; i < dataLen; i++) { - - if (i+3 <= dataLen) - if ((data[i] == 'f') && - (data[i+1] == 'm') && - (data[i+2] == 't') && - (data[i+3] == ' ')) { - i += 4; - - /* length of the rest of this subblock (should be 16 for PCM data */ - // long len = GET_DWORD(data, i); - i+=4; - - format = GET_WORD(data, i); - i+=2; - - channels = GET_WORD(data, i); - i+=2; - - samples_per_sec = GET_DWORD(data, i); - i+=4; - - avg_bytes_per_sec = GET_DWORD(data, i); - i+=4; - - block_align = GET_WORD(data, i); - i+=2; - - bits_per_sample = GET_WORD(data, i); - i+=2; - - rate = samples_per_sec; - - break; - } - } - -#ifdef DEBUG - printf("f: %d | c: %d | sps: %li | abps: %li | ba: %d | bps: %d | rate: %li\n", - format, channels, samples_per_sec, avg_bytes_per_sec, block_align, bits_per_sample, rate); -#endif - - /* open up conneciton to esd */ - EsdPlayStreamFallbackType EsdPlayStreamFallback = (EsdPlayStreamFallbackType) PR_FindSymbol(elib, "esd_play_stream_fallback"); - - mask = ESD_PLAY | ESD_STREAM; - - if (bits_per_sample == 8) - mask |= ESD_BITS8; - else - mask |= ESD_BITS16; - - if (channels == 1) - mask |= ESD_MONO; - else - mask |= ESD_STEREO; - - fd = (*EsdPlayStreamFallback)(mask, rate, NULL, "mozillaSound"); - - if (fd < 0) { - return NS_ERROR_FAILURE; - } - - /* write data out */ - // ESD only handle little-endian data. - // Swap the byte order if we're on a big-endian architecture. -#ifdef IS_BIG_ENDIAN - if (bits_per_sample == 8) - write(fd, data, dataLen); - else { - PRUint8 *buf = new PRUint8[dataLen - WAV_MIN_LENGTH]; - // According to the wav file format, the first 44 bytes are headers. - // We don't really need to send them. - if (!buf) - return NS_ERROR_OUT_OF_MEMORY; - for (PRUint32 j = 0; j < dataLen - WAV_MIN_LENGTH - 1; j += 2) { - buf[j] = data[j + WAV_MIN_LENGTH + 1]; - buf[j + 1] = data[j + WAV_MIN_LENGTH]; - } - write(fd, buf, (dataLen - WAV_MIN_LENGTH)); - delete [] buf; - } -#else - write(fd, data, dataLen); -#endif - - close(fd); - - return NS_OK; -} - -NS_METHOD nsSound::Beep() -{ - ::gdk_beep(); - - return NS_OK; -} - -NS_METHOD nsSound::Play(nsIURL *aURL) -{ - nsresult rv; - - if (!mInited) - Init(); - - if (!elib) return NS_ERROR_FAILURE; - - nsCOMPtr loader; - rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this); - - return rv; -} - -NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) -{ - if (aSoundAlias.EqualsLiteral("_moz_mailbeep")) - { - return Beep(); - } - nsresult rv; - nsCOMPtr fileURI; - - // create a nsILocalFile and then a nsIFileURL from that - nsCOMPtr soundFile; - rv = NS_NewLocalFile(aSoundAlias, PR_TRUE, - getter_AddRefs(soundFile)); - NS_ENSURE_SUCCESS(rv,rv); - - rv = NS_NewFileURI(getter_AddRefs(fileURI), soundFile); - NS_ENSURE_SUCCESS(rv,rv); - - nsCOMPtr fileURL = do_QueryInterface(fileURI,&rv); - NS_ENSURE_SUCCESS(rv,rv); - rv = Play(fileURL); - return rv; -} diff --git a/mozilla/widget/src/gtk/nsSound.h b/mozilla/widget/src/gtk/nsSound.h deleted file mode 100644 index bd0062c322c..00000000000 --- a/mozilla/widget/src/gtk/nsSound.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsSound_h__ -#define __nsSound_h__ - -#include "nsISound.h" -#include "nsIStreamLoader.h" - -#include - -class nsSound : public nsISound, - public nsIStreamLoaderObserver -{ - public: - - nsSound(); - virtual ~nsSound(); - - static void Shutdown(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISOUND - NS_DECL_NSISTREAMLOADEROBSERVER - -private: - PRBool mInited; - -}; - -#endif /* __nsSound_h__ */ diff --git a/mozilla/widget/src/gtk/nsToolkit.cpp b/mozilla/widget/src/gtk/nsToolkit.cpp deleted file mode 100644 index 9ff972507a0..00000000000 --- a/mozilla/widget/src/gtk/nsToolkit.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nscore.h" // needed for 'nsnull' -#include "nsToolkit.h" -#include "nsWidgetAtoms.h" - -// -// Static thread local storage index of the Toolkit -// object associated with a given thread... -// -static PRUintn gToolkitTLSIndex = 0; - -//------------------------------------------------------------------------- -// -// constructor -// -//------------------------------------------------------------------------- -nsToolkit::nsToolkit() -{ - mSharedGC = nsnull; -} - -//------------------------------------------------------------------------- -// -// destructor -// -//------------------------------------------------------------------------- -nsToolkit::~nsToolkit() -{ - if (mSharedGC) { - gdk_gc_unref(mSharedGC); - } - - // Remove the TLS reference to the toolkit... - PR_SetThreadPrivate(gToolkitTLSIndex, nsnull); -} - -//------------------------------------------------------------------------- -// -// nsISupports implementation macro -// -//------------------------------------------------------------------------- - -NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit) - -void nsToolkit::CreateSharedGC(void) -{ - GdkPixmap *pixmap; - - if (mSharedGC) - return; - - pixmap = gdk_pixmap_new(NULL, 1, 1, gdk_rgb_get_visual()->depth); - mSharedGC = gdk_gc_new(pixmap); - gdk_pixmap_unref(pixmap); -} - -GdkGC *nsToolkit::GetSharedGC(void) -{ - return gdk_gc_ref(mSharedGC); -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsToolkit::Init(PRThread *aThread) -{ - CreateSharedGC(); - - nsWidgetAtoms::RegisterAtoms(); - - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Return the nsIToolkit for the current thread. If a toolkit does not -// yet exist, then one will be created... -// -//------------------------------------------------------------------------- -NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult) -{ - nsIToolkit* toolkit = nsnull; - nsresult rv = NS_OK; - PRStatus status; - - // Create the TLS index the first time through... - if (0 == gToolkitTLSIndex) { - status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL); - if (PR_FAILURE == status) { - rv = NS_ERROR_FAILURE; - } - } - - if (NS_SUCCEEDED(rv)) { - toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex); - - // - // Create a new toolkit for this thread... - // - if (!toolkit) { - toolkit = new nsToolkit(); - - if (!toolkit) { - rv = NS_ERROR_OUT_OF_MEMORY; - } else { - NS_ADDREF(toolkit); - toolkit->Init(PR_GetCurrentThread()); - // - // The reference stored in the TLS is weak. It is removed in the - // nsToolkit destructor... - // - PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit); - } - } else { - NS_ADDREF(toolkit); - } - *aResult = toolkit; - } - - return rv; -} - - diff --git a/mozilla/widget/src/gtk/nsToolkit.h b/mozilla/widget/src/gtk/nsToolkit.h deleted file mode 100644 index 3c72e991014..00000000000 --- a/mozilla/widget/src/gtk/nsToolkit.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef TOOLKIT_H -#define TOOLKIT_H - -#include "nsIToolkit.h" -#include - -/** - * Wrapper around the thread running the message pump. - * The toolkit abstraction is necessary because the message pump must - * execute within the same thread that created the widget under Win32. - */ - -class nsToolkit : public nsIToolkit -{ - -public: - nsToolkit(); - virtual ~nsToolkit(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(PRThread *aThread); - - void CreateSharedGC(void); - GdkGC *GetSharedGC(void); - -private: - GdkGC *mSharedGC; -}; - - - -#endif // TOOLKIT_H diff --git a/mozilla/widget/src/gtk/nsWidget.cpp b/mozilla/widget/src/gtk/nsWidget.cpp deleted file mode 100644 index 90d84e1e0b6..00000000000 --- a/mozilla/widget/src/gtk/nsWidget.cpp +++ /dev/null @@ -1,2417 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Andrew Wellington - * Graham Dennis - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - -#include "nsWidget.h" - -#include "nsGtkEventHandler.h" -#include "nsIAppShell.h" -#include "nsIComponentManager.h" -#include "nsIDeviceContext.h" -#include "nsIFontMetrics.h" -#include "nsToolkit.h" -#include "nsWidgetsCID.h" -#include "nsGfxCIID.h" -#include -#include "nsIRollupListener.h" -#include "nsIMenuRollup.h" -#include "nsIServiceManager.h" -#include "nsIDragSessionGTK.h" -#include "nsIDragService.h" - -#include "nsGtkUtils.h" // for nsGtkUtils::gdk_keyboard_get_modifiers() - -static void -ConvertKeyEventToContextMenuEvent(const nsKeyEvent* inKeyEvent, - nsMouseEvent* outCMEvent); - -static inline PRBool -IsContextMenuKey(const nsKeyEvent& inKeyEvent); - -static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); -static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); - -// this is the nsWindow with the focus -nsWidget *nsWidget::sFocusWindow = 0; - -// this is the last time that an event happened. we keep this -// around so that we can synth drag events properly -guint32 nsWidget::sLastEventTime = 0; - -// we should convert the context key to context menu event in the OnKey member -// function, and dispatch the NS_CONTEXTMENU instead of a normal key event. -PRBool nsWidget::OnKey(nsKeyEvent &aEvent) -{ - - PRBool ret = PR_FALSE; - PRBool releaseWidget = PR_FALSE; - nsWidget *widget = nsnull; - - // rewrite the key event to the window with 'de focus - if (sFocusWindow) { - widget = sFocusWindow; - NS_ADDREF(widget); - aEvent.widget = sFocusWindow; - releaseWidget = PR_TRUE; - } - if (mEventCallback) { - // before we dispatch a key, check if it's the context menu key. - // If so, send a context menu key event instead. - if (IsContextMenuKey(aEvent)) { - nsMouseEvent contextMenuEvent(PR_TRUE, 0, nsnull, nsMouseEvent::eReal); - ConvertKeyEventToContextMenuEvent(&aEvent, &contextMenuEvent); - ret = DispatchWindowEvent(&contextMenuEvent); - } - else - ret = DispatchWindowEvent(&aEvent); - } - - if (releaseWidget) - NS_RELEASE(widget); - - return ret; -} - -// -// ConvertKeyEventToContextMenuEvent -// -// Take a key event and all of its attributes at convert it into -// a context menu event. We want just about everything (focused -// widget, etc) but a few fields should be tweaked. See also the -// implemention for the Mac - -static void -ConvertKeyEventToContextMenuEvent(const nsKeyEvent* inKeyEvent, - nsMouseEvent* outCMEvent) -{ - *(nsInputEvent *)outCMEvent = *(nsInputEvent *)inKeyEvent; - outCMEvent->eventStructType = NS_MOUSE_EVENT; - outCMEvent->message = NS_CONTEXTMENU; - outCMEvent->button = nsMouseEvent::eRightButton; - outCMEvent->context = nsMouseEvent::eContextMenuKey; - outCMEvent->isShift = outCMEvent->isControl = PR_FALSE; - outCMEvent->isAlt = outCMEvent->isMeta = PR_FALSE; - outCMEvent->clickCount = 0; - outCMEvent->acceptActivation = PR_FALSE; -} - - -// IsContextMenuKey -// -// Check if the event should be a context menu event instead. Currently, -// that is a Shift-F10 in linux. -// -static inline PRBool -IsContextMenuKey(const nsKeyEvent& inKeyEvent) -{ - enum { kContextMenuKey = NS_VK_F10, kDedicatedContextMenuKey = NS_VK_CONTEXT_MENU }; - - return ((inKeyEvent.keyCode == kContextMenuKey && inKeyEvent.isShift && - !inKeyEvent.isControl && !inKeyEvent.isMeta && !inKeyEvent.isAlt) || - (inKeyEvent.keyCode == kDedicatedContextMenuKey && !inKeyEvent.isShift && - !inKeyEvent.isControl && !inKeyEvent.isMeta && !inKeyEvent.isAlt)); -} - -PRBool nsWidget::OnInput(nsInputEvent &aEvent) -{ - - PRBool ret = PR_FALSE; - PRBool releaseWidget = PR_FALSE; - nsWidget *widget = NULL; - - // rewrite the key event to the window with 'de focus - if (sFocusWindow) { - widget = sFocusWindow; - NS_ADDREF(widget); - aEvent.widget = sFocusWindow; - releaseWidget = PR_TRUE; - } - if (mEventCallback) { - ret = DispatchWindowEvent(&aEvent); - } - - if (releaseWidget) - NS_RELEASE(widget); - - return ret; -} - -/* virtual - really to be implemented by nsWindow */ -GtkWidget *nsWidget::GetOwningWidget() -{ - NS_WARNING("nsWidget::GetOwningWidget called!\n"); - return nsnull; -} - -void nsWidget::SetLastEventTime(guint32 aTime) -{ - sLastEventTime = aTime; -} - -void nsWidget::GetLastEventTime(guint32 *aTime) -{ - if (aTime) - *aTime = sLastEventTime; -} - -void nsWidget::DropMotionTarget(void) -{ - if (sButtonMotionTarget) { - GtkWidget *owningWidget = sButtonMotionTarget->GetOwningWidget(); - if (owningWidget) - gtk_grab_remove(owningWidget); - - sButtonMotionTarget = nsnull; - } -} - -nsCOMPtr nsWidget::gRollupListener; -nsWeakPtr nsWidget::gRollupWidget; - -PRBool nsWidget::mGDKHandlerInstalled = PR_FALSE; -PRBool nsWidget::sTimeCBSet = PR_FALSE; - -// -// Keep track of the last widget being "dragged" -// -nsWidget *nsWidget::sButtonMotionTarget = NULL; -gint nsWidget::sButtonMotionRootX = -1; -gint nsWidget::sButtonMotionRootY = -1; -gint nsWidget::sButtonMotionWidgetX = -1; -gint nsWidget::sButtonMotionWidgetY = -1; - -//#undef DEBUG_pavlov - -nsWidget::nsWidget() -{ - mWidget = nsnull; - mMozBox = 0; - mParent = nsnull; - mPreferredWidth = 0; - mPreferredHeight = 0; - mShown = PR_FALSE; - mInternalShown = PR_FALSE; - mBounds.x = 0; - mBounds.y = 0; - mBounds.width = 0; - mBounds.height = 0; - mIsToplevel = PR_FALSE; - - mUpdateArea = do_CreateInstance(kRegionCID); - if (mUpdateArea) { - mUpdateArea->Init(); - mUpdateArea->SetTo(0, 0, 0, 0); - } - - mListenForResizes = PR_FALSE; - mHasFocus = PR_FALSE; - if (mGDKHandlerInstalled == PR_FALSE) { - mGDKHandlerInstalled = PR_TRUE; - // It is most convenient for us to intercept our events after - // they have been converted to GDK, but before GTK+ gets them - gdk_event_handler_set (handle_gdk_event, NULL, NULL); - } - if (sTimeCBSet == PR_FALSE) { - sTimeCBSet = PR_TRUE; - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - if (!dragService) { -#ifdef DEBUG - g_print("*** warning: failed to get the drag service. this is a _bad_ thing.\n"); -#endif - sTimeCBSet = PR_FALSE; - } - nsCOMPtr dragServiceGTK; - dragServiceGTK = do_QueryInterface(dragService); - if (!dragServiceGTK) { - sTimeCBSet = PR_FALSE; - return; - } - dragServiceGTK->TargetSetTimeCallback(nsWidget::GetLastEventTime); - } -} - -nsWidget::~nsWidget() -{ -#ifdef NOISY_DESTROY - IndentByDepth(stdout); - printf("nsWidget::~nsWidget:%p\n", this); -#endif - - // it's safe to always call Destroy() because it will only allow itself - // to be called once - Destroy(); - -} - - -//------------------------------------------------------------------------- -// -// nsISupport stuff -// -//------------------------------------------------------------------------- -NS_IMPL_ISUPPORTS_INHERITED2(nsWidget, nsBaseWidget, nsIKBStateControl, nsISupportsWeakReference) - -NS_IMETHODIMP nsWidget::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) -{ - gint x; - gint y; - - if (mWidget) - { - if (mWidget->window) - { - gdk_window_get_origin(mWidget->window, &x, &y); - aNewRect.x = x + aOldRect.x; - aNewRect.y = y + aOldRect.y; - } - else - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) -{ -#ifdef DEBUG_pavlov - g_print("nsWidget::ScreenToWidget\n"); -#endif - NS_NOTYETIMPLEMENTED("nsWidget::ScreenToWidget"); - return NS_OK; -} - -#ifdef DEBUG -void -nsWidget::IndentByDepth(FILE* out) -{ - PRInt32 depth = 0; - nsWidget* parent = (nsWidget*)mParent.get(); - while (parent) { - parent = (nsWidget*) parent->mParent.get(); - depth++; - } - while (--depth >= 0) fprintf(out, " "); -} -#endif - -//------------------------------------------------------------------------- -// -// Close this nsWidget -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::Destroy(void) -{ - // printf("%p nsWidget::Destroy()\n", this); - // make sure we don't call this more than once. - if (mIsDestroying) - return NS_OK; - - // we don't want people sending us events if we are the button motion target - if (sButtonMotionTarget == this) - DropMotionTarget(); - - // ok, set our state - mIsDestroying = PR_TRUE; - - // call in and clean up any of our base widget resources - // are released - nsBaseWidget::Destroy(); - mParent = 0; - - // just to be safe. If we're going away and for some reason we're still - // the rollup widget, rollup and turn off capture. - nsCOMPtr rollupWidget = do_QueryReferent(gRollupWidget); - if ( NS_STATIC_CAST(nsIWidget*,this) == rollupWidget.get() ) { - if ( gRollupListener ) - gRollupListener->Rollup(); - gRollupWidget = nsnull; - gRollupListener = nsnull; - } - - // destroy our native windows - DestroyNative(); - - // make sure to call the OnDestroy if it hasn't been called yet - if (mOnDestroyCalled == PR_FALSE) - OnDestroy(); - - // make sure no callbacks happen - mEventCallback = nsnull; - - return NS_OK; -} - -// this is the function that will destroy the native windows for this widget. - -/* virtual */ -void nsWidget::DestroyNative(void) -{ - if (mMozBox) { - // destroying the mMozBox will also destroy the mWidget in question. - ::gtk_widget_destroy(mMozBox); - mWidget = NULL; - mMozBox = NULL; - } -} - -// make sure that we clean up here - -void nsWidget::OnDestroy() -{ - mOnDestroyCalled = PR_TRUE; - // release references to children, device context, toolkit + app shell - nsBaseWidget::OnDestroy(); - - nsCOMPtr kungFuDeathGrip = this; - DispatchStandardEvent(NS_DESTROY); -} - -gint -nsWidget::DestroySignal(GtkWidget* aGtkWidget, nsWidget* aWidget) -{ - aWidget->OnDestroySignal(aGtkWidget); - return PR_TRUE; -} - -void -nsWidget::OnDestroySignal(GtkWidget* aGtkWidget) -{ - OnDestroy(); -} - -//------------------------------------------------------------------------- -// -// Get this nsWidget parent -// -//------------------------------------------------------------------------- - -nsIWidget* nsWidget::GetParent(void) -{ - return mParent; -} - -//------------------------------------------------------------------------- -// -// Hide or show this component -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::Show(PRBool bState) -{ - if (!mWidget) - return NS_OK; // Will be null durring printing - - mShown = bState; - - ResetInternalVisibility(); - - return NS_OK; -} - -void nsWidget::ResetInternalVisibility() -{ - PRBool show = mShown; - if (show) { - if (mParent != nsnull) { - nsRect parentBounds; - mParent->GetClientBounds(parentBounds); - parentBounds.x = parentBounds.y = 0; - nsRect myBounds; - GetBounds(myBounds); - if (!myBounds.Intersects(parentBounds)) { - show = PR_FALSE; - } - } - } - - if (show == mInternalShown) { - return; - } - - SetInternalVisibility(show); -} - -void nsWidget::SetInternalVisibility(PRBool aVisible) -{ - mInternalShown = aVisible; - - if (aVisible) { - if (mWidget) - gtk_widget_show(mWidget); - if (mMozBox) - gtk_widget_show(mMozBox); - } else { - if (mWidget) - gtk_widget_hide(mWidget); - if (mMozBox) - gtk_widget_hide(mMozBox); - } -} - -NS_IMETHODIMP nsWidget::CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) -{ - return NS_OK; -} - -GdkWindow* nsWidget::GetLayeringWindow() -{ - return mWidget->window; -} - -void nsWidget::ResetZOrder() -{ - if (!GetNextSibling()) { - GdkWindow* window = GetLayeringWindow(); - if (window) { - gdk_window_raise(window); - } - } else { - // Move this widget and all the widgets above it to the top, in - // the right order - for (nsWidget* w = this; w; - w = NS_STATIC_CAST(nsWidget*, w->GetNextSibling())) { - GdkWindow* window = w->GetLayeringWindow(); - if (window) { - gdk_window_raise(window); - } - } - } -} - -NS_IMETHODIMP nsWidget::SetZIndex(PRInt32 aZIndex) -{ - nsIWidget* oldPrev = GetPrevSibling(); - - nsBaseWidget::SetZIndex(aZIndex); - - if (GetPrevSibling() != oldPrev) { - ResetZOrder(); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::IsVisible(PRBool &aState) -{ - if (mWidget) - aState = GTK_WIDGET_VISIBLE(mWidget); - else - aState = PR_FALSE; - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::GetWindowClass(char *aClass) -{ -//nsWidget's base impl will throw a failure -//to find out that this toolkit supports this function pass null. - if (!aClass) - return NS_OK; - - *aClass = nsnull; - - if (mWindowType != eWindowType_toplevel) - return NS_OK; - - GtkWindow *topWindow; - topWindow = GetTopLevelWindow(); - - if (!topWindow) - return NS_ERROR_FAILURE; - - XClassHint *class_hint = XAllocClassHint(); - - if (XGetClassHint(GDK_DISPLAY(), - GDK_WINDOW_XWINDOW(GTK_WIDGET(topWindow)->window), - class_hint)) - aClass = strdup(class_hint->res_class); - - XFree(class_hint); - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetWindowClass(char *aClass) -{ - if (mWindowType != eWindowType_toplevel) - return NS_OK; - - GtkWindow *topWindow; - topWindow = GetTopLevelWindow(); - - if (!topWindow) - return NS_ERROR_FAILURE; - - XClassHint *class_hint = XAllocClassHint(); - - class_hint->res_name = "Mozilla"; - class_hint->res_class = aClass; - - XSetClassHint(GDK_DISPLAY(), - GDK_WINDOW_XWINDOW(GTK_WIDGET(topWindow)->window), - class_hint); - XFree(class_hint); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Move this component -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::ConstrainPosition(PRBool aAllowSlop, - PRInt32 *aX, PRInt32 *aY) -{ - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Move this component -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::Move(PRInt32 aX, PRInt32 aY) -{ - // check if we are at right place already - if((aX == mBounds.x) && (aY == mBounds.y)) { - return NS_OK; - } - - mBounds.x = aX; - mBounds.y = aY; - - if (mMozBox) - { - gtk_mozbox_set_position(GTK_MOZBOX(mMozBox), aX, aY); - } - - ResetInternalVisibility(); - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) -{ -#ifdef DEBUG_MOVE - printf("nsWidget::Resize %s (%p) to %d %d\n", - (const char *) debug_GetName(mWidget), - this, - aWidth, aHeight); -#endif - mBounds.width = aWidth; - mBounds.height = aHeight; - - if (mWidget) - gtk_widget_set_usize(mWidget, aWidth, aHeight); - - ResetInternalVisibility(); - for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - NS_STATIC_CAST(nsWidget*, kid)->ResetInternalVisibility(); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, - PRInt32 aHeight, PRBool aRepaint) -{ - Move(aX, aY); - Resize(aWidth,aHeight,aRepaint); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Send a resize message to the listener -// -//------------------------------------------------------------------------- -PRBool nsWidget::OnResize(nsSizeEvent *event) -{ - - mBounds.width = event->mWinWidth; - mBounds.height = event->mWinHeight; - - return DispatchWindowEvent(event); -} - - -PRBool nsWidget::OnResize(nsRect &aRect) -{ - nsSizeEvent event(PR_TRUE, NS_SIZE, this); - - InitEvent(event); - - nsRect *foo = new nsRect(0, 0, aRect.width, aRect.height); - event.windowSize = foo; - - event.refPoint.x = 0; - event.refPoint.y = 0; - event.mWinWidth = aRect.width; - event.mWinHeight = aRect.height; - - mBounds.width = aRect.width; - mBounds.height = aRect.height; - - ResetInternalVisibility(); - - NS_ADDREF_THIS(); - PRBool result = OnResize(&event); - NS_RELEASE_THIS(); - - return result; -} - - -//------ -// Move -//------ -PRBool nsWidget::OnMove(PRInt32 aX, PRInt32 aY) -{ -#if 0 - printf("nsWidget::OnMove %s (%p) (%d,%d) -> (%d,%d)\n", - (const char *) debug_GetName(mWidget), - this, mBounds.x, mBounds.y, aX, aY); -#endif - mBounds.x = aX; - mBounds.y = aY; - - ResetInternalVisibility(); - - nsGUIEvent event(PR_TRUE, NS_MOVE, this); - InitEvent(event); - event.refPoint.x = aX; - event.refPoint.y = aY; - PRBool result = DispatchWindowEvent(&event); - return result; -} - -//------------------------------------------------------------------------- -// -// Enable/disable this component -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::Enable(PRBool aState) -{ - if (mWidget) - { - if (GTK_WIDGET_SENSITIVE(mWidget) == aState) - return NS_OK; - gtk_widget_set_sensitive(mWidget, aState); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::IsEnabled(PRBool *aState) -{ - NS_ENSURE_ARG_POINTER(aState); - *aState = !mWidget || GTK_WIDGET_SENSITIVE(mWidget); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Give the focus to this component -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::SetFocus(PRBool aRaise) -{ - // call this so that any cleanup will happen that needs to... - LoseFocus(); - - if (mWidget) - { - if (!GTK_WIDGET_HAS_FOCUS(mWidget)) - gtk_widget_grab_focus(mWidget); - } - - return NS_OK; -} - -/* virtual */ void -nsWidget::LoseFocus(void) -{ - // doesn't do anything. needed for nsWindow housekeeping, really. - if (mHasFocus == PR_FALSE) - return; - - sFocusWindow = 0; - mHasFocus = PR_FALSE; - -} - -//------------------------------------------------------------------------- -// -// Get this component font -// -//------------------------------------------------------------------------- -nsIFontMetrics *nsWidget::GetFont(void) -{ - NS_NOTYETIMPLEMENTED("nsWidget::GetFont"); - return nsnull; -} - -//------------------------------------------------------------------------- -// -// Set this component font -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -//------------------------------------------------------------------------- -// -// Set the background color -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::SetBackgroundColor(const nscolor &aColor) -{ - nsBaseWidget::SetBackgroundColor(aColor); - - if (nsnull != mWidget) { - GdkColor color_nor, color_bri, color_dark; - - NSCOLOR_TO_GDKCOLOR(aColor, color_nor); - NSCOLOR_TO_GDKCOLOR(NS_BrightenColor(aColor), color_bri); - NSCOLOR_TO_GDKCOLOR(NS_DarkenColor(aColor), color_dark); - - // gdk_color.red = 256 * NS_GET_R(aColor); - // gdk_color.green = 256 * NS_GET_G(aColor); - // gdk_color.blue = 256 * NS_GET_B(aColor); - // gdk_color.pixel ? - - // calls virtual native set color - SetBackgroundColorNative(&color_nor, &color_bri, &color_dark); - -#if 0 - GtkStyle *style = gtk_style_copy(mWidget->style); - - style->bg[GTK_STATE_NORMAL]=gdk_color; - // other states too? (GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, - // GTK_STATE_SELECTED, GTK_STATE_INSENSITIVE) - gtk_widget_set_style(mWidget, style); - gtk_style_unref(style); -#endif - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Set this component cursor -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::SetCursor(nsCursor aCursor) -{ -#ifdef DEBUG - printf("nsWidget::SetCursor\n"); -#endif - if (!mWidget || !mWidget->window) - return NS_ERROR_FAILURE; - - // Only change cursor if it's changing - if (aCursor != mCursor) { - GdkCursor *newCursor = 0; - - /* These cases should agree with enum nsCursor in nsIWidget.h - * We're limited to those cursors available with XCreateFontCursor() - * If you change these, change them in gtk/nsWindow, too. */ - switch(aCursor) { - case eCursor_standard: - newCursor = gdk_cursor_new(GDK_LEFT_PTR); - break; - - case eCursor_wait: - newCursor = gdk_cursor_new(GDK_WATCH); - break; - - case eCursor_select: - newCursor = gdk_cursor_new(GDK_XTERM); - break; - - case eCursor_hyperlink: - newCursor = gdk_cursor_new(GDK_HAND2); - break; - - case eCursor_n_resize: - newCursor = gdk_cursor_new(GDK_TOP_SIDE); - break; - - case eCursor_s_resize: - newCursor = gdk_cursor_new(GDK_BOTTOM_SIDE); - break; - - case eCursor_w_resize: - newCursor = gdk_cursor_new(GDK_LEFT_SIDE); - break; - - case eCursor_e_resize: - newCursor = gdk_cursor_new(GDK_RIGHT_SIDE); - break; - - case eCursor_nw_resize: - newCursor = gdk_cursor_new(GDK_TOP_LEFT_CORNER); - break; - - case eCursor_se_resize: - newCursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER); - break; - - case eCursor_ne_resize: - newCursor = gdk_cursor_new(GDK_TOP_RIGHT_CORNER); - break; - - case eCursor_sw_resize: - newCursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER); - break; - - case eCursor_crosshair: - newCursor = gdk_cursor_new(GDK_CROSSHAIR); - break; - - case eCursor_move: - newCursor = gdk_cursor_new(GDK_FLEUR); - break; - - case eCursor_help: - newCursor = gdk_cursor_new(GDK_QUESTION_ARROW); - break; - - case eCursor_copy: - case eCursor_alias: - // XXX: these CSS3 cursors need to be implemented - break; - - case eCursor_context_menu: - newCursor = gdk_cursor_new(GDK_RIGHTBUTTON); - break; - - case eCursor_cell: - newCursor = gdk_cursor_new(GDK_PLUS); - break; - - case eCursor_grab: - case eCursor_grabbing: - newCursor = gdk_cursor_new(GDK_HAND1); - break; - - case eCursor_spinning: - newCursor = gdk_cursor_new(GDK_EXCHANGE); - break; - - case eCursor_zoom_in: - newCursor = gdk_cursor_new(GDK_PLUS); - break; - - case eCursor_zoom_out: - newCursor = gdk_cursor_new(GDK_EXCHANGE); - break; - - case eCursor_not_allowed: - case eCursor_no_drop: - newCursor = gdk_cursor_new(GDK_X_CURSOR); - break; - - case eCursor_col_resize: - newCursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); - break; - - case eCursor_row_resize: - newCursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW); - break; - - case eCursor_vertical_text: - newCursor = gdk_cursor_new(GDK_XTERM); - break; - - case eCursor_all_scroll: - newCursor = gdk_cursor_new(GDK_FLEUR); - break; - - case eCursor_nesw_resize: - newCursor = gdk_cursor_new(GDK_TOP_RIGHT_CORNER); - break; - - case eCursor_nwse_resize: - newCursor = gdk_cursor_new(GDK_TOP_LEFT_CORNER); - break; - - case eCursor_ns_resize: - newCursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW); - break; - - case eCursor_ew_resize: - newCursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); - break; - - default: - NS_ASSERTION(PR_FALSE, "Invalid cursor type"); - break; - } - - if (nsnull != newCursor) { - mCursor = aCursor; - ::gdk_window_set_cursor(mWidget->window, newCursor); - ::gdk_cursor_destroy(newCursor); - } - } - return NS_OK; -} - -#define CAPS_LOCK_IS_ON \ -(nsGtkUtils::gdk_keyboard_get_modifiers() & GDK_LOCK_MASK) - -NS_IMETHODIMP nsWidget::Validate() -{ - mUpdateArea->SetTo(0, 0, 0, 0); - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Invalidate(PRBool aIsSynchronous) -{ - if (!mWidget) - return NS_OK; // mWidget will be null during printing. - - if (!GTK_IS_WIDGET(mWidget)) - return NS_ERROR_FAILURE; - - if (!GTK_WIDGET_REALIZED(mWidget) || !GTK_WIDGET_VISIBLE(mWidget)) - return NS_ERROR_FAILURE; - -#ifdef DEBUG - // Check the pref _before_ checking caps lock, because checking - // caps lock requires a server round-trip. - if (debug_GetCachedBoolPref("nglayout.debug.invalidate_dumping") && CAPS_LOCK_IS_ON) - { - debug_DumpInvalidate(stdout, - this, - nsnull, - aIsSynchronous, - debug_GetName(mWidget), - debug_GetRenderXID(mWidget)); - } -#endif // DEBUG - - mUpdateArea->SetTo(0, 0, mBounds.width, mBounds.height); - - if (aIsSynchronous) { - ::gtk_widget_draw(mWidget, (GdkRectangle *) NULL); - } else { - ::gtk_widget_queue_draw(mWidget); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) -{ - if (!mWidget) - return NS_OK; // mWidget is null during printing - - if (!GTK_IS_WIDGET(mWidget)) - return NS_ERROR_FAILURE; - - if (!GTK_WIDGET_REALIZED(mWidget) || !GTK_WIDGET_VISIBLE(mWidget)) - return NS_ERROR_FAILURE; - - mUpdateArea->Union(aRect.x, aRect.y, aRect.width, aRect.height); - -#ifdef DEBUG - // Check the pref _before_ checking caps lock, because checking - // caps lock requires a server round-trip. - if (debug_GetCachedBoolPref("nglayout.debug.invalidate_dumping") && CAPS_LOCK_IS_ON) - { - debug_DumpInvalidate(stdout, - this, - &aRect, - aIsSynchronous, - debug_GetName(mWidget), - debug_GetRenderXID(mWidget)); - } -#endif // DEBUG - - if (aIsSynchronous) - { - GdkRectangle nRect; - NSRECT_TO_GDKRECT(aRect, nRect); - - gtk_widget_draw(mWidget, &nRect); - } - else - { - gtk_widget_queue_draw_area(mWidget, - aRect.x, aRect.y, - aRect.width, aRect.height); - } - - return NS_OK; -} - - -NS_IMETHODIMP nsWidget::InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous) -{ - nsRegionRectSet *regionRectSet = nsnull; - - if (!GTK_IS_WIDGET(mWidget)) - return NS_ERROR_FAILURE; - - if (!GTK_WIDGET_REALIZED(mWidget) || !GTK_WIDGET_VISIBLE(mWidget)) - return NS_ERROR_FAILURE; - - mUpdateArea->Union(*aRegion); - - if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) - { - return NS_ERROR_FAILURE; - } - - PRUint32 len; - PRUint32 i; - - len = regionRectSet->mRectsLen; - - for (i=0;imRects[i]); - - -#ifdef DEBUG - // Check the pref _before_ checking caps lock, because checking - // caps lock requires a server round-trip. - if (debug_GetCachedBoolPref("nglayout.debug.invalidate_dumping") && CAPS_LOCK_IS_ON) - { - nsRect rect(r->x, r->y, r->width, r->height); - debug_DumpInvalidate(stdout, - this, - &rect, - aIsSynchronous, - debug_GetName(mWidget), - debug_GetRenderXID(mWidget)); - } -#endif // DEBUG - - - if (aIsSynchronous) - { - GdkRectangle nRect; - nRect.x = r->x; - nRect.y = r->y; - nRect.width = r->width; - nRect.height = r->height; - gtk_widget_draw(mWidget, &nRect); - } else { - gtk_widget_queue_draw_area(mWidget, - r->x, r->y, - r->width, r->height); - } - } - - // drop the const.. what's the right thing to do here? - ((nsIRegion*)aRegion)->FreeRects(regionRectSet); - - return NS_OK; -} - - -NS_IMETHODIMP nsWidget::Update(void) -{ - if (!mWidget) - return NS_OK; - - if (!GTK_IS_WIDGET(mWidget)) - return NS_ERROR_FAILURE; - - if (!GTK_WIDGET_REALIZED(mWidget) || !GTK_WIDGET_VISIBLE(mWidget)) - return NS_ERROR_FAILURE; - - // printf("nsWidget::Update()\n"); - - // this will Union() again, but so what? - return InvalidateRegion(mUpdateArea, PR_TRUE); -} - -//------------------------------------------------------------------------- -// -// Return some native data according to aDataType -// -//------------------------------------------------------------------------- -void *nsWidget::GetNativeData(PRUint32 aDataType) -{ - switch(aDataType) { - case NS_NATIVE_WINDOW: - if (mWidget) { - return (void *)mWidget->window; - } - break; - - case NS_NATIVE_DISPLAY: - return (void *)GDK_DISPLAY(); - - case NS_NATIVE_WIDGET: - case NS_NATIVE_PLUGIN_PORT: - if (mWidget) { - return (void *)mWidget; - } - break; - - case NS_NATIVE_GRAPHIC: - /* GetSharedGC ups the ref count on the GdkGC so make sure you release - * it afterwards. */ - NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC"); - return (void *)NS_STATIC_CAST(nsToolkit*,mToolkit)->GetSharedGC(); - - default: -#ifdef DEBUG - g_print("nsWidget::GetNativeData(%i) - weird value\n", aDataType); -#endif - break; - } - return nsnull; -} - -//------------------------------------------------------------------------- -// -// Set the colormap of the window -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::SetColorMap(nsColorMap *aColorMap) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::BeginResizingChildren(void) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::EndResizingChildren(void) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) -{ - aWidth = mPreferredWidth; - aHeight = mPreferredHeight; - return (mPreferredWidth != 0 && mPreferredHeight != 0)?NS_OK:NS_ERROR_FAILURE; -} - -NS_IMETHODIMP nsWidget::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) -{ - mPreferredWidth = aWidth; - mPreferredHeight = aHeight; - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetTitle(const nsAString &aTitle) -{ - gtk_widget_set_name(mWidget, "foo"); - return NS_OK; -} - -nsresult nsWidget::CreateWidget(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData, - nsNativeWidget aNativeParent) -{ - GtkObject *parentWidget = nsnull; - -#ifdef NOISY_DESTROY - if (aParent) - g_print("nsWidget::CreateWidget (%p) nsIWidget parent\n", - this); - else if (aNativeParent) - g_print("nsWidget::CreateWidget (%p) native parent\n", - this); - else if(aAppShell) - g_print("nsWidget::CreateWidget (%p) nsAppShell parent\n", - this); -#endif - - gtk_widget_push_colormap(gdk_rgb_get_cmap()); - gtk_widget_push_visual(gdk_rgb_get_visual()); - - nsIWidget *baseParent = aInitData && - (aInitData->mWindowType == eWindowType_dialog || - aInitData->mWindowType == eWindowType_toplevel || - aInitData->mWindowType == eWindowType_invisible) ? - nsnull : aParent; - - NS_ASSERTION(aInitData->mWindowType != eWindowType_popup || - !aParent, "Popups should not be hooked into nsIWidget hierarchy"); - - BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, - aAppShell, aToolkit, aInitData); - - mParent = aParent; - - if (aNativeParent) { - parentWidget = GTK_OBJECT(aNativeParent); - mListenForResizes = PR_TRUE; - } else if (aParent) { - // this ups the refcount of the gtk widget, we must unref later. - parentWidget = GTK_OBJECT(aParent->GetNativeData(NS_NATIVE_WIDGET)); - mListenForResizes = aInitData ? aInitData->mListenForResizes : PR_FALSE; - } - - mBounds = aRect; - CreateNative (parentWidget); - - Resize(aRect.width, aRect.height, PR_FALSE); - - gtk_widget_pop_colormap(); - gtk_widget_pop_visual(); - - if (mWidget) { - /* we used to listen to motion notify signals, button press - signals and button release signals here but since nsWindow - became its own managed class we don't need to do that by - default anymore. Any subclasses that need to listen to those - events should do so on their own. */ - - // InstallButtonPressSignal(mWidget); - // InstallButtonReleaseSignal(mWidget); - - // InstallMotionNotifySignal(mWidget); - - InstallEnterNotifySignal(mWidget); - InstallLeaveNotifySignal(mWidget); - - // Focus - InstallFocusInSignal(mWidget); - InstallFocusOutSignal(mWidget); - - } - - DispatchStandardEvent(NS_CREATE); - InitCallbacks(); - - if (mWidget) { - // Add in destroy callback - gtk_signal_connect(GTK_OBJECT(mWidget), - "destroy", - GTK_SIGNAL_FUNC(DestroySignal), - this); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// create with nsIWidget parent -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - return CreateWidget(aParent, aRect, aHandleEventFunction, - aContext, aAppShell, aToolkit, aInitData, - nsnull); -} - -//------------------------------------------------------------------------- -// -// create with a native parent -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::Create(nsNativeWidget aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - return CreateWidget(nsnull, aRect, aHandleEventFunction, - aContext, aAppShell, aToolkit, aInitData, - aParent); -} - -//------------------------------------------------------------------------- -// -// Initialize all the Callbacks -// -//------------------------------------------------------------------------- -void nsWidget::InitCallbacks(char *aName) -{ -} - -void nsWidget::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY) -{ - -} - -void nsWidget::InitEvent(nsGUIEvent& event, nsPoint* aPoint) -{ - // This copies, and we need to call gdk_event_free. - GdkEvent *ge = gtk_get_current_event(); - - if (aPoint == nsnull) { // use the point from the event - // get the message position in client coordinates and in twips - - if (ge != nsnull) { - // ::ScreenToClient(mWnd, &cpos); - event.refPoint.x = PRInt32(ge->configure.x); - event.refPoint.y = PRInt32(ge->configure.y); - } - } - else { // use the point override if provided - event.refPoint.x = aPoint->x; - event.refPoint.y = aPoint->y; - } - - event.time = gdk_event_get_time(ge); - - // mLastPoint.x = event.refPoint.x; - // mLastPoint.y = event.refPoint.y; - - if (ge) - gdk_event_free(ge); -} - -PRBool nsWidget::DispatchWindowEvent(nsGUIEvent* event) -{ - nsEventStatus status; - DispatchEvent(event, status); - return ConvertStatus(status); -} - -//------------------------------------------------------------------------- -// -// Dispatch standard event -// -//------------------------------------------------------------------------- - -PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg) -{ - nsGUIEvent event(PR_TRUE, aMsg, this); - InitEvent(event); - PRBool result = DispatchWindowEvent(&event); - return result; -} - -PRBool nsWidget::DispatchFocus(nsGUIEvent &aEvent) -{ - if (mEventCallback) - return DispatchWindowEvent(&aEvent); - - return PR_FALSE; -} - -////////////////////////////////////////////////////////////////// -// -// OnSomething handlers -// -////////////////////////////////////////////////////////////////// - -#ifdef DEBUG -PRInt32 -nsWidget::debug_GetRenderXID(GtkObject * aGtkWidget) -{ - GdkWindow * renderWindow = GetRenderWindow(aGtkWidget); - - Window xid = renderWindow ? GDK_WINDOW_XWINDOW(renderWindow) : 0x0; - - return (PRInt32) xid; -} - -PRInt32 -nsWidget::debug_GetRenderXID(GtkWidget * aGtkWidget) -{ - return debug_GetRenderXID(GTK_OBJECT(aGtkWidget)); -} - -nsCAutoString -nsWidget::debug_GetName(GtkObject * aGtkWidget) -{ - if (nsnull != aGtkWidget && GTK_IS_WIDGET(aGtkWidget)) - return debug_GetName(GTK_WIDGET(aGtkWidget)); - - return nsCAutoString("null"); -} - -nsCAutoString -nsWidget::debug_GetName(GtkWidget * aGtkWidget) -{ - - if (nsnull != aGtkWidget) - return nsCAutoString(gtk_widget_get_name(aGtkWidget)); - - return nsCAutoString("null"); -} - -#endif // DEBUG - - -////////////////////////////////////////////////////////////////// - -//------------------------------------------------------------------------- -// -// Invokes callback and ProcessEvent method on Event Listener object -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent *aEvent, - nsEventStatus &aStatus) -{ - NS_ADDREF(aEvent->widget); - -#ifdef DEBUG - GtkObject *gw; - void *nativeWidget = aEvent->widget->GetNativeData(NS_NATIVE_WIDGET); - if (nativeWidget) { - gw = GTK_OBJECT(nativeWidget); - - // Check the pref _before_ checking caps lock, because checking - // caps lock requires a server round-trip. - - if (debug_GetCachedBoolPref("nglayout.debug.event_dumping") && CAPS_LOCK_IS_ON) - { - debug_DumpEvent(stdout, - aEvent->widget, - aEvent, - debug_GetName(gw), - (PRInt32) debug_GetRenderXID(gw)); - } - } -#endif // DEBUG - - if (nsnull != mMenuListener) { - if (NS_MENU_EVENT == aEvent->eventStructType) - aStatus = mMenuListener->MenuSelected(NS_STATIC_CAST(nsMenuEvent&, *aEvent)); - } - - aStatus = nsEventStatus_eIgnore; - if (nsnull != mEventCallback) { - aStatus = (*mEventCallback)(aEvent); - } - - // Dispatch to event listener if event was not consumed - if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) { - aStatus = mEventListener->ProcessEvent(*aEvent); - } - NS_IF_RELEASE(aEvent->widget); - - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Deal with all sort of mouse event -// -//------------------------------------------------------------------------- -PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) -{ - PRBool result = PR_FALSE; - if (nsnull == mEventCallback && nsnull == mMouseListener) { - return result; - } - - // call the event callback - if (nsnull != mEventCallback) { - result = DispatchWindowEvent(&aEvent); - - return result; - } - - if (nsnull != mMouseListener) { - switch (aEvent.message) { - case NS_MOUSE_MOVE: { -// result = ConvertStatus(mMouseListener->MouseMoved(aEvent)); -// nsRect rect; -// GetBounds(rect); -// if (rect.Contains(event.refPoint.x, event.refPoint.y)) { -// if (mCurrentWindow == NULL || mCurrentWindow != this) { -// printf("Mouse enter"); -// mCurrentWindow = this; -// } -// } else { -// printf("Mouse exit"); -// } - - } break; - - case NS_MOUSE_BUTTON_DOWN: - result = ConvertStatus(mMouseListener->MousePressed(aEvent)); - break; - - case NS_MOUSE_BUTTON_UP: - result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); - result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); - break; - - case NS_DRAGDROP_DROP: -#ifdef DEBUG - printf("nsWidget::DispatchMouseEvent, NS_DRAGDROP_DROP\n"); -#endif - break; - - default: - break; - - } // switch - } - return result; -} - -////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////// -// -// GTK signal installers -// -////////////////////////////////////////////////////////////////// -void -nsWidget::AddToEventMask(GtkWidget * aWidget, - gint aEventMask) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( 0 != aEventMask, "mask is 0"); - - gtk_widget_add_events(aWidget,aEventMask); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallEnterNotifySignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"enter_notify_event", - GTK_SIGNAL_FUNC(nsWidget::EnterNotifySignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallLeaveNotifySignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"leave_notify_event", - GTK_SIGNAL_FUNC(nsWidget::LeaveNotifySignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallButtonPressSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"button_press_event", - GTK_SIGNAL_FUNC(nsWidget::ButtonPressSignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallButtonReleaseSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"button_release_event", - GTK_SIGNAL_FUNC(nsWidget::ButtonReleaseSignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallFocusInSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"focus_in_event", - GTK_SIGNAL_FUNC(nsWidget::FocusInSignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallFocusOutSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"focus_out_event", - GTK_SIGNAL_FUNC(nsWidget::FocusOutSignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallRealizeSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"realize", - GTK_SIGNAL_FUNC(nsWidget::RealizeSignal)); -} -////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent) -{ - - if (mIsDestroying) - return; - - nsMouseEvent event(PR_TRUE, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal); - - // If there is a button motion target, use that instead of the - // current widget - - // XXX pav - // i'm confused as to wtf this sButtonMoetionTarget thing is for. - // so i'm not going to use it. - - // XXX ramiro - // - // Because of dynamic widget creation and destruction, this could - // potentially be a dangerious thing to do. - // - // If the sButtonMotionTarget is destroyed between the time when - // it got set and now, we should end up sending an event to - // a junk nsWidget. - // - // The way to solve this would be to add a destroy signal to - // the GtkWidget corresponding to the sButtonMotionTarget and - // marking if nsnull in there. - // - gint x, y; - - if (aGdkMotionEvent) - { - x = (gint) aGdkMotionEvent->x; - y = (gint) aGdkMotionEvent->y; - - event.refPoint.x = nscoord(x); - event.refPoint.y = nscoord(y); - event.widget = this; - } - - if (sButtonMotionTarget) - { - gint diffX; - gint diffY; - - if (aGdkMotionEvent) - { - // Compute the difference between the original root coordinates - diffX = (gint) aGdkMotionEvent->x_root - sButtonMotionRootX; - diffY = (gint) aGdkMotionEvent->y_root - sButtonMotionRootY; - - event.widget = sButtonMotionTarget; - - // The event coords will be the initial *widget* coords plus the - // root difference computed above. - event.refPoint.x = nscoord(sButtonMotionWidgetX + diffX); - event.refPoint.y = nscoord(sButtonMotionWidgetY + diffY); - } - } - else - { - event.widget = this; - } - - if (aGdkMotionEvent) - { - event.time = aGdkMotionEvent->time; - event.isShift = aGdkMotionEvent->state & ShiftMask; - event.isControl = aGdkMotionEvent->state & ControlMask; - event.isAlt = aGdkMotionEvent->state & Mod1Mask; - } - - AddRef(); - - if (sButtonMotionTarget) - sButtonMotionTarget->DispatchMouseEvent(event); - else - DispatchMouseEvent(event); - - Release(); -} - -////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent) -{ - if (aGdkCrossingEvent->subwindow != NULL) - return; - - // If there is a button motion target, then we can ignore this - // event since what the gecko event system expects is for - // only motion events to be sent to that widget, even if the - // pointer is crossing on other widgets. - // - // XXX ramiro - Same as above. - // - if (nsnull != sButtonMotionTarget) - { - return; - } - - nsMouseEvent event(PR_TRUE, NS_MOUSE_ENTER, this, nsMouseEvent::eReal); - - if (aGdkCrossingEvent != NULL) - { - event.refPoint.x = nscoord(aGdkCrossingEvent->x); - event.refPoint.y = nscoord(aGdkCrossingEvent->y); - event.time = aGdkCrossingEvent->time; - } - - AddRef(); - - DispatchMouseEvent(event); - - Release(); -} -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent) -{ - if (aGdkCrossingEvent->subwindow != NULL) - return; - - // If there is a button motion target, then we can ignore this - // event since what the gecko event system expects is for - // only motion events to be sent to that widget, even if the - // pointer is crossing on other widgets. - // - // XXX ramiro - Same as above. - // - if (nsnull != sButtonMotionTarget) - { - return; - } - - nsMouseEvent event(PR_TRUE, NS_MOUSE_EXIT, this, nsMouseEvent::eReal); - - if (aGdkCrossingEvent != NULL) - { - event.refPoint.x = nscoord(aGdkCrossingEvent->x); - event.refPoint.y = nscoord(aGdkCrossingEvent->y); - event.time = aGdkCrossingEvent->time; - } - - AddRef(); - - DispatchMouseEvent(event); - - Release(); -} - - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent) -{ - nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, this); - PRUint32 eventType = 0; - PRInt16 button = nsMouseEvent::eLeftButton; - - // If you double click in GDK, it will actually generate a single - // click event before sending the double click event, and this is - // different than the DOM spec. GDK puts this in the queue - // programatically, so it's safe to assume that if there's a - // double click in the queue, it was generated so we can just drop - // this click. - GdkEvent *peekedEvent = gdk_event_peek(); - if (peekedEvent) { - GdkEventType type = peekedEvent->any.type; - gdk_event_free(peekedEvent); - if (type == GDK_2BUTTON_PRESS || type == GDK_3BUTTON_PRESS) - return; - } - - - // Switch on single, double, triple click. - switch (aGdkButtonEvent->type) - { - // Single click. - case GDK_BUTTON_PRESS: - // Double click. - case GDK_2BUTTON_PRESS: - // Triple click. - case GDK_3BUTTON_PRESS: - - eventType = NS_MOUSE_BUTTON_DOWN; - switch (aGdkButtonEvent->button) // Which button? - { - case 1: - button = nsMouseEvent::eLeftButton; - break; - - case 2: - button = nsMouseEvent::eMiddleButton; - break; - - case 3: - button = nsMouseEvent::eRightButton; - break; - - case 4: - case 5: - case 6: - case 7: - if (aGdkButtonEvent->button == 4 || aGdkButtonEvent->button == 5) - scrollEvent.scrollFlags = nsMouseScrollEvent::kIsVertical; - else - scrollEvent.scrollFlags = nsMouseScrollEvent::kIsHorizontal; - - if (aGdkButtonEvent->button == 4 || aGdkButtonEvent->button == 6) - scrollEvent.delta = -3; - else - scrollEvent.delta = 3; - - scrollEvent.refPoint.x = nscoord(aGdkButtonEvent->x); - scrollEvent.refPoint.y = nscoord(aGdkButtonEvent->y); - - scrollEvent.isShift = (aGdkButtonEvent->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; - scrollEvent.isControl = (aGdkButtonEvent->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; - scrollEvent.isAlt = (aGdkButtonEvent->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE; - scrollEvent.isMeta = PR_FALSE; // GTK+ doesn't support the meta key - scrollEvent.time = aGdkButtonEvent->time; - AddRef(); - if (mEventCallback) - DispatchWindowEvent(&scrollEvent); - Release(); - return; - - // Single-click default. - default: - button = nsMouseEvent::eLeftButton; - break; - } - break; - - default: - break; - } - - nsMouseEvent event(PR_TRUE, eventType, this, nsMouseEvent::eReal); - InitMouseEvent(aGdkButtonEvent, event); - event.button = button; - - // Set the button motion target and remeber the widget and root coords - sButtonMotionTarget = this; - - // Make sure to add this widget to the gtk grab list so that events - // are rewritten to this window. - GtkWidget *owningWidget; - owningWidget = GetOwningWidget(); - if (owningWidget) - gtk_grab_add(owningWidget); - - sButtonMotionRootX = (gint) aGdkButtonEvent->x_root; - sButtonMotionRootY = (gint) aGdkButtonEvent->y_root; - - sButtonMotionWidgetX = (gint) aGdkButtonEvent->x; - sButtonMotionWidgetY = (gint) aGdkButtonEvent->y; - - AddRef(); // kung-fu deathgrip - - DispatchMouseEvent(event); - - // if we're a right-button-down on linux, we're trying to - // popup a context menu. send that event to gecko also. - if (button == nsMouseEvent::eRightButton) { - nsMouseEvent contextMenuEvent(PR_TRUE, NS_CONTEXTMENU, this, - nsMouseEvent::eReal); - InitMouseEvent(aGdkButtonEvent, contextMenuEvent); - DispatchMouseEvent(contextMenuEvent); - } - - Release(); - -} -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent) -{ - PRUint16 button; - switch (aGdkButtonEvent->button) - { - case 1: - button = nsMouseEvent::eLeftButton; - break; - - case 2: - button = nsMouseEvent::eMiddleButton; - break; - - case 3: - button = nsMouseEvent::eRightButton; - break; - - case 4: - case 5: - case 6: - case 7: - // We don't really need to do anything here, but we don't want - // LEFT_BUTTON_UP to happen - return; - - default: - button = nsMouseEvent::eLeftButton; - break; - } - - nsMouseEvent event(PR_TRUE, NS_MOUSE_BUTTON_UP, this, nsMouseEvent::eReal); - event.button = button; - InitMouseEvent(aGdkButtonEvent, event); - - if (sButtonMotionTarget) { - gint diffX = 0; - gint diffY = 0; - - diffX = (gint) aGdkButtonEvent->x_root - sButtonMotionRootX; - diffY = (gint) aGdkButtonEvent->y_root - sButtonMotionRootY; - - event.widget = sButtonMotionTarget; - - // see comments in nsWidget::OnMotionNotifySignal - event.refPoint.x = nscoord(sButtonMotionWidgetX + diffX); - event.refPoint.y = nscoord(sButtonMotionWidgetY + diffY); - } - - // Drop the motion target before dispatching the event so that we - // don't get events that we shouldn't. - DropMotionTarget(); - - // event.widget can get set to null when calling DispatchMouseEvent, - // so to release it we must make a copy - nsWidget* theWidget = NS_STATIC_CAST(nsWidget*,event.widget); - - NS_ADDREF(theWidget); - theWidget->DispatchMouseEvent(event); - NS_IF_RELEASE(theWidget); - -} -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnFocusInSignal(GdkEventFocus * aGdkFocusEvent) -{ - if (mIsDestroying) - return; - - GTK_WIDGET_SET_FLAGS(mWidget, GTK_HAS_FOCUS); - - nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, this); - -// event.time = aGdkFocusEvent->time;; -// event.time = PR_Now(); - - AddRef(); - - DispatchFocus(event); - - Release(); -} -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent) -{ - if (mIsDestroying) - return; - - GTK_WIDGET_UNSET_FLAGS(mWidget, GTK_HAS_FOCUS); - - nsFocusEvent event(PR_TRUE, NS_LOSTFOCUS, this); - -// event.time = aGdkFocusEvent->time;; -// event.time = PR_Now(); - - AddRef(); - - DispatchFocus(event); - - Release(); -} -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWidget::OnRealize(GtkWidget *aWidget) -{ -#ifdef DEBUG - printf("nsWidget::OnRealize(%p)\n", NS_STATIC_CAST(void *, this)); -#endif -} -////////////////////////////////////////////////////////////////////// - - -////////////////////////////////////////////////////////////////// -// -// GTK event support methods -// -////////////////////////////////////////////////////////////////// -void -nsWidget::InstallSignal(GtkWidget * aWidget, - gchar * aSignalName, - GtkSignalFunc aSignalFunction) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( aSignalName, "signal name is null"); - NS_ASSERTION( aSignalFunction, "signal function is null"); - - gtk_signal_connect(GTK_OBJECT(aWidget), - aSignalName, - GTK_SIGNAL_FUNC(aSignalFunction), - (gpointer) this); -} -////////////////////////////////////////////////////////////////// -void -nsWidget::InitMouseEvent(GdkEventButton * aGdkButtonEvent, - nsMouseEvent &anEvent) -{ - if (aGdkButtonEvent != NULL) { - anEvent.refPoint.x = nscoord(aGdkButtonEvent->x); - anEvent.refPoint.y = nscoord(aGdkButtonEvent->y); - - anEvent.isShift = (aGdkButtonEvent->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isControl = (aGdkButtonEvent->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isAlt = (aGdkButtonEvent->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE; - anEvent.isMeta = PR_FALSE; // GTK+ doesn't support the meta key - anEvent.time = aGdkButtonEvent->time; - - switch(aGdkButtonEvent->type) - { - case GDK_BUTTON_PRESS: - anEvent.clickCount = 1; - break; - case GDK_2BUTTON_PRESS: - anEvent.clickCount = 2; - break; - case GDK_3BUTTON_PRESS: - anEvent.clickCount = 3; - break; - default: - anEvent.clickCount = 1; - } - - } -} - -////////////////////////////////////////////////////////////////// -// -// GTK widget signals -// -////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::EnterNotifySignal(GtkWidget * aWidget, - GdkEventCrossing * aGdkCrossingEvent, - gpointer aData) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( nsnull != aGdkCrossingEvent, "event is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnEnterNotifySignal(aGdkCrossingEvent); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::LeaveNotifySignal(GtkWidget * aWidget, - GdkEventCrossing * aGdkCrossingEvent, - gpointer aData) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( nsnull != aGdkCrossingEvent, "event is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnLeaveNotifySignal(aGdkCrossingEvent); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::ButtonPressSignal(GtkWidget * aWidget, - GdkEventButton * aGdkButtonEvent, - gpointer aData) -{ - // printf("nsWidget::ButtonPressSignal(%p)\n",aData); - - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( nsnull != aGdkButtonEvent, "event is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnButtonPressSignal(aGdkButtonEvent); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::ButtonReleaseSignal(GtkWidget * aWidget, - GdkEventButton * aGdkButtonEvent, - gpointer aData) -{ - // printf("nsWidget::ButtonReleaseSignal(%p)\n",aData); - - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( nsnull != aGdkButtonEvent, "event is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnButtonReleaseSignal(aGdkButtonEvent); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::RealizeSignal(GtkWidget * aWidget, - gpointer aData) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnRealize(aWidget); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::FocusInSignal(GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData) -{ - // printf("nsWidget::ButtonReleaseSignal(%p)\n",aData); - - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( nsnull != aGdkFocusEvent, "event is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnFocusInSignal(aGdkFocusEvent); - - if (GTK_IS_WINDOW(aWidget)) - gtk_signal_emit_stop_by_name(GTK_OBJECT(aWidget), "focus_in_event"); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// -/* static */ gint -nsWidget::FocusOutSignal(GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData) -{ - // printf("nsWidget::ButtonReleaseSignal(%p)\n",aData); - - NS_ASSERTION( nsnull != aWidget, "widget is null"); - NS_ASSERTION( nsnull != aGdkFocusEvent, "event is null"); - - nsWidget * widget = (nsWidget *) aData; - - NS_ASSERTION( nsnull != widget, "instance pointer is null"); - - widget->OnFocusOutSignal(aGdkFocusEvent); - - if (GTK_IS_WINDOW(aWidget)) - gtk_signal_emit_stop_by_name(GTK_OBJECT(aWidget), "focus_out_event"); - - return PR_TRUE; -} -////////////////////////////////////////////////////////////////////// - -/* virtual */ GdkWindow * -nsWidget::GetRenderWindow(GtkObject * aGtkWidget) -{ - GdkWindow * renderWindow = nsnull; - - if (GDK_IS_SUPERWIN(aGtkWidget)) { - renderWindow = GDK_SUPERWIN(aGtkWidget)->bin_window; - } - - return renderWindow; -} - -void -nsWidget::ThemeChanged() -{ - // Dispatch a NS_THEMECHANGED event for each of our children, recursively - for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - NS_STATIC_CAST(nsWidget*, kid)->ThemeChanged(); - } - - DispatchStandardEvent(NS_THEMECHANGED); - Invalidate(PR_FALSE); -} - -////////////////////////////////////////////////////////////////////// -// default setfont for most widgets -/*virtual*/ -void nsWidget::SetFontNative(GdkFont *aFont) -{ - GtkStyle *style = gtk_style_copy(mWidget->style); - // gtk_style_copy ups the ref count of the font - gdk_font_unref (style->font); - - style->font = aFont; - gdk_font_ref(style->font); - - gtk_widget_set_style(mWidget, style); - - gtk_style_unref(style); -} - -////////////////////////////////////////////////////////////////////// -// default SetBackgroundColor for most widgets -/*virtual*/ -void nsWidget::SetBackgroundColorNative(GdkColor *aColorNor, - GdkColor *aColorBri, - GdkColor *aColorDark) -{ - // use same style copy as SetFont - GtkStyle *style = gtk_style_copy(mWidget->style); - - style->bg[GTK_STATE_NORMAL]=*aColorNor; - - // Mouse over button - style->bg[GTK_STATE_PRELIGHT]=*aColorBri; - - // Button is down - style->bg[GTK_STATE_ACTIVE]=*aColorDark; - - // other states too? (GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, - // GTK_STATE_SELECTED, GTK_STATE_INSENSITIVE) - gtk_widget_set_style(mWidget, style); - gtk_style_unref(style); -} - - - - - - - - - - - - - - - - - - - -////////////////////////////////////////////////////////////////////// - -NS_IMETHODIMP nsWidget::ResetInputState() -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetIMEOpenState(PRBool aState) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsWidget::GetIMEOpenState(PRBool* aState) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsWidget::SetIMEEnabled(PRUint32 aState) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsWidget::GetIMEEnabled(PRUint32* aState) { - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsWidget::CancelIMEComposition() { - return NS_ERROR_NOT_IMPLEMENTED; -} - -/* virtual */ -GtkWindow *nsWidget::GetTopLevelWindow(void) -{ - if (mWidget) - return GTK_WINDOW(gtk_widget_get_toplevel(mWidget)); - else - return NULL; -} - -void nsWidget::IMECommitEvent(GdkEventKey *aEvent) { - NS_ASSERTION(0, "nsWidget::IMECommitEvent() shouldn't be called!\n"); -} - -void nsWidget::DispatchSetFocusEvent(void) -{ - NS_ASSERTION(0, "nsWidget::DispatchSetFocusEvent shouldn't be called!\n"); -} -void nsWidget::DispatchLostFocusEvent(void) -{ - NS_ASSERTION(0, "nsWidget::DispatchLostFocusEvent shouldn't be called!\n"); -} -void nsWidget::DispatchActivateEvent(void) -{ - NS_ASSERTION(0, "nsWidget::DispatchActivateEvent shouldn't be called!\n"); -} -void nsWidget::DispatchDeactivateEvent(void) -{ - NS_ASSERTION(0, "nsWidget::DispatchDeactivateEvent shouldn't be called!\n"); -} diff --git a/mozilla/widget/src/gtk/nsWidget.h b/mozilla/widget/src/gtk/nsWidget.h deleted file mode 100644 index aa8f385c871..00000000000 --- a/mozilla/widget/src/gtk/nsWidget.h +++ /dev/null @@ -1,436 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsWidget_h__ -#define nsWidget_h__ - -#include "nsBaseWidget.h" -#include "nsWeakReference.h" -#include "nsIKBStateControl.h" -#include "nsIRegion.h" -#include "nsIRollupListener.h" - -class nsILookAndFeel; -class nsIAppShell; -class nsIToolkit; - -#include - -#include - -#include "gtkmozbox.h" -#include "nsITimer.h" - -#define NSRECT_TO_GDKRECT(ns,gdk) \ - PR_BEGIN_MACRO \ - gdk.x = ns.x; \ - gdk.y = ns.y; \ - gdk.width = ns.width; \ - gdk.height = ns.height; \ - PR_END_MACRO - -#define NSCOLOR_TO_GDKCOLOR(n,g) \ - PR_BEGIN_MACRO \ - g.red = 256 * NS_GET_R(n); \ - g.green = 256 * NS_GET_G(n); \ - g.blue = 256 * NS_GET_B(n); \ - PR_END_MACRO - - -/** - * Base of all GTK+ native widgets. - */ - -class nsWidget : public nsBaseWidget, public nsIKBStateControl, public nsSupportsWeakReference -{ -public: - nsWidget(); - virtual ~nsWidget(); - - NS_DECL_ISUPPORTS_INHERITED - - // nsIWidget - - NS_IMETHOD Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell = nsnull, - nsIToolkit *aToolkit = nsnull, - nsWidgetInitData *aInitData = nsnull); - NS_IMETHOD Create(nsNativeWidget aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell = nsnull, - nsIToolkit *aToolkit = nsnull, - nsWidgetInitData *aInitData = nsnull); - - NS_IMETHOD Destroy(void); - nsIWidget* GetParent(void); - virtual void OnDestroy(); - - NS_IMETHOD Show(PRBool state); - NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent); - NS_IMETHOD IsVisible(PRBool &aState); - - NS_IMETHOD ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY); - NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); - NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint); - NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, - PRInt32 aHeight, PRBool aRepaint); - - NS_IMETHOD Enable(PRBool aState); - NS_IMETHOD IsEnabled(PRBool *aState); - NS_IMETHOD SetFocus(PRBool aRaise); - - virtual void LoseFocus(void); - - PRBool OnResize(nsSizeEvent *event); - virtual PRBool OnResize(nsRect &aRect); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - - NS_IMETHOD SetZIndex(PRInt32 aZIndex); - - nsIFontMetrics *GetFont(void); - NS_IMETHOD SetFont(const nsFont &aFont); - - NS_IMETHOD SetBackgroundColor(const nscolor &aColor); - - NS_IMETHOD SetCursor(nsCursor aCursor); - - NS_IMETHOD SetColorMap(nsColorMap *aColorMap); - - void* GetNativeData(PRUint32 aDataType); - - NS_IMETHOD WidgetToScreen(const nsRect &aOldRect, nsRect &aNewRect); - NS_IMETHOD ScreenToWidget(const nsRect &aOldRect, nsRect &aNewRect); - - NS_IMETHOD BeginResizingChildren(void); - NS_IMETHOD EndResizingChildren(void); - - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); - NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); - - // Use this to set the name of a widget for normal widgets.. not the same as the nsWindow version - NS_IMETHOD SetTitle(const nsAString& aTitle); - - - virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY); - - // the following are nsWindow specific, and just stubbed here - NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) { return NS_ERROR_FAILURE; } - NS_IMETHOD SetMenuBar(nsIMenuBar *aMenuBar) { return NS_ERROR_FAILURE; } - NS_IMETHOD ShowMenuBar(PRBool aShow) { return NS_ERROR_FAILURE; } - // *could* be done on a widget, but that would be silly wouldn't it? - NS_IMETHOD CaptureMouse(PRBool aCapture) { return NS_ERROR_FAILURE; } - - NS_IMETHOD GetWindowClass(char *aClass); - NS_IMETHOD SetWindowClass(char *aClass); - - NS_IMETHOD Validate(); - NS_IMETHOD Invalidate(PRBool aIsSynchronous); - NS_IMETHOD Invalidate(const nsRect &aRect, PRBool aIsSynchronous); - NS_IMETHOD InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous); - NS_IMETHOD Update(void); - NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); - - - // nsIKBStateControl - NS_IMETHOD ResetInputState(); - NS_IMETHOD SetIMEOpenState(PRBool aState); - NS_IMETHOD GetIMEOpenState(PRBool* aState); - NS_IMETHOD SetIMEEnabled(PRUint32 aState); - NS_IMETHOD GetIMEEnabled(PRUint32* aState); - NS_IMETHOD CancelIMEComposition(); - - void InitEvent(nsGUIEvent& event, nsPoint* aPoint = nsnull); - - // Utility functions - - PRBool ConvertStatus(nsEventStatus aStatus) - { return aStatus == nsEventStatus_eConsumeNoDefault; } - PRBool DispatchMouseEvent(nsMouseEvent& aEvent); - PRBool DispatchStandardEvent(PRUint32 aMsg); - PRBool DispatchFocus(nsGUIEvent &aEvent); - - // are we a "top level" widget? - PRBool mIsToplevel; - - virtual void DispatchSetFocusEvent(void); - virtual void DispatchLostFocusEvent(void); - virtual void DispatchActivateEvent(void); - virtual void DispatchDeactivateEvent(void); - -#ifdef DEBUG - void IndentByDepth(FILE* out); -#endif - - // Return the Gdk window used for rendering - virtual GdkWindow * GetRenderWindow(GtkObject * aGtkWidget); - // Return the Gdk window used for positioning, raising and lowering - virtual GdkWindow* GetLayeringWindow(); - - - // get the toplevel window for this widget - virtual GtkWindow *GetTopLevelWindow(void); - - - PRBool OnKey(nsKeyEvent &aEvent); - PRBool OnText(nsTextEvent &aEvent) { return OnInput(aEvent); }; - PRBool OnComposition(nsCompositionEvent &aEvent) { return OnInput(aEvent); }; - PRBool OnInput(nsInputEvent &aEvent); - - // this will return the GtkWidget * that owns this object - virtual GtkWidget *GetOwningWidget(); - - // the event handling code needs to let us know the time of the last event - static void SetLastEventTime(guint32 aTime); - static void GetLastEventTime(guint32 *aTime); - - static void DropMotionTarget(void); - - // inform the widget code that we are about to do a drag - it must - // release the sButtonMotionTarget if it is set. - static void DragStarted(void) { DropMotionTarget(); }; - - virtual void ThemeChanged(); - -protected: - - virtual void InitCallbacks(char * aName = nsnull); - - NS_IMETHOD CreateNative(GtkObject *parentWindow) { return NS_OK; } - - nsresult CreateWidget(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData, - nsNativeWidget aNativeParent = nsnull); - - - PRBool DispatchWindowEvent(nsGUIEvent* event); - - // this is the "native" destroy code that will destroy any - // native windows / widgets for this logical widget - virtual void DestroyNative(void); - - // Sets font for widgets - virtual void SetFontNative(GdkFont *aFont); - // Sets backround for widgets - virtual void SetBackgroundColorNative(GdkColor *aColorNor, - GdkColor *aColorBri, - GdkColor *aColorDark); - - // this is set when a given widget has the focus. - PRBool mHasFocus; - - - // if anyone uses this for public access other than the key - // press/release code on the main window, i will kill you. pav -public: - // this is the current GdkSuperWin with the focus - static nsWidget *sFocusWindow; - -protected: - // - - ////////////////////////////////////////////////////////////////// - // - // GTK signal installers - // - ////////////////////////////////////////////////////////////////// - void InstallEnterNotifySignal(GtkWidget * aWidget); - - void InstallLeaveNotifySignal(GtkWidget * aWidget); - - void InstallButtonPressSignal(GtkWidget * aWidget); - - void InstallButtonReleaseSignal(GtkWidget * aWidget); - - virtual - void InstallFocusInSignal(GtkWidget * aWidget); - - virtual - void InstallFocusOutSignal(GtkWidget * aWidget); - - void InstallRealizeSignal(GtkWidget * aWidget); - - void AddToEventMask(GtkWidget * aWidget, - gint aEventMask); - - ////////////////////////////////////////////////////////////////// - // - // OnSomething handlers - // - ////////////////////////////////////////////////////////////////// - virtual void OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent); - virtual void OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent); - virtual void OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent); - virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent); - virtual void OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent); - virtual void OnFocusInSignal(GdkEventFocus * aGdkFocusEvent); - virtual void OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent); - virtual void OnRealize(GtkWidget *aWidget); - - virtual void OnDestroySignal(GtkWidget* aGtkWidget); - - // Static method used to trampoline to OnDestroySignal - static gint DestroySignal(GtkWidget * aGtkWidget, - nsWidget* aWidget); - -public: - virtual void IMECommitEvent(GdkEventKey *aEvent); - - // This MUST be called after you change the widget bounds - // or after the parent's size changes - // or when you show the widget - // We will decide whether to really show the widget or not - // We will hide the widget if it doesn't overlap the parent bounds - // This reduces problems with 16-bit coordinates wrapping. - virtual void ResetInternalVisibility(); - - // Reestablish the correct Z-ordering of this widget among - // its siblings - void ResetZOrder(); - -protected: - // override this method to do whatever you have to do to make this - // widget visible or invisibile --- i.e., the real work of Show() - virtual void SetInternalVisibility(PRBool aVisible); - - ////////////////////////////////////////////////////////////////// - // - // GTK widget signals - // - ////////////////////////////////////////////////////////////////// - - static gint EnterNotifySignal(GtkWidget * aWidget, - GdkEventCrossing * aGdkCrossingEvent, - gpointer aData); - - static gint LeaveNotifySignal(GtkWidget * aWidget, - GdkEventCrossing * aGdkCrossingEvent, - gpointer aData); - - static gint ButtonPressSignal(GtkWidget * aWidget, - GdkEventButton * aGdkButtonEvent, - gpointer aData); - - static gint ButtonReleaseSignal(GtkWidget * aWidget, - GdkEventButton * aGdkButtonEvent, - gpointer aData); - - static gint RealizeSignal(GtkWidget * aWidget, - gpointer aData); - - - static gint FocusInSignal(GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData); - - static gint FocusOutSignal(GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData); - -protected: - - ////////////////////////////////////////////////////////////////// - // - // GTK event support methods - // - ////////////////////////////////////////////////////////////////// - void InstallSignal(GtkWidget * aWidget, - gchar * aSignalName, - GtkSignalFunc aSignalFunction); - - void InitMouseEvent(GdkEventButton * aGdkButtonEvent, - nsMouseEvent & anEvent); - -#ifdef DEBUG - nsCAutoString debug_GetName(GtkObject * aGtkWidget); - nsCAutoString debug_GetName(GtkWidget * aGtkWidget); - PRInt32 debug_GetRenderXID(GtkObject * aGtkWidget); - PRInt32 debug_GetRenderXID(GtkWidget * aGtkWidget); -#endif - - GtkWidget *mWidget; - // our mozbox for those native widgets - GtkWidget *mMozBox; - - nsCOMPtr mParent; - - // This is the composite update area (union of all the calls to - // Invalidate) - nsCOMPtr mUpdateArea; - - PRUint32 mPreferredWidth, mPreferredHeight; - PRPackedBool mListenForResizes; - PRPackedBool mShown; - PRPackedBool mInternalShown; - - // this is the rollup listener variables - static nsCOMPtr gRollupListener; - static nsWeakPtr gRollupWidget; - - // this is the last time that an event happened. we keep this - // around so that we can synth drag events properly - static guint32 sLastEventTime; - -private: - // this will keep track of whether or not the gdk handler - // is installed yet - static PRBool mGDKHandlerInstalled; - // this will keep track of whether or not we've told the drag - // service how to call back into us to get the last event time - static PRBool sTimeCBSet; - - // - // Keep track of the last widget being "dragged" - // -public: - static nsWidget *sButtonMotionTarget; - static gint sButtonMotionRootX; - static gint sButtonMotionRootY; - static gint sButtonMotionWidgetX; - static gint sButtonMotionWidgetY; -}; - -#endif /* nsWidget_h__ */ diff --git a/mozilla/widget/src/gtk/nsWidgetFactory.cpp b/mozilla/widget/src/gtk/nsWidgetFactory.cpp deleted file mode 100644 index 060b214baf2..00000000000 --- a/mozilla/widget/src/gtk/nsWidgetFactory.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher Blizzzard - * Stuart Parmenter - * Dan Rosen - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIGenericFactory.h" -#include "nsIModule.h" -#include "nsCOMPtr.h" -#include "nsWidgetsCID.h" - -#include "nsWindow.h" -#include "nsAppShell.h" -#include "nsAppShellSingleton.h" -#include "nsToolkit.h" -#include "nsLookAndFeel.h" -#include "nsTransferable.h" -#include "nsClipboard.h" -#include "nsClipboardHelper.h" -#include "nsHTMLFormatConverter.h" -#include "nsDragService.h" -#include "nsSound.h" -#include "nsBidiKeyboard.h" -#include "nsScreenManagerGtk.h" -#ifdef NATIVE_THEME_SUPPORT -#include "nsNativeThemeGTK.h" -#endif - -#include "nsGtkIMEHelper.h" - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) -NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk) -#ifdef NATIVE_THEME_SUPPORT -NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK) -#endif - -static const nsModuleComponentInfo components[] = -{ - { "Gtk nsWindow", - NS_WINDOW_CID, - "@mozilla.org/widgets/window/gtk;1", - nsWindowConstructor }, - { "Gtk Child nsWindow", - NS_CHILD_CID, - "@mozilla.org/widgets/child_window/gtk;1", - ChildWindowConstructor }, - { "Gtk AppShell", - NS_APPSHELL_CID, - "@mozilla.org/widget/appshell/gtk;1", - nsAppShellConstructor }, - { "Gtk Toolkit", - NS_TOOLKIT_CID, - "@mozilla.org/widget/toolkit/gtk;1", - nsToolkitConstructor }, - { "Gtk Look And Feel", - NS_LOOKANDFEEL_CID, - "@mozilla.org/widget/lookandfeel;1", - nsLookAndFeelConstructor }, - { "Gtk Sound", - NS_SOUND_CID, - // "@mozilla.org/widget/sound/gtk;1" - "@mozilla.org/sound;1", - nsSoundConstructor }, - { "Transferable", - NS_TRANSFERABLE_CID, - // "@mozilla.org/widget/transferable/gtk;1", - "@mozilla.org/widget/transferable;1", - nsTransferableConstructor }, - { "Gtk Clipboard", - NS_CLIPBOARD_CID, - // "@mozilla.org/widget/clipboard/gtk;1", - "@mozilla.org/widget/clipboard;1", - nsClipboardConstructor }, - { "Clipboard Helper", - NS_CLIPBOARDHELPER_CID, - "@mozilla.org/widget/clipboardhelper;1", - nsClipboardHelperConstructor }, - { "HTML Format Converter", - NS_HTMLFORMATCONVERTER_CID, - "@mozilla.org/widget/htmlformatconverter;1", - nsHTMLFormatConverterConstructor }, - { "Gtk Drag Service", - NS_DRAGSERVICE_CID, - // "@mozilla.org/widget/dragservice/gtk;1", - "@mozilla.org/widget/dragservice;1", - nsDragServiceConstructor }, - { "Gtk Bidi Keyboard", - NS_BIDIKEYBOARD_CID, - "@mozilla.org/widget/bidikeyboard;1", - nsBidiKeyboardConstructor }, - { "Gtk Screen Manager", - NS_SCREENMANAGER_CID, - "@mozilla.org/gfx/screenmanager;1", - nsScreenManagerGtkConstructor }, -#ifdef NATIVE_THEME_SUPPORT - { "Native Theme Renderer", - NS_THEMERENDERER_CID, - "@mozilla.org/chrome/chrome-native-theme;1", - nsNativeThemeGTKConstructor } -#endif -}; - -PR_STATIC_CALLBACK(void) -nsWidgetGTKModuleDtor(nsIModule *self) -{ - nsWindow::ReleaseGlobals(); - nsGtkIMEHelper::Shutdown(); - nsAppShellShutdown(self); -} - -NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsWidgetGTKModule, - components, - nsAppShellInit, - nsWidgetGTKModuleDtor) diff --git a/mozilla/widget/src/gtk/nsWindow.cpp b/mozilla/widget/src/gtk/nsWindow.cpp deleted file mode 100644 index 5cd8ca2a968..00000000000 --- a/mozilla/widget/src/gtk/nsWindow.cpp +++ /dev/null @@ -1,4464 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ilya Konstantinov - * tim copperfield - * Mats Palmgren - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#undef DEBUG_CURSORCACHE - -#include - -#include - -#include -#include -// XXX FTSO nsWebShell -#include - -#include // For XA_STRING - -#include "nsWindow.h" -#include "nsWidgetsCID.h" -#include "nsIFontMetrics.h" -#include "nsFont.h" -#include "nsGUIEvent.h" -#include "nsIRenderingContext.h" -#include "nsIDOMNode.h" -#include "nsRect.h" -#include "nsTransform2D.h" -#include "nsGfxCIID.h" -#include "nsGtkEventHandler.h" -#include "nsIAppShell.h" -#include "nsClipboard.h" -#include "nsIRollupListener.h" - -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" - -#include "nsICharsetConverterManager.h" -#include "nsIPlatformCharset.h" -#include "nsIServiceManager.h" -#include "nsIIOService.h" -#include "nsIProtocolHandler.h" -#include "nsIURI.h" -#include "nsNetUtil.h" -#include "nsIResProtocolHandler.h" -#include "nsIFileURL.h" - -#include "nsGtkUtils.h" // for nsGtkUtils::gdk_window_flash() - -#include "nsIDragService.h" -#include "nsIDragSessionGTK.h" -#include "nsAutoPtr.h" - -#include "nsGtkIMEHelper.h" -#include "nsKeyboardUtils.h" - -#include "nsGtkCursors.h" // for custom cursors - -#include "nspr.h" - -#include - -#ifdef NEED_USLEEP_PROTOTYPE -extern "C" int usleep(unsigned int); -#endif -#if defined(__QNX__) -#define usleep(s) sleep(s) -#endif - -#undef DEBUG_DND_XLATE -#undef DEBUG_DND_EVENTS -#undef DEBUG_FOCUS -#undef DEBUG_GRAB -#undef DEBUG_ICONS -#define MODAL_TIMERS_BROKEN - -#define NS_TO_GDK_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff) - -#define CAPS_LOCK_IS_ON \ -(nsGtkUtils::gdk_keyboard_get_modifiers() & GDK_LOCK_MASK) - -#define WANT_PAINT_FLASHING \ -(debug_WantPaintFlashing() && CAPS_LOCK_IS_ON) - -#define kWindowPositionSlop 20 - -static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); - -static PRBool gGlobalsInitialized = PR_FALSE; -static PRBool gRaiseWindows = PR_TRUE; -/* cursors cache */ -GdkCursor *nsWindow::gsGtkCursorCache[eCursorCount]; - -/* window icon cache */ -struct IconEntry : public PLDHashEntryHdr { - const char* string; - GdkPixmap* w_pixmap; - GdkBitmap* w_mask; - GdkPixmap* w_minipixmap; - GdkBitmap* w_minimask; -}; - -static PLDHashTableOps iconHashOps = { - PL_DHashAllocTable, - PL_DHashFreeTable, - PL_DHashStringKey, - PL_DHashMatchStringKey, - PL_DHashMoveEntryStub, - nsWindow::ClearIconEntry, - PL_DHashFinalizeStub, - NULL -}; - -gint handle_mozarea_focus_in ( - GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData); - -gint handle_mozarea_focus_out ( - GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData); - -void handle_toplevel_configure ( - GtkMozArea * aArea, - nsWindow * aWindow); - -// are we grabbing? -PRBool nsWindow::sIsGrabbing = PR_FALSE; -nsWindow *nsWindow::sGrabWindow = NULL; -PRBool nsWindow::sIsDraggingOutOf = PR_FALSE; - -// this is a hash table that contains a list of the -// shell_window -> nsWindow * lookups -GHashTable *nsWindow::mWindowLookupTable = NULL; - -// this is the last window that had a drag event happen on it. -nsWindow *nsWindow::mLastDragMotionWindow = NULL; - -PLDHashTable* nsWindow::sIconCache; - -PRBool gJustGotDeactivate = PR_FALSE; -PRBool gJustGotActivate = PR_FALSE; - -#define NS_WINDOW_TITLE_MAX_LENGTH 4095 - -#ifdef USE_XIM - -struct nsXICLookupEntry : public PLDHashEntryHdr { - nsWindow* mShellWindow; - nsIMEGtkIC* mXIC; -}; - -PLDHashTable nsWindow::gXICLookupTable; -GdkFont *nsWindow::gPreeditFontset = nsnull; -GdkFont *nsWindow::gStatusFontset = nsnull; - -#define XIC_FONTSET "-*-*-medium-r-*-*-%d-*-*-*-*-*-*-*,-*-*-*-r-*-*-%d-*-*-*-*-*-*-*,-*-*-*-*-*-*-%d-*-*-*-*-*-*-*" -#endif // USE_XIM - -#ifdef DEBUG_DND_XLATE -static void printDepth(int depth) { - int i; - for (i=0; i < depth; i++) - { - g_print(" "); - } -} -#endif - -static int is_parent_ungrab_enter(GdkEventCrossing *aEvent); -static int is_parent_grab_leave(GdkEventCrossing *aEvent); - -NS_IMETHODIMP nsWindow::SetParent(nsIWidget* aNewParent) -{ - NS_ENSURE_ARG_POINTER(aNewParent); - - GdkWindow* newParentWindow = - NS_STATIC_CAST(GdkWindow*, aNewParent->GetNativeData(NS_NATIVE_WINDOW)); - NS_ASSERTION(newParentWindow, "Parent widget has a null native window handle"); - - if (!mShell && mSuperWin) { - gdk_superwin_reparent(mSuperWin, newParentWindow); - } else { - NS_NOTREACHED("nsWindow::SetParent - reparenting a non-child window"); - } - return NS_OK; -} - - -// This function will check if a button event falls inside of a -// window's bounds. -static PRBool -ButtonEventInsideWindow (GdkWindow *window, GdkEventButton *aGdkButtonEvent) -{ - gint x, y; - gint width, height; - gdk_window_get_position(window, &x, &y); - gdk_window_get_size(window, &width, &height); - - // This event is measured from the origin of the window itself, not - // from the origin of the screen. - if (aGdkButtonEvent->x >= x && aGdkButtonEvent->y >= y && - aGdkButtonEvent->x <= width + x && aGdkButtonEvent->y <= height + y) - return TRUE; - - return FALSE; -} - -NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsWidget) - -//------------------------------------------------------------------------- -// -// nsWindow constructor -// -//------------------------------------------------------------------------- -nsWindow::nsWindow() -{ - mShell = nsnull; - mWindowType = eWindowType_child; - mBorderStyle = eBorderStyle_default; - mSuperWin = 0; - mMozArea = 0; - mMozAreaClosestParent = 0; - mCachedX = mCachedY = -1; - - mIsTooSmall = PR_FALSE; - mIsUpdating = PR_FALSE; - mTransientParent = nsnull; - // init the hash table if it hasn't happened already - if (mWindowLookupTable == NULL) { - mWindowLookupTable = g_hash_table_new(g_direct_hash, g_direct_equal); - } - if (mLastDragMotionWindow == this) - mLastDragMotionWindow = NULL; - mBlockMozAreaFocusIn = PR_FALSE; - mLastGrabFailed = PR_TRUE; - mHasAnonymousChildren = PR_FALSE; - mDragMotionWidget = 0; - mDragMotionContext = 0; - mDragMotionX = 0; - mDragMotionY = 0; - mDragMotionTime = 0; - mDragMotionTimerID = 0; - - // for commit character - mIMECompositionUniString = nsnull; - mIMECompositionUniStringSize = 0; - - mIsTranslucent = PR_FALSE; - mTransparencyBitmap = nsnull; - -#ifdef USE_XIM - mIMEEnable = PR_TRUE; //currently will not be used - mIMEShellWindow = 0; - mIMECallComposeStart = PR_FALSE; - mIMECallComposeEnd = PR_TRUE; - mIMEIsBeingActivate = PR_FALSE; - mICSpotTimer = nsnull; - mXICFontSize = 16; - if (gXICLookupTable.ops == NULL) { - PL_DHashTableInit(&gXICLookupTable, PL_DHashGetStubOps(), nsnull, - sizeof(nsXICLookupEntry), PL_DHASH_MIN_SIZE); - } -#endif // USE_XIM - - mLeavePending = PR_FALSE; - mRestoreFocus = PR_FALSE; - - // initialize globals - if (!gGlobalsInitialized) { - gGlobalsInitialized = PR_TRUE; - - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefs) { - PRBool val = PR_TRUE; - nsresult rv; - rv = prefs->GetBoolPref("mozilla.widget.raise-on-setfocus", - &val); - if (NS_SUCCEEDED(rv)) - gRaiseWindows = val; - - // - // control the "keyboard Mode_switch during XGrabKeyboard" - // - PRBool grab_during_popup = PR_TRUE; - PRBool ungrab_during_mode_switch = PR_TRUE; - prefs->GetBoolPref("autocomplete.grab_during_popup", - &grab_during_popup); - prefs->GetBoolPref("autocomplete.ungrab_during_mode_switch", - &ungrab_during_mode_switch); - nsXKBModeSwitch::ControlWorkaround(grab_during_popup, - ungrab_during_mode_switch); - } - - sIconCache = PL_NewDHashTable(&iconHashOps, nsnull, sizeof(IconEntry), 28); - } -} - -//------------------------------------------------------------------------- -// -// nsWindow destructor -// -//------------------------------------------------------------------------- -nsWindow::~nsWindow() -{ -#ifdef USE_XIM - KillICSpotTimer(); -#endif // USE_XIM - - if (mIMECompositionUniString) { - delete[] mIMECompositionUniString; - mIMECompositionUniString = nsnull; - } - - // make sure to unset any drag motion timers here. - ResetDragMotionTimer(0, 0, 0, 0, 0); - - // printf("%p nsWindow::~nsWindow\n", this); - // make sure that we release the grab indicator here - if (sGrabWindow == this) { - sIsGrabbing = PR_FALSE; - sGrabWindow = NULL; - } - // make sure that we unset the lastDragMotionWindow if - // we are it. - if (mLastDragMotionWindow == this) { - mLastDragMotionWindow = NULL; - } - // make sure to release our focus window - if (mHasFocus == PR_TRUE) { - sFocusWindow = NULL; - } - - // always call destroy. if it's already been called, there's no harm - // since it keeps track of when it's already been called. - - Destroy(); - - delete[] mTransparencyBitmap; - mTransparencyBitmap = nsnull; - - if (mIsUpdating) - UnqueueDraw(); -} - -/* static */ void -nsWindow::ReleaseGlobals() -{ - if (mWindowLookupTable) { - g_hash_table_destroy(mWindowLookupTable); - mWindowLookupTable = nsnull; - } - if (gXICLookupTable.ops) { - PL_DHashTableFinish(&gXICLookupTable); - gXICLookupTable.ops = nsnull; - } - if (sIconCache) { - PL_DHashTableDestroy(sIconCache); - sIconCache = nsnull; - } - if (gPreeditFontset) { - gdk_font_unref(gPreeditFontset); - gPreeditFontset = nsnull; - } - if (gStatusFontset) { - gdk_font_unref(gStatusFontset); - gStatusFontset = nsnull; - } - for (int i = 0, n = NS_ARRAY_LENGTH(gsGtkCursorCache); i < n; ++i) { - if (gsGtkCursorCache[i]) { - gdk_cursor_destroy(gsGtkCursorCache[i]); - gsGtkCursorCache[i] = nsnull; - } - } - gGlobalsInitialized = PR_FALSE; -} - -NS_IMETHODIMP nsWindow::Destroy(void) -{ - // remove our pointer from the object so that we event handlers don't send us events - // after we are gone or in the process of going away - - if (mSuperWin) - gtk_object_remove_data(GTK_OBJECT(mSuperWin), "nsWindow"); - if (mShell) - gtk_object_remove_data(GTK_OBJECT(mShell), "nsWindow"); - if (mMozArea) - gtk_object_remove_data(GTK_OBJECT(mMozArea), "nsWindow"); - - return nsWidget::Destroy(); -} - - -void nsWindow::InvalidateWindowPos(void) -{ - mCachedX = mCachedY = -1; - - for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - // Force kid to invalidate its window position if necessary. - nsRect kidBounds; - kid->GetBounds(kidBounds); - kid->Move(kidBounds.x, kidBounds.y); - } - - // The following code was shamelessly copied from nsWindow::DestroyNativeChildren - // If this wasn't GTK1, I'd refactor it to share code with that function - if (mSuperWin && mHasAnonymousChildren) { - Display *display = GDK_DISPLAY(); - Window window = GDK_WINDOW_XWINDOW(mSuperWin->bin_window); - if (window && !((GdkWindowPrivate *)mSuperWin->bin_window)->destroyed) - { - Window root_return; - Window parent_return; - Window *children_return = NULL; - unsigned int nchildren_return = 0; - // get a list of children for this window - XQueryTree(display, window, &root_return, &parent_return, - &children_return, &nchildren_return); - // walk the list of children - for (unsigned int i=0; i < nchildren_return; i++) - { - Window child_window = children_return[i]; - nsWindow *thisWindow = GetnsWindowFromXWindow(child_window); - if (thisWindow) - { - nsRect kidBounds; - thisWindow->GetBounds(kidBounds); - thisWindow->Move(kidBounds.x, kidBounds.y); - } - } - } - } -} - -void -handle_invalidate_pos(GtkMozArea *aArea, gpointer p) -{ - nsWindow *widget = (nsWindow *)p; - widget->InvalidateWindowPos(); -} - -PRBool nsWindow::GetWindowPos(nscoord &x, nscoord &y) -{ - if ((mCachedX==-1) && (mCachedY==-1)) { /* Not cached */ - gint xpos, ypos; - - if (mMozArea) - { - if (mMozArea->window) - { - if (!GTK_WIDGET_MAPPED(mMozArea) || !GTK_WIDGET_REALIZED(mMozArea)) { - // get_root_origin will do Bad Things - return PR_FALSE; - } - gdk_window_get_root_origin(mMozArea->window, &xpos, &ypos); - } - else - return PR_FALSE; - } - else if (mSuperWin) - { - if (mSuperWin->bin_window) - { - gdk_window_get_origin(mSuperWin->bin_window, &xpos, &ypos); - } - else - return PR_FALSE; - } - else - return PR_FALSE; - - mCachedX = xpos; - mCachedY = ypos; - } - - x = mCachedX; - y = mCachedY; - - return PR_TRUE; -} - -NS_IMETHODIMP nsWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) -{ - nscoord x; - nscoord y; - - aNewRect.width = aOldRect.width; - aNewRect.height = aOldRect.height; - - if (!GetWindowPos(x, y)) - return NS_ERROR_FAILURE; - - aNewRect.x = x + aOldRect.x; - aNewRect.y = y + aOldRect.y; - - return NS_OK; -} - -// this is the function that will destroy the native windows for this widget. - -/* virtual */ -void -nsWindow::DestroyNative(void) -{ - // destroy all of the children that are nsWindow() classes - // preempting the gdk destroy system. - DestroyNativeChildren(); - -#ifdef USE_XIM - IMEDestroyIC(); -#endif // USE_XIM - - if (mSuperWin) { - // remove the key from the hash table for the shell_window - g_hash_table_remove(mWindowLookupTable, mSuperWin->shell_window); - } - - if (mShell) { - gtk_widget_destroy(mShell); - mShell = nsnull; - // the moz area and superwin will have been destroyed when we destroyed the shell - mMozArea = nsnull; - mSuperWin = nsnull; - } - else if(mMozArea) { - // We will get here if the widget was created as the child of a - // GtkContainer. - gtk_widget_destroy(mMozArea); - mMozArea = nsnull; - mSuperWin = nsnull; - } - else if(mSuperWin) { - gtk_object_unref(GTK_OBJECT(mSuperWin)); - mSuperWin = NULL; - } -} - -// this function will walk the list of children and destroy them. -// the reason why this is here is that because of the superwin code -// it's very likely that we will never get notification of the -// the destruction of the child windows. so, we have to beat the -// layout engine to the punch. CB - -void -nsWindow::DestroyNativeChildren(void) -{ - - Display *display; - Window window; - Window root_return; - Window parent_return; - Window *children_return = NULL; - unsigned int nchildren_return = 0; - unsigned int i = 0; - - if (mSuperWin) - { - display = GDK_DISPLAY(); - window = GDK_WINDOW_XWINDOW(mSuperWin->bin_window); - if (window && !((GdkWindowPrivate *)mSuperWin->bin_window)->destroyed) - { - // get a list of children for this window - XQueryTree(display, window, &root_return, &parent_return, - &children_return, &nchildren_return); - // walk the list of children - for (i=0; i < nchildren_return; i++) - { - Window child_window = children_return[i]; - nsWindow *thisWindow = GetnsWindowFromXWindow(child_window); - if (thisWindow) - { - thisWindow->Destroy(); - } - } - } - } - - // free up this struct - if (children_return) - XFree(children_return); -} - -// This function will try to take a given native X window and try -// to find the nsWindow * class that has it corresponds to. - -/* static */ -nsWindow * -nsWindow::GetnsWindowFromXWindow(Window aWindow) -{ - GdkWindow *thisWindow = NULL; - - thisWindow = gdk_window_lookup(aWindow); - - if (!thisWindow) - { - return NULL; - } - gpointer data = NULL; - // see if this is a real widget - gdk_window_get_user_data(thisWindow, &data); - if (data) - { - if (GTK_IS_OBJECT(data)) - { - return (nsWindow *)gtk_object_get_data(GTK_OBJECT(data), "nsWindow"); - } - else - { - return NULL; - } - } - else - { - // ok, see if it's a shell window - nsWindow *childWindow = (nsWindow *)g_hash_table_lookup(nsWindow::mWindowLookupTable, - thisWindow); - if (childWindow) - { - return childWindow; - } - } - // shouldn't ever get here but just to make the compiler happy... - return NULL; -} - -// given an origin window and inner window ( can be the same ) -// this function will find the innermost window in the -// window tree that fits inside of the coordinates -// the depth is how deep we are in the tree and really -// is for debugging... - -/* static */ -Window -nsWindow::GetInnerMostWindow(Window aOriginWindow, - Window aWindow, - nscoord x, nscoord y, - nscoord *retx, nscoord *rety, - int depth) -{ - - Display *display; - Window window; - Window root_return; - Window parent_return; - Window *children_return = NULL; - unsigned int nchildren_return; - unsigned int i; - Window returnWindow = None; - - display = GDK_DISPLAY(); - window = aWindow; - -#ifdef DEBUG_DND_XLATE - printDepth(depth); - g_print("Finding children for 0x%lx\n", aWindow); -#endif - - // get a list of children for this window - XQueryTree(display, window, &root_return, &parent_return, - &children_return, &nchildren_return); - -#ifdef DEBUG_DND_XLATE - printDepth(depth); - g_print("Found %d children\n", nchildren_return); -#endif - - // walk the list looking for someone who matches the coords - - for (i=0; i < nchildren_return; i++) - { - Window src_w = aOriginWindow; - Window dest_w = children_return[i]; - int src_x = x; - int src_y = y; - int dest_x_return, dest_y_return; - Window child_return; - -#ifdef DEBUG_DND_XLATE - printDepth(depth); - g_print("Checking window 0x%lx with coords %d %d\n", dest_w, - src_x, src_y); -#endif - if (XTranslateCoordinates(display, src_w, dest_w, - src_x, src_y, - &dest_x_return, &dest_y_return, - &child_return)) - { - int x_return, y_return; - unsigned int width_return, height_return; - unsigned int border_width_return; - unsigned int depth_return; - - // get the parent window's geometry - XGetGeometry(display, src_w, &root_return, &x_return, &y_return, - &width_return, &height_return, &border_width_return, - &depth_return); - -#ifdef DEBUG_DND_XLATE - printDepth(depth); - g_print("parent has geo %d %d %d %d\n", - x_return, y_return, width_return, height_return); -#endif - - // get the child window's geometry - XGetGeometry(display, dest_w, &root_return, &x_return, &y_return, - &width_return, &height_return, &border_width_return, - &depth_return); - -#ifdef DEBUG_DND_XLATE - printDepth(depth); - g_print("child has geo %d %d %d %d\n", - x_return, y_return, width_return, height_return); - printDepth(depth); - g_print("coords are %d %d in child window's geo\n", - dest_x_return, dest_y_return); -#endif - - int x_offset = width_return; - int y_offset = height_return; - x_offset -= dest_x_return; - y_offset -= dest_y_return; -#ifdef DEBUG_DND_XLATE - printDepth(depth); - g_print("offsets are %d %d\n", x_offset, y_offset); -#endif - // does this child exist within the x,y coords? - if ((dest_x_return > 0) && (dest_y_return > 0) && - (y_offset > 0) && (x_offset > 0)) - { - // set our return window to this dest - returnWindow = dest_w; - // set the coords that we are going to return to the coords that we got above. - *retx = dest_x_return; - *rety = dest_y_return; - // check to see if there's a more inner window that is - // also within these coords - Window tempWindow = None; - tempWindow = GetInnerMostWindow(aOriginWindow, dest_w, x, y, retx, rety, (depth + 1)); - if (tempWindow != None) - returnWindow = tempWindow; - goto finishedWalk; - } - - } - else - { - g_assert("XTranslateCoordinates failed!\n"); - } - } - - finishedWalk: - - // free up the list of children - if (children_return) - XFree(children_return); - - return returnWindow; -} - -// Routines implementing an update queue. -// We keep a single queue for all widgets because it is -// (most likely) more efficient and better looking to handle -// all the updates in one shot. Actually, this queue should -// be at most per-toplevel. FIXME. -// - -static GSList *update_queue = NULL; -static guint update_idle = 0; - -gboolean -nsWindow::UpdateIdle (gpointer data) -{ - GSList *old_queue = update_queue; - GSList *it; - - update_idle = 0; - update_queue = nsnull; - - for (it = old_queue; it; it = it->next) - { - nsWindow *window = (nsWindow *)it->data; - window->mIsUpdating = PR_FALSE; - } - - for (it = old_queue; it; it = it->next) - { - nsWindow *window = (nsWindow *)it->data; - window->Update(); - } - - g_slist_free (old_queue); - - return PR_FALSE; -} - -void -nsWindow::QueueDraw () -{ - if (!mIsUpdating) - { - update_queue = g_slist_prepend (update_queue, (gpointer)this); - if (!update_idle) - update_idle = g_idle_add_full (G_PRIORITY_HIGH_IDLE, - UpdateIdle, - NULL, (GDestroyNotify)NULL); - mIsUpdating = PR_TRUE; - } -} - -void -nsWindow::UnqueueDraw () -{ - if (mIsUpdating) - { - update_queue = g_slist_remove (update_queue, (gpointer)this); - mIsUpdating = PR_FALSE; - } -} - -void -nsWindow::DoPaint (nsIRegion *aClipRegion) -{ - if (!mEventCallback) - return; - - // Don't paint anything if our window isn't visible. - if (!mSuperWin) - return; - - if (mSuperWin->visibility == GDK_VISIBILITY_FULLY_OBSCURED) { - // if our window has translucent pixels, then we can't trust the obscured - // check; it's possible that no pixels of the window are *currently* showing, - // but maybe after the paint new non-transparent pixels will appear in visible - // positions. - PRBool isTranslucent; - GetWindowTranslucency(isTranslucent); - if (!isTranslucent) - return; - } - - nsCOMPtr rc = getter_AddRefs(GetRenderingContext()); - if (!rc) - return; - -// defining NS_PAINT_SEPARATELY is useful for debugging invalidation -// problems since it limits repainting to the rects that were actually -// invalidated. -#undef NS_PAINT_SEPARATELY - -#ifdef NS_PAINT_SEPARATELY - nsRegionRectSet *regionRectSet = nsnull; - aClipRegion->GetRects(®ionRectSet); - for (nsRegionRect *r = regionRectSet->mRects, - *r_end = r + regionRectSet->mNumRects; r < r_end; ++r) { - nsRect boundsRect(r->x, r->y, r->width, r->height); -#else - nsRect boundsRect; - aClipRegion->GetBoundingBox(&boundsRect.x, &boundsRect.y, &boundsRect.width, &boundsRect.height); -#endif - - nsPaintEvent event(PR_TRUE, NS_PAINT, this); - event.renderingContext = rc; - event.time = GDK_CURRENT_TIME; // No time in EXPOSE events - event.rect = &boundsRect; - -#ifdef DEBUG - GdkWindow *gw = GetRenderWindow(GTK_OBJECT(mSuperWin)); - if (WANT_PAINT_FLASHING && gw) - { - GdkRegion *region; - aClipRegion->GetNativeRegion(*(void**)®ion); - nsGtkUtils::gdk_window_flash(gw,1,100000,region); - } - - // Check the pref _before_ checking caps lock, because checking - // caps lock requires a server round-trip. - if (debug_GetCachedBoolPref("nglayout.debug.paint_dumping") && CAPS_LOCK_IS_ON) - debug_DumpPaintEvent(stdout, this, &event, - debug_GetName(GTK_OBJECT(mSuperWin)), - (PRInt32) debug_GetRenderXID(GTK_OBJECT(mSuperWin))); -#endif // DEBUG - - DispatchWindowEvent(&event); -#ifdef NS_PAINT_SEPARATELY - } -#endif -} - -static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); - -NS_IMETHODIMP nsWindow::Update(void) -{ - if (!mSuperWin) // XXX ??? - return NS_OK; - - if (mIsUpdating) - UnqueueDraw(); - - if (!mUpdateArea->IsEmpty()) { - // Watch out for updates occuring during DoPaint. We must clear - // mUpdateArea before we go into DoPaint. - nsCOMPtr updateArea = mUpdateArea; - mUpdateArea = do_CreateInstance(kRegionCID); - if (mUpdateArea) { - mUpdateArea->Init(); - mUpdateArea->SetTo(0, 0, 0, 0); - } - - DoPaint(updateArea); - } else { - // g_print("nsWidget::Update(this=%p): avoided update of empty area\n", this); - } - - // While I'd think you should NS_RELEASE(aPaintEvent.widget) here, - // if you do, it is a NULL pointer. Not sure where it is getting - // released. - return NS_OK; -} - -NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener * aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent) -{ - GtkWidget *grabWidget; - - grabWidget = mWidget; - // XXX we need a visible widget!! - - if (aDoCapture) { - - if (mSuperWin) { - - // real grab is only done when there is no dragging - if (!nsWindow::DragInProgress()) { - NativeGrab(PR_TRUE); - - sIsGrabbing = PR_TRUE; - sGrabWindow = this; - } - } - - gRollupListener = aListener; - gRollupWidget = do_GetWeakReference(NS_STATIC_CAST(nsIWidget*,this)); - } else { - // make sure that the grab window is marked as released - if (sGrabWindow == this) { - sGrabWindow = NULL; - } - sIsGrabbing = PR_FALSE; - - if (!nsWindow::DragInProgress()) - NativeGrab(PR_FALSE); - gRollupListener = nsnull; - gRollupWidget = nsnull; - } - - return NS_OK; -} - -// this function is the function that actually does the native window -// grab passing in PR_TRUE will activate the grab, PR_FALSE will -// release the grab - -void nsWindow::NativeGrab(PRBool aGrab) -{ - // unconditionally reset our state - mLastGrabFailed = PR_FALSE; - - if (aGrab) { - DropMotionTarget(); - gint retval; - retval = gdk_pointer_grab (GDK_SUPERWIN(mSuperWin)->bin_window, PR_TRUE, (GdkEventMask) - (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | - GDK_POINTER_MOTION_MASK), - (GdkWindow*)NULL, NULL, GDK_CURRENT_TIME); -#ifdef DEBUG_GRAB - printf("nsWindow::NativeGrab %p pointer_grab %d\n", this, retval); -#endif - // check and set our flag if the grab failed - if (retval != 0) - mLastGrabFailed = PR_TRUE; - - if (mTransientParent) - retval = nsXKBModeSwitch::GrabKeyboard(GTK_WIDGET(mTransientParent)->window, - PR_TRUE, GDK_CURRENT_TIME); - else - retval = nsXKBModeSwitch::GrabKeyboard(mSuperWin->bin_window, - PR_TRUE, GDK_CURRENT_TIME); -#ifdef DEBUG_GRAB - printf("nsWindow::NativeGrab %p keyboard_grab %d\n", this, retval); -#endif - // check and set our flag if the grab failed - if (retval != 0) - mLastGrabFailed = PR_TRUE; - - // make sure to add outselves as the grab window - gtk_grab_add(GetOwningWidget()); - } else { -#ifdef DEBUG_GRAB - printf("nsWindow::NativeGrab %p ungrab\n", this); -#endif - nsXKBModeSwitch::UnGrabKeyboard(GDK_CURRENT_TIME); - gtk_grab_remove(GetOwningWidget()); - DropMotionTarget(); - gdk_pointer_ungrab(GDK_CURRENT_TIME); - - // Unlock CDE if something is deadlock - gdk_flush(); - } -} - -NS_IMETHODIMP nsWindow::Validate() -{ - if (mIsUpdating) { - mUpdateArea->SetTo(0, 0, 0, 0); - UnqueueDraw(); - } - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Invalidate(PRBool aIsSynchronous) -{ - - if (!mSuperWin) - return NS_OK; - - mUpdateArea->SetTo(0, 0, mBounds.width, mBounds.height); - - if (aIsSynchronous) - Update(); - else - QueueDraw(); - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Invalidate(const nsRect &aRect, PRBool aIsSynchronous) -{ - - if (!mSuperWin) - return NS_OK; - - mUpdateArea->Union(aRect.x, aRect.y, aRect.width, aRect.height); - - if (aIsSynchronous) - Update(); - else - QueueDraw(); - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous) -{ - - if (!mSuperWin) - return NS_OK; - - mUpdateArea->Union(*aRegion); - - if (aIsSynchronous) - Update(); - else - QueueDraw(); - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::SetBackgroundColor(const nscolor &aColor) -{ - nsBaseWidget::SetBackgroundColor(aColor); - - if (nsnull != mSuperWin) { - GdkColor back_color; - - back_color.pixel = ::gdk_rgb_xpixel_from_rgb(NS_TO_GDK_RGB(aColor)); - - gdk_window_set_background(mSuperWin->bin_window, &back_color); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Set this component cursor -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWindow::SetCursor(nsCursor aCursor) -{ - if (!mSuperWin) - /* These cases should agree with enum nsCursor in nsIWidget.h - * We're limited to those cursors available with XCreateFontCursor() - * If you change these, change them in gtk/nsWidget, too. */ - return NS_ERROR_FAILURE; - - // if we're not the toplevel window pass up the cursor request to - // the toplevel window to handle it. - if (!mMozArea) - return GetOwningWindow()->SetCursor(aCursor); - - // Only change cursor if it's changing - if (aCursor != mCursor) { - GdkCursor *newCursor = 0; - - newCursor = GtkCreateCursor(aCursor); - - if (nsnull != newCursor) { - mCursor = aCursor; - ::gdk_window_set_cursor(mSuperWin->shell_window, newCursor); - XFlush(GDK_DISPLAY()); - } - } - return NS_OK; -} - -GdkCursor *nsWindow::GtkCreateCursor(nsCursor aCursorType) -{ - GdkPixmap *cursor; - GdkPixmap *mask; - GdkColor fg, bg; - GdkCursor *gdkcursor = nsnull; - PRUint8 newType = 0xff; - - if ((gdkcursor = gsGtkCursorCache[aCursorType])) { -#ifdef DEBUG_CURSORCACHE - printf("cached cursor found: %p\n", gdkcursor); -#endif - return gdkcursor; - } - - switch (aCursorType) { - case eCursor_standard: - gdkcursor = gdk_cursor_new(GDK_LEFT_PTR); - break; - case eCursor_wait: - gdkcursor = gdk_cursor_new(GDK_WATCH); - break; - case eCursor_select: - gdkcursor = gdk_cursor_new(GDK_XTERM); - break; - case eCursor_hyperlink: - gdkcursor = gdk_cursor_new(GDK_HAND2); - break; - case eCursor_n_resize: - gdkcursor = gdk_cursor_new(GDK_TOP_SIDE); - break; - case eCursor_s_resize: - gdkcursor = gdk_cursor_new(GDK_BOTTOM_SIDE); - break; - case eCursor_w_resize: - gdkcursor = gdk_cursor_new(GDK_LEFT_SIDE); - break; - case eCursor_e_resize: - gdkcursor = gdk_cursor_new(GDK_RIGHT_SIDE); - break; - case eCursor_nw_resize: - gdkcursor = gdk_cursor_new(GDK_TOP_LEFT_CORNER); - break; - case eCursor_se_resize: - gdkcursor = gdk_cursor_new(GDK_BOTTOM_RIGHT_CORNER); - break; - case eCursor_ne_resize: - gdkcursor = gdk_cursor_new(GDK_TOP_RIGHT_CORNER); - break; - case eCursor_sw_resize: - gdkcursor = gdk_cursor_new(GDK_BOTTOM_LEFT_CORNER); - break; - case eCursor_crosshair: - gdkcursor = gdk_cursor_new(GDK_CROSSHAIR); - break; - case eCursor_move: - gdkcursor = gdk_cursor_new(GDK_FLEUR); - break; - case eCursor_help: - newType = MOZ_CURSOR_QUESTION_ARROW; - break; - case eCursor_copy: // CSS3 - newType = MOZ_CURSOR_COPY; - break; - case eCursor_alias: - newType = MOZ_CURSOR_ALIAS; - break; - case eCursor_context_menu: - newType = MOZ_CURSOR_CONTEXT_MENU; - break; - case eCursor_cell: - gdkcursor = gdk_cursor_new(GDK_PLUS); - break; - case eCursor_grab: - newType = MOZ_CURSOR_HAND_GRAB; - break; - case eCursor_grabbing: - newType = MOZ_CURSOR_HAND_GRABBING; - break; - case eCursor_spinning: - newType = MOZ_CURSOR_SPINNING; - break; - case eCursor_zoom_in: - newType = MOZ_CURSOR_ZOOM_IN; - break; - case eCursor_zoom_out: - newType = MOZ_CURSOR_ZOOM_OUT; - break; - case eCursor_not_allowed: - case eCursor_no_drop: - newType = MOZ_CURSOR_NOT_ALLOWED; - break; - case eCursor_col_resize: - newType = MOZ_CURSOR_COL_RESIZE; - break; - case eCursor_row_resize: - newType = MOZ_CURSOR_ROW_RESIZE; - break; - case eCursor_vertical_text: - newType = MOZ_CURSOR_VERTICAL_TEXT; - break; - case eCursor_all_scroll: - gdkcursor = gdk_cursor_new(GDK_FLEUR); - break; - case eCursor_nesw_resize: - newType = MOZ_CURSOR_NESW_RESIZE; - break; - case eCursor_nwse_resize: - newType = MOZ_CURSOR_NWSE_RESIZE; - break; - case eCursor_ns_resize: - gdkcursor = gdk_cursor_new(GDK_SB_V_DOUBLE_ARROW); - break; - case eCursor_ew_resize: - gdkcursor = gdk_cursor_new(GDK_SB_H_DOUBLE_ARROW); - break; - default: - NS_ASSERTION(aCursorType, "Invalid cursor type"); - gdkcursor = gdk_cursor_new(GDK_LEFT_PTR); - break; - } - - /* if by now we don't have a xcursor, this means we have to make a custom one */ - if (newType != 0xff) { - gdk_color_parse("#000000", &fg); - gdk_color_parse("#ffffff", &bg); - - cursor = gdk_bitmap_create_from_data(NULL, - (char *)GtkCursors[newType].bits, - 32, 32); - mask = gdk_bitmap_create_from_data(NULL, - (char *)GtkCursors[newType].mask_bits, - 32, 32); - - gdkcursor = gdk_cursor_new_from_pixmap(cursor, mask, &fg, &bg, - GtkCursors[newType].hot_x, - GtkCursors[newType].hot_y); - - gdk_bitmap_unref(mask); - gdk_bitmap_unref(cursor); - } - -#ifdef DEBUG_CURSORCACHE - printf("inserting cursor into the cache: %p\n", gdkcursor); -#endif - gsGtkCursorCache[aCursorType] = gdkcursor; - - return gdkcursor; -} - -NS_IMETHODIMP -nsWindow::Enable(PRBool aState) -{ - GtkWidget *top_mozarea = GetOwningWidget(); - GtkWindow *top_window = GTK_WINDOW(gtk_widget_get_toplevel(top_mozarea)); - - if (aState) { - gtk_widget_set_sensitive(top_mozarea, TRUE); - // See if now that we're sensitive again check to see if we need - // to reset ourselves the default focus widget for the toplevel - // window. We should only do that if there is no focus widget - // since someone else might have taken the focus while we were - // disabled, and stealing focus is rude! - if (mRestoreFocus && !top_window->focus_widget) { - gtk_window_set_focus(top_window, top_mozarea); - } - mRestoreFocus = PR_FALSE; - } - else { - // Setting the window insensitive below will remove the window - // focus widget so we will have to restore it when we are - // reenabled. Of course, because of embedding, we might not - // actually _be_ the widget with focus, so keep that in mind. - if (top_window->focus_widget == top_mozarea) { - mRestoreFocus = PR_TRUE; - } - gtk_widget_set_sensitive(top_mozarea, FALSE); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsWindow::IsEnabled(PRBool *aState) -{ - NS_ENSURE_ARG_POINTER(aState); - - *aState = !mMozArea || GTK_WIDGET_IS_SENSITIVE(mMozArea); - - return NS_OK; -} - -NS_IMETHODIMP -nsWindow::SetFocus(PRBool aRaise) -{ -#ifdef DEBUG_FOCUS - printf("nsWindow::SetFocus %p\n", NS_STATIC_CAST(void *, this)); -#endif /* DEBUG_FOCUS */ - - GtkWidget *top_mozarea = GetOwningWidget(); - GtkWidget *toplevel = nsnull; - - if (top_mozarea) - toplevel = gtk_widget_get_toplevel(top_mozarea); - - // map the window if the pref says to and neither the mozarea or its - // toplevel window has focus - if (gRaiseWindows && aRaise && toplevel && top_mozarea && - (!GTK_WIDGET_HAS_FOCUS(top_mozarea) && !GTK_WIDGET_HAS_FOCUS(toplevel))) - GetAttention(-1); - -#ifdef DEBUG_FOCUS - printf("top moz area is %p\n", NS_STATIC_CAST(void *, top_mozarea)); -#endif - - // see if the toplevel window has focus - gboolean toplevel_focus = - gtk_mozarea_get_toplevel_focus(GTK_MOZAREA(top_mozarea)); - - // we need to grab focus or make sure that we get focus the next - // time that the toplevel gets focus. - if (top_mozarea && !GTK_WIDGET_HAS_FOCUS(top_mozarea)) { - - gpointer data = gtk_object_get_data(GTK_OBJECT(top_mozarea), "nsWindow"); - nsWindow *mozAreaWindow = NS_STATIC_CAST(nsWindow *, data); - mozAreaWindow->mBlockMozAreaFocusIn = PR_TRUE; - gtk_widget_grab_focus(top_mozarea); - mozAreaWindow->mBlockMozAreaFocusIn = PR_FALSE; - - // !!hack alert!! This works around bugs in version of gtk older - // than 1.2.9, which is what most people use. If the toplevel - // window doesn't have focus then we have to unset the focus flag - // on this widget since it was probably just set incorrectly. - if (!toplevel_focus) - GTK_WIDGET_UNSET_FLAGS(top_mozarea, GTK_HAS_FOCUS); - - // always dispatch a set focus event - DispatchSetFocusEvent(); - return NS_OK; - } - - if (mHasFocus) - { -#ifdef DEBUG_FOCUS - printf("Returning: Already have focus.\n"); -#endif /* DEBUG_FOCUS */ - return NS_OK; - } - - // check to see if we need to send a focus out event for the old window - if (sFocusWindow) - { - // let the current window loose its focus - sFocusWindow->DispatchLostFocusEvent(); - sFocusWindow->LoseFocus(); - } - - // set the focus window to this window - - sFocusWindow = this; - mHasFocus = PR_TRUE; - -#ifdef USE_XIM - IMESetFocusWindow(); -#endif // USE_XIM - - DispatchSetFocusEvent(); - -#ifdef DEBUG_FOCUS - printf("Returning:\n"); -#endif - - return NS_OK; -} - -/* virtual */ void -nsWindow::LoseFocus(void) -{ - // doesn't do anything. needed for nsWindow housekeeping, really. - if (mHasFocus == PR_FALSE) - return; - -#ifdef USE_XIM - IMEUnsetFocusWindow(); -#endif // USE_XIM - - sFocusWindow = 0; - mHasFocus = PR_FALSE; - -} - -void nsWindow::DispatchSetFocusEvent(void) -{ -#ifdef DEBUG_FOCUS - printf("nsWindow::DispatchSetFocusEvent %p\n", NS_STATIC_CAST(void *, this)); -#endif /* DEBUG_FOCUS */ - - nsGUIEvent event(PR_TRUE, NS_GOTFOCUS, this); - - NS_ADDREF_THIS(); - DispatchFocus(event); - - if (gJustGotActivate) { - gJustGotActivate = PR_FALSE; - DispatchActivateEvent(); - } - - NS_RELEASE_THIS(); -} - -void nsWindow::DispatchLostFocusEvent(void) -{ - -#ifdef DEBUG_FOCUS - printf("nsWindow::DispatchLostFocusEvent %p\n", NS_STATIC_CAST(void *, this)); -#endif /* DEBUG_FOCUS */ - - nsGUIEvent event(PR_TRUE, NS_LOSTFOCUS, this); - - NS_ADDREF_THIS(); - - DispatchFocus(event); - - NS_RELEASE_THIS(); -} - -void nsWindow::DispatchActivateEvent(void) -{ -#ifdef DEBUG_FOCUS - printf("nsWindow::DispatchActivateEvent %p\n", NS_STATIC_CAST(void *, this)); -#endif - -#ifdef USE_XIM - IMEBeingActivate(PR_TRUE); -#endif // USE_XIM - - gJustGotDeactivate = PR_FALSE; - - nsGUIEvent event(PR_TRUE, NS_ACTIVATE, this); - - NS_ADDREF_THIS(); - DispatchFocus(event); - NS_RELEASE_THIS(); - -#ifdef USE_XIM - IMEBeingActivate(PR_FALSE); -#endif // USE_XIM -} - -void nsWindow::DispatchDeactivateEvent(void) -{ -#ifdef DEBUG_FOCUS - printf("nsWindow::DispatchDeactivateEvent %p\n", - NS_STATIC_CAST(void *, this)); -#endif -#ifdef USE_XIM - IMEBeingActivate(PR_TRUE); -#endif // USE_XIM - - nsGUIEvent event(PR_TRUE, NS_DEACTIVATE, this); - - NS_ADDREF_THIS(); - DispatchFocus(event); - NS_RELEASE_THIS(); - -#ifdef USE_XIM - IMEBeingActivate(PR_FALSE); -#endif // USE_XIM -} - -// this function is called whenever there's a focus in event on the -// mozarea. - -void nsWindow::HandleMozAreaFocusIn(void) -{ - // If we're getting this focus in as a result of a child superwin - // getting called with SetFocus() this flag will be set. We don't - // want to generate extra focus in events so just return. - if (mBlockMozAreaFocusIn) - return; - - // otherwise, dispatch our focus events -#ifdef DEBUG_FOCUS - printf("nsWindow::HandleMozAreaFocusIn %p\n", NS_STATIC_CAST(void *, this)); -#endif - // we only set the gJustGotActivate signal if we're the toplevel - // window. embedding handles activate semantics for us. - if (mIsToplevel) - gJustGotActivate = PR_TRUE; - -#ifdef USE_XIM - IMESetFocusWindow(); -#endif // USE_XIM - - DispatchSetFocusEvent(); -} - -// this function is called whenever there's a focus out event on the -// mozarea. - -void nsWindow::HandleMozAreaFocusOut(void) -{ - // otherwise handle our focus out here. -#ifdef DEBUG_FOCUS - printf("nsWindow::HandleMozAreaFocusOut %p\n", NS_STATIC_CAST(void *, this)); -#endif - // if there's a window with focus, send a focus out event for that - // window. - if (sFocusWindow) - { - // Figure out of the focus widget is the child of this widget. If - // it isn't then we don't send the event since it was already sent - // earlier. - PRBool isChild = PR_FALSE; - GdkWindow *window; - window = (GdkWindow *)sFocusWindow->GetNativeData(NS_NATIVE_WINDOW); - while (window) - { - gpointer data = NULL; - gdk_window_get_user_data(window, &data); - if (GTK_IS_MOZAREA(data)) - { - GtkWidget *tmpMozArea = GTK_WIDGET(data); - if (tmpMozArea == mMozArea) - { - isChild = PR_TRUE; - break; - } - } - window = gdk_window_get_parent(window); - } - - if (isChild) - { - nsWidget *focusWidget = sFocusWindow; - nsCOMPtr focusWidgetGuard(focusWidget); - - focusWidget->DispatchLostFocusEvent(); - // we only send activate/deactivate events for toplevel windows. - // activation and deactivation is handled by embedders. - if (mIsToplevel) - focusWidget->DispatchDeactivateEvent(); - focusWidget->LoseFocus(); - } - } -} - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnMotionNotifySignal(GdkEventMotion *aGdkMotionEvent) -{ - XEvent xevent; - GdkEvent gdk_event; - PRBool synthEvent = PR_FALSE; - while (XCheckWindowEvent(GDK_DISPLAY(), - GDK_WINDOW_XWINDOW(mSuperWin->bin_window), - ButtonMotionMask, &xevent)) { - synthEvent = PR_TRUE; - } - if (synthEvent) { - gdk_event.type = GDK_MOTION_NOTIFY; - gdk_event.motion.window = aGdkMotionEvent->window; - gdk_event.motion.send_event = aGdkMotionEvent->send_event; - gdk_event.motion.time = xevent.xmotion.time; - gdk_event.motion.x = xevent.xmotion.x; - gdk_event.motion.y = xevent.xmotion.y; - gdk_event.motion.pressure = aGdkMotionEvent->pressure; - gdk_event.motion.xtilt = aGdkMotionEvent->xtilt; - gdk_event.motion.ytilt = aGdkMotionEvent->ytilt; - gdk_event.motion.state = aGdkMotionEvent->state; - gdk_event.motion.is_hint = xevent.xmotion.is_hint; - gdk_event.motion.source = aGdkMotionEvent->source; - gdk_event.motion.deviceid = aGdkMotionEvent->deviceid; - gdk_event.motion.x_root = xevent.xmotion.x_root; - gdk_event.motion.y_root = xevent.xmotion.y_root; - nsWidget::OnMotionNotifySignal(&gdk_event.motion); - } - else { - nsWidget::OnMotionNotifySignal(aGdkMotionEvent); - } -} - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnEnterNotifySignal(GdkEventCrossing *aGdkCrossingEvent) -{ - if (GTK_WIDGET_SENSITIVE(GetOwningWidget())) { - nsWidget::OnEnterNotifySignal(aGdkCrossingEvent); - if (mMozArea) { - GTK_PRIVATE_SET_FLAG(mMozArea, GTK_LEAVE_PENDING); - mLeavePending = PR_TRUE; - } - } -} - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnLeaveNotifySignal(GdkEventCrossing *aGdkCrossingEvent) -{ - if (mMozArea) { - if (mLeavePending) { - GTK_PRIVATE_UNSET_FLAG(mMozArea, GTK_LEAVE_PENDING); - mLeavePending = PR_FALSE; - nsWidget::OnLeaveNotifySignal(aGdkCrossingEvent); - } - } else - nsWidget::OnLeaveNotifySignal(aGdkCrossingEvent); -} - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnButtonPressSignal(GdkEventButton *aGdkButtonEvent) -{ - // This widget has gotten a button press event. If there's a rollup - // widget and we're not inside of a popup window we should pop up - // the rollup widget. Also, if the event is our event but it - // happens outside of the bounds of the window we should roll up as - // well. - if (gRollupWidget && ((GetOwningWindowType() != eWindowType_popup) || - (mSuperWin->bin_window == aGdkButtonEvent->window && - !ButtonEventInsideWindow(aGdkButtonEvent->window, - aGdkButtonEvent)))) { - gRollupListener->Rollup(); - gRollupWidget = nsnull; - gRollupListener = nsnull; - return; - } - - nsWidget::OnButtonPressSignal(aGdkButtonEvent); -} - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnButtonReleaseSignal(GdkEventButton *aGdkButtonEvent) -{ - // we only dispatch this event if there's a button motion target or - // if it's happening inside of a popup window while there is a - // rollup widget - if (!sButtonMotionTarget && - (gRollupWidget && GetOwningWindowType() != eWindowType_popup)) { - return; - } - nsWidget::OnButtonReleaseSignal(aGdkButtonEvent); -} - -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnFocusInSignal(GdkEventFocus * aGdkFocusEvent) -{ - - GTK_WIDGET_SET_FLAGS(mMozArea, GTK_HAS_FOCUS); - - nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, this); -#ifdef DEBUG - printf("send NS_GOTFOCUS from nsWindow::OnFocusInSignal\n"); -#endif - -// event.time = aGdkFocusEvent->time;; -// event.time = PR_Now(); - - AddRef(); - - DispatchFocus(event); - - Release(); -} -////////////////////////////////////////////////////////////////////// -/* virtual */ void -nsWindow::OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent) -{ - - GTK_WIDGET_UNSET_FLAGS(mMozArea, GTK_HAS_FOCUS); - - nsFocusEvent event(PR_TRUE, NS_LOSTFOCUS, this); - -// event.time = aGdkFocusEvent->time;; -// event.time = PR_Now(); - - AddRef(); - - DispatchFocus(event); - - Release(); -} - -////////////////////////////////////////////////////////////////// -void -nsWindow::InstallFocusInSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"focus_in_event", - GTK_SIGNAL_FUNC(nsWindow::FocusInSignal)); -} -////////////////////////////////////////////////////////////////// -void -nsWindow::InstallFocusOutSignal(GtkWidget * aWidget) -{ - NS_ASSERTION( nsnull != aWidget, "widget is null"); - - InstallSignal(aWidget, - (gchar *)"focus_out_event", - GTK_SIGNAL_FUNC(nsWindow::FocusOutSignal)); -} - - -void -nsWindow::HandleGDKEvent(GdkEvent *event) -{ - if (mIsDestroying) - return; - - switch (event->any.type) - { - case GDK_MOTION_NOTIFY: - // when we receive this, it must be that the gtk dragging is over, - // it is dropped either in or out of mozilla, clear the flag - sIsDraggingOutOf = PR_FALSE; - OnMotionNotifySignal (&event->motion); - break; - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - OnButtonPressSignal (&event->button); - break; - case GDK_BUTTON_RELEASE: - OnButtonReleaseSignal (&event->button); - break; - case GDK_ENTER_NOTIFY: - if(is_parent_ungrab_enter(&event->crossing)) - return; - - OnEnterNotifySignal (&event->crossing); - break; - case GDK_LEAVE_NOTIFY: - if(is_parent_grab_leave(&event->crossing)) - return; - - OnLeaveNotifySignal (&event->crossing); - break; - - default: - break; - } -} - -void -nsWindow::OnDestroySignal(GtkWidget* aGtkWidget) -{ - nsWidget::OnDestroySignal(aGtkWidget); - if (aGtkWidget == mShell) { - mShell = nsnull; - } -} - -gint handle_delete_event(GtkWidget *w, GdkEventAny *e, nsWindow *win) -{ - - PRBool isEnabled; - // If this window is disabled, don't dispatch the delete event - win->IsEnabled(&isEnabled); - if (!isEnabled) - return TRUE; - - NS_ADDREF(win); - - // dispatch an "onclose" event. to delete immediately, call win->Destroy() - nsGUIEvent event(PR_TRUE, NS_XUL_CLOSE, win); - nsEventStatus status; - - win->DispatchEvent(&event, status); - - NS_RELEASE(win); - return TRUE; -} - - - -NS_IMETHODIMP nsWindow::PreCreateWidget(nsWidgetInitData *aInitData) -{ - if (nsnull != aInitData) { - SetWindowType(aInitData->mWindowType); - SetBorderStyle(aInitData->mBorderStyle); - - return NS_OK; - } - return NS_ERROR_FAILURE; -} - - -gint nsWindow::ConvertBorderStyles(nsBorderStyle bs) -{ - gint w = 0; - - if (bs == eBorderStyle_default) - return -1; - - if (bs & eBorderStyle_all) - w |= GDK_DECOR_ALL; - if (bs & eBorderStyle_border) - w |= GDK_DECOR_BORDER; - if (bs & eBorderStyle_resizeh) - w |= GDK_DECOR_RESIZEH; - if (bs & eBorderStyle_title) - w |= GDK_DECOR_TITLE; - if (bs & eBorderStyle_menu) - w |= GDK_DECOR_MENU; - if (bs & eBorderStyle_minimize) - w |= GDK_DECOR_MINIMIZE; - if (bs & eBorderStyle_maximize) - w |= GDK_DECOR_MAXIMIZE; - if (bs & eBorderStyle_close) { -#ifdef DEBUG - printf("we don't handle eBorderStyle_close yet... please fix me\n"); -#endif /* DEBUG */ - } - - return w; -} - - -//------------------------------------------------------------------------- -// -// Create the native widget -// -//------------------------------------------------------------------------- - -NS_METHOD nsWindow::CreateNative(GtkObject *parentWidget) -{ - GdkSuperWin *superwin = 0; - GdkEventMask mask; - PRBool parentIsContainer = PR_FALSE; - GtkContainer *parentContainer = NULL; - GtkWindow *topLevelParent = NULL; - - if (parentWidget) { - if (GDK_IS_SUPERWIN(parentWidget)) { - superwin = GDK_SUPERWIN(parentWidget); - GdkWindow *topGDKWindow = - gdk_window_get_toplevel(GDK_SUPERWIN(parentWidget)->shell_window); - gpointer data; - gdk_window_get_user_data(topGDKWindow, &data); - if (GTK_IS_WINDOW(data)) { - topLevelParent = GTK_WINDOW(data); - } - } - else if (GTK_IS_CONTAINER(parentWidget)) { - parentContainer = GTK_CONTAINER(parentWidget); - parentIsContainer = PR_TRUE; - topLevelParent = - GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(parentWidget))); - } - else { - NS_WARNING("Unknown parent widget type"); - } - } - - switch(mWindowType) - { - case eWindowType_dialog: - mIsToplevel = PR_TRUE; - mShell = gtk_window_new(GTK_WINDOW_DIALOG); - if (topLevelParent) { - gtk_window_set_transient_for(GTK_WINDOW(mShell), topLevelParent); - mTransientParent = topLevelParent; - } - gtk_window_set_policy(GTK_WINDOW(mShell), PR_TRUE, PR_TRUE, PR_FALSE); - // gtk_widget_set_app_paintable(mShell, PR_TRUE); - InstallRealizeSignal(mShell); - - // create the mozarea. this will be the single child of the - // toplevel window - mMozArea = gtk_mozarea_new(); - gtk_container_add(GTK_CONTAINER(mShell), mMozArea); - gtk_widget_realize(GTK_WIDGET(mMozArea)); - SetIcon(NS_LITERAL_STRING("default")); - mSuperWin = GTK_MOZAREA(mMozArea)->superwin; - // set the back pixmap to None so that we don't get a flash of - // black - gdk_window_set_back_pixmap(mShell->window, NULL, FALSE); - - gtk_signal_connect(GTK_OBJECT(mShell), - "delete_event", - GTK_SIGNAL_FUNC(handle_delete_event), - this); - break; - - case eWindowType_popup: - mIsToplevel = PR_TRUE; - mShell = gtk_window_new(GTK_WINDOW_POPUP); - if (topLevelParent) { - gtk_window_set_transient_for(GTK_WINDOW(mShell), topLevelParent); - mTransientParent = topLevelParent; - } - // create the mozarea. this will be the single child of the - // toplevel window - mMozArea = gtk_mozarea_new(); - gtk_container_add(GTK_CONTAINER(mShell), mMozArea); - gtk_widget_realize(GTK_WIDGET(mMozArea)); - mSuperWin = GTK_MOZAREA(mMozArea)->superwin; - // set the back pixmap to None so that we don't get a flash of - // black - gdk_window_set_back_pixmap(mShell->window, NULL, FALSE); - - // gdk does not automatically set the cursor for "temporary" - // windows, which are what gtk uses for popups. - - mCursor = eCursor_wait; // force SetCursor to actually set the cursor, - // even though our internal state indicates - // that we already have the standard cursor. - SetCursor(eCursor_standard); - - break; - - case eWindowType_toplevel: - case eWindowType_invisible: - mIsToplevel = PR_TRUE; - mShell = gtk_window_new(GTK_WINDOW_TOPLEVEL); - // gtk_widget_set_app_paintable(mShell, PR_TRUE); - gtk_window_set_policy(GTK_WINDOW(mShell), PR_TRUE, PR_TRUE, PR_FALSE); - InstallRealizeSignal(mShell); - // create the mozarea. this will be the single child of the - // toplevel window - mMozArea = gtk_mozarea_new(); - gtk_container_add(GTK_CONTAINER(mShell), mMozArea); - gtk_widget_realize(GTK_WIDGET(mMozArea)); - SetIcon(NS_LITERAL_STRING("default")); - mSuperWin = GTK_MOZAREA(mMozArea)->superwin; - // set the back pixmap to None so that we don't get a flash of - // black - gdk_window_set_back_pixmap(mShell->window, NULL, FALSE); - - if (!topLevelParent) { - GdkWindow* dialoglead = mShell->window; - gdk_window_set_group(dialoglead, dialoglead); - } - gtk_signal_connect(GTK_OBJECT(mShell), - "delete_event", - GTK_SIGNAL_FUNC(handle_delete_event), - this); - gtk_signal_connect_after(GTK_OBJECT(mShell), - "size_allocate", - GTK_SIGNAL_FUNC(handle_size_allocate), - this); - break; - - case eWindowType_child: - // check to see if we need to create a mozarea for this widget - - if (parentIsContainer) { - // check to make sure that the widget is realized - if (!GTK_WIDGET_REALIZED(parentContainer)) - g_print("Warning: The parent container of this widget is not realized. I'm going to crash very, very soon.\n"); - else { - // create a containg mozarea for the superwin since we've got - // play nice with the gtk widget system. - mMozArea = gtk_mozarea_new(); - gtk_container_add(parentContainer, mMozArea); - gtk_widget_realize(GTK_WIDGET(mMozArea)); - mSuperWin = GTK_MOZAREA(mMozArea)->superwin; - } - } - else { - if (superwin) { - mSuperWin = gdk_superwin_new(superwin->bin_window, - mBounds.x, mBounds.y, - mBounds.width, mBounds.height); - nsWindow* realParent = - NS_STATIC_CAST(nsWindow*, gtk_object_get_data(GTK_OBJECT(superwin), "nsWindow")); - if (realParent && !mParent) { - realParent->mHasAnonymousChildren = PR_TRUE; - } - } - } - break; - - default: - break; - } - - // set up all the focus handling - - if (mShell) { - mask = (GdkEventMask) (GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_FOCUS_CHANGE_MASK ); - gdk_window_set_events(mShell->window, - mask); - - } - - if (mMozArea) { - // make sure that the mozarea widget can take the focus - GTK_WIDGET_SET_FLAGS(mMozArea, GTK_CAN_FOCUS); - // If there's a shell too make sure that this widget is the - // default for that window. We do this here because it has to - // happen after the GTK_CAN_FOCUS flag is set on the widget but - // before we hook up to the signals otherwise we will get spurious - // events. - if (mShell) - gtk_window_set_focus(GTK_WINDOW(mShell), mMozArea); - - // track focus events for the moz area - gtk_signal_connect(GTK_OBJECT(mMozArea), - "focus_in_event", - GTK_SIGNAL_FUNC(handle_mozarea_focus_in), - this); - gtk_signal_connect(GTK_OBJECT(mMozArea), - "focus_out_event", - GTK_SIGNAL_FUNC(handle_mozarea_focus_out), - this); - // Install button press and release signals so in the grab case we - // get the events. - InstallButtonPressSignal(mMozArea); - InstallButtonReleaseSignal(mMozArea); - } - - // end of settup up focus handling - - mask = (GdkEventMask)(GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK | - GDK_EXPOSURE_MASK | - GDK_FOCUS_CHANGE_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_POINTER_MOTION_MASK); - - - NS_ASSERTION(mSuperWin,"no super window!"); - if (!mSuperWin) return NS_ERROR_FAILURE; - - gdk_window_set_events(mSuperWin->bin_window, - mask); - - // set our object data so that we can find the class for this window - gtk_object_set_data (GTK_OBJECT (mSuperWin), "nsWindow", this); - // we want to set this on our moz area and shell too so we can - // always find the nsWindow given a specific GtkWidget * - if (mShell) - gtk_object_set_data(GTK_OBJECT(mShell), "nsWindow", this); - if (mMozArea) { - gtk_object_set_data(GTK_OBJECT(mMozArea), "nsWindow", this); - } - // set user data on the bin_window so we can find the superwin for it. - gdk_window_set_user_data (mSuperWin->bin_window, (gpointer)mSuperWin); - - // unset the back pixmap on this window. - gdk_window_set_back_pixmap(mSuperWin->bin_window, NULL, 0); - - if (mShell) { - // set up our drag and drop for the shell - gtk_drag_dest_set(mShell, - (GtkDestDefaults)0, - NULL, - 0, - (GdkDragAction)0); - - gtk_signal_connect(GTK_OBJECT(mShell), - "drag_motion", - GTK_SIGNAL_FUNC(nsWindow::DragMotionSignal), - this); - gtk_signal_connect(GTK_OBJECT(mShell), - "drag_leave", - GTK_SIGNAL_FUNC(nsWindow::DragLeaveSignal), - this); - gtk_signal_connect(GTK_OBJECT(mShell), - "drag_drop", - GTK_SIGNAL_FUNC(nsWindow::DragDropSignal), - this); - gtk_signal_connect(GTK_OBJECT(mShell), - "drag_data_received", - GTK_SIGNAL_FUNC(nsWindow::DragDataReceived), - this); - - // Also set up client_event handling for theme change notifications - gtk_signal_connect(GTK_OBJECT(mShell), - "client_event", - GTK_SIGNAL_FUNC(nsWindow::ClientEventSignal), - this); - } - - if (mMozArea) { - - // add our key event masks so that we can pass events to the inner - // windows. - mask = (GdkEventMask) ( GDK_EXPOSURE_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK | - GDK_STRUCTURE_MASK | - GDK_FOCUS_CHANGE_MASK ); - gdk_window_set_events(mMozArea->window, - mask); - gtk_signal_connect(GTK_OBJECT(mMozArea), - "key_press_event", - GTK_SIGNAL_FUNC(handle_key_press_event), - this); - gtk_signal_connect(GTK_OBJECT(mMozArea), - "key_release_event", - GTK_SIGNAL_FUNC(handle_key_release_event), - this); - - // Connect to the configure event from the mozarea. This will - // notify us when the toplevel window that contains the mozarea - // changes size so that we can update our size caches. It handles - // the plug/socket case, too. - gtk_signal_connect(GTK_OBJECT(mMozArea), - "toplevel_configure", - GTK_SIGNAL_FUNC(handle_toplevel_configure), - this); - } - - if (mSuperWin) { - // add the shell_window for this window to the table lookup - // this is so that as part of destruction we can find the superwin - // associated with the window. - g_hash_table_insert(mWindowLookupTable, mSuperWin->shell_window, this); - } - - // Any time the toplevel window invalidates mark ourselves as dirty - // with respect to caching window positions. - GtkWidget *top_mozarea = GetOwningWidget(); - if (top_mozarea) { - gtk_signal_connect_while_alive(GTK_OBJECT(top_mozarea), - "toplevel_configure", - GTK_SIGNAL_FUNC(handle_invalidate_pos), - this, - GTK_OBJECT(mSuperWin)); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Initialize all the Callbacks -// -//------------------------------------------------------------------------- -void nsWindow::InitCallbacks(char * aName) -{ - NS_ASSERTION(mSuperWin,"no superwin, can't init callbacks"); - if (mSuperWin) { - gdk_superwin_set_event_funcs(mSuperWin, - handle_xlib_shell_event, - handle_superwin_paint, - handle_superwin_flush, - nsXKBModeSwitch::HandleKeyPress, - nsXKBModeSwitch::HandleKeyRelease, - this, NULL); - } -} - -//------------------------------------------------------------------------- -// -// Return some native data according to aDataType -// -//------------------------------------------------------------------------- -void * nsWindow::GetNativeData(PRUint32 aDataType) -{ - - if (aDataType == NS_NATIVE_WINDOW) - { - if (mSuperWin) { - GdkWindowPrivate *private_window = (GdkWindowPrivate *)mSuperWin->bin_window; - if (private_window->destroyed == PR_TRUE) { - return NULL; - } - return (void *)mSuperWin->bin_window; - } - } - else if (aDataType == NS_NATIVE_WIDGET) { - if (mSuperWin) { - GdkWindowPrivate *private_window = (GdkWindowPrivate *)mSuperWin->bin_window; - if (private_window->destroyed == PR_TRUE) { - return NULL; - } - } - return (void *)mSuperWin; - } - else if (aDataType == NS_NATIVE_PLUGIN_PORT) { - if (mSuperWin) { - GdkWindowPrivate *private_window = (GdkWindowPrivate *)mSuperWin->bin_window; - if (private_window->destroyed == PR_TRUE) { - return NULL; - } - - // we have to flush the X queue here so that any plugins that - // might be running on separate X connections will be able to use - // this window in case it was just created - XSync(GDK_DISPLAY(), False); - return (void *)GDK_WINDOW_XWINDOW(mSuperWin->bin_window); - } - return NULL; - } - else if (aDataType == NS_NATIVE_SHELLWIDGET) { - return (void *) mShell; - } - - return nsWidget::GetNativeData(aDataType); -} - -//------------------------------------------------------------------------- -// -// Scroll the bits of a window -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) -{ - NS_ASSERTION(mIsDestroying != PR_TRUE, "Trying to scroll a destroyed widget\n"); - UnqueueDraw(); - mUpdateArea->Offset(aDx, aDy); - - if (mSuperWin) { - // scroll baby, scroll! - gdk_superwin_scroll(mSuperWin, aDx, aDy); - } - - // Update bounds on our child windows - for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - nsRect bounds; - kid->GetBounds(bounds); - bounds.x += aDx; - bounds.y += aDy; - nsWidget* childWidget = NS_STATIC_CAST(nsWidget*, kid); - childWidget->SetBounds(bounds); - childWidget->ResetInternalVisibility(); - } - - // Now invalidate the screen position cache, since things moved around. - InvalidateWindowPos(); - - return NS_OK; -} -//------------------------------------------------------------------------- -// -// Scroll the bits of a window -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWindow::ScrollWidgets(PRInt32 aDx, PRInt32 aDy) -{ - UnqueueDraw(); - mUpdateArea->Offset(aDx, aDy); - - if (mSuperWin) { - // scroll baby, scroll! - gdk_superwin_scroll(mSuperWin, aDx, aDy); - } - return NS_OK; -} - -NS_IMETHODIMP nsWindow::ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWindow::SetTitle(const nsAString& aTitle) -{ - if (!mShell) - return NS_ERROR_FAILURE; - - nsresult rv; - char *platformText = nsnull; - PRInt32 platformLen; - - // Set UTF8_STRING title for NET_WM-supporting window managers -#define UTF8_FOLLOWBYTE(ch) (((ch) & 0xC0) == 0x80) - NS_ConvertUTF16toUTF8 titleUTF8(aTitle); - if (titleUTF8.Length() > NS_WINDOW_TITLE_MAX_LENGTH) { - // Truncate overlong titles (bug 167315). Make sure we chop after a - // complete sequence by making sure the next char isn't a follow-byte. - PRUint32 len = NS_WINDOW_TITLE_MAX_LENGTH; - while(UTF8_FOLLOWBYTE(titleUTF8[len])) - --len; - titleUTF8.Truncate(len); - } - - XChangeProperty(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(mShell->window), - XInternAtom(GDK_DISPLAY(), "_NET_WM_NAME", False), - XInternAtom(GDK_DISPLAY(), "UTF8_STRING", False), - 8, PropModeReplace, (unsigned char *) titleUTF8.get(), - titleUTF8.Length()); - - // Set UTF8_STRING title for _NET_WM_ICON_NAME as well - XChangeProperty(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(mShell->window), - XInternAtom(GDK_DISPLAY(), "_NET_WM_ICON_NAME", False), - XInternAtom(GDK_DISPLAY(), "UTF8_STRING", False), - 8, PropModeReplace, (unsigned char *) titleUTF8.get(), - titleUTF8.Length()); - - nsCOMPtr encoder; - // get the charset - nsCAutoString platformCharset; - nsCOMPtr platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) - rv = platformCharsetService->GetCharset(kPlatformCharsetSel_Menu, platformCharset); - - // This is broken, it's just a random guess - if (NS_FAILED(rv)) - platformCharset.AssignLiteral("ISO-8859-1"); - - // get the encoder - nsCOMPtr ccm = - do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - rv = ccm->GetUnicodeEncoderRaw(platformCharset.get(), getter_AddRefs(encoder)); - NS_ASSERTION(NS_SUCCEEDED(rv), "GetUnicodeEncoderRaw failed."); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - - // Estimate out length and allocate the buffer based on a worst-case estimate, then do - // the conversion. - nsAString::const_iterator begin; - const PRUnichar *title = aTitle.BeginReading(begin).get(); - PRInt32 len = (PRInt32)aTitle.Length(); - encoder->GetMaxLength(title, len, &platformLen); - if (platformLen) { - // Truncate overlong titles (bug 167315). - if (platformLen > NS_WINDOW_TITLE_MAX_LENGTH) { - platformLen = NS_WINDOW_TITLE_MAX_LENGTH; - } - platformText = NS_REINTERPRET_CAST(char*, nsMemory::Alloc(platformLen + sizeof(char))); - if (platformText) { - rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?'); - if (NS_SUCCEEDED(rv)) - rv = encoder->Convert(title, &len, platformText, &platformLen); - (platformText)[platformLen] = '\0'; // null terminate. Convert() doesn't do it for us - } - } // if valid length - - if (platformLen > 0 && platformText) { - gtk_window_set_title(GTK_WINDOW(mShell), platformText); - } - else { - gtk_window_set_title(GTK_WINDOW(mShell), ""); - } - - if (platformText) - nsMemory::Free(platformText); - - return NS_OK; -} - -NS_IMETHODIMP -nsWindow::SetIcon(const nsAString& aIconSpec) -{ - // See if we have a cached icon set for this window type. - // Note that icon specs must be UTF8. - NS_ConvertUTF16toUTF8 iconKey(aIconSpec); - IconEntry* entry = NS_STATIC_CAST(IconEntry*, - PL_DHashTableOperate(sIconCache, - iconKey.get(), - PL_DHASH_ADD)); - if (!entry) - return NS_ERROR_OUT_OF_MEMORY; - - if (!entry->string) { - // We'll need to create the pixmaps. -#ifdef NS_DEBUG - PRUint32 generation = sIconCache->generation; -#endif - - GtkStyle* w_style; - GdkPixmap* w_pixmap = NULL, *w_minipixmap = NULL; - GdkBitmap* w_mask = NULL, *w_minimask = NULL; - - w_style = gtk_widget_get_style(mShell); - - nsCOMPtr iconFile; - ResolveIconName(aIconSpec, NS_LITERAL_STRING(".xpm"), - getter_AddRefs(iconFile)); - if (iconFile) { - nsCAutoString path; - iconFile->GetNativePath(path); - - w_pixmap = - gdk_pixmap_colormap_create_from_xpm(mShell->window, - gdk_colormap_get_system(), - &w_mask, - &w_style->bg[GTK_STATE_NORMAL], - path.get()); -#ifdef DEBUG_ICONS - printf("Loaded large icon file: %s\n", path.get()); -#endif - } - - ResolveIconName(aIconSpec, NS_LITERAL_STRING("16.xpm"), - getter_AddRefs(iconFile)); - if (iconFile) { - nsCAutoString path; - iconFile->GetNativePath(path); - - w_minipixmap = - gdk_pixmap_colormap_create_from_xpm(mShell->window, - gdk_colormap_get_system(), - &w_minimask, - &w_style->bg[GTK_STATE_NORMAL], - path.get()); -#ifdef DEBUG_ICONS - printf("Loaded small icon file: %s\n", path.get()); -#endif - } - - NS_ASSERTION(sIconCache->generation == generation, "sIconCache changed!"); - entry->string = strdup(iconKey.get()); - entry->w_pixmap = w_pixmap; - entry->w_mask = w_mask; - entry->w_minipixmap = w_minipixmap; - entry->w_minimask = w_minimask; - } -#ifdef DEBUG_ICONS - else - printf("Loaded icon set for %s from cache\n", iconKey.get()); -#endif - - if (entry->w_pixmap && SetIcon(entry->w_pixmap, entry->w_mask) != NS_OK) - return NS_ERROR_FAILURE; - - /* Now set the mini icon */ - if (entry->w_minipixmap) - return SetMiniIcon (entry->w_minipixmap, entry->w_minimask); - return NS_OK; -} - -nsresult nsWindow::SetMiniIcon(GdkPixmap *pixmap, - GdkBitmap *mask) -{ - GdkAtom icon_atom; - glong data[2]; - - if (!mShell) - return NS_ERROR_FAILURE; - - data[0] = ((GdkPixmapPrivate *)pixmap)->xwindow; - data[1] = ((GdkPixmapPrivate *)mask)->xwindow; - - icon_atom = gdk_atom_intern ("KWM_WIN_ICON", FALSE); - gdk_property_change (mShell->window, icon_atom, icon_atom, - 32, GDK_PROP_MODE_REPLACE, - (guchar *)data, 2); - return NS_OK; -} - -// Set the iconify icon for the window. -nsresult nsWindow::SetIcon(GdkPixmap *pixmap, - GdkBitmap *mask) -{ - if (!mShell) - return NS_ERROR_FAILURE; - - gdk_window_set_icon(mShell->window, (GdkWindow*)nsnull, pixmap, mask); - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::BeginResizingChildren(void) -{ - // gtk_layout_freeze(GTK_LAYOUT(mWidget)); - return NS_OK; -} - -NS_IMETHODIMP nsWindow::EndResizingChildren(void) -{ - // gtk_layout_thaw(GTK_LAYOUT(mWidget)); - return NS_OK; -} - -NS_IMETHODIMP nsWindow::GetScreenBounds(nsRect &aRect) -{ - nsRect origin(0,0,mBounds.width,mBounds.height); - WidgetToScreen(origin, aRect); - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Hide or show this component -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWindow::Show(PRBool bState) -{ - if (!mSuperWin) - return NS_OK; // Will be null durring printing - - mShown = bState; - - // show - ResetInternalVisibility(); - - return NS_OK; -} - -void nsWindow::ResetInternalVisibility() -{ - if (mShell) - { // top level, always set the visibility regardless of parent geometry - SetInternalVisibility(mShown); - } - else - { - nsWidget::ResetInternalVisibility(); - } -} - -void nsWindow::SetInternalVisibility(PRBool aVisible) -{ - // don't show if we are too small - if (mIsTooSmall) - { - aVisible = PR_FALSE; - } - - // Bail out now if we have nothing to do - if (aVisible == mInternalShown) - { - return; - } - - mInternalShown = aVisible; - - if (aVisible) - { - // GTK wants us to set the window mask before we show the window - // for the first time, or setting the mask later won't work. - // GTK also wants us to NOT set the window mask if we're not really - // going to need it, because GTK won't let us unset the mask properly - // later. - // So, we delay setting the mask until the last moment: when the window - // is shown. - if (mIsTranslucent) { - ApplyTransparencyBitmap(); - } - - // show mSuperWin - gdk_window_show(mSuperWin->bin_window); - gdk_window_show(mSuperWin->shell_window); - - if (mMozArea) - { - gtk_widget_show(mMozArea); - // if we're a toplevel window, show that too - if (mShell) - gtk_widget_show(mShell); - } - - // We just brought ourselves to the top. If we're not supposed to - // be at the top, put us back where we belong. - if (GetNextSibling()) { - ResetZOrder(); - } - - // and if we've been grabbed, grab for good measure. - if (sGrabWindow == this && mLastGrabFailed && !nsWindow::DragInProgress()) - NativeGrab(PR_TRUE); - } - // hide - else - { - gdk_window_hide(mSuperWin->bin_window); - gdk_window_hide(mSuperWin->shell_window); - // hide toplevel first so that things don't disapear from the screen one by one - - // are we a toplevel window? - if (mMozArea) - { - // if we're a toplevel window hide that too - if (mShell) - gtk_widget_hide(mShell); - gtk_widget_hide(mMozArea); - } - - } -} - -//------------------------------------------------------------------------- -// -// grab mouse events for this widget -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWindow::CaptureMouse(PRBool aCapture) -{ - GtkWidget *grabWidget; - - if (mIsToplevel && mMozArea) - grabWidget = mMozArea; - else - grabWidget = mWidget; - - if (aCapture) - { - if (!grabWidget) { -#ifdef DEBUG - g_print("nsWindow::CaptureMouse on NULL grabWidget\n"); -#endif - return NS_ERROR_FAILURE; - } - - GdkCursor *cursor = gdk_cursor_new (GDK_ARROW); - DropMotionTarget(); - gdk_pointer_grab (GTK_WIDGET(grabWidget)->window, PR_TRUE, (GdkEventMask) - (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | - GDK_POINTER_MOTION_MASK), - (GdkWindow*) NULL, cursor, GDK_CURRENT_TIME); - gdk_cursor_destroy(cursor); - gtk_grab_add(grabWidget); - } - else - { - DropMotionTarget(); - gdk_pointer_ungrab(GDK_CURRENT_TIME); - if (grabWidget) gtk_grab_remove(grabWidget); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY) -{ - if (mIsToplevel && mShell) - { - PRInt32 screenWidth = gdk_screen_width(); - PRInt32 screenHeight = gdk_screen_height(); - if (aAllowSlop) { - if (*aX < kWindowPositionSlop - mBounds.width) - *aX = kWindowPositionSlop - mBounds.width; - if (*aX > screenWidth - kWindowPositionSlop) - *aX = screenWidth - kWindowPositionSlop; - if (*aY < kWindowPositionSlop - mBounds.height) - *aY = kWindowPositionSlop - mBounds.height; - if (*aY > screenHeight - kWindowPositionSlop) - *aY = screenHeight - kWindowPositionSlop; - } else { - if (*aX < 0) - *aX = 0; - if (*aX > screenWidth - mBounds.width) - *aX = screenWidth - mBounds.width; - if (*aY < 0) - *aY = 0; - if (*aY > screenHeight - mBounds.height) - *aY = screenHeight - mBounds.height; - } - } - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Move(PRInt32 aX, PRInt32 aY) -{ - InvalidateWindowPos(); - // check if we are at right place already - if((aX == mBounds.x) && (aY == mBounds.y) && !mIsToplevel) { - return NS_OK; - } - - mBounds.x = aX; - mBounds.y = aY; - - if (mIsToplevel && mShell) - { -#ifdef DEBUG - /* complain if a top-level window is moved offscreen - (legal, but potentially worrisome) */ - if (!mParent) { - PRInt32 screenWidth = gdk_screen_width(); - PRInt32 screenHeight = gdk_screen_height(); - // no annoying assertions. just mention the issue. - if (aX < 0 || aX >= screenWidth || aY < 0 || aY >= screenHeight) - printf("window moved to offscreen position\n"); - } -#endif - - // do it the way it should be done period. - if (mParent && mWindowType == eWindowType_popup) { - // *VERY* stupid hack to make gfx combo boxes work - nsRect oldrect, newrect; - oldrect.x = aX; - oldrect.y = aY; - mParent->WidgetToScreen(oldrect, newrect); - gtk_widget_set_uposition(mShell, newrect.x, newrect.y); - } else { - gtk_widget_set_uposition(mShell, aX, aY); - } - } - else if (mSuperWin) { - gdk_window_move(mSuperWin->shell_window, aX, aY); - } - - ResetInternalVisibility(); - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint) -{ - PRInt32 sizeHeight = aHeight; - PRInt32 sizeWidth = aWidth; - -#if 0 - printf("nsWindow::Resize %s (%p) to %d %d\n", - (const char *) debug_GetName(mWidget), - this, - aWidth, aHeight); -#endif - - ResizeTransparencyBitmap(aWidth, aHeight); - - mBounds.width = aWidth; - mBounds.height = aHeight; - - // code to keep the window from showing before it has been moved or - // resized - // if we are resized to 1x1 or less, we will hide the window. - // Show(TRUE) will be ignored until a larger resize has happened - if (aWidth <= 1 || aHeight <= 1) - { - mIsTooSmall = PR_TRUE; - } - else - { - mIsTooSmall = PR_FALSE; - } - - if (mSuperWin) { - // toplevel window? if so, we should resize it as well. - if (mIsToplevel && mShell) - { - // set_default_size won't make a window smaller after it is visible - if (GTK_WIDGET_VISIBLE(mShell) && GTK_WIDGET_REALIZED(mShell)) - gdk_window_resize(mShell->window, aWidth, aHeight); - - gtk_window_set_default_size(GTK_WINDOW(mShell), aWidth, aHeight); - } - // we could be a mozarea resizing. - else if (mMozArea) - gdk_window_resize(mMozArea->window, aWidth, aHeight); - // in any case we always resize our mSuperWin window. - gdk_superwin_resize(mSuperWin, aWidth, aHeight); - } - if (mIsToplevel || mListenForResizes) { - //g_print("sending resize event\n"); - nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); - sevent.windowSize = new nsRect (0, 0, sizeWidth, sizeHeight); - sevent.mWinWidth = sizeWidth; - sevent.mWinHeight = sizeHeight; - // XXX fix sevent.time - AddRef(); - OnResize(&sevent); - Release(); - delete sevent.windowSize; - } - else { - //g_print("not sending resize event\n"); - } - - if (aRepaint) - Invalidate(PR_FALSE); - - // Do the actual work of showing or hiding the window as necessary - ResetInternalVisibility(); - for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - NS_STATIC_CAST(nsWidget*, kid)->ResetInternalVisibility(); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, - PRInt32 aHeight, PRBool aRepaint) -{ - Move(aX,aY); - // resize can cause a show to happen, so do this last - Resize(aWidth,aHeight,aRepaint); - return NS_OK; -} - -NS_IMETHODIMP nsWindow::GetAttention(PRInt32 aCycleCount) -{ - // get the next up moz area - GtkWidget *top_mozarea = GetOwningWidget(); - if (top_mozarea) { - GtkWidget *top_window = gtk_widget_get_toplevel(top_mozarea); - if (top_window && GTK_WIDGET_VISIBLE(top_window)) { - // this will raise the toplevel window - gdk_window_show(top_window->window); - } - } - return NS_OK; -} - -/* virtual */ void -nsWindow::OnRealize(GtkWidget *aWidget) -{ - if (aWidget == mShell) { - gint wmd = ConvertBorderStyles(mBorderStyle); - if (wmd != -1) - gdk_window_set_decorations(mShell->window, (GdkWMDecoration)wmd); - } -} - -gint handle_mozarea_focus_in(GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData) -{ - if (!aWidget) - return FALSE; - - if (!aGdkFocusEvent) - return FALSE; - - nsWindow *widget = (nsWindow *)aData; - - if (!widget) - return FALSE; - -#ifdef DEBUG_FOCUS - printf("handle_mozarea_focus_in\n"); -#endif - -#ifdef DEBUG_FOCUS - printf("aWidget is %p\n", NS_STATIC_CAST(void *, aWidget)); -#endif - - // set the flag since got a focus in event - GTK_WIDGET_SET_FLAGS(aWidget, GTK_HAS_FOCUS); - - widget->HandleMozAreaFocusIn(); - - return FALSE; -} - -gint handle_mozarea_focus_out(GtkWidget * aWidget, - GdkEventFocus * aGdkFocusEvent, - gpointer aData) -{ -#ifdef DEBUG_FOCUS - printf("handle_mozarea_focus_out\n"); -#endif - - if (!aWidget) { - return FALSE; - } - - if (!aGdkFocusEvent) { - return FALSE; - } - - nsWindow *widget = (nsWindow *) aData; - - if (!widget) { - return FALSE; - } - - // make sure that we unset our focus flag - GTK_WIDGET_UNSET_FLAGS(aWidget, GTK_HAS_FOCUS); - - widget->HandleMozAreaFocusOut(); - - return FALSE; -} - -void handle_toplevel_configure ( - GtkMozArea * aArea, - nsWindow * aWindow) -{ - // This event handler is only installed on toplevel windows - - // Find out if the window position has changed - nsRect oldBounds; - aWindow->GetBounds(oldBounds); - - // this is really supposed to be get_origin, not get_root_origin - // - bryner - nscoord x,y; - gdk_window_get_origin(GTK_WIDGET(aArea)->window, &x, &y); - - if ((oldBounds.x == x) && (oldBounds.y == y)) { - return; - } - - aWindow->OnMove(x, y); -} - -void -nsWindow::HandleXlibConfigureNotifyEvent(XEvent *event) -{ -#if 0 - XEvent config_event; - - while (XCheckTypedWindowEvent(event->xany.display, - event->xany.window, - ConfigureNotify, - &config_event) == True) { - // make sure that we don't get other types of events. - // StructureNotifyMask includes other kinds of events, too. - // g_print("clearing xlate queue from widget handler, serial is %ld\n", event->xany.serial); - // gdk_superwin_clear_translate_queue(mSuperWin, event->xany.serial); - *event = config_event; - // make sure that if we remove a configure event from the queue - // that it gets pulled out of the superwin tranlate queue, - // too. -#if 0 - g_print("Extra ConfigureNotify event for window 0x%lx %d %d %d %d\n", - event->xconfigure.window, - event->xconfigure.x, - event->xconfigure.y, - event->xconfigure.width, - event->xconfigure.height); -#endif - } - - // gdk_superwin_clear_translate_queue(mSuperWin, event->xany.serial); - -#endif - - if (mIsToplevel) { - nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); - sevent.windowSize = new nsRect (event->xconfigure.x, event->xconfigure.y, - event->xconfigure.width, event->xconfigure.height); - sevent.refPoint.x = event->xconfigure.x; - sevent.refPoint.y = event->xconfigure.y; - sevent.mWinWidth = event->xconfigure.width; - sevent.mWinHeight = event->xconfigure.height; - // XXX fix sevent.time - AddRef(); - OnResize(&sevent); - Release(); - delete sevent.windowSize; - } -} - -// Return the GtkMozArea that is the nearest parent of this widget -GtkWidget * -nsWindow::GetOwningWidget() -{ - GdkWindow *parent = nsnull; - GtkWidget *widget; - - if (mMozAreaClosestParent) - { - return (GtkWidget *)mMozAreaClosestParent; - } - if ((mMozAreaClosestParent == nsnull) && mMozArea) - { - mMozAreaClosestParent = mMozArea; - return (GtkWidget *)mMozAreaClosestParent; - } - - if (mSuperWin) - { - parent = mSuperWin->shell_window; - } - - while (parent) - { - gdk_window_get_user_data (parent, (void **)&widget); - if (widget != nsnull && GTK_IS_MOZAREA (widget)) - { - mMozAreaClosestParent = widget; - break; - } - parent = gdk_window_get_parent (parent); - parent = gdk_window_get_parent (parent); - } - - return (GtkWidget *)mMozAreaClosestParent; -} - -nsWindow * -nsWindow::GetOwningWindow(void) -{ - GtkWidget *widget = GetOwningWidget(); - - return NS_STATIC_CAST(nsWindow *, gtk_object_get_data(GTK_OBJECT(widget), - "nsWindow")); -} - -nsWindowType -nsWindow::GetOwningWindowType(void) -{ - nsWindow *owningWindow; - owningWindow = GetOwningWindow(); - - nsWindowType retval; - owningWindow->GetWindowType(retval); - - return retval; -} - -PRBool -nsWindow::GrabInProgress(void) -{ - return nsWindow::sIsGrabbing; -} - -/* static */ -PRBool -nsWindow::DragInProgress(void) -{ - // mLastDragMotionWindow means the drag arrow is over mozilla - // sIsDraggingOutOf means the drag arrow is out of mozilla - // both cases mean the dragging is happenning. - if (mLastDragMotionWindow || sIsDraggingOutOf) - return PR_TRUE; - else - return PR_FALSE; -} - - -/* static */ -nsWindow * -nsWindow::GetGrabWindow(void) -{ - if (nsWindow::sIsGrabbing) - return sGrabWindow; - else - return nsnull; -} - -GdkWindow * -nsWindow::GetGdkGrabWindow(void) -{ - if (!nsWindow::sIsGrabbing) - { - return nsnull; - } - if (mTransientParent) - return GTK_WIDGET(mTransientParent)->window; - else - return mSuperWin->bin_window; - -} - -GdkWindow * -nsWindow::GetLayeringWindow() -{ - return mSuperWin->shell_window; -} - -/* virtual */ GdkWindow * -nsWindow::GetRenderWindow(GtkObject * aGtkObject) -{ - GdkWindow * renderWindow = nsnull; - - if (aGtkObject) - { - if (GDK_IS_SUPERWIN(aGtkObject)) - { - renderWindow = GDK_SUPERWIN(aGtkObject)->bin_window; - } - } - return renderWindow; -} - -/* virtual */ -GtkWindow *nsWindow::GetTopLevelWindow(void) -{ - GtkWidget *moz_area; - - if (!mSuperWin) - return NULL; - moz_area = GetOwningWidget(); - return GTK_WINDOW(gtk_widget_get_toplevel(moz_area)); -} - -////////////////////////////////////////////////////////////////////// -// These are all of our drag and drop operations - -void -nsWindow::InitDragEvent(nsMouseEvent &aEvent) -{ - // set the keyboard modifiers - gint x, y; - GdkModifierType state = (GdkModifierType)0; - gdk_window_get_pointer(NULL, &x, &y, &state); - aEvent.isShift = (state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; - aEvent.isControl = (state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; - aEvent.isAlt = (state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE; - aEvent.isMeta = PR_FALSE; // GTK+ doesn't support the meta key -} - -// This will update the drag action based on the information in the -// drag context. Gtk gets this from a combination of the key settings -// and what the source is offering. - -void -nsWindow::UpdateDragStatus(nsMouseEvent &aEvent, - GdkDragContext *aDragContext, - nsIDragService *aDragService) -{ - // default is to do nothing - int action = nsIDragService::DRAGDROP_ACTION_NONE; - - // set the default just in case nothing matches below - if (aDragContext->actions & GDK_ACTION_DEFAULT) { - action = nsIDragService::DRAGDROP_ACTION_MOVE; - } - - // first check to see if move is set - if (aDragContext->actions & GDK_ACTION_MOVE) - action = nsIDragService::DRAGDROP_ACTION_MOVE; - - // then fall to the others - else if (aDragContext->actions & GDK_ACTION_LINK) - action = nsIDragService::DRAGDROP_ACTION_LINK; - - // copy is ctrl - else if (aDragContext->actions & GDK_ACTION_COPY) - action = nsIDragService::DRAGDROP_ACTION_COPY; - - // update the drag information - nsCOMPtr session; - aDragService->GetCurrentSession(getter_AddRefs(session)); - - if (session) - session->SetDragAction(action); -} - -/* static */ -gint -nsWindow::DragMotionSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData) -{ - nsWindow *window = (nsWindow *)aData; - return window->OnDragMotionSignal(aWidget, aDragContext, aX, aY, aTime, aData); -} - -gint nsWindow::OnDragMotionSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::OnDragMotionSignal\n"); -#endif /* DEBUG_DND_EVENTS */ - - sIsDraggingOutOf = PR_FALSE; - - // Reset out drag motion timer - ResetDragMotionTimer(aWidget, aDragContext, aX, aY, aTime); - - // get our drag context - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - nsCOMPtr dragSessionGTK = do_QueryInterface(dragService); - - // first, figure out which internal widget this drag motion actually - // happened on - nscoord retx = 0; - nscoord rety = 0; - - Window thisWindow = GDK_WINDOW_XWINDOW(aWidget->window); - Window returnWindow = None; - returnWindow = GetInnerMostWindow(thisWindow, thisWindow, aX, aY, - &retx, &rety, 0); - - nsWindow *innerMostWidget = NULL; - innerMostWidget = GetnsWindowFromXWindow(returnWindow); - - if (!innerMostWidget) - innerMostWidget = this; - - // check to see if there was a drag motion window already in place - if (mLastDragMotionWindow) { - // if it wasn't this - if (mLastDragMotionWindow != innerMostWidget) { - // send a drag event to the last window that got a motion event - mLastDragMotionWindow->OnDragLeave(); - // and enter on the new one - innerMostWidget->OnDragEnter(retx, rety); - - } - } - else { - // if there was no other motion window, then we're starting a - // drag. Send an enter event to initiate the drag. - - innerMostWidget->OnDragEnter(retx, rety); - } - - // set the last window to the innerMostWidget - mLastDragMotionWindow = innerMostWidget; - - // update the drag context - dragSessionGTK->TargetSetLastContext(aWidget, aDragContext, aTime); - - // notify the drag service that we are starting a drag motion. - dragSessionGTK->TargetStartDragMotion(); - - nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, innerMostWidget, - nsMouseEvent::eReal); - - InitDragEvent(event); - - // now that we have initialized the event update our drag status - UpdateDragStatus(event, aDragContext, dragService); - - event.refPoint.x = retx; - event.refPoint.y = rety; - - innerMostWidget->AddRef(); - - innerMostWidget->DispatchMouseEvent(event); - - innerMostWidget->Release(); - - // we're done with the drag motion event. notify the drag service. - dragSessionGTK->TargetEndDragMotion(aWidget, aDragContext, aTime); - - // and unset our context - dragSessionGTK->TargetSetLastContext(0, 0, 0); - - return TRUE; -} - -/* static */ -void -nsWindow::DragLeaveSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - guint aTime, - gpointer aData) -{ - nsWindow *window = (nsWindow *)aData; - window->OnDragLeaveSignal(aWidget, aDragContext, aTime, aData); -} - -void -nsWindow::OnDragLeaveSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - guint aTime, - gpointer aData) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::OnDragLeaveSignal\n"); -#endif /* DEBUG_DND_EVENTS */ - - sIsDraggingOutOf = PR_TRUE; - - // make sure to unset any drag motion timers here. - ResetDragMotionTimer(0, 0, 0, 0, 0); - - // create a fast timer - we're delaying the drag leave until the - // next mainloop in hopes that we might be able to get a drag drop - // signal - mDragLeaveTimer = do_CreateInstance("@mozilla.org/timer;1"); - NS_ASSERTION(mDragLeaveTimer, "Failed to create drag leave timer!"); - // fire this baby asafp - mDragLeaveTimer->InitWithFuncCallback(DragLeaveTimerCallback, this, 0, - nsITimer::TYPE_ONE_SHOT); -} - -/* static */ -gint -nsWindow::DragDropSignal (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData) -{ - nsWindow *window = (nsWindow *)aData; - return window->OnDragDropSignal(aWidget, aDragContext, aX, aY, aTime, aData); -} - -gint -nsWindow::OnDragDropSignal (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::OnDragDropSignal\n"); -#endif /* DEBUG_DND_EVENTS */ - - // get our drag context - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - nsCOMPtr dragSessionGTK = do_QueryInterface(dragService); - - nscoord retx = 0; - nscoord rety = 0; - - Window thisWindow = GDK_WINDOW_XWINDOW(aWidget->window); - Window returnWindow = None; - returnWindow = GetInnerMostWindow(thisWindow, thisWindow, aX, aY, - &retx, &rety, 0); - - nsWindow *innerMostWidget = NULL; - innerMostWidget = GetnsWindowFromXWindow(returnWindow); - - // set this now before any of the drag enter or leave events happen - dragSessionGTK->TargetSetLastContext(aWidget, aDragContext, aTime); - - if (!innerMostWidget) - innerMostWidget = this; - - // check to see if there was a drag motion window already in place - if (mLastDragMotionWindow) { - // if it wasn't this - if (mLastDragMotionWindow != innerMostWidget) { - // send a drag event to the last window that got a motion event - mLastDragMotionWindow->OnDragLeave(); - // and enter on the new one - innerMostWidget->OnDragEnter(retx, rety); - } - } - else { - // if there was no other motion window, send an enter event to - // initiate the drag session. - innerMostWidget->OnDragEnter(retx, rety); - } - - // clear any drag leave timer that might be pending so that it - // doesn't get processed when we actually go out to get data. - if (mDragLeaveTimer) { - mDragLeaveTimer->Cancel(); - mDragLeaveTimer = 0; - } - - // set the last window to this - mLastDragMotionWindow = innerMostWidget; - - // What we do here is dispatch a new drag motion event to - // re-validate the drag target and then we do the drop. The events - // look the same except for the type. - - innerMostWidget->AddRef(); - - nsMouseEvent event(PR_TRUE, NS_DRAGDROP_OVER, innerMostWidget, - nsMouseEvent::eReal); - - InitDragEvent(event); - - // now that we have initialized the event update our drag status - UpdateDragStatus(event, aDragContext, dragService); - - event.refPoint.x = retx; - event.refPoint.y = rety; - - innerMostWidget->DispatchMouseEvent(event); - - InitDragEvent(event); - - event.message = NS_DRAGDROP_DROP; - event.widget = innerMostWidget; - event.refPoint.x = retx; - event.refPoint.y = rety; - - innerMostWidget->DispatchMouseEvent(event); - - innerMostWidget->Release(); - - // before we unset the context we need to do a drop_finish - - gdk_drop_finish(aDragContext, TRUE, aTime); - - // after a drop takes place we need to make sure that the drag - // service doesn't think that it still has a context. if the other - // way ( besides the drop ) to end a drag event is during the leave - // event and and that case is handled in that handler. - dragSessionGTK->TargetSetLastContext(0, 0, 0); - - // send our drag exit event - innerMostWidget->OnDragLeave(); - // and clear the mLastDragMotion window - mLastDragMotionWindow = 0; - - // Make sure to end the drag session. If this drag started in a - // different app, we won't get a drag_end signal to end it from. - dragService->EndDragSession(PR_TRUE); - - return TRUE; -} - -// when the data has been received -/* static */ -void -nsWindow::DragDataReceived (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime, - gpointer aData) -{ - nsWindow *window = (nsWindow *)aData; - window->OnDragDataReceived(aWidget, aDragContext, aX, aY, - aSelectionData, aInfo, aTime, aData); -} - -void -nsWindow::OnDragDataReceived (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime, - gpointer aData) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::OnDragDataReceived\n"); -#endif /* DEBUG_DND_EVENTS */ - // get our drag context - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - nsCOMPtr dragSessionGTK = do_QueryInterface(dragService); - - dragSessionGTK->TargetDataReceived(aWidget, aDragContext, aX, aY, - aSelectionData, aInfo, aTime); -} - -void -nsWindow::OnDragLeave(void) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::OnDragLeave\n"); -#endif /* DEBUG_DND_EVENTS */ - - nsMouseEvent event(PR_TRUE, NS_DRAGDROP_EXIT, this, nsMouseEvent::eReal); - - AddRef(); - - DispatchMouseEvent(event); - - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - - if (dragService) { - nsCOMPtr currentDragSession; - dragService->GetCurrentSession(getter_AddRefs(currentDragSession)); - - if (currentDragSession) { - nsCOMPtr sourceNode; - currentDragSession->GetSourceNode(getter_AddRefs(sourceNode)); - - if (!sourceNode) { - // We're leaving a window while doing a drag that was - // initiated in a different app. End the drag session, since - // we're done with it for now (until the user drags back into - // mozilla). - dragService->EndDragSession(PR_FALSE); - } - } - } - - Release(); -} - -void -nsWindow::OnDragEnter(nscoord aX, nscoord aY) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::OnDragEnter\n"); -#endif /* DEBUG_DND_EVENTS */ - - nsRefPtr kungFuDeathGrip(this); - - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - - if (dragService) { - // Make sure that the drag service knows we're now dragging. - dragService->StartDragSession(); - } - - nsMouseEvent event(PR_TRUE, NS_DRAGDROP_ENTER, this, nsMouseEvent::eReal); - - event.refPoint.x = aX; - event.refPoint.y = aY; - - DispatchMouseEvent(event); -} - -void -nsWindow::ResetDragMotionTimer(GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, gint aY, guint aTime) -{ - - // We have to be careful about ref ordering here. if aWidget == - // mDraMotionWidget be careful not to let the refcnt drop to zero. - // Same with the drag context. - if (aWidget) - gtk_widget_ref(aWidget); - if (mDragMotionWidget) - gtk_widget_unref(mDragMotionWidget); - mDragMotionWidget = aWidget; - - if (aDragContext) - gdk_drag_context_ref(aDragContext); - if (mDragMotionContext) - gdk_drag_context_unref(mDragMotionContext); - mDragMotionContext = aDragContext; - - mDragMotionX = aX; - mDragMotionY = aY; - mDragMotionTime = aTime; - - // always clear the timer - if (mDragMotionTimerID) { - gtk_timeout_remove(mDragMotionTimerID); - mDragMotionTimerID = 0; -#ifdef DEBUG_DND_EVENTS - g_print("*** canceled motion timer\n"); -#endif - } - - // if no widget was passed in, just return instead of setting a new - // timer - if (!aWidget) { - return; - } - - // otherwise we create a new timer - mDragMotionTimerID = gtk_timeout_add(100, - (GtkFunction)DragMotionTimerCallback, - this); -} - -void -nsWindow::FireDragMotionTimer(void) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::FireDragMotionTimer\n"); -#endif - OnDragMotionSignal(mDragMotionWidget, mDragMotionContext, - mDragMotionX, mDragMotionY, mDragMotionTime, - this); -} - -void -nsWindow::FireDragLeaveTimer(void) -{ -#ifdef DEBUG_DND_EVENTS - g_print("nsWindow::FireDragLeaveTimer\n"); -#endif - mDragLeaveTimer = 0; - - // clean up any pending drag motion window info - if (mLastDragMotionWindow) { - // send our leave signal - mLastDragMotionWindow->OnDragLeave(); - mLastDragMotionWindow = 0; - } - -} - -/* static */ -guint -nsWindow::DragMotionTimerCallback(gpointer aClosure) -{ - nsWindow *window = NS_STATIC_CAST(nsWindow *, aClosure); - window->FireDragMotionTimer(); - return FALSE; -} - -/* static */ -void -nsWindow::DragLeaveTimerCallback(nsITimer *aTimer, void *aClosure) -{ - nsWindow *window = NS_STATIC_CAST(nsWindow *, aClosure); - window->FireDragLeaveTimer(); -} - -/* static */ -gint -nsWindow::ClientEventSignal(GtkWidget* widget, GdkEventClient* event, void* data) -{ - static GdkAtom atom_rcfiles = GDK_NONE; - if (!atom_rcfiles) - atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE); - - if (event->message_type == atom_rcfiles) { - nsWidget* targetWindow = (nsWidget*) data; - targetWindow->ThemeChanged(); - } - - return FALSE; -} - -void -nsWindow::ThemeChanged() -{ - Display *display; - Window window; - Window root_return; - Window parent_return; - Window *children_return = NULL; - unsigned int nchildren_return = 0; - unsigned int i = 0; - - if (mSuperWin) - { - display = GDK_DISPLAY(); - window = GDK_WINDOW_XWINDOW(mSuperWin->bin_window); - if (window && !((GdkWindowPrivate *)mSuperWin->bin_window)->destroyed) - { - // get a list of children for this window - XQueryTree(display, window, &root_return, &parent_return, - &children_return, &nchildren_return); - // walk the list of children - for (i=0; i < nchildren_return; i++) - { - Window child_window = children_return[i]; - nsWindow *thisWindow = GetnsWindowFromXWindow(child_window); - if (thisWindow) - { - thisWindow->ThemeChanged(); - } - } - - // free up the list of children - if (children_return) - XFree(children_return); - } - } - - DispatchStandardEvent(NS_THEMECHANGED); - Invalidate(PR_FALSE); -} - -ChildWindow::ChildWindow() -{ -} - -ChildWindow::~ChildWindow() -{ -#ifdef NOISY_DESTROY - IndentByDepth(stdout); - printf("ChildWindow::~ChildWindow:%p\n", this); -#endif -} - -#ifdef USE_XIM -nsresult nsWindow::KillICSpotTimer () -{ - if(mICSpotTimer) - { - mICSpotTimer->Cancel(); - mICSpotTimer = nsnull; - } - return NS_OK; -} - -nsresult nsWindow::PrimeICSpotTimer () -{ - KillICSpotTimer(); - nsresult err; - mICSpotTimer = do_CreateInstance("@mozilla.org/timer;1", &err); - if (NS_FAILED(err)) - return err; - mICSpotTimer->InitWithFuncCallback(ICSpotCallback, this, 1000, - nsITimer::TYPE_ONE_SHOT); - return NS_OK; -} - -void nsWindow::ICSpotCallback(nsITimer * aTimer, void * aClosure) -{ - nsWindow *window= NS_REINTERPRET_CAST(nsWindow*, aClosure); - if( ! window) return; - nsresult res = NS_ERROR_FAILURE; - - nsIMEGtkIC *xic = window->IMEGetInputContext(PR_FALSE); - if (xic) { - res = window->UpdateICSpot(xic); - } - if(NS_SUCCEEDED(res)) - { - window->PrimeICSpotTimer(); - } -} - -nsresult nsWindow::UpdateICSpot(nsIMEGtkIC *aXIC) -{ - // set spot location - nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_QUERY, this); - static gint oldx =0; - static gint oldy =0; - static gint oldw =0; - static gint oldh =0; - compEvent.theReply.mCursorPosition.x=-1; - compEvent.theReply.mCursorPosition.y=-1; - this->OnComposition(compEvent); - // set SpotLocation - if((compEvent.theReply.mCursorPosition.x < 0) && - (compEvent.theReply.mCursorPosition.y < 0)) - return NS_ERROR_FAILURE; - - // In over-the-spot style, pre-edit can not be drawn properly when - // IMESetFocusWindow() is called at height=1 and width=1 - // After resizing, we need to call SetPreeditArea() again - if((oldw != mBounds.width) || (oldh != mBounds.height)) { - GdkWindow *gdkWindow = (GdkWindow*)this->GetNativeData(NS_NATIVE_WINDOW); - if (gdkWindow) { - aXIC->SetPreeditArea(0, 0, - (int)((GdkWindowPrivate*)gdkWindow)->width, - (int)((GdkWindowPrivate*)gdkWindow)->height); - } - oldw = mBounds.width; - oldh = mBounds.height; - } - - if((compEvent.theReply.mCursorPosition.x != oldx)|| - (compEvent.theReply.mCursorPosition.y != oldy)) - { - nsPoint spot; - spot.x = compEvent.theReply.mCursorPosition.x; - spot.y = compEvent.theReply.mCursorPosition.y + - compEvent.theReply.mCursorPosition.height; - SetXICBaseFontSize(aXIC, compEvent.theReply.mCursorPosition.height - 1); - SetXICSpotLocation(aXIC, spot); - oldx = compEvent.theReply.mCursorPosition.x; - oldy = compEvent.theReply.mCursorPosition.y; - } - return NS_OK; -} - -void -nsWindow::SetXICBaseFontSize(nsIMEGtkIC* aXIC, int height) -{ - if (height%2) { - height-=1; - } - if (height<2) return; - if (height == mXICFontSize) return; - if (gPreeditFontset) { - gdk_font_unref(gPreeditFontset); - } - char *xlfdbase = PR_smprintf(XIC_FONTSET, height, height, height); - gPreeditFontset = gdk_fontset_load(xlfdbase); - if (gPreeditFontset) { - aXIC->SetPreeditFont(gPreeditFontset); - } - mXICFontSize = height; - PR_smprintf_free(xlfdbase); -} - -void -nsWindow::SetXICSpotLocation(nsIMEGtkIC* aXIC, nsPoint aPoint) -{ - if (gPreeditFontset) { - unsigned long x, y; - x = aPoint.x, y = aPoint.y; - y -= gPreeditFontset->descent; - aXIC->SetPreeditSpotLocation(x, y); - } -} - -void -nsWindow::ime_preedit_start() { -} - -void -nsWindow::ime_preedit_draw(nsIMEGtkIC *aXIC) { - IMEComposeStart(nsnull); - nsIMEPreedit *preedit = aXIC->GetPreedit(); - IMEComposeText(nsnull, - preedit->GetPreeditString(), - preedit->GetPreeditLength(), - preedit->GetPreeditFeedback()); - if (aXIC->IsPreeditComposing() == PR_FALSE) { - IMEComposeEnd(nsnull); - } -} - -void -nsWindow::ime_preedit_done() { -#ifdef _AIX - IMEComposeStart(nsnull); - IMEComposeText(nsnull, nsnull, 0, nsnull); -#endif - IMEComposeEnd(nsnull); -} - -void -nsWindow::IMEUnsetFocusWindow() -{ - KillICSpotTimer(); -} - -void -nsWindow::IMESetFocusWindow() -{ - // there is only one place to get ShellWindow - IMEGetShellWindow(); - - nsIMEGtkIC *xic = IMEGetInputContext(PR_TRUE); - - if (xic) { - if (xic->IsPreeditComposing() == PR_FALSE) { - IMEComposeEnd(nsnull); - } - xic->SetFocusWindow(this); - if (xic->mInputStyle & GDK_IM_PREEDIT_POSITION) { - UpdateICSpot(xic); - PrimeICSpotTimer(); - } - } -} - -void -nsWindow::IMEBeingActivate(PRBool aActive) -{ - // mIMEShellWindow has been retrieved in IMESetFocusWindow() - if (mIMEShellWindow) { - mIMEShellWindow->mIMEIsBeingActivate = aActive; - } else { - NS_ASSERTION(0, "mIMEShellWindow should exist"); - } -} - -void -nsWindow::IMEGetShellWindow(void) -{ - if (!mIMEShellWindow) { - nsWindow *mozAreaWindow = nsnull; - GtkWidget *top_mozarea = GetOwningWidget(); - if (top_mozarea) { - mozAreaWindow = NS_STATIC_CAST(nsWindow *, - gtk_object_get_data(GTK_OBJECT(top_mozarea), "nsWindow")); - } - mIMEShellWindow = mozAreaWindow; - NS_ASSERTION(mIMEShellWindow, "IMEGetShellWindow() fails"); - } -} - -nsIMEGtkIC* -nsWindow::IMEGetInputContext(PRBool aCreate) -{ - if (!mIMEShellWindow) { - return nsnull; - } - - nsXICLookupEntry* entry = - NS_STATIC_CAST(nsXICLookupEntry *, - PL_DHashTableOperate(&gXICLookupTable, mIMEShellWindow, - aCreate ? PL_DHASH_ADD - : PL_DHASH_LOOKUP)); - - if (!entry) { - return nsnull; - } - if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mXIC) { - return entry->mXIC; - } - - // create new XIC - if (aCreate) { - // create XLFD, needs 3 arguments of height, see XIC_FONTSET definition - char *xlfdbase = PR_smprintf(XIC_FONTSET, mXICFontSize, mXICFontSize, - mXICFontSize); - if (xlfdbase) { - if (gPreeditFontset == nsnull) { - gPreeditFontset = gdk_fontset_load(xlfdbase); - } - if (gStatusFontset == nsnull) { - gStatusFontset = gdk_fontset_load(xlfdbase); - } - PR_smprintf_free(xlfdbase); - nsIMEGtkIC *xic = nsnull; - if (gPreeditFontset && gStatusFontset) { - xic = nsIMEGtkIC::GetXIC(mIMEShellWindow, gPreeditFontset, - gStatusFontset); - if (xic) { - xic->SetPreeditSpotLocation(0, 14); - entry->mShellWindow = mIMEShellWindow; - entry->mXIC = xic; - mIMEShellWindow->mIMEShellWindow = mIMEShellWindow; - return xic; - } - } - } - - // ran out of memory somewhere in this block... - PL_DHashTableRawRemove(&gXICLookupTable, entry); - } - - return nsnull; -} - -void -nsWindow::IMEDestroyIC() -{ - // do not call IMEGetShellWindow() here - // user mIMEShellWindow to retrieve XIC - nsIMEGtkIC *xic = IMEGetInputContext(PR_FALSE); - - // xic=null means mIMEShellWindow is destroyed before - // or xic is never created for this widget - if (!xic) { - return; - } - - // reset parent window for status window - if (xic->mInputStyle & GDK_IM_STATUS_CALLBACKS) { - xic->ResetStatusWindow(this); - } - - if (mIMEShellWindow == this) { - // shell widget is being destroyed - // remove XIC from hashtable by mIMEShellWindow key - PL_DHashTableOperate(&gXICLookupTable, mIMEShellWindow, PL_DHASH_REMOVE); - delete xic; - } else { - // xic and mIMEShellWindow are valid - - nsWindow *gwin = xic->GetGlobalFocusWindow(); - nsWindow *fwin = xic->GetFocusWindow(); - - // bug 53989 - // if the current focused widget in xic is being destroyed, - // we need to change focused window to mIMEShellWindow - if (fwin && fwin == this) { - xic->SetFocusWindow(mIMEShellWindow); - xic->UnsetFocusWindow(); - - // bug 142873 - // if focus is already changed before, we need to change - // focus window to the current focused window again for XIC - if (gwin && gwin != this && sFocusWindow == gwin) { - nsIMEGtkIC *focused_xic = gwin->IMEGetInputContext(PR_FALSE); - if (focused_xic) { - focused_xic->SetFocusWindow(gwin); - } - } - } - } -} -#endif // USE_XIM - -void -nsWindow::IMEComposeStart(guint aTime) -{ -#ifdef USE_XIM - if (mIMECallComposeStart == PR_TRUE) { - return; - } -#endif // USE_XIM - nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_START, this); - compEvent.time = aTime; - - OnComposition(compEvent); - -#ifdef USE_XIM - mIMECallComposeStart = PR_TRUE; - mIMECallComposeEnd = PR_FALSE; -#endif // USE_XIM -} - -void -nsWindow::IMECommitEvent(GdkEventKey *aEvent) { - PRInt32 srcLen = aEvent->length; - - if (srcLen && aEvent->string && aEvent->string[0] && - nsGtkIMEHelper::GetSingleton()) { - - PRInt32 uniCharSize; - uniCharSize = nsGtkIMEHelper::GetSingleton()->MultiByteToUnicode( - aEvent->string, - srcLen, - &(mIMECompositionUniString), - &(mIMECompositionUniStringSize)); - - if (uniCharSize) { -#ifdef USE_XIM - nsIMEGtkIC *xic = IMEGetInputContext(PR_FALSE); - mIMECompositionUniString[uniCharSize] = 0; - if(sFocusWindow == 0 && xic != 0) { - // Commit event happens when Mozilla window does not have - // input focus but Lookup window (candidate) window has the focus - // At the case, we have to call IME events with focused widget - nsWindow *window = xic->GetFocusWindow(); - if (window) { - window->IMEComposeStart(aEvent->time); - window->IMEComposeText(aEvent, - mIMECompositionUniString, - uniCharSize, - nsnull); - window->IMEComposeEnd(aEvent->time); - } - } else -#endif // USE_XIM - { - IMEComposeStart(aEvent->time); - IMEComposeText(aEvent, - mIMECompositionUniString, - uniCharSize, - nsnull); - IMEComposeEnd(aEvent->time); - } - } - } - -#ifdef USE_XIM - nsIMEGtkIC *xic = IMEGetInputContext(PR_FALSE); - if (xic) { - if (xic->mInputStyle & GDK_IM_PREEDIT_POSITION) { - nsWindow *window = xic->GetFocusWindow(); - if (window) { - window->UpdateICSpot(xic); - window->PrimeICSpotTimer(); - } - } - } -#endif // USE_XIM -} - -void -nsWindow::IMEComposeText(GdkEventKey *aEvent, - const PRUnichar *aText, const PRInt32 aLen, - const char *aFeedback) { - nsTextEvent textEvent(PR_TRUE, NS_TEXT_TEXT, this); - if (aEvent) { - textEvent.isShift = (aEvent->state & GDK_SHIFT_MASK) ? PR_TRUE : PR_FALSE; - textEvent.isControl = (aEvent->state & GDK_CONTROL_MASK) ? PR_TRUE : PR_FALSE; - textEvent.isAlt = (aEvent->state & GDK_MOD1_MASK) ? PR_TRUE : PR_FALSE; - // XXX - textEvent.isMeta = PR_FALSE; //(aEvent->state & GDK_MOD2_MASK) ? PR_TRUE : PR_FALSE; - textEvent.time = aEvent->time; - } - - if (aLen != 0) { - textEvent.theText = (PRUnichar*)aText; -#ifdef USE_XIM - if (aFeedback) { - nsIMEPreedit::IMSetTextRange(aLen, - aFeedback, - &(textEvent.rangeCount), - &(textEvent.rangeArray)); - } -#endif // USE_XIM - } - OnText(textEvent); -#ifdef USE_XIM - if (textEvent.rangeArray) { - delete[] textEvent.rangeArray; - } -#endif // USE_XIM -} - -void -nsWindow::IMEComposeEnd(guint aTime) -{ -#ifdef USE_XIM - if (mIMECallComposeEnd == PR_TRUE) { - return; - } -#endif // USE_XIM - - nsCompositionEvent compEvent(PR_TRUE, NS_COMPOSITION_END, this); - compEvent.time = aTime; - OnComposition(compEvent); - -#ifdef USE_XIM - mIMECallComposeStart = PR_FALSE; - mIMECallComposeEnd = PR_TRUE; -#endif // USE_XIM -} - -NS_IMETHODIMP nsWindow::ResetInputState() -{ -#ifdef USE_XIM - nsIMEGtkIC *xic = IMEGetInputContext(PR_FALSE); - if (xic) { - // while being called for NS_ACTIVE and NS_DEACTIVATE, - // ignore ResetInputState() call - if (mIMEShellWindow->mIMEIsBeingActivate == PR_TRUE) { - return NS_OK; - } - - // while no focus on this widget, reseting IM status - // should not be done - if (mHasFocus == PR_FALSE) { - return NS_OK; - } - - // if no composed text, should just return - if(xic->IsPreeditComposing() == PR_FALSE) { - IMEComposeEnd(nsnull); - return NS_OK; - } - - // when composed text exists, - PRInt32 uniCharSize = - xic->ResetIC(&(mIMECompositionUniString), - &(mIMECompositionUniStringSize)); - - if (uniCharSize == 0) { - // ResetIC() returns 0, need to erase existing composed text - // in GDK_IM_PREEDIT_CALLBACKS style - if (xic->mInputStyle & GDK_IM_PREEDIT_CALLBACKS) { - IMEComposeStart(nsnull); - IMEComposeText(nsnull, nsnull, 0, nsnull); - IMEComposeEnd(nsnull); - } - } else { - mIMECompositionUniString[uniCharSize] = 0; - IMEComposeStart(nsnull); - IMEComposeText(nsnull, - mIMECompositionUniString, - uniCharSize, - nsnull); - IMEComposeEnd(nsnull); - } - if (xic->mInputStyle & GDK_IM_PREEDIT_POSITION) { - UpdateICSpot(xic); - } - } -#endif // USE_XIM - return NS_OK; -} - -static void -gdk_wmspec_change_state (gboolean add, - GdkWindow *window, - GdkAtom state1, - GdkAtom state2) -{ - XEvent xev; - -#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */ -#define _NET_WM_STATE_ADD 1 /* add/set property */ -#define _NET_WM_STATE_TOGGLE 2 /* toggle property */ - - xev.xclient.type = ClientMessage; - xev.xclient.serial = 0; - xev.xclient.send_event = True; - xev.xclient.window = GDK_WINDOW_XWINDOW(window); - xev.xclient.message_type = gdk_atom_intern("_NET_WM_STATE", FALSE); - xev.xclient.format = 32; - xev.xclient.data.l[0] = add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; - xev.xclient.data.l[1] = state1; - xev.xclient.data.l[2] = state2; - - XSendEvent(gdk_display, GDK_ROOT_WINDOW(), False, - SubstructureRedirectMask | SubstructureNotifyMask, &xev); -} - -#ifndef MOZ_XUL -void nsWindow::ApplyTransparencyBitmap() {} -void nsWindow::ResizeTransparencyBitmap(PRInt32 aNewWidth, PRInt32 aNewHeight) { -} -#else -NS_IMETHODIMP nsWindow::SetWindowTranslucency(PRBool aTranslucent) { - if (!mMozArea) - return GetOwningWindow()->SetWindowTranslucency(aTranslucent); - - if (!mShell) { - // we must be embedded - NS_WARNING("Trying to use transparent chrome in an embedded context"); - return NS_ERROR_FAILURE; - } - - if (mIsTranslucent == aTranslucent) - return NS_OK; - - if (!aTranslucent) { - if (mTransparencyBitmap) { - delete[] mTransparencyBitmap; - mTransparencyBitmap = nsnull; - gtk_widget_reset_shapes(mShell); - } - } // else the new default alpha values are "all 1", so we don't - // need to change anything yet - - mIsTranslucent = aTranslucent; - return NS_OK; -} - -NS_IMETHODIMP nsWindow::GetWindowTranslucency(PRBool& aTranslucent) { - if (!mMozArea) - return GetOwningWindow()->GetWindowTranslucency(aTranslucent); - - aTranslucent = mIsTranslucent; - return NS_OK; -} - -static gchar* CreateDefaultTransparencyBitmap(PRInt32 aWidth, PRInt32 aHeight) { - PRInt32 size = ((aWidth+7)/8)*aHeight; - gchar* bits = new gchar[size]; - if (bits) { - memset(bits, 255, size); - } - return bits; -} - -void nsWindow::ResizeTransparencyBitmap(PRInt32 aNewWidth, PRInt32 aNewHeight) { - if (!mTransparencyBitmap) - return; - - gchar* newBits = CreateDefaultTransparencyBitmap(aNewWidth, aNewHeight); - if (!newBits) { - delete[] mTransparencyBitmap; - mTransparencyBitmap = nsnull; - return; - } - - // Now copy the intersection of the old and new areas into the new mask - PRInt32 copyWidth = PR_MIN(aNewWidth, mBounds.width); - PRInt32 copyHeight = PR_MIN(aNewHeight, mBounds.height); - PRInt32 oldRowBytes = (mBounds.width+7)/8; - PRInt32 newRowBytes = (aNewWidth+7)/8; - PRInt32 copyBytes = (copyWidth+7)/8; - - PRInt32 i; - gchar* fromPtr = mTransparencyBitmap; - gchar* toPtr = newBits; - for (i = 0; i < copyHeight; i++) { - memcpy(toPtr, fromPtr, copyBytes); - fromPtr += oldRowBytes; - toPtr += newRowBytes; - } - - delete[] mTransparencyBitmap; - mTransparencyBitmap = newBits; -} - -static PRBool ChangedMaskBits(gchar* aMaskBits, PRInt32 aMaskWidth, PRInt32 aMaskHeight, - const nsRect& aRect, PRUint8* aAlphas) { - PRInt32 x, y, xMax = aRect.XMost(), yMax = aRect.YMost(); - PRInt32 maskBytesPerRow = (aMaskWidth + 7)/8; - for (y = aRect.y; y < yMax; y++) { - gchar* maskBytes = aMaskBits + y*maskBytesPerRow; - for (x = aRect.x; x < xMax; x++) { - PRBool newBit = *aAlphas > 0; - aAlphas++; - - gchar maskByte = maskBytes[x >> 3]; - PRBool maskBit = (maskByte & (1 << (x & 7))) != 0; - - if (maskBit != newBit) { - return PR_TRUE; - } - } - } - - return PR_FALSE; -} - -static void UpdateMaskBits(gchar* aMaskBits, PRInt32 aMaskWidth, PRInt32 aMaskHeight, - const nsRect& aRect, PRUint8* aAlphas) { - PRInt32 x, y, xMax = aRect.XMost(), yMax = aRect.YMost(); - PRInt32 maskBytesPerRow = (aMaskWidth + 7)/8; - for (y = aRect.y; y < yMax; y++) { - gchar* maskBytes = aMaskBits + y*maskBytesPerRow; - for (x = aRect.x; x < xMax; x++) { - PRBool newBit = *aAlphas > 0; - aAlphas++; - - gchar mask = 1 << (x & 7); - gchar maskByte = maskBytes[x >> 3]; - // Note: '-newBit' turns 0 into 00...00 and 1 into 11...11 - maskBytes[x >> 3] = (maskByte & ~mask) | (-newBit & mask); - } - } -} - -void nsWindow::ApplyTransparencyBitmap() { - if (!mTransparencyBitmap) { - mTransparencyBitmap = CreateDefaultTransparencyBitmap(mBounds.width, mBounds.height); - if (!mTransparencyBitmap) - return; - } - - gtk_widget_reset_shapes(mShell); - GdkBitmap* maskBitmap = gdk_bitmap_create_from_data(mShell->window, - mTransparencyBitmap, - mBounds.width, mBounds.height); - if (!maskBitmap) - return; - - gtk_widget_shape_combine_mask(mShell, maskBitmap, 0, 0); - gdk_bitmap_unref(maskBitmap); -} - -NS_IMETHODIMP nsWindow::UpdateTranslucentWindowAlpha(const nsRect& aRect, - PRUint8* aAlphas) -{ - if (!mMozArea) - return GetOwningWindow()->UpdateTranslucentWindowAlpha(aRect, aAlphas); - - NS_ASSERTION(mIsTranslucent, "Window is not transparent"); - - if (!mTransparencyBitmap) { - mTransparencyBitmap = CreateDefaultTransparencyBitmap(mBounds.width, mBounds.height); - if (!mTransparencyBitmap) - return NS_ERROR_FAILURE; - } - - NS_ASSERTION(aRect.x >= 0 && aRect.y >= 0 - && aRect.XMost() <= mBounds.width && aRect.YMost() <= mBounds.height, - "Rect is out of window bounds"); - - if (!ChangedMaskBits(mTransparencyBitmap, mBounds.width, mBounds.height, aRect, aAlphas)) - // skip the expensive stuff if the mask bits haven't changed; hopefully - // this is the common case - return NS_OK; - - UpdateMaskBits(mTransparencyBitmap, mBounds.width, mBounds.height, aRect, aAlphas); - - if (mShown) { - ApplyTransparencyBitmap(); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsWindow::HideWindowChrome(PRBool aShouldHide) -{ - if (!mMozArea) - return GetOwningWindow()->HideWindowChrome(aShouldHide); - - if (!mShell) { - // we must be embedded - NS_WARNING("Trying to hide window decorations in an embedded context"); - return NS_ERROR_FAILURE; - } - - // Sawfish, metacity, and presumably other window managers get - // confused if we change the window decorations while the window - // is visible. - - if (mShown) - gdk_window_hide(mShell->window); - - gint wmd; - if (aShouldHide) - wmd = 0; - else - wmd = ConvertBorderStyles(mBorderStyle); - - gdk_window_set_decorations(mShell->window, (GdkWMDecoration) wmd); - - if (mShown) - gdk_window_show(mShell->window); - // XXX This brought the window to the front, which maybe isn't what - // we wanted. - - // For some window managers, adding or removing window decorations - // requires unmapping and remapping our toplevel window. Go ahead - // and flush the queue here so that we don't end up with a BadWindow - // error later when this happens (when the persistence timer fires - // and GetWindowPos is called). - XSync(GDK_DISPLAY(), False); - - return NS_OK; -} - -NS_IMETHODIMP -nsWindow::MakeFullScreen(PRBool aFullScreen) -{ - if (!mMozArea) - return GetOwningWindow()->MakeFullScreen(aFullScreen); - - if (!mShell) { - // we must be embedded - NS_WARNING("Trying to go fullscreen in an embedded context"); - return NS_ERROR_FAILURE; - } - - gdk_wmspec_change_state(aFullScreen, mShell->window, - gdk_atom_intern("_NET_WM_STATE_FULLSCREEN", False), - GDK_NONE); - return NS_OK; -} -#endif - -void PR_CALLBACK -nsWindow::ClearIconEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr) -{ - IconEntry* entry = NS_STATIC_CAST(IconEntry*, aHdr); - if (entry->w_pixmap) { - gdk_pixmap_unref(entry->w_pixmap); - gdk_bitmap_unref(entry->w_mask); - } - if (entry->w_minipixmap) { - gdk_pixmap_unref(entry->w_minipixmap); - gdk_bitmap_unref(entry->w_minimask); - } - if (entry->string) - free((void*) entry->string); - PL_DHashClearEntryStub(aTable, aHdr); -} - -/* static */ -int -is_parent_ungrab_enter(GdkEventCrossing *event) -{ - return (GDK_CROSSING_UNGRAB == event->mode) && - ((GDK_NOTIFY_ANCESTOR == event->detail) || - (GDK_NOTIFY_VIRTUAL == event->detail)); -} - -/* static */ -int -is_parent_grab_leave(GdkEventCrossing *event) -{ - return (GDK_CROSSING_GRAB == event->mode) && - ((GDK_NOTIFY_ANCESTOR == event->detail) || - (GDK_NOTIFY_VIRTUAL == event->detail)); -} diff --git a/mozilla/widget/src/gtk/nsWindow.h b/mozilla/widget/src/gtk/nsWindow.h deleted file mode 100644 index 0c65f22404f..00000000000 --- a/mozilla/widget/src/gtk/nsWindow.h +++ /dev/null @@ -1,439 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsWindow_h__ -#define nsWindow_h__ - -#include "nsISupports.h" - -#include "nsWidget.h" - -#include "nsString.h" - -#include "nsIDragService.h" - -#include "gtkmozarea.h" -#include "gdksuperwin.h" - -#ifdef USE_XIM -#include "pldhash.h" -class nsIMEGtkIC; -class nsIMEPreedit; -#endif // USE_XIM - -class nsFont; -class nsIAppShell; - -/** - * Native GTK+ window wrapper. - */ - -class nsWindow : public nsWidget -{ - -public: - // nsIWidget interface - - nsWindow(); - virtual ~nsWindow(); - - static void ReleaseGlobals(); - - NS_DECL_ISUPPORTS_INHERITED - - NS_IMETHOD WidgetToScreen(const nsRect &aOldRect, nsRect &aNewRect); - - NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData); - - virtual void* GetNativeData(PRUint32 aDataType); - - NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); - NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy); - NS_IMETHOD ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy); - - NS_IMETHOD SetTitle(const nsAString& aTitle); - NS_IMETHOD Show(PRBool aShow); - NS_IMETHOD CaptureMouse(PRBool aCapture); - - NS_IMETHOD ConstrainPosition(PRBool aAllowSlop, - PRInt32 *aX, PRInt32 *aY); - NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); - - NS_IMETHOD Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint); - NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, - PRInt32 aHeight, PRBool aRepaint); - - NS_IMETHOD BeginResizingChildren(void); - NS_IMETHOD EndResizingChildren(void); - - NS_IMETHOD GetScreenBounds(nsRect &aRect); - - NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent); - NS_IMETHOD Validate(); - NS_IMETHOD Invalidate(PRBool aIsSynchronous); - NS_IMETHOD Invalidate(const nsRect &aRect, PRBool aIsSynchronous); - NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous); - NS_IMETHOD SetBackgroundColor(const nscolor &aColor); - NS_IMETHOD SetCursor(nsCursor aCursor); - NS_IMETHOD Enable (PRBool aState); - NS_IMETHOD IsEnabled (PRBool *aState); - NS_IMETHOD SetFocus(PRBool aRaise); - NS_IMETHOD GetAttention(PRInt32 aCycleCount); - NS_IMETHOD Destroy(); - NS_IMETHOD SetParent(nsIWidget* aNewParent); - void ResizeTransparencyBitmap(PRInt32 aNewWidth, PRInt32 aNewHeight); - void ApplyTransparencyBitmap(); -#ifdef MOZ_XUL - NS_IMETHOD SetWindowTranslucency(PRBool aTransparent); - NS_IMETHOD GetWindowTranslucency(PRBool& aTransparent); - NS_IMETHOD UpdateTranslucentWindowAlpha(const nsRect& aRect, PRUint8* aAlphas); - NS_IMETHOD HideWindowChrome(PRBool aShouldHide); - NS_IMETHOD MakeFullScreen(PRBool aFullScreen); -#endif - NS_IMETHOD SetIcon(const nsAString& aIcon); - GdkCursor *GtkCreateCursor(nsCursor aCursorType); - virtual void LoseFocus(void); - - // nsIKBStateControl - NS_IMETHOD ResetInputState(); - - void QueueDraw(); - void UnqueueDraw(); - void DoPaint(nsIRegion *aClipRegion); - static gboolean UpdateIdle (gpointer data); - // get the toplevel window for this widget - virtual GtkWindow *GetTopLevelWindow(void); - NS_IMETHOD Update(void); - virtual void OnMotionNotifySignal(GdkEventMotion *aGdkMotionEvent); - virtual void OnEnterNotifySignal(GdkEventCrossing *aGdkCrossingEvent); - virtual void OnLeaveNotifySignal(GdkEventCrossing *aGdkCrossingEvent); - virtual void OnButtonPressSignal(GdkEventButton *aGdkButtonEvent); - virtual void OnButtonReleaseSignal(GdkEventButton *aGdkButtonEvent); - virtual void OnFocusInSignal(GdkEventFocus * aGdkFocusEvent); - virtual void OnFocusOutSignal(GdkEventFocus * aGdkFocusEvent); - virtual void InstallFocusInSignal(GtkWidget * aWidget); - virtual void InstallFocusOutSignal(GtkWidget * aWidget); - void HandleGDKEvent(GdkEvent *event); - - gint ConvertBorderStyles(nsBorderStyle bs); - - void InvalidateWindowPos(void); - - - // in nsWidget now - // virtual PRBool OnResize(nsSizeEvent &aEvent); - - void HandleXlibConfigureNotifyEvent(XEvent *event); - - // Return the GtkMozArea that is the nearest parent of this widget - virtual GtkWidget *GetOwningWidget(); - - // Get the owning window for this window - nsWindow *GetOwningWindow(); - - // Return the type of the window that is the toplevel mozilla window - // for this (possibly) inner window - nsWindowType GetOwningWindowType(); - - // Return the Gdk window used for rendering - virtual GdkWindow * GetRenderWindow(GtkObject * aGtkWidget); - - // this is the "native" destroy code that will destroy any - // native windows / widgets for this logical widget - virtual void DestroyNative(void); - - // grab in progress - PRBool GrabInProgress(void); - // drag in progress - static PRBool DragInProgress(void); - - // XXX Chris - fix these - // virtual void OnButtonPressSignal(GdkEventButton * aGdkButtonEvent); - - // this will get the nsWindow with the grab. The return will not be - // addrefed. - static nsWindow *GetGrabWindow(void); - GdkWindow *GetGdkGrabWindow(void); - - // Return the Gdk window used for positioning, raising and lowering - virtual GdkWindow* GetLayeringWindow(); - - virtual void DispatchSetFocusEvent(void); - virtual void DispatchLostFocusEvent(void); - virtual void DispatchActivateEvent(void); - virtual void DispatchDeactivateEvent(void); - - PRBool mBlockMozAreaFocusIn; - - void HandleMozAreaFocusIn(void); - void HandleMozAreaFocusOut(void); - - // Window icon cache - static PRBool IconEntryMatches(PLDHashTable* aTable, - const PLDHashEntryHdr* aHdr, - const void* aKey); - static void ClearIconEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr); - -protected: - virtual void ResetInternalVisibility(); - virtual void SetInternalVisibility(PRBool aVisible); - - virtual void OnRealize(GtkWidget *aWidget); - - virtual void OnDestroySignal(GtkWidget* aGtkWidget); - - ////////////////////////////////////////////////////////////////////// - - virtual void InitCallbacks(char * aName = nsnull); - NS_IMETHOD CreateNative(GtkObject *parentWidget); - - PRBool mIsTooSmall; - - GtkWidget *mShell; /* used for toplevel windows */ - GdkSuperWin *mSuperWin; - GtkWidget *mMozArea; - GtkWidget *mMozAreaClosestParent; - - PRBool GetWindowPos(nscoord &x, nscoord &y); - nscoord mCachedX, mCachedY; - - // are we doing a grab? - static PRBool sIsGrabbing; - static nsWindow *sGrabWindow; - static PRBool sIsDraggingOutOf; - - // our wonderful hash table with our window -> nsWindow * lookup - static GHashTable *mWindowLookupTable; - - // this will query all of it's children trying to find a child - // that has a containing rectangle and return it. - static Window GetInnerMostWindow(Window aOriginWindow, - Window aWindow, - nscoord x, nscoord y, - nscoord *retx, nscoord *rety, - int depth); - // given an X window this will find the nsWindow * for it. - static nsWindow *GetnsWindowFromXWindow(Window aWindow); - - static gint ClientEventSignal(GtkWidget* widget, GdkEventClient* event, void* data); - virtual void ThemeChanged(); - - // all of our DND stuff - - // this is the last window that had a drag event happen on it. - static nsWindow *mLastDragMotionWindow; - static GdkCursor *gsGtkCursorCache[eCursorCount]; - - void InitDragEvent(nsMouseEvent &aEvent); - void UpdateDragStatus(nsMouseEvent &aEvent, - GdkDragContext *aDragContext, - nsIDragService *aDragService); - - // DragBegin not needed ? - // always returns TRUE - static gint DragMotionSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData); - gint OnDragMotionSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData); - - static void DragLeaveSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - guint aTime, - gpointer aData); - void OnDragLeaveSignal (GtkWidget * aWidget, - GdkDragContext *aDragContext, - guint aTime, - gpointer aData); - - // always returns TRUE - static gint DragDropSignal (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData); - gint OnDragDropSignal (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime, - void *aData); - // when the data has been received - static void DragDataReceived (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime, - gpointer aData); - void OnDragDataReceived (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - GtkSelectionData *aSelectionData, - guint aInfo, - guint32 aTime, - gpointer aData); - - // these are drag and drop events that aren't generated by widget - // events but we do synthesize - - void OnDragLeave(void); - void OnDragEnter(nscoord aX, nscoord aY); - - // this is everything we need to be able to fire motion events - // repeatedly - GtkWidget *mDragMotionWidget; - GdkDragContext *mDragMotionContext; - gint mDragMotionX; - gint mDragMotionY; - guint mDragMotionTime; - guint mDragMotionTimerID; - nsCOMPtr mDragLeaveTimer; - - void ResetDragMotionTimer (GtkWidget *aWidget, - GdkDragContext *aDragContext, - gint aX, - gint aY, - guint aTime); - void FireDragMotionTimer (void); - void FireDragLeaveTimer (void); - static guint DragMotionTimerCallback (gpointer aClosure); - static void DragLeaveTimerCallback (nsITimer *aTimer, void *aClosure); - - // Hash table for icon spec -> icon set lookup - static PLDHashTable* sIconCache; - -#ifdef USE_XIM -protected: - static GdkFont *gPreeditFontset; - static GdkFont *gStatusFontset; - static GdkIMStyle gInputStyle; - static PLDHashTable gXICLookupTable; - PRPackedBool mIMEEnable; - PRPackedBool mIMECallComposeStart; - PRPackedBool mIMECallComposeEnd; - PRPackedBool mIMEIsBeingActivate; - nsWindow* mIMEShellWindow; - void SetXICSpotLocation(nsIMEGtkIC* aXIC, nsPoint aPoint); - void SetXICBaseFontSize(nsIMEGtkIC* aXIC, int height); - nsCOMPtr mICSpotTimer; - static void ICSpotCallback(nsITimer* aTimer, void* aClosure); - nsresult KillICSpotTimer(); - nsresult PrimeICSpotTimer(); - nsresult UpdateICSpot(nsIMEGtkIC* aXIC); - int mXICFontSize; - -public: - nsIMEGtkIC* IMEGetInputContext(PRBool aCreate); - - void ime_preedit_start(); - void ime_preedit_draw(nsIMEGtkIC* aXIC); - void ime_preedit_done(); - void ime_status_draw(); - - void IMEUnsetFocusWindow(); - void IMESetFocusWindow(); - void IMEGetShellWindow(); - void IMEDestroyIC(); - void IMEBeingActivate(PRBool aActive); -#endif // USE_XIM - -protected: - void IMEComposeStart(guint aTime); - void IMEComposeText(GdkEventKey*, - const PRUnichar *aText, - const PRInt32 aLen, - const char *aFeedback); - void IMEComposeEnd(guint aTime); - -public: - virtual void IMECommitEvent(GdkEventKey *aEvent); - -private: - PRUnichar* mIMECompositionUniString; - PRInt32 mIMECompositionUniStringSize; - - nsresult SetMiniIcon(GdkPixmap *window_pixmap, - GdkBitmap *window_mask); - nsresult SetIcon(GdkPixmap *window_pixmap, - GdkBitmap *window_mask); - - void NativeGrab(PRBool aGrab); - - PRPackedBool mLastGrabFailed; - PRPackedBool mIsUpdating; - PRPackedBool mLeavePending; - PRPackedBool mRestoreFocus; - - /** - * Whether this widget has child widgets that are not linked into - * its explicit nsIWidget child list - */ - PRPackedBool mHasAnonymousChildren; - PRPackedBool mIsTranslucent; - - // This bitmap tracks which pixels are transparent. We don't support - // full translucency at this time; each pixel is either fully opaque - // or fully transparent. - gchar* mTransparencyBitmap; - - void DestroyNativeChildren(void); - - GtkWindow *mTransientParent; -}; - -// -// A child window is a window with different style -// -class ChildWindow : public nsWindow { -public: - ChildWindow(); - ~ChildWindow(); -}; - -#endif // Window_h__ diff --git a/mozilla/widget/src/gtk/widget_gtk.pkg b/mozilla/widget/src/gtk/widget_gtk.pkg deleted file mode 100644 index 6da7569affc..00000000000 --- a/mozilla/widget/src/gtk/widget_gtk.pkg +++ /dev/null @@ -1,10 +0,0 @@ -[gecko] -#if SHARED_LIBRARY -dist/bin/components/@SHARED_LIBRARY@ -#else -!staticcomp @LIBRARY@ @MODULE_NAME@ -#endif - -[xpfe-browser] -dist/bin/icons/mozicon50.xpm -dist/bin/icons/mozicon16.xpm diff --git a/mozilla/widget/src/gtksuperwin/Makefile.in b/mozilla/widget/src/gtksuperwin/Makefile.in deleted file mode 100644 index 4b0a3ee8fa9..00000000000 --- a/mozilla/widget/src/gtksuperwin/Makefile.in +++ /dev/null @@ -1,79 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org Code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = widget -LIBRARY_NAME = gtksuperwin -EXPORT_LIBRARY = 1 -LIBXUL_LIBRARY = 1 - -PACKAGE_FILE = gtksuperwin.pkg - -CSRCS = \ - gdksuperwin.c \ - gtkmozarea.c \ - gtkmozbox.c - - -EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS) - -EXPORTS = gdksuperwin.h \ - gtkmozarea.h \ - gtkmozbox.h - -REQUIRES = xpcom - -include $(topsrcdir)/config/rules.mk - -CFLAGS += $(MOZ_GTK_CFLAGS) - -DEFINES += -D_IMPL_GTKSUPERWIN_API -DUSE_XIM - -ifeq ($(OS_ARCH), OpenVMS) -DEFINES += -DGENERIC_MOTIF_REDEFINES -endif - -INCLUDES += \ - -I$(srcdir) \ - $(NULL) - diff --git a/mozilla/widget/src/gtksuperwin/gdksuperwin.c b/mozilla/widget/src/gtksuperwin/gdksuperwin.c deleted file mode 100644 index fd77d4b85e7..00000000000 --- a/mozilla/widget/src/gtksuperwin/gdksuperwin.c +++ /dev/null @@ -1,729 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Owen Taylor and Christopher Blizzard . - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "gdksuperwin.h" - -static void gdk_superwin_class_init(GdkSuperWinClass *klass); -static void gdk_superwin_init(GdkSuperWin *superwin); -static void gdk_superwin_expose_area (GdkSuperWin *superwin, - gint x, - gint y, - gint width, - gint height); -static void gdk_superwin_flush(GdkSuperWin *superwin); -static void gdk_superwin_destroy(GtkObject *object); - -static void gdk_superwin_add_translation(GdkSuperWin *superwin, unsigned long serial, - gint dx, gint dy); -static void gdk_superwin_add_antiexpose (GdkSuperWin *superwin, unsigned long serial, - gint x, gint y, - gint width, gint height); - -static void gdk_superwin_handle_expose (GdkSuperWin *superwin, XEvent *xevent, - GdkRegion **region, gboolean dont_recurse); - -static Bool gdk_superwin_expose_predicate(Display *display, - XEvent *xevent, - XPointer arg); - -typedef struct _GdkSuperWinTranslate GdkSuperWinTranslate; - -enum { - GDK_SUPERWIN_TRANSLATION = 1, - GDK_SUPERWIN_ANTIEXPOSE -}; - - -struct _GdkSuperWinTranslate -{ - int type; - unsigned long serial; - union { - struct { - gint dx; - gint dy; - } translation; - struct { - GdkRectangle rect; - } antiexpose; - } data; -}; - -GtkType -gdk_superwin_get_type(void) -{ - static GtkType superwin_type = 0; - - if (!superwin_type) - { - static const GtkTypeInfo superwin_info = - { - "GtkSuperWin", - sizeof(GdkSuperWin), - sizeof(GdkSuperWinClass), - (GtkClassInitFunc) gdk_superwin_class_init, - (GtkObjectInitFunc) gdk_superwin_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL - }; - - superwin_type = gtk_type_unique (gtk_object_get_type(), &superwin_info); - } - return superwin_type; -} - -static void -gdk_superwin_class_init(GdkSuperWinClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - object_class->destroy = gdk_superwin_destroy; - -} - -static void -gdk_superwin_init(GdkSuperWin *superwin) -{ - -} - -static GdkFilterReturn gdk_superwin_bin_filter (GdkXEvent *gdk_xevent, - GdkEvent *event, - gpointer data); -static GdkFilterReturn gdk_superwin_shell_filter (GdkXEvent *gdk_xevent, - GdkEvent *event, - gpointer data); - -static gboolean gravity_works; - -GdkSuperWin * -gdk_superwin_new (GdkWindow *parent_window, - guint x, - guint y, - guint width, - guint height) -{ - GdkWindowAttr attributes; - gint attributes_mask; - Window bin_xwindow; - Display *xdisplay; - XSetWindowAttributes xattr; - unsigned long xattr_mask; - - GdkSuperWin *superwin = gtk_type_new(GDK_TYPE_SUPERWIN); - - superwin->translate_queue = NULL; - - superwin->shell_func = NULL; - superwin->paint_func = NULL; - superwin->flush_func = NULL; - superwin->func_data = NULL; - superwin->notify = NULL; - - /* Create the shell (clipping) window */ - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = x; - attributes.y = y; - attributes.width = width; - attributes.height = height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.colormap = gdk_rgb_get_cmap(); - attributes.visual = gdk_rgb_get_visual(); - attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; - - attributes_mask = GDK_WA_VISUAL | GDK_WA_X | GDK_WA_Y | GDK_WA_COLORMAP; - - superwin->shell_window = gdk_window_new (parent_window, - &attributes, attributes_mask); - - /* set the back pixmap to None so that you don't end up with the gtk - default which is BlackPixel */ - gdk_window_set_back_pixmap (superwin->shell_window, NULL, FALSE); - - /* if we failed to create a window, die a horrible death */ - g_assert((superwin->shell_window)); - - /* Create the bin window for drawing */ - - attributes.x = 0; - attributes.y = 0; - attributes.event_mask = GDK_EXPOSURE_MASK; - - superwin->bin_window = gdk_window_new (superwin->shell_window, - &attributes, attributes_mask); - - /* set the back pixmap to None so that you don't end up with the gtk - default which is BlackPixel */ - gdk_window_set_back_pixmap (superwin->bin_window, NULL, FALSE); - - /* set the backing store for the bin window */ - bin_xwindow = GDK_WINDOW_XWINDOW(superwin->bin_window); - xdisplay = GDK_WINDOW_XDISPLAY(superwin->bin_window); - /* XXX should we make this Always? */ - xattr.backing_store = WhenMapped; - xattr_mask = CWBackingStore; - /* XChangeWindowAttributes(xdisplay, bin_xwindow, xattr_mask, &xattr); */ - - gdk_window_show (superwin->bin_window); - - gdk_window_add_filter (superwin->shell_window, gdk_superwin_shell_filter, superwin); - gdk_window_add_filter (superwin->bin_window, gdk_superwin_bin_filter, superwin); - - gravity_works = gdk_window_set_static_gravities (superwin->bin_window, TRUE); - - return superwin; -} - -/* XXX this should really be part of the object... */ -/* XXX and it should chain up to the object's destructor */ - -void gdk_superwin_destroy(GtkObject *object) -{ - - GdkSuperWin *superwin = NULL; - - g_return_if_fail(object != NULL); - g_return_if_fail(GTK_IS_OBJECT(object)); - g_return_if_fail(GTK_OBJECT_CONSTRUCTED(object)); - g_return_if_fail(GDK_IS_SUPERWIN(object)); - - superwin = GDK_SUPERWIN(object); - - gdk_window_remove_filter(superwin->shell_window, - gdk_superwin_shell_filter, - superwin); - gdk_window_remove_filter(superwin->bin_window, - gdk_superwin_bin_filter, - superwin); - gdk_window_destroy(superwin->bin_window); - gdk_window_destroy(superwin->shell_window); - - if (superwin->translate_queue) { - GSList *tmp_list = superwin->translate_queue; - while (tmp_list) { - g_free(tmp_list->data); - tmp_list = tmp_list->next; - } - g_slist_free(superwin->translate_queue); - } -} - -void gdk_superwin_reparent(GdkSuperWin *superwin, - GdkWindow *parent_window) -{ - gdk_window_reparent(superwin->shell_window, - parent_window, 0, 0); -} - -void -gdk_superwin_scroll (GdkSuperWin *superwin, - gint dx, - gint dy) -{ - gint width, height; - - gint first_resize_x = 0; - gint first_resize_y = 0; - gint first_resize_width = 0; - gint first_resize_height = 0; - - unsigned long first_resize_serial = 0; - unsigned long move_serial = 0; - unsigned long last_resize_serial = 0; - gint move_x = 0; - gint move_y = 0; - - /* get the current dimensions of the window */ - gdk_window_get_size (superwin->shell_window, &width, &height); - - /* calculate the first resize. */ - - /* for the first move resize, the width + height default to the - width and height of the window. */ - first_resize_width = width; - first_resize_height = height; - - /* if scrolling left ( dx < 0 ) need to extend window right by - ABS(dx) and left side of window won't move. */ - if (dx < 0) { - /* left side of the window doesn't move. */ - first_resize_x = 0; - /* right side of window will be the width + the offset of the - scroll */ - first_resize_width = width + ABS(dx); - } - - /* if scrolling right ( dx > 0 ) need to extend window left by - ABS(dx) and right side of the window doesn't move */ - if (dx > 0) { - /* left side of the window will be offset to the left by ABS(dx) ( - x will be < 0 ) */ - first_resize_x = -dx; - /* right side of the window won't move. We have to add the offset - to the width so that it doesn't. */ - first_resize_width = width + dx; - } - - /* if scrolling down ( dy < 0 ) need to extend window down by - ABS(dy) and top of window won't move */ - if (dy < 0) { - /* top of window not moving */ - first_resize_y = 0; - /* bottom of window will be the height + the offset of the scroll */ - first_resize_height = height + ABS(dy); - } - - /* if scrolling up ( dy > 0 ) need to extend window up by ABS(dy) - and bottom of window won't move. */ - if (dy > 0) { - /* top of the window will be moved up by ABS(dy) ( y will be < 0 ) */ - first_resize_y = -dy; - /* this will cause the bottom of the window not to move since - we're moving y by the offset up. */ - first_resize_height = height + dy; - } - - /* calculate our move offsets */ - - /* if scrolling left ( dx < 0 ) we need to move the window left by - ABS(dx) */ - if (dx < 0) { - /* dx will be negative - this will move it left */ - move_x = dx; - } - - /* if scrolling right ( dx > 0 ) we need to move the window right by - ABS(dx). Because we already resized the window to -dx by moving - it to zero we are actually moving the window to the right. */ - if (dx > 0) { - move_x = 0; - } - - /* If scrolling down ( dy < 0 ) we need to move the window up by - ABS(dy) */ - if (dy < 0) { - /* dy will be negative - this will move it up */ - move_y = dy; - } - - /* If scrolling up ( dy > 0 ) we need to move the window down by - ABS(dy). In this case we already resized the top of the window - to -dy so by moving it to zero we are actually moving the window - down. */ - if (dy > 0) { - move_y = 0; - } - - /* save the serial of the first request */ - first_resize_serial = NextRequest(GDK_DISPLAY()); - - /* move our window */ - gdk_window_move_resize(superwin->bin_window, - first_resize_x, first_resize_y, - first_resize_width, first_resize_height); - - /* window move - this move will cause all of the exposes to happen - and is where all the translation magic has to be applied. we - need to save the serial of this operation since any expose events - with serial request numbers lower than it will have to have their - coordinates translated into the new coordinate system. */ - - move_serial = NextRequest(GDK_DISPLAY()); - - gdk_window_move(superwin->bin_window, - move_x, move_y); - - /* last resize. This will resize the window to its original - position. */ - - /* save the request of the last resize */ - last_resize_serial = NextRequest(GDK_DISPLAY()); - - gdk_window_move_resize(superwin->bin_window, - 0, 0, width, height); - - /* now that we have moved everything, repaint the damaged areas */ - - /* if scrolling left ( dx < 0 ) moving window left so expose area at - the right of the window. Clip the width of the exposure to the - width of the window or the offset, whichever is smaller. Also - clip the start to the origin ( 0 ) if the width minus the - absolute value of the offset is < 0 to handle > 1 page - scrolls. */ - if (dx < 0) { - gdk_superwin_expose_area(superwin, MAX(0, width - ABS(dx)), 0, - MIN(width, ABS(dx)), height); - /* If we've exposed this area add an antiexpose for it. When the - window was moved left the expose will be offset by ABS(dx). - For greated than one page scrolls, the expose will be offset by - the actual offset of the move, hence the MAX(height, - ABS(dy)). */ - gdk_superwin_add_antiexpose(superwin, move_serial, - MAX(width, ABS(dx)), - 0, MIN(width, ABS(dx)), height); - } - - /* if scrolling right ( dx > 0 ) moving window right so expose area - at the left of the window. Clip the width of the exposure to the - width of the window or the offset, whichever is smaller. */ - if (dx > 0) { - gdk_superwin_expose_area(superwin, 0, 0, - MIN(width, ABS(dx)), height); - /* If we've exposed this area add an antiexpose for it. */ - gdk_superwin_add_antiexpose(superwin, move_serial, - 0, 0, MIN(width, ABS(dx)), height); - } - - /* if scrolling down ( dy < 0 ) moving window up so expose area at - the bottom of the window. Clip the exposed area to the height of - the window or the offset, whichever is smaller. Also clip the - start to the origin ( 0 ) if the the height minus the absolute - value of the offset is < 0 to handle > 1 page scrolls. */ - - if (dy < 0) { - gdk_superwin_expose_area(superwin, 0, MAX(0, height - ABS(dy)), - width, MIN(height, ABS(dy))); - /* If we've exposed this area add an antiexpose for it. When the - was moved up before the second move the expose will be offset - by ABS(dy). For greater than one page scrolls, the expose will - be offset by actual offset of the move, hence the MAX(height, - ABS(dy)). */ - gdk_superwin_add_antiexpose(superwin, move_serial, - 0, - MAX(height, ABS(dy)), - width, MIN(height, ABS(dy))); - } - - /* if scrolling up ( dy > 0 ) moving window down so expose area at - the top of the window. Clip the exposed area to the height or - the offset, whichever is smaller. */ - if (dy > 0) { - gdk_superwin_expose_area(superwin, 0, 0, - width, MIN(height, ABS(dy))); - /* if we've exposed this area add an antiexpose for it. */ - gdk_superwin_add_antiexpose(superwin, move_serial, - 0, 0, width, MIN(height, ABS(dy))); - } - - /* if we are scrolling right or down ( dx > 0 or dy > 0 ) we need to - add our translation before the fist move_resize. Once we do this - all previous expose events will be translated into the new - coordinate space */ - if (dx > 0 || dy > 0) { - gdk_superwin_add_translation(superwin, first_resize_serial, - MAX(0, dx), MAX(0, dy)); - } - - /* If we are scrolling left or down ( x < 0 or y < 0 ) we need to - add our translation before the last move_resize. Once we do this - all previous expose events will be translated in the new - coordinate space. */ - if (dx < 0 || dy < 0) { - gdk_superwin_add_translation(superwin, last_resize_serial, - MIN(0, dx), MIN(0, dy)); - } - - /* sync so we get the windows moved now */ - XSync(GDK_DISPLAY(), False); -} - -void -gdk_superwin_set_event_funcs (GdkSuperWin *superwin, - GdkSuperWinFunc shell_func, - GdkSuperWinPaintFunc paint_func, - GdkSuperWinPaintFlushFunc flush_func, - GdkSuperWinKeyPressFunc keyprs_func, - GdkSuperWinKeyReleaseFunc keyrel_func, - gpointer func_data, - GDestroyNotify notify) -{ - if (superwin->notify && superwin->func_data) - superwin->notify (superwin->func_data); - - superwin->shell_func = shell_func; - superwin->paint_func = paint_func; - superwin->flush_func = flush_func; - superwin->keyprs_func = keyprs_func; - superwin->keyrel_func = keyrel_func; - superwin->func_data = func_data; - superwin->notify = notify; - -} - -void gdk_superwin_resize (GdkSuperWin *superwin, - gint width, - gint height) -{ - gdk_window_resize (superwin->bin_window, width, height); - gdk_window_resize (superwin->shell_window, width, height); -} - -static void -gdk_superwin_expose_area (GdkSuperWin *superwin, - gint x, - gint y, - gint width, - gint height) -{ - if (superwin->paint_func) - superwin->paint_func(x, y, width, height, superwin->func_data); -} - -static void -gdk_superwin_flush(GdkSuperWin *superwin) -{ - if (superwin->flush_func) - superwin->flush_func(superwin->func_data); -} - -static GdkFilterReturn -gdk_superwin_bin_filter (GdkXEvent *gdk_xevent, - GdkEvent *event, - gpointer data) -{ - XEvent *xevent = (XEvent *)gdk_xevent; - GdkSuperWin *superwin = data; - GdkFilterReturn retval = GDK_FILTER_CONTINUE; - GdkRegion *region = NULL; - - switch (xevent->xany.type) { - case Expose: - region = gdk_region_new(); - retval = GDK_FILTER_REMOVE; - gdk_superwin_handle_expose(superwin, xevent, ®ion, FALSE); - gdk_region_destroy(region); - break; - case KeyPress: - if (superwin->keyprs_func) - superwin->keyprs_func(&xevent->xkey); - break; - case KeyRelease: - if (superwin->keyrel_func) - superwin->keyrel_func(&xevent->xkey); - break; - default: - break; - } - return retval; -} - - -static GdkFilterReturn -gdk_superwin_shell_filter (GdkXEvent *gdk_xevent, - GdkEvent *event, - gpointer data) -{ - XEvent *xevent = (XEvent *)gdk_xevent; - GdkSuperWin *superwin = data; - - if (xevent->type == VisibilityNotify) - { - switch (xevent->xvisibility.state) - { - case VisibilityFullyObscured: - superwin->visibility = GDK_VISIBILITY_FULLY_OBSCURED; - break; - - case VisibilityPartiallyObscured: - superwin->visibility = GDK_VISIBILITY_PARTIAL; - break; - - case VisibilityUnobscured: - superwin->visibility = GDK_VISIBILITY_UNOBSCURED; - break; - } - - return GDK_FILTER_REMOVE; - } - - if (superwin->shell_func) { - superwin->shell_func (superwin, xevent, superwin->func_data); - } - return GDK_FILTER_CONTINUE; -} - -/* this function is used to check whether or not a particular event is - for a specific superwin and is a ConfigureNotify or Expose - event. */ - -Bool gdk_superwin_expose_predicate(Display *display, - XEvent *xevent, - XPointer arg) { - GdkSuperWin *superwin = (GdkSuperWin *)arg; - if (xevent->xany.window != GDK_WINDOW_XWINDOW(superwin->bin_window)) - return False; - switch (xevent->xany.type) { - case Expose: - return True; - break; - default: - return False; - break; - } -} - -/* static */ -void gdk_superwin_add_translation(GdkSuperWin *superwin, unsigned long serial, - gint dx, gint dy) -{ - GdkSuperWinTranslate *translate = g_new(GdkSuperWinTranslate, 1); - translate->type = GDK_SUPERWIN_TRANSLATION; - translate->serial = serial; - translate->data.translation.dx = dx; - translate->data.translation.dy = dy; - superwin->translate_queue = g_slist_append(superwin->translate_queue, translate); -} - -/* static */ -void gdk_superwin_add_antiexpose (GdkSuperWin *superwin, unsigned long serial, - gint x, gint y, - gint width, gint height) - -{ - GdkSuperWinTranslate *translate = g_new(GdkSuperWinTranslate, 1); - translate->type = GDK_SUPERWIN_ANTIEXPOSE; - translate->serial = serial; - translate->data.antiexpose.rect.x = x; - translate->data.antiexpose.rect.y = y; - translate->data.antiexpose.rect.width = width; - translate->data.antiexpose.rect.height = height; - superwin->translate_queue = g_slist_append(superwin->translate_queue, translate); -} - -/* static */ -void gdk_superwin_handle_expose (GdkSuperWin *superwin, XEvent *xevent, - GdkRegion **region, gboolean dont_recurse) -{ - GSList *tmp_list; - gboolean send_event = TRUE; - unsigned long serial = xevent->xany.serial; - XEvent extra_event; - GdkRectangle rect; - GdkRegion *tmp_region = NULL; - gboolean is_special = TRUE; - - /* set up our rect for the damaged area */ - rect.x = xevent->xexpose.x; - rect.y = xevent->xexpose.y; - rect.width = xevent->xexpose.width; - rect.height = xevent->xexpose.height; - - /* try to see if this is a special event that matches an antiexpose */ - tmp_list = superwin->translate_queue; - while (tmp_list) { - GdkSuperWinTranslate *xlate = tmp_list->data; - if (xlate->type == GDK_SUPERWIN_ANTIEXPOSE && serial == xlate->serial) { - GdkRegion *antiexpose_region = gdk_region_new(); - tmp_region = gdk_region_union_with_rect(antiexpose_region, - &xlate->data.antiexpose.rect); - gdk_region_destroy(antiexpose_region); - antiexpose_region = tmp_region; - /* if the rect of the expose event is contained in the - antiexpose then we should just drop it on the floor. */ - if (gdk_region_rect_in(antiexpose_region, &rect) == GDK_OVERLAP_RECTANGLE_IN) { - gdk_region_destroy(antiexpose_region); - goto end; - } - gdk_region_destroy(antiexpose_region); - - } - tmp_list = tmp_list->next; - } - - /* we walk the list looking for any transformations */ - tmp_list = superwin->translate_queue; - while (tmp_list) { - GdkSuperWinTranslate *xlate = tmp_list->data; - /* apply translations to this event if we can. */ - if (xlate->type == GDK_SUPERWIN_TRANSLATION && serial < xlate->serial ) { - rect.x += xlate->data.translation.dx; - rect.y += xlate->data.translation.dy; - } - tmp_list = tmp_list->next; - } - - /* add this expose area to our damaged rect */ - - tmp_region = gdk_region_union_with_rect(*region, &rect); - gdk_region_destroy(*region); - *region = tmp_region; - - end: - - /* remove any events from the queue that are old */ - tmp_list = superwin->translate_queue; - while (tmp_list) { - GdkSuperWinTranslate *xlate = tmp_list->data; - if (serial > xlate->serial) { - GSList *tmp_link = tmp_list; - tmp_list = tmp_list->next; - superwin->translate_queue = g_slist_remove_link(superwin->translate_queue, - tmp_link); - g_free(tmp_link->data); - g_slist_free_1(tmp_link); - } - else { - tmp_list = tmp_list->next; - } - } - - /* if we're not supposed to recurse or paint then return now */ - if (dont_recurse) - return; - - /* try to do any expose event compression we can */ - while (XCheckTypedWindowEvent(xevent->xany.display, - xevent->xany.window, - Expose, - &extra_event) == True) { - gdk_superwin_handle_expose(superwin, &extra_event, region, TRUE); - } - - /* if the region isn't empty, send the paint event */ - if (gdk_region_empty(*region) == FALSE) { - GdkRectangle clip_box; - gdk_region_get_clipbox(*region, &clip_box); - if (superwin->paint_func) - superwin->paint_func(clip_box.x, clip_box.y, - clip_box.width, clip_box.height, - superwin->func_data); - } - -} diff --git a/mozilla/widget/src/gtksuperwin/gdksuperwin.h b/mozilla/widget/src/gtksuperwin/gdksuperwin.h deleted file mode 100644 index d5c54a30242..00000000000 --- a/mozilla/widget/src/gtksuperwin/gdksuperwin.h +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Owen Taylor and Christopher Blizzard - * . - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __GDK_SUPERWIN_H__ -#define __GDK_SUPERWIN_H__ - -#include -#include -#include -#ifdef MOZILLA_CLIENT -#include "nscore.h" -#ifdef _IMPL_GTKSUPERWIN_API -#define GTKSUPERWIN_API(type) NS_EXPORT_(type) -#else -#define GTKSUPERWIN_API(type) NS_IMPORT_(type) -#endif -#else -#define GTKSUPERWIN_API(type) type -#endif - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct _GdkSuperWin GdkSuperWin; -typedef struct _GdkSuperWinClass GdkSuperWinClass; - -#define GDK_TYPE_SUPERWIN (gdk_superwin_get_type()) -#define GDK_SUPERWIN(obj) (GTK_CHECK_CAST((obj), GDK_TYPE_SUPERWIN, GdkSuperWin)) -#define GDK_SUPERWIN_CLASS(klass) (GTK_CHECK_CLASS_CAST((klass), GDK_TYPE_SUPERWIN, GdkSuperWinClass)) -#define GDK_IS_SUPERWIN(obj) (GTK_CHECK_TYPE((obj), GDK_TYPE_SUPERWIN)) -#define GDK_IS_SUPERWIN_CLASS(klass) (GTK_CHECK_CLASS_TYPE((klass), GDK_TYPE_SUPERWIN)) - -typedef void (*GdkSuperWinFunc) (GdkSuperWin *super_win, - XEvent *event, - gpointer data); - -typedef void (*GdkSuperWinPaintFunc) (gint x, gint y, - gint width, gint height, - gpointer data); -typedef void (*GdkSuperWinPaintFlushFunc) (gpointer data); - -typedef void (*GdkSuperWinKeyPressFunc) (XKeyEvent *event); -typedef void (*GdkSuperWinKeyReleaseFunc) (XKeyEvent *event); - -struct _GdkSuperWin -{ - GtkObject object; - GdkWindow *shell_window; - GdkWindow *bin_window; - - /* Private */ - GSList *translate_queue; - GdkSuperWinFunc shell_func; - GdkSuperWinPaintFunc paint_func; - GdkSuperWinPaintFlushFunc flush_func; - GdkSuperWinKeyPressFunc keyprs_func; - GdkSuperWinKeyReleaseFunc keyrel_func; - gpointer func_data; - GDestroyNotify notify; - - GdkVisibilityState visibility; -}; - -struct _GdkSuperWinClass -{ - GtkObjectClass object_class; -}; - -GTKSUPERWIN_API(GtkType) gdk_superwin_get_type(void); - -GTKSUPERWIN_API(GdkSuperWin*) gdk_superwin_new (GdkWindow *parent_window, - guint x, - guint y, - guint width, - guint height); - -GTKSUPERWIN_API(void) gdk_superwin_reparent(GdkSuperWin *superwin, - GdkWindow *parent_window); - -GTKSUPERWIN_API(void) -gdk_superwin_set_event_funcs (GdkSuperWin *superwin, - GdkSuperWinFunc shell_func, - GdkSuperWinPaintFunc paint_func, - GdkSuperWinPaintFlushFunc flush_func, - GdkSuperWinKeyPressFunc keyprs_func, - GdkSuperWinKeyReleaseFunc keyrel_func, - gpointer func_data, - GDestroyNotify notify); - -GTKSUPERWIN_API(void) gdk_superwin_scroll (GdkSuperWin *superwin, - gint dx, - gint dy); -GTKSUPERWIN_API(void) gdk_superwin_resize (GdkSuperWin *superwin, - gint width, - gint height); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _GDK_SUPERWIN_H__ */ - diff --git a/mozilla/widget/src/gtksuperwin/gtkmozarea.c b/mozilla/widget/src/gtksuperwin/gtkmozarea.c deleted file mode 100644 index ce5aab04a32..00000000000 --- a/mozilla/widget/src/gtksuperwin/gtkmozarea.c +++ /dev/null @@ -1,414 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Owen Taylor and Christopher Blizzard - * . - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "gtkmozarea.h" -#include -#include - -static void gtk_mozarea_class_init (GtkMozAreaClass *klass); -static void gtk_mozarea_init (GtkMozArea *mozarea); -static void gtk_mozarea_realize (GtkWidget *widget); -static void gtk_mozarea_unrealize (GtkWidget *widget); -static void gtk_mozarea_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void gtk_mozarea_destroy (GtkObject *object); - -static void -attach_toplevel_listener(GtkMozArea *mozarea); - -static void -remove_toplevel_listener(GtkMozArea *mozarea); - -static Window -get_real_toplevel(Window aWindow); - -static GdkWindow * -get_real_gdk_toplevel(GtkMozArea *mozarea); - -static GdkFilterReturn -toplevel_window_filter(GdkXEvent *aGdkXEvent, - GdkEvent *aEvent, - gpointer data); - -static GdkFilterReturn -widget_window_filter(GdkXEvent *aGdkXEvent, - GdkEvent *aEvent, - gpointer data); - -GtkWidgetClass *parent_class = NULL; - -enum { - TOPLEVEL_FOCUS_IN, - TOPLEVEL_FOCUS_OUT, - TOPLEVEL_CONFIGURE, - LAST_SIGNAL -}; - -static guint mozarea_signals[LAST_SIGNAL] = { 0 }; - -GtkType -gtk_mozarea_get_type (void) -{ - static GtkType mozarea_type = 0; - - if (!mozarea_type) - { - static const GtkTypeInfo mozarea_info = - { - "GtkMozArea", - sizeof (GtkMozArea), - sizeof (GtkMozAreaClass), - (GtkClassInitFunc) gtk_mozarea_class_init, - (GtkObjectInitFunc) gtk_mozarea_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL - }; - - mozarea_type = gtk_type_unique (GTK_TYPE_WIDGET, &mozarea_info); - } - - return mozarea_type; -} - -static void -gtk_mozarea_class_init (GtkMozAreaClass *klass) -{ - GtkWidgetClass *widget_class; - GtkObjectClass *object_class; - - widget_class = GTK_WIDGET_CLASS (klass); - object_class = GTK_OBJECT_CLASS (klass); - - widget_class->realize = gtk_mozarea_realize; - widget_class->unrealize = gtk_mozarea_unrealize; - widget_class->size_allocate = gtk_mozarea_size_allocate; - - object_class->destroy = gtk_mozarea_destroy; - - parent_class = gtk_type_class(gtk_widget_get_type()); - - /* set up our signals */ - - mozarea_signals[TOPLEVEL_FOCUS_IN] = - gtk_signal_new("toplevel_focus_in", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET(GtkMozAreaClass, toplevel_focus_in), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - mozarea_signals[TOPLEVEL_FOCUS_OUT] = - gtk_signal_new("toplevel_focus_out", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET(GtkMozAreaClass, toplevel_focus_out), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - mozarea_signals[TOPLEVEL_CONFIGURE] = - gtk_signal_new("toplevel_configure", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET(GtkMozAreaClass, toplevel_configure), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - gtk_object_class_add_signals(object_class, mozarea_signals, LAST_SIGNAL); - -} - -static void -gtk_mozarea_init (GtkMozArea *mozarea) -{ - mozarea->superwin = NULL; - mozarea->toplevel_focus = FALSE; - mozarea->toplevel_window = NULL; - gtk_widget_set_name(GTK_WIDGET(mozarea), "gtkmozarea"); -} - -static void -gtk_mozarea_realize (GtkWidget *widget) -{ - GtkMozArea *mozarea; - - g_return_if_fail (GTK_IS_MOZAREA (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - mozarea = GTK_MOZAREA (widget); - - mozarea->superwin = gdk_superwin_new (gtk_widget_get_parent_window (widget), - widget->allocation.x, - widget->allocation.y, - widget->allocation.width, - widget->allocation.height); - gdk_window_set_user_data (mozarea->superwin->shell_window, mozarea); - widget->window = mozarea->superwin->shell_window; - widget->style = gtk_style_attach (widget->style, widget->window); - /* make sure that we add a reference to this window. - if we don't then it will be destroyed by both the superwin - destroy method and the widget class destructor */ - gdk_window_ref(widget->window); - - /* attach the toplevel X listener */ - attach_toplevel_listener(mozarea); - - /* Attach a filter so that we can get reparent notifications so we - can reset our toplevel window. This will automatically be - removed when our window is destroyed. */ - gdk_window_add_filter(widget->window, widget_window_filter, mozarea); -} - -static void -gtk_mozarea_unrealize(GtkWidget *widget) -{ - GtkMozArea *mozarea; - - g_return_if_fail(GTK_IS_MOZAREA(widget)); - - GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED); - - mozarea = GTK_MOZAREA(widget); - - if (mozarea->superwin) { - gtk_object_unref(GTK_OBJECT(mozarea->superwin)); - mozarea->superwin = NULL; - } - GTK_WIDGET_CLASS(parent_class)->unrealize(widget); -} - -static void -gtk_mozarea_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - GtkMozArea *mozarea; - - g_return_if_fail (GTK_IS_MOZAREA (widget)); - - mozarea = GTK_MOZAREA (widget); - - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move (mozarea->superwin->shell_window, - allocation->x, allocation->y); - gdk_superwin_resize (mozarea->superwin, - allocation->width, allocation->height); - } -} - -static void -gtk_mozarea_destroy(GtkObject *object) -{ - GtkMozArea *mozarea; - - g_return_if_fail(GTK_IS_MOZAREA(object)); - - mozarea = GTK_MOZAREA(object); - - /* remove the listener from the toplevel */ - remove_toplevel_listener(mozarea); - - GTK_OBJECT_CLASS(parent_class)->destroy(object); -} - -GtkWidget* -gtk_mozarea_new (GdkWindow *parent_window) -{ - return GTK_WIDGET (gtk_type_new (GTK_TYPE_MOZAREA)); -} - -gboolean -gtk_mozarea_get_toplevel_focus(GtkMozArea *area) -{ - g_return_val_if_fail(GTK_IS_MOZAREA(area), FALSE); - - return area->toplevel_focus; -} - -/* this function will attach a listener to this widget's real toplevel - window */ -static void -attach_toplevel_listener(GtkMozArea *mozarea) -{ - /* get the real gdk toplevel window */ - GdkWindow *gdk_window = get_real_gdk_toplevel(mozarea); - - /* attach our passive filter. when this widget is destroyed it will - be removed in our destroy method. */ - gdk_window_add_filter(gdk_window, toplevel_window_filter, mozarea); - - /* save it so that we can remove the filter later */ - mozarea->toplevel_window = gdk_window; -} - -/* this function will remove a toplevel listener for a widget */ -static void -remove_toplevel_listener(GtkMozArea *mozarea) -{ - gdk_window_remove_filter(mozarea->toplevel_window, toplevel_window_filter, - mozarea); -} - -/* this function will try to find the real toplevel for a gdk window. */ -static Window -get_real_toplevel(Window aWindow) -{ - Window current = aWindow; - Atom atom; - - /* get the atom for the WM_STATE variable that you get on WM - managed windows. */ - - atom = XInternAtom(GDK_DISPLAY(), "WM_STATE", FALSE); - - while (current) { - Atom type = None; - int format; - unsigned long nitems, after; - unsigned char *data; - - Window root_return; - Window parent_return; - Window *children_return = NULL; - unsigned int nchildren_return; - - /* check for the atom on this window */ - XGetWindowProperty(GDK_DISPLAY(), current, atom, - 0, 0, /* offsets */ - False, /* don't delete */ - AnyPropertyType, - &type, &format, &nitems, &after, &data); - - /* did we get something? */ - if (type != None) { - XFree(data); - data = NULL; - /* ok, this is the toplevel window since it has the property set - on it. */ - break; - } - - /* what is the parent? */ - XQueryTree(GDK_DISPLAY(), current, &root_return, - &parent_return, &children_return, - &nchildren_return); - - if (children_return) - XFree(children_return); - - /* If the parent window of this window is the root window then - there is no window manager running so the current window is the - toplevel window. */ - if (parent_return == root_return) - break; - - current = parent_return; - } - - return current; -} - -static GdkWindow * -get_real_gdk_toplevel(GtkMozArea *mozarea) -{ - /* get the native window for this widget */ - GtkWidget *widget = GTK_WIDGET(mozarea); - Window window = GDK_WINDOW_XWINDOW(widget->window); - - Window toplevel = get_real_toplevel(window); - - /* check to see if this is an already registered window with the - type system. */ - GdkWindow *gdk_window = gdk_window_lookup(toplevel); - - /* This isn't our window? It is now, fool! */ - if (!gdk_window) { - /* import it into the type system */ - gdk_window = gdk_window_foreign_new(toplevel); - /* make sure that we are listening for the right events on it. */ - gdk_window_set_events(gdk_window, GDK_FOCUS_CHANGE_MASK); - } - - return gdk_window; -} - -static GdkFilterReturn -toplevel_window_filter(GdkXEvent *aGdkXEvent, - GdkEvent *aEvent, - gpointer data) -{ - XEvent *xevent = (XEvent *)aGdkXEvent; - GtkMozArea *mozarea = (GtkMozArea *)data; - - switch (xevent->xany.type) { - case FocusIn: - mozarea->toplevel_focus = TRUE; - gtk_signal_emit(GTK_OBJECT(mozarea), mozarea_signals[TOPLEVEL_FOCUS_IN]); - break; - case FocusOut: - mozarea->toplevel_focus = FALSE; - gtk_signal_emit(GTK_OBJECT(mozarea), mozarea_signals[TOPLEVEL_FOCUS_OUT]); - break; - case ConfigureNotify: - gtk_signal_emit(GTK_OBJECT(mozarea), mozarea_signals[TOPLEVEL_CONFIGURE]); - break; - default: - break; - } - - return GDK_FILTER_CONTINUE; -} - -static GdkFilterReturn -widget_window_filter(GdkXEvent *aGdkXEvent, - GdkEvent *aEvent, - gpointer data) -{ - XEvent *xevent = (XEvent *)aGdkXEvent; - GtkMozArea *mozarea = (GtkMozArea *)data; - - switch(xevent->xany.type) { - case ReparentNotify: - /* remove the old filter on the toplevel and attach to the new one */ - remove_toplevel_listener(mozarea); - attach_toplevel_listener(mozarea); - break; - default: - break; - } - return GDK_FILTER_CONTINUE; -} diff --git a/mozilla/widget/src/gtksuperwin/gtkmozarea.h b/mozilla/widget/src/gtksuperwin/gtkmozarea.h deleted file mode 100644 index fd7f3ffc9e8..00000000000 --- a/mozilla/widget/src/gtksuperwin/gtkmozarea.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Owen Taylor and Christopher Blizzard - * . - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __GTK_MOZAREA_H__ -#define __GTK_MOZAREA_H__ - -#include -#include "gdksuperwin.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct _GtkMozArea GtkMozArea; -typedef struct _GtkMozAreaClass GtkMozAreaClass; - -#define GTK_TYPE_MOZAREA (gtk_mozarea_get_type ()) -#define GTK_MOZAREA(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_MOZAREA, GtkMozArea)) -#define GTK_MOZAREA_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MOZAREA, GtkMozAreaClass)) -#define GTK_IS_MOZAREA(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_MOZAREA)) -#define GTK_IS_MOZAREA_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MOZAREA)) - -struct _GtkMozArea -{ - GtkWidget widget; - GdkSuperWin *superwin; - gboolean toplevel_focus; - - /* store away the toplevel window */ - GdkWindow *toplevel_window; -}; - -struct _GtkMozAreaClass -{ - GtkWindowClass window_class; - - /* signals */ - void (* toplevel_focus_in ) (GtkMozArea *area); - void (* toplevel_focus_out) (GtkMozArea *area); - void (* toplevel_configure) (GtkMozArea *area); -}; - -GTKSUPERWIN_API(GtkType) gtk_mozarea_get_type (void); -GTKSUPERWIN_API(GtkWidget*) gtk_mozarea_new (); -GTKSUPERWIN_API(gboolean) gtk_mozarea_get_toplevel_focus(GtkMozArea *area); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __GTK_MOZAREA_H__ */ diff --git a/mozilla/widget/src/gtksuperwin/gtkmozbox.c b/mozilla/widget/src/gtksuperwin/gtkmozbox.c deleted file mode 100644 index 4a46aac9d85..00000000000 --- a/mozilla/widget/src/gtksuperwin/gtkmozbox.c +++ /dev/null @@ -1,269 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Owen Taylor and Christopher Blizzard - * . - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "gtkmozbox.h" -#include -#include - -static void gtk_mozbox_class_init (GtkMozBoxClass *klass); -static void gtk_mozbox_init (GtkMozBox *mozbox); -static void gtk_mozbox_realize (GtkWidget *widget); -static void gtk_mozbox_set_focus (GtkWindow *window, - GtkWidget *focus); -static gint gtk_mozbox_key_press_event (GtkWidget *widget, - GdkEventKey *event); -static GdkFilterReturn gtk_mozbox_filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data); -static GtkWindow * gtk_mozbox_get_parent_gtkwindow (GtkMozBox *mozbox); - -void (*parent_class_set_focus)(GtkWindow *, GtkWidget *); - -GtkType -gtk_mozbox_get_type (void) -{ - static GtkType mozbox_type = 0; - - if (!mozbox_type) - { - static const GtkTypeInfo mozbox_info = - { - "GtkMozBox", - sizeof (GtkMozBox), - sizeof (GtkMozBoxClass), - (GtkClassInitFunc) gtk_mozbox_class_init, - (GtkObjectInitFunc) gtk_mozbox_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL - }; - - mozbox_type = gtk_type_unique (GTK_TYPE_WINDOW, &mozbox_info); - } - - return mozbox_type; -} - -static void -gtk_mozbox_class_init (GtkMozBoxClass *klass) -{ - GtkWidgetClass *widget_class; - GtkWindowClass *window_class; - - widget_class = GTK_WIDGET_CLASS (klass); - window_class = GTK_WINDOW_CLASS (klass); - - widget_class->realize = gtk_mozbox_realize; - widget_class->key_press_event = gtk_mozbox_key_press_event; - - /* save the parent class' set_focus method */ - parent_class_set_focus = window_class->set_focus; - window_class->set_focus = gtk_mozbox_set_focus; - -} - -static void -gtk_mozbox_init (GtkMozBox *mozbox) -{ - mozbox->parent_window = NULL; - mozbox->x = 0; - mozbox->y = 0; -} - -static void -gtk_mozbox_realize (GtkWidget *widget) -{ - GdkWindowAttr attributes; - gint attributes_mask; - GtkMozBox *mozbox; - - g_return_if_fail (GTK_IS_MOZBOX (widget)); - - mozbox = GTK_MOZBOX (widget); - - /* GtkWindow checks against premature realization here. Just - * don't do it. - */ - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = mozbox->x; - attributes.y = mozbox->y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= GDK_EXPOSURE_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (mozbox->parent_window, - &attributes, attributes_mask); - - /* set the back pixmap to None so that you don't end up with the gtk - default which is BlackPixel */ - gdk_window_set_back_pixmap (widget->window, NULL, FALSE); - - gdk_window_set_user_data (widget->window, mozbox); - - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); - - gdk_window_add_filter (widget->window, gtk_mozbox_filter, mozbox); -} - -static void -gtk_mozbox_set_focus (GtkWindow *window, - GtkWidget *focus) -{ - GtkMozBox *mozbox; - GdkWindow *tmpWindow; - GtkWindow *parentGtkWindow; - - g_return_if_fail(window != NULL); - g_return_if_fail(GTK_IS_MOZBOX(window)); - - mozbox = GTK_MOZBOX(window); - - parentGtkWindow = gtk_mozbox_get_parent_gtkwindow (mozbox); - - if (parentGtkWindow) { - parent_class_set_focus(parentGtkWindow, focus); - return; - } - - /* as a fall back just hand it off to our parent class */ - parent_class_set_focus(window, focus); - -} - -static gint -gtk_mozbox_key_press_event (GtkWidget *widget, - GdkEventKey *event) -{ - GtkWindow *window; - GtkMozBox *mozbox; - GtkWindow *parentWindow; - gboolean handled = FALSE; - - window = GTK_WINDOW (widget); - mozbox = GTK_MOZBOX (widget); - - parentWindow = gtk_mozbox_get_parent_gtkwindow(mozbox); - - /* give the focus window the chance to handle the event first. */ - if (parentWindow && parentWindow->focus_widget) { - handled = gtk_widget_event (parentWindow->focus_widget, (GdkEvent*) event); - } - - /* pass it off to the parent widget */ - if (!handled) { - gdk_window_unref(event->window); - event->window = mozbox->parent_window; - gdk_window_ref(event->window); - gdk_event_put((GdkEvent *)event); - } - - return TRUE; -} - -static GdkFilterReturn -gtk_mozbox_filter (GdkXEvent *xevent, - GdkEvent *event, - gpointer data) -{ - XEvent *xev = xevent; - GtkWidget *widget = data; - - switch (xev->xany.type) - { - case ConfigureNotify: - event->configure.type = GDK_CONFIGURE; - event->configure.window = widget->window; - event->configure.x = 0; - event->configure.y = 0; - event->configure.width = xev->xconfigure.width; - event->configure.height = xev->xconfigure.height; - return GDK_FILTER_TRANSLATE; - default: - return GDK_FILTER_CONTINUE; - } -} - -static GtkWindow * -gtk_mozbox_get_parent_gtkwindow (GtkMozBox *mozbox) -{ - GdkWindow *tmpWindow; - /* look for a parent GtkWindow in the heirarchy */ - tmpWindow = mozbox->parent_window; - while (tmpWindow) { - gpointer data = NULL; - gdk_window_get_user_data(tmpWindow, &data); - if (data && GTK_IS_WINDOW(data)) { - return GTK_WINDOW(data); - } - tmpWindow = gdk_window_get_parent(tmpWindow); - } - return NULL; -} - -GtkWidget* -gtk_mozbox_new (GdkWindow *parent_window) -{ - GtkMozBox *mozbox; - - mozbox = gtk_type_new (GTK_TYPE_MOZBOX); - mozbox->parent_window = parent_window; - - return GTK_WIDGET (mozbox); -} - -void -gtk_mozbox_set_position (GtkMozBox *mozbox, - gint x, - gint y) -{ - mozbox->x = x; - mozbox->y = y; - - if (GTK_WIDGET_REALIZED (mozbox)) - gdk_window_move (GTK_WIDGET (mozbox)->window, x, y); -} - diff --git a/mozilla/widget/src/gtksuperwin/gtkmozbox.h b/mozilla/widget/src/gtksuperwin/gtkmozbox.h deleted file mode 100644 index ccfa4603350..00000000000 --- a/mozilla/widget/src/gtksuperwin/gtkmozbox.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org Code. - * - * The Initial Developer of the Original Code is - * Owen Taylor and Christopher Blizzard - * . - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __GTK_MOZBOX_H__ -#define __GTK_MOZBOX_H__ - -#include -#include "gdksuperwin.h" /* for GTKSUPERWIN_API */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct _GtkMozBox GtkMozBox; -typedef struct _GtkMozBoxClass GtkMozBoxClass; - -#define GTK_TYPE_MOZBOX (gtk_mozbox_get_type ()) -#define GTK_MOZBOX(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_MOZBOX, GtkMozBox)) -#define GTK_MOZBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_MOZBOX, GtkMozBoxClass)) -#define GTK_IS_MOZBOX(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_MOZBOX)) -#define GTK_IS_MOZBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_MOZBOX)) - -struct _GtkMozBox -{ - GtkWindow window; - GdkWindow *parent_window; - gint x; - gint y; -}; - -struct _GtkMozBoxClass -{ - GtkWindowClass window_class; -}; - -GTKSUPERWIN_API(GtkType) gtk_mozbox_get_type (void); -GTKSUPERWIN_API(GtkWidget*) gtk_mozbox_new (GdkWindow *parent_window); -GTKSUPERWIN_API(void) gtk_mozbox_set_position (GtkMozBox *mozbox, - gint x, - gint y); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __GTK_MOZBOX_H__ */ diff --git a/mozilla/widget/src/gtksuperwin/gtksuperwin.pkg b/mozilla/widget/src/gtksuperwin/gtksuperwin.pkg deleted file mode 100644 index 81976c1468a..00000000000 --- a/mozilla/widget/src/gtksuperwin/gtksuperwin.pkg +++ /dev/null @@ -1,4 +0,0 @@ -[gecko] -#if SHARED_LIBRARY -dist/bin/@SHARED_LIBRARY@ -#endif diff --git a/mozilla/widget/src/xlib/Makefile.in b/mozilla/widget/src/xlib/Makefile.in deleted file mode 100644 index 9730f9d0079..00000000000 --- a/mozilla/widget/src/xlib/Makefile.in +++ /dev/null @@ -1,106 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Roland Mainz -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = widget -LIBRARY_NAME = widget_xlib -EXPORT_LIBRARY = 1 -IS_COMPONENT = 1 -MODULE_NAME = nsWidgetXLIBModule -GRE_MODULE = 1 -LIBXUL_LIBRARY = 1 - -PACKAGE_FILE = widget_xlib.pkg - -REQUIRES = xpcom \ - string \ - appshell \ - gfx \ - layout \ - content \ - dom \ - js \ - xlibrgb \ - uconv \ - pref \ - webshell \ - htmlparser \ - view \ - necko \ - $(NULL) - -CPPSRCS = \ - nsAppShell.cpp \ - nsBidiKeyboard.cpp \ - nsClipboard.cpp \ - nsDragService.cpp \ - nsKeyCode.cpp \ - nsLookAndFeel.cpp \ - nsScreenXlib.cpp \ - nsScreenManagerXlib.cpp \ - nsSound.cpp \ - nsToolkit.cpp \ - nsWidget.cpp \ - nsWidgetFactory.cpp \ - nsWindow.cpp \ - nsXUtils.cpp \ - $(NULL) - -SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a - -include $(topsrcdir)/config/rules.mk - -EXTRA_DSO_LDOPTS += -L$(DIST)/bin -L$(DIST)/lib -lgkgfx $(MOZ_COMPONENT_LIBS) - -EXTRA_DSO_LDOPTS += -L$(DIST)/bin -lXt -lxlibrgb -lxlibxtbin $(MOZ_XLIB_LDFLAGS) - -CXXFLAGS += $(MOZ_XLIB_CFLAGS) - -DEFINES += -D_IMPL_NS_WIDGET - -LOCAL_INCLUDES = \ - -I$(srcdir)/../xpwidgets \ - -I$(srcdir) \ - $(NULL) - diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp deleted file mode 100644 index 44136027d91..00000000000 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ /dev/null @@ -1,1254 +0,0 @@ -/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * Tony Tsui - * Caspian Maclean - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "nsWindow.h" -#include "nsWidget.h" -#include "nsAppShell.h" -#include "nsKeyCode.h" -#include "nsWidgetsCID.h" - -#include "nsIWidget.h" -#include "nsIEventQueueService.h" -#include "nsIServiceManager.h" -#include "nsIDragService.h" -#include "nsIDragSessionXlib.h" -#include "nsITimer.h" - -#include "xlibrgb.h" - -#define CHAR_BUF_SIZE 80 - -static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); - -/* nsAppShell static members */ -Display *nsAppShell::mDisplay = nsnull; -XlibRgbHandle *nsAppShell::mXlib_rgb_handle = nsnull; -XtAppContext nsAppShell::mAppContext; -PRTime nsAppShell::mClickTime = 0; -PRInt16 nsAppShell::mClicks = 1; -PRUint16 nsAppShell::mClickedButton = 0; -PRPackedBool nsAppShell::mClicked = PR_FALSE; -PRPackedBool nsAppShell::mDragging = PR_FALSE; -PRPackedBool nsAppShell::mAltDown = PR_FALSE; -PRPackedBool nsAppShell::mShiftDown = PR_FALSE; -PRPackedBool nsAppShell::mCtrlDown = PR_FALSE; -PRPackedBool nsAppShell::mMetaDown = PR_FALSE; -PRPackedBool nsAppShell::DieAppShellDie = PR_FALSE; - -static PLHashTable *sQueueHashTable = nsnull; -static PLHashTable *sCountHashTable = nsnull; -static nsVoidArray *sEventQueueList = nsnull; - - -// For debugging. -static const char *event_names[] = -{ - "", - "", - "KeyPress", - "KeyRelease", - "ButtonPress", - "ButtonRelease", - "MotionNotify", - "EnterNotify", - "LeaveNotify", - "FocusIn", - "FocusOut", - "KeymapNotify", - "Expose", - "GraphicsExpose", - "NoExpose", - "VisibilityNotify", - "CreateNotify", - "DestroyNotify", - "UnmapNotify", - "MapNotify", - "MapRequest", - "ReparentNotify", - "ConfigureNotify", - "ConfigureRequest", - "GravityNotify", - "ResizeRequest", - "CirculateNotify", - "CirculateRequest", - "PropertyNotify", - "SelectionClear", - "SelectionRequest", - "SelectionNotify", - "ColormapNotify", - "ClientMessage", - "MappingNotify" -}; - -#define COMPARE_FLAG1( a,b) ((b)[0]=='-' && !strcmp((a), &(b)[1])) -#define COMPARE_FLAG2( a,b) ((b)[0]=='-' && (b)[1]=='-' && !strcmp((a), &(b)[2])) -#define COMPARE_FLAG12(a,b) ((b)[0]=='-' && !strcmp((a), (b)[1]=='-'?&(b)[2]:&(b)[1])) - -#define ALL_EVENTS ( KeyPressMask | KeyReleaseMask | ButtonPressMask | \ - ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | \ - PointerMotionMask | PointerMotionHintMask | Button1MotionMask | \ - Button2MotionMask | Button3MotionMask | \ - Button4MotionMask | Button5MotionMask | ButtonMotionMask | \ - KeymapStateMask | ExposureMask | VisibilityChangeMask | \ - StructureNotifyMask | ResizeRedirectMask | \ - SubstructureNotifyMask | SubstructureRedirectMask | \ - FocusChangeMask | PropertyChangeMask | \ - ColormapChangeMask | OwnerGrabButtonMask ) - -nsAppShell::nsAppShell() -{ - if (!sEventQueueList) - sEventQueueList = new nsVoidArray(); - - mEventQueue = nsnull; -} - -NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell) - -PR_BEGIN_EXTERN_C -static -int xerror_handler( Display *display, XErrorEvent *ev ) -{ - /* this should _never_ be happen... but if this happens - debug mode or not - scream !!! */ - char errmsg[80]; - XGetErrorText(display, ev->error_code, errmsg, sizeof(errmsg)); - fprintf(stderr, "nsAppShellXlib: Warning (X Error) - %s\n", errmsg); - abort(); // die !! - - return 0; -} -PR_END_EXTERN_C - -NS_METHOD nsAppShell::Create(int* bac, char ** bav) -{ - /* Create the Xt Application context... */ - if (mAppContext == nsnull) { - int argc = bac ? *bac : 0; - char **argv = bav; - nsresult rv; - - char *displayName = nsnull; - Bool synchronize = False; - int i; - XlibRgbArgs xargs; - memset(&xargs, 0, sizeof(xargs)); - /* Use a "well-known" name that other modules can "look-up" this handle - * via |xxlib_find_handle| ... */ - xargs.handle_name = XXLIBRGB_DEFAULT_HANDLE; - - for (i = 0; ++i < argc-1; ) { - /* allow both --display and -display */ - if (COMPARE_FLAG12 ("display", argv[i])) { - displayName=argv[i+1]; - break; - } - } - for (i = 0; ++i < argc-1; ) { - if (COMPARE_FLAG1 ("visual", argv[i])) { - xargs.xtemplate_mask |= VisualIDMask; - xargs.xtemplate.visualid = strtol(argv[i+1], NULL, 0); - break; - } - } - for (i = 0; ++i < argc; ) { - if (COMPARE_FLAG1 ("sync", argv[i])) { - synchronize = True; - break; - } - } - for (i = 0; ++i < argc; ) { - /* allow both --no-xshm and -no-xshm */ - if (COMPARE_FLAG12 ("no-xshm", argv[i])) { - xargs.disallow_mit_shmem = True; - break; - } - } - for (i = 0; ++i < argc; ) { - if (COMPARE_FLAG1 ("install_colormap", argv[i])) { - xargs.install_colormap = True; - break; - } - } - - /* setup locale */ - if (!setlocale (LC_ALL,"")) - NS_WARNING("locale not supported by C library"); - - if (!XSupportsLocale ()) { - NS_WARNING("locale not supported by Xlib, locale set to C"); - setlocale (LC_ALL, "C"); - } - - if (!XSetLocaleModifiers ("")) - NS_WARNING("can not set locale modifiers"); - - XtToolkitInitialize(); - mAppContext = XtCreateApplicationContext(); - - if (!(mDisplay = XtOpenDisplay (mAppContext, displayName, - "Mozilla5", "Mozilla5", nsnull, 0, - &argc, argv))) - { - fprintf (stderr, "%s: unable to open display \"%s\"\n", argv[0], XDisplayName(displayName)); - exit (EXIT_FAILURE); - } - - // Requires XSynchronize(mDisplay, True); To stop X buffering. Use this - // to make debugging easier. KenF - if (synchronize) - { - /* Set error handler which calls abort() - only usefull with an - * unbuffered X connection */ - (void)XSetErrorHandler(xerror_handler); - - NS_WARNING("running via unbuffered X connection."); - XSynchronize(mDisplay, True); - } - - mXlib_rgb_handle = xxlib_rgb_create_handle(mDisplay, XDefaultScreenOfDisplay(mDisplay), - &xargs); - if (!mXlib_rgb_handle) - { - fprintf (stderr, "%s: unable to create Xlib context\n", argv[0]); - exit (EXIT_FAILURE); - } - } - - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsAppShell::Create(dpy=%p)\n", - mDisplay)); - - return NS_OK; -} - -NS_IMETHODIMP nsAppShell::Spinup() -{ - nsresult rv = NS_OK; - -#ifdef DEBUG_APPSHELL - printf("nsAppShell::Spinup()\n"); -#endif - - /* Get the event queue service */ - nsCOMPtr eventQService = do_GetService(kEventQueueServiceCID, &rv); - - if (NS_FAILED(rv)) { - NS_WARNING("Could not obtain event queue service"); - return rv; - } - - /* Get the event queue for the thread.*/ - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(mEventQueue)); - - /* If we got an event queue, use it. */ - if (!mEventQueue) { - /* otherwise create a new event queue for the thread */ - rv = eventQService->CreateThreadEventQueue(); - if (NS_FAILED(rv)) { - NS_WARNING("Could not create the thread event queue"); - return rv; - } - - /* Ask again nicely for the event queue now that we have created one. */ - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(mEventQueue)); - if (NS_FAILED(rv)) { - NS_WARNING("Could not get the thread event queue"); - return rv; - } - } - - ListenToEventQueue(mEventQueue, PR_TRUE); - - return rv; -} - -/* must be a |XtInputCallbackProc| !! */ -PR_BEGIN_EXTERN_C -static -void HandleQueueXtProc(XtPointer ptr, int *source_fd, XtInputId* id) -{ - nsIEventQueue *queue = (nsIEventQueue *)ptr; - queue->ProcessPendingEvents(); -} -PR_END_EXTERN_C - -nsresult nsAppShell::Run() -{ - if (mEventQueue == nsnull) - Spinup(); - - if (mEventQueue == nsnull) { - NS_WARNING("Cannot initialize the Event Queue"); - return NS_ERROR_NOT_INITIALIZED; - } - - XEvent xevent; - - /* process events. */ - while (!DieAppShellDie) - { - XtAppNextEvent(mAppContext, &xevent); - - if (XtDispatchEvent(&xevent) == False) - DispatchXEvent(&xevent); - - if (XEventsQueued(mDisplay, QueuedAlready) == 0) - { - /* Flush the nsWindow's drawing queue */ - nsWindow::UpdateIdle(nsnull); - } - } - - Spindown(); - return NS_OK; -} - -NS_METHOD nsAppShell::Spindown() -{ - if (mEventQueue) { - ListenToEventQueue(mEventQueue, PR_FALSE); - mEventQueue->ProcessPendingEvents(); - mEventQueue = nsnull; - } - - return NS_OK; -} - -#define NUMBER_HASH_KEY(_num) ((PLHashNumber) _num) - -static PLHashNumber -IntHashKey(PRInt32 key) -{ - return NUMBER_HASH_KEY(key); -} -// wrapper so we can call a macro -PR_BEGIN_EXTERN_C -static unsigned long getNextRequest (void *aClosure) { - return XNextRequest(nsAppShell::mDisplay); -} -PR_END_EXTERN_C - -NS_IMETHODIMP nsAppShell::ListenToEventQueue(nsIEventQueue *aQueue, - PRBool aListen) -{ - if (!mEventQueue) { - NS_WARNING("nsAppShell::ListenToEventQueue(): No event queue available."); - return NS_ERROR_NOT_INITIALIZED; - } - -#ifdef DEBUG_APPSHELL - printf("ListenToEventQueue(%p, %d) this=%p\n", aQueue, aListen, this); -#endif - if (!sQueueHashTable) { - sQueueHashTable = PL_NewHashTable(3, (PLHashFunction)IntHashKey, - PL_CompareValues, PL_CompareValues, 0, 0); - } - if (!sCountHashTable) { - sCountHashTable = PL_NewHashTable(3, (PLHashFunction)IntHashKey, - PL_CompareValues, PL_CompareValues, 0, 0); - } - - int queue_fd = aQueue->GetEventQueueSelectFD(); - void *key = aQueue; - if (aListen) { - /* Add listener - - * but only if we arn't already in the table... */ - if (!PL_HashTableLookup(sQueueHashTable, key)) { - long tag; - - /* set up our fds callbacks */ - tag = (long)XtAppAddInput(mAppContext, - queue_fd, - (XtPointer)(long)(XtInputReadMask), - HandleQueueXtProc, - (XtPointer)mEventQueue); - -/* This hack would not be necessary if we would have a hashtable function - * which returns success/failure in a separate var ... - */ -#define NEVER_BE_ZERO_MAGIC (54321) - tag += NEVER_BE_ZERO_MAGIC; /* be sure that |tag| is _never_ 0 */ - NS_ASSERTION(tag!=0, "tag is 0 while adding"); - - if (tag) { - PL_HashTableAdd(sQueueHashTable, key, (void *)tag); - } - - PLEventQueue *plqueue; - aQueue->GetPLEventQueue(&plqueue); - PL_RegisterEventIDFunc(plqueue, getNextRequest, 0); - sEventQueueList->AppendElement(plqueue); - } - } else { - /* Remove listener... */ - PLEventQueue *plqueue; - aQueue->GetPLEventQueue(&plqueue); - PL_UnregisterEventIDFunc(plqueue); - sEventQueueList->RemoveElement(plqueue); - - int tag = long(PL_HashTableLookup(sQueueHashTable, key)); - if (tag) { - tag -= NEVER_BE_ZERO_MAGIC; - XtRemoveInput((XtInputId)tag); - PL_HashTableRemove(sQueueHashTable, key); - } - } - - return NS_OK; -} - -/* Does nothing. Used by xp code with non-gtk expectations. - * this method will be removed once xp eventloops are working. - */ -NS_METHOD -nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent) -{ - aRealEvent = PR_FALSE; - aEvent = nsnull; - - return NS_OK; -} - -nsresult nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent) -{ - XEvent xevent; - - if (!mEventQueue) - return NS_ERROR_NOT_INITIALIZED; - -#if 1 - /* gisburn: Why do we have to call this explicitly ? - * I have registered a callback via XtAddAppInput() above... - */ - mEventQueue->ProcessPendingEvents(); -#endif - - XtAppNextEvent(mAppContext, &xevent); - - if (XtDispatchEvent(&xevent) == False) - DispatchXEvent(&xevent); - - if (XEventsQueued(mDisplay, QueuedAlready) == 0) - { - /* Flush the nsWindow's drawing queue */ - nsWindow::UpdateIdle(nsnull); - } - - return NS_OK; -} - -NS_METHOD nsAppShell::Exit() -{ - DieAppShellDie = PR_TRUE; - return NS_OK; -} - -nsAppShell::~nsAppShell() -{ -} - -void* nsAppShell::GetNativeData(PRUint32 aDataType) -{ - return nsnull; -} - -void -nsAppShell::DispatchXEvent(XEvent *event) -{ - nsWidget *widget; - widget = nsWidget::GetWidgetForWindow(event->xany.window); - - // did someone pass us an x event for a window we don't own? - // bad! bad! - if (widget == nsnull) - return; - - // switch on the type of event - switch (event->type) - { - case Expose: - HandleExposeEvent(event, widget); - break; - - case ConfigureNotify: - // we need to make sure that this is the LAST of the - // config events. - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("DispatchEvent: ConfigureNotify event for window 0x%lx %d %d %d %d\n", - event->xconfigure.window, - event->xconfigure.x, - event->xconfigure.y, - event->xconfigure.width, - event->xconfigure.height)); - - HandleConfigureNotifyEvent(event, widget); - - break; - - case ButtonPress: - case ButtonRelease: - HandleFocusInEvent(event, widget); - HandleButtonEvent(event, widget); - break; - - case MotionNotify: - HandleMotionNotifyEvent(event, widget); - break; - - case KeyPress: - HandleKeyPressEvent(event, widget); - break; - case KeyRelease: - HandleKeyReleaseEvent(event, widget); - break; - - case FocusIn: - HandleFocusInEvent(event, widget); - break; - - case FocusOut: - HandleFocusOutEvent(event, widget); - break; - - case EnterNotify: - HandleEnterEvent(event, widget); - break; - - case LeaveNotify: - HandleLeaveEvent(event, widget); - break; - - case NoExpose: - // these annoy me. - break; - case VisibilityNotify: - HandleVisibilityNotifyEvent(event, widget); - break; - case ClientMessage: - HandleClientMessageEvent(event, widget); - break; - case SelectionRequest: - HandleSelectionRequestEvent(event, widget); - break; - default: - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Unhandled window event: Window 0x%lx Got a %s event\n", - event->xany.window, event_names[event->type])); - - break; - } -} - -void -nsAppShell::HandleMotionNotifyEvent(XEvent *event, nsWidget *aWidget) -{ - if (mDragging) { - HandleDragMotionEvent(event, aWidget); - } - - nsMouseEvent mevent(PR_TRUE, NS_MOUSE_MOVE, aWidget, nsMouseEvent::eReal); - XEvent aEvent; - - mevent.refPoint.x = event->xmotion.x; - mevent.refPoint.y = event->xmotion.y; - - mevent.isShift = mShiftDown; - mevent.isControl = mCtrlDown; - mevent.isAlt = mAltDown; - mevent.isMeta = mMetaDown; - - Display * dpy = (Display *)aWidget->GetNativeData(NS_NATIVE_DISPLAY); - Window win = (Window)aWidget->GetNativeData(NS_NATIVE_WINDOW); - // We are only interested in the LAST (newest) location of the pointer - while(XCheckWindowEvent(dpy, - win, - ButtonMotionMask, - &aEvent)) { - mevent.refPoint.x = aEvent.xmotion.x; - mevent.refPoint.y = aEvent.xmotion.y; - } - NS_ADDREF(aWidget); - aWidget->DispatchMouseEvent(mevent); - NS_RELEASE(aWidget); -} - -void -nsAppShell::HandleButtonEvent(XEvent *event, nsWidget *aWidget) -{ - PRUint32 eventType = 0; - PRInt16 button = nsMouseEvent::eLeftButton; - PRBool currentlyDragging = mDragging; - nsMouseScrollEvent scrollEvent(PR_TRUE, NS_MOUSE_SCROLL, aWidget); - - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Button event for window 0x%lx button %d type %s\n", - event->xany.window, - event->xbutton.button, - (event->type == ButtonPress ? "ButtonPress" : "ButtonRelease"))); - switch(event->type) { - case ButtonPress: - eventType = NS_MOUSE_BUTTON_DOWN; - switch(event->xbutton.button) { - case 1: - button = nsMouseEvent::eLeftButton; - mDragging = PR_TRUE; - break; - case 2: - button = nsMouseEvent::eMiddleButton; - break; - case 3: - /* look back into this in case anything actually needs a - * NS_MOUSE_RIGHT_BUTTON_DOWN */ - eventType = NS_CONTEXTMENU; - button = nsMouseEvent::eRightButton; - break; - case 4: - case 5: - scrollEvent.delta = (event->xbutton.button == 4) ? -3 : 3; - scrollEvent.scrollFlags = nsMouseScrollEvent::kIsVertical; - - scrollEvent.refPoint.x = event->xbutton.x; - scrollEvent.refPoint.y = event->xbutton.y; - - scrollEvent.isShift = mShiftDown; - scrollEvent.isControl = mCtrlDown; - scrollEvent.isAlt = mAltDown; - scrollEvent.isMeta = mMetaDown; - scrollEvent.time = PR_Now(); - NS_IF_ADDREF(aWidget); - aWidget->DispatchWindowEvent(scrollEvent); - NS_IF_RELEASE(aWidget); - return; - } - break; - case ButtonRelease: - eventType = NS_MOUSE_BUTTON_UP; - switch(event->xbutton.button) { - case 1: - button = nsMouseEvent::eLeftButton; - mDragging = PR_FALSE; - break; - case 2: - button = nsMouseEvent::eMiddleButton; - break; - case 3: - button = nsMouseEvent::eRightButton; - break; - case 4: - case 5: - return; - } - break; - } - - nsMouseEvent mevent(PR_TRUE, eventType, aWidget, nsMouseEvent::eReal); - mevent.button = button; - mevent.isShift = mShiftDown; - mevent.isControl = mCtrlDown; - mevent.isAlt = mAltDown; - mevent.isMeta = mMetaDown; - mevent.refPoint.x = event->xbutton.x; - mevent.refPoint.y = event->xbutton.y; - mevent.time = PR_Now(); - - // If we are waiting longer than 1 sec for the second click, this is not a - // double click. - if (PR_Now() - mClickTime > 1000000) - mClicked = PR_FALSE; - - if (event->type == ButtonPress) { - if (!mClicked) { - mClicked = PR_TRUE; - mClickTime = PR_Now(); - mClicks = 1; - mClickedButton = event->xbutton.button; - } else { - mClickTime = PR_Now() - mClickTime; - if ((mClickTime < 500000) && (mClickedButton == event->xbutton.button)) - mClicks = 2; - else - mClicks = 1; - mClicked = PR_FALSE; - } - } - - if (currentlyDragging && !mDragging) - HandleDragDropEvent(event, aWidget); - - mevent.clickCount = mClicks; - NS_IF_ADDREF(aWidget); - aWidget->DispatchMouseEvent(mevent); - NS_IF_RELEASE(aWidget); -} - -void -nsAppShell::HandleExposeEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Expose event for window 0x%lx %d %d %d %d\n", event->xany.window, - event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height)); - - nsRect dirtyRect(event->xexpose.x, event->xexpose.y, - event->xexpose.width, event->xexpose.height); - - /* compress expose events... - */ - if (event->xexpose.count!=0) { - XEvent txe; - do { - XWindowEvent(event->xany.display, event->xany.window, ExposureMask, (XEvent *)&txe); - dirtyRect.UnionRect(dirtyRect, nsRect(txe.xexpose.x, txe.xexpose.y, - txe.xexpose.width, txe.xexpose.height)); - } while (txe.xexpose.count>0); - } - - aWidget->Invalidate(dirtyRect, PR_FALSE); -} - -void -nsAppShell::HandleConfigureNotifyEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("ConfigureNotify event for window 0x%lx %d %d %d %d\n", - event->xconfigure.window, - event->xconfigure.x, event->xconfigure.y, - event->xconfigure.width, event->xconfigure.height)); - - XEvent config_event; - while (XCheckTypedWindowEvent(event->xany.display, - event->xany.window, - ConfigureNotify, - &config_event) == True) { - // make sure that we don't get other types of events. - // StructureNotifyMask includes other kinds of events, too. - if (config_event.type == ConfigureNotify) - { - *event = config_event; - - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("DispatchEvent: Extra ConfigureNotify event for window 0x%lx %d %d %d %d\n", - event->xconfigure.window, - event->xconfigure.x, - event->xconfigure.y, - event->xconfigure.width, - event->xconfigure.height)); - } - else { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("EVENT LOSSAGE\n")); - } - } - - nsSizeEvent sevent(PR_TRUE, NS_SIZE, aWidget); - sevent.windowSize = new nsRect (event->xconfigure.x, event->xconfigure.y, - event->xconfigure.width, event->xconfigure.height); - sevent.refPoint.x = event->xconfigure.x; - sevent.refPoint.y = event->xconfigure.y; - sevent.mWinWidth = event->xconfigure.width; - sevent.mWinHeight = event->xconfigure.height; - // XXX fix sevent.time - NS_ADDREF(aWidget); - aWidget->OnResize(sevent); - NS_RELEASE(aWidget); - delete sevent.windowSize; -} - -PRUint32 nsConvertCharCodeToUnicode(XKeyEvent* xkey) -{ - // The only Unicode specific at the moment is casting to PRUint32. - - // For control characters convert from the event ascii code (e.g. 1 for - // control-a) to the ascii code for the key, e.g., 'a' for - // control-a. - - KeySym keysym; - XComposeStatus compose; - unsigned char string_buf[CHAR_BUF_SIZE]; - int len = 0; - - len = XLookupString(xkey, (char *)string_buf, CHAR_BUF_SIZE-1, &keysym, &compose); - if (0 == len) - return 0; - - if (xkey->state & ControlMask) { - if (xkey->state & ShiftMask) { - return (PRUint32)(string_buf[0] + 'A' - 1); - } - else { - return (PRUint32)(string_buf[0] + 'a' - 1); - } - } - if (!isprint(string_buf[0])) { - return 0; - } - else { - return (PRUint32)(string_buf[0]); - } -} - -void -nsAppShell::HandleKeyPressEvent(XEvent *event, nsWidget *aWidget) -{ - char string_buf[CHAR_BUF_SIZE]; - int len = 0; - Window focusWindow = None; - nsWidget *focusWidget = 0; - - // figure out where the real focus should go... - focusWindow = nsWidget::GetFocusWindow(); - if (focusWindow != None) { - focusWidget = nsWidget::GetWidgetForWindow(focusWindow); - } - - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("KeyPress event for window 0x%lx ( 0x%lx focus window )\n", - event->xkey.window, - focusWindow)); - - // don't even bother... - if (focusWidget == 0) { - return; - } - - KeySym keysym = nsKeyCode::ConvertKeyCodeToKeySym(event->xkey.display, - event->xkey.keycode); - - switch (keysym) { - case XK_Alt_L: - case XK_Alt_R: - mAltDown = PR_TRUE; - break; - case XK_Control_L: - case XK_Control_R: - mCtrlDown = PR_TRUE; - break; - case XK_Shift_L: - case XK_Shift_R: - mShiftDown = PR_TRUE; - break; - case XK_Meta_L: - case XK_Meta_R: - mMetaDown = PR_TRUE; - break; - default: - break; - } - - // Don't dispatch events for modifier keys pressed ALONE - if (nsKeyCode::KeyCodeIsModifier(event->xkey.keycode)) - { - return; - } - - nsKeyEvent keyEvent(PR_TRUE, NS_KEY_DOWN, focusWidget); - - XComposeStatus compose; - - len = XLookupString(&event->xkey, string_buf, CHAR_BUF_SIZE-1, &keysym, &compose); - string_buf[len] = '\0'; - - keyEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym); - keyEvent.time = event->xkey.time; - keyEvent.isShift = (event->xkey.state & ShiftMask) ? PR_TRUE : PR_FALSE; - keyEvent.isControl = (event->xkey.state & ControlMask) ? 1 : 0; - keyEvent.isAlt = (event->xkey.state & Mod1Mask) ? 1 : 0; - // I think 'meta' is the same as 'alt' in X11. Is this OK for other systems? - keyEvent.isMeta = (event->xkey.state & Mod1Mask) ? 1 : 0; - - // printf("keysym = %x, keycode = %x, vk = %x\n", - // keysym, - // event->xkey.keycode, - // keyEvent.keyCode); - - PRBool noDefault = focusWidget->DispatchKeyEvent(keyEvent); - - nsKeyEvent pressEvent(PR_TRUE, NS_KEY_PRESS, focusWidget); - pressEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym); - pressEvent.charCode = nsConvertCharCodeToUnicode(&event->xkey); - pressEvent.time = event->xkey.time; - pressEvent.isShift = (event->xkey.state & ShiftMask) ? PR_TRUE : PR_FALSE; - pressEvent.isControl = (event->xkey.state & ControlMask) ? 1 : 0; - pressEvent.isAlt = (event->xkey.state & Mod1Mask) ? 1 : 0; - pressEvent.isMeta = (event->xkey.state & Mod1Mask) ? 1 : 0; - if (noDefault) { // If default prevented on keydown, do same for keypress - pressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT; - } - - focusWidget->DispatchKeyEvent(pressEvent); -} - -void -nsAppShell::HandleKeyReleaseEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("KeyRelease event for window 0x%lx\n", - event->xkey.window)); - - KeySym keysym = nsKeyCode::ConvertKeyCodeToKeySym(event->xkey.display, - event->xkey.keycode); - - switch (keysym) { - case XK_Alt_L: - case XK_Alt_R: - mAltDown = PR_FALSE; - break; - case XK_Control_L: - case XK_Control_R: - mCtrlDown = PR_FALSE; - break; - case XK_Shift_L: - case XK_Shift_R: - mShiftDown = PR_FALSE; - break; - case XK_Meta_L: - case XK_Meta_R: - mMetaDown = PR_FALSE; - break; - default: - break; - } - - // Don't dispatch events for modifier keys pressed ALONE - if (nsKeyCode::KeyCodeIsModifier(event->xkey.keycode)) - { - return; - } - - nsKeyEvent keyEvent(PR_TRUE, NS_KEY_UP, aWidget); - - keyEvent.keyCode = nsKeyCode::ConvertKeySymToVirtualKey(keysym); - keyEvent.time = event->xkey.time; - keyEvent.isShift = event->xkey.state & ShiftMask; - keyEvent.isControl = (event->xkey.state & ControlMask) ? 1 : 0; - keyEvent.isAlt = (event->xkey.state & Mod1Mask) ? 1 : 0; - keyEvent.isMeta = (event->xkey.state & Mod1Mask) ? 1 : 0; - keyEvent.refPoint.x = event->xkey.x; - keyEvent.refPoint.y = event->xkey.y; - - NS_ADDREF(aWidget); - - aWidget->DispatchKeyEvent(keyEvent); - - NS_RELEASE(aWidget); -} - -void -nsAppShell::HandleFocusInEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("FocusIn event for window 0x%lx\n", - event->xfocus.window)); - nsFocusEvent focusEvent(PR_TRUE, NS_GOTFOCUS, aWidget); - - NS_ADDREF(aWidget); - aWidget->DispatchWindowEvent(focusEvent); - NS_RELEASE(aWidget); -} - -void -nsAppShell::HandleFocusOutEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("FocusOut event for window 0x%lx\n", - event->xfocus.window)); - nsFocusEvent focusEvent(PR_TRUE, NS_LOSTFOCUS, aWidget); - - NS_ADDREF(aWidget); - aWidget->DispatchWindowEvent(focusEvent); - NS_RELEASE(aWidget); -} - -/* Identify pointer grab/ungrab events due to window manager activity */ -static inline int -is_wm_ungrab_enter(XCrossingEvent *event) -{ - return (NotifyGrab == event->mode) && - ((NotifyAncestor == event->detail) || - (NotifyVirtual == event->detail)); -} - -static inline int -is_wm_grab_leave(XCrossingEvent *event) -{ - return (NotifyGrab == event->mode) && - ((NotifyAncestor == event->detail) || - (NotifyVirtual == event->detail)); -} - -void -nsAppShell::HandleEnterEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Enter event for window 0x%lx\n", - event->xcrossing.window)); - - if (event->xcrossing.subwindow != None) - return; - - if(is_wm_ungrab_enter(&event->xcrossing)) - return; - - if (mDragging) { - HandleDragEnterEvent(event, aWidget); - } - - nsMouseEvent enterEvent(PR_TRUE, NS_MOUSE_ENTER, aWidget, - nsMouseEvent::eReal); - - enterEvent.time = event->xcrossing.time; - enterEvent.refPoint.x = nscoord(event->xcrossing.x); - enterEvent.refPoint.y = nscoord(event->xcrossing.y); - - // make sure this is in focus. This will do until I rewrite all the - // focus routines. KenF - aWidget->SetFocus(); - - NS_ADDREF(aWidget); - aWidget->DispatchWindowEvent(enterEvent); - NS_RELEASE(aWidget); -} - -void -nsAppShell::HandleLeaveEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Leave event for window 0x%lx\n", - event->xcrossing.window)); - - if (event->xcrossing.subwindow != None) - return; - - if(is_wm_grab_leave(&event->xcrossing)) - return; - - if (mDragging) { - HandleDragLeaveEvent(event, aWidget); - } - - nsMouseEvent leaveEvent(PR_TRUE, NS_MOUSE_EXIT, aWidget, - nsMouseEvent::eReal); - - leaveEvent.time = event->xcrossing.time; - leaveEvent.refPoint.x = nscoord(event->xcrossing.x); - leaveEvent.refPoint.y = nscoord(event->xcrossing.y); - - NS_ADDREF(aWidget); - aWidget->DispatchWindowEvent(leaveEvent); - NS_RELEASE(aWidget); -} - -void nsAppShell::HandleVisibilityNotifyEvent(XEvent *event, nsWidget *aWidget) -{ -#ifdef DEBUG - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("VisibilityNotify event for window 0x%lx ", - event->xfocus.window)); - switch(event->xvisibility.state) { - case VisibilityFullyObscured: - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Fully Obscured\n")); - break; - case VisibilityPartiallyObscured: - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Partially Obscured\n")); - break; - case VisibilityUnobscured: - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Unobscured\n")); - } -#endif - aWidget->SetVisibility(event->xvisibility.state); -} - -void nsAppShell::HandleMapNotifyEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("MapNotify event for window 0x%lx\n", - event->xmap.window)); - // XXX set map status is gone now.. - // aWidget->SetMapStatus(PR_TRUE); -} - -void nsAppShell::HandleUnmapNotifyEvent(XEvent *event, nsWidget *aWidget) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("UnmapNotifyEvent for window 0x%lx\n", - event->xunmap.window)); - // XXX set map status is gone now.. - //aWidget->SetMapStatus(PR_FALSE); -} - -void nsAppShell::HandleClientMessageEvent(XEvent *event, nsWidget *aWidget) -{ - // check to see if it's a WM_DELETE message -#if defined(DEBUG_warren) || defined(DEBUG_quy) - printf("handling client message\n"); -#endif - if (nsWidget::WMProtocolsInitialized) { - if ((Atom)event->xclient.data.l[0] == nsWidget::WMDeleteWindow) { -#ifdef DEBUG - printf("got a delete window event\n"); -#endif /* DEBUG */ - aWidget->OnDeleteWindow(); - } - } -} - -void nsAppShell::HandleSelectionRequestEvent(XEvent *event, nsWidget *aWidget) -{ - nsGUIEvent ev(PR_TRUE, 0, aWidget); - - ev.nativeMsg = (void *)event; - - aWidget->DispatchWindowEvent(ev); -} - -void nsAppShell::HandleDragMotionEvent(XEvent *event, nsWidget *aWidget) { - PRBool currentlyDragging = PR_FALSE; - - nsresult rv; - nsCOMPtr dragService( do_GetService(kCDragServiceCID, &rv) ); - nsCOMPtr dragServiceXlib; - if (NS_SUCCEEDED(rv)) { - dragServiceXlib = do_QueryInterface(dragService); - if (dragServiceXlib) { - dragServiceXlib->IsDragging(¤tlyDragging); - } - } - - if (currentlyDragging) { - dragServiceXlib->UpdatePosition(event->xmotion.x, event->xmotion.y); - - dragService->FireDragEventAtSource(NS_DRAGDROP_DRAG); - - nsMouseEvent mevent(PR_TRUE, NS_DRAGDROP_OVER, aWidget, - nsMouseEvent::eReal); - mevent.refPoint.x = event->xmotion.x; - mevent.refPoint.y = event->xmotion.y; - - NS_ADDREF(aWidget); - aWidget->DispatchMouseEvent(mevent); - NS_RELEASE(aWidget); - } -} - -void nsAppShell::HandleDragEnterEvent(XEvent *event, nsWidget *aWidget) { - PRBool currentlyDragging = PR_FALSE; - - nsresult rv; - nsCOMPtr dragService( do_GetService(kCDragServiceCID, &rv) ); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr dragServiceXlib; - dragServiceXlib = do_QueryInterface(dragService); - if (dragServiceXlib) { - dragServiceXlib->IsDragging(¤tlyDragging); - } - } - - if (currentlyDragging) { - nsMouseEvent enterEvent(PR_TRUE, NS_DRAGDROP_ENTER, aWidget, - nsMouseEvent::eReal); - - enterEvent.refPoint.x = event->xcrossing.x; - enterEvent.refPoint.y = event->xcrossing.y; - - NS_ADDREF(aWidget); - aWidget->DispatchWindowEvent(enterEvent); - NS_RELEASE(aWidget); - } -} - -void nsAppShell::HandleDragLeaveEvent(XEvent *event, nsWidget *aWidget) { - PRBool currentlyDragging = PR_FALSE; - - nsresult rv; - nsCOMPtr dragService( do_GetService(kCDragServiceCID, &rv) ); - - // FIXME: Not sure if currentlyDragging is required. KenF - if (NS_SUCCEEDED(rv)) { - nsCOMPtr dragServiceXlib; - dragServiceXlib = do_QueryInterface(dragService); - if (dragServiceXlib) { - dragServiceXlib->IsDragging(¤tlyDragging); - } - } - - if (currentlyDragging) { - nsMouseEvent leaveEvent(PR_TRUE, NS_DRAGDROP_EXIT, aWidget, - nsMouseEvent::eReal); - - leaveEvent.refPoint.x = event->xcrossing.x; - leaveEvent.refPoint.y = event->xcrossing.y; - - NS_ADDREF(aWidget); - aWidget->DispatchWindowEvent(leaveEvent); - NS_RELEASE(aWidget); - } -} - -void nsAppShell::HandleDragDropEvent(XEvent *event, nsWidget *aWidget) { - PRBool currentlyDragging = PR_FALSE; - - nsresult rv; - nsCOMPtr dragService( do_GetService(kCDragServiceCID, &rv) ); - - // FIXME: Don't think the currentlyDragging check is required. KenF - if (NS_SUCCEEDED(rv)) { - nsCOMPtr dragServiceXlib; - dragServiceXlib = do_QueryInterface(dragService); - if (dragServiceXlib) { - dragServiceXlib->IsDragging(¤tlyDragging); - } - } - - if (currentlyDragging) { - nsMouseEvent mevent(PR_TRUE, NS_DRAGDROP_DROP, aWidget, - nsMouseEvent::eReal); - mevent.refPoint.x = event->xbutton.x; - mevent.refPoint.y = event->xbutton.y; - - NS_IF_ADDREF(aWidget); - aWidget->DispatchMouseEvent(mevent); - NS_IF_RELEASE(aWidget); - - dragService->EndDragSession(); - } -} - -void nsAppShell::ForwardEvent(XEvent *event, nsWidget *aWidget) -{ - nsGUIEvent ev(PR_TRUE, 0, aWidget); - ev.nativeMsg = (void *)event; - - aWidget->DispatchWindowEvent(ev); -} - diff --git a/mozilla/widget/src/xlib/nsAppShell.h b/mozilla/widget/src/xlib/nsAppShell.h deleted file mode 100644 index 0a59ba23da1..00000000000 --- a/mozilla/widget/src/xlib/nsAppShell.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsAppShell_h__ -#define nsAppShell_h__ - -#include "nsIAppShell.h" -#include "nsIEventQueueService.h" -#include "nsWidget.h" -#include "prtime.h" -#include "xlibrgb.h" -#include - -class nsAppShell : public nsIAppShell -{ -public: - nsAppShell(); - virtual ~nsAppShell(); - - NS_DECL_ISUPPORTS - - // nsIAppShellInterface - - NS_IMETHOD Create(int* argc, char ** argv); - virtual nsresult Run(); - NS_IMETHOD Spinup(); - NS_IMETHOD Spindown(); - NS_IMETHOD ListenToEventQueue(nsIEventQueue *aQueue, PRBool aListen); - NS_IMETHOD GetNativeEvent(PRBool &aRealEvent, void *&aEvent); - NS_IMETHOD DispatchNativeEvent(PRBool aRealEvent, void *aEvent); - - NS_IMETHOD Exit(); - virtual void * GetNativeData(PRUint32 aDataType); - static void DispatchXEvent(XEvent *event); - /* |xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE)| would be the official - * way - but |nsAppShell::GetXlibRgbHandle()| one is little bit faster... :-) - */ - static XtAppContext mAppContext; - static XlibRgbHandle *GetXlibRgbHandle() { return mXlib_rgb_handle; } - static Display *mDisplay; - private: - static XlibRgbHandle *mXlib_rgb_handle; - - static void HandleButtonEvent(XEvent *event, nsWidget *aWidget); - static void HandleMotionNotifyEvent(XEvent *event, nsWidget *aWidget); - static void HandleExposeEvent(XEvent *event, nsWidget *aWidget); - static void HandleConfigureNotifyEvent(XEvent *event, nsWidget *aWidget); - static void HandleKeyPressEvent(XEvent *event, nsWidget *aWidget); - static void HandleKeyReleaseEvent(XEvent *event, nsWidget *aWidget); - static void HandleFocusInEvent(XEvent *event, nsWidget *aWidget); - static void HandleFocusOutEvent(XEvent *event, nsWidget *aWidget); - static void HandleVisibilityNotifyEvent(XEvent *event, nsWidget *aWidget); - static void HandleMapNotifyEvent(XEvent *event, nsWidget *aWidget); - static void HandleUnmapNotifyEvent(XEvent *event, nsWidget *aWidget); - static void HandleEnterEvent(XEvent *event, nsWidget *aWidget); - static void HandleLeaveEvent(XEvent *event, nsWidget *aWidget); - static void HandleClientMessageEvent(XEvent *event, nsWidget *aWidget); - static void HandleSelectionRequestEvent(XEvent *event, nsWidget *aWidget); - static void HandleDragMotionEvent(XEvent *event, nsWidget *aWidget); - static void HandleDragEnterEvent(XEvent *event, nsWidget *aWidget); - static void HandleDragLeaveEvent(XEvent *event, nsWidget *aWidget); - static void HandleDragDropEvent(XEvent *event, nsWidget *aWidget); - static void ForwardEvent(XEvent *event, nsWidget *aWidget); - static PRInt16 mClicks; - static PRUint16 mClickedButton; - static PRTime mClickTime; - static PRPackedBool mClicked; - static PRPackedBool mDragging; - static PRPackedBool mAltDown; - static PRPackedBool mShiftDown; - static PRPackedBool mCtrlDown; - static PRPackedBool mMetaDown; - static PRPackedBool DieAppShellDie; - -protected: - nsCOMPtr mEventQueue; -}; - -#endif /* !nsAppShell_h__ */ diff --git a/mozilla/widget/src/xlib/nsBidiKeyboard.cpp b/mozilla/widget/src/xlib/nsBidiKeyboard.cpp deleted file mode 100644 index c1e4b61b7b4..00000000000 --- a/mozilla/widget/src/xlib/nsBidiKeyboard.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is IBM code. - * - * The Initial Developer of the Original Code is - * IBM. Portions created by IBM are Copyright (C) International Business Machines Corporation, 2000. All Rights Reserved. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Simon Montagu - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsBidiKeyboard.h" - -NS_IMPL_ISUPPORTS1(nsBidiKeyboard, nsIBidiKeyboard) - -nsBidiKeyboard::nsBidiKeyboard() : nsIBidiKeyboard() -{ -} - -nsBidiKeyboard::~nsBidiKeyboard() -{ -} - -NS_IMETHODIMP nsBidiKeyboard::IsLangRTL(PRBool *aIsRTL) -{ - *aIsRTL = PR_FALSE; - // XXX Insert platform specific code to determine keyboard direction - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) -{ - // XXX Insert platform specific code to set keyboard language - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/mozilla/widget/src/xlib/nsBidiKeyboard.h b/mozilla/widget/src/xlib/nsBidiKeyboard.h deleted file mode 100644 index 3011affdd16..00000000000 --- a/mozilla/widget/src/xlib/nsBidiKeyboard.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is IBM code. - * - * The Initial Developer of the Original Code is - * IBM. Portions created by IBM are Copyright (C) International Business Machines Corporation, 2000. All Rights Reserved. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Simon Montagu - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsBidiKeyboard -#define __nsBidiKeyboard -#include "nsIBidiKeyboard.h" - -class nsBidiKeyboard : public nsIBidiKeyboard -{ -public: - NS_DECL_ISUPPORTS - NS_DECL_NSIBIDIKEYBOARD - - nsBidiKeyboard(); - virtual ~nsBidiKeyboard(); - /* additional members */ -}; - - -#endif // __nsBidiKeyboard diff --git a/mozilla/widget/src/xlib/nsClipboard.cpp b/mozilla/widget/src/xlib/nsClipboard.cpp deleted file mode 100644 index 814349957b5..00000000000 --- a/mozilla/widget/src/xlib/nsClipboard.cpp +++ /dev/null @@ -1,437 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * Dan Rosen - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* TODO: - * Currently this only supports the transfer of TEXT! FIXME - */ - -#include "nsAppShell.h" -#include "nsClipboard.h" - -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsISupportsArray.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" - -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" -#include "nsWidgetsCID.h" -#include "nsXPIDLString.h" -#include "nsPrimitiveHelpers.h" - -#include "nsTextFormatter.h" - -#include -#include - -#include "xlibrgb.h" - - -#include "nsIServiceManager.h" -#include "nsICharsetConverterManager.h" -// unicode conversion -# include "nsIPlatformCharset.h" - - -// The class statics: -nsITransferable *nsClipboard::mTransferable = nsnull; -Window nsClipboard::sWindow; -Display *nsClipboard::sDisplay; - -#if defined(DEBUG_mcafee) || defined(DEBUG_pavlov) -#define DEBUG_CLIPBOARD -#endif - -NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard) - -nsClipboard::nsClipboard() { - sDisplay = xxlib_rgb_get_display(nsAppShell::GetXlibRgbHandle()); - - Init(); -} - -nsClipboard::~nsClipboard() { - NS_IF_RELEASE(sWidget); -} - -/*static*/ void nsClipboard::Shutdown() { - NS_IF_RELEASE(mTransferable); -} - -// Initialize the clipboard and create a nsWidget for communications - -void nsClipboard::Init() { - NS_ASSERTION(!sWidget, "already initialized"); - - sWidget = new nsWidget(); - if (!sWidget) return; - NS_ADDREF(sWidget); - - const nsRect rect(0,0,100,100); - - sWidget->Create((nsIWidget *)nsnull, rect, Callback, - (nsIDeviceContext *)nsnull, (nsIAppShell *)nsnull, - (nsIToolkit *)nsnull, (nsWidgetInitData *)nsnull); - sWindow = (Window)sWidget->GetNativeData(NS_NATIVE_WINDOW); - - XSelectInput(sDisplay, sWindow, 0x0fffff); -} - -// This is the callback function for our nsWidget. It is given the -// XEvent from nsAppShell. -// FIXME: We _should_ assign mTransferable here depending on if its a -// selectionrequest -nsEventStatus PR_CALLBACK nsClipboard::Callback(nsGUIEvent *event) { - XEvent *ev = (XEvent *)event->nativeMsg; - - /* may be nsnull in the |event->message == NS_DESTROY| case... */ - if(ev == nsnull) - return nsEventStatus_eIgnore; - - // Check the event type - if (ev->type == SelectionRequest) { - if (mTransferable == nsnull) { - fprintf(stderr, "nsClipboard::Callback: null transferable\n"); - return nsEventStatus_eIgnore; - } - - // Get the data from the Transferable - - const char *dataFlavor = kUnicodeMime; - nsCOMPtr genDataWrapper; - nsresult rv; - PRUint32 dataLength; - void *data; - data = malloc(16384); - rv = mTransferable->GetTransferData(dataFlavor, - getter_AddRefs(genDataWrapper), - &dataLength); - nsPrimitiveHelpers::CreateDataFromPrimitive(dataFlavor, genDataWrapper, - &data, dataLength); - if (NS_SUCCEEDED(rv) && data && dataLength) { - char *plainText = nsnull; - PRUnichar* unicodeData = NS_REINTERPRET_CAST(PRUnichar*, data); - PRInt32 plainLen = 0; - nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText(unicodeData, - dataLength/2, - &plainText, - &plainLen); - if (data) { - free(data); - data = plainText; - dataLength = plainLen; - } - - // Set the window property to contain the data - XChangeProperty(sDisplay, - ev->xselectionrequest.requestor, - ev->xselectionrequest.property, - ev->xselectionrequest.target, - 8, PropModeReplace, - (unsigned char *)data, dataLength); - - // Send the requestor a SelectionNotify event - XEvent aEvent; - aEvent.type = SelectionNotify; - aEvent.xselection.serial = ev->xselectionrequest.serial; - aEvent.xselection.display = ev->xselectionrequest.display; - aEvent.xselection.requestor = ev->xselectionrequest.requestor; - aEvent.xselection.selection = ev->xselectionrequest.selection; - aEvent.xselection.target = ev->xselectionrequest.target; - aEvent.xselection.property = ev->xselectionrequest.property; - aEvent.xselection.time = CurrentTime; - XSendEvent(sDisplay, ev->xselectionrequest.requestor, 1, 0, &aEvent); - } - } - return nsEventStatus_eIgnore; -} - -nsITransferable *nsClipboard::GetTransferable(PRInt32 aWhichClipboard) -{ - nsITransferable *transferable = nsnull; - switch (aWhichClipboard) - { - case kGlobalClipboard: - transferable = mGlobalTransferable; - break; - case kSelectionClipboard: - transferable = mSelectionTransferable; - break; - } - return transferable; -} - -// Ripped from GTK. Does the writing to the appropriate transferable. -// Does *some* flavour stuff, but not all!!! -// FIXME: Needs to be completed. -NS_IMETHODIMP nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard) -{ - // bomb out if we cannot get ownership. - if (XSetSelectionOwner(sDisplay, XA_PRIMARY, sWindow, CurrentTime)) - if (XGetSelectionOwner(sDisplay, XA_PRIMARY) != sWindow) { - fprintf(stderr, "nsClipboard::SetData: Cannot get ownership\n"); - return NS_ERROR_FAILURE; - } - - // get flavor list that includes all flavors that can be written (including ones - // obtained through conversion) - nsCOMPtr flavorList; - nsCOMPtr transferable(GetTransferable(aWhichClipboard)); - - // FIXME Need to make sure mTransferable has reference to selectionclipboard. - // This solves the problem with copying to an external app. - // but cannot be sure if its fully correct until menu copy/paste is working. - if (aWhichClipboard == kSelectionClipboard) { - NS_IF_RELEASE(mTransferable); - mTransferable = transferable; - NS_IF_ADDREF(mTransferable); - } - - // make sure we have a good transferable - if (nsnull == transferable) { -#ifdef DEBUG_faulkner - fprintf(stderr, "nsClipboard::SetNativeClipboardData(): no transferable!\n"); -#endif /* DEBUG_faulkner */ - return NS_ERROR_FAILURE; - } - - nsresult errCode = transferable->FlavorsTransferableCanExport ( getter_AddRefs(flavorList) ); - if ( NS_FAILED(errCode) ) - return NS_ERROR_FAILURE; - - PRUint32 cnt; - flavorList->Count(&cnt); - for ( PRUint32 i=0; i genericFlavor; - flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) ); - nsCOMPtr currentFlavor ( do_QueryInterface(genericFlavor) ); - if ( currentFlavor ) { - nsXPIDLCString flavorStr; - currentFlavor->ToString(getter_Copies(flavorStr)); - - // FIXME Do we need to register this in XLIB? KenF - // add these types as selection targets - // RegisterFormat(flavorStr, selectionAtom); - } - } - - mIgnoreEmptyNotification = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP nsClipboard::SetData(nsITransferable *aTransferable, - nsIClipboardOwner *anOwner, - PRInt32 aWhichClipboard) -{ - if (XSetSelectionOwner(sDisplay, XA_PRIMARY, sWindow, CurrentTime)) - if (XGetSelectionOwner(sDisplay, XA_PRIMARY) != sWindow) { - fprintf(stderr, "nsClipboard::SetData: Cannot get ownership\n"); - return NS_ERROR_FAILURE; - } - - // Check from GTK. (must double check this!!) - if ((aTransferable == mGlobalTransferable.get() && - anOwner == mGlobalOwner.get() && - aWhichClipboard == kGlobalClipboard ) || - (aTransferable == mSelectionTransferable.get() && - anOwner == mSelectionOwner.get() && - aWhichClipboard == kSelectionClipboard) - ) - { - return NS_OK; - } - - EmptyClipboard(aWhichClipboard); - - switch(aWhichClipboard) { - case kSelectionClipboard: - mSelectionOwner = anOwner; - mSelectionTransferable = aTransferable; - break; - case kGlobalClipboard: - mGlobalOwner = anOwner; - mGlobalTransferable = aTransferable; - break; - } - - return SetNativeClipboardData(aWhichClipboard); -} - -NS_IMETHODIMP nsClipboard::GetData(nsITransferable *aTransferable, - PRInt32 aWhichClipboard) -{ - unsigned char *data = 0; - unsigned long bytes = 0; - Bool only_if_exists; - Atom data_atom; - int i; - - if (aTransferable == nsnull) { - fprintf(stderr, "nsClipboard::GetData: NULL transferable\n"); - return NS_ERROR_FAILURE; - } - - - // Get which transferable we should use. - NS_IF_RELEASE(mTransferable); - mTransferable = GetTransferable(aWhichClipboard); - NS_ASSERTION(!mTransferable,"mTransferable is null!! see bug 80181"); - if (!mTransferable) return NS_ERROR_FAILURE; - NS_ADDREF(mTransferable); - - // If we currently own the selection, we will handle the paste - // internally, otherwise get the data from the X server - - if (XGetSelectionOwner(sDisplay, XA_PRIMARY) == sWindow) { - const char *dataFlavor = kUnicodeMime; - nsCOMPtr genDataWrapper; - nsresult rv; - PRUint32 dataLength; - nsCOMPtr trans = do_QueryInterface(aTransferable); - if (!trans) - return NS_ERROR_FAILURE; - - rv = mTransferable->GetTransferData(dataFlavor, - getter_AddRefs(genDataWrapper), - &dataLength); - if (NS_SUCCEEDED(rv)) { - rv = trans->SetTransferData(dataFlavor, - genDataWrapper, - dataLength); - } - } else { - data_atom = XInternAtom(sDisplay, "DATA_ATOM", only_if_exists = False); - XConvertSelection(sDisplay, XA_PRIMARY, XA_STRING, data_atom, - sWindow, CurrentTime); - - // Wait for the SelectNotify event - mBlocking = PR_TRUE; - XEvent event; - for (i=0; (mBlocking == PR_TRUE) && i<10000; i++) { - if (XPending(sDisplay)) { - XNextEvent(sDisplay, &event); - if (event.type == SelectionNotify) { - mBlocking = PR_FALSE; - } - } - } - // If we got the event, mBlocking will still be true. - // So, get the data. - if (mBlocking == PR_FALSE) { - Atom type; - int format; - unsigned long items; - if (event.xselection.property != None) { - XGetWindowProperty(sDisplay, event.xselection.requestor, - event.xselection.property, 0, 16384/4, - 0, AnyPropertyType, - &type, &format, &items, &bytes, &data); - // XXX could return BadValue or BadWindow or ... - bytes = strlen((char *)data); - } - } - mBlocking = PR_FALSE; - - // Place the data in the transferable - PRInt32 length = 0; - PRUnichar *testing = nsnull; - const char *constData = ""; - if (data) - constData = (char*) data; - nsPrimitiveHelpers::ConvertPlatformPlainTextToUnicode(constData, - (PRInt32)bytes, - &testing, - &length); - - nsCOMPtr genDataWrapper; - nsPrimitiveHelpers::CreatePrimitiveForData("text/unicode", - testing, length, - getter_AddRefs(genDataWrapper)); - - aTransferable->SetTransferData("text/unicode", - genDataWrapper, - length); - if (data) - XFree(data); - free(testing); - } - return NS_OK; -} - -NS_IMETHODIMP nsClipboard::EmptyClipboard(PRInt32 aWhichClipboard) -{ - if (mIgnoreEmptyNotification) { - return NS_OK; - } - - switch(aWhichClipboard) { - case kSelectionClipboard: - if (mSelectionOwner) { - mSelectionOwner->LosingOwnership(mSelectionTransferable); - mSelectionOwner = nsnull; - } - mSelectionTransferable = nsnull; - break; - case kGlobalClipboard: - if (mGlobalOwner) { - mGlobalOwner->LosingOwnership(mGlobalTransferable); - mGlobalOwner = nsnull; - } - mGlobalTransferable = nsnull; - break; - } - return NS_OK; -} - -NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(nsISupportsArray *aFlavorList, - PRInt32 aWhichClipboard, - PRBool *_retval) { - *_retval = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP nsClipboard::SupportsSelectionClipboard(PRBool *_retval) { - NS_ENSURE_ARG_POINTER(_retval); - - *_retval = PR_TRUE; // we support the selection clipboard on unix. - return NS_OK; -} diff --git a/mozilla/widget/src/xlib/nsClipboard.h b/mozilla/widget/src/xlib/nsClipboard.h deleted file mode 100644 index 1dbb2ef6aa5..00000000000 --- a/mozilla/widget/src/xlib/nsClipboard.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsClipboard_h__ -#define nsClipboard_h__ - -#include "nsIClipboard.h" -#include "nsITransferable.h" -#include "nsIClipboardOwner.h" -#include -#include "nsWidget.h" - -#include -#include - -class nsITransferable; -class nsIClipboardOwner; -class nsIWidget; - -/** - * Native Xlib Clipboard wrapper - */ - -class nsClipboard : public nsIClipboard -{ - -public: - nsClipboard(); - virtual ~nsClipboard(); - - static void Shutdown(); - - //nsISupports - NS_DECL_ISUPPORTS - - // nsIClipboard - NS_DECL_NSICLIPBOARD - -protected: - void Init(void); - - static nsEventStatus PR_CALLBACK Callback(nsGUIEvent *event); - PRBool mIgnoreEmptyNotification; - inline nsITransferable *GetTransferable(PRInt32 aWhichClipboard); - NS_IMETHOD SetNativeClipboardData(PRInt32 aWhichClipboard); - -private: - static nsITransferable* mTransferable; // strong reference - nsCOMPtr mSelectionOwner; - nsCOMPtr mGlobalOwner; - nsCOMPtr mSelectionTransferable; - nsCOMPtr mGlobalTransferable; - - - // Used for communicating pasted data - // from the asynchronous X routines back to a blocking paste: - PRBool mBlocking; - - static Window sWindow; - nsWidget *sWidget; - static Display *sDisplay; - -}; - -#endif // nsClipboard_h__ diff --git a/mozilla/widget/src/xlib/nsDragService.cpp b/mozilla/widget/src/xlib/nsDragService.cpp deleted file mode 100644 index 13dbea09876..00000000000 --- a/mozilla/widget/src/xlib/nsDragService.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim:ts=2:et:sw=2 - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard . - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher Blizzard - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsAppShell.h" -#include "nsDragService.h" -#include "nsWidgetsCID.h" -#include "nsIWidget.h" -#include "nsIServiceManager.h" -#include "nsXPIDLString.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsPrimitiveHelpers.h" -#include "nsString.h" - -#include - -#include "xlibrgb.h" - -NS_IMPL_ISUPPORTS_INHERITED1(nsDragService, - nsBaseDragService, - nsIDragSessionXlib) - -/* drag bitmaps */ -static const unsigned char drag_bitmap[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, - 0x00, 0xc0, 0x02, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x38, 0x04, 0x00, - 0x00, 0x0e, 0x0c, 0x00, 0x80, 0x03, 0x08, 0x00, 0xe0, 0x00, 0x18, 0x00, - 0xb0, 0x00, 0x30, 0x00, 0x20, 0x01, 0x60, 0x00, 0x20, 0x02, 0xc0, 0x00, - 0x20, 0x04, 0x80, 0x00, 0x20, 0x02, 0x80, 0x01, 0x20, 0x01, 0x00, 0x03, - 0xa0, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, 0x0c, 0x60, 0x00, 0x00, 0x08, - 0x20, 0x00, 0x00, 0x0c, 0x60, 0x00, 0x00, 0x03, 0x40, 0x00, 0x80, 0x01, - 0xc0, 0x00, 0xe0, 0x00, 0x80, 0x00, 0x30, 0x00, 0x80, 0x01, 0x0c, 0x00, - 0x00, 0x01, 0x06, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x82, 0x01, 0x00, - 0x00, 0x64, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char drag_mask[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, - 0x00, 0xc0, 0x03, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xf8, 0x07, 0x00, - 0x00, 0xfe, 0x0f, 0x00, 0x80, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0x1f, 0x00, - 0xf0, 0xff, 0x3f, 0x00, 0xe0, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0x00, - 0xe0, 0xff, 0xff, 0x00, 0xe0, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0x03, - 0xe0, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x0f, - 0xe0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, - 0xc0, 0xff, 0xff, 0x00, 0x80, 0xff, 0x3f, 0x00, 0x80, 0xff, 0x0f, 0x00, - 0x00, 0xff, 0x07, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0xfe, 0x01, 0x00, - 0x00, 0x7c, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -nsWidget *nsDragService::sWidget = nsnull; -Window nsDragService::sWindow; -XlibRgbHandle *nsDragService::sXlibRgbHandle; -Display *nsDragService::sDisplay; -PRBool nsDragService::mDragging = PR_FALSE; - -nsDragService::nsDragService() -{ - sXlibRgbHandle = nsAppShell::GetXlibRgbHandle(); - sDisplay = xxlib_rgb_get_display(sXlibRgbHandle); - mCanDrop = PR_FALSE; - sWindow = None; -} - -nsDragService::~nsDragService() -{ -} - -// nsIDragService -NS_IMETHODIMP nsDragService::InvokeDragSession (nsIDOMNode *aDOMNode, - nsISupportsArray *aArrayTransferables, - nsIScriptableRegion *aRegion, - PRUint32 aActionType) -{ - nsBaseDragService::InvokeDragSession(aDOMNode, aArrayTransferables, - aRegion, aActionType); - - /* no data - no dnd */ - if (!aArrayTransferables) - return NS_ERROR_INVALID_ARG; - - nsresult rv; - PRUint32 numItemsToDrag = 0; - - mSourceDataItems = aArrayTransferables; - - rv = mSourceDataItems->Count(&numItemsToDrag); - if (!numItemsToDrag) - return NS_ERROR_FAILURE; - - mDragging = PR_TRUE; - - CreateDragCursor(aActionType); - - return NS_OK; -} - -NS_IMETHODIMP nsDragService::StartDragSession() -{ - mDragging = PR_TRUE; - - return nsBaseDragService::StartDragSession(); -} - -NS_IMETHODIMP nsDragService::EndDragSession(PRBool aDoneDrag) -{ - if (sWindow) { - XDestroyWindow(sDisplay, sWindow); - sWindow = 0; - } - mDragging = PR_FALSE; - - return nsBaseDragService::EndDragSession(aDoneDrag); -} - -// nsIDragSession - -// For some reason we need this, but GTK does not. Hmmm... -NS_IMETHODIMP nsDragService::GetCurrentSession(nsIDragSession **aSession) -{ - if (!aSession) - return NS_ERROR_FAILURE; - - if (!mDragging) { - *aSession = nsnull; - return NS_OK; - } - - *aSession = (nsIDragSession *)this; - NS_ADDREF(*aSession); - return NS_OK; -} - -NS_IMETHODIMP nsDragService::SetCanDrop(PRBool aCanDrop) -{ - mCanDrop = aCanDrop; - return NS_OK; -} - -NS_IMETHODIMP nsDragService::GetCanDrop(PRBool *aCanDrop) -{ - *aCanDrop = mCanDrop; - return NS_OK; -} - -NS_IMETHODIMP nsDragService::GetNumDropItems(PRUint32 *aNumItems) -{ - mSourceDataItems->Count(aNumItems); - return NS_OK; -} - -NS_IMETHODIMP nsDragService::GetData(nsITransferable *aTransferable, PRUint32 anItemIndex) -{ - if (!aTransferable) - return NS_ERROR_INVALID_ARG; - - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr flavorList; - rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList)); - if (NS_FAILED(rv)) - return rv; - - PRUint32 cnt, i; - flavorList->Count (&cnt); - - for (i = 0; i < cnt; ++i) { - nsCAutoString foundFlavor; - nsCOMPtr genericWrapper; - - flavorList->GetElementAt(i, getter_AddRefs(genericWrapper)); - nsCOMPtr currentFlavor; - currentFlavor = do_QueryInterface(genericWrapper); - - if (currentFlavor) { - nsXPIDLCString flavorStr; - currentFlavor->ToString(getter_Copies(flavorStr)); - foundFlavor = nsCAutoString(flavorStr); - -#if 0 - g_print("Looking for data in type %s\n", - NS_STATIC_CAST(const char*, flavorStr)); -#endif - - /* set the data */ - nsCOMPtr genItem; - mSourceDataItems->GetElementAt(anItemIndex, getter_AddRefs(genItem)); - - nsCOMPtr item(do_QueryInterface(genItem)); - nsCOMPtr data; - PRUint32 dataLen = 0; - - item->GetTransferData(foundFlavor.get(), getter_AddRefs(data), &dataLen); - aTransferable->SetTransferData(foundFlavor.get(), data, dataLen); - } - } - - EndDragSession(PR_TRUE); - - return NS_OK; -} - -NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char *aDataFlavor, PRBool *_retval) -{ - /* XXX Please implement this - for now - support all flavors */ - *_retval = PR_TRUE; - return NS_OK; -} - -// nsIDragSessionXlib - -NS_IMETHODIMP nsDragService::IsDragging(PRBool *result) { - *result = mDragging; - return NS_OK; -} - -NS_IMETHODIMP nsDragService::UpdatePosition(PRInt32 x, PRInt32 y) -{ - if (sWindow) { - Window aRoot, aChild; - int cx, cy; - unsigned int mask; - XQueryPointer(sDisplay, sWindow, &aRoot, &aChild, &x, &y, &cx, &cy, &mask); - XMoveWindow(sDisplay, sWindow, x, y); - } - return NS_OK; -} - -void nsDragService::CreateDragCursor(PRUint32 aActionType) -{ - if (sWindow == None) { - Pixmap aPixmap; - Pixmap aShapeMask; - XSetWindowAttributes wattr; - unsigned long wattr_mask; - XWMHints wmHints; - int depth; - Screen *screen = xxlib_rgb_get_screen(sXlibRgbHandle); - int screennum = XScreenNumberOfScreen(screen); - - wattr.override_redirect = True; - wattr.background_pixel = XWhitePixel(sDisplay, screennum); - wattr.border_pixel = XBlackPixel(sDisplay, screennum); - wattr.colormap = xxlib_rgb_get_cmap(sXlibRgbHandle); - wattr_mask = CWOverrideRedirect | CWBorderPixel | CWBackPixel; - if (wattr.colormap) - wattr_mask |= CWColormap; - - depth = xxlib_rgb_get_depth(sXlibRgbHandle); - - /* make a window off-screen at -64, -64 */ - sWindow = XCreateWindow(sDisplay, XRootWindowOfScreen(screen), - -64, -64, 32, 32, 0, depth, - InputOutput, xxlib_rgb_get_visual(sXlibRgbHandle), - wattr_mask, &wattr); - - aPixmap = XCreatePixmapFromBitmapData(sDisplay, sWindow, - (char *)drag_bitmap, - 32, 32, 0x0, 0xffffffff, depth); - - aShapeMask = XCreatePixmapFromBitmapData(sDisplay, sWindow, - (char *)drag_mask, - 32, 32, 0xffffffff, 0x0, 1); - - wmHints.flags = StateHint; - wmHints.initial_state = NormalState; - XSetWMProperties(sDisplay, sWindow, nsnull, nsnull, nsnull, 0, nsnull, - &wmHints, nsnull); - XSetTransientForHint(sDisplay, sWindow, sWindow); - XShapeCombineMask(sDisplay, sWindow, ShapeClip, 0, 0, - aShapeMask, ShapeSet); - XShapeCombineMask(sDisplay, sWindow, ShapeBounding, 0, 0, - aShapeMask, ShapeSet); - XSetWindowBackgroundPixmap(sDisplay, sWindow, aPixmap); - XMapWindow(sDisplay, sWindow); - } -} diff --git a/mozilla/widget/src/xlib/nsDragService.h b/mozilla/widget/src/xlib/nsDragService.h deleted file mode 100644 index f809255f2d7..00000000000 --- a/mozilla/widget/src/xlib/nsDragService.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Christopher Blizzard . - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Christopher Blizzard - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDragService_h__ -#define nsDragService_h__ - -#include "nsBaseDragService.h" -#include "nsIDragService.h" -#include "nsIDragSessionXlib.h" -#include "nsGUIEvent.h" -#include "nsIWidget.h" -#include "nsWidget.h" - -/** - * xlib shell based on gtk - */ - -class nsDragService : public nsBaseDragService, public nsIDragSessionXlib -{ - -public: - - NS_DECL_ISUPPORTS_INHERITED - - nsDragService(); - virtual ~nsDragService(); - - // nsIDragService - NS_IMETHOD InvokeDragSession (nsIDOMNode *aDOMNode, - nsISupportsArray * anArrayTransferables, - nsIScriptableRegion * aRegion, - PRUint32 aActionType); - NS_IMETHOD StartDragSession(); - NS_IMETHOD EndDragSession(PRBool aDoneDrag); - - // nsIDragSession - NS_IMETHOD GetCurrentSession (nsIDragSession **aSession); - NS_IMETHOD SetCanDrop (PRBool aCanDrop); - NS_IMETHOD GetCanDrop (PRBool *aCanDrop); - NS_IMETHOD GetNumDropItems (PRUint32 * aNumItems); - NS_IMETHOD GetData (nsITransferable * aTransferable, PRUint32 anItemIndex); - NS_IMETHOD IsDataFlavorSupported (const char *aDataFlavor, PRBool *_retval); - - //nsIDragSessionXlib - NS_IMETHOD IsDragging(PRBool *result); - NS_IMETHOD UpdatePosition(PRInt32 x, PRInt32 y); - -protected: - static nsEventStatus PR_CALLBACK Callback(nsGUIEvent *event); - -private: - static nsWidget *sWidget; - static Window sWindow; - static XlibRgbHandle *sXlibRgbHandle; - static Display *sDisplay; - static PRBool mDragging; - PRBool mCanDrop; - - nsWidget *mDropWidget; - nsCOMPtr mSourceDataItems; - - void CreateDragCursor(PRUint32 aActionType); -}; - -#endif // nsDragService_h__ diff --git a/mozilla/widget/src/xlib/nsKeyCode.cpp b/mozilla/widget/src/xlib/nsKeyCode.cpp deleted file mode 100644 index fb5ba4783b9..00000000000 --- a/mozilla/widget/src/xlib/nsKeyCode.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsKeyCode.h" - -#include -#include -#include -#include - -#include "nsGUIEvent.h" // For NS_VK - -struct nsKeyConverter -{ - int vkCode; // Platform independent key code - unsigned int keysym; // XK keysym key code -}; - -struct nsKeyConverter nsKeycodes[] = -{ - { NS_VK_CANCEL, XK_Cancel}, - { NS_VK_BACK, XK_BackSpace}, - { NS_VK_TAB, XK_Tab}, -#ifdef XK_ISO_Left_Tab - { NS_VK_TAB, XK_ISO_Left_Tab }, // SunOS 5.5.1 doesn't have it. -#endif - { NS_VK_CLEAR, XK_Clear}, - { NS_VK_RETURN, XK_Return}, - { NS_VK_ENTER, XK_KP_Enter}, - { NS_VK_SHIFT, XK_Shift_L}, - { NS_VK_SHIFT, XK_Shift_R}, - { NS_VK_CONTROL, XK_Control_L}, - { NS_VK_CONTROL, XK_Control_R}, - { NS_VK_ALT, XK_Alt_L}, - { NS_VK_ALT, XK_Alt_R}, - { NS_VK_PAUSE, XK_Pause}, - { NS_VK_CAPS_LOCK, XK_Caps_Lock}, - { NS_VK_ESCAPE, XK_Escape}, - { NS_VK_SPACE, XK_KP_Space}, - { NS_VK_SPACE, XK_space}, - { NS_VK_PAGE_UP, XK_Page_Up}, - { NS_VK_PAGE_UP, XK_KP_Page_Up}, - { NS_VK_PAGE_DOWN, XK_Page_Down}, - { NS_VK_PAGE_DOWN, XK_KP_Page_Down}, - { NS_VK_END, XK_End}, - { NS_VK_END, XK_KP_End}, - { NS_VK_HOME, XK_Home}, - { NS_VK_HOME, XK_KP_Home}, - { NS_VK_LEFT, XK_Left}, - { NS_VK_LEFT, XK_KP_Left}, - { NS_VK_UP, XK_Up}, - { NS_VK_UP, XK_KP_Up}, - { NS_VK_RIGHT, XK_Right}, - { NS_VK_RIGHT, XK_KP_Right}, - { NS_VK_DOWN, XK_Down}, - { NS_VK_DOWN, XK_KP_Down}, - { NS_VK_PRINTSCREEN, XK_Print}, - { NS_VK_INSERT, XK_Insert}, - { NS_VK_INSERT, XK_KP_Insert}, - { NS_VK_DELETE, XK_Delete}, - { NS_VK_DELETE, XK_KP_Delete}, - { NS_VK_0, XK_0}, - { NS_VK_1, XK_1}, - { NS_VK_2, XK_2}, - { NS_VK_3, XK_3}, - { NS_VK_4, XK_4}, - { NS_VK_5, XK_5}, - { NS_VK_6, XK_6}, - { NS_VK_7, XK_7}, - { NS_VK_8, XK_8}, - { NS_VK_9, XK_9}, - { NS_VK_SEMICOLON, XK_semicolon}, - { NS_VK_EQUALS, XK_equal}, - { NS_VK_NUMPAD0, XK_KP_0}, - { NS_VK_NUMPAD1, XK_KP_1}, - { NS_VK_NUMPAD2, XK_KP_2}, - { NS_VK_NUMPAD3, XK_KP_3}, - { NS_VK_NUMPAD4, XK_KP_4}, - { NS_VK_NUMPAD5, XK_KP_5}, - { NS_VK_NUMPAD6, XK_KP_6}, - { NS_VK_NUMPAD7, XK_KP_7}, - { NS_VK_NUMPAD8, XK_KP_8}, - { NS_VK_NUMPAD9, XK_KP_9}, - { NS_VK_MULTIPLY, XK_KP_Multiply}, - { NS_VK_ADD, XK_KP_Add}, - { NS_VK_SEPARATOR, XK_KP_Separator}, - { NS_VK_SUBTRACT, XK_KP_Subtract}, - { NS_VK_DECIMAL, XK_KP_Decimal}, - { NS_VK_DIVIDE, XK_KP_Divide}, - { NS_VK_F1, XK_F1}, - { NS_VK_F2, XK_F2}, - { NS_VK_F3, XK_F3}, - { NS_VK_F4, XK_F4}, - { NS_VK_F5, XK_F5}, - { NS_VK_F6, XK_F6}, - { NS_VK_F7, XK_F7}, - { NS_VK_F8, XK_F8}, - { NS_VK_F9, XK_F9}, - { NS_VK_F10, XK_F10}, - { NS_VK_F11, XK_F11}, - { NS_VK_F12, XK_F12}, - { NS_VK_F13, XK_F13}, - { NS_VK_F14, XK_F14}, - { NS_VK_F15, XK_F15}, - { NS_VK_F16, XK_F16}, - { NS_VK_F17, XK_F17}, - { NS_VK_F18, XK_F18}, - { NS_VK_F19, XK_F19}, - { NS_VK_F20, XK_F20}, - { NS_VK_F21, XK_F21}, - { NS_VK_F22, XK_F22}, - { NS_VK_F23, XK_F23}, - { NS_VK_F24, XK_F24}, - { NS_VK_NUM_LOCK, XK_Num_Lock}, - { NS_VK_SCROLL_LOCK, XK_Scroll_Lock}, - { NS_VK_COMMA, XK_comma}, - { NS_VK_PERIOD, XK_period}, - { NS_VK_SLASH, XK_slash}, - { NS_VK_BACK_QUOTE, XK_grave}, - { NS_VK_OPEN_BRACKET, XK_bracketleft}, - { NS_VK_BACK_SLASH, XK_backslash}, - { NS_VK_CLOSE_BRACKET, XK_bracketright}, - { NS_VK_QUOTE, XK_apostrophe} -}; - -PRInt32 -nsKeyCode::ConvertKeySymToVirtualKey(KeySym keysym) -{ - unsigned int i; - unsigned int length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter); - - if (keysym >= XK_a && keysym <= XK_z) - return keysym - XK_a + NS_VK_A; - if (keysym >= XK_A && keysym <= XK_Z) - return keysym - XK_A + NS_VK_A; - - for (i = 0; i < length; i++) - { - if (nsKeycodes[i].keysym == keysym) - { - return(nsKeycodes[i].vkCode); - } - } - - return((int)0); -} - -////////////////////////////////////////////////////////////////////////// -/* static */ PRBool -nsKeyCode::KeyCodeIsModifier(KeyCode aKeyCode) -{ - if (aKeyCode == XK_Shift_L || - aKeyCode == XK_Shift_R || - aKeyCode == XK_Control_L || - aKeyCode == XK_Control_R || - aKeyCode == XK_Caps_Lock || - aKeyCode == XK_Shift_Lock || - aKeyCode == XK_Meta_L || - aKeyCode == XK_Meta_R || - aKeyCode == XK_Alt_L || - aKeyCode == XK_Alt_R) - { - return PR_TRUE; - } - - return PR_FALSE; -} -////////////////////////////////////////////////////////////////////////// -/* static */ KeySym -nsKeyCode::ConvertKeyCodeToKeySym(Display * aDisplay, KeyCode aKeyCode) -{ - KeySym keysym = 0; - - keysym = XKeycodeToKeysym(aDisplay, aKeyCode, 0); - - return keysym; -} -////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/widget/src/xlib/nsKeyCode.h b/mozilla/widget/src/xlib/nsKeyCode.h deleted file mode 100644 index c56ddc6b7cf..00000000000 --- a/mozilla/widget/src/xlib/nsKeyCode.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsKeyCode_h -#define __nsKeyCode_h - -#include -#include - -#include "prtypes.h" - -struct nsKeyCode -{ - static PRInt32 ConvertKeySymToVirtualKey(KeySym aKeySym); - - static PRBool KeyCodeIsModifier(KeyCode aKeyCode); - - static KeySym ConvertKeyCodeToKeySym(Display *aDisplay, - KeyCode aKeyCode); -}; - -#endif // __nsKeyCode_h diff --git a/mozilla/widget/src/xlib/nsLookAndFeel.cpp b/mozilla/widget/src/xlib/nsLookAndFeel.cpp deleted file mode 100644 index 834f0727b8f..00000000000 --- a/mozilla/widget/src/xlib/nsLookAndFeel.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsLookAndFeel.h" -#include "nsWidget.h" - -nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::nsLookAndFeel()\n")); -} - -nsLookAndFeel::~nsLookAndFeel() -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::~nsLookAndFeel()\n")); -} - -nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID, nscolor &aColor) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::NativeGetColor()\n")); - nsresult res = NS_OK; - - aColor = 0; - switch (aID) { - case eColor_WindowBackground: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_WindowForeground: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_WidgetBackground: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_WidgetForeground: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_WidgetSelectBackground: - aColor = NS_RGB(0x00, 0x00, 0x9c); - break; - case eColor_WidgetSelectForeground: - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - case eColor_Widget3DHighlight: - aColor = NS_RGB(0x99,0x99,0x99); - break; - case eColor_Widget3DShadow: - aColor = NS_RGB(0x40,0x40,0x40); - break; - case eColor_TextBackground: - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - case eColor_TextForeground: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_TextSelectBackground: - case eColor_IMESelectedRawTextBackground: - case eColor_IMESelectedConvertedTextBackground: - aColor = NS_RGB(0x00, 0x00, 0x9c); - break; - case eColor_TextSelectForeground: - case eColor_IMESelectedRawTextForeground: - case eColor_IMESelectedConvertedTextForeground: - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - case eColor_IMERawInputBackground: - case eColor_IMEConvertedTextBackground: - aColor = NS_TRANSPARENT; - break; - case eColor_IMERawInputForeground: - case eColor_IMEConvertedTextForeground: - aColor = NS_SAME_AS_FOREGROUND_COLOR; - break; - case eColor_IMERawInputUnderline: - case eColor_IMEConvertedTextUnderline: - aColor = NS_SAME_AS_FOREGROUND_COLOR; - break; - case eColor_IMESelectedRawTextUnderline: - case eColor_IMESelectedConvertedTextUnderline: - aColor = NS_TRANSPARENT; - break; - - - // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors - case eColor_activeborder: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_activecaption: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_appworkspace: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_background: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - - case eColor_captiontext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_graytext: - aColor = NS_RGB(0x80, 0x80, 0x80); - break; - case eColor_highlight: - case eColor__moz_menuhover: - aColor = NS_RGB(0x00, 0x00, 0x9c); - break; - case eColor_highlighttext: - case eColor__moz_menuhovertext: - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - case eColor_inactiveborder: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_inactivecaption: - aColor = NS_RGB(0x80, 0x80, 0x80); - break; - case eColor_inactivecaptiontext: - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - case eColor_infobackground: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_infotext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_menu: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor_menutext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor_scrollbar: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - - case eColor_threedface: - // 3-D face color - case eColor_buttonface: - case eColor__moz_buttonhoverface: - // 3-D face color - case eColor_threedlightshadow: - // 3-D inner highlight color - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - - case eColor_buttonhighlight: - // 3-D highlight color - case eColor_threedhighlight: - // 3-D outer highlight color - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - - case eColor_buttontext: - case eColor__moz_buttonhovertext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - - case eColor_buttonshadow: - // 3-D shadow color - case eColor_threedshadow: - // 3-D inner shadow color - aColor = NS_RGB(0x66, 0x66, 0x66); - break; - - case eColor_threeddarkshadow: - // 3-D outer shadow color - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - - case eColor_window: - case eColor_windowframe: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - - case eColor_windowtext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - - case eColor__moz_field: - aColor = NS_RGB(0xff, 0xff, 0xff); - break; - case eColor__moz_fieldtext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - case eColor__moz_dialog: - case eColor__moz_cellhighlight: - aColor = NS_RGB(0xcc, 0xcc, 0xcc); - break; - case eColor__moz_dialogtext: - case eColor__moz_cellhighlighttext: - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - - case eColor__moz_buttondefault: - // default button border color - aColor = NS_RGB(0x00, 0x00, 0x00); - break; - - default: - /* default color is BLACK */ - aColor = 0; - res = NS_ERROR_FAILURE; - break; - } - return NS_OK; -} - -NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric()\n")); - // XXX These are not complete! - nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric); - if (NS_SUCCEEDED(res)) - return res; - res = NS_OK; - - switch (aID) { - case eMetric_WindowTitleHeight: - aMetric = 20; - break; - case eMetric_WindowBorderWidth: - aMetric = 1; - break; - case eMetric_WindowBorderHeight: - aMetric = 1; - break; - case eMetric_Widget3DBorder: - aMetric = 1; - break; - case eMetric_TextFieldHeight: - aMetric = 24; - break; - case eMetric_ButtonHorizontalInsidePaddingNavQuirks: - aMetric = 10; - break; - case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks: - aMetric = 8; - break; - case eMetric_CheckboxSize: - aMetric = 15; - break; - case eMetric_RadioboxSize: - aMetric = 15; - break; - case eMetric_TextHorizontalInsideMinimumPadding: - aMetric = 3; - break; - case eMetric_TextVerticalInsidePadding: - aMetric = 0; - break; - case eMetric_TextShouldUseVerticalInsidePadding: - aMetric = 0; - break; - case eMetric_TextShouldUseHorizontalInsideMinimumPadding: - aMetric = 1; - break; - case eMetric_ListShouldUseHorizontalInsideMinimumPadding: - aMetric = 0; - break; - case eMetric_ListHorizontalInsideMinimumPadding: - aMetric = 3; - break; - case eMetric_ListShouldUseVerticalInsidePadding: - aMetric = 0; - break; - case eMetric_ListVerticalInsidePadding: - aMetric = 0; - break; - case eMetric_CaretBlinkTime: - aMetric = 500; - break; - case eMetric_CaretWidth: - aMetric = 1; - break; - case eMetric_ShowCaretDuringSelection: - aMetric = 0; - break; - case eMetric_SelectTextfieldsOnKeyFocus: - // Select textfield content when focused by kbd - // used by nsEventStateManager::sTextfieldSelectModel - aMetric = 1; - break; - case eMetric_SubmenuDelay: - aMetric = 200; - break; - case eMetric_TreeOpenDelay: - aMetric = 1000; - break; - case eMetric_TreeCloseDelay: - aMetric = 1000; - break; - case eMetric_TreeLazyScrollDelay: - aMetric = 150; - break; - case eMetric_TreeScrollDelay: - aMetric = 100; - break; - case eMetric_TreeScrollLinesMax: - aMetric = 3; - break; - default: - aMetric = 0; - res = NS_ERROR_FAILURE; - } - return res; -} - -NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric()\n")); - - // XXX this is not complete - nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric); - if (NS_SUCCEEDED(res)) - return res; - res = NS_OK; - - switch (aID) { - case eMetricFloat_TextFieldVerticalInsidePadding: - aMetric = 0.25f; - break; - case eMetricFloat_TextFieldHorizontalInsidePadding: - aMetric = 0.95f; - break; - case eMetricFloat_TextAreaVerticalInsidePadding: - aMetric = 0.40f; - break; - case eMetricFloat_TextAreaHorizontalInsidePadding: - aMetric = 0.40f; - break; - case eMetricFloat_ListVerticalInsidePadding: - aMetric = 0.10f; - break; - case eMetricFloat_ListHorizontalInsidePadding: - aMetric = 0.40f; - break; - case eMetricFloat_ButtonVerticalInsidePadding: - aMetric = 0.25f; - break; - case eMetricFloat_ButtonHorizontalInsidePadding: - aMetric = 0.25f; - break; - case eMetricFloat_IMEUnderlineRelativeSize: - aMetric = 1.0f; - break; - default: - aMetric = -1.0; - res = NS_ERROR_FAILURE; - } - return res; -} diff --git a/mozilla/widget/src/xlib/nsLookAndFeel.h b/mozilla/widget/src/xlib/nsLookAndFeel.h deleted file mode 100644 index bcc0d0da23d..00000000000 --- a/mozilla/widget/src/xlib/nsLookAndFeel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsLookAndFeel -#define __nsLookAndFeel - -#include "nsXPLookAndFeel.h" - -class nsLookAndFeel: public nsXPLookAndFeel { -public: - nsLookAndFeel(); - virtual ~nsLookAndFeel(); - - nsresult NativeGetColor(const nsColorID aID, nscolor &aColor); - NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric); - NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric); -}; - -#endif diff --git a/mozilla/widget/src/xlib/nsScreenManagerXlib.cpp b/mozilla/widget/src/xlib/nsScreenManagerXlib.cpp deleted file mode 100644 index 3194e1d523a..00000000000 --- a/mozilla/widget/src/xlib/nsScreenManagerXlib.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScreenManagerXlib.h" -#include "nsScreenXlib.h" - - -nsScreenManagerXlib :: nsScreenManagerXlib ( ) -{ - // nothing else to do. I guess we could cache a bunch of information - // here, but we want to ask the device at runtime in case anything - // has changed. -} - - -nsScreenManagerXlib :: ~nsScreenManagerXlib() -{ - // nothing to see here. -} - - -// addref, release, QI -NS_IMPL_ISUPPORTS1(nsScreenManagerXlib, nsIScreenManager) - - -// -// CreateNewScreenObject -// -// Utility routine. Creates a new screen object from the given device handle -// -// NOTE: For this "single-monitor" impl, we just always return the cached primary -// screen. This should change when a multi-monitor impl is done. -// -nsIScreen* -nsScreenManagerXlib :: CreateNewScreenObject ( ) -{ - nsIScreen* retval = nsnull; - if ( !mCachedMainScreen ) - mCachedMainScreen = new nsScreenXlib ( ); - NS_IF_ADDREF(retval = mCachedMainScreen.get()); - - return retval; -} - - -// -// ScreenForRect -// -// Returns the screen that contains the rectangle. If the rect overlaps -// multiple screens, it picks the screen with the greatest area of intersection. -// -// The coordinates are in pixels (not twips) and in screen coordinates. -// -NS_IMETHODIMP -nsScreenManagerXlib :: ScreenForRect ( PRInt32 /*inLeft*/, PRInt32 /*inTop*/, PRInt32 /*inWidth*/, - PRInt32 /*inHeight*/, nsIScreen **outScreen ) -{ - GetPrimaryScreen ( outScreen ); - return NS_OK; - -} // ScreenForRect - - -// -// GetPrimaryScreen -// -// The screen with the menubar/taskbar. This shouldn't be needed very -// often. -// -NS_IMETHODIMP -nsScreenManagerXlib :: GetPrimaryScreen(nsIScreen * *aPrimaryScreen) -{ - *aPrimaryScreen = CreateNewScreenObject(); // addrefs - return NS_OK; - -} // GetPrimaryScreen - - -// -// GetNumberOfScreens -// -// Returns how many physical screens are available. -// -NS_IMETHODIMP -nsScreenManagerXlib :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) -{ - *aNumberOfScreens = 1; - return NS_OK; - -} // GetNumberOfScreens - diff --git a/mozilla/widget/src/xlib/nsScreenManagerXlib.h b/mozilla/widget/src/xlib/nsScreenManagerXlib.h deleted file mode 100644 index a2205db5427..00000000000 --- a/mozilla/widget/src/xlib/nsScreenManagerXlib.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsScreenManagerXlib_h___ -#define nsScreenManagerXlib_h___ - -#include "nsIScreenManager.h" -#include "nsIScreen.h" -#include "nsCOMPtr.h" - -//------------------------------------------------------------------------ - -class nsScreenManagerXlib : public nsIScreenManager -{ -public: - nsScreenManagerXlib ( ); - virtual ~nsScreenManagerXlib(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCREENMANAGER - -private: - - nsIScreen* CreateNewScreenObject ( ) ; - - // cache the primary screen object to avoid memory allocation every time - nsCOMPtr mCachedMainScreen; - -}; - -#endif // nsScreenManagerXlib_h___ diff --git a/mozilla/widget/src/xlib/nsScreenXlib.cpp b/mozilla/widget/src/xlib/nsScreenXlib.cpp deleted file mode 100644 index f7da9ea1a6d..00000000000 --- a/mozilla/widget/src/xlib/nsScreenXlib.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScreenXlib.h" -#include "xlibrgb.h" -#include - -nsScreenXlib :: nsScreenXlib ( ) -{ - // nothing else to do. I guess we could cache a bunch of information - // here, but we want to ask the device at runtime in case anything - // has changed. -} - - -nsScreenXlib :: ~nsScreenXlib() -{ - // nothing to see here. -} - - -// addref, release, QI -NS_IMPL_ISUPPORTS1(nsScreenXlib, nsIScreen) - - -NS_IMETHODIMP -nsScreenXlib :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight) -{ - XlibRgbHandle *xrh; - if (!(xrh = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE))) - abort(); - - *outTop = 0; - *outLeft = 0; - *outWidth = XDisplayWidth(xxlib_rgb_get_display(xrh), 0); - *outHeight = XDisplayHeight(xxlib_rgb_get_display(xrh), 0); - - return NS_OK; - -} // GetRect - - -NS_IMETHODIMP -nsScreenXlib :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight) -{ - XlibRgbHandle *xrh; - if (!(xrh = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE))) - abort(); - - *outTop = 0; - *outLeft = 0; - *outWidth = XDisplayWidth(xxlib_rgb_get_display(xrh), 0); - *outHeight = XDisplayHeight(xxlib_rgb_get_display(xrh), 0); - - return NS_OK; - -} // GetAvailRect - - -NS_IMETHODIMP -nsScreenXlib :: GetPixelDepth(PRInt32 *aPixelDepth) -{ - XlibRgbHandle *xrh; - if (!(xrh = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE))) - abort(); - - *aPixelDepth = xxlib_rgb_get_depth(xrh); - - return NS_OK; - -} // GetPixelDepth - - -NS_IMETHODIMP -nsScreenXlib :: GetColorDepth(PRInt32 *aColorDepth) -{ - return GetPixelDepth ( aColorDepth ); - -} // GetColorDepth - - diff --git a/mozilla/widget/src/xlib/nsScreenXlib.h b/mozilla/widget/src/xlib/nsScreenXlib.h deleted file mode 100644 index 45bbaedbac1..00000000000 --- a/mozilla/widget/src/xlib/nsScreenXlib.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsScreenXlib_h___ -#define nsScreenXlib_h___ - -#include "nsIScreen.h" - -//------------------------------------------------------------------------ - -class nsScreenXlib : public nsIScreen -{ -public: - nsScreenXlib ( ); - virtual ~nsScreenXlib(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCREEN - -private: - -}; - -#endif // nsScreenXlib_h___ diff --git a/mozilla/widget/src/xlib/nsSound.cpp b/mozilla/widget/src/xlib/nsSound.cpp deleted file mode 100644 index 06c27fe3bf4..00000000000 --- a/mozilla/widget/src/xlib/nsSound.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nscore.h" -#include "plstr.h" -#include "prlink.h" - -#include "nsSound.h" -#include "nsAppShell.h" - -#include "nsIURL.h" -#include "nsNetUtil.h" -#include "nsCOMPtr.h" - -#include -#include - - -NS_IMPL_THREADSAFE_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver) - -//////////////////////////////////////////////////////////////////////// -nsSound::nsSound() -{ - -} - -nsSound::~nsSound() -{ - -} - -NS_IMETHODIMP nsSound::Init() -{ - -#ifdef DEBUG_faulkner - fprintf(stderr, "\n////////// nsSound::Init() in xlib called //////////\n"); -#endif /* DEBUG_faulkner */ - return NS_OK; -} - -NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader, - nsISupports *context, - nsresult aStatus, - PRUint32 stringLen, - const PRUint8 *string) -{ -#ifdef DEBUG_faulkner - fprintf(stderr, "\n////////// nsSound::Init() in xlib called //////////\n"); -#endif /* DEBUG_faulkner */ - return NS_OK; -} - -NS_METHOD nsSound::Beep() -{ -#ifdef DEBUG_faulkner - fprintf(stderr, "\n////////// nsSound::Beep() in xlib called //////////\n"); -#endif /* DEBUG_faulkner */ - - XBell(nsAppShell::mDisplay, 80); - return NS_OK; -} - -NS_METHOD nsSound::Play(nsIURL *aURL) -{ -#ifdef DEBUG_faulkner - fprintf(stderr, "\n////////// nsSound::Play() in xlib called //////////\n"); -#endif /* DEBUG_faulkner */ - return NS_OK; -} - -NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias) -{ - return Beep(); -} diff --git a/mozilla/widget/src/xlib/nsSound.h b/mozilla/widget/src/xlib/nsSound.h deleted file mode 100644 index b28ba02661e..00000000000 --- a/mozilla/widget/src/xlib/nsSound.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stuart Parmenter - * Peter Hartshorn - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsSound_h__ -#define __nsSound_h__ - -#include "nsISound.h" -#include "nsIStreamLoader.h" - - -class nsSound : public nsISound, - public nsIStreamLoaderObserver -{ - public: - - nsSound(); - virtual ~nsSound(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISOUND - NS_DECL_NSISTREAMLOADEROBSERVER -}; - -#endif /* __nsSound_h__ */ diff --git a/mozilla/widget/src/xlib/nsToolkit.cpp b/mozilla/widget/src/xlib/nsToolkit.cpp deleted file mode 100644 index 7bb9223493f..00000000000 --- a/mozilla/widget/src/xlib/nsToolkit.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nscore.h" // needed for 'nsnull' -#include "xlibrgb.h" -#include "nsToolkit.h" -#include "nsGCCache.h" -#include "nsAppShell.h" // needed for nsAppShell::GetXlibRgbHandle() -#include "nsWidgetAtoms.h" - -// Static Thread Local Storage index of the toolkit object associated with -// a given thread... -static PRUintn gToolkitTLSIndex = 0; - -nsToolkit::nsToolkit() -{ - mGC = nsnull; - mDisplay = xxlib_rgb_get_display(nsAppShell::GetXlibRgbHandle()); -} - -nsToolkit::~nsToolkit() -{ - if (mGC) - mGC->Release(); - - // Remove the TLS reference to the toolkit... - PR_SetThreadPrivate(gToolkitTLSIndex, nsnull); -} - -NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit) - -void nsToolkit::CreateSharedGC() -{ - if (mGC) - return; - - mGC = new xGC(mDisplay, XDefaultRootWindow(mDisplay), 0, nsnull); - mGC->AddRef(); // this is for us -} - -xGC *nsToolkit::GetSharedGC() -{ - if (!mGC) - CreateSharedGC(); - - mGC->AddRef(); - return mGC; -} - -NS_METHOD nsToolkit::Init(PRThread *aThread) -{ - CreateSharedGC(); - - nsWidgetAtoms::RegisterAtoms(); - - return NS_OK; -} - -NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult) -{ - nsIToolkit* toolkit = nsnull; - nsresult rv = NS_OK; - PRStatus status; - - // Create the TLS (Thread Local Storage) index the first time through - if (gToolkitTLSIndex == 0) - { - status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, nsnull); - if (PR_FAILURE == status) - { - rv = NS_ERROR_FAILURE; - } - } - - if (NS_SUCCEEDED(rv)) - { - toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex); - - // - // Create a new toolkit for this thread... - // - if (!toolkit) { - toolkit = new nsToolkit(); - - if (!toolkit) { - rv = NS_ERROR_OUT_OF_MEMORY; - } else { - NS_ADDREF(toolkit); - toolkit->Init(PR_GetCurrentThread()); - // - // The reference stored in the TLS is weak. It is removed in the - // nsToolkit destructor... - // - PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit); - } - } else { - NS_ADDREF(toolkit); - } - *aResult = toolkit; - } - return rv; -} diff --git a/mozilla/widget/src/xlib/nsToolkit.h b/mozilla/widget/src/xlib/nsToolkit.h deleted file mode 100644 index 565d7200e3d..00000000000 --- a/mozilla/widget/src/xlib/nsToolkit.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsToolkit_h__ -#define nsToolkit_h__ - -#include "nsIToolkit.h" -#include "nsGCCache.h" -#include -#include - -/** - * Wrapper around the thread running the message pump. - * The toolkit abstraction is necessary because the message pump must - * execute within the same thread that created the widget under Win32. - */ - -class nsToolkit : public nsIToolkit -{ -private: - Display *mDisplay; - void CreateSharedGC(); - xGC *mGC; - -public: - nsToolkit(); - virtual ~nsToolkit(); - - NS_DECL_ISUPPORTS - NS_IMETHOD Init(PRThread *aThread); - xGC *GetSharedGC(); -}; - -#endif diff --git a/mozilla/widget/src/xlib/nsWidget.cpp b/mozilla/widget/src/xlib/nsWidget.cpp deleted file mode 100644 index 10774eacebc..00000000000 --- a/mozilla/widget/src/xlib/nsWidget.cpp +++ /dev/null @@ -1,1508 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * Quy Tonthat - * B.J. Rossiter - * Tony Tsui - * L. David Baron - * Tim Copperfield - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#undef DEBUG_CURSORCACHE - -#include "nsWidget.h" -#include "nsIServiceManager.h" -#include "nsAppShell.h" - -#include -#include -#include "nsXlibCursors.h" - -#include "nsIEventListener.h" -#include "nsIMenuListener.h" -#include "nsIMouseListener.h" -#include "nsIRollupListener.h" -#include "nsGfxCIID.h" -#include "nsIMenuRollup.h" -#include "nsIRenderingContext.h" -#include "nsToolkit.h" - -#include "xlibrgb.h" - -static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); - -PRLogModuleInfo *XlibWidgetsLM = PR_NewLogModule("XlibWidgets"); -PRLogModuleInfo *XlibScrollingLM = PR_NewLogModule("XlibScrolling"); - -// set up our static members here. -nsHashtable *nsWidget::gsWindowList = nsnull; // WEAK references to nsWidget* - -// cursors hash table -Cursor nsWidget::gsXlibCursorCache[eCursorCount]; - -// this is for implemention the WM_PROTOCOL code -PRBool nsWidget::WMProtocolsInitialized = PR_FALSE; -Atom nsWidget::WMDeleteWindow = 0; -Atom nsWidget::WMTakeFocus = 0; -Atom nsWidget::WMSaveYourself = 0; - -// this is the window that has the focus -Window nsWidget::mFocusWindow = 0; - -// For popup handling -nsCOMPtr nsWidget::gRollupListener; -nsWeakPtr nsWidget::gRollupWidget; -PRBool nsWidget::gRollupConsumeRollupEvent = PR_FALSE; - -class nsWindowKey : public nsHashKey { -protected: - Window mKey; - -public: - nsWindowKey(Window key) { - mKey = key; - } - ~nsWindowKey(void) { - } - PRUint32 HashCode(void) const { - return (PRUint32)mKey; - } - - PRBool Equals(const nsHashKey *aKey) const { - return (mKey == ((nsWindowKey *)aKey)->mKey); - } - - nsHashKey *Clone(void) const { - return new nsWindowKey(mKey); - } -}; - -nsWidget::nsWidget() // : nsBaseWidget() -{ - mPreferredWidth = 0; - mPreferredHeight = 0; - - mDisplay = 0; - mScreen = 0; - mVisual = 0; - mDepth = 0; - - mBaseWindow = 0; - mBackground = NS_RGB(192, 192, 192); - mBorderRGB = NS_RGB(192, 192, 192); - /* |xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE)| would be the official - * way - but |nsAppShell::GetXlibRgbHandle()| one is little bit faster...*/ - mXlibRgbHandle = nsAppShell::GetXlibRgbHandle(); - mBackgroundPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBackground); - mBackground = NS_RGB(192, 192, 192); - mBorderPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBorderRGB); - mParentWidget = nsnull; - mName.AssignLiteral("unnamed"); - mIsShown = PR_FALSE; - mIsToplevel = PR_FALSE; - mVisibility = VisibilityFullyObscured; // this is an X constant. - mWindowType = eWindowType_child; - mBorderStyle = eBorderStyle_default; - - // added KenF - mIsDestroying = PR_FALSE; - mOnDestroyCalled = PR_FALSE; - mListenForResizes = PR_FALSE; // If we're native we need to listen. - mMapped = PR_FALSE; - - - mUpdateArea = do_CreateInstance(kRegionCID); - if (mUpdateArea) { - mUpdateArea->Init(); - mUpdateArea->SetTo(0, 0, 0, 0); - } -} - -// FIXME: -// Heavily modifying so functionally similar as gtk version. KenF -nsWidget::~nsWidget() -{ - //mIsDestroying = TRUE; - - if (mBaseWindow) - Destroy(); -} - -// Borrowed heavily from GTK. This should go through heirarchy of XWindow -// windows, and destroy the appropriate children. -// KenF -void -nsWidget::DestroyNativeChildren(Display *aDisplay, Window aWindow) -{ - Window root_return; - Window parent_return; - Window *children_return = nsnull; - unsigned int nchildren_return = 0; - unsigned int i = 0; - - XQueryTree(aDisplay, aWindow, &root_return, &parent_return, - &children_return, &nchildren_return); - // walk the list of children - for (i=0; i < nchildren_return; i++) { - nsWidget *thisWidget = GetWidgetForWindow(children_return[i]); - if (thisWidget) { - thisWidget->Destroy(); - } - } - - // free up this struct - if (children_return) - XFree(children_return); -} - -void -nsWidget::DestroyNative() -{ - NS_ASSERTION(mBaseWindow, "no native window"); - - // We have to destroy the children ourselves before we call XDestroyWindow - // because otherwise XDestroyWindow will destroy the windows and leave us - // with dangling references. - DestroyNativeChildren(mDisplay, mBaseWindow); - - XDestroyWindow(mDisplay, mBaseWindow); - DeleteWindowCallback(mBaseWindow); -} - -// Stub in nsWidget, real in nsWindow. KenF -void * nsWidget::CheckParent(long ThisWindow) -{ - return (void*)-1; -} - -NS_IMETHODIMP nsWidget::Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - // Do adding in SWC() KenF - //mParentWidget = aParent; - //NS_IF_ADDREF(mParentWidget); // KenF FIXME - - return StandardWidgetCreate(aParent, aRect, aHandleEventFunction, - aContext, aAppShell, aToolkit, aInitData, - nsnull); -} - -NS_IMETHODIMP nsWidget::Create(nsNativeWidget aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - return(StandardWidgetCreate(nsnull, aRect, aHandleEventFunction, - aContext, aAppShell, aToolkit, aInitData, - aParent)); -} - -nsresult -nsWidget::StandardWidgetCreate(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData, - nsNativeWidget aNativeParent) -{ - unsigned long attr_mask; - XSetWindowAttributes attr; - Window parent=nsnull; - - NS_ASSERTION(!mBaseWindow, "already initialized"); - if (mBaseWindow) return NS_ERROR_ALREADY_INITIALIZED; - - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - mScreen = xxlib_rgb_get_screen(mXlibRgbHandle); - mVisual = xxlib_rgb_get_visual(mXlibRgbHandle); - mDepth = xxlib_rgb_get_depth(mXlibRgbHandle); - - mParentWidget = aParent; - - NS_IF_ADDREF(mParentWidget); - - mBounds = aRect; - - if (mBounds.width <= 0) - mBounds.width = 1; - if (mBounds.height <= 0) - mBounds.height = 1; - - BaseCreate(mParentWidget, mBounds, aHandleEventFunction, aContext, - aAppShell, aToolkit, aInitData); - - if (aNativeParent) { - parent = (Window)aNativeParent; - mListenForResizes = PR_TRUE; - } else if (aParent) { - parent = (Window)aParent->GetNativeData(NS_NATIVE_WINDOW); - } else { - parent = XRootWindowOfScreen(mScreen); - } - - if (nsnull != aInitData) { - mWindowType = aInitData->mWindowType; - } - - mParentWindow = parent; - - attr.bit_gravity = NorthWestGravity; - attr.event_mask = GetEventMask(); - attr.colormap = xxlib_rgb_get_cmap(mXlibRgbHandle); - attr.background_pixel = mBackgroundPixel; - attr.border_pixel = mBorderPixel; - attr_mask = CWBitGravity | CWEventMask | CWBorderPixel | CWBackPixel; - - if (attr.colormap) - attr_mask |= CWColormap; - - switch (mWindowType) { - case eWindowType_dialog: - mIsToplevel = PR_TRUE; - parent = XRootWindowOfScreen(mScreen); - mBaseWindow = XCreateWindow(mDisplay, parent, mBounds.x, mBounds.y, - mBounds.width, mBounds.height, 0, - mDepth, InputOutput, mVisual, - attr_mask, &attr); - XSetWindowBackgroundPixmap(mDisplay, mBaseWindow, None); - AddWindowCallback(mBaseWindow, this); - SetUpWMHints(); - XSetTransientForHint(mDisplay, mBaseWindow, mParentWindow); - break; - - case eWindowType_popup: - mIsToplevel = PR_TRUE; - attr_mask |= CWOverrideRedirect | CWSaveUnder; - attr.save_under = True; - attr.override_redirect = True; - parent = XRootWindowOfScreen(mScreen); - mBaseWindow = XCreateWindow(mDisplay, parent, - mBounds.x, mBounds.y, - mBounds.width, mBounds.height, 0, - mDepth, InputOutput, mVisual, - attr_mask, &attr); - XSetWindowBackgroundPixmap(mDisplay, mBaseWindow, None); - AddWindowCallback(mBaseWindow, this); - SetUpWMHints(); - XSetTransientForHint(mDisplay, mBaseWindow, mParentWindow); - break; - - case eWindowType_toplevel: - case eWindowType_invisible: - mIsToplevel = PR_TRUE; - parent = XRootWindowOfScreen(mScreen); - mBaseWindow = XCreateWindow(mDisplay, parent, mBounds.x, mBounds.y, - mBounds.width, mBounds.height, 0, - mDepth, InputOutput, mVisual, - attr_mask, &attr); - XSetWindowBackgroundPixmap(mDisplay, mBaseWindow, None); - AddWindowCallback(mBaseWindow, this); - SetUpWMHints(); - break; - - case eWindowType_child: - mIsToplevel = PR_FALSE; - // for some reason I need to do this, as opposed to the other cases. FIXME - CreateNative(parent, mBounds); - break; - - default: - break; - } - - return NS_OK; -} - -// FIXME: Being heavily modified so functionally similar to gtk version. -// (just a test) KenF -NS_IMETHODIMP nsWidget::Destroy() -{ - - // Don't reenter. - if (mIsDestroying) - return NS_OK; - - mIsDestroying = PR_TRUE; - - nsBaseWidget::Destroy(); - NS_IF_RELEASE(mParentWidget); //???? - - - if (mBaseWindow) { - DestroyNative(); - //mBaseWindow = nsnull; - if (PR_FALSE == mOnDestroyCalled) - OnDestroy(); - mBaseWindow = nsnull; - mEventCallback = nsnull; - } - - return NS_OK; - -} - -NS_IMETHODIMP nsWidget::ConstrainPosition(PRBool aAllowSlop, - PRInt32 *aX, PRInt32 *aY) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Move(PRInt32 aX, PRInt32 aY) -{ - //printf("nsWidget::Move aX=%i, aY=%i\n", aX, aY); - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Move(x, y)\n")); - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Moving window 0x%lx to %d, %d\n", mBaseWindow, aX, aY)); - - if((aX == mBounds.x) && (aY == mBounds.y) && !mIsToplevel) { - //printf("discard this move\n"); - return NS_OK; - } - - - mBounds.x = aX; - mBounds.y = aY; - - if (mWindowType == eWindowType_popup) { - nsRect aRect, transRect; - PRInt32 screenWidth = WidthOfScreen(mScreen); - PRInt32 screenHeight = HeightOfScreen(mScreen); - - if (aX >= screenWidth) - aX = screenWidth - mBounds.width; - if (aY >= screenHeight) - aY = screenHeight - mBounds.height; - - aRect.x = aX; - aRect.y = aY; - - if (mParentWidget) { - mParentWidget->WidgetToScreen(aRect, transRect); - } else if (mParentWindow) { - Window child; - XTranslateCoordinates(mDisplay, mParentWindow, - XRootWindowOfScreen(mScreen), - aX, aY, &transRect.x, &transRect.y, - &child); - } - aX = transRect.x; - aY = transRect.y; - } - - mRequestedSize.x = aX; - mRequestedSize.y = aY; - if (mParentWidget) { - ((nsWidget*)mParentWidget)->WidgetMove(this); - } else { - /* Workaround for bug 77344. I am not sure whether this is mandatory or not. */ - if (mDisplay) - XMoveWindow(mDisplay, mBaseWindow, aX, aY); - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Resize(PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint) -{ - //printf("nsWidget::Resize aWidth=%i, Height=%i\n",aWidth, aHeight); - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Resize(width, height)\n")); - - if (aWidth <= 0) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("*** width is %d, fixing.\n", aWidth)); - aWidth = 1; - - } - if (aHeight <= 0) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("*** height is %d, fixing.\n", aHeight)); - aHeight = 1; - } - - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Resizing window 0x%lx to %d, %d\n", mBaseWindow, aWidth, aHeight)); - mRequestedSize.width = mBounds.width = aWidth; - mRequestedSize.height = mBounds.height = aHeight; - - if (mParentWidget) { - ((nsWidget *)mParentWidget)->WidgetResize(this); - } else { - /* Workaround for bug 77344. I am not sure whether this is mandatory or not. */ - if (mDisplay) - XResizeWindow(mDisplay, mBaseWindow, aWidth, aHeight); - } - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Resize(PRInt32 aX, - PRInt32 aY, - PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint) -{ - //printf("nsWidget::Resize aX=%i, aY=%i, aWidth=%i, aHeight=%i\n", aX, aY, aWidth, aHeight); - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Resize(x, y, width, height)\n")); - - if (aWidth <= 0) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("*** width is %d, fixing.\n", aWidth)); - aWidth = 1; - } - if (aHeight <= 0) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("*** height is %d, fixing.\n", aHeight)); - aHeight = 1; - } - if (aX < 0) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("*** x is %d, fixing.\n", aX)); - aX = 0; - } - if (aY < 0) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("*** y is %d, fixing.\n", aY)); - aY = 0; - } - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, - ("Resizing window 0x%lx to %d, %d\n", mBaseWindow, aWidth, aHeight)); - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, - ("Moving window 0x%lx to %d, %d\n", mBaseWindow, aX, aY)); - mRequestedSize.x = aX; - mRequestedSize.y = aY; - mRequestedSize.width = mBounds.width = aWidth; - mRequestedSize.height = mBounds.height = aHeight; - if (mParentWidget) { - ((nsWidget *)mParentWidget)->WidgetMoveResize(this); - } else { - XMoveResizeWindow(mDisplay, mBaseWindow, aX, aY, aWidth, aHeight); - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Enable(PRBool aState) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::IsEnabled(PRBool *aState) -{ - NS_ENSURE_ARG_POINTER(aState); - *aState = PR_TRUE; - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP nsWidget::SetFocus(PRBool aRaise) -{ - - if (mBaseWindow) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::SetFocus() setting focus to 0x%lx\n", mBaseWindow)); - mFocusWindow = mBaseWindow; - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetName(const char * aName) -{ - mName.AssignWithConversion(aName); - - return NS_OK; -} - -Window -nsWidget::GetFocusWindow(void) -{ - return mFocusWindow; -} - -NS_IMETHODIMP nsWidget::Invalidate(PRBool aIsSynchronous) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Invalidate(sync)\n")); - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Invalidate(rect, sync)\n")); - return NS_OK; -} - -nsIFontMetrics* nsWidget::GetFont(void) -{ - return nsnull; -} - -NS_IMETHODIMP nsWidget::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetMenuBar(nsIMenuBar * aMenuBar) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::ShowMenuBar(PRBool aShow) -{ - return NS_OK; -} - -void * nsWidget::GetNativeData(PRUint32 aDataType) -{ - switch (aDataType) { - case NS_NATIVE_WIDGET: - case NS_NATIVE_WINDOW: - case NS_NATIVE_PLUGIN_PORT: - return (void *)mBaseWindow; - break; - case NS_NATIVE_DISPLAY: - return (void *)mDisplay; - break; - case NS_NATIVE_GRAPHIC: - NS_ASSERTION(nsnull != mToolkit, "NULL toolkit, unable to get a GC"); - return (void *)NS_STATIC_CAST(nsToolkit*,mToolkit)->GetSharedGC(); - break; - default: - fprintf(stderr, "nsWidget::GetNativeData(%d) called with crap value.\n", - aDataType); - return nsnull; - break; - } -} - -NS_IMETHODIMP nsWidget::SetTooltips(PRUint32 aNumberOfTips, - nsRect* aTooltipAreas[]) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::UpdateTooltips(nsRect* aNewTips[]) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::RemoveTooltips() -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetFont(const nsFont &aFont) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::BeginResizingChildren(void) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::EndResizingChildren(void) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetColorMap(nsColorMap *aColorMap) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Show(PRBool bState) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Show()\n")); - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("state is %d\n", bState)); - - if (bState) { - Map(); - } else { - Unmap(); - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::IsVisible(PRBool &aState) -{ - if (mVisibility != VisibilityFullyObscured) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::IsVisible: yes\n")); - aState = PR_TRUE; - } - else { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::IsVisible: no\n")); - aState = PR_FALSE; - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Update() -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::Update()\n")); - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetBackgroundColor(const nscolor &aColor) -{ - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("nsWidget::SetBackgroundColor()\n")); - - nsBaseWidget::SetBackgroundColor(aColor); - mBackgroundPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBackground); - // set the window attrib - XSetWindowBackground(mDisplay, mBaseWindow, mBackgroundPixel); - return NS_OK; -} - -NS_IMETHODIMP nsWidget::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) -{ - return NS_OK; -} - -NS_IMPL_ISUPPORTS_INHERITED1(nsWidget, nsBaseWidget, nsISupportsWeakReference) - -NS_IMETHODIMP nsWidget::WidgetToScreen(const nsRect& aOldRect, - nsRect& aNewRect) -{ - Window child; - XTranslateCoordinates(mDisplay, - mBaseWindow, - XRootWindowOfScreen(mScreen), - aOldRect.x, aOldRect.y, - &aNewRect.x, &aNewRect.y, - &child); - return NS_OK; -} - -NS_IMETHODIMP nsWidget::ScreenToWidget(const nsRect& aOldRect, - nsRect& aNewRect) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetCursor(nsCursor aCursor) -{ - - if (!mBaseWindow) - return NS_ERROR_FAILURE; - - /* don't bother setting if it it isn't mapped, duh */ - if (!mMapped) - return NS_OK; - - // Only change cursor if it's changing - if (aCursor != mCursor) { - Cursor newCursor = None; - - newCursor = XlibCreateCursor(aCursor); - - if (None != newCursor) { - mCursor = aCursor; - XDefineCursor(mDisplay, mBaseWindow, newCursor); - XFlush(mDisplay); - } - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::PreCreateWidget(nsWidgetInitData *aInitData) -{ - if (nsnull != aInitData) { - SetWindowType(aInitData->mWindowType); - SetBorderStyle(aInitData->mBorderStyle); - - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -nsIWidget *nsWidget::GetParent(void) -{ - return mParentWidget; -} - -void nsWidget::CreateNative(Window aParent, nsRect aRect) -{ - XSetWindowAttributes attr; - unsigned long attr_mask; - - attr.bit_gravity = NorthWestGravity; - attr.event_mask = GetEventMask(); - attr.colormap = xxlib_rgb_get_cmap(mXlibRgbHandle); - attr.background_pixel = mBackgroundPixel; - attr.border_pixel = mBorderPixel; - attr_mask = CWBitGravity | CWEventMask | CWBorderPixel | CWBackPixel; - - if (attr.colormap) - attr_mask |= CWColormap; - - CreateNativeWindow(aParent, mBounds, attr, attr_mask); -} - -/* virtual */ long -nsWidget::GetEventMask() -{ - long event_mask; - - event_mask = - ButtonMotionMask | - Button1MotionMask | - ButtonPressMask | - ButtonReleaseMask | - EnterWindowMask | - ExposureMask | - KeyPressMask | - KeyReleaseMask | - LeaveWindowMask | - PointerMotionMask | - StructureNotifyMask | - VisibilityChangeMask | - FocusChangeMask | - OwnerGrabButtonMask; - - return event_mask; -} - -void nsWidget::CreateNativeWindow(Window aParent, nsRect aRect, - XSetWindowAttributes aAttr, unsigned long aMask) -{ - NS_ASSERTION(!mBaseWindow, "already initialized"); - if (mBaseWindow) return; - - mBaseWindow = XCreateWindow(mDisplay, - aParent, - aRect.x, aRect.y, - aRect.width, aRect.height, - 0, // border width - mDepth, // depth - InputOutput, // class - mVisual, // visual - aMask, - &aAttr); - XSetWindowBackgroundPixmap(mDisplay, mBaseWindow, None); - - mRequestedSize.height = mBounds.height = aRect.height; - mRequestedSize.width = mBounds.width = aRect.width; - AddWindowCallback(mBaseWindow, this); -} - -nsWidget * -nsWidget::GetWidgetForWindow(Window aWindow) -{ - if (gsWindowList == nsnull) { - return nsnull; - } - nsWindowKey window_key(aWindow); - nsWidget *retval = (nsWidget *)gsWindowList->Get(&window_key); - return retval; -} - -void -nsWidget::AddWindowCallback(Window aWindow, nsWidget *aWidget) -{ - // make sure that the list has been initialized - if (gsWindowList == nsnull) { - gsWindowList = new nsHashtable(); - } - nsWindowKey window_key(aWindow); - gsWindowList->Put(&window_key, aWidget); -} - -void -nsWidget::DeleteWindowCallback(Window aWindow) -{ - nsWindowKey window_key(aWindow); - gsWindowList->Remove(&window_key); - - if (gsWindowList->Count() == 0) { - delete gsWindowList; - gsWindowList = nsnull; - - /* clear out the cursor cache */ -#ifdef DEBUG_CURSORCACHE - printf("freeing cursor cache\n"); -#endif - for (int i = 0; i < eCursorCount; i++) - if (gsXlibCursorCache[i]) - XFreeCursor(nsAppShell::mDisplay, gsXlibCursorCache[i]); - } -} - -#undef TRACE_PAINT -#undef TRACE_PAINT_FLASH - -#ifdef TRACE_PAINT_FLASH -#include "nsXUtils.h" // for nsXUtils::XFlashWindow() -#endif - -PRBool -nsWidget::OnPaint(nsPaintEvent &event) -{ - nsresult result = PR_FALSE; - if (mEventCallback) { - event.renderingContext = GetRenderingContext(); - if (event.renderingContext) { - result = DispatchWindowEvent(event); - NS_RELEASE(event.renderingContext); - } - } - -#ifdef TRACE_PAINT - static PRInt32 sPrintCount = 0; - - if (event.rect) - { - printf("%4d nsWidget::OnPaint (this=%p,name=%s,xid=%p,rect=%d,%d,%d,%d)\n", - sPrintCount++, - (void *) this, - (const char *) nsCAutoString(mName), - (void *) mBaseWindow, - event.rect->x, - event.rect->y, - event.rect->width, - event.rect->height); - } - else - { - printf("%4d nsWidget::OnPaint (this=%p,name=%s,xid=%p,rect=none)\n", - sPrintCount++, - (void *) this, - (const char *) nsCAutoString(mName), - (void *) mBaseWindow); - } -#endif - -#ifdef TRACE_PAINT_FLASH - XRectangle ar; - XRectangle * area = nsnull; - - if (event.rect) - { - ar.x = event.rect->x; - ar.y = event.rect->y; - - ar.width = event.rect->width; - ar.height = event.rect->height; - - area = &ar; - } - - nsXUtils::XFlashWindow(mDisplay,mBaseWindow,1,100000,area); -#endif - - - return result; -} - -PRBool nsWidget::IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY) -{ - XWindowAttributes inWindowAttributes; - - /* sometimes we get NULL window */ - if (!window) - return PR_FALSE; - - /* Get the origin (top left corner) coordinate and window's size */ - if (XGetWindowAttributes(mDisplay, window, &inWindowAttributes) == 0) { - fprintf(stderr, "Failed calling XGetWindowAttributes in nsWidget::IsMouseInWindow"); - return PR_FALSE; - } - - // Note: These coordinates are now relative to the root window as popups are now created - // with the root window as parent - - // Must get mouse click coordinates relative to root window - int root_inMouse_x, - root_inMouse_y; - Window returnedChild; - Window rootWindow; - rootWindow = XRootWindow(mDisplay, XDefaultScreen(mDisplay)); - if (!XTranslateCoordinates(mDisplay, mBaseWindow, rootWindow, - inMouseX, inMouseY, - &root_inMouse_x, &root_inMouse_y, &returnedChild)){ - fprintf(stderr, "Could not get coordinates for origin coordinates for mouseclick\n"); - // should we return true or false?????? - return PR_FALSE; - } - //fprintf(stderr, "Here are the mouse click coordinates x:%i y%i\n", root_inMouse_x, root_inMouse_y); - - // Test using coordinates relative to root window if click was inside passed popup window - if (root_inMouse_x > inWindowAttributes.x && - root_inMouse_x < (inWindowAttributes.x + inWindowAttributes.width) && - root_inMouse_y > inWindowAttributes.y && - root_inMouse_y < (inWindowAttributes.y + inWindowAttributes.height)) { -#ifdef DEBUG_whoemeveraddedthatprintforginally - //fprintf(stderr, "Mouse click INSIDE passed popup\n"); -#endif - return PR_TRUE; - } - -#ifdef DEBUG_whoemeveraddedthatprintforginally - //fprintf(stderr, "Mouse click OUTSIDE of passed popup\n"); -#endif - return PR_FALSE; -} - - -// -// HandlePopup -// -// Deal with rollup of popups (xpmenus, etc) -// -PRBool nsWidget::HandlePopup ( PRInt32 inMouseX, PRInt32 inMouseY ) -{ - PRBool retVal = PR_FALSE; - PRBool rollup = PR_FALSE; - - // The gRollupListener and gRollupWidget are both set to nsnull when a popup is no - // longer visible - - nsCOMPtr rollupWidget = do_QueryReferent(gRollupWidget); - - if (rollupWidget && gRollupListener) { - Window currentPopup = (Window)rollupWidget->GetNativeData(NS_NATIVE_WINDOW); - - if (!IsMouseInWindow(currentPopup, inMouseX, inMouseY)) { - rollup = PR_TRUE; - nsCOMPtr menuRollup ( do_QueryInterface(gRollupListener) ); - - if ( menuRollup ) { - nsCOMPtr widgetChain; - menuRollup->GetSubmenuWidgetChain ( getter_AddRefs(widgetChain) ); - if ( widgetChain ) { - PRUint32 count = 0; - widgetChain->Count ( &count ); - for ( PRUint32 i = 0; i < count; ++i ) { - nsCOMPtr genericWidget; - widgetChain->GetElementAt ( i, getter_AddRefs(genericWidget) ); - nsCOMPtr widget ( do_QueryInterface(genericWidget) ); - if ( widget ) { - Window currWindow = (Window)widget->GetNativeData(NS_NATIVE_WINDOW); - if ( IsMouseInWindow(currWindow, inMouseX, inMouseY) ) { - rollup = PR_FALSE; - break; - } - } - } // foreach parent menu widget - } - } - } - } - - if (rollup) { - gRollupListener->Rollup(); - retVal = PR_TRUE; - } - return retVal; -} - - -// Added KenF FIXME -void nsWidget::OnDestroy() -{ - mOnDestroyCalled = PR_TRUE; - nsBaseWidget::OnDestroy(); - - // M14/GTK creates a widget which is called kungFuDeathGrip - // and assigns it "this". This might be because its making sure that this - // widget isn't destroyed? (still has a reference to it?) - // Check into it. FIXME KenF - DispatchDestroyEvent(); -} - -PRBool nsWidget::OnDeleteWindow(void) -{ -#ifdef DEBUG - printf("nsWidget::OnDeleteWindow()\n"); -#endif /* DEBUUG */ - nsBaseWidget::OnDestroy(); - // emit a destroy signal - return DispatchDestroyEvent(); -} - -PRBool nsWidget::DispatchDestroyEvent(void) { - PRBool result = PR_FALSE; - if (nsnull != mEventCallback) { - nsGUIEvent event(PR_TRUE, NS_DESTROY, this); - AddRef(); - result = DispatchWindowEvent(event); - Release(); - } - return result; -} - -PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) -{ - PRBool result = PR_FALSE; - if (nsnull == mEventCallback && nsnull == mMouseListener) { - return result; - } - - /* If there was a mouse down event, check if any popups need to be notified */ - if (aEvent.message == NS_MOUSE_BUTTON_DOWN && - HandlePopup(aEvent.refPoint.x, aEvent.refPoint.y)) { - return PR_TRUE; - } - - if (nsnull != mEventCallback) { - result = DispatchWindowEvent(aEvent); - return result; - } - if (nsnull != mMouseListener) { - switch (aEvent.message) { - case NS_MOUSE_MOVE: - // XXX this isn't handled in gtk for some reason. - break; - case NS_MOUSE_BUTTON_DOWN: - result = ConvertStatus(mMouseListener->MousePressed(aEvent)); - break; - case NS_MOUSE_BUTTON_UP: - result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); - result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); - break; - } - } - return result; -} - -PRBool -nsWidget::OnResize(nsSizeEvent &event) -{ - mBounds.width = event.mWinWidth; - mBounds.height = event.mWinHeight; - - nsresult result = PR_FALSE; - if (mEventCallback) { - result = DispatchWindowEvent(event); - } - return result; -} - -PRBool nsWidget::DispatchWindowEvent(nsGUIEvent & aEvent) -{ - nsEventStatus status; - DispatchEvent(&aEvent, status); - return ConvertStatus(status); -} - -PRBool nsWidget::DispatchKeyEvent(nsKeyEvent & aKeyEvent) -{ - if (mEventCallback) - { - return DispatchWindowEvent(aKeyEvent); - } - - return PR_FALSE; -} - -////////////////////////////////////////////////////////////////// -// -// Turning TRACE_EVENTS on will cause printfs for all -// mouse events that are dispatched. -// -// These are extra noisy, and thus have their own switch: -// -// NS_MOUSE_MOVE -// NS_PAINT -// NS_MOUSE_ENTER, NS_MOUSE_EXIT -// -////////////////////////////////////////////////////////////////// - -#undef TRACE_EVENTS -#undef TRACE_EVENTS_MOTION -#undef TRACE_EVENTS_PAINT -#undef TRACE_EVENTS_CROSSING -#undef DEBUG - -#ifdef DEBUG -void -nsWidget::DebugPrintEvent(nsGUIEvent & aEvent, - Window aWindow) -{ -#ifndef TRACE_EVENTS_MOTION - if (aEvent.message == NS_MOUSE_MOVE) - { - return; - } -#endif - -#ifndef TRACE_EVENTS_PAINT - if (aEvent.message == NS_PAINT) - { - return; - } -#endif - -#ifndef TRACE_EVENTS_CROSSING - if (aEvent.message == NS_MOUSE_ENTER || aEvent.message == NS_MOUSE_EXIT) - { - return; - } -#endif - - static int sPrintCount=0; - - nsCAutoString eventString; - eventString.AssignWithConversion(debug_GuiEventToString(&aEvent)); - printf("%4d %-26s(this=%-8p , window=%-8p", - sPrintCount++, - (const char *) eventString, - (void *) this, - (void *) aWindow); - - printf(" , x=%-3d, y=%d)",aEvent.refPoint.x,aEvent.refPoint.y); - - printf("\n"); -} -#endif // DEBUG -////////////////////////////////////////////////////////////////// - - -NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent * aEvent, - nsEventStatus &aStatus) -{ -#ifdef TRACE_EVENTS - DebugPrintEvent(*aEvent,mBaseWindow); -#endif - - NS_ADDREF(aEvent->widget); - - if (nsnull != mMenuListener) { - if (NS_MENU_EVENT == aEvent->eventStructType) - aStatus = mMenuListener->MenuSelected(NS_STATIC_CAST(nsMenuEvent&, *aEvent)); - } - - aStatus = nsEventStatus_eIgnore; - if (nsnull != mEventCallback) { - aStatus = (*mEventCallback)(aEvent); - } - - // Dispatch to event listener if event was not consumed - if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) { - aStatus = mEventListener->ProcessEvent(*aEvent); - } - - NS_IF_RELEASE(aEvent->widget); - - return NS_OK; -} - -void nsWidget::WidgetPut(nsWidget *aWidget) -{ -} - -void nsWidget::WidgetMove(nsWidget *aWidget) -{ - PR_LOG(XlibScrollingLM, PR_LOG_DEBUG, ("nsWidget::WidgetMove()\n")); - XMoveWindow(aWidget->mDisplay, aWidget->mBaseWindow, - aWidget->mRequestedSize.x, aWidget->mRequestedSize.y); -} - -void nsWidget::WidgetResize(nsWidget *aWidget) -{ - PR_LOG(XlibScrollingLM, PR_LOG_DEBUG, ("nsWidget::WidgetResize()\n")); - XResizeWindow(aWidget->mDisplay, aWidget->mBaseWindow, - aWidget->mRequestedSize.width, - aWidget->mRequestedSize.height); -} - -void nsWidget::WidgetMoveResize(nsWidget *aWidget) -{ - PR_LOG(XlibScrollingLM, PR_LOG_DEBUG, ("nsWidget::WidgetMoveResize()\n")); - XMoveResizeWindow(aWidget->mDisplay, - aWidget->mBaseWindow, - aWidget->mRequestedSize.x, - aWidget->mRequestedSize.y, - aWidget->mRequestedSize.width, - aWidget->mRequestedSize.height); -} - -void nsWidget::WidgetShow(nsWidget *aWidget) -{ - aWidget->Map(); -} - -PRBool nsWidget::WidgetVisible(nsRect &aBounds) -{ - nsRect scrollArea; - scrollArea.x = 0; - scrollArea.y = 0; - scrollArea.width = mRequestedSize.width + 1; - scrollArea.height = mRequestedSize.height + 1; - if (scrollArea.Intersects(aBounds)) { - PR_LOG(XlibScrollingLM, PR_LOG_DEBUG, ("nsWidget::WidgetVisible(): widget is visible\n")); - return PR_TRUE; - } - PR_LOG(XlibScrollingLM, PR_LOG_DEBUG, ("nsWidget::WidgetVisible(): widget is not visible\n")); - return PR_FALSE; -} - -void nsWidget::Map(void) -{ - if (!mMapped) { - /* Workaround for bug 77344. I am not sure whether this is mandatory or not. */ - if (mDisplay) - XMapWindow(mDisplay, mBaseWindow); - mMapped = PR_TRUE; - } -} - -void nsWidget::Unmap(void) -{ - if (mMapped) { - /* Workaround for bug 77344. I am not sure whether this is mandatory or not. */ - if (mDisplay) - XUnmapWindow(mDisplay, mBaseWindow); - mMapped = PR_FALSE; - } -} - -void nsWidget::SetVisibility(int aState) -{ - mVisibility = aState; -} - -// create custom pixmap cursor from cursors in nsXlibCursors.h -Cursor nsWidget::XlibCreateCursor(nsCursor aCursorType) -{ - Pixmap cursor = None; - Pixmap mask = None; - XColor fg, bg; - Cursor xcursor = None; - PRUint8 newType = 0xff; - - fg.pixel = 0; - fg.red = 0; - fg.green = 0; - fg.blue = 0; - fg.flags = 0xf; - - bg.pixel = 0xffffffff; - bg.red = 0xffff; - bg.green = 0xffff; - bg.blue = 0xffff; - bg.flags = 0xf; - - /* lookup the cursor in cache */ - if ((xcursor = gsXlibCursorCache[aCursorType])) { -#ifdef DEBUG_CURSORCACHE - printf("cached cursor found: %lx\n", xcursor); -#endif - return xcursor; - } - - /* handle cursor type */ - switch (aCursorType) { - case eCursor_select: - xcursor = XCreateFontCursor(mDisplay, XC_xterm); - break; - case eCursor_wait: - xcursor = XCreateFontCursor(mDisplay, XC_watch); - break; - case eCursor_hyperlink: - xcursor = XCreateFontCursor(mDisplay, XC_hand2); - break; - case eCursor_standard: - xcursor = XCreateFontCursor(mDisplay, XC_left_ptr); - break; - case eCursor_n_resize: - xcursor = XCreateFontCursor(mDisplay, XC_top_side); - break; - case eCursor_s_resize: - xcursor = XCreateFontCursor(mDisplay, XC_bottom_side); - break; - case eCursor_w_resize: - xcursor = XCreateFontCursor(mDisplay, XC_left_side); - break; - case eCursor_e_resize: - xcursor = XCreateFontCursor(mDisplay, XC_right_side); - break; - case eCursor_nw_resize: - xcursor = XCreateFontCursor(mDisplay, XC_top_left_corner); - break; - case eCursor_se_resize: - xcursor = XCreateFontCursor(mDisplay, XC_bottom_right_corner); - break; - case eCursor_ne_resize: - xcursor = XCreateFontCursor(mDisplay, XC_top_right_corner); - break; - case eCursor_sw_resize: - xcursor = XCreateFontCursor(mDisplay, XC_bottom_left_corner); - break; - case eCursor_crosshair: - xcursor = XCreateFontCursor(mDisplay, XC_crosshair); - break; - case eCursor_move: - xcursor = XCreateFontCursor(mDisplay, XC_fleur); - break; - case eCursor_help: - newType = XLIB_QUESTION_ARROW; - break; - case eCursor_copy: - newType = XLIB_COPY; - break; - case eCursor_alias: - newType = XLIB_ALIAS; - break; - case eCursor_context_menu: - newType = XLIB_CONTEXT_MENU; - break; - case eCursor_cell: - xcursor = XCreateFontCursor(mDisplay, XC_plus); - break; - case eCursor_grab: - newType = XLIB_HAND_GRAB; - break; - case eCursor_grabbing: - newType = XLIB_HAND_GRABBING; - break; - case eCursor_spinning: - newType = XLIB_SPINNING; - break; - case eCursor_zoom_in: - newType = XLIB_ZOOM_IN; - break; - case eCursor_zoom_out: - newType = XLIB_ZOOM_OUT; - break; - case eCursor_not_allowed: - case eCursor_no_drop: - newType = XLIB_NOT_ALLOWED; - break; - case eCursor_col_resize: - newType = XLIB_COL_RESIZE; - break; - case eCursor_row_resize: - newType = XLIB_ROW_RESIZE; - break; - case eCursor_vertical_text: - newType = XLIB_VERTICAL_TEXT; - break; - case eCursor_all_scroll: - xcursor = XCreateFontCursor(mDisplay, XC_fleur); - break; - case eCursor_nesw_resize: - newType = XLIB_NESW_RESIZE; - break; - case eCursor_nwse_resize: - newType = XLIB_NWSE_RESIZE; - break; - case eCursor_ns_resize: - xcursor = XCreateFontCursor(mDisplay, XC_sb_v_double_arrow); - break; - case eCursor_ew_resize: - xcursor = XCreateFontCursor(mDisplay, XC_sb_h_double_arrow); - break; - default: - break; - } - - /* if by now we don't have a xcursor, this means we have to make a custom one */ - if (!xcursor) { - NS_ASSERTION(newType != 0xff, "Unknown cursor type and no standard cursor"); - - /* we can use mBaseWindow for the pixmaps because SetCursor checks this - * before calling here */ - cursor = XCreatePixmapFromBitmapData(mDisplay, mBaseWindow, - (char *)XlibCursors[newType].bits, - 32, 32, 0xffffffff, 0x0, 1); - - mask = XCreatePixmapFromBitmapData(mDisplay, mBaseWindow, - (char *)XlibCursors[newType].mask_bits, - 32, 32, 0xffffffff, 0x0, 1); - - xcursor = XCreatePixmapCursor(mDisplay, cursor, mask, &fg, &bg, - XlibCursors[newType].hot_x, - XlibCursors[newType].hot_y); - - XFreePixmap(mDisplay, mask); - XFreePixmap(mDisplay, cursor); - } - -#ifdef DEBUG_CURSORCACHE - printf("inserting cursor into the cache: %lx\n", xcursor); -#endif - gsXlibCursorCache[aCursorType] = xcursor; - - return xcursor; -} - -void -nsWidget::SetUpWMHints(void) { - // check to see if we need to get the atoms for the protocols - if (WMProtocolsInitialized == PR_FALSE) { - WMDeleteWindow = XInternAtom(mDisplay, "WM_DELETE_WINDOW", True); - WMTakeFocus = XInternAtom(mDisplay, "WM_TAKE_FOCUS", True); - WMSaveYourself = XInternAtom(mDisplay, "WM_SAVE_YOURSELF", True); - WMProtocolsInitialized = PR_TRUE; - } - Atom WMProtocols[2]; - WMProtocols[0] = WMDeleteWindow; - WMProtocols[1] = WMTakeFocus; - // note that we only set two of the above protocols - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Setting up wm hints for window 0x%lx\n", - mBaseWindow)); - XSetWMProtocols(mDisplay, mBaseWindow, WMProtocols, 2); -} - -NS_METHOD nsWidget::SetBounds(const nsRect &aRect) -{ - mRequestedSize = aRect; - return nsBaseWidget::SetBounds(aRect); -} - -NS_METHOD nsWidget::GetRequestedBounds(nsRect &aRect) -{ - aRect = mRequestedSize; - return NS_OK; -} - -NS_IMETHODIMP -nsWidget::SetTitle(const nsAString& title) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent) -{ - return NS_OK; -} - diff --git a/mozilla/widget/src/xlib/nsWidget.h b/mozilla/widget/src/xlib/nsWidget.h deleted file mode 100644 index ef9fe21956e..00000000000 --- a/mozilla/widget/src/xlib/nsWidget.h +++ /dev/null @@ -1,257 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ken Faulkner - * Quy Tonthat - * B.J. Rossiter - * Roland Mainz - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsWidget_h__ -#define nsWidget_h__ - -#include "nsBaseWidget.h" -#include "nsWeakReference.h" -#include "nsHashtable.h" -#include "prlog.h" -#include "nsIRegion.h" -#include "nsIRollupListener.h" -#include "xlibrgb.h" - -#ifdef DEBUG_blizzard -#define XLIB_WIDGET_NOISY -#endif - -class nsWidget : public nsBaseWidget, public nsSupportsWeakReference -{ -public: - nsWidget(); - virtual ~nsWidget(); - - NS_DECL_ISUPPORTS_INHERITED - - NS_IMETHOD Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell = nsnull, - nsIToolkit *aToolkit = nsnull, - nsWidgetInitData *aInitData = nsnull); - - NS_IMETHOD Create(nsNativeWidget aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell = nsnull, - nsIToolkit *aToolkit = nsnull, - nsWidgetInitData *aInitData = nsnull); - - virtual nsresult StandardWidgetCreate(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData, - nsNativeWidget aNativeParent = nsnull); - NS_IMETHOD Destroy(); - virtual nsIWidget *GetParent(void); - NS_IMETHOD Show(PRBool bState); - NS_IMETHOD IsVisible(PRBool &aState); - - NS_IMETHOD ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX, PRInt32 *aY); - NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); - NS_IMETHOD Resize(PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint); - NS_IMETHOD Resize(PRInt32 aX, - PRInt32 aY, - PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint); - - NS_IMETHOD Enable(PRBool aState); - NS_IMETHOD IsEnabled(PRBool *aState); - NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE); - NS_IMETHOD SetName(const char * aName); - NS_IMETHOD SetBackgroundColor(const nscolor &aColor); - virtual nsIFontMetrics* GetFont(void); - NS_IMETHOD SetFont(const nsFont &aFont); - NS_IMETHOD SetCursor(nsCursor aCursor); - void LockCursor(PRBool aLock); - - NS_IMETHOD Invalidate(PRBool aIsSynchronous); - NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous); - NS_IMETHOD Update(); - virtual void* GetNativeData(PRUint32 aDataType); - NS_IMETHOD SetColorMap(nsColorMap *aColorMap); - NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); - NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); - NS_IMETHOD ShowMenuBar(PRBool aShow); - NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); - NS_IMETHOD RemoveTooltips(); - NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]); - NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect); - NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect); - NS_IMETHOD BeginResizingChildren(void); - NS_IMETHOD EndResizingChildren(void); - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); - NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); - NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); - NS_IMETHOD SetBounds(const nsRect &aRect); - NS_IMETHOD GetRequestedBounds(nsRect &aRect); - - NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent); - NS_IMETHOD SetTitle(const nsAString& title); -#ifdef DEBUG - void DebugPrintEvent(nsGUIEvent & aEvent,Window aWindow); -#endif - - virtual PRBool OnPaint(nsPaintEvent &event); - virtual PRBool OnResize(nsSizeEvent &event); - virtual PRBool OnDeleteWindow(void); - - // KenF Added FIXME: - virtual void OnDestroy(void); - virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent); - virtual PRBool DispatchKeyEvent(nsKeyEvent &aKeyEvent); - virtual PRBool DispatchDestroyEvent(void); - - static nsWidget * GetWidgetForWindow(Window aWindow); - void SetVisibility(int aState); // using the X constants here - void SetIonic(PRBool isIonic); - static Window GetFocusWindow(void); - - Cursor XlibCreateCursor(nsCursor aCursorType); - - PRBool DispatchWindowEvent(nsGUIEvent & aEvent); - - // these are for the wm protocols - static Atom WMDeleteWindow; - static Atom WMTakeFocus; - static Atom WMSaveYourself; - static PRBool WMProtocolsInitialized; - - // Checks if parent is alive. nsWidget has a stub, nsWindow has real - // thing. KenF - void *CheckParent(long ThisWindow); - - // Deal with rollup for popups - PRBool IsMouseInWindow(Window window, PRInt32 inMouseX, PRInt32 inMouseY); - PRBool HandlePopup( PRInt32 inMouseX, PRInt32 inMouseY); - - void WidgetShow (nsWidget *aWidget); -protected: - - nsCOMPtr mUpdateArea; - // private event functions - static PRBool ConvertStatus(nsEventStatus aStatus) - { return aStatus == nsEventStatus_eConsumeNoDefault; } - - // create the native window for this class - virtual void CreateNativeWindow(Window aParent, nsRect aRect, - XSetWindowAttributes aAttr, unsigned long aMask); - virtual void CreateNative(Window aParent, nsRect aRect); - virtual void DestroyNative(); - static void DestroyNativeChildren(Display *aDisplay, Window aWindow); - void Map(void); - void Unmap(void); - - // Let each sublclass set the event mask according to their needs - virtual long GetEventMask(); - - // these will add and delete a window - static void AddWindowCallback (Window aWindow, nsWidget *aWidget); - static void DeleteWindowCallback(Window aWindow); - - // set up our wm hints - void SetUpWMHints(void); - - // here's how we add children - // there's no geometry information here because that should be in the mBounds - // in the widget - void WidgetPut (nsWidget *aWidget); - void WidgetMove (nsWidget *aWidget); - void WidgetMoveResize (nsWidget *aWidget); - void WidgetResize (nsWidget *aWidget); - // check to see whether or not a rect will intersect with the current scrolled area - PRBool WidgetVisible (nsRect &aBounds); - - PRBool mIsShown; - int mVisibility; // this is an int because that's the way X likes it - PRUint32 mPreferredWidth; - PRUint32 mPreferredHeight; - - nsIWidget * mParentWidget; - Window mParentWindow; - - // All widgets have at least these items. - XlibRgbHandle *mXlibRgbHandle; - Display * mDisplay; - Screen * mScreen; - Window mBaseWindow; - Visual * mVisual; - int mDepth; - unsigned long mBackgroundPixel; - PRUint32 mBorderRGB; - unsigned long mBorderPixel; - nsString mName; // name of the type of widget - nsRect mRequestedSize; - PRPackedBool mIsToplevel; - PRPackedBool mMapped; - PRPackedBool mLastGrabFailed; - - static Window mFocusWindow; - - // Changed to protected so nsWindow has access to it. KenF -protected: - PRBool mListenForResizes; // If we're native we want to listen. - static nsHashtable * gsWindowList; - static Cursor gsXlibCursorCache[eCursorCount]; - - // Variables for infomation about the current popup window and its listener - static nsCOMPtr gRollupListener; - static nsWeakPtr gRollupWidget; - static PRBool gRollupConsumeRollupEvent; -}; - -extern PRLogModuleInfo *XlibWidgetsLM; -extern PRLogModuleInfo *XlibScrollingLM; - -#endif /* !nsWidget_h__ */ - - - diff --git a/mozilla/widget/src/xlib/nsWidgetFactory.cpp b/mozilla/widget/src/xlib/nsWidgetFactory.cpp deleted file mode 100644 index 6ad25223c26..00000000000 --- a/mozilla/widget/src/xlib/nsWidgetFactory.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * Dan Rosen - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIGenericFactory.h" -#include "nsIModule.h" -#include "nsCOMPtr.h" -#include "nsWidgetsCID.h" - -#include "nsWindow.h" -#include "nsAppShell.h" -#include "nsToolkit.h" -#include "nsLookAndFeel.h" -#include "nsTransferable.h" -#include "nsClipboard.h" -#include "nsClipboardHelper.h" -#include "nsHTMLFormatConverter.h" -#include "nsDragService.h" -#include "nsSound.h" -#include "nsScreenManagerXlib.h" - -#include "nsBidiKeyboard.h" - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) -NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerXlib) - -static const nsModuleComponentInfo components[] = -{ - { "Xlib nsWindow", - NS_WINDOW_CID, - "@mozilla.org/widgets/window/xlib;1", - nsWindowConstructor }, - { "Xlib Child nsWindow", - NS_CHILD_CID, - "@mozilla.org/widgets/child_window/xlib;1", - ChildWindowConstructor }, - { "Xlib AppShell", - NS_APPSHELL_CID, - "@mozilla.org/widget/appshell/xlib;1", - nsAppShellConstructor }, - { "Xlib Toolkit", - NS_TOOLKIT_CID, - "@mozilla.org/widget/toolkit/xlib;1", - nsToolkitConstructor }, - { "Xlib Look And Feel", - NS_LOOKANDFEEL_CID, - "@mozilla.org/widget/lookandfeel;1", - nsLookAndFeelConstructor }, - { "Xlib Sound", - NS_SOUND_CID, - "@mozilla.org/sound;1", - nsSoundConstructor }, - { "Transferrable", - NS_TRANSFERABLE_CID, - // "@mozilla.org/widget/transferrable/xlib;1", - "@mozilla.org/widget/transferable;1", - nsTransferableConstructor }, - { "Xlib Clipboard", - NS_CLIPBOARD_CID, - // "@mozilla.org/widget/clipboard/xlib;1", - "@mozilla.org/widget/clipboard;1", - nsClipboardConstructor }, - { "Clipboard Helper", - NS_CLIPBOARDHELPER_CID, - "@mozilla.org/widget/clipboardhelper;1", - nsClipboardHelperConstructor }, - { "HTML Format Converter", - NS_HTMLFORMATCONVERTER_CID, - "@mozilla.org/widget/htmlformatconverter;1", - nsHTMLFormatConverterConstructor }, - { "Xlib Drag Service", - NS_DRAGSERVICE_CID, - // "@mozilla.org/widget/dragservice/xlib;1", - "@mozilla.org/widget/dragservice;1", - nsDragServiceConstructor }, - { "Xlib Bidi Keyboard", - NS_BIDIKEYBOARD_CID, - "@mozilla.org/widget/bidikeyboard;1", - nsBidiKeyboardConstructor }, - { "Xlib Screen Manager", - NS_SCREENMANAGER_CID, - "@mozilla.org/gfx/screenmanager;1", - nsScreenManagerXlibConstructor } -}; - -PR_STATIC_CALLBACK(void) -nsWidgetXLIBModuleDtor(nsIModule *self) -{ - nsClipboard::Shutdown(); -} - -NS_IMPL_NSGETMODULE_WITH_DTOR(nsWidgetXLIBModule, - components, - nsWidgetXLIBModuleDtor) diff --git a/mozilla/widget/src/xlib/nsWindow.cpp b/mozilla/widget/src/xlib/nsWindow.cpp deleted file mode 100644 index 679243d9296..00000000000 --- a/mozilla/widget/src/xlib/nsWindow.cpp +++ /dev/null @@ -1,803 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * B.J. Rossiter - * Tony Tsui - * Roland Mainz - * Mats Palmgren - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsWindow.h" -#include "xlibrgb.h" - -#include "nsIRenderingContext.h" - -/* for window title unicode->locale conversion */ -#include "nsICharsetConverterManager.h" -#include "nsIPlatformCharset.h" -#include "nsIServiceManager.h" - -#define NS_WINDOW_TITLE_MAX_LENGTH 4095 - -// Variables for grabbing -PRBool nsWindow::sIsGrabbing = PR_FALSE; -nsWindow *nsWindow::sGrabWindow = nsnull; - -// Routines implementing an update queue. -// We keep a single queue for all widgets because it is -// (most likely) more efficient and better looking to handle -// all the updates in one shot. Actually, this queue should -// be at most per-toplevel. FIXME. -// - -nsListItem::nsListItem(void *aData, nsListItem *aPrev) -{ - next = nsnull; - prev = aPrev; - data = aData; -} - -nsList::nsList() -{ - head = nsnull; - tail = nsnull; -} - -nsList::~nsList() -{ - reset(); -} - -void nsList::add(void *aData) -{ - if (head == nsnull) { // We have an empty list, create the head - head = new nsListItem(aData, nsnull); - tail = head; - } else { // Append to the end of the list - tail->setNext(new nsListItem(aData, tail)); - tail = tail->getNext(); // Reset the tail - tail->setNext(nsnull); - } -} - -void nsList::remove(void *aData) -{ - if (head == nsnull) { // Removing from a null list - return; - } else { // find the data - nsListItem *aItem = head; - while ((aItem != nsnull) && (aItem->getData() != aData)) { - aItem = aItem->getNext(); - } - if (aItem == nsnull) { // we didn't find it - return; - } else - if (aItem == head) { // we have to remove the head - head = aItem->getNext(); - delete aItem; - if (head == nsnull) // we have emptied the list - tail = nsnull; - else - head->setPrev(nsnull); - } else - if (aItem == tail) { // we have to remove the tail - tail = aItem->getPrev(); - delete aItem; - if (tail == nsnull) // we have emptied the list - head = nsnull; - else - tail->setNext(nsnull); - } else { // we remove from the middle - nsListItem *prev = aItem->getPrev(); - nsListItem *next = aItem->getNext(); - delete aItem; - prev->setNext(next); - next->setPrev(prev); - } - } -} - -void nsList::reset() -{ - while (head != nsnull) { - void *aData = head->getData(); - remove(aData); - } -} - -static nsList *update_queue = nsnull; - -void -nsWindow::UpdateIdle (void *data) -{ - if (update_queue != nsnull) { - nsList *old_queue; - nsListItem *tmp_list; - - old_queue = update_queue; - update_queue = nsnull; - - for( tmp_list = old_queue->getHead() ; tmp_list != nsnull ; tmp_list = tmp_list->getNext() ) - { - nsWindow *window = NS_STATIC_CAST(nsWindow*,(tmp_list->getData())); - - window->mIsUpdating = PR_FALSE; - } - - for( tmp_list = old_queue->getHead() ; tmp_list != nsnull ; tmp_list = tmp_list->getNext() ) - { - nsWindow *window = NS_STATIC_CAST(nsWindow*,(tmp_list->getData())); - - window->Update(); - } - - delete old_queue; - } -} - -// Just raises the window. -// There should probably be checks on this. -// FIXME KenF -NS_IMETHODIMP nsWindow::GetAttention(PRInt32 aCycleCount) -{ - XRaiseWindow(mDisplay, mBaseWindow); - return NS_OK; -} - -void -nsWindow::QueueDraw () -{ - if (!mIsUpdating) - { - if (update_queue == nsnull) - update_queue = new nsList(); - update_queue->add((void *)this); - mIsUpdating = PR_TRUE; - } -} - -void -nsWindow::UnqueueDraw () -{ - if (mIsUpdating) - { - if (update_queue != nsnull) - update_queue->remove((void *)this); - mIsUpdating = PR_FALSE; - } -} - -/////////////////////////////////////////////////////////////////// -NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsWidget) -/////////////////////////////////////////////////////////////////// - -nsWindow::nsWindow() : nsWidget() -{ - mName.AssignLiteral("nsWindow"); - mBackground = NS_RGB(255, 255, 255); - mBackgroundPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBackground); - mBorderRGB = NS_RGB(255,255,255); - mBorderPixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, mBorderRGB); - - // FIXME KenF - mIsUpdating = PR_FALSE; - mBlockFocusEvents = PR_FALSE; - mLastGrabFailed = PR_TRUE; - mIsTooSmall = PR_FALSE; - - // FIXME New on M17 merge. - mWindowType = eWindowType_child; - mBorderStyle = eBorderStyle_default; - mIsToplevel = PR_FALSE; - - mScrollGC = nsnull; -} - - -nsWindow::~nsWindow() -{ - if (mScrollGC) - XFreeGC(mDisplay, mScrollGC); - - // Release grab - if (sGrabWindow == this) - { - sIsGrabbing = PR_FALSE; - sGrabWindow = nsnull; - } - - // Should get called from ~nsWidget() anyway. KenF - // if (mBaseWindow) - //Destroy(); - if (mIsUpdating) - UnqueueDraw(); -} - -PRBool nsWindow::OnExpose(nsPaintEvent &event) -{ - nsresult result = PR_TRUE; - - // call the event callback - if (mEventCallback) - { - event.renderingContext = nsnull; - - // printf("nsWindow::OnExpose\n"); - - // expose.. we didn't get an Invalidate, so we should up the count here - // mBounds.UnionRect(mBounds, event.rect); - - // SendExposeEvent(); - } - - return result; -} - -NS_IMETHODIMP nsWindow::Show(PRBool bState) -{ - // don't show if we are too small - if (mIsTooSmall) - return NS_OK; - - if (bState) { - if (mIsToplevel) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Someone just used the show method on the toplevel window.\n")); - } - - if (mParentWidget) { - ((nsWidget *)mParentWidget)->WidgetShow(this); - // Fix Popups appearing behind mozilla window. TonyT - XRaiseWindow(mDisplay, mBaseWindow); - } else { - if (mBaseWindow) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Mapping window 0x%lx...\n", mBaseWindow)); - Map(); - } - } - - mIsShown = PR_TRUE; - if (sGrabWindow == this && mLastGrabFailed) { - /* re-grab things like popup menus - the window isn't mapped when - * the first grab occurs */ - NativeGrab(PR_TRUE); - } - } else { - if (mBaseWindow) { - PR_LOG(XlibWidgetsLM, PR_LOG_DEBUG, ("Unmapping window 0x%lx...\n", mBaseWindow)); - Unmap(); - } - mIsShown = PR_FALSE; - } - return NS_OK; -} - -// Function that does native grab. -void nsWindow::NativeGrab(PRBool aGrab) -{ - mLastGrabFailed = PR_FALSE; - - if (aGrab) - { - int retval; - - Cursor newCursor = XCreateFontCursor(mDisplay, XC_right_ptr); - retval = XGrabPointer(mDisplay, mBaseWindow, PR_TRUE, (ButtonPressMask | - ButtonReleaseMask | EnterWindowMask | LeaveWindowMask - | PointerMotionMask), GrabModeAsync, GrabModeAsync, - (Window)0, newCursor, CurrentTime); - XFreeCursor(mDisplay, newCursor); - - if (retval != GrabSuccess) - mLastGrabFailed = PR_TRUE; - - retval = XGrabKeyboard(mDisplay, mBaseWindow, PR_TRUE, GrabModeAsync, - GrabModeAsync, CurrentTime); - - if (retval != GrabSuccess) - mLastGrabFailed = PR_TRUE; - - } else { - XUngrabPointer(mDisplay, CurrentTime); - XUngrabKeyboard(mDisplay, CurrentTime); - } -} - -/* This called when a popup is generated so that if a mouse down event occurs, - * the passed listener can be informed (see nsWidget::HandlePopup). It is also - * called with aDoCapture == PR_FALSE when a popup is no longer visible - */ -NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener * aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent) - { - if (aDoCapture) { - NativeGrab(PR_TRUE); - - sIsGrabbing = PR_TRUE; - sGrabWindow = this; - - gRollupConsumeRollupEvent = PR_TRUE; - gRollupListener = aListener; - gRollupWidget = do_GetWeakReference(NS_STATIC_CAST(nsIWidget*, this)); - }else{ - // Release Grab - if (sGrabWindow == this) - sGrabWindow = nsnull; - - sIsGrabbing = PR_FALSE; - - NativeGrab(PR_FALSE); - - gRollupListener = nsnull; - gRollupWidget = nsnull; - } - return NS_OK; -} - -NS_IMETHODIMP nsWindow::InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous) -{ - mUpdateArea->Union(*aRegion); - - if (aIsSynchronous) - Update(); - else - QueueDraw(); - - return NS_OK; -} - - -NS_IMETHODIMP nsWindow::SetFocus(PRBool aRaise) -{ - nsEventStatus status; - nsFocusEvent event(PR_TRUE, NS_GOTFOCUS, this); - // nsGUIEvent eventActivate; - - if (mBaseWindow) - mFocusWindow = mBaseWindow; - - if (mBlockFocusEvents) - return NS_OK; - - mBlockFocusEvents = PR_TRUE; - - AddRef(); - DispatchEvent(&event, status); - Release(); - - nsGUIEvent actEvent(PR_TRUE, NS_ACTIVATE, this); - - AddRef(); - DispatchWindowEvent(actEvent); - Release(); - - mBlockFocusEvents = PR_FALSE; - - return NS_OK; -} - -/* NOTE: Originally, nsWindow just uses Resize from nsWidget. - * Changed so it will first use the nsWidget resizing routine, then - * send out a NS_SIZE event. This makes sure that the resizing is known - * by all parts that NEED to know about it. - * event bit is common for both resizes, yes, could make it a function, - * but haven't yet.... - */ -NS_IMETHODIMP nsWindow::Resize(PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint) -{ - //printf("nsWindow::Resize aWidth=%i aHeight=%i\n", aWidth,aHeight); - PRBool NeedToShow = PR_FALSE; - /* PRInt32 sizeHeight = aHeight; - PRInt32 sizeWidth = aWidth; */ - - mBounds.width = aWidth; - mBounds.height = aHeight; - - // code to keep the window from showing before it has been moved or resized - - // if we are resized to 1x1 or less, we will hide the window. Show(TRUE) will be ignored until a - // larger resize has happened - if (aWidth <= 1 || aHeight <= 1) - { - aWidth = 1; - aHeight = 1; - mIsTooSmall = PR_TRUE; - Show(PR_FALSE); - } - else - { - if (mIsTooSmall) - { - // if we are not shown, we don't want to force a show here, so check and see if Show(TRUE) has been called - NeedToShow = mIsShown; - mIsTooSmall = PR_FALSE; - } - } - nsWidget::Resize(aWidth, aHeight, aRepaint); - - nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); - nsRect sevent_windowSize(0, 0, aWidth, aHeight); - sevent.windowSize = &sevent_windowSize; - sevent.mWinWidth = aWidth; - sevent.mWinHeight = aHeight; - AddRef(); - OnResize(sevent); - Release(); - - if (NeedToShow) - Show(PR_TRUE); - - if (aRepaint) - Invalidate(PR_FALSE); - - return NS_OK; -} - -/* NOTE: Originally, nsWindow just uses Resize from nsWidget. - * Changed so it will first use the nsWidget resizing routine, then - * send out a NS_SIZE event. This makes sure that the resizing is known - * by all parts that NEED to know about it. - */ -NS_IMETHODIMP nsWindow::Resize(PRInt32 aX, - PRInt32 aY, - PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint) -{ - //printf("nsWindow::Resize aX=%i, aY=%i, aWidth=%i, aHeight=%i\n", aX,aY,aWidth,aHeight); - - nsWidget::Resize(aX, aY, aWidth, aHeight, aRepaint); - - nsSizeEvent sevent(PR_TRUE, NS_SIZE, this); - nsRect sevent_windowSize(0, 0, aWidth, aHeight); - sevent.windowSize = &sevent_windowSize; - sevent.mWinWidth = aWidth; - sevent.mWinHeight = aHeight; - AddRef(); - OnResize(sevent); - Release(); - return NS_OK; -} - -/* virtual */ long -nsWindow::GetEventMask() -{ - long event_mask; - - event_mask = - ButtonMotionMask | - ButtonPressMask | - ButtonReleaseMask | - EnterWindowMask | - ExposureMask | - KeyPressMask | - KeyReleaseMask | - LeaveWindowMask | - PointerMotionMask | - StructureNotifyMask | - VisibilityChangeMask | - FocusChangeMask | - OwnerGrabButtonMask; - return event_mask; -} - -#undef TRACE_INVALIDATE - -#ifdef TRACE_INVALIDATE -static PRInt32 sInvalidatePrintCount = 0; -#endif - -NS_IMETHODIMP nsWindow::Invalidate(PRBool aIsSynchronous) -{ - mUpdateArea->SetTo(mBounds.x, mBounds.y, mBounds.width, mBounds.height); - - if (aIsSynchronous) - Update(); - else - QueueDraw(); - - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) -{ - mUpdateArea->Union(aRect.x, aRect.y, aRect.width, aRect.height); - if (aIsSynchronous) - Update(); - else - QueueDraw(); - - return NS_OK; -} - -void -nsWindow::DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, - nsIRegion *aClipRegion) -{ - if (mEventCallback) { - nsPaintEvent event(PR_TRUE, NS_PAINT, this); - nsRect rect(aX, aY, aWidth, aHeight); - event.refPoint.x = aX; - event.refPoint.y = aY; - event.time = PR_Now(); /* No time in EXPOSE events */ - event.rect = ▭ - - event.renderingContext = GetRenderingContext(); - if (event.renderingContext) { - DispatchWindowEvent(event); - NS_RELEASE(event.renderingContext); - } - } -} - -NS_IMETHODIMP nsWindow::Update(void) -{ - if (mIsUpdating) - UnqueueDraw(); - - if (!mUpdateArea->IsEmpty()) { - PRUint32 numRects; - mUpdateArea->GetNumRects(&numRects); - - /* We paint the rects by themselves if we have 2 to 15 rects, - * otherwise we will just paint the bounding box. */ - if (numRects != 1 && numRects < 16) { - nsRegionRectSet *regionRectSet = nsnull; - - if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) - return NS_ERROR_FAILURE; - - PRUint32 len; - PRUint32 i; - - len = regionRectSet->mRectsLen; - - for (i=0;imRects[i]); - DoPaint (r->x, r->y, r->width, r->height, mUpdateArea); - } - - mUpdateArea->FreeRects(regionRectSet); - - mUpdateArea->SetTo(0, 0, 0, 0); - return NS_OK; - } else { - PRInt32 x, y, w, h; - mUpdateArea->GetBoundingBox(&x, &y, &w, &h); - DoPaint (x, y, w, h, mUpdateArea); - mUpdateArea->SetTo(0, 0, 0, 0); - } - } - - // While I'd think you should NS_RELEASE(aPaintEvent.widget) here, - // if you do, it is a NULL pointer. Not sure where it is getting - // released. - return NS_OK; -} - -NS_IMETHODIMP nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) -{ - PR_LOG(XlibScrollingLM, PR_LOG_DEBUG, ("nsWindow::Scroll()\n")); - - if (mIsUpdating) - UnqueueDraw(); - - PRInt32 srcX = 0, srcY = 0, destX = 0, destY = 0, width = 0, height = 0; - nsRect aRect; - - /* only create GC for scolling once ... */ - if (!mScrollGC) - mScrollGC = XCreateGC(mDisplay, mBaseWindow, 0, nsnull); - - if (aDx < 0 || aDy < 0) - { - srcX = mBounds.x + PR_ABS(aDx); - srcY = mBounds.y + PR_ABS(aDy); - destX = mBounds.x; - destY = mBounds.y; - width = mBounds.width - PR_ABS(aDx); - height = mBounds.height - PR_ABS(aDy); - } - else if (aDx > 0 || aDy > 0) - { - srcX = mBounds.x; - srcY = mBounds.y; - destX = mBounds.x + PR_ABS(aDx); - destY = mBounds.y + PR_ABS(aDy); - width = mBounds.width - PR_ABS(aDx); - height = mBounds.height - PR_ABS(aDy); - } - - XCopyArea(mDisplay, mBaseWindow, mBaseWindow, mScrollGC, - srcX, srcY, width, height, destX, destY); - - width = mBounds.width; - height = mBounds.height; - - if (aDx != 0 || aDy != 0) { - if (aDx < 0) { - aRect.SetRect(width + aDx, 0, - -aDx, height); - } - else if (aDx > 0) { - aRect.SetRect(0,0, aDx, height); - } - - if (aDy < 0) { - aRect.SetRect(0, height + aDy, - width, -aDy); - } - else if (aDy > 0) { - aRect.SetRect(0,0, width, aDy); - } - - mUpdateArea->Offset(aDx, aDy); - Invalidate(aRect, PR_TRUE); - } - - //-------- - // Scroll the children - for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { - nsWindow* childWindow = NS_STATIC_CAST(nsWindow*, kid); - nsRect bounds; - childWindow->GetRequestedBounds(bounds); - childWindow->Move(bounds.x + aDx, bounds.y + aDy); - Invalidate(bounds, PR_TRUE); - } - - // If we are obscurred by another window we have to update those areas - // which were not copied with the XCopyArea function. - - if (mVisibility == VisibilityPartiallyObscured) - { - XEvent event; - PRBool needToUpdate = PR_FALSE; - mUpdateArea->SetTo(0,0,0,0); - while(XCheckWindowEvent(mDisplay, mBaseWindow, 0xffffffff, &event)) - { - if (event.type == GraphicsExpose) { - nsRect rect; - rect.SetRect(event.xgraphicsexpose.x, - event.xgraphicsexpose.y, - event.xgraphicsexpose.width, - event.xgraphicsexpose.height); - mUpdateArea->Union(rect.x, rect.y, rect.width, rect.height); - needToUpdate = PR_TRUE; - if (event.xgraphicsexpose.count == 0) { - continue; - } - } - } - if (needToUpdate) - Update(); - } - return NS_OK; -} - -NS_IMETHODIMP nsWindow::ScrollWidgets(PRInt32 aDx, PRInt32 aDy) -{ - return Scroll(aDx, aDy, nsnull); -} - -NS_IMETHODIMP nsWindow::ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy) -{ - return Scroll(aDx, aDy, nsnull); -} - -NS_IMETHODIMP nsWindow::SetTitle(const nsAString& aTitle) -{ - if(!mBaseWindow) - return NS_ERROR_FAILURE; - - nsresult rv; - char *platformText; - PRInt32 platformLen; - - nsCOMPtr encoder; - /* get the charset */ - nsCAutoString platformCharset; - nsCOMPtr platformCharsetService = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) - rv = platformCharsetService->GetCharset(kPlatformCharsetSel_Menu, platformCharset); - - if (NS_FAILED(rv)) - platformCharset.AssignLiteral("ISO-8859-1"); - - /* get the encoder */ - nsCOMPtr ccm = - do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - rv = ccm->GetUnicodeEncoderRaw(platformCharset.get(), getter_AddRefs(encoder)); - NS_ASSERTION(NS_SUCCEEDED(rv), "GetUnicodeEncoderRaw failed."); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - - /* Estimate out length and allocate the buffer based on a worst-case estimate, then do - the conversion. */ - nsAString::const_iterator begin; - const PRUnichar *title = aTitle.BeginReading(begin).get(); - PRInt32 len = (PRInt32)aTitle.Length(); - encoder->GetMaxLength(title, len, &platformLen); - if (platformLen) { - // Truncate overlong titles (bug 167315). - if (platformLen > NS_WINDOW_TITLE_MAX_LENGTH) { - platformLen = NS_WINDOW_TITLE_MAX_LENGTH; - } - platformText = NS_REINTERPRET_CAST(char*, nsMemory::Alloc(platformLen + sizeof(char))); - if (platformText) { - rv = encoder->Convert(title, &len, platformText, &platformLen); - (platformText)[platformLen] = '\0'; // null terminate. Convert() doesn't do it for us - } - } // if valid length - - if (platformLen > 0) { - int status = 0; - XTextProperty prop; - - /* Use XStdICCTextStyle for 41786(a.k.a TWM sucks) and 43108(JA text title) */ - prop.value = 0; - status = XmbTextListToTextProperty(mDisplay, &platformText, 1, - XStdICCTextStyle, &prop); - - if (status == Success) { - XSetWMProperties(mDisplay, mBaseWindow, - &prop, &prop, nsnull, 0, nsnull, nsnull, nsnull); - if (prop.value) - XFree(prop.value); - - nsMemory::Free(platformText); - return NS_OK; - } else { // status != Success - if (prop.value) - XFree(prop.value); - nsMemory::Free(platformText); - } - } - - /* if the stuff above failed, replace multibyte with .... */ - XStoreName(mDisplay, mBaseWindow, NS_LossyConvertUTF16toASCII(aTitle).get()); - - return NS_OK; -} - -ChildWindow::ChildWindow(): nsWindow() -{ - mName.AssignLiteral("nsChildWindow"); -} - - diff --git a/mozilla/widget/src/xlib/nsWindow.h b/mozilla/widget/src/xlib/nsWindow.h deleted file mode 100644 index c6b05ecd29b..00000000000 --- a/mozilla/widget/src/xlib/nsWindow.h +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Peter Hartshorn - * Ken Faulkner - * B.J. Rossiter - * Tony Tsui - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsWindow_h__ -#define nsWindow_h__ - -#include "nsWidget.h" -#include - -#include "nsString.h" - -class nsListItem { -public: - nsListItem() {} - nsListItem(void *aData, nsListItem *aPrev); - ~nsListItem() {} - - void *getData() { return data; } - nsListItem *getNext() { return next; } - void setNext(nsListItem *aNext) { next = aNext; } - nsListItem *getPrev() { return prev; }; - void setPrev(nsListItem *aPrev) { prev = aPrev; } - -private: - void *data; - nsListItem *next; - nsListItem *prev; -}; - -class nsList { -public: - nsList(); - ~nsList(); - nsListItem *getHead() { return head; } - void add(void *aData); - void remove(void *aData); - void reset(); - -private: - nsListItem *head; - nsListItem *tail; -}; - - -class nsWindow : public nsWidget -{ - public: - nsWindow(); - ~nsWindow(); - - NS_DECL_ISUPPORTS_INHERITED - - static void UpdateIdle (void *data); - NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent); - NS_IMETHOD Invalidate(PRBool aIsSynchronous); - NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous); - NS_IMETHOD InvalidateRegion(const nsIRegion* aRegion, PRBool aIsSynchronous); - NS_IMETHOD Update(); - NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); - NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy); - NS_IMETHOD ScrollRect(nsRect &aSrcRect, PRInt32 aDx, PRInt32 aDy); - - NS_IMETHOD SetTitle(const nsAString& aTitle); - NS_IMETHOD Show(PRBool aShow); - - NS_IMETHOD Resize(PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint); - NS_IMETHOD Resize(PRInt32 aX, - PRInt32 aY, - PRInt32 aWidth, - PRInt32 aHeight, - PRBool aRepaint); - - - NS_IMETHOD SetFocus(PRBool aRaise); - virtual PRBool OnExpose(nsPaintEvent &event); - NS_IMETHOD GetAttention(PRInt32 aCycleCount); - -protected: - virtual long GetEventMask(); - - // Keyboard and Pointer Grabbing - void NativeGrab(PRBool aGrab); - - void DoPaint (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, - nsIRegion *aClipRegion); - - void QueueDraw(); - void UnqueueDraw(); - PRBool mIsUpdating; - PRBool mBlockFocusEvents; - PRBool mIsTooSmall; - - GC mScrollGC; // GC used by nsWindow::Scroll() - - static PRBool sIsGrabbing; - static nsWindow *sGrabWindow; - -#if 0 - virtual void CreateNative(Window aParent, nsRect aRect); -#endif -}; - -class ChildWindow : public nsWindow -{ - public: - ChildWindow(); - virtual PRInt32 IsChild() { return PR_TRUE; }; -}; - -#endif diff --git a/mozilla/widget/src/xlib/nsXUtils.cpp b/mozilla/widget/src/xlib/nsXUtils.cpp deleted file mode 100644 index fed0f652fe0..00000000000 --- a/mozilla/widget/src/xlib/nsXUtils.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsXUtils.h" - -#include -#include - -#ifdef NEED_USLEEP_PROTOTYPE -extern "C" int usleep(unsigned int); -#endif -#if defined(__QNX__) -#define usleep(s) sleep(s) -#endif - -////////////////////////////////////////////////////////////////// -/* static */ void -nsXUtils::XFlashWindow(Display * aDisplay, - Window aWindow, - unsigned int aTimes, - unsigned long aInterval, - XRectangle * aArea) -{ - Window root_window = 0; - Window child_window = 0; - GC gc; - int x; - int y; - unsigned int width; - unsigned int height; - unsigned int border_width; - unsigned int depth; - int root_x; - int root_y; - unsigned int i; - XGCValues gcv; - - XGetGeometry(aDisplay, - aWindow, - &root_window, - &x, - &y, - &width, - &height, - &border_width, - &depth); - - XTranslateCoordinates(aDisplay, - aWindow, - root_window, - 0, - 0, - &root_x, - &root_y, - &child_window); - - memset(&gcv, 0, sizeof(XGCValues)); - - gcv.function = GXxor; - gcv.foreground = XWhitePixel(aDisplay, XDefaultScreen(aDisplay)); - gcv.subwindow_mode = IncludeInferiors; - - if (gcv.foreground == 0) - gcv.foreground = 1; - - gc = XCreateGC(aDisplay, - root_window, - GCFunction | GCForeground | GCSubwindowMode, - &gcv); - - XGrabServer(aDisplay); - - // If an area is given, use that. Notice how out of whack coordinates - // and dimentsions are not checked!!! - if (aArea) - { - root_x += aArea->x; - root_y += aArea->y; - - width = aArea->width; - height = aArea->height; - } - - // Need to do this twice so that the XOR effect can replace - // the original window contents. - for (i = 0; i < aTimes * 2; i++) - { - XFillRectangle(aDisplay, - root_window, - gc, - root_x, - root_y, - width, - height); - - XSync(aDisplay, False); - - usleep(aInterval); - } - - - XFreeGC(aDisplay, gc); - - XUngrabServer(aDisplay); -} -/*****************************************************************/ diff --git a/mozilla/widget/src/xlib/nsXUtils.h b/mozilla/widget/src/xlib/nsXUtils.h deleted file mode 100644 index b2f50543dc7..00000000000 --- a/mozilla/widget/src/xlib/nsXUtils.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __nsXUtils_h -#define __nsXUtils_h - -#include - -struct nsXUtils -{ - /** - * Flash an area within a window (or the whole window) - * - * @param aDisplay The display. - * @param aWindow The XID of the window to flash. - * @param aTimes Number of times to flash the area. - * @param aInterval Interval between flashes in milliseconds. - * @param aArea The area to flash. The whole window if NULL. - * - */ - static void XFlashWindow(Display * aDisplay, - Window aWindow, - unsigned int aTimes, - unsigned long aInterval, - XRectangle * aArea); -}; - -#endif // __nsXUtils_h diff --git a/mozilla/widget/src/xlib/nsXlibCursors.h b/mozilla/widget/src/xlib/nsXlibCursors.h deleted file mode 100644 index cfdbb40b018..00000000000 --- a/mozilla/widget/src/xlib/nsXlibCursors.h +++ /dev/null @@ -1,492 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim:ts=2:et:sw=2 - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Tim Copperfield. Portions created by Tim Copperfield are Copyright (C) Tim Copperfield. All Rights Reserved. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Tim Copperfield - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsXlibCursors_h__ -#define nsXlibCursors_h__ - -typedef struct { - const unsigned char *bits; - const unsigned char *mask_bits; - int hot_x; - int hot_y; -} nsXlibCursor; - -/* XLIB_QUESTION_ARROW */ -static const unsigned char xlib_question_arrow_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0xe3, 0x00, 0x00, 0x7c, 0xb0, 0x01, 0x00, 0x6c, 0x80, 0x01, 0x00, - 0xc4, 0xc0, 0x00, 0x00, 0xc0, 0x60, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, - 0x80, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_question_arrow_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0xe3, 0x00, 0x00, - 0xfe, 0xf7, 0x01, 0x00, 0xfe, 0xfb, 0x03, 0x00, 0xfe, 0xf0, 0x03, 0x00, - 0xee, 0xe1, 0x01, 0x00, 0xe4, 0xf1, 0x00, 0x00, 0xc0, 0x63, 0x00, 0x00, - 0xc0, 0xf3, 0x00, 0x00, 0x80, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_HAND_GRAB */ -static const unsigned char xlib_hand_grab_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, - 0x60, 0x39, 0x00, 0x00, 0x90, 0x49, 0x00, 0x00, 0x90, 0x49, 0x01, 0x00, - 0x20, 0xc9, 0x02, 0x00, 0x20, 0x49, 0x02, 0x00, 0x58, 0x40, 0x02, 0x00, - 0x64, 0x00, 0x02, 0x00, 0x44, 0x00, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, - 0x10, 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, - 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_hand_grab_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x60, 0x3f, 0x00, 0x00, - 0xf0, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf8, 0xff, 0x03, 0x00, - 0xf0, 0xff, 0x07, 0x00, 0xf8, 0xff, 0x07, 0x00, 0xfc, 0xff, 0x07, 0x00, - 0xfe, 0xff, 0x07, 0x00, 0xfe, 0xff, 0x03, 0x00, 0xfc, 0xff, 0x03, 0x00, - 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x01, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_HAND_GRABBING */ -static const unsigned char xlib_hand_grabbing_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xc0, 0x36, 0x00, 0x00, 0x20, 0xc9, 0x00, 0x00, 0x20, 0x40, 0x01, 0x00, - 0x40, 0x00, 0x01, 0x00, 0x60, 0x00, 0x01, 0x00, 0x10, 0x00, 0x01, 0x00, - 0x10, 0x00, 0x01, 0x00, 0x10, 0x80, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, - 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_hand_grabbing_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x36, 0x00, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x03, 0x00, - 0xe0, 0xff, 0x03, 0x00, 0xf0, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x03, 0x00, - 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x01, 0x00, - 0xe0, 0xff, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_COPY */ -static const unsigned char xlib_copy_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x03, 0x00, 0x00, 0x7c, 0x30, 0x00, 0x00, 0x6c, 0x30, 0x00, 0x00, - 0xc4, 0xfc, 0x00, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, - 0x80, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_copy_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, - 0xfe, 0x37, 0x00, 0x00, 0xfe, 0x7b, 0x00, 0x00, 0xfe, 0xfc, 0x00, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x00, 0x00, - 0xc0, 0x7b, 0x00, 0x00, 0x80, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_ALIAS */ -static const unsigned char xlib_alias_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x03, 0x00, 0x00, 0x7c, 0xf0, 0x00, 0x00, 0x6c, 0xe0, 0x00, 0x00, - 0xc4, 0xf0, 0x00, 0x00, 0xc0, 0xb0, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, - 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_alias_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x03, 0x00, 0x00, - 0xfe, 0xf7, 0x00, 0x00, 0xfe, 0xfb, 0x01, 0x00, 0xfe, 0xf0, 0x01, 0x00, - 0xee, 0xf9, 0x01, 0x00, 0xe4, 0xf9, 0x01, 0x00, 0xc0, 0xbf, 0x00, 0x00, - 0xc0, 0x3f, 0x00, 0x00, 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_CONTEXT_MENU */ -static const unsigned char xlib_menu_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0xfd, 0x00, 0x00, - 0xfc, 0xff, 0x00, 0x00, 0x7c, 0x84, 0x00, 0x00, 0x6c, 0xfc, 0x00, 0x00, - 0xc4, 0x84, 0x00, 0x00, 0xc0, 0xfc, 0x00, 0x00, 0x80, 0x85, 0x00, 0x00, - 0x80, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_menu_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0xfd, 0x00, 0x00, 0xfe, 0xff, 0x01, 0x00, - 0xfe, 0xff, 0x01, 0x00, 0xfe, 0xff, 0x01, 0x00, 0xfe, 0xfe, 0x01, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0xc0, 0xff, 0x01, 0x00, 0x80, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_SPINNING */ -static const unsigned char xlib_spinning_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00, 0x00, - 0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00, - 0xc4, 0xdc, 0x00, 0x00, 0xc0, 0x44, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, - 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_spinning_mask_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - 0xfe, 0x00, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfe, 0x3b, 0x00, 0x00, - 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0xfe, 0x00, 0x00, - 0xee, 0xff, 0x01, 0x00, 0xe4, 0xff, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, - 0xc0, 0x7f, 0x00, 0x00, 0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_ZOOM_IN */ -static const unsigned char xlib_zoom_in_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x62, 0x04, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00, - 0xf9, 0x09, 0x00, 0x00, 0x61, 0x08, 0x00, 0x00, 0x62, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_zoom_in_mask_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_ZOOM_OUT */ -static const unsigned char xlib_zoom_out_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0xf9, 0x09, 0x00, 0x00, - 0xf9, 0x09, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, - 0x02, 0x04, 0x00, 0x00, 0x0c, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_zoom_out_mask_bits[] = { - 0xf0, 0x00, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, - 0xff, 0x0f, 0x00, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0xf0, 0x1c, 0x00, 0x00, - 0x00, 0x38, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_NOT_ALLOWED */ -static const unsigned char xlib_not_allowed_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, - 0xf0, 0xf0, 0x00, 0x00, 0x38, 0xc0, 0x01, 0x00, 0x7c, 0x80, 0x03, 0x00, - 0xec, 0x00, 0x03, 0x00, 0xce, 0x01, 0x07, 0x00, 0x86, 0x03, 0x06, 0x00, - 0x06, 0x07, 0x06, 0x00, 0x06, 0x0e, 0x06, 0x00, 0x06, 0x1c, 0x06, 0x00, - 0x0e, 0x38, 0x07, 0x00, 0x0c, 0x70, 0x03, 0x00, 0x1c, 0xe0, 0x03, 0x00, - 0x38, 0xc0, 0x01, 0x00, 0xf0, 0xf0, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, - 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_not_allowed_mask_bits[] = { - 0x80, 0x1f, 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, - 0xf8, 0xff, 0x01, 0x00, 0xfc, 0xf0, 0x03, 0x00, 0xfe, 0xc0, 0x07, 0x00, - 0xfe, 0x81, 0x07, 0x00, 0xff, 0x83, 0x0f, 0x00, 0xcf, 0x07, 0x0f, 0x00, - 0x8f, 0x0f, 0x0f, 0x00, 0x0f, 0x1f, 0x0f, 0x00, 0x0f, 0x3e, 0x0f, 0x00, - 0x1f, 0xfc, 0x0f, 0x00, 0x1e, 0xf8, 0x07, 0x00, 0x3e, 0xf0, 0x07, 0x00, - 0xfc, 0xf0, 0x03, 0x00, 0xf8, 0xff, 0x01, 0x00, 0xf0, 0xff, 0x00, 0x00, - 0xe0, 0x7f, 0x00, 0x00, 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_COL_RESIZE */ -static const unsigned char xlib_col_resize_bits[] = { - 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x05, 0x00, 0x00, 0x10, 0x45, 0x00, 0x00, 0x18, 0xc5, 0x00, 0x00, - 0x1c, 0xc5, 0x01, 0x00, 0x7e, 0xf5, 0x03, 0x00, 0x1c, 0xc5, 0x01, 0x00, - 0x18, 0xc5, 0x00, 0x00, 0x10, 0x45, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_col_resize_mask_bits[] = { - 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, - 0x90, 0x4f, 0x00, 0x00, 0xb8, 0xef, 0x00, 0x00, 0xbc, 0xef, 0x01, 0x00, - 0xbe, 0xef, 0x03, 0x00, 0xff, 0xff, 0x07, 0x00, 0xbe, 0xef, 0x03, 0x00, - 0xbc, 0xef, 0x01, 0x00, 0xb8, 0xef, 0x00, 0x00, 0x90, 0x4f, 0x00, 0x00, - 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_ROW_RESIZE */ -static const unsigned char xlib_row_resize_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, - 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, - 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_row_resize_mask_bits[] = { - 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, - 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, - 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, - 0xf0, 0x07, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_VERTICAL_TEXT */ -static const unsigned char xlib_vertical_text_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, - 0x06, 0x60, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0x06, 0x60, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_vertical_text_mask_bits[] = { - 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, - 0xff, 0xff, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, - 0x0f, 0xf0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_NESW_RESIZE */ -static const unsigned char xlib_nesw_resize_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0x00, 0xbe, 0x00, 0x00, 0x00, 0xbc, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, - 0x02, 0xb4, 0x00, 0x00, 0x02, 0xa2, 0x00, 0x00, 0x02, 0x81, 0x00, 0x00, - 0x8a, 0x80, 0x00, 0x00, 0x5a, 0x80, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, - 0x7a, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xfe, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_nesw_resize_mask_bits[] = { - 0xc0, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0x00, 0xff, 0x01, 0x00, 0x00, 0xfe, 0x01, 0x00, 0x00, 0xfc, 0x01, 0x00, - 0x07, 0xfe, 0x01, 0x00, 0x07, 0xf7, 0x01, 0x00, 0x8f, 0xe3, 0x01, 0x00, - 0xdf, 0xc1, 0x01, 0x00, 0xff, 0xc0, 0x01, 0x00, 0x7f, 0x00, 0x00, 0x00, - 0xff, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, - 0xff, 0x07, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* XLIB_NWSE_RESIZE */ -static const unsigned char xlib_nwse_resize_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0xfe, 0x07, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, - 0xfa, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, - 0x5a, 0x80, 0x00, 0x00, 0x8a, 0x80, 0x00, 0x00, 0x02, 0x81, 0x00, 0x00, - 0x02, 0xa2, 0x00, 0x00, 0x02, 0xb4, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, - 0x00, 0xbc, 0x00, 0x00, 0x00, 0xbe, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, - 0xc0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -static const unsigned char xlib_nwse_resize_mask_bits[] = { - 0xff, 0x07, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, 0xff, 0x07, 0x00, 0x00, - 0xff, 0x01, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, - 0xff, 0xc0, 0x01, 0x00, 0xdf, 0xc1, 0x01, 0x00, 0x8f, 0xe3, 0x01, 0x00, - 0x07, 0xf7, 0x01, 0x00, 0x07, 0xfe, 0x01, 0x00, 0x00, 0xfc, 0x01, 0x00, - 0x00, 0xfe, 0x01, 0x00, 0x00, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, - 0xc0, 0xff, 0x01, 0x00, 0xc0, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -enum { - XLIB_QUESTION_ARROW = 0, - XLIB_HAND_GRAB, - XLIB_HAND_GRABBING, - XLIB_COPY, - XLIB_ALIAS, - XLIB_CONTEXT_MENU, - XLIB_SPINNING, - XLIB_ZOOM_IN, - XLIB_ZOOM_OUT, - XLIB_NOT_ALLOWED, - XLIB_COL_RESIZE, - XLIB_ROW_RESIZE, - XLIB_VERTICAL_TEXT, - XLIB_NESW_RESIZE, - XLIB_NWSE_RESIZE -}; - -static const nsXlibCursor XlibCursors[] = { - { xlib_question_arrow_bits, xlib_question_arrow_mask_bits, 2, 2 }, - { xlib_hand_grab_bits, xlib_hand_grab_mask_bits, 10, 10 }, - { xlib_hand_grabbing_bits, xlib_hand_grabbing_mask_bits, 10, 10 }, - { xlib_copy_bits, xlib_copy_mask_bits, 2, 2 }, - { xlib_alias_bits, xlib_alias_mask_bits, 2, 2 }, - { xlib_menu_bits, xlib_menu_mask_bits, 2, 2 }, - { xlib_spinning_bits, xlib_spinning_mask_bits, 2, 2 }, - { xlib_zoom_in_bits, xlib_zoom_in_mask_bits, 6, 6 }, - { xlib_zoom_out_bits, xlib_zoom_out_mask_bits, 6, 6 }, - { xlib_not_allowed_bits, xlib_not_allowed_mask_bits, 9, 9 }, - { xlib_col_resize_bits, xlib_col_resize_mask_bits, 9, 7 }, - { xlib_row_resize_bits, xlib_row_resize_mask_bits, 7, 9 }, - { xlib_vertical_text_bits, xlib_vertical_text_mask_bits, 8, 4 }, - { xlib_nesw_resize_bits, xlib_nesw_resize_mask_bits, 8, 8 }, - { xlib_nwse_resize_bits, xlib_nwse_resize_mask_bits, 8, 8 } -}; - -#endif /* nsXlibCursors_h__ */ diff --git a/mozilla/widget/src/xlib/widget_xlib.pkg b/mozilla/widget/src/xlib/widget_xlib.pkg deleted file mode 100644 index faf3766ff50..00000000000 --- a/mozilla/widget/src/xlib/widget_xlib.pkg +++ /dev/null @@ -1,6 +0,0 @@ -[gecko] -#if SHARED_LIBRARY -dist/bin/components/@SHARED_LIBRARY@ -#else -!staticcomp @LIBRARY@ @MODULE_NAME@ -#endif diff --git a/mozilla/widget/src/xlibxtbin/Makefile.in b/mozilla/widget/src/xlibxtbin/Makefile.in deleted file mode 100644 index 25cc6baec40..00000000000 --- a/mozilla/widget/src/xlibxtbin/Makefile.in +++ /dev/null @@ -1,74 +0,0 @@ -# -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is mozilla.org Code. -# -# The Initial Developer of the Original Code is -# Netscape Communications Corporation. -# Portions created by the Initial Developer are Copyright (C) 1998 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Rusty Lynch (rusty.lynch@intel.com) -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = xlibxtbin -LIBRARY_NAME = xlibxtbin -EXPORT_LIBRARY = 1 -LIBXUL_LIBRARY = 1 - -PACKAGE_FILE = xlibxtbin.pkg - -REQUIRES = xlibrgb - -CPPSRCS = \ - xlibxtbin.cpp \ - -EXTRA_DSO_LDOPTS += -L$(DIST)/bin -L$(DIST)/lib -lxlibrgb - -EXTRA_DSO_LDOPTS += $(MOZ_XLIB_LDFLAGS) -L/usr/X11R6/lib -lXt - -EXPORTS = xlibxtbin.h - -include $(topsrcdir)/config/rules.mk - -CFLAGS += $(MOZ_XLIB_CFLAGS) - -DEFINES += -D_IMPL_NS_WIDGET -DUSE_XIM - -INCLUDES += \ - -I$(srcdir) \ - $(NULL) - diff --git a/mozilla/widget/src/xlibxtbin/xlibxtbin.cpp b/mozilla/widget/src/xlibxtbin/xlibxtbin.cpp deleted file mode 100644 index ac1549b73b2..00000000000 --- a/mozilla/widget/src/xlibxtbin/xlibxtbin.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* widget -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim:ts=2:et:sw=2 */ - -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Peter Hartshorn. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Based on GtkXtBin by Rusty Lynch - 02/27/2000 - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "xlibxtbin.h" -#include "xlibrgb.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -xtbin::xtbin() { - initialized = False; - xtwindow = None; -} - -xtbin::~xtbin() { -} - -void xtbin::xtbin_init() { - mXlibRgbHandle = xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE); - xtdisplay = xxlib_rgb_get_display(mXlibRgbHandle); - if (!xtdisplay) - abort(); - app_context = XtDisplayToApplicationContext(xtdisplay); - initialized = True; -} - -void xtbin::xtbin_realize() { - Arg args[2]; - int n; - Widget top_widget; - Widget embedded; - XSetWindowAttributes attr; - unsigned long mask; - - attr.bit_gravity = NorthWestGravity; - attr.event_mask = - ButtonMotionMask | - ButtonPressMask | - ButtonReleaseMask | - EnterWindowMask | - ExposureMask | - KeyPressMask | - KeyReleaseMask | - LeaveWindowMask | - PointerMotionMask | - StructureNotifyMask | - VisibilityChangeMask | - FocusChangeMask; - - attr.colormap = xxlib_rgb_get_cmap(mXlibRgbHandle); - attr.background_pixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, 0xFFC0C0C0); - attr.border_pixel = xxlib_rgb_xpixel_from_rgb(mXlibRgbHandle, 0xFF646464); - -#ifdef DEBUG - printf("attr.background_pixel = %lx, attr.border_pixel = %lx, parent_window = %x\n", - (long)attr.background_pixel, - (long)attr.border_pixel, (int)parent_window); -#endif /* DEBUG */ - - mask = CWBitGravity | CWEventMask | CWBorderPixel | CWBackPixel; - - if (attr.colormap) - mask |= CWColormap; - - window = XCreateWindow(xtdisplay, parent_window, - x, y, width, height, 0, - xxlib_rgb_get_depth(mXlibRgbHandle), - InputOutput, xxlib_rgb_get_visual(mXlibRgbHandle), - mask, &attr); - XSetWindowBackgroundPixmap(xtdisplay, window, None); - XSelectInput(xtdisplay, window, ExposureMask); - - XMapWindow(xtdisplay, window); - XFlush(xtdisplay); - - top_widget = XtAppCreateShell("drawingArea", "Wrapper", - applicationShellWidgetClass, xtdisplay, - NULL, 0); - - xtwidget = top_widget; - - n = 0; - XtSetArg(args[n], XtNheight, height); n++; - XtSetArg(args[n], XtNwidth, width); n++; - XtSetValues(top_widget, args, n); - - embedded = XtVaCreateWidget("form", compositeWidgetClass, top_widget, NULL); - - n = 0; - XtSetArg(args[n], XtNheight, height); n++; - XtSetArg(args[n], XtNwidth, width); n++; - XtSetValues(embedded, args, n); - - oldwindow = top_widget->core.window; - top_widget->core.window = window; - - XtRegisterDrawable(xtdisplay, window, top_widget); - - XtRealizeWidget(embedded); - XtRealizeWidget(top_widget); - XtManageChild(embedded); - - /* Now fill out the xtbin info */ - xtwindow = XtWindow(embedded); - - /* Suppress background refresh flashing */ - XSetWindowBackgroundPixmap(xtdisplay, XtWindow(top_widget), None); - XSetWindowBackgroundPixmap(xtdisplay, XtWindow(embedded), None); - - /* Listen to all Xt events */ - XSelectInput(xtdisplay, XtWindow(top_widget), 0x0fffff); - XSelectInput(xtdisplay, XtWindow(embedded), 0x0fffff); - - sync(); -} - -void xtbin::xtbin_new(Window aParent) { - parent_window = aParent; -} - -void xtbin::sync() { - /* is this really all ? */ - XSync(xtdisplay, False); -} - -void xtbin::xtbin_destroy() { - sync(); - XtUnregisterDrawable(xtdisplay, xtwindow); - sync(); - xtwidget->core.window = oldwindow; - XtUnrealizeWidget(xtwidget); - initialized = False; -} - -void xtbin::xtbin_resize(int aX, int aY, int aWidth, int aHeight) { - x = aX; - y = aY; - width = aWidth; - height = aHeight; -} - -int xtbin::xtbin_initialized() { - return initialized; -} - diff --git a/mozilla/widget/src/xlibxtbin/xlibxtbin.h b/mozilla/widget/src/xlibxtbin/xlibxtbin.h deleted file mode 100644 index 4f8b0365976..00000000000 --- a/mozilla/widget/src/xlibxtbin/xlibxtbin.h +++ /dev/null @@ -1,130 +0,0 @@ -/* widget -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim:ts=2:et:sw=2 */ - -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Peter Hartshorn. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Based on GtkXtBin by Rusty Lynch - 02/27/2000 - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef __XLIB_XTBIN_H__ -#define __XLIB_XTBIN_H__ - -#include "xlibrgb.h" - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -typedef struct _XtTMRec { - XtTranslations translations; /* private to Translation Manager */ - XtBoundActions proc_table; /* procedure bindings for actions */ - struct _XtStateRec *current_state; /* Translation Manager state ptr */ - unsigned long lastEventTime; -} XtTMRec, *XtTM; - -typedef struct _CorePart { - Widget self; /* pointer to widget itself */ - WidgetClass widget_class; /* pointer to Widget's ClassRec */ - Widget parent; /* parent widget */ - XrmName xrm_name; /* widget resource name quarkified */ - Boolean being_destroyed; /* marked for destroy */ - XtCallbackList destroy_callbacks; /* who to call when widget destroyed */ - XtPointer constraints; /* constraint record */ - Position x, y; /* window position */ - Dimension width, height; /* window dimensions */ - Dimension border_width; /* window border width */ - Boolean managed; /* is widget geometry managed? */ - Boolean sensitive; /* is widget sensitive to user events*/ - Boolean ancestor_sensitive; /* are all ancestors sensitive? */ - XtEventTable event_table; /* private to event dispatcher */ - XtTMRec tm; /* translation management */ - XtTranslations accelerators; /* accelerator translations */ - Pixel border_pixel; /* window border pixel */ - Pixmap border_pixmap; /* window border pixmap or NULL */ - WidgetList popup_list; /* list of popups */ - Cardinal num_popups; /* how many popups */ - String name; /* widget resource name */ - Screen *screen; /* window's screen */ - Colormap colormap; /* colormap */ - Window window; /* window ID */ - Cardinal depth; /* number of planes in window */ - Pixel background_pixel; /* window background pixel */ - Pixmap background_pixmap; /* window background pixmap or NULL */ - Boolean visible; /* is window mapped and not occluded?*/ - Boolean mapped_when_managed;/* map window if it's managed? */ -} CorePart; - -typedef struct _WidgetRec { - CorePart core; - } WidgetRec, CoreRec; -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -class xtbin { -public: - xtbin(); - ~xtbin(); - - void xtbin_init(); - void xtbin_realize(); - void xtbin_new(Window aParent); - void xtbin_destroy(); - void xtbin_resize(int aX, int aY, int aWidth, int aHeight); - Window xtbin_xtwindow() { return xtwindow; } - int xtbin_initialized(); - void sync(); - -private: - int initialized; - XlibRgbHandle *mXlibRgbHandle; - Display *xtdisplay; - Window xtwindow; - XtAppContext app_context; - Window parent_window; - Widget xtwidget; - Window window; - Window oldwindow; - int x, y, width, height; -}; - - -#endif /* __XLIB_XTBIN_H__ */ - diff --git a/mozilla/widget/src/xlibxtbin/xlibxtbin.pkg b/mozilla/widget/src/xlibxtbin/xlibxtbin.pkg deleted file mode 100644 index 81976c1468a..00000000000 --- a/mozilla/widget/src/xlibxtbin/xlibxtbin.pkg +++ /dev/null @@ -1,4 +0,0 @@ -[gecko] -#if SHARED_LIBRARY -dist/bin/@SHARED_LIBRARY@ -#endif