From b44c065b1dbca9359db22766e350f184f117e177 Mon Sep 17 00:00:00 2001 From: "seawood%netscape.com" Date: Sat, 22 Feb 2003 07:14:37 +0000 Subject: [PATCH] Remove qt toolkit support from the tree. Use the QT_LAST_RITES tag to pull the last known "good" tree to continue work on the port. Bug #178987 r=bryner --- allmakefiles.sh | 3 - config/autoconf.mk.in | 4 - configure.in | 102 +- gfx/src/Makefile.in | 3 - gfx/src/qt/.cvsignore | 1 - gfx/src/qt/Makefile.in | 113 - gfx/src/qt/nsDeviceContextQT.cpp | 560 ----- gfx/src/qt/nsDeviceContextQT.h | 119 - gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp | 80 - gfx/src/qt/nsDeviceContextSpecFactoryQT.h | 64 - gfx/src/qt/nsDeviceContextSpecQT.cpp | 1053 -------- gfx/src/qt/nsDeviceContextSpecQT.h | 130 - gfx/src/qt/nsDrawingSurfaceQT.cpp | 262 -- gfx/src/qt/nsDrawingSurfaceQT.h | 108 - gfx/src/qt/nsFontMetricsQT.cpp | 2259 ------------------ gfx/src/qt/nsFontMetricsQT.h | 234 -- gfx/src/qt/nsGfxFactoryQT.cpp | 175 -- gfx/src/qt/nsIDrawingSurfaceQT.h | 86 - gfx/src/qt/nsImageQT.cpp | 480 ---- gfx/src/qt/nsImageQT.h | 157 -- gfx/src/qt/nsRegionQT.cpp | 263 -- gfx/src/qt/nsRegionQT.h | 87 - gfx/src/qt/nsRenderingContextQT.cpp | 1563 ------------ gfx/src/qt/nsRenderingContextQT.h | 243 -- gfx/src/qt/nsScreenManagerQT.cpp | 137 -- gfx/src/qt/nsScreenManagerQT.h | 71 - gfx/src/qt/nsScreenQT.cpp | 113 - gfx/src/qt/nsScreenQT.h | 63 - gfx/src/qt/qtlog.h | 49 - modules/plugin/base/src/Makefile.in | 6 - modules/plugin/base/src/nsPluginHostImpl.cpp | 9 - webshell/tests/viewer/.cvsignore | 3 - webshell/tests/viewer/Makefile.in | 18 +- widget/src/Makefile.in | 4 - widget/src/qt/.cvsignore | 10 - widget/src/qt/Makefile.in | 113 - widget/src/qt/nsAppShell.cpp | 263 -- widget/src/qt/nsAppShell.h | 63 - widget/src/qt/nsBidiKeyboard.cpp | 46 - widget/src/qt/nsBidiKeyboard.h | 39 - widget/src/qt/nsButton.cpp | 125 - widget/src/qt/nsButton.h | 92 - widget/src/qt/nsCheckButton.cpp | 147 -- widget/src/qt/nsCheckButton.h | 88 - widget/src/qt/nsClipboard.cpp | 361 --- widget/src/qt/nsClipboard.h | 78 - widget/src/qt/nsDragService.cpp | 299 --- widget/src/qt/nsDragService.h | 89 - widget/src/qt/nsIDragSessionQt.h | 61 - widget/src/qt/nsLabel.cpp | 183 -- widget/src/qt/nsLabel.h | 92 - widget/src/qt/nsLookAndFeel.cpp | 425 ---- widget/src/qt/nsLookAndFeel.h | 54 - widget/src/qt/nsMime.cpp | 174 -- widget/src/qt/nsMime.h | 96 - widget/src/qt/nsQApplication.cpp | 443 ---- widget/src/qt/nsQApplication.h | 93 - widget/src/qt/nsQEventHandler.cpp | 806 ------- widget/src/qt/nsQEventHandler.h | 82 - widget/src/qt/nsQWidget.cpp | 1127 --------- widget/src/qt/nsQWidget.h | 189 -- widget/src/qt/nsScrollbar.cpp | 402 ---- widget/src/qt/nsScrollbar.h | 155 -- widget/src/qt/nsTextHelper.cpp | 351 --- widget/src/qt/nsTextHelper.h | 79 - widget/src/qt/nsTextWidget.cpp | 108 - widget/src/qt/nsTextWidget.h | 78 - widget/src/qt/nsToolkit.cpp | 117 - widget/src/qt/nsToolkit.h | 58 - widget/src/qt/nsWidget.cpp | 892 ------- widget/src/qt/nsWidget.h | 199 -- widget/src/qt/nsWidgetFactory.cpp | 178 -- widget/src/qt/nsWindow.cpp | 537 ----- widget/src/qt/nsWindow.h | 126 - 74 files changed, 3 insertions(+), 17537 deletions(-) delete mode 100644 gfx/src/qt/.cvsignore delete mode 100644 gfx/src/qt/Makefile.in delete mode 100644 gfx/src/qt/nsDeviceContextQT.cpp delete mode 100644 gfx/src/qt/nsDeviceContextQT.h delete mode 100644 gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp delete mode 100644 gfx/src/qt/nsDeviceContextSpecFactoryQT.h delete mode 100644 gfx/src/qt/nsDeviceContextSpecQT.cpp delete mode 100644 gfx/src/qt/nsDeviceContextSpecQT.h delete mode 100644 gfx/src/qt/nsDrawingSurfaceQT.cpp delete mode 100644 gfx/src/qt/nsDrawingSurfaceQT.h delete mode 100644 gfx/src/qt/nsFontMetricsQT.cpp delete mode 100644 gfx/src/qt/nsFontMetricsQT.h delete mode 100644 gfx/src/qt/nsGfxFactoryQT.cpp delete mode 100644 gfx/src/qt/nsIDrawingSurfaceQT.h delete mode 100644 gfx/src/qt/nsImageQT.cpp delete mode 100644 gfx/src/qt/nsImageQT.h delete mode 100644 gfx/src/qt/nsRegionQT.cpp delete mode 100644 gfx/src/qt/nsRegionQT.h delete mode 100644 gfx/src/qt/nsRenderingContextQT.cpp delete mode 100644 gfx/src/qt/nsRenderingContextQT.h delete mode 100644 gfx/src/qt/nsScreenManagerQT.cpp delete mode 100644 gfx/src/qt/nsScreenManagerQT.h delete mode 100644 gfx/src/qt/nsScreenQT.cpp delete mode 100644 gfx/src/qt/nsScreenQT.h delete mode 100644 gfx/src/qt/qtlog.h delete mode 100644 widget/src/qt/.cvsignore delete mode 100644 widget/src/qt/Makefile.in delete mode 100644 widget/src/qt/nsAppShell.cpp delete mode 100644 widget/src/qt/nsAppShell.h delete mode 100644 widget/src/qt/nsBidiKeyboard.cpp delete mode 100644 widget/src/qt/nsBidiKeyboard.h delete mode 100644 widget/src/qt/nsButton.cpp delete mode 100644 widget/src/qt/nsButton.h delete mode 100644 widget/src/qt/nsCheckButton.cpp delete mode 100644 widget/src/qt/nsCheckButton.h delete mode 100644 widget/src/qt/nsClipboard.cpp delete mode 100644 widget/src/qt/nsClipboard.h delete mode 100644 widget/src/qt/nsDragService.cpp delete mode 100644 widget/src/qt/nsDragService.h delete mode 100644 widget/src/qt/nsIDragSessionQt.h delete mode 100644 widget/src/qt/nsLabel.cpp delete mode 100644 widget/src/qt/nsLabel.h delete mode 100644 widget/src/qt/nsLookAndFeel.cpp delete mode 100644 widget/src/qt/nsLookAndFeel.h delete mode 100644 widget/src/qt/nsMime.cpp delete mode 100644 widget/src/qt/nsMime.h delete mode 100644 widget/src/qt/nsQApplication.cpp delete mode 100644 widget/src/qt/nsQApplication.h delete mode 100644 widget/src/qt/nsQEventHandler.cpp delete mode 100644 widget/src/qt/nsQEventHandler.h delete mode 100644 widget/src/qt/nsQWidget.cpp delete mode 100644 widget/src/qt/nsQWidget.h delete mode 100644 widget/src/qt/nsScrollbar.cpp delete mode 100644 widget/src/qt/nsScrollbar.h delete mode 100644 widget/src/qt/nsTextHelper.cpp delete mode 100644 widget/src/qt/nsTextHelper.h delete mode 100644 widget/src/qt/nsTextWidget.cpp delete mode 100644 widget/src/qt/nsTextWidget.h delete mode 100644 widget/src/qt/nsToolkit.cpp delete mode 100644 widget/src/qt/nsToolkit.h delete mode 100644 widget/src/qt/nsWidget.cpp delete mode 100644 widget/src/qt/nsWidget.h delete mode 100644 widget/src/qt/nsWidgetFactory.cpp delete mode 100644 widget/src/qt/nsWindow.cpp delete mode 100644 widget/src/qt/nsWindow.h diff --git a/allmakefiles.sh b/allmakefiles.sh index 10be34e5ee55..3cc29c5d7ee4 100755 --- a/allmakefiles.sh +++ b/allmakefiles.sh @@ -140,7 +140,6 @@ gfx/src/gtk/Makefile gfx/src/ps/Makefile gfx/src/photon/Makefile gfx/src/mac/Makefile -gfx/src/qt/Makefile gfx/src/xlib/Makefile gfx/src/os2/Makefile gfx/src/xlibrgb/Makefile @@ -522,7 +521,6 @@ webshell/tests/viewer/Makefile webshell/tests/viewer/public/Makefile webshell/tests/viewer/unix/Makefile webshell/tests/viewer/unix/gtk/Makefile -webshell/tests/viewer/unix/qt/Makefile webshell/tests/viewer/unix/xlib/Makefile " @@ -542,7 +540,6 @@ widget/src/cocoa/Makefile widget/src/xlib/Makefile widget/src/os2/Makefile widget/src/os2/tests/Makefile -widget/src/qt/Makefile widget/src/windows/Makefile widget/src/windows/expose/Makefile widget/src/windows/expose/ISimpleDOMNode/Makefile diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 34c8e5803a52..9bc692a279e0 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -326,7 +326,6 @@ MOZ_TOOLKIT_REGISTRY_CFLAGS = \ MOZ_ENABLE_GTK = @MOZ_ENABLE_GTK@ MOZ_ENABLE_GTK2 = @MOZ_ENABLE_GTK2@ MOZ_ENABLE_XLIB = @MOZ_ENABLE_XLIB@ -MOZ_ENABLE_QT = @MOZ_ENABLE_QT@ MOZ_ENABLE_PHOTON = @MOZ_ENABLE_PHOTON@ MOZ_ENABLE_COCOA = @MOZ_ENABLE_COCOA@ MOZ_ENABLE_XREMOTE = @MOZ_ENABLE_XREMOTE@ @@ -340,9 +339,6 @@ MOZ_GTK2_LIBS = @MOZ_GTK2_LIBS@ MOZ_XLIB_CFLAGS = @MOZ_XLIB_CFLAGS@ MOZ_XLIB_LDFLAGS = @MOZ_XLIB_LDFLAGS@ -MOZ_QT_CFLAGS = @MOZ_QT_CFLAGS@ -MOZ_QT_LDFLAGS = @MOZ_QT_LDFLAGS@ - MOZ_XPRINT_CFLAGS = @MOZ_XPRINT_CFLAGS@ MOZ_XPRINT_LDFLAGS = @MOZ_XPRINT_LDFLAGS@ MOZ_ENABLE_XPRINT = @MOZ_ENABLE_XPRINT@ diff --git a/configure.in b/configure.in index 3b722fac73ba..1c4f03947946 100644 --- a/configure.in +++ b/configure.in @@ -87,8 +87,6 @@ GLIB_VERSION=1.2.0 GTK_VERSION=1.2.0 LIBIDL_VERSION=0.6.3 PERL_VERSION=5.004 -QT_VERSION=2.2.0 -QT_VERSION_NUM=220 LIBART_VERSION=2.3.4 GTK2_VERSION=1.3.7 @@ -676,11 +674,6 @@ if test "$GNU_CXX"; then # Turn on GNU specific features _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wall -Wconversion -Wpointer-arith -Wcast-align -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy" - dnl The following warning breaks Qt - if test ! "$QTDIR"; then - _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS}" - fi - _DEFINES_CXXFLAGS='-DMOZILLA_CLIENT -include $(DEPTH)/mozilla-config.h' _USE_CPP_INCLUDE_FLAG=1 else @@ -2972,7 +2965,6 @@ MOZ_ARG_HEADER(Toolkit Options) [ _DEFAULT_TOOLKIT=$_PLATFORM_DEFAULT_TOOLKIT]) if test "$_DEFAULT_TOOLKIT" = "gtk" \ - -o "$_DEFAULT_TOOLKIT" = "qt" \ -o "$_DEFAULT_TOOLKIT" = "gtk2" \ -o "$_DEFAULT_TOOLKIT" = "xlib" \ -o "$_DEFAULT_TOOLKIT" = "os2" \ @@ -2987,7 +2979,7 @@ MOZ_ARG_HEADER(Toolkit Options) MOZ_WIDGET_TOOLKIT=`echo "$_DEFAULT_TOOLKIT" | sed -e "s/,.*$//"` else if test "$no_x" != "yes"; then - AC_MSG_ERROR([Toolkit must be xlib, gtk, gtk2 or qt.]) + AC_MSG_ERROR([Toolkit must be xlib, gtk or gtk2.]) else AC_MSG_ERROR([Toolkit must be $_PLATFORM_DEFAULT_TOOLKIT.]) fi @@ -3011,14 +3003,6 @@ if test "$no_x" != "yes"; then MOZ_ENABLE_XLIB=1, MOZ_ENABLE_XLIB= ) - dnl ======================================================== - dnl = Qt support hackery = - dnl ======================================================== - MOZ_ARG_ENABLE_BOOL(toolkit-qt, - [ --enable-toolkit-qt Enable Qt Toolkit support ], - MOZ_ENABLE_QT=1, - MOZ_ENABLE_QT= ) - fi # !no_x AC_DEFINE_UNQUOTED(MOZ_DEFAULT_TOOLKIT,"$MOZ_WIDGET_TOOLKIT") @@ -3052,14 +3036,6 @@ xlib) AC_DEFINE(MOZ_WIDGET_XLIB) ;; -qt) - MOZ_ENABLE_QT=1 - MOZ_ENABLE_XREMOTE=1 - TK_CFLAGS='$(MOZ_QT_CFLAGS)' - TK_LIBS='$(MOZ_QT_LDFLAGS)' - AC_DEFINE(MOZ_WIDGET_QT) - ;; - photon) MOZ_ENABLE_PHOTON=1 AC_DEFINE(MOZ_WIDGET_PHOTON) @@ -3117,77 +3093,6 @@ then MOZ_XLIB_LDFLAGS="$MOZ_XLIB_LDFLAGS $XEXT_LIBS $X11_LIBS" fi -if test "$MOZ_ENABLE_QT" -then - MOZ_ARG_WITH_STRING(qtdir, - [ --with-qtdir=\$dir Specify Qt directory ], - [ QTDIR=$withval]) - - if test -z "$QTDIR"; then - QTDIR="/usr" - fi - QTINCDIR="/include/qt" - if test ! -d "$QTDIR$QTINCDIR"; then - QTINCDIR="/include/X11/qt" - fi - if test ! -d "$QTDIR$QTINCDIR"; then - QTINCDIR="/include" - fi - - if test -x "$QTDIR/bin/moc"; then - HOST_MOC="$QTDIR/bin/moc" - else - AC_CHECK_PROGS(HOST_MOC, moc, "") - fi - if test -z "$HOST_MOC"; then - AC_MSG_ERROR([no acceptable moc preprocessor found]) - fi - MOC=$HOST_MOC - - QT_CFLAGS="-I${QTDIR}${QTINCDIR} -DQT_GENUINE_STR -DQT_NO_STL" - if test -z "$MOZ_DEBUG"; then - QT_CFLAGS="$QT_CFLAGS -DQT_NO_DEBUG -DNO_DEBUG" - fi - _SAVE_LDFLAGS=$LDFLAGS - QT_LDFLAGS=-L${QTDIR}/lib - LDFLAGS="$LDFLAGS $QT_LDFLAGS" - AC_LANG_SAVE - AC_LANG_CPLUSPLUS - AC_CHECK_LIB(qt, main, QT_LIB=-lqt, - AC_CHECK_LIB(qt-mt, main, QT_LIB=-lqt-mt, - AC_MSG_ERROR([Cannot find QT libraries.]))) - LDFLAGS=$_SAVE_LDFLAGS - QT_LIBS="-L/usr/X11R6/lib $QT_LDFLAGS $QT_LIB -lXext -lX11" -dnl AM_PATH_QT($QT_VERSION,, -dnl AC_MSG_ERROR(Test for QT failed.)) - - MOZ_QT_LDFLAGS=$QT_LIBS - MOZ_QT_CFLAGS=$QT_CFLAGS - - _SAVE_CXXFLAGS=$CXXFLAGS - _SAVE_LIBS=$LIBS - - CXXFLAGS="$CXXFLAGS $QT_CFLAGS" - LIBS="$LIBS $QT_LIBS" - - AC_MSG_CHECKING(Qt - version >= $QT_VERSION) - AC_TRY_COMPILE([#include ], - [ - #if (QT_VERSION < $QT_VERSION_NUM) - #error "QT_VERSION too old" - #endif - ],result="yes",result="no") - - AC_MSG_RESULT("$result") - if test "$result" = "no"; then - AC_MSG_ERROR([Qt Mozilla requires at least version $QT_VERSION of Qt]) - fi - CXXFLAGS=$_SAVE_CXXFLAGS - LIBS=$_SAVE_LIBS - - AC_LANG_RESTORE -fi - AC_SUBST(MOZ_DEFAULT_TOOLKIT) AC_SUBST(GTK_CONFIG) @@ -3197,7 +3102,6 @@ AC_SUBST(TK_LIBS) AC_SUBST(MOZ_ENABLE_GTK) AC_SUBST(MOZ_ENABLE_XLIB) AC_SUBST(MOZ_ENABLE_GTK2) -AC_SUBST(MOZ_ENABLE_QT) AC_SUBST(MOZ_ENABLE_PHOTON) AC_SUBST(MOZ_ENABLE_COCOA) AC_SUBST(MOZ_ENABLE_XREMOTE) @@ -3207,12 +3111,10 @@ AC_SUBST(MOZ_GTK2_CFLAGS) AC_SUBST(MOZ_GTK2_LIBS) AC_SUBST(MOZ_XLIB_CFLAGS) AC_SUBST(MOZ_XLIB_LDFLAGS) -AC_SUBST(MOZ_QT_CFLAGS) -AC_SUBST(MOZ_QT_LDFLAGS) AC_SUBST(MOC) -if test "$MOZ_ENABLE_GTK" || test "$MOZ_ENABLE_QT" \ +if test "$MOZ_ENABLE_GTK" \ || test "$MOZ_ENABLE_XLIB" \ || test "$MOZ_ENABLE_GTK2" then diff --git a/gfx/src/Makefile.in b/gfx/src/Makefile.in index a39edaeb1573..24de4a1a1bd7 100644 --- a/gfx/src/Makefile.in +++ b/gfx/src/Makefile.in @@ -71,9 +71,6 @@ endif ifdef MOZ_ENABLE_GTK2 DIRS += gtk endif -ifdef MOZ_ENABLE_QT -DIRS += qt -endif ifdef MOZ_ENABLE_XLIB DIRS += xlib endif diff --git a/gfx/src/qt/.cvsignore b/gfx/src/qt/.cvsignore deleted file mode 100644 index f3c7a7c5da68..000000000000 --- a/gfx/src/qt/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/gfx/src/qt/Makefile.in b/gfx/src/qt/Makefile.in deleted file mode 100644 index ed17b4844627..000000000000 --- a/gfx/src/qt/Makefile.in +++ /dev/null @@ -1,113 +0,0 @@ -# -# The contents of this file are subject to the Netscape 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/NPL/ -# -# 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 Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): -# John C. Griggs -# - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = gfx -LIBRARY_NAME = gfx_qt -EXPORT_LIBRARY = 1 -GRE_MODULE = 1 - -REQUIRES = xpcom \ - string \ - widget \ - view \ - uconv \ - pref \ - util \ - js \ - mozcomps \ - unicharutil \ - intl \ - locale \ - $(NULL) -IS_COMPONENT = 1 -MODULE_NAME = nsGfxQTModule - -CPPSRCS = \ - nsDeviceContextQT.cpp \ - nsDeviceContextSpecFactoryQT.cpp \ - nsDeviceContextSpecQT.cpp \ - nsDrawingSurfaceQT.cpp \ - nsFontMetricsQT.cpp \ - nsGfxFactoryQT.cpp \ - nsImageQT.cpp \ - nsRegionQT.cpp \ - nsRenderingContextQT.cpp \ - nsScreenManagerQT.cpp \ - nsScreenQT.cpp \ - $(NULL) - -# If not primary toolkit, install in secondary path -ifneq (qt,$(MOZ_GFX_TOOLKIT)) -INACTIVE_COMPONENT = 1 -endif - -include $(topsrcdir)/config/rules.mk - -CXXFLAGS += $(MOZ_QT_CFLAGS) -CFLAGS += $(MOZ_QT_CFLAGS) - -EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \ - $(MOZ_JS_LIBS) \ - -lgkgfx \ - -lgfxshared_s \ - $(XPCOM_LIBS) \ - $(XPCOM_GLUE_LIBS) \ - $(MOZ_QT_LDFLAGS) \ - $(NSPR_LIBS) \ - $(NULL) - -ifeq ($(OS_ARCH), Linux) -DEFINES += -D_BSD_SOURCE -endif -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 - -ifdef MOZ_ENABLE_POSTSCRIPT -DEFINES += -DUSE_POSTSCRIPT -endif - -ifdef MOZ_ENABLE_XPRINT -DEFINES += -DUSE_XPRINT -DUSE_MOZILLA_TYPES -EXTRA_DSO_LDOPTS += $(MOZ_XPRINT_LDFLAGS) -endif - -LOCAL_INCLUDES = \ - -I$(srcdir)/. \ - -I$(srcdir)/.. \ - -I$(srcdir)/../shared \ - $(NULL) - diff --git a/gfx/src/qt/nsDeviceContextQT.cpp b/gfx/src/qt/nsDeviceContextQT.cpp deleted file mode 100644 index d5ca9402cf55..000000000000 --- a/gfx/src/qt/nsDeviceContextQT.cpp +++ /dev/null @@ -1,560 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Esben Mose Hansen - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include - -#include "nspr.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" -#include "nsIPrefService.h" -#include "nsIServiceManager.h" -#include "nsCRT.h" -#include "nsDeviceContextQT.h" -#include "nsFontMetricsQT.h" -#include "nsFont.h" -#include "nsGfxCIID.h" -#include "nsRenderingContextQT.h" -#include "nsDeviceContextSpecQT.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 */ - -#include -#include -#include -#include -#include - -#include "nsIScreenManager.h" - -#include "qtlog.h" - -#define QCOLOR_TO_NS_RGB(c) \ - ((nscolor)NS_RGB(c.red(),c.green(),c.blue())) - -nscoord nsDeviceContextQT::mDpi = 96; - -#define dmsg(level, item) traceMessage(level, item); - -enum Trace_level { ENTER, EXIT }; - -void traceMessage(Trace_level level, const char* const item) { - char logBuf[1024] = ""; // let's trust that these messages won't get longer than this - static int indent = 0; - if (EXIT == level && indent>0) --indent; - for (int i=0; i pbi = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (pbi) { - pbi->RemoveObserver("browser.display.screen_resolution", this); - } - dmsg(EXIT, "~nsDeviceContextQT"); -} - -NS_IMETHODIMP nsDeviceContextQT::Init(nsNativeWidget aNativeWidget) -{ - dmsg(ENTER, "Init"); - PRBool bCleanUp = PR_FALSE; - QWidget *pWidget = nsnull; - - mWidget = (QWidget*)aNativeWidget; - - if (mWidget != nsnull) - pWidget = mWidget; - else { - pWidget = new QWidget(); - bCleanUp = PR_TRUE; - } - QPaintDeviceMetrics qPaintMetrics(pWidget); - - nsresult ignore; - nsCOMPtr sm(do_GetService("@mozilla.org/gfx/screenmanager;1", - &ignore)); - if (sm) { - nsCOMPtr screen; - sm->GetPrimaryScreen(getter_AddRefs(screen)); - if (screen) { - PRInt32 x,y,width,height,depth; - - screen->GetAvailRect(&x,&y,&width,&height); - screen->GetPixelDepth(&depth); - mWidthFloat = float(width); - mHeightFloat = float(height); - mDepth = NS_STATIC_CAST(PRUint32,depth); - } - } - static int initialized = 0; - - if (!initialized) { - initialized = 1; - - // Set prefVal the value of the preference "browser.display.screen_resolution" - // or -1 if we can't get it. - // If it's negative, we pretend it's not set. - // If it's 0, it means force use of the operating system's logical resolution. - // If it's positive, we use it as the logical resolution - PRInt32 prefVal = -1; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - nsresult res = prefBranch->GetIntPref("browser.display.screen_resolution", - &prefVal); - if (NS_FAILED(res)) { - prefVal = -1; - } - nsCOMPtr pbi(do_QueryInterface(prefBranch)); - pbi->AddObserver("browser.display.screen_resolution", this, PR_FALSE); - } - - // Set OSVal to what the operating system thinks the logical resolution is. - PRInt32 OSVal = qPaintMetrics.logicalDpiX(); - - if (prefVal > 0) { - // If there's a valid pref value for the logical resolution, - // use it. - mDpi = prefVal; - } - else if (prefVal == 0 || OSVal > 96) { - // Either if the pref is 0 (force use of OS value) or the OS - // value is bigger than 96, use the OS value. - mDpi = OSVal; - } - else { - // if we couldn't get the pref or it's negative, and the OS - // value is under 96ppi, then use 96. - mDpi = 96; - } - } - SetDPI(mDpi); - -#ifdef MOZ_LOGGING - static PRBool once = PR_TRUE; - if (once) { - PR_LOG(gQTLogModule, QT_BASIC, ("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n", - mDpi,mTwipsToPixels,mPixelsToTwips,mDepth)); - once = PR_FALSE; - } -#endif - - QScrollBar * sb = new QScrollBar(nsnull,nsnull); - if (sb) { - sb->setOrientation(QScrollBar::Vertical); - QSize size = sb->sizeHint(); - - mScrollbarWidth = size.width(); - - sb->setOrientation(QScrollBar::Horizontal); - size = sb->sizeHint(); - - mScrollbarHeight = size.height(); - } - QRect rect = pWidget->frameGeometry(); - - mWindowBorderWidth = rect.width(); - mWindowBorderHeight = rect.height(); - - DeviceContextImpl::CommonInit(); - - delete sb; - - if (bCleanUp) - delete pWidget; - return NS_OK; - dmsg(EXIT, "Init"); -} - -NS_IMETHODIMP -nsDeviceContextQT::CreateRenderingContext(nsIRenderingContext *&aContext) -{ - dmsg(ENTER, "CreateRenderingContext"); - nsIRenderingContext *pContext; - nsresult rv; - nsDrawingSurfaceQT *surf; - QPaintDevice *pDev = nsnull; - - if (mWidget) - pDev = (QPaintDevice*)mWidget; - - // to call init for this, we need to have a valid nsDrawingSurfaceQT created - pContext = new nsRenderingContextQT(); - - if (nsnull != pContext) { - NS_ADDREF(pContext); - - // create the nsDrawingSurfaceQT - surf = new nsDrawingSurfaceQT(); - - if (surf) { - QPainter *gc = new QPainter(); - - // init the nsDrawingSurfaceQT - if (pDev) - rv = surf->Init(pDev,gc); - else - rv = surf->Init(gc,10,10,0); - - if (NS_OK == rv) - // Init the nsRenderingContextQT - rv = pContext->Init(this,surf); - } - else - rv = NS_ERROR_OUT_OF_MEMORY; - } - else - rv = NS_ERROR_OUT_OF_MEMORY; - - if (NS_OK != rv) { - NS_IF_RELEASE(pContext); - } - aContext = pContext; - dmsg(EXIT, "CreateRenderingContext"); - return rv; -} - -NS_IMETHODIMP -nsDeviceContextQT::SupportsNativeWidgets(PRBool &aSupportsWidgets) -{ - dmsg(ENTER, "SupportsNativeWidgets"); - //XXX it is very critical that this not lie!! MMP - // read the comments in the mac code for this - aSupportsWidgets = PR_TRUE; - - dmsg(EXIT, "SupportsNativeWidgets"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::GetScrollBarDimensions(float &aWidth, - float &aHeight) const -{ - dmsg(ENTER, "GetScrollBarDimensions"); - float scale; - GetCanonicalPixelScale(scale); - aWidth = mScrollbarWidth * mPixelsToTwips * scale; - aHeight = mScrollbarHeight * mPixelsToTwips * scale; - dmsg(EXIT, "GetScrollBarDimensions"); - return NS_OK; -} - -NS_IMETHODIMP -nsDeviceContextQT::GetSystemFont(nsSystemFontID anID, nsFont *aFont) const -{ - dmsg(ENTER, "GetSystemFont"); - nsresult status = NS_OK; - - switch (anID) { - case eSystemFont_Caption: - 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: - case eSystemFont_Widget: - status = GetSystemFontInfo(aFont); - break; - } - dmsg(EXIT, "GetSystemFont"); - return status; -} - -NS_IMETHODIMP nsDeviceContextQT::ConvertPixel(nscolor aColor, - PRUint32 &aPixel) -{ - dmsg(ENTER, "ConvertPixel"); - QColor color(NS_GET_R(aColor),NS_GET_G(aColor),NS_GET_B(aColor)); - - aPixel = color.pixel(); - - dmsg(ENTER, "ConvertPixel"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::CheckFontExistence(const nsString& aFontName) -{ - dmsg(ENTER, "CheckFontExistence"); - dmsg(EXIT, "CheckFontExistence"); - return nsFontMetricsQT::FamilyExists(aFontName); -} - -NS_IMETHODIMP nsDeviceContextQT::GetDeviceSurfaceDimensions(PRInt32 &aWidth, - PRInt32 &aHeight) -{ - dmsg(ENTER, "GetDeviceSurfaceDimensions"); - if (-1 == mWidth) - mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits); - - if (-1 == mHeight) - mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits); - - aWidth = mWidth; - aHeight = mHeight; - dmsg(EXIT, "GetDeviceSurfaceDimensions"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::GetRect(nsRect &aRect) -{ - dmsg(ENTER, "GetRect"); - PRInt32 width,height; - nsresult rv; - - rv = GetDeviceSurfaceDimensions(width,height); - aRect.x = 0; - aRect.y = 0; - aRect.width = width; - aRect.height = height; - dmsg(EXIT, "GetRect"); - return rv; -} - -NS_IMETHODIMP nsDeviceContextQT::GetClientRect(nsRect &aRect) -{ - dmsg(ENTER, "GetClientRect"); - dmsg(EXIT, "GetClientRect"); - return GetRect(aRect); -} - -NS_IMETHODIMP nsDeviceContextQT::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, - nsIDeviceContext *&aContext) -{ - nsresult rv; - PrintMethod method; - nsDeviceContextSpecQT *spec = NS_STATIC_CAST(nsDeviceContextSpecQT *, 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 rv; - - 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 rv; - - 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 nsDeviceContextQT::BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage) -{ - dmsg(ENTER, "BeginDocument"); - dmsg(EXIT, "BeginDocument"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::EndDocument(void) -{ - dmsg(ENTER, "EndDocument"); - dmsg(EXIT, "EndDocument"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::BeginPage(void) -{ - dmsg(ENTER, "BeginPage"); - dmsg(EXIT, "BeginPage"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::EndPage(void) -{ - dmsg(ENTER, "EndPage"); - dmsg(EXIT, "EndPage"); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextQT::GetDepth(PRUint32& aDepth) -{ - dmsg(ENTER, "GetDepth"); - aDepth = mDepth; - dmsg(EXIT, "GetDepth"); - return NS_OK; -} - -nsresult nsDeviceContextQT::SetDPI(PRInt32 aDpi) -{ - dmsg(ENTER, "SetDPI"); - mDpi = aDpi; - - int pt2t = 72; - - // make p2t a nice round number - this prevents rounding problems - mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(aDpi))); - mTwipsToPixels = 1.0f / mPixelsToTwips; - - // XXX need to reflow all documents - dmsg(EXIT, "SetDPI"); - return NS_OK; -} - -NS_IMETHODIMP -nsDeviceContextQT::Observe(nsISupports* aSubject, const char* aTopic, - const PRUnichar* aData) -{ - dmsg(ENTER, "observe"); - if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) != 0) { - // Our local observer only handles pref changes. - // Forward everything else to our super class. - dmsg(EXIT, "observe"); - return DeviceContextImpl::Observe(aSubject, aTopic, aData); - } - nsCOMPtr prefBranch(do_QueryInterface(aSubject)); - NS_ASSERTION(prefBranch, - "All pref change observer subjects implement nsIPrefBranch"); - nsCAutoString prefName(NS_LossyConvertUCS2toASCII(aData).get()); - if (prefName.Equals(NS_LITERAL_CSTRING("browser.display.screen_resolution"))) { - PRInt32 dpi; - nsresult rv = prefBranch->GetIntPref(prefName.get(), &dpi); - if (NS_SUCCEEDED(rv)) - SetDPI(dpi); - } - dmsg(EXIT, "observe"); - return NS_OK; -} - -nsresult -nsDeviceContextQT::GetSystemFontInfo(nsFont* aFont) const -{ - dmsg(ENTER, "GetSystemFontInfo"); - nsresult status = NS_OK; - int rawWeight; - QFont theFont = QApplication::font(); - QFontInfo theFontInfo(theFont); - - aFont->style = NS_FONT_STYLE_NORMAL; - aFont->weight = NS_FONT_WEIGHT_NORMAL; - aFont->decorations = NS_FONT_DECORATION_NONE; - aFont->name.AssignWithConversion(theFontInfo.family().latin1()); - if (theFontInfo.bold()) { - aFont->weight = NS_FONT_WEIGHT_BOLD; - } - rawWeight = theFontInfo.pointSize(); - aFont->size = NSIntPixelsToTwips(rawWeight,mPixelsToTwips); - if (theFontInfo.italic()) { - aFont->style = NS_FONT_STYLE_ITALIC; - } - if (theFontInfo.underline()) { - aFont->decorations = NS_FONT_DECORATION_UNDERLINE; - } - dmsg(EXIT, "GetSystemFontInfo"); - return (status); -} diff --git a/gfx/src/qt/nsDeviceContextQT.h b/gfx/src/qt/nsDeviceContextQT.h deleted file mode 100644 index c0116907a319..000000000000 --- a/gfx/src/qt/nsDeviceContextQT.h +++ /dev/null @@ -1,119 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsDeviceContextQT_h___ -#define nsDeviceContextQT_h___ - -#include "nsDeviceContext.h" -#include "nsUnitConversion.h" -#include "nsIWidget.h" -#include "nsIView.h" -#include "nsIRenderingContext.h" - -class QWidget; - -class nsDeviceContextQT : public DeviceContextImpl -{ -public: - nsDeviceContextQT(); - virtual ~nsDeviceContextQT(); - - 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 SupportsNativeWidgets(PRBool &aSupportsWidgets); - - NS_IMETHOD GetScrollBarDimensions(float &aWidth,float &aHeight) const; - NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const; - - NS_IMETHOD ConvertPixel(nscolor aColor,PRUint32 &aPixel); - NS_IMETHOD CheckFontExistence(const nsString &aFontName); - - NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth,PRInt32 &aHeight); - NS_IMETHOD GetClientRect(nsRect &aRect); - NS_IMETHOD GetRect(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 BeginPage(void); - NS_IMETHOD EndPage(void); - - // Overridden DeviceContextImpl functions. - NS_IMETHOD GetDepth(PRUint32 &aDepth); - - // Preferences observer - NS_DECL_NSIOBSERVER - - nsresult SetDPI(PRInt32 dpi); - -private: - PRUint32 mDepth; - PRBool mWriteable; - PRUint32 mNumCells; - PRInt16 mScrollbarHeight; - PRInt16 mScrollbarWidth; - PRInt16 mWindowBorderWidth; - PRInt16 mWindowBorderHeight; - QWidget *mWidget; - PRInt32 mWidth; - PRInt32 mHeight; - float mWidthFloat; - float mHeightFloat; - - static nscoord mDpi; - - nsresult GetSystemFontInfo(nsFont *aFont) const; - - PRUint32 mID; -}; - -#endif /* nsDeviceContextQT_h___ */ - diff --git a/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp b/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp deleted file mode 100644 index d7021f3c4505..000000000000 --- a/gfx/src/qt/nsDeviceContextSpecFactoryQT.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDeviceContextSpecFactoryQT.h" -#include "nsDeviceContextSpecQT.h" -#include "nsGfxCIID.h" -#include "plstr.h" - -NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryQT, nsIDeviceContextSpecFactory) - -nsDeviceContextSpecFactoryQT::nsDeviceContextSpecFactoryQT() -{ -} - -nsDeviceContextSpecFactoryQT::~nsDeviceContextSpecFactoryQT() -{ -} - -NS_IMETHODIMP nsDeviceContextSpecFactoryQT::Init(void) -{ - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecFactoryQT::CreateDeviceContextSpec(nsIWidget *aWidget, - nsIPrintSettings* aPrintSettings, - nsIDeviceContextSpec *&aNewSpec, - PRBool aIsPrintPreview) -{ - nsresult rv; - static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID); - nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); - if (NS_SUCCEEDED(rv)) - { - rv = ((nsDeviceContextSpecQT *)devSpec.get())->Init(aPrintSettings); - if (NS_SUCCEEDED(rv)) - { - aNewSpec = devSpec; - NS_ADDREF(aNewSpec); - } - } - - return rv; -} - diff --git a/gfx/src/qt/nsDeviceContextSpecFactoryQT.h b/gfx/src/qt/nsDeviceContextSpecFactoryQT.h deleted file mode 100644 index d487eeee8d7f..000000000000 --- a/gfx/src/qt/nsDeviceContextSpecFactoryQT.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDeviceContextSpecFactoryQT_h___ -#define nsDeviceContextSpecFactoryQT_h___ - -#include "nsIDeviceContextSpecFactory.h" -#include "nsIDeviceContextSpec.h" - -class nsDeviceContextSpecFactoryQT : public nsIDeviceContextSpecFactory -{ - -public: - nsDeviceContextSpecFactoryQT(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(void); - NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, - nsIPrintSettings* aPrintSettings, - nsIDeviceContextSpec *&aNewSpec, - PRBool aIsPrintPreview); - -protected: - virtual ~nsDeviceContextSpecFactoryQT(); -}; - -#endif /* !nsDeviceContextSpecFactoryQT_h___ */ diff --git a/gfx/src/qt/nsDeviceContextSpecQT.cpp b/gfx/src/qt/nsDeviceContextSpecQT.cpp deleted file mode 100644 index ef9334602be8..000000000000 --- a/gfx/src/qt/nsDeviceContextSpecQT.cpp +++ /dev/null @@ -1,1053 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, 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" - -#define FORCE_PR_LOG /* Allow logging in the release build */ -#define PR_LOGGING 1 -#include "prlog.h" - -#include "nsDeviceContextSpecQT.h" - -#include "nsIPref.h" -#include "prenv.h" /* for PR_GetEnv */ - -#include "nsPrintfCString.h" -#include "nsReadableUtils.h" -#include "nsIServiceManager.h" -#include "nsCRT.h" - -#ifdef USE_XPRINT -#include "xprintutil.h" -#endif /* USE_XPRINT */ - -#ifdef USE_POSTSCRIPT -/* Fetch |postscript_module_paper_sizes| */ -#include "nsPostScriptObj.h" -#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 *DeviceContextSpecQTLM = PR_NewLogModule("DeviceContextSpecQT"); -#endif /* PR_LOGGING */ -/* Macro to make lines shorter */ -#define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecQTLM, PR_LOG_DEBUG, x) - -//---------------------------------------------------------------------------------- -// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecQT -// The PrinterEnumerator creates the printer info -// but the nsDeviceContextSpecQT 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 mGlobalNumPrinters; } - nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); } - void GetDefaultPrinterName(PRUnichar **aDefaultPrinterName); - -protected: - GlobalPrinters() {} - - static GlobalPrinters mGlobalPrinters; - static nsStringArray* mGlobalPrinterList; - static int mGlobalNumPrinters; -}; - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS -/* "Prototype" for the new nsPrinterFeatures service */ -class nsPrinterFeatures { -public: - nsPrinterFeatures( const char *printername ); - ~nsPrinterFeatures() {}; - - /* Does this device allow to set/change the paper size ? */ - void SetCanChangePaperSize( PRBool aCanSetPaperSize ); - /* 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 device allow to set/change the content orientation ? */ - void SetCanChangeOrientation( PRBool aCanSetOrientation ); - /* Set number of orientation records and the records itself */ - void SetNumOrientationRecords( PRInt32 aCount ); - void SetOrientationRecord( PRInt32 aIndex, const char *aName ); - - /* Does this device allow to set/change the spooler command ? */ - void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand ); - - /* 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 ); - - nsXPIDLCString 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_PREF_CONTRACTID); - - SetBoolValue("has_special_printerfeatures", PR_TRUE); -} - -void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize ) -{ - SetBoolValue("can_change_paper_size", aCanSetPaperSize); -} - -/* 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::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::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand ) -{ - SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand); -} - -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; -int GlobalPrinters::mGlobalNumPrinters = 0; -//--------------- - -nsDeviceContextSpecQT::nsDeviceContextSpecQT() -{ - DO_PR_DEBUG_LOG(("nsDeviceContextSpecQT::nsDeviceContextSpecQT()\n")); -} - -nsDeviceContextSpecQT::~nsDeviceContextSpecQT() -{ - DO_PR_DEBUG_LOG(("nsDeviceContextSpecQT::~nsDeviceContextSpecQT()\n")); -} - -/* Use both PostScript and Xprint module */ -#if defined(USE_XPRINT) && defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS3(nsDeviceContextSpecQT, - nsIDeviceContextSpec, - nsIDeviceContextSpecPS, - nsIDeviceContextSpecXp) -/* Use only PostScript module */ -#elif !defined(USE_XPRINT) && defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS2(nsDeviceContextSpecQT, - nsIDeviceContextSpec, - nsIDeviceContextSpecPS) -/* Use only Xprint module module */ -#elif defined(USE_XPRINT) && !defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS2(nsDeviceContextSpecQT, - nsIDeviceContextSpec, - nsIDeviceContextSpecXp) -/* Both Xprint and PostScript module are missing */ -#elif !defined(USE_XPRINT) && !defined(USE_POSTSCRIPT) -NS_IMPL_ISUPPORTS1(nsDeviceContextSpecQT, - nsIDeviceContextSpec) -#else -#error "This should not happen" -#endif - -/** ------------------------------------------------------- - * Initialize the nsDeviceContextSpecQT - * @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 nsDeviceContextSpecGTK::Init() - * - Xlib-toolkit: - * file: mozilla/gfx/src/xlib/nsDeviceContextSpecQT.cpp - * function: NS_IMETHODIMP nsDeviceContextSpecQT::Init() - * - Qt-toolkit: - * file: mozilla/gfx/src/qt/nsDeviceContextSpecQT.cpp - * function: NS_IMETHODIMP nsDeviceContextSpecQT::Init() - * - * ** Please update the other toolkits when changing this function. - */ -NS_IMETHODIMP nsDeviceContextSpecQT::Init(nsIPrintSettings *aPS) -{ - DO_PR_DEBUG_LOG(("nsDeviceContextSpecQT::Init(aPS=%p\n", aPS)); - nsresult rv = NS_ERROR_FAILURE; - - mPrintSettings = aPS; - - // if there is a current selection then enable the "Selection" radio button - if (mPrintSettings) { - PRBool isOn; - mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); - } - } - - 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 *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->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) - strcpy(mPath, NS_ConvertUCS2toUTF8(printfile).get()); - if (command) - strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get()); - if (printer) - strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get()); - if (papername) - strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get()); - - 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_ConvertUCS2toUTF8(printfile).get():"")); - DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"")); - DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"")); - DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"")); - - mTop = dtop; - mBottom = dbottom; - mLeft = dleft; - mRight = dright; - mFpf = !reversed; - mGrayscale = !color; - mOrientation = orientation; - mToPrinter = !tofile; - mCopies = copies; - } - - return rv; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetToPrinter(PRBool &aToPrinter) -{ - aToPrinter = mToPrinter; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetPrinterName ( const char **aPrinter ) -{ - *aPrinter = mPrinter; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetCopies ( int &aCopies ) -{ - aCopies = mCopies; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetFirstPageFirst(PRBool &aFpf) -{ - aFpf = mFpf; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetGrayscale(PRBool &aGrayscale) -{ - aGrayscale = mGrayscale; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetLandscape(PRBool &aLandscape) -{ - aLandscape = (mOrientation == NS_LANDSCAPE); - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetTopMargin(float &aValue) -{ - aValue = mTop; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetBottomMargin(float &aValue) -{ - aValue = mBottom; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetRightMargin(float &aValue) -{ - aValue = mRight; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetLeftMargin(float &aValue) -{ - aValue = mLeft; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetCommand(const char **aCommand) -{ - *aCommand = mCommand; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetPath(const char **aPath) -{ - *aPath = mPath; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetUserCancelled(PRBool &aCancel) -{ - aCancel = mCancel; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetPaperName( const char **aPaperName ) -{ - *aPaperName = mPaperName; - return NS_OK; -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) -{ - return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); -} - -NS_IMETHODIMP nsDeviceContextSpecQT::GetPrintMethod(PrintMethod &aMethod) -{ - return GetPrintMethod(mPrinter, aMethod); -} - -/* static !! */ -nsresult nsDeviceContextSpecQT::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod) -{ -#if defined(USE_POSTSCRIPT) && defined(USE_XPRINT) - /* printer names for the PostScript module alwas start with - * the NS_POSTSCRIPT_DRIVER_NAME string */ - if (strncmp(aPrinter, NS_POSTSCRIPT_DRIVER_NAME, - NS_POSTSCRIPT_DRIVER_NAME_LEN) != 0) - 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 nsDeviceContextSpecQT::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)); - - NS_ENSURE_ARG_POINTER(return_buf); - - nsXPIDLCString name; - nsresult rv = NS_ERROR_FAILURE; - - if (printername && modulename) { - /* Get prefs per printer name and module name */ - name = nsPrintfCString(512, "print.%s.printer_%s.%s", modulename, printername, prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, 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->CopyCharPref(name, return_buf); - } - - if (NS_FAILED(rv)) { - if (modulename) { - /* Get prefs per module name */ - name = nsPrintfCString(512, "print.%s.%s", modulename, prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, return_buf); - } - - if (NS_FAILED(rv)) { - /* Get prefs */ - name = nsPrintfCString(512, "print.%s", prefname); - DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); - rv = pref->CopyCharPref(name, return_buf); - } - } - } - -#ifdef PR_LOG - if (NS_SUCCEEDED(rv)) { - DO_PR_DEBUG_LOG(("CopyPrinterCharPref returning '%s'.\n", *return_buf)); - } - else - { - DO_PR_DEBUG_LOG(("CopyPrinterCharPref failure.\n")); - } -#endif /* PR_LOG */ - - return rv; -} - -// Printer Enumerator -nsPrinterEnumeratorQT::nsPrinterEnumeratorQT() -{ -} - -NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorQT, nsIPrinterEnumerator) - -NS_IMETHODIMP nsPrinterEnumeratorQT::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 nsPrinterEnumeratorQT::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName) -{ - DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQT::GetDefaultPrinterName()\n")); - NS_ENSURE_ARG_POINTER(aDefaultPrinterName); - - GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName); - - DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUCS2toUTF8(*aDefaultPrinterName).get())); - return NS_OK; -} - -/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */ -NS_IMETHODIMP nsPrinterEnumeratorQT::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings) -{ - DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQT::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_PREF_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_ConvertUCS2toUTF8(aPrinterName)); - printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName)); - DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get())); - - PrintMethod type = pmInvalid; - rv = nsDeviceContextSpecQT::GetPrintMethod(printerName, type); - if (NS_FAILED(rv)) - return rv; - -#ifdef USE_POSTSCRIPT - /* "Demangle" postscript printer name */ - if (type == pmPostScript) { - /* Strip the leading NS_POSTSCRIPT_DRIVER_NAME from |printerName|, - * e.g. turn "PostScript/foobar" to "foobar" */ - printerName.Cut(0, NS_POSTSCRIPT_DRIVER_NAME_LEN); - } -#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", getter_Copies(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.Assign("mozilla.ps"); - } - DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get())); - aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get()); - - aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE); -#ifdef USE_XPRINT - if (type == pmXprint) { - DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for Xprint printer\n")); - - 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); - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - nsPrinterFeatures printerFeatures(fullPrinterName); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - /* Setup orientation stuff */ - XpuOrientationList olist; - int ocount; - XpuOrientationRec *default_orientation; - -#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); - } - - /* 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) { - nsXPIDLCString 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 = nsPrintfCString(256, "%s/%s", default_medium->tray_name, default_medium->medium_name); - } - else { - papername.Assign(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_ConvertUTF8toUCS2(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; - if (curr->tray_name) { - papername = nsPrintfCString(256, "%s/%s", curr->tray_name, curr->medium_name); - } - else { - papername.Assign(curr->medium_name); - } - - printerFeatures.SetPaperRecord(i, papername, PRInt32(total_width), PRInt32(total_height), PR_FALSE); - } - printerFeatures.SetNumPaperSizeRecords(mcount); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - XpuFreeMediumSourceSizeList(mlist); - } - -#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); - - /* 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); -#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", getter_Copies(orientation)))) { - if (!PL_strcasecmp(orientation, "portrait")) { - DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n")); - aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); - } - else if (!PL_strcasecmp(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", orientation.get())); - } - } - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - int i; - for( i = 0 ; postscript_module_orientations[i].orientation != nsnull ; i++ ) - { - const PSOrientationRec *curr = &postscript_module_orientations[i]; - printerFeatures.SetOrientationRecord(i, curr->orientation); - } - printerFeatures.SetNumOrientationRecords(i); -#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", getter_Copies(papername)))) { - int i; - const PSPaperSizeRec *default_paper = nsnull; - - for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ ) - { - const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i]; - - if (!PL_strcasecmp(papername, curr->name)) { - default_paper = curr; - break; - } - } - - if (default_paper) { - DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g inch/%g inch)\n", - default_paper->name, - PSPaperSizeRec_FullPaperWidth(default_paper), - PSPaperSizeRec_FullPaperHeight(default_paper))); - aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined); - aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches); - aPrintSettings->SetPaperWidth(PSPaperSizeRec_FullPaperWidth(default_paper)); - aPrintSettings->SetPaperHeight(PSPaperSizeRec_FullPaperHeight(default_paper)); - aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(default_paper->name).get()); - } - else { - DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get())); - } -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ ) - { - const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i]; -#define CONVERT_INCH_TO_MILLIMETERS(inch) ((inch) * 25.4) - double total_width = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperWidth(curr)), - total_height = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperHeight(curr)); - - printerFeatures.SetPaperRecord(i, curr->name, PRInt32(total_width), PRInt32(total_height), PR_TRUE); - } - printerFeatures.SetNumPaperSizeRecords(i); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - } - -#ifdef SET_PRINTER_FEATURES_VIA_PREFS - printerFeatures.SetCanChangeSpoolerCommand(PR_TRUE); -#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ - - nsXPIDLCString command; - if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) { - DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get())); - aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(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 nsPrinterEnumeratorQT::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings) -{ - return NS_OK; -} - -//---------------------------------------------------------------------- -nsresult GlobalPrinters::InitializeGlobalPrinters () -{ - if (PrintersAreAllocated()) { - return NS_OK; - } - - mGlobalNumPrinters = 0; - mGlobalPrinterList = new nsStringArray(); - if (!mGlobalPrinterList) - return NS_ERROR_OUT_OF_MEMORY; - -#ifdef USE_XPRINT - XPPrinterList plist = XpuGetPrinterList(nsnull, &mGlobalNumPrinters); - - if (plist && (mGlobalNumPrinters > 0)) - { - int i; - for( i = 0 ; i < mGlobalNumPrinters ; i++ ) - { - mGlobalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name))); - } - - XpuFreePrinterList(plist); - } -#endif /* USE_XPRINT */ - -#ifdef USE_POSTSCRIPT - /* Get the list of PostScript-module printers */ - char *printerList = nsnull; - PRBool added_default_printer = PR_FALSE; /* Did we already add the default printer ? */ - - /* The env var MOZILLA_POSTSCRIPT_PRINTER_LIST can "override" the prefs */ - printerList = PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST"); - - if (!printerList) { - nsresult rv; - nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - (void) pPrefs->CopyCharPref("print.printer_list", &printerList); - } - } - - if (printerList) { - char *tok_lasts; - const char *name; - - /* PL_strtok_r() will modify the string - copy it! */ - printerList = strdup(printerList); - if (!printerList) - return NS_ERROR_OUT_OF_MEMORY; - - for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; - name != nsnull ; - name = PL_strtok_r(nsnull, " ", &tok_lasts) ) - { - /* Is this the "default" printer ? */ - if (!strcmp(name, "default")) - added_default_printer = PR_TRUE; - - mGlobalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + - nsString(NS_ConvertASCIItoUCS2(name))); - mGlobalNumPrinters++; - } - - free(printerList); - } - - /* Add an entry for the default printer (see nsPostScriptObj.cpp) if we - * did not add it already... */ - if (!added_default_printer) - { - mGlobalPrinterList->AppendString( - nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); - mGlobalNumPrinters++; - } -#endif /* USE_POSTSCRIPT */ - - if (mGlobalNumPrinters == 0) - return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; - - return NS_OK; -} - -//---------------------------------------------------------------------- -void GlobalPrinters::FreeGlobalPrinters() -{ - if (mGlobalPrinterList) { - delete mGlobalPrinterList; - mGlobalPrinterList = nsnull; - mGlobalNumPrinters = 0; - } -} - -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/gfx/src/qt/nsDeviceContextSpecQT.h b/gfx/src/qt/nsDeviceContextSpecQT.h deleted file mode 100644 index c219a9e90bc6..000000000000 --- a/gfx/src/qt/nsDeviceContextSpecQT.h +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDeviceContextSpecQT_h___ -#define nsDeviceContextSpecQT_h___ - -#include "nsCOMPtr.h" -#include "nsIDeviceContextSpec.h" -#include "nsIPrintSettings.h" -#include "nsIPrintOptions.h" -#include "nsVoidArray.h" -#include -#ifdef USE_POSTSCRIPT -#include "nsIDeviceContextSpecPS.h" -#endif /* USE_POSTSCRIPT */ -#ifdef USE_XPRINT -#include "nsIDeviceContextSpecXPrint.h" -#endif /* USE_XPRINT */ - -#define NS_PORTRAIT 0 -#define NS_LANDSCAPE 1 - -typedef enum -{ - pmInvalid = 0, - pmXprint, - pmPostScript -} PrintMethod; - -class nsDeviceContextSpecQT : public nsIDeviceContextSpec -#ifdef USE_POSTSCRIPT - , public nsIDeviceContextSpecPS -#endif /* USE_POSTSCRIPT */ -#ifdef USE_XPRINT - , public nsIDeviceContextSpecXp -#endif /* USE_XPRINT */ -{ -public: - nsDeviceContextSpecQT(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(nsIPrintSettings* aPS); - NS_IMETHOD ClosePrintManager(); - - NS_IMETHOD GetToPrinter(PRBool &aToPrinter); - 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); - virtual ~nsDeviceContextSpecQT(); - -protected: - nsCOMPtr mPrintSettings; - PRBool mToPrinter; /* If PR_TRUE, print to printer */ - PRBool mFpf; /* If PR_TRUE, first page first */ - PRBool mGrayscale; /* If PR_TRUE, print grayscale */ - 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 */ - int mCopies; /* number of copies */ - PRBool mCancel; /* If PR_TRUE, user cancelled */ - float mLeft; /* left margin */ - float mRight; /* right margin */ - float mTop; /* top margin */ - float mBottom; /* bottom margin */ -}; - -//------------------------------------------------------------------------- -// Printer Enumerator -//------------------------------------------------------------------------- -class nsPrinterEnumeratorQT : public nsIPrinterEnumerator -{ -public: - nsPrinterEnumeratorQT(); - NS_DECL_ISUPPORTS - NS_DECL_NSIPRINTERENUMERATOR -}; - -#endif /* !nsDeviceContextSpecQT_h___ */ diff --git a/gfx/src/qt/nsDrawingSurfaceQT.cpp b/gfx/src/qt/nsDrawingSurfaceQT.cpp deleted file mode 100644 index 0fd00f52422c..000000000000 --- a/gfx/src/qt/nsDrawingSurfaceQT.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDrawingSurfaceQT.h" -#include "nsRenderingContextQT.h" -#include - -#include "qtlog.h" - -#ifdef DEBUG -PRUint32 gDSCount = 0; -PRUint32 gDSID = 0; -#endif - -NS_IMPL_ISUPPORTS2(nsDrawingSurfaceQT, nsIDrawingSurface, nsIDrawingSurfaceQT) - -nsDrawingSurfaceQT::nsDrawingSurfaceQT() -{ -#ifdef DEBUG - gDSCount++; - mID = gDSID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsDrawingSurfaceQT CTOR (%p) ID: %d, Count: %d\n", - this, mID, gDSCount)); -#endif - - mPaintDevice = nsnull; - mPixmap = nsnull; - mGC = nsnull; - mDepth = -1; - mWidth = 0; - mHeight = 0; - mFlags = 0; - mLockWidth = 0; - mLockHeight = 0; - mLockFlags = 0; - mLocked = PR_FALSE; - - // I have no idea how to compute these values. - // FIXME - mPixFormat.mRedMask = 0; - mPixFormat.mGreenMask = 0; - mPixFormat.mBlueMask = 0; - mPixFormat.mAlphaMask = 0; - - mPixFormat.mRedShift = 0; - mPixFormat.mGreenShift = 0; - mPixFormat.mBlueShift = 0; - mPixFormat.mAlphaShift = 0; -} - -nsDrawingSurfaceQT::~nsDrawingSurfaceQT() -{ -#ifdef DEBUG - gDSCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsDrawingSurfaceQT DTOR (%p) ID: %d, Count: %d\n", - this, mID, gDSCount)); -#endif - - if (mGC && mGC->isActive()) { - mGC->end(); - } - if (mGC) { - delete mGC; - mGC = nsnull; - } - if (mPixmap) { - delete mPixmap; - mPixmap = nsnull; - } - if (mPaintDevice) { - if (mIsOffscreen && !mPaintDevice->paintingActive()) - delete mPaintDevice; - mPaintDevice = nsnull; - } -} - -NS_IMETHODIMP nsDrawingSurfaceQT::Lock(PRInt32 aX,PRInt32 aY, - PRUint32 aWidth,PRUint32 aHeight, - void **aBits,PRInt32 *aStride, - PRInt32 *aWidthBytes,PRUint32 aFlags) -{ - if (mLocked) { - NS_ASSERTION(0, "nested lock attempt"); - return NS_ERROR_FAILURE; - } - if (!mPixmap) { - NS_ASSERTION(0, "NULL pixmap in lock attempt"); - return NS_ERROR_FAILURE; - } - mLocked = PR_TRUE; - mLockX = aX; - mLockY = aY; - mLockWidth = aWidth; - mLockHeight = aHeight; - mLockFlags = aFlags; - - if (mImage.isNull()) - mImage = mPixmap->convertToImage(); - - *aBits = mImage.bits(); - *aStride = mImage.bytesPerLine(); - *aWidthBytes = mImage.bytesPerLine(); - - return NS_OK; -} - -NS_IMETHODIMP nsDrawingSurfaceQT::Unlock(void) -{ - if (!mLocked) { - NS_ASSERTION(0,"attempting to unlock an DrawingSurface that isn't locked"); - return NS_ERROR_FAILURE; - } - if (!mPixmap) { - NS_ASSERTION(0, "NULL pixmap in unlock attempt"); - return NS_ERROR_FAILURE; - } - if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) { - mGC->drawPixmap(0,0,*mPixmap,mLockY,mLockY,mLockWidth,mLockHeight); - } - mLocked = PR_FALSE; - - return NS_OK; -} - -NS_IMETHODIMP nsDrawingSurfaceQT::GetDimensions(PRUint32 *aWidth, - PRUint32 *aHeight) -{ - *aWidth = mWidth; - *aHeight = mHeight; - - return NS_OK; -} - -NS_IMETHODIMP nsDrawingSurfaceQT::IsOffscreen(PRBool *aOffScreen) -{ - *aOffScreen = mIsOffscreen; - return NS_OK; -} - -NS_IMETHODIMP nsDrawingSurfaceQT::IsPixelAddressable(PRBool *aAddressable) -{ - *aAddressable = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP nsDrawingSurfaceQT::GetPixelFormat(nsPixelFormat *aFormat) -{ - *aFormat = mPixFormat; - - return NS_OK; -} - -NS_IMETHODIMP nsDrawingSurfaceQT::Init(QPaintDevice *aPaintDevice, - QPainter *aGC) -{ - PR_LOG(gQTLogModule, QT_BASIC, ("[%p] nsDrawingSurface::Init\n", this)); - NS_ASSERTION(aPaintDevice, "need paint dev."); - QPaintDeviceMetrics qMetrics(aPaintDevice); - mGC = aGC; - - mPaintDevice = aPaintDevice; - - mWidth = qMetrics.width(); - mHeight = qMetrics.height(); - mDepth = qMetrics.depth(); - - mIsOffscreen = PR_FALSE; - - if (!mImage.isNull()) - mImage.reset(); - - return CommonInit(); -} - -NS_IMETHODIMP nsDrawingSurfaceQT::Init(QPainter *aGC, - PRUint32 aWidth, - PRUint32 aHeight, - PRUint32 aFlags) -{ - PR_LOG(gQTLogModule, QT_BASIC, ("[%p] nsDrawingSurface::Init\n", this)); - if (nsnull == aGC || aWidth <= 0 || aHeight <= 0) { - return NS_ERROR_FAILURE; - } - mGC = aGC; - mWidth = aWidth; - mHeight = aHeight; - mFlags = aFlags; - - mPixmap = new QPixmap(mWidth, mHeight, mDepth); - mPaintDevice = mPixmap; - NS_ASSERTION(mPaintDevice, "this better not fail"); - - mIsOffscreen = PR_TRUE; - - if (!mImage.isNull()) - mImage.reset(); - - return CommonInit(); -} - -NS_IMETHODIMP nsDrawingSurfaceQT::CommonInit() -{ - PR_LOG(gQTLogModule, QT_BASIC, ("[%p] nsDrawingSurface::CommonInit\n", this)); - if (nsnull == mGC || nsnull == mPaintDevice) { - return NS_ERROR_FAILURE; - } - if (mGC->isActive()) { - mGC->end(); - } - mGC->begin(mPaintDevice); - return NS_OK; -} - -QPainter* nsDrawingSurfaceQT::GetGC() -{ - return mGC; -} - -QPaintDevice* nsDrawingSurfaceQT::GetPaintDevice() -{ - PR_LOG(gQTLogModule, QT_BASIC, ("[%p] nsDrawingSurfaceQt::GetPaintDevice\n", this)); - NS_ASSERTION(mPaintDevice, "No paint device! Something will probably crash soon."); - return mPaintDevice; -} diff --git a/gfx/src/qt/nsDrawingSurfaceQT.h b/gfx/src/qt/nsDrawingSurfaceQT.h deleted file mode 100644 index a87d648adf24..000000000000 --- a/gfx/src/qt/nsDrawingSurfaceQT.h +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsDrawingSurfaceQT_h___ -#define nsDrawingSurfaceQT_h___ - -#include "nsIDrawingSurface.h" -#include "nsIDrawingSurfaceQT.h" - -#include -#include - -class QPixmap; - -class nsDrawingSurfaceQT : public nsIDrawingSurface, - public nsIDrawingSurfaceQT -{ -public: - nsDrawingSurfaceQT(); - virtual ~nsDrawingSurfaceQT(); - - NS_DECL_ISUPPORTS - - //nsIDrawingSurface interface - 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); - - //nsIDrawingSurfaceQT interface - NS_IMETHOD Init(QPaintDevice * aPaintDevice, QPainter *aGC); - NS_IMETHOD Init(QPainter *aGC,PRUint32 aWidth,PRUint32 aHeight, - PRUint32 aFlags); - - // utility functions. - PRInt32 GetDepth() { return mDepth; } - QPainter *GetGC(void); - QPaintDevice *GetPaintDevice(void); - -protected: - NS_IMETHOD CommonInit(); - -private: - /* general */ - QPaintDevice *mPaintDevice; - QPixmap *mPixmap; - QPainter *mGC; - int mDepth; - nsPixelFormat mPixFormat; - PRUint32 mWidth; - PRUint32 mHeight; - PRUint32 mFlags; - PRBool mIsOffscreen; - - /* for locks */ - QImage mImage; - PRInt32 mLockX; - PRInt32 mLockY; - PRUint32 mLockWidth; - PRUint32 mLockHeight; - PRUint32 mLockFlags; - PRBool mLocked; - - PRUint32 mID; -}; - -#endif diff --git a/gfx/src/qt/nsFontMetricsQT.cpp b/gfx/src/qt/nsFontMetricsQT.cpp deleted file mode 100644 index 9396530f312e..000000000000 --- a/gfx/src/qt/nsFontMetricsQT.cpp +++ /dev/null @@ -1,2259 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Jean Claude Batista - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsQuickSort.h" -#include "nsFontMetricsQT.h" -#include "nsFont.h" -#include "nsString.h" -#include "nsXPIDLString.h" -#include "nsReadableUtils.h" -#include "nsIServiceManager.h" -#include "nsISaveAsCharset.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsCOMPtr.h" -#include "nspr.h" -#include "nsHashtable.h" -#include "nsDrawingSurfaceQT.h" -#include "nsRenderingContextQT.h" -#include "nsILanguageAtomService.h" - -#include -#include -#include - -#include "qtlog.h" - -#undef USER_DEFINED -#define USER_DEFINED "x-user-def" - -#ifdef DEBUG -PRUint32 gQFontCount = 0; -PRUint32 gQFontID = 0; - -PRUint32 gFontMetricsCount = 0; -PRUint32 gFontMetricsID = 0; -#endif - -static int gFontMetricsQTCount = 0; -static int gInitialized = 0; - -// XXX many of these statics need to be freed at shutdown time - -static nsIPrefBranch *gPrefBranch = nsnull; -static nsIUnicodeEncoder *gUserDefinedConverter = nsnull; -static nsICharsetConverterManager2 *gCharSetManager = nsnull; -static PRUint32 gUserDefinedMap[2048]; - -static nsHashtable *gCharSets = nsnull; -static nsHashtable *gSpecialCharSets = nsnull; - -static nsIAtom *gUnicode = nsnull; -static nsIAtom *gUserDefined = nsnull; -static nsIAtom *gUsersLocale = nsnull; - -static NS_DEFINE_IID(kIFontMetricsIID,NS_IFONT_METRICS_IID); -static NS_DEFINE_CID(kCharSetManagerCID,NS_ICHARSETCONVERTERMANAGER_CID); -static NS_DEFINE_CID(kSaveAsCharsetCID,NS_SAVEASCHARSET_CID); - -#define NSQ_DOUBLEBYTE 1 - -struct nsFontCharSetInfo -{ - const char *mCharSet; - nsIAtom *mCharsetAtom; - nsIAtom *mLangGroup; - PRUint32 *mMap; - PRUint8 mType; -}; - -struct nsFontCharSetMap -{ - char *mName; - nsFontCharSetInfo *mInfo; -}; - -static nsFontCharSetInfo Unknown = - { nsnull, nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo Special = - { nsnull, nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO106461 = - { nsnull, nsnull, nsnull, nsnull, 0 }; - -static nsFontCharSetInfo CP1251 = - { "windows-1251", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88591 = - { "ISO-8859-1", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88592 = - { "ISO-8859-2", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88593 = - { "ISO-8859-3", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88594 = - { "ISO-8859-4", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88595 = - { "ISO-8859-5", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88596 = - { "ISO-8859-6", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88597 = - { "ISO-8859-7", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88598 = - { "ISO-8859-8", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO88599 = - { "ISO-8859-9", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO885913 = - { "ISO-8859-13", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo ISO885915 = - { "ISO-8859-15", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo JISX0201 = - { "jis_0201", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo KOI8R = - { "KOI8-R", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo KOI8U = - { "KOI8-U", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo TIS620 = - { "TIS-620", nsnull, nsnull, nsnull, 0 }; - -static nsFontCharSetInfo Big5 = - { "x-x-big5", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116431 = - { "x-cns-11643-1", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116432 = - { "x-cns-11643-2", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116433 = - { "x-cns-11643-3", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116434 = - { "x-cns-11643-4", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116435 = - { "x-cns-11643-5", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116436 = - { "x-cns-11643-6", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo CNS116437 = - { "x-cns-11643-7", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo GB2312 = - { "gb_2312-80", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo GB18030_0 = - { "gb18030.2000-0", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo GB18030_1 = - { "gb18030.2000-1", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo GBK = - { "x-gbk", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo HKSCS = - { "hkscs-1", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo JISX0208 = - { "jis_0208-1983", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo JISX0212 = - { "jis_0212-1990", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo KSC5601 = - { "ks_c_5601-1987", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo X11Johab = - { "x-x11johab", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; -static nsFontCharSetInfo Johab = - { "x-johab", nsnull, nsnull, nsnull, NSQ_DOUBLEBYTE }; - -static nsFontCharSetInfo AdobeSymbol = - { "Adobe-Symbol-Encoding", nsnull, nsnull, nsnull, 0 }; - -#ifdef MOZ_MATHML -static nsFontCharSetInfo CMCMEX = - { "x-t1-cmex", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo CMCMSY = - { "x-t1-cmsy", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo CMCMR = - { "x-t1-cmr", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo CMCMMI = - { "x-t1-cmmi", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo Mathematica1 = - { "x-mathematica1", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo Mathematica2 = - { "x-mathematica2", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo Mathematica3 = - { "x-mathematica3", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo Mathematica4 = - { "x-mathematica4", nsnull, nsnull, nsnull, 0 }; -static nsFontCharSetInfo Mathematica5 = - { "x-mathematica5", nsnull, nsnull, nsnull, 0 }; -#endif - -static nsFontCharSetMap gCharSetMap[] = -{ - { "-ascii", &Unknown }, - { "-ibm pc", &Unknown }, - { "adobe-fontspecific", &Special }, - { "big5-0", &Big5 }, - { "big5-1", &Big5 }, - { "big5.et-0", &Big5 }, - { "big5.et.ext-0", &Big5 }, - { "big5.etext-0", &Big5 }, - { "big5.hku-0", &Big5 }, - { "big5.hku-1", &Big5 }, - { "big5.pc-0", &Big5 }, - { "big5.shift-0", &Big5 }, - { "big5hkscs-0", &HKSCS }, - { "cns11643.1986-1", &CNS116431 }, - { "cns11643.1986-2", &CNS116432 }, - { "cns11643.1992-1", &CNS116431 }, - { "cns11643.1992.1-0", &CNS116431 }, - { "cns11643.1992-12", &Unknown }, - { "cns11643.1992.2-0", &CNS116432 }, - { "cns11643.1992-2", &CNS116432 }, - { "cns11643.1992-3", &CNS116433 }, - { "cns11643.1992.3-0", &CNS116433 }, - { "cns11643.1992.4-0", &CNS116434 }, - { "cns11643.1992-4", &CNS116434 }, - { "cns11643.1992.5-0", &CNS116435 }, - { "cns11643.1992-5", &CNS116435 }, - { "cns11643.1992.6-0", &CNS116436 }, - { "cns11643.1992-6", &CNS116436 }, - { "cns11643.1992.7-0", &CNS116437 }, - { "cns11643.1992-7", &CNS116437 }, - { "cns11643-1", &CNS116431 }, - { "cns11643-2", &CNS116432 }, - { "cns11643-3", &CNS116433 }, - { "cns11643-4", &CNS116434 }, - { "cns11643-5", &CNS116435 }, - { "cns11643-6", &CNS116436 }, - { "cns11643-7", &CNS116437 }, - { "cp1251-1", &CP1251 }, - { "dec-dectech", &Unknown }, - { "dtsymbol-1", &Unknown }, - { "fontspecific-0", &Unknown }, - { "gb2312.1980-0", &GB2312 }, - { "gb2312.1980-1", &GB2312 }, - { "gb13000.1993-1", &GBK }, - { "gb18030.2000-0", &GB18030_0 }, - { "gb18030.2000-1", &GB18030_1 }, - { "gbk-0", &GBK }, - { "hkscs-1", &HKSCS }, - { "hp-japanese15", &Unknown }, - { "hp-japaneseeuc", &Unknown }, - { "hp-roman8", &Unknown }, - { "hp-schinese15", &Unknown }, - { "hp-tchinese15", &Unknown }, - { "hp-tchinesebig5", &Big5 }, - { "hp-wa", &Unknown }, - { "hpbig5-", &Big5 }, - { "hproc16-", &Unknown }, - { "ibm-1252", &Unknown }, - { "ibm-850", &Unknown }, - { "ibm-fontspecific", &Unknown }, - { "ibm-sbdcn", &Unknown }, - { "ibm-sbdtw", &Unknown }, - { "ibm-special", &Unknown }, - { "ibm-udccn", &Unknown }, - { "ibm-udcjp", &Unknown }, - { "ibm-udctw", &Unknown }, - { "iso646.1991-irv", &Unknown }, - { "iso8859-1", &ISO88591 }, - { "iso8859-13", &ISO885913 }, - { "iso8859-15", &ISO885915 }, - { "iso8859-1@cn", &Unknown }, - { "iso8859-1@kr", &Unknown }, - { "iso8859-1@tw", &Unknown }, - { "iso8859-1@zh", &Unknown }, - { "iso8859-2", &ISO88592 }, - { "iso8859-3", &ISO88593 }, - { "iso8859-4", &ISO88594 }, - { "iso8859-5", &ISO88595 }, - { "iso8859-6", &ISO88596 }, - { "iso8859-7", &ISO88597 }, - { "iso8859-8", &ISO88598 }, - { "iso8859-9", &ISO88599 }, - { "iso10646-1", &ISO106461 }, - { "jisx0201.1976-0", &JISX0201 }, - { "jisx0201.1976-1", &JISX0201 }, - { "jisx0208.1983-0", &JISX0208 }, - { "jisx0208.1990-0", &JISX0208 }, - { "jisx0212.1990-0", &JISX0212 }, - { "koi8-r", &KOI8R }, - { "koi8-u", &KOI8U }, - { "johab-1", &X11Johab }, - { "johabs-1", &X11Johab }, - { "johabsh-1", &X11Johab }, - { "ksc5601.1987-0", &KSC5601 }, - { "ksc5601.1992-3", &Johab }, - { "microsoft-cp1251", &CP1251 }, - { "misc-fontspecific", &Unknown }, - { "sgi-fontspecific", &Unknown }, - { "sun-fontspecific", &Unknown }, - { "sunolcursor-1", &Unknown }, - { "sunolglyph-1", &Unknown }, - { "tis620.2529-1", &TIS620 }, - { "tis620.2533-0", &TIS620 }, - { "tis620.2533-1", &TIS620 }, - { "tis620-0", &TIS620 }, - { "iso8859-11", &TIS620 }, - { "ucs2.cjk-0", &Unknown }, - { "ucs2.cjk_japan-0", &Unknown }, - { "ucs2.cjk_taiwan-0", &Unknown }, - - { nsnull, nsnull } -}; - -static nsFontCharSetMap gSpecialCharSetMap[] = -{ - { "symbol-adobe-fontspecific", &AdobeSymbol }, - -#ifdef MOZ_MATHML - { "cmex10-adobe-fontspecific", &CMCMEX }, - { "cmsy10-adobe-fontspecific", &CMCMSY }, - { "cmr10-adobe-fontspecific", &CMCMR }, - { "cmmi10-adobe-fontspecific", &CMCMMI }, - - { "math1-adobe-fontspecific", &Mathematica1 }, - { "math2-adobe-fontspecific", &Mathematica2 }, - { "math3-adobe-fontspecific", &Mathematica3 }, - { "math4-adobe-fontspecific", &Mathematica4 }, - { "math5-adobe-fontspecific", &Mathematica5 }, - - { "math1mono-adobe-fontspecific", &Mathematica1 }, - { "math2mono-adobe-fontspecific", &Mathematica2 }, - { "math3mono-adobe-fontspecific", &Mathematica3 }, - { "math4mono-adobe-fontspecific", &Mathematica4 }, - { "math5mono-adobe-fontspecific", &Mathematica5 }, -#endif - - { nsnull, nsnull } -}; - -struct nsFontFamilyName -{ - char *mName; - char *mXName; -}; - -static struct nsFontFamilyName 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 - - { nsnull, nsnull } -}; - -struct nsFontSearch -{ - nsFontMetricsQT *mMetrics; - PRUnichar mChar; - nsFontQT *mFont; -}; - -class nsFontQTNormal : public nsFontQT -{ -public: - nsFontQTNormal(); - nsFontQTNormal(QFont *aQFont); - virtual ~nsFontQTNormal(); - - virtual int GetWidth(const PRUnichar *aString,PRUint32 aLength); - virtual int DrawString(nsRenderingContextQT *aContext, - nsDrawingSurfaceQT *aSurface,nscoord aX, - nscoord aY,const PRUnichar *aString, - PRUint32 aLength); -#ifdef MOZ_MATHML - virtual nsresult GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics); -#endif -}; - -class nsFontQTSubstitute : public nsFontQT -{ -public: - nsFontQTSubstitute(nsFontQT *aFont); - virtual ~nsFontQTSubstitute(); - - virtual QFont *GetQFont(void); - virtual int SupportsChar(PRUnichar aChar); - virtual int GetWidth(const PRUnichar *aString,PRUint32 aLength); - virtual int DrawString(nsRenderingContextQT *aContext, - nsDrawingSurfaceQT *aSurface,nscoord aX, - nscoord aY,const PRUnichar *aString, - PRUint32 aLength); -#ifdef MOZ_MATHML - virtual nsresult GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics); -#endif - virtual PRUint32 Convert(const PRUnichar *aSrc,PRUint32 aSrcLen, - PRUnichar *aDest,PRUint32 aDestLen); - - nsFontQT *mSubstituteFont; - - static int gCount; - static nsISaveAsCharset *gConverter; -}; - -int nsFontQTSubstitute::gCount = 0; -nsISaveAsCharset *nsFontQTSubstitute::gConverter = nsnull; - -class nsFontQTUserDefined : public nsFontQT -{ -public: - nsFontQTUserDefined(); - virtual ~nsFontQTUserDefined(); - - virtual PRUint32 *GetCharSetMap() { return mMap; }; - virtual PRBool Init(nsFontQT *aFont); - virtual int GetWidth(const PRUnichar *aString,PRUint32 aLength); - virtual int DrawString(nsRenderingContextQT *aContext, - nsDrawingSurfaceQT *aSurface,nscoord aX, - nscoord aY,const PRUnichar *aString, - PRUint32 aLength); -#ifdef MOZ_MATHML - virtual nsresult GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics); -#endif - virtual PRUint32 Convert(const PRUnichar *aSrc,PRInt32 aSrcLen, - char *aDest,PRInt32 aDestLen); - - PRUint32 *mMap; -}; - -QFontDatabase *nsFontMetricsQT::mQFontDB = nsnull; - -static PRBool -FreeCharSet(nsHashKey *aKey,void *aData,void *aClosure) -{ - nsFontCharSetInfo *charset = (nsFontCharSetInfo*)aData; - - NS_IF_RELEASE(charset->mCharsetAtom); - NS_IF_RELEASE(charset->mLangGroup); - return PR_TRUE; -} - -static void -FreeGlobals(void) -{ - // XXX complete this - gInitialized = 0; - NS_IF_RELEASE(gCharSetManager); - if (gCharSets) { - gCharSets->Reset(FreeCharSet,nsnull); - delete gCharSets; - gCharSets = nsnull; - } - if (gSpecialCharSets) { - delete gSpecialCharSets; - gSpecialCharSets = nsnull; - } - NS_IF_RELEASE(gPrefBranch); - NS_IF_RELEASE(gUnicode); - NS_IF_RELEASE(gUserDefined); - NS_IF_RELEASE(gUserDefinedConverter); - NS_IF_RELEASE(gUsersLocale); -} - -static nsresult -InitGlobals(void) -{ - nsServiceManager::GetService(kCharSetManagerCID, - NS_GET_IID(nsICharsetConverterManager2), - (nsISupports**)&gCharSetManager); - if (!gCharSetManager) { - FreeGlobals(); - return NS_ERROR_FAILURE; - } - CallGetService(NS_PREFSERVICE_CONTRACTID, &gPrefBranch); - if (!gPrefBranch) { - FreeGlobals(); - return NS_ERROR_FAILURE; - } - nsFontFamilyName *f = gFamilyNameTable; - while (f->mName) { - QFont::insertSubstitution(QString(f->mName),QString(f->mXName)); - f++; - } - gCharSets = new nsHashtable(); - if (!gCharSets) { - FreeGlobals(); - return NS_ERROR_OUT_OF_MEMORY; - } - nsFontCharSetMap *charSetMap = gCharSetMap; - while (charSetMap->mName) { - nsCStringKey key(charSetMap->mName); - gCharSets->Put(&key,charSetMap->mInfo); - charSetMap++; - } - gSpecialCharSets = new nsHashtable(); - if (!gSpecialCharSets) { - FreeGlobals(); - return NS_ERROR_OUT_OF_MEMORY; - } - nsFontCharSetMap *specialCharSetMap = gSpecialCharSetMap; - while (specialCharSetMap->mName) { - nsCStringKey key(specialCharSetMap->mName); - gSpecialCharSets->Put(&key,specialCharSetMap->mInfo); - specialCharSetMap++; - } - gUnicode = NS_NewAtom("x-unicode"); - if (!gUnicode) { - FreeGlobals(); - return NS_ERROR_OUT_OF_MEMORY; - } - gUserDefined = NS_NewAtom(USER_DEFINED); - if (!gUserDefined) { - FreeGlobals(); - return NS_ERROR_OUT_OF_MEMORY; - } - memset(gUserDefinedMap,0,sizeof(gUserDefinedMap)); - - nsCOMPtr langService; - langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - if (langService) { - langService->GetLocaleLanguageGroup(&gUsersLocale); - } - if (!gUsersLocale) { - gUsersLocale = NS_NewAtom("x-western"); - } - if (!gUsersLocale) { - FreeGlobals(); - return NS_ERROR_OUT_OF_MEMORY; - } - gInitialized = 1; - return NS_OK; -} - -static void ParseFontPref(nsCAutoString &aPrefValue,QString &aFontName, - QString &aFontFoundryName,QString &aCharSet) -{ - nsCAutoString fontName,fontFoundryName,fontCharSetName; - - /* count hyphens */ - const char *str = aPrefValue.get(); - PRUint32 len = aPrefValue.Length(); - int hyphens = 0; - for (PRUint32 i = 0; i < len; i++) { - if (str[i] == '-') { - hyphens++; - } - } - /* - * if there are 3 hyphens, the name is something like - * - * adobe-times-iso8859-1 - * - * otherwise it is something like - * - * times new roman - */ - if (hyphens == 3) { - PRInt32 start,end; - - /* Try both foundry-name and name */ - start = aPrefValue.FindChar('-'); - end = aPrefValue.FindChar('-',start + 1); - aPrefValue.Left(fontFoundryName,end); - aPrefValue.Right(fontCharSetName,len - end - 1); - aPrefValue.Mid(fontName,start + 1,end - start - 1); - aFontName = fontName.get(); - aFontFoundryName = fontFoundryName.get(); - aCharSet = fontCharSetName.get(); - } - else { - aFontFoundryName = aPrefValue.get(); - } -} - -nsFontMetricsQT::nsFontMetricsQT() -{ -#ifdef DEBUG - gFontMetricsCount++; - mID = gFontMetricsID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsFontMetricsQT CTOR (%p) ID: %d, Count: %d\n", - this, mID, gFontMetricsCount)); -#endif - gFontMetricsQTCount++; - mDeviceContext = nsnull; - mFont = nsnull; - mQStyle = nsnull; - - mLeading = 0; - mMaxAscent = 0; - mMaxDescent = 0; - mMaxAdvance = 0; - mAveCharWidth = 0; - mXHeight = 0; - mSuperscriptOffset = 0; - mSubscriptOffset = 0; - mStrikeoutSize = 0; - mStrikeoutOffset = 0; - mUnderlineSize = 0; - mUnderlineOffset = 0; - mLoadedFonts = nsnull; - mLoadedFontsCount = 0; - mLoadedFontsAlloc = 0; - mUserDefinedFont = nsnull; -} - -nsFontMetricsQT::~nsFontMetricsQT() -{ -#ifdef DEBUG - gFontMetricsCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsFontMetricsQT DTOR (%p) ID: %d, Count: %d\n", - this, mID, gFontMetricsCount)); -#endif - if (nsnull != mFont) { - delete mFont; - mFont = nsnull; - } - if (mLoadedFonts) { - PR_Free(mLoadedFonts); - mLoadedFonts = nsnull; - } - if (mSubstituteFont) { - delete mSubstituteFont; - mSubstituteFont = nsnull; - } - if (mQStyle) { - delete mQStyle; - mQStyle = nsnull; - } - if (mUserDefinedFont) { - delete mUserDefinedFont; - mUserDefinedFont = nsnull; - } - if (mDeviceContext) { - // Notify our device context that owns us so that it can update its font cache - mDeviceContext->FontMetricsDeleted(this); - mDeviceContext = nsnull; - } - if (!--gFontMetricsQTCount) { - FreeGlobals(); - if (mQFontDB) { - delete mQFontDB; - mQFontDB = nsnull; - } - } -} - -NS_IMPL_ISUPPORTS1(nsFontMetricsQT,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) -{ - PR_LOG(gQTLogModule, QT_EXTRA_FONTS, - ("font = '%s'\n", NS_LossyConvertUCS2toASCII(aFamily).get())); - - if (!IsASCIIFontName(aFamily)) { - return PR_TRUE; // skip and continue - } - nsCAutoString name; - nsFontMetricsQT *metrics = (nsFontMetricsQT*)aData; - - name.AssignWithConversion(aFamily.get()); - ToLowerCase(name); - 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 -} - -#if (QT_VERSION >= 230) -static int use_qt_xft() -{ - static int use_xft = 0; - static int chkd_env = 0; - - if (!chkd_env) { - char *e = getenv ("QT_XFT"); - if (e && (*e == '1' || *e == 'y' || *e == 'Y' - || *e == 't' || *e == 'T' )) - use_xft = 1; - chkd_env = 1; - } - return use_xft; - -} -#endif - -NS_IMETHODIMP nsFontMetricsQT::Init(const nsFont &aFont,nsIAtom *aLangGroup, - nsIDeviceContext *aContext) -{ - NS_ASSERTION(!(nsnull == aContext), - "attempt to init fontmetrics with null device context"); - nsresult res; - - if (!gInitialized) { - res = InitGlobals(); - if (NS_FAILED(res)) { - return res; - } - } - mFont = new nsFont(aFont); - mLangGroup = aLangGroup; - mDeviceContext = aContext; - - float a2d; - - aContext->GetAppUnitsToDevUnits(a2d); - mPixelSize = NSToIntRound(a2d * mFont->size); - if (mFont->style == NS_FONT_STYLE_NORMAL) { -#if (QT_VERSION >= 230) - if (use_qt_xft()) - mQStyle = new QString("Regular"); - else -#endif - mQStyle = new QString("Normal"); - } - else if (mFont->style == NS_FONT_STYLE_OBLIQUE) { - mQStyle = new QString("Oblique"); - } - else { - mQStyle = new QString("Italic"); - } - mWeight = mFont->weight; - - mFont->EnumerateFamilies(FontEnumCallback,this); - nsXPIDLCString value; - if (!mGeneric) { - res = gPrefBranch->GetCharPref("font.default", getter_Copies(value)); - if (NS_SUCCEEDED(res)) { - mDefaultFont.Assign(value); - } - 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('.')); - - const PRUnichar *langGroup = nsnull; - mLangGroup->GetUnicode(&langGroup); - name.AppendWithConversion(langGroup); - - PRInt32 minimum = 0; - res = gPrefBranch->GetIntPref(name.get(), &minimum); - if (NS_FAILED(res)) { - nsCOMPtr prefService = do_QueryInterface(gPrefBranch); - nsCOMPtr defaultBranch; - prefService->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch)); - if (defaultBranch) { - defaultBranch->GetIntPref(name.get(), &minimum); - } - } - if (minimum < 0) { - minimum = 0; - } - if (mPixelSize < minimum) { - mPixelSize = minimum; - } - } - if (mLangGroup.get() == gUserDefined) { - if (!gUserDefinedConverter) { - nsCOMPtr charset; - - res = gCharSetManager->GetCharsetAtom2("x-user-defined", - getter_AddRefs(charset)); - if (NS_SUCCEEDED(res)) { - res = gCharSetManager->GetUnicodeEncoder(charset, - &gUserDefinedConverter); - if (NS_SUCCEEDED(res)) { - res - = gUserDefinedConverter->SetOutputErrorBehavior(gUserDefinedConverter->kOnError_Replace, - nsnull, '?'); - nsCOMPtr mapper - = do_QueryInterface(gUserDefinedConverter); - if (mapper) { - res = mapper->FillInfo(gUserDefinedMap); - } - } - else { - return res; - } - } - else { - return res; - } - } - nsCAutoString name("font.name."); - name.Append(*mGeneric); - name.Append(char('.')); - name.Append(USER_DEFINED); - res = gPrefBranch->GetCharPref(name.get(), getter_Copies(value)); - if (NS_SUCCEEDED(res)) { - mUserDefined.Assign(value); - mIsUserDefined = 1; - } - } - mWesternFont = FindFont('a'); - if (!mWesternFont) { - return NS_ERROR_FAILURE; - } - RealizeFont(); - return NS_OK; -} - -QFontDatabase *nsFontMetricsQT::GetQFontDB() -{ - if (!mQFontDB) { - mQFontDB = new QFontDatabase(); - } - return mQFontDB; -} - -NS_IMETHODIMP nsFontMetricsQT::Destroy() -{ - mDeviceContext = nsnull; - return NS_OK; -} - -void nsFontMetricsQT::RealizeFont() -{ - QFontMetrics fm(*(mWesternFont->GetQFont())); - - float f; - mDeviceContext->GetDevUnitsToAppUnits(f); - - mMaxAscent = nscoord(fm.ascent() * f) ; - mMaxDescent = nscoord(fm.descent() * f); - mMaxHeight = mMaxAscent + mMaxDescent; - - mEmHeight = nscoord(fm.height() * f); - mMaxAdvance = nscoord(fm.maxWidth() * f); - - mAveCharWidth = nscoord(fm.width(QChar('x')) * f); - - mEmAscent = mMaxAscent; - mEmDescent = mMaxDescent; - - // 56% of ascent, best guess for non-true type - mXHeight = NSToCoordRound((float) fm.ascent() * f * 0.56f); - - mUnderlineOffset = - nscoord(fm.underlinePos() * f); - - mUnderlineSize = NSToIntRound(fm.lineWidth() * f); - - mSuperscriptOffset = mXHeight; - mSubscriptOffset = mXHeight; - - mStrikeoutOffset = nscoord(fm.strikeOutPos() * f); - mStrikeoutSize = mUnderlineSize; - - mLeading = nscoord(fm.leading() * f); - mSpaceWidth = nscoord(fm.width(QChar(' ')) * f); -} - -NS_IMETHODIMP nsFontMetricsQT::GetXHeight(nscoord &aResult) -{ - aResult = mXHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetSuperscriptOffset(nscoord &aResult) -{ - aResult = mSuperscriptOffset; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetSubscriptOffset(nscoord &aResult) -{ - aResult = mSubscriptOffset; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetStrikeout(nscoord &aOffset,nscoord &aSize) -{ - aOffset = mStrikeoutOffset; - aSize = mStrikeoutSize; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetUnderline(nscoord &aOffset,nscoord &aSize) -{ - aOffset = mUnderlineOffset; - aSize = mUnderlineSize; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetHeight(nscoord &aHeight) -{ - aHeight = mMaxHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetNormalLineHeight(nscoord &aHeight) -{ - aHeight = mEmHeight + mLeading; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetLeading(nscoord &aLeading) -{ - aLeading = mLeading; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetEmHeight(nscoord &aHeight) -{ - aHeight = mEmHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetEmAscent(nscoord &aAscent) -{ - aAscent = mEmAscent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetEmDescent(nscoord &aDescent) -{ - aDescent = mEmDescent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetMaxHeight(nscoord &aHeight) -{ - aHeight = mMaxHeight; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetMaxAscent(nscoord &aAscent) -{ - aAscent = mMaxAscent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetMaxDescent(nscoord &aDescent) -{ - aDescent = mMaxDescent; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetMaxAdvance(nscoord &aAdvance) -{ - aAdvance = mMaxAdvance; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetAveCharWidth(nscoord &aAveCharWidth) -{ - aAveCharWidth = mAveCharWidth; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetSpaceWidth(nscoord &aSpaceWidth) -{ - aSpaceWidth = mSpaceWidth; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetFont(const nsFont *&aFont) -{ - aFont = mFont; - return NS_OK; -} - -NS_IMETHODIMP nsFontMetricsQT::GetLangGroup(nsIAtom **aLangGroup) -{ - if (!aLangGroup) { - return NS_ERROR_NULL_POINTER; - } - *aLangGroup = mLangGroup; - NS_IF_ADDREF(*aLangGroup); - return NS_OK; -} - - -NS_IMETHODIMP nsFontMetricsQT::GetFontHandle(nsFontHandle &aHandle) -{ - aHandle = (nsFontHandle)mWesternFont; - return NS_OK; -} - -nsFontQT* -nsFontMetricsQT::LookUpFontPref(nsCAutoString &aName,PRUnichar aChar) -{ - QString fontName,foundryName,charSetName; - nsFontQT *font = nsnull; - - ParseFontPref(aName,fontName,foundryName,charSetName); - if (!fontName.isEmpty()) { - if (!charSetName.isEmpty()) { - font = LoadFont(foundryName,charSetName,aChar); - if (font) { - return font; - } - } - else { - font = LoadFont(foundryName,aChar); - if (font) { - return font; - } - } - } - else { - font = LoadFont(foundryName,aChar); - if (font) { - return font; - } - } - return font; -} - -nsFontQT* -nsFontMetricsQT::LoadFont(QString &aName,PRUnichar aChar) -{ -#if 0 - QFontDatabase *qFontDB = GetQFontDB(); - nsFontQT *font; - - QStringList *qCharsets = qFontDB->charSets(aName,FALSE); - qCharsets.sort(); - for (QStringList::Iterator csIt = qCharsets.begin(); - csIt != qCharsets.end(); ++csIt) { - font = LoadFont(aName,*csIt,aChar); - if (font) { - return font; - } - } -#endif - return nsnull; -} - -#define USECHARSETS 1 - -nsFontQT* -nsFontMetricsQT::LoadFont(QString &aName, const QString &aCharSet, PRUnichar aChar) -{ - nsFontQT *newFont = nsnull; - QFont *qFont; - nsIUnicodeEncoder *converter; -#ifdef USECHARSETS //XXX need to eventually - - nsCStringKey charSetKey(aCharSet.latin1()); - - nsFontCharSetInfo *charSetInfo - = (nsFontCharSetInfo*)gCharSets->Get(&charSetKey); - - // indirection for font specific charset encoding - if (charSetInfo == &Special) { - nsCAutoString familyCharSetName(aName.latin1()); - familyCharSetName.Append('-'); - familyCharSetName.Append(aCharSet.latin1()); - nsCStringKey familyCharSetKey(familyCharSetName); - charSetInfo = (nsFontCharSetInfo*)gSpecialCharSets->Get(&familyCharSetKey); - } - if (charSetInfo == &Unknown) { - return nsnull; - } - if (!charSetInfo) { - if (mIsUserDefined && FONT_HAS_GLYPH(gUserDefinedMap,aChar)) { - charSetInfo = &Unknown; - } - else { - PR_LOG(gQTLogModule, QT_FONTS, ("cannot find charset %s-%s\n", - aName.latin1(), aCharSet.latin1())); - return nsnull; - } - } - if (charSetInfo->mCharSet) { - if (charSetInfo->mMap) { - for (int i = 0; i < mLoadedFontsCount; i++) { - if (mLoadedFonts[i]->GetCharSetMap() == charSetInfo->mMap) { - return nsnull; - } - } - } - else { - nsresult res; - if (!charSetInfo->mCharsetAtom) { - res - = gCharSetManager->GetCharsetAtom2(charSetInfo->mCharSet, - &charSetInfo->mCharsetAtom); - if (NS_FAILED(res)) { - PR_LOG(gQTLogModule, QT_FONTS, ("=== cannot get Charset Atom for %s\n", - charSetInfo->mCharSet)); - return nsnull; - } - } - if (!charSetInfo->mLangGroup) { - res - = gCharSetManager->GetCharsetLangGroup(charSetInfo->mCharsetAtom, - &charSetInfo->mLangGroup); - if (NS_FAILED(res)) { - PR_LOG(gQTLogModule, QT_FONTS, ("=== cannot get lang group for %s\n", - charSetInfo->mCharSet)); - return nsnull; - } - } - nsCOMPtr charsetAtom - = getter_AddRefs(NS_NewAtom(charSetInfo->mCharSet)); - if (!charsetAtom) { - NS_WARNING("cannot get atom"); - return nsnull; - } - res = gCharSetManager->GetUnicodeEncoder(charsetAtom,&converter); - if (NS_FAILED(res)) { - NS_WARNING("cannot get Unicode converter"); - return nsnull; - } - res = converter->SetOutputErrorBehavior(converter->kOnError_Replace, - nsnull,'?'); - nsCOMPtr mapper - = do_QueryInterface(converter); - if (!mapper) { - NS_WARNING("cannot get nsICharRepresentable"); - return nsnull; - } - charSetInfo->mMap = (PRUint32*)PR_Calloc(2048,4); - if (nsnull == charSetInfo->mMap) { - return nsnull; - } - res = mapper->FillInfo(charSetInfo->mMap); - - /* - * XXX This is a bit of a hack. Documents containing the CP1252 - * extensions of Latin-1 (e.g. smart quotes) will display with - * those special characters way too large. This is because they - * happen to be in these large double byte fonts. So, we disable - * those characters here. Revisit this decision later. - */ - if (charSetInfo->mType == NSQ_DOUBLEBYTE) { - PRUint32 *map = charSetInfo->mMap; -#undef REMOVE_CHAR -#define REMOVE_CHAR(map,c) (map)[(c) >> 5] &= ~(1L << ((c) & 0x1f)) - REMOVE_CHAR(map,0x20AC); - REMOVE_CHAR(map,0x201A); - REMOVE_CHAR(map,0x0192); - REMOVE_CHAR(map,0x201E); - REMOVE_CHAR(map,0x2026); - REMOVE_CHAR(map,0x2020); - REMOVE_CHAR(map,0x2021); - REMOVE_CHAR(map,0x02C6); - REMOVE_CHAR(map,0x2030); - REMOVE_CHAR(map,0x0160); - REMOVE_CHAR(map,0x2039); - REMOVE_CHAR(map,0x0152); - REMOVE_CHAR(map,0x017D); - REMOVE_CHAR(map,0x2018); - REMOVE_CHAR(map,0x2019); - REMOVE_CHAR(map,0x201C); - REMOVE_CHAR(map,0x201D); - REMOVE_CHAR(map,0x2022); - REMOVE_CHAR(map,0x2013); - REMOVE_CHAR(map,0x2014); - REMOVE_CHAR(map,0x02DC); - REMOVE_CHAR(map,0x2122); - REMOVE_CHAR(map,0x0161); - REMOVE_CHAR(map,0x203A); - REMOVE_CHAR(map,0x0153); - REMOVE_CHAR(map,0x017E); - REMOVE_CHAR(map,0x0178); - } - } - if (!FONT_HAS_GLYPH(charSetInfo->mMap,aChar)) { - return nsnull; - } - } -#endif - qFont = LoadQFont(aName); - if (qFont) { - newFont = new nsFontQTNormal(qFont); - if (!newFont) { - delete qFont; - return nsnull; - } -#if 0 - if (charSetInfo == &ISO106461) { - if (!newFont->HasChar(aChar)) { - delete newFont; - return nsnull; - } - } -#endif - if (mLoadedFontsCount == mLoadedFontsAlloc) { - int newSize; - if (mLoadedFontsAlloc) { - newSize = (2 * mLoadedFontsAlloc); - } - else { - newSize = 1; - } - nsFontQT **newPointer - = (nsFontQT**)PR_Realloc(mLoadedFonts, - newSize * sizeof(nsFontQT*)); - if (newPointer) { - mLoadedFonts = newPointer; - mLoadedFontsAlloc = newSize; - } - else { - delete newFont; - return nsnull; - } - } - if (mIsUserDefined) { - mUserDefinedFont = new nsFontQTUserDefined(); - if (nsnull == mUserDefinedFont) { - delete newFont; - return nsnull; - } - mUserDefinedFont->Init(newFont); - newFont = mUserDefinedFont; - } - else { -#ifdef USECHARSETS - newFont->mCharSetInfo = charSetInfo; -#endif - } - mLoadedFonts[mLoadedFontsCount++] = newFont; - } - return newFont; -} - -QFont* -nsFontMetricsQT::LoadQFont(QString &aName) -{ - QFontDatabase *qFontDB; - QFont *qFont; - - qFontDB = GetQFontDB(); - if (qFontDB->isSmoothlyScalable(aName,*mQStyle)) { - qFont = new QFont(qFontDB->font(aName,*mQStyle,(int)mPixelSize)); - } - else { - typedef QValueList QFSList; - QFSList qSizes; - PRUint16 curSz = mPixelSize, loSz = 0; - PRBool exactMatch = PR_FALSE, nameFound = PR_FALSE; - - qSizes = qFontDB->smoothSizes(aName,*mQStyle); - for (QFSList::Iterator szIt = qSizes.begin(); szIt != qSizes.end(); - ++szIt) { - nameFound = PR_TRUE; - curSz = (PRUint16)*szIt; - - if (curSz == mPixelSize) { - exactMatch = PR_TRUE; - break; - } - else if (curSz < mPixelSize) { - loSz = curSz; - } - else { - break; - } - } - if (nameFound) { - if (exactMatch) { - qFont = new QFont(qFontDB->font(aName,*mQStyle,(int)mPixelSize)); - } - else { - PRUint16 loDiff,hiDiff,pixSz; - - loDiff = mPixelSize - loSz; - hiDiff = curSz - mPixelSize; - if (loSz != 0 && loDiff <= hiDiff) { - pixSz = loSz; - } - else { - pixSz = curSz; - } - qFont = new QFont(qFontDB->font(aName,*mQStyle,(int)pixSz)); - } - } - else { - return nsnull; - } - } - if (qFont->family() == aName || qFont->family() == QFont::substitute(aName)) { - // We need to map CSS2 font weight (ranging from [100..900]) to - // qt font weight (ranging from [0..99]) - JCB 2001-03-09 - qFont->setWeight((int)((((mWeight - 100) * 99) + 400) / 800)); - } - else { - delete qFont; - return nsnull; - } - return qFont; -} - -nsresult -nsFontMetricsQT::FamilyExists(const nsString &aName) -{ - if (!IsASCIIFontName(aName)) { - return NS_ERROR_FAILURE; - } - QFontDatabase *qFontDB = GetQFontDB(); - - nsCAutoString name; - name.AssignWithConversion(aName.get()); -#if QT_VERSION < 300 - QStringList qCharsets = qFontDB->charSets(QString((char*)name.get()),FALSE); - if (!qCharsets.isEmpty()) { - return NS_OK; - } -#else - if(qFontDB->families().contains(QString((char*)name.get()))) - return NS_OK; -#endif - return NS_ERROR_FAILURE; -} - -static void -PrefEnumCallback(const char *aName,void *aClosure) -{ - nsFontSearch *s = (nsFontSearch*)aClosure; - if (s->mFont) { - return; - } - QString fontName,foundryName,charSetName; - nsXPIDLCString value; - nsresult res = gPrefBranch->GetCharPref(aName, getter_Copies(value)); - nsCAutoString name; - if (NS_SUCCEEDED(res)) { - name.Assign(value.get()); - s->mFont = s->mMetrics->LookUpFontPref(name,s->mChar); - } - if (!s->mFont) { - nsCOMPtr prefService = do_QueryInterface(gPrefBranch); - nsCOMPtr defaultBranch; - prefService->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch)); - if (defaultBranch) { - res = defaultBranch->GetCharPref(name.get(), getter_Copies(value)); - if (NS_SUCCEEDED(res)) { - name.Assign(value); - s->mFont = s->mMetrics->LookUpFontPref(name,s->mChar); - } - } - } -} - -nsFontQT* -nsFontMetricsQT::FindLangGroupPrefFont(nsIAtom *aLangGroup, - PRUnichar aChar) -{ - nsFontQT *font = nsnull; - nsCAutoString prefix("font.name."); - - prefix.Append(*mGeneric); - if (aLangGroup) { - // check user set pref - nsCAutoString pref = prefix; - const PRUnichar *langGroup = nsnull; - nsXPIDLCString value; - nsCAutoString str; - nsCAutoString str_user; - - pref.Append(char('.')); - aLangGroup->GetUnicode(&langGroup); - pref.AppendWithConversion(langGroup); - nsresult res = gPrefBranch->GetCharPref(pref.get(), getter_Copies(value)); - if (NS_SUCCEEDED(res)) { - str.Assign(value); - str_user.Assign(value); - font = LookUpFontPref(str,aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - // check factory set pref - nsCOMPtr prefService = do_QueryInterface(gPrefBranch); - nsCOMPtr defaultBranch; - prefService->GetDefaultBranch(nsnull, getter_AddRefs(defaultBranch)); - if (defaultBranch) { - res = defaultBranch->GetCharPref(pref.get(), getter_Copies(value)); - if (NS_SUCCEEDED(res)) { - str.Assign(value); - font = LookUpFontPref(str,aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return font; - } - } - } - } - return nsnull; -} - -nsFontQT* -nsFontMetricsQT::FindGenericFont(PRUnichar aChar) -{ - nsFontQT *font = nsnull; - - if (mTriedAllGenerics) { - return nsnull; - } - if (mLangGroup) { - font = FindLangGroupPrefFont(mLangGroup,aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return(font); - } - } - if (mLangGroup != gUsersLocale) { - font = FindLangGroupPrefFont(gUsersLocale,aChar); - if (font) { - NS_ASSERTION(font->SupportsChar(aChar), "font supposed to support this char"); - return(font); - } - } - nsCAutoString prefix("font.name."); - nsFontSearch search = { this,aChar,nsnull }; - - prefix.Append(*mGeneric); - PRUint32 childCount; - char** childArray; - nsresult rv = gPrefBranch->GetChildList(prefix.get(), &childCount, &childArray); - if (NS_SUCCEEDED(rv)) { - for (PRUint32 i = 0; i < childCount; ++i) { - PrefEnumCallback(childArray[i], &search); - } - - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(childCount, childArray); - } - 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; - rv = gPrefBranch->GetChildList(allPrefs.get(), &childCount, &childArray); - if (NS_SUCCEEDED(rv)) { - for (PRUint32 i = 0; i < childCount; ++i) { - PrefEnumCallback(childArray[i], &search); - } - - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(childCount, childArray); - } - if (search.mFont) { - NS_ASSERTION(search.mFont->SupportsChar(aChar), "font supposed to support this char"); - return search.mFont; - } - mTriedAllGenerics = 1; - return nsnull; -} - -nsFontQT* -nsFontMetricsQT::FindLocalFont(PRUnichar aChar) -{ - while (mFontsIndex < mFonts.Count()) { - if (mFontIsGeneric[mFontsIndex]) { - return nsnull; - } - QString qName((*(mFonts.CStringAt(mFontsIndex++))).get()); - nsFontQT *font; - - font = LoadFont(qName,aChar); - if (font) { - return font; - } - } - return nsnull; -} - -#if QT_VERSION < 300 -nsFontQT* -nsFontMetricsQT::FindGlobalFont(PRUnichar aChar) -{ - QStringList qFamilies,qCharsets; - QFontDatabase *qFontDB = GetQFontDB(); - nsFontQT *font; - - qFamilies = qFontDB->families(FALSE); - qFamilies.sort(); - for (QStringList::Iterator famIt = qFamilies.begin(); famIt != qFamilies.end(); ++famIt) { - qCharsets = nsFontMetricsQT::GetQFontDB()->charSets(*famIt,FALSE); - qCharsets.sort(); - for (QStringList::Iterator csIt = qCharsets.begin(); - csIt != qCharsets.end(); ++csIt) { - font = LoadFont(*famIt,*csIt,aChar); - if (font) { - return font; - } - } - } - return nsnull; -} -#endif - -nsFontQT* -nsFontMetricsQT::FindSubstituteFont(PRUnichar aChar) -{ - if (!mSubstituteFont) { - for (int i = 0; i < mLoadedFontsCount; i++) { - if (mLoadedFonts[i]->SupportsChar('a')) { - mSubstituteFont = new nsFontQTSubstitute(mLoadedFonts[i]); - break; - } - } - } - return mSubstituteFont; -} - - -nsFontQT* -nsFontMetricsQT::FindUserDefinedFont(PRUnichar aChar) -{ - if (mIsUserDefined) { - if (!mUserDefinedFont) { - QString fontName(mUserDefined.get()); - LoadFont(fontName,aChar); - } - return mUserDefinedFont; - } - 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 (FindLocalFont). - * - * 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 (FindGenericFont). - * - * Next, we try all of the fonts on the system (FindGlobalFont). This is - * expensive on some Unixes. - * - * Finally, we try to create a substitute font that offers substitute glyphs - * for the characters (FindSubstituteFont). - */ -nsFontQT* -nsFontMetricsQT::FindFont(PRUnichar aChar) -{ - if (!mCharSubst.isEmpty()) { - if (mCharSubst.find((long)aChar)) { - return mSubstituteFont; - } - } - nsFontQT *font = FindUserDefinedFont(aChar); - if (!font) { - font = FindLocalFont(aChar); - if (!font) { - font = FindGenericFont(aChar); - if (!font) { -#if QT_VERSION < 300 - font = FindGlobalFont(aChar); - if (!font) { -#endif - font = FindSubstituteFont(aChar); - if (font) { - mCharSubst.insert((long)aChar,"ok"); - } - } -#if QT_VERSION < 300 - } -#endif - } - } - return font; -} - -MOZ_DECL_CTOR_COUNTER(nsFontQT); - -nsFontQT::nsFontQT() -{ - MOZ_COUNT_CTOR(nsFontQT); - mFont = nsnull; - mFontInfo = nsnull; - mFontMetrics = nsnull; -} - -nsFontQT::nsFontQT(QFont *aQFont) -{ -#ifdef DEBUG - gQFontCount++; - mID = gQFontID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsFontQT CTOR (%p) ID: %d, Count: %d\n",this,mID,gQFontCount)); -#endif - MOZ_COUNT_CTOR(nsFontQT); - mFont = aQFont; - mFontInfo = new QFontInfo(*mFont); - mFontMetrics = new QFontMetrics(*mFont); -} - -nsFontQT::~nsFontQT() -{ -#ifdef DEBUG - gQFontCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsFontQT DTOR (%p) ID: %d, Count: %d\n",this,mID,gQFontCount)); -#endif - MOZ_COUNT_DTOR(nsFontQT); - if (mFont) { - delete mFont; - mFont = nsnull; - } - if (mFontInfo) { - delete mFontInfo; - mFontInfo = nsnull; - } - if (mFontMetrics) { - delete mFontMetrics; - mFontMetrics = nsnull; - } -} - -PRUint32 *nsFontQT::GetCharSetMap() -{ - return -#ifdef USECHARSETS - mCharSetInfo->mMap; -#else - ISO88591; -#endif -} - -QFont* -nsFontQT::GetQFont(void) -{ - return mFont; -} - -int nsFontQT::SupportsChar(PRUnichar aChar) -{ - if (IsUnicodeFont()) - return HasChar(aChar); - else - return (mFont && FONT_HAS_GLYPH(GetCharSetMap(),aChar)); -} - -PRBool nsFontQT::IsUnicodeFont() -{ - return(mCharSetInfo == &ISO106461); -} - -nsFontQTNormal::nsFontQTNormal() -{ -} - -nsFontQTNormal::nsFontQTNormal(QFont *aQFont) - : nsFontQT(aQFont) -{ -} - -nsFontQTNormal::~nsFontQTNormal() -{ -} - -int -nsFontQTNormal::GetWidth(const PRUnichar *aString,PRUint32 aLength) -{ - int result = 0; - - if (mFontMetrics) { - QChar *buf = new QChar[aLength + 1]; - - for (PRUint32 i = 0; i < aLength; i++) { - buf[i] = QChar(*aString++); - } - result = mFontMetrics->width(QString(buf,aLength)); - delete [] buf; - } - return result; -} - -int -nsFontQTNormal::DrawString(nsRenderingContextQT *aContext, - nsDrawingSurfaceQT *aSurface, - nscoord aX,nscoord aY, - const PRUnichar *aString,PRUint32 aLength) -{ - int result = 0; - if (mFontMetrics) { - QChar *buf = new QChar[aLength + 1]; - - for (PRUint32 i = 0; i < aLength; i++) { - buf[i] = QChar(*aString++); - } - QString qStr(buf,aLength); - aContext->MyDrawString(aSurface->GetGC(),aX,aY,qStr); - result = mFontMetrics->width(qStr); - delete [] buf; - } - return result; -} - -#ifdef MOZ_MATHML -// bounding metrics for a string -// remember returned values are not in app units -nsresult -nsFontQTNormal::GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics) -{ - aBoundingMetrics.Clear(); - if (!mFont) { - return NS_ERROR_FAILURE; - } - if (aString && 0 < aLength) { - QChar *buf = new QChar[aLength + 1]; - - for (int i = 0; i < aLength; i++) { - buf[i] = QChar(*aString++); - } - QString qStr(buf,aLength); - - aBoundingMetrics.width = mFontMetrics->width(qStr); - aBoundingMetrics.leftBearing - = mFontMetrics->leftBearing(buf[0]); - aBoundingMetrics.rightBearing - = mFontMetrics->rightBearing(buf[aLength - 1]); - aBoundingMetrics.ascent = mFontMetrics->ascent(); - aBoundingMetrics.descent = mFontMetrics->descent(); - delete [] buf; - } - return NS_OK; -} -#endif - -nsFontQTSubstitute::nsFontQTSubstitute(nsFontQT *aFont) -{ - gCount++; - mSubstituteFont = aFont; -} - -nsFontQTSubstitute::~nsFontQTSubstitute() -{ - if (!--gCount) { - NS_IF_RELEASE(gConverter); - } - // Do not free mSubstituteFont here. It is owned by somebody else. -} - -PRUint32 -nsFontQTSubstitute::Convert(const PRUnichar *aSrc,PRUint32 aSrcLen, - PRUnichar *aDest,PRUint32 aDestLen) -{ - nsresult res; - - if (!gConverter) { - nsComponentManager::CreateInstance(kSaveAsCharsetCID,nsnull, - NS_GET_IID(nsISaveAsCharset), - (void**)&gConverter); - if (gConverter) { - res = gConverter->Init("ISO-8859-1", - nsISaveAsCharset::attr_FallbackQuestionMark - + nsISaveAsCharset::attr_EntityBeforeCharsetConv, - nsIEntityConverter::transliterate); - if (NS_FAILED(res)) { - NS_RELEASE(gConverter); - } - } - } - if (gConverter) { - nsAutoString tmp(aSrc,aSrcLen); - char *conv = nsnull; - res = gConverter->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 -nsFontQTSubstitute::GetWidth(const PRUnichar *aString,PRUint32 aLength) -{ - PRUnichar buf[512]; - PRUint32 len = Convert(aString,aLength,buf,sizeof(buf) / 2); - - return mSubstituteFont->GetWidth(buf,len); -} - -int -nsFontQTSubstitute::DrawString(nsRenderingContextQT *aContext, - nsDrawingSurfaceQT *aSurface, - nscoord aX,nscoord aY, - const PRUnichar *aString,PRUint32 aLength) -{ - PRUnichar buf[512]; - PRUint32 len = Convert(aString,aLength,buf,sizeof(buf) / 2); - - return mSubstituteFont->DrawString(aContext,aSurface,aX,aY,buf,len); -} - -#ifdef MOZ_MATHML -// bounding metrics for a string -// remember returned values are not in app units -nsresult -nsFontQTSubstitute::GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics) -{ - PRUnichar buf[512]; // XXX watch buffer length !!! - PRUint32 len = Convert(aString,aLength,buf,sizeof(buf) / 2); - - return mSubstituteFont->GetBoundingMetrics(buf,len,aBoundingMetrics); -} -#endif - -QFont* -nsFontQTSubstitute::GetQFont(void) -{ - return mSubstituteFont->GetQFont(); -} - -int nsFontQTSubstitute::SupportsChar(PRUnichar aChar) -{ - return mSubstituteFont->SupportsChar(aChar); -} - -nsFontQTUserDefined::nsFontQTUserDefined() -{ - mMap = nsnull; -} - -nsFontQTUserDefined::~nsFontQTUserDefined() -{ - // Do not free mFont here. It is owned by somebody else. -} - -PRBool -nsFontQTUserDefined::Init(nsFontQT *aFont) -{ - mFont = aFont->GetQFont(); - mFontInfo = new QFontInfo(*mFont); - mFontMetrics = new QFontMetrics(*mFont); - mMap = gUserDefinedMap; - return PR_TRUE; -} - -PRUint32 -nsFontQTUserDefined::Convert(const PRUnichar *aSrc,PRInt32 aSrcLen, - char *aDest,PRInt32 aDestLen) -{ - if (aSrcLen > aDestLen) { - aSrcLen = aDestLen; - } - gUserDefinedConverter->Convert(aSrc,&aSrcLen,aDest,&aDestLen); - return aSrcLen; -} - -int -nsFontQTUserDefined::GetWidth(const PRUnichar *aString,PRUint32 aLength) -{ - int result = 0; - - if (mFontMetrics) { - QChar *buf = new QChar[aLength + 1]; - - for (PRUint32 i = 0; i < aLength; i++) { - buf[i] = QChar(*aString++); - } - result = mFontMetrics->width(QString(buf,aLength)); - delete [] buf; - } - return result; -} - -int -nsFontQTUserDefined::DrawString(nsRenderingContextQT *aContext, - nsDrawingSurfaceQT *aSurface, - nscoord aX,nscoord aY, - const PRUnichar *aString,PRUint32 aLength) -{ - int result = 0; - - if (mFontMetrics) { - QChar *buf = new QChar[aLength + 1]; - - for (PRUint32 i = 0; i < aLength; i++) { - buf[i] = QChar(*aString++); - } - QString qStr(buf,aLength); - - aContext->MyDrawString(aSurface->GetGC(),aX,aY,qStr); - result = mFontMetrics->width(qStr); - delete [] buf; - } - return result; -} - -#ifdef MOZ_MATHML -// bounding metrics for a string -// remember returned values are not in app units -nsresult -nsFontQTUserDefined::GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics) -{ - aBoundingMetrics.Clear(); - if (!mFontMetrics) { - return NS_ERROR_FAILURE; - } - if (aString && 0 < aLength) { - QChar *buf = new QChar[aLength + 1]; - - for (int i = 0; i < aLength; i++) { - buf[i] = QChar(*aString++); - } - QString qStr(buf,aLength); - - aBoundingMetrics.width = mFontMetrics->width(qStr); - aBoundingMetrics.leftBearing = mFontMetrics->leftBearing(buf[0]); - aBoundingMetrics.rightBearing = mFontMetrics->rightBearing(buf[aLength - 1]); - aBoundingMetrics.ascent = mFontMetrics->ascent(); - aBoundingMetrics.descent = mFontMetrics->descent(); - delete [] buf; - } - return NS_OK; -} -#endif - -// The Font Enumerator -nsFontEnumeratorQT::nsFontEnumeratorQT() -{ -} - -NS_IMPL_ISUPPORTS1(nsFontEnumeratorQT, nsIFontEnumerator) - -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); -} - -struct FontEnumNode -{ - PRUnichar *name; - struct FontEnumNode *next; -}; - -typedef struct FontEnumNode FontEnumNode; - -#if QT_VERSION < 300 -static nsresult EnumFonts(nsIAtom *aLangGroup,const char *aGeneric, - PRUint32 *aCount,PRUnichar ***aResult) -{ - QFontDatabase *qFontDB = nsFontMetricsQT::GetQFontDB(); - QStringList qCharsets,qFamilies; - FontEnumNode *head = nsnull,*tail = nsnull; - int count = 0; - - /* Get list of all fonts */ - qFamilies = qFontDB->families(FALSE); - qFamilies.sort(); - for (QStringList::Iterator famIt = qFamilies.begin(); - famIt != qFamilies.end(); ++famIt) { - qCharsets = qFontDB->charSets(*famIt,FALSE); - qCharsets.sort(); - for (QStringList::Iterator csIt = qCharsets.begin(); - csIt != qCharsets.end(); ++csIt) { - nsCStringKey charSetKey((*csIt).latin1()); - - nsFontCharSetInfo *charSetInfo - = (nsFontCharSetInfo*)gCharSets->Get(&charSetKey); - - // indirection for font specific charset encoding - if (charSetInfo == &Special) { - nsCAutoString familyCharSetName((*famIt).latin1()); - familyCharSetName.Append('-'); - familyCharSetName.Append((*csIt).latin1()); - nsCStringKey familyCharSetKey(familyCharSetName); - charSetInfo - = (nsFontCharSetInfo*)gSpecialCharSets->Get(&familyCharSetKey); - } - if (!charSetInfo) { - continue; - } - if (aLangGroup != gUserDefined && charSetInfo == &Unknown) { - continue; - } - if (aLangGroup != gUnicode) { - nsresult res; - - if (!charSetInfo->mCharsetAtom) { - res = gCharSetManager->GetCharsetAtom2(charSetInfo->mCharSet, - &charSetInfo->mCharsetAtom); - if (NS_FAILED(res)) { - continue; - } - } - if (!charSetInfo->mLangGroup) { - res = gCharSetManager->GetCharsetLangGroup(charSetInfo->mCharsetAtom, - &charSetInfo->mLangGroup); - if (NS_FAILED(res)) { - continue; - } - } - if (aLangGroup != charSetInfo->mLangGroup) { - continue; - } - } - nsCAutoString name((*famIt).latin1()); - FontEnumNode *node = (FontEnumNode*)nsMemory::Alloc(sizeof(FontEnumNode)); - - if (!node) { - FontEnumNode *ptr = head,*tmp; - while (ptr) { - tmp = ptr; - nsMemory::Free(ptr->name); - ptr = ptr->next; - nsMemory::Free(tmp); - } - return NS_ERROR_OUT_OF_MEMORY; - } - node->name = ToNewUnicode(name); - if (!node->name) { - FontEnumNode *ptr = head,*tmp; - while (ptr) { - tmp = ptr; - nsMemory::Free(ptr->name); - ptr = ptr->next; - nsMemory::Free(tmp); - } - return NS_ERROR_OUT_OF_MEMORY; - } - node->next = nsnull; - if (!head) { - head = node; - } - else { - tail->next = node; - } - tail = node; - count++; - } - } - PRUnichar **array = (PRUnichar**)nsMemory::Alloc(count * sizeof(PRUnichar*)); - if (!array) { - FontEnumNode *ptr = head,*tmp; - while (ptr) { - tmp = ptr; - nsMemory::Free(ptr->name); - ptr = ptr->next; - nsMemory::Free(tmp); - } - return NS_ERROR_OUT_OF_MEMORY; - } - FontEnumNode *ptr = head,*tmp; - for (int i = 0; i < count; i++) { - tmp = ptr; - array[i] = ptr->name; - ptr = ptr->next; - nsMemory::Free(tmp); - } - NS_QuickSort(array,count,sizeof(PRUnichar*),CompareFontNames,nsnull); - - *aCount = count; - *aResult = array; - return NS_OK; -} -#else -static nsresult EnumFonts(nsIAtom *aLangGroup,const char *aGeneric, - PRUint32 *aCount,PRUnichar ***aResult) -{ - QFontDatabase *qFontDB = nsFontMetricsQT::GetQFontDB(); - QStringList qFamilies; - FontEnumNode *head = nsnull,*tail = nsnull; - int count = 0; - - /* Get list of all fonts */ - qFamilies = qFontDB->families(); - qFamilies.sort(); - for (QStringList::Iterator famIt = qFamilies.begin(); - famIt != qFamilies.end(); ++famIt) { - nsCAutoString name((*famIt).latin1()); - FontEnumNode *node = (FontEnumNode*)nsMemory::Alloc(sizeof(FontEnumNode)); - - if (!node) { - FontEnumNode *ptr = head,*tmp; - while (ptr) { - tmp = ptr; - nsMemory::Free(ptr->name); - ptr = ptr->next; - nsMemory::Free(tmp); - } - return NS_ERROR_OUT_OF_MEMORY; - } - node->name = ToNewUnicode(name); - if (!node->name) { - FontEnumNode *ptr = head,*tmp; - while (ptr) { - tmp = ptr; - nsMemory::Free(ptr->name); - ptr = ptr->next; - nsMemory::Free(tmp); - } - return NS_ERROR_OUT_OF_MEMORY; - } - node->next = nsnull; - if (!head) { - head = node; - } - else { - tail->next = node; - } - tail = node; - count++; - } - PRUnichar **array = (PRUnichar**)nsMemory::Alloc(count * sizeof(PRUnichar*)); - if (!array) { - FontEnumNode *ptr = head,*tmp; - while (ptr) { - tmp = ptr; - nsMemory::Free(ptr->name); - ptr = ptr->next; - nsMemory::Free(tmp); - } - return NS_ERROR_OUT_OF_MEMORY; - } - FontEnumNode *ptr = head,*tmp; - for (int i = 0; i < count; i++) { - tmp = ptr; - array[i] = ptr->name; - ptr = ptr->next; - nsMemory::Free(tmp); - } - NS_QuickSort(array,count,sizeof(PRUnichar*),CompareFontNames,nsnull); - - *aCount = count; - *aResult = array; - return NS_OK; -} -#endif - -NS_IMETHODIMP -nsFontEnumeratorQT::EnumerateAllFonts(PRUint32 *aCount,PRUnichar ***aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - NS_ENSURE_ARG_POINTER(aCount); - *aCount = 0; - - return EnumFonts(nsnull,nsnull,aCount,aResult); -} - -NS_IMETHODIMP -nsFontEnumeratorQT::EnumerateFonts(const char *aLangGroup,const char *aGeneric, - PRUint32 *aCount,PRUnichar ***aResult) -{ - nsresult res; - - NS_ENSURE_ARG_POINTER(aResult); - *aResult = nsnull; - NS_ENSURE_ARG_POINTER(aCount); - *aCount = 0; - NS_ENSURE_ARG_POINTER(aGeneric); - NS_ENSURE_ARG_POINTER(aLangGroup); - - nsIAtom *langGroup = NS_NewAtom(aLangGroup); - - res = EnumFonts(langGroup,aGeneric,aCount,aResult); - NS_IF_RELEASE(langGroup); - return(res); -} - -NS_IMETHODIMP -nsFontEnumeratorQT::HaveFontFor(const char *aLangGroup,PRBool *aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - NS_ENSURE_ARG_POINTER(aLangGroup); - - *aResult = PR_TRUE; // always return true for now. - // Finish me - return NS_OK; -} - -NS_IMETHODIMP -nsFontEnumeratorQT::UpdateFontList(PRBool *updateFontList) -{ - *updateFontList = PR_FALSE; // always return false for now - return NS_OK; -} - diff --git a/gfx/src/qt/nsFontMetricsQT.h b/gfx/src/qt/nsFontMetricsQT.h deleted file mode 100644 index dd4279ac8bb4..000000000000 --- a/gfx/src/qt/nsFontMetricsQT.h +++ /dev/null @@ -1,234 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Jean Claude Batista - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsFontMetricsQT_h__ -#define nsFontMetricsQT_h__ - -#include "nsIFontMetrics.h" -#include "nsIFontEnumerator.h" -#include "nsIDeviceContext.h" -#include "nsCRT.h" -#include "nsCOMPtr.h" -#include "nsICharRepresentable.h" -#include "nsICharsetConverterManager.h" -#include "nsICharsetConverterManager2.h" -#include "nsVoidArray.h" - -#include -#include - -class nsFont; -class nsString; -class nsRenderingContextQT; -class nsDrawingSurfaceQT; -class nsFontMetricsQT; -class nsFontQTUserDefined; -class QString; -class QFont; -class QFontInfo; -class QFontDatabase; - -#undef FONT_HAS_GLYPH -#define FONT_HAS_GLYPH(map,char) IS_REPRESENTABLE(map,char) - -typedef struct nsFontCharSetInfo nsFontCharSetInfo; - -class nsFontQT -{ -public: - nsFontQT(); - nsFontQT(QFont *aQFont); - virtual ~nsFontQT(); - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - virtual QFont *GetQFont(void); - virtual PRUint32 *GetCharSetMap(); - PRBool IsUnicodeFont(); - - inline int HasChar(PRUnichar aChar) - { - return(mFontMetrics && mFontMetrics->inFont(QChar(aChar))); - }; - virtual int SupportsChar(PRUnichar aChar); - - virtual int GetWidth(const PRUnichar* aString, PRUint32 aLength) = 0; - virtual int DrawString(nsRenderingContextQT* aContext, - nsDrawingSurfaceQT* 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 - - QFont* mFont; - QFontInfo* mFontInfo; - QFontMetrics* mFontMetrics; - nsFontCharSetInfo* mCharSetInfo; -#ifdef DEBUG -private: - PRUint32 mID; -#endif -}; - -class nsFontMetricsQT : public nsIFontMetrics -{ -public: - nsFontMetricsQT(); - virtual ~nsFontMetricsQT(); - - 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); - NS_IMETHOD GetNormalLineHeight(nscoord &aHeight); - NS_IMETHOD GetLeading(nscoord &aLeading); - 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 GetFont(const nsFont *&aFont); - NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); - NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); - - NS_IMETHOD GetSpaceWidth(nscoord &aSpaceWidth); - - nsFontQT* FindFont(PRUnichar aChar); - nsFontQT* FindUserDefinedFont(PRUnichar aChar); - nsFontQT* FindLangGroupPrefFont(nsIAtom *aLangGroup,PRUnichar aChar); - nsFontQT* FindLocalFont(PRUnichar aChar); - nsFontQT* FindGenericFont(PRUnichar aChar); - nsFontQT* FindGlobalFont(PRUnichar aChar); - nsFontQT* FindSubstituteFont(PRUnichar aChar); - - nsFontQT* LookUpFontPref(nsCAutoString &aName,PRUnichar aChar); - nsFontQT* LoadFont(QString &aName,PRUnichar aChar); - nsFontQT* LoadFont(QString &aName,const QString &aCharSet, - PRUnichar aChar); - QFont* LoadQFont(QString &aName); - - static nsresult FamilyExists(const nsString& aFontName); - - nsFontQT **mLoadedFonts; - PRUint16 mLoadedFontsAlloc; - PRUint16 mLoadedFontsCount; - - nsFontQT *mSubstituteFont; - nsFontQTUserDefined *mUserDefinedFont; - - nsCOMPtr mLangGroup; - nsCStringArray mFonts; - PRUint16 mFontsIndex; - nsVoidArray mFontIsGeneric; - nsCAutoString mDefaultFont; - nsCString *mGeneric; - nsCAutoString mUserDefined; - - PRUint8 mTriedAllGenerics; - PRUint8 mIsUserDefined; - - static QFontDatabase *GetQFontDB(); - -protected: - void RealizeFont(); - - nsIDeviceContext *mDeviceContext; - nsFont *mFont; - nsFontQT *mWesternFont; - - QString *mQStyle; - PRUint16 mPixelSize; - PRUint16 mWeight; - - QIntDict mCharSubst; - - nscoord mLeading; - nscoord mEmHeight; - nscoord mEmAscent; - nscoord mEmDescent; - nscoord mMaxHeight; - nscoord mMaxAscent; - nscoord mMaxDescent; - nscoord mMaxAdvance; - nscoord mAveCharWidth; - nscoord mXHeight; - nscoord mSuperscriptOffset; - nscoord mSubscriptOffset; - nscoord mStrikeoutSize; - nscoord mStrikeoutOffset; - nscoord mUnderlineSize; - nscoord mUnderlineOffset; - nscoord mSpaceWidth; - - static QFontDatabase *mQFontDB; -#ifdef DEBUG -private: - PRUint32 mID; -#endif -}; - -class nsFontEnumeratorQT : public nsIFontEnumerator -{ -public: - nsFontEnumeratorQT(); - NS_DECL_ISUPPORTS - NS_DECL_NSIFONTENUMERATOR -}; - -#endif diff --git a/gfx/src/qt/nsGfxFactoryQT.cpp b/gfx/src/qt/nsGfxFactoryQT.cpp deleted file mode 100644 index 08baf1933f00..000000000000 --- a/gfx/src/qt/nsGfxFactoryQT.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIGenericFactory.h" -#include "nsIModule.h" -#include "nsCOMPtr.h" -#include "nsGfxCIID.h" - -#include "nsBlender.h" -#include "nsFontMetricsQT.h" -#include "nsRenderingContextQT.h" -#include "nsDeviceContextSpecQT.h" -#include "nsDeviceContextSpecFactoryQT.h" -#include "nsScreenManagerQT.h" -#include "nsScriptableRegion.h" -#include "nsDeviceContextQT.h" -#include "nsImageQT.h" -#include "nsFontList.h" -#include "nsPrintSession.h" -#include "gfxImageFrame.h" - -#include "qtlog.h" - -// Initialize qt logging -PRLogModuleInfo *gQTLogModule = PR_NewLogModule("QtGfx"); - -// objects that just require generic constructors - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorQT) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList); -NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerQT) -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; - - if (NULL == aResult) { - rv = NS_ERROR_NULL_POINTER; - return rv; - } - *aResult = NULL; - if (NULL != aOuter) { - rv = NS_ERROR_NO_AGGREGATION; - return rv; - } - // create an nsRegionQT and get the scriptable region from it - nsCOMPtr rgn; - NS_NEWXPCOM(rgn, nsRegionQT); - 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[] = -{ - { "Qt Font Metrics", - NS_FONT_METRICS_CID, - "@mozilla.org/gfx/fontmetrics;1", - nsFontMetricsQTConstructor }, - { "Qt Device Context", - NS_DEVICE_CONTEXT_CID, - "@mozilla.org/gfx/devicecontext;1", - nsDeviceContextQTConstructor }, - { "Qt Rendering Context", - NS_RENDERING_CONTEXT_CID, - "@mozilla.org/gfx/renderingcontext;1", - nsRenderingContextQTConstructor }, - { "Qt Image", - NS_IMAGE_CID, - "@mozilla.org/gfx/image;1", - nsImageQTConstructor }, - { "Qt Region", - NS_REGION_CID, - "@mozilla.org/gfx/region/qt;1", - nsRegionQTConstructor }, - { "Scriptable Region", - NS_SCRIPTABLE_REGION_CID, - "@mozilla.org/gfx/region;1", - nsScriptableRegionConstructor }, - { "Blender", - NS_BLENDER_CID, - "@mozilla.org/gfx/blender;1", - nsBlenderConstructor }, - { "Qt Device Context Spec", - NS_DEVICE_CONTEXT_SPEC_CID, - "@mozilla.org/gfx/devicecontextspec;1", - nsDeviceContextSpecQTConstructor }, - { "Qt Device Context Spec Factory", - NS_DEVICE_CONTEXT_SPEC_FACTORY_CID, - "@mozilla.org/gfx/devicecontextspecfactory;1", - nsDeviceContextSpecFactoryQTConstructor }, - { "Qt Font Enumerator", - NS_FONT_ENUMERATOR_CID, - "@mozilla.org/gfx/fontenumerator;1", - nsFontEnumeratorQTConstructor }, - { "Font List", - NS_FONTLIST_CID, - // "@mozilla.org/gfx/fontlist;1" - NS_FONTLIST_CONTRACTID, - nsFontListConstructor }, - { "Qt Screen Manager", - NS_SCREENMANAGER_CID, - "@mozilla.org/gfx/screenmanager;1", - nsScreenManagerQTConstructor }, - { "shared image frame", - GFX_IMAGEFRAME_CID, - "@mozilla.org/gfx/image/frame;2", - gfxImageFrameConstructor, }, - { "Print Session", - NS_PRINTSESSION_CID, - "@mozilla.org/gfx/printsession;1", - nsPrintSessionConstructor } -}; - -NS_IMPL_NSGETMODULE(nsGfxQTModule, components) - diff --git a/gfx/src/qt/nsIDrawingSurfaceQT.h b/gfx/src/qt/nsIDrawingSurfaceQT.h deleted file mode 100644 index 9502dfbbccef..000000000000 --- a/gfx/src/qt/nsIDrawingSurfaceQT.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIDrawingSurfaceQT_h___ -#define nsIDrawingSurfaceQT_h___ - -#include "nsIDrawingSurface.h" - -class QPainter; -class QPaintDevice; - -// windows specific drawing surface method set - -#define NS_IDRAWING_SURFACE_QT_IID \ -{ 0x1ed958b0, 0xcab6, 0x11d2, \ -{ 0xa8, 0x49, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } - -class nsIDrawingSurfaceQT : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDRAWING_SURFACE_QT_IID) - - /** - * Initialize a drawing surface using a QPainter and QPaintDevice. - * these are "owned" by the drawing surface until the drawing - * surface is destroyed. - * @param aGC QPainter to initialize drawing surface with - * @param aPaintDevice QPixmap to initialize drawing surface with - * @return error status - **/ - NS_IMETHOD Init(QPaintDevice *aPaintDevice, QPainter *aGC) = 0; - - /** - * Initialize an offscreen drawing surface using a - * QPainter. aGC is not "owned" by this drawing surface, instead - * it is used to create a drawing surface compatible - * with aGC. if width or height are less than zero, aGC will - * be created with no offscreen bitmap installed. - * @param aGC QPainter to initialize drawing surface with - * @param aWidth width of drawing surface - * @param aHeight height of drawing surface - * @param aFlags flags used to control type of drawing - * surface created - * @return error status - **/ - NS_IMETHOD Init(QPainter * aGC,PRUint32 aWidth,PRUint32 aHeight, - PRUint32 aFlags) = 0; -}; - -#endif // nsIDrawingSurfaceQT_h___ diff --git a/gfx/src/qt/nsImageQT.cpp b/gfx/src/qt/nsImageQT.cpp deleted file mode 100644 index 5509e432708d..000000000000 --- a/gfx/src/qt/nsImageQT.cpp +++ /dev/null @@ -1,480 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsImageQT.h" -#include "nsRenderingContextQT.h" - -#include "nspr.h" -#include "qtlog.h" - -#define IsFlagSet(a,b) ((a) & (b)) - -#ifdef DEBUG -PRUint32 gImageCount = 0; -PRUint32 gImageID = 0; -#endif - -NS_IMPL_ISUPPORTS1(nsImageQT, nsIImage) - -//------------------------------------------------------------ -nsImageQT::nsImageQT() -: mImageBits(nsnull) -, mWidth(0) -, mHeight(0) -, mDepth(0) -, mRequestDepth(0) -, mAlphaBits(nsnull) -, mAlphaPixmap(nsnull) -, mImagePixmap(nsnull) -, mAlphaDepth(0) -, mRowBytes(0) -, mSizeImage(0) -, mAlphaRowBytes(0) -, mNumBytesPixel(0) -, mDecodedX1(0) -, mDecodedY1(0) -, mDecodedX2(0) -, mDecodedY2(0) -{ -#ifdef DEBUG - gImageCount++; - mID = gImageID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsImageQT CTOR (%p) ID: %d, Count: %d\n", this, mID, gImageCount)); -#endif -} - -//------------------------------------------------------------ -nsImageQT::~nsImageQT() -{ -#ifdef DEBUG - gImageCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsImageQT DTOR (%p) ID: %d, Count: %d\n", this, mID, gImageCount)); -#endif - if (nsnull != mImageBits) { - delete[] (PRUint8*)mImageBits; - mImageBits = nsnull; - } - if (nsnull != mAlphaBits) { - delete[] (PRUint8*)mAlphaBits; - mAlphaBits = nsnull; - } - if (nsnull != mAlphaPixmap) { - delete mAlphaPixmap; - } - if (nsnull != mImagePixmap) { - delete mImagePixmap; - } -} - -//------------------------------------------------------------ -nsresult nsImageQT::Init(PRInt32 aWidth,PRInt32 aHeight, - PRInt32 aDepth, - nsMaskRequirements aMaskRequirements) -{ - // gfxImageFrame forces only one nsImageQT::Init - if (aWidth == 0 || aHeight == 0) { - return NS_ERROR_FAILURE; - } - // mImagePixmap gets created once per unique image bits in Draw() - // ImageUpdated(nsImageUpdateFlags_kBitsChanged) can cause the - // image bits to change and mImagePixmap will be unrefed and nulled. - if (nsnull != mImagePixmap) { - delete mImagePixmap; - mImagePixmap = nsnull; - } - if (32 == aDepth) { - mNumBytesPixel = 4; - mDepth = aDepth; - mRequestDepth = mDepth; - } - else if (24 == aDepth) { - mNumBytesPixel = 4; - mDepth = 32; - mRequestDepth = aDepth; - } - else { - NS_NOTREACHED("unexpected image depth"); - return NS_ERROR_UNEXPECTED; - } - mWidth = aWidth; - mHeight = aHeight; - - // 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 PRUint8[mAlphaRowBytes * aHeight]; - break; - - case nsMaskRequirements_kNeeds8Bit: - mAlphaRowBytes = aWidth; - mAlphaDepth = 8; - - // 32-bit align each row - mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3; - mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight]; - break; - } - PR_LOG(gQTLogModule, QT_BASIC, ("nsImageQT::Init succeeded")); - return NS_OK; -} - -//------------------------------------------------------------ - -void nsImageQT::ComputeMetrics() -{ - mRowBytes = CalcBytesSpan(mWidth); - mSizeImage = mRowBytes * mHeight; -} - -PRInt32 nsImageQT::GetHeight() -{ - return mHeight; -} - -PRInt32 nsImageQT::GetWidth() -{ - return mWidth; -} - -PRUint8 *nsImageQT::GetBits() -{ - return mImageBits; -} - -void *nsImageQT::GetBitInfo() -{ - return nsnull; -} - -PRInt32 nsImageQT::GetLineStride() -{ - return mRowBytes; -} - -nsColorMap *nsImageQT::GetColorMap() -{ - return nsnull; -} - -PRUint8 *nsImageQT::GetAlphaBits() -{ - return mAlphaBits; -} - -PRInt32 nsImageQT::GetAlphaLineStride() -{ - return mAlphaRowBytes; -} - -//------------------------------------------------------------ - -PRInt32 nsImageQT::CalcBytesSpan(PRUint32 aWidth) -{ - PRInt32 spanbytes; - - spanbytes = (aWidth * mDepth) >> 5; - - if (((PRUint32)aWidth * mDepth) & 0x1F) { - spanbytes++; - } - spanbytes <<= 2; - return(spanbytes); -} - -//------------------------------------------------------------ - -// set up the palette to the passed in color array, RGB only in this array -void nsImageQT::ImageUpdated(nsIDeviceContext *aContext, - PRUint8 aFlags,nsRect *aUpdateRect) -{ - if (IsFlagSet(nsImageUpdateFlags_kBitsChanged,aFlags)) { - if (nsnull != mAlphaPixmap) { - delete mAlphaPixmap; - mAlphaPixmap = nsnull; - } - // mImagePixmap gets created once per unique image bits in Draw() - // ImageUpdated(nsImageUpdateFlags_kBitsChanged) can cause the - // image bits to change and mImagePixmap will be unrefed and nulled. - if (nsnull != mImagePixmap) { - delete mImagePixmap; - mImagePixmap = nsnull; - } - } - if (aUpdateRect->YMost() > mDecodedY2) - mDecodedY2 = aUpdateRect->YMost(); - if (aUpdateRect->XMost() > mDecodedX2) - mDecodedX2 = aUpdateRect->XMost(); -} - -// Draw the bitmap, this method has a source and destination coordinates -NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - PRInt32 aSX, PRInt32 aSY, - PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, - PRInt32 aDWidth, PRInt32 aDHeight) -{ - if (nsnull == aSurface) { - return NS_ERROR_FAILURE; - } - // Render unique image bits onto an off screen pixmap only once - // The image bits can change as a result of ImageUpdated() - for - // example: animated GIFs. - if (nsnull == mImagePixmap) { - CreateImagePixmap(); - } - if (nsnull == mImagePixmap) - return NS_ERROR_FAILURE; - - // Copy data from mImageBits to the drawing surface specified by aSurface. - // We only want a subset of the data in mImageBits, and the data might - // need to be scaled. - nsDrawingSurfaceQT *drawing = (nsDrawingSurfaceQT*)aSurface; - - drawing->GetGC()->drawImage(aDX,aDY,*mImagePixmap,aSX,aSY, - aSWidth,aSHeight); - return NS_OK; -} - -//------------------------------------------------------------ - -// Draw the bitmap, this draw just has destination coordinates -NS_IMETHODIMP nsImageQT::Draw(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight) -{ - if (nsnull == aSurface) { - return NS_ERROR_FAILURE; - } - // XXX kipp: this is temporary code until we eliminate the - // width/height arguments from the draw method. - if ((aWidth != mWidth) || (aHeight != mHeight)) { - aWidth = mWidth; - aHeight = mHeight; - } - nsDrawingSurfaceQT *drawing = (nsDrawingSurfaceQT*)aSurface; - - // Render unique image bits onto an off screen pixmap only once - // The image bits can change as a result of ImageUpdated() - for - // example: animated GIFs. - if (nsnull == mImagePixmap) { - CreateImagePixmap(); - } - if (nsnull == mImagePixmap) - return NS_ERROR_FAILURE; - - drawing->GetGC()->drawImage(aX,aY,*mImagePixmap,0,0,aWidth,aHeight); - return NS_OK; -} - -void nsImageQT::CreateOffscreenPixmap(PRInt32 aWidth,PRInt32 aHeight) -{ - if (mImagePixmap) - delete mImagePixmap; - mImagePixmap = new QImage(aWidth,aHeight,mDepth); - if (mImagePixmap) { - mImagePixmap->setAlphaBuffer(PR_TRUE); - mImagePixmap->fill(0); - } -} - -void nsImageQT::CreateImagePixmap() -{ - mImagePixmap = new QImage(mWidth,mHeight,mDepth); - - if (mImagePixmap) { - PRInt8 bytesPerPixel = mRequestDepth / 8; - PRUint8 *alpha = mAlphaBits; - PRUint8 *image = mImageBits; - PRUint8 *imagePtr; - PRUint32 pixel; - PRInt32 i,j; - QRgb *line; - - mImagePixmap->setAlphaBuffer(PR_TRUE); - for (i = 0; i < mHeight; i++) { - line = (QRgb*)mImagePixmap->scanLine(i); - - imagePtr = image; - for (j = 0; j < mWidth; j++) { - pixel = 0xFF000000 | *(imagePtr + bytesPerPixel - 1) - | (*(imagePtr + bytesPerPixel - 2) << 8) - | (*(imagePtr + bytesPerPixel - 3) << 16); - if (mAlphaBits) { - if (mAlphaDepth == 1) { - if (!(alpha[j / 8] & (1 << (7 - (j % 8))))) { - pixel &= 0x00FFFFFF; - } - } - else { - pixel &= (alpha[j] << 24); - } - } - else if (bytesPerPixel == 4) - pixel &= (*(imagePtr + bytesPerPixel - 4) << 24); - - line[j] = pixel; - imagePtr += bytesPerPixel; - } - alpha += mAlphaRowBytes; - image += mRowBytes; - } - } -} - -NS_IMETHODIMP nsImageQT::DrawTile(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - nsRect &aSrcRect, nsRect &aTileRect) -{ - nsDrawingSurfaceQT *drawing = (nsDrawingSurfaceQT*)aSurface; - - if (aTileRect.width <= 0 || aTileRect.height <= 0) { - NS_ASSERTION(aTileRect.width > 0 && aTileRect.height > 0, - "Error: image has 0 width or height!"); - return NS_OK; - } - if (drawing->GetDepth() == 8 || mAlphaDepth == 8) { - PRInt32 aY0 = aTileRect.y, aX0 = aTileRect.x; - PRInt32 aY1 = aTileRect.y + aTileRect.height; - PRInt32 aX1 = aTileRect.x + aTileRect.width; - - for (PRInt32 y = aY0; y < aY1; y += aSrcRect.height) - for (PRInt32 x = aX0; x < aX1; x += aSrcRect.width) - Draw(aContext,aSurface,x,y, PR_MIN(aSrcRect.width, aX1 - x), - PR_MIN(aSrcRect.height, aY1 - y)); - - return NS_OK; - } - // Render unique image bits onto an off screen pixmap only once - // The image bits can change as a result of ImageUpdated() - for - // example: animated GIFs. - if (nsnull == mImagePixmap) { - CreateImagePixmap(); - } - if (nsnull == mImagePixmap) - return NS_ERROR_FAILURE; - - QPixmap qPmap; - - qPmap.convertFromImage(*mImagePixmap); - drawing->GetGC()->drawTiledPixmap(aTileRect.x,aTileRect.y, - aTileRect.width,aTileRect.height, - qPmap,aSrcRect.x,aSrcRect.y); - return NS_OK; -} - -NS_IMETHODIMP nsImageQT::DrawTile(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - const nsRect &aTileRect) -{ - nsRect srcRect(aSXOffset,aSYOffset,mWidth,mHeight); - nsRect dstRect(aTileRect); - - return DrawTile(aContext, aSurface, srcRect, dstRect); -} - -//------------------------------------------------------------ - -nsresult nsImageQT::Optimize(nsIDeviceContext* aContext) -{ - return NS_OK; -} - -PRInt32 nsImageQT::GetBytesPix() -{ - return mNumBytesPixel; -} - -//------------------------------------------------------------ -// lock the image pixels. Implement this if you need it. -NS_IMETHODIMP -nsImageQT::LockImagePixels(PRBool aMaskPixels) -{ - return NS_OK; -} - -//------------------------------------------------------------ -// unlock the image pixels. Implement this if you need it. -NS_IMETHODIMP -nsImageQT::UnlockImagePixels(PRBool aMaskPixels) -{ - return NS_OK; -} - -NS_IMETHODIMP nsImageQT::DrawToImage(nsIImage *aDstImage, - nscoord aDX,nscoord aDY, - nscoord aDWidth,nscoord aDHeight) -{ - nsImageQT *dest = NS_STATIC_CAST(nsImageQT*,aDstImage); - - if (!dest) - return NS_ERROR_FAILURE; - - if (!mImagePixmap) - CreateImagePixmap(); - - if (!mImagePixmap) - return NS_ERROR_FAILURE; - - if (!dest->mImagePixmap) - dest->CreateOffscreenPixmap(dest->mWidth,dest->mHeight); - - if (!dest->mImagePixmap) - return NS_ERROR_FAILURE; - - bitBlt(dest->mImagePixmap,aDX,aDY,mImagePixmap,0,0,mWidth,mHeight, - Qt::CopyROP); - - return NS_OK; -} - diff --git a/gfx/src/qt/nsImageQT.h b/gfx/src/qt/nsImageQT.h deleted file mode 100644 index 38577b518b80..000000000000 --- a/gfx/src/qt/nsImageQT.h +++ /dev/null @@ -1,157 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsImageQT_h___ -#define nsImageQT_h___ - -#include "nsIImage.h" - -#include -#include - -#undef Bool - -class nsImageQT : public nsIImage -{ -public: - nsImageQT(); - virtual ~nsImageQT(); - - NS_DECL_ISUPPORTS - - /** - * @see nsIImage.h - */ - virtual PRInt32 GetBytesPix(); - virtual PRBool GetIsRowOrderTopToBottom() {return PR_TRUE;} - virtual PRInt32 GetHeight(); - virtual PRInt32 GetWidth(); - virtual PRUint8 *GetBits(); - virtual void *GetBitInfo(); - virtual PRInt32 GetLineStride(); - - virtual nsColorMap *GetColorMap(); - NS_IMETHOD Draw(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - PRInt32 aX, PRInt32 aY, - PRInt32 aWidth, PRInt32 aHeight); - NS_IMETHOD Draw(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - PRInt32 aSX, PRInt32 aSY, - PRInt32 aSWidth, PRInt32 aSHeight, - PRInt32 aDX, PRInt32 aDY, - PRInt32 aDWidth, PRInt32 aDHeight); - - void CreateOffscreenPixmap(PRInt32 aWidth,PRInt32 aHeight); - NS_IMETHOD DrawToImage(nsIImage *aDstImage,nscoord aDX,nscoord aDY, - nscoord aDWidth,nscoord aDHeight); - - NS_IMETHOD DrawTile(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - nsRect &aSrcRect, - nsRect &aTileRect); - - NS_IMETHOD DrawTile(nsIRenderingContext &aContext, - nsDrawingSurface aSurface, - PRInt32 aSXOffset, PRInt32 aSYOffset, - const nsRect &aTileRect); - - virtual void ImageUpdated(nsIDeviceContext *aContext, - PRUint8 aFlags,nsRect *aUpdateRect); - 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(); - - /** - * Calculate the number of bytes spaned for this image for a given width - * @param aWidth is the width to calculate the number of bytes for - * @return the number of bytes in this span - */ - PRInt32 CalcBytesSpan(PRUint32 aWidth); - /** - * 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(); - void ComputePaletteSize(PRIntn nBitCount); - void CreateImagePixmap(); - -private: - PRInt32 mWidth; - PRInt32 mHeight; - PRInt32 mDepth; // actual bits per pixel - PRInt32 mRequestDepth; // requested bits per pixel - PRInt32 mRowBytes; - PRUint8 *mImageBits; - PRInt32 mSizeImage; - - PRInt8 mNumBytesPixel; - - PRInt32 mDecodedX1; //Keeps track of what part of image - PRInt32 mDecodedY1; // has been decoded. - PRInt32 mDecodedX2; - PRInt32 mDecodedY2; - - // alpha layer members - PRUint8 *mAlphaBits; - QImage *mAlphaPixmap; - PRInt8 mAlphaDepth; // alpha layer depth - PRInt16 mAlphaRowBytes; // alpha bytes per row - QImage *mImagePixmap; - - PRUint32 mID; -}; - -#endif diff --git a/gfx/src/qt/nsRegionQT.cpp b/gfx/src/qt/nsRegionQT.cpp deleted file mode 100644 index ad06421c3662..000000000000 --- a/gfx/src/qt/nsRegionQT.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsRegionQT.h" -#include "prmem.h" -#include "nsRenderingContextQT.h" -#include - -#include "qtlog.h" - -#ifdef DEBUG -PRUint32 gRegionCount = 0; -PRUint32 gRegionID = 0; -#endif - -nsRegionQT::nsRegionQT() : mRegion() -{ -#ifdef DEBUG - gRegionCount++; - mID = gRegionID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsRegionQT CTOR (%p) ID: %d, Count: %d\n", this, mID, gRegionCount)); -#endif -} - -nsRegionQT::~nsRegionQT() -{ -#ifdef DEBUG - gRegionCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsRegionQT DTOR (%p) ID: %d, Count: %d\n", this, mID, gRegionCount)); -#endif -} - -NS_IMPL_ISUPPORTS1(nsRegionQT, nsIRegion) - -nsresult nsRegionQT::Init(void) -{ - SetRegionEmpty(); - return NS_OK; -} - -void nsRegionQT::SetTo(const nsIRegion &aRegion) -{ - nsRegionQT *pRegion = (nsRegionQT*)&aRegion; - - SetRegionEmpty(); - SetTo(pRegion); -} - -void nsRegionQT::SetTo(const nsRegionQT *aRegion) -{ - SetRegionEmpty(); - - mRegion = aRegion->mRegion; -} - -void nsRegionQT::SetTo(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight) -{ - SetRegionEmpty(); - - QRegion nRegion(aX, aY, aWidth, aHeight); - - mRegion = nRegion; -} - -void nsRegionQT::Intersect(const nsIRegion &aRegion) -{ - nsRegionQT *pRegion = (nsRegionQT*)&aRegion; - - mRegion = mRegion.intersect(pRegion->mRegion); -} - -void nsRegionQT::Intersect(PRInt32 aX,PRInt32 aY, - PRInt32 aWidth,PRInt32 aHeight) -{ - QRegion region(aX, aY, aWidth, aHeight); - - mRegion = mRegion.intersect(region); -} - -void nsRegionQT::Union(const nsIRegion &aRegion) -{ - nsRegionQT *pRegion = (nsRegionQT*)&aRegion; - - mRegion = mRegion.unite(pRegion->mRegion); -} - -void nsRegionQT::Union(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight) -{ - QRegion region(aX, aY, aWidth, aHeight); - - mRegion = mRegion.unite(region); -} - -void nsRegionQT::Subtract(const nsIRegion &aRegion) -{ - nsRegionQT *pRegion = (nsRegionQT*)&aRegion; - - mRegion = mRegion.subtract(pRegion->mRegion); -} - -void nsRegionQT::Subtract(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight) -{ - QRegion aRegion(aX, aY, aWidth, aHeight); - - mRegion = mRegion.subtract(aRegion); -} - -PRBool nsRegionQT::IsEmpty(void) -{ - return mRegion.isEmpty(); -} - -PRBool nsRegionQT::IsEqual(const nsIRegion &aRegion) -{ - nsRegionQT *pRegion = (nsRegionQT*)&aRegion; - - return (mRegion == pRegion->mRegion); -} - -void nsRegionQT::GetBoundingBox(PRInt32 *aX,PRInt32 *aY, - PRInt32 *aWidth,PRInt32 *aHeight) -{ - QRect rect = mRegion.boundingRect(); - - *aX = rect.x(); - *aY = rect.y(); - *aWidth = rect.width(); - *aHeight = rect.height(); -} - -void nsRegionQT::Offset(PRInt32 aXOffset, PRInt32 aYOffset) -{ - mRegion.translate(aXOffset, aYOffset); -} - -PRBool nsRegionQT::ContainsRect(PRInt32 aX,PRInt32 aY, - PRInt32 aWidth,PRInt32 aHeight) -{ - QRect rect(aX, aY, aWidth, aHeight); - - return mRegion.contains(rect); -} - -NS_IMETHODIMP nsRegionQT::GetRects(nsRegionRectSet **aRects) -{ - NS_ASSERTION(!(nsnull == aRects), "bad ptr"); - - QArray array = mRegion.rects(); - PRUint32 size = array.size(); - nsRegionRect *rect = nsnull; - nsRegionRectSet *rects = *aRects; - - if (nsnull == rects || rects->mRectsLen < (PRUint32)size) { - void *buf = PR_Realloc(rects, - sizeof(nsRegionRectSet) - + (sizeof(nsRegionRect) * (size - 1))); - - if (nsnull == buf) { - if (nsnull != rects) - rects->mNumRects = 0; - return NS_OK; - } - rects = (nsRegionRectSet*)buf; - rects->mRectsLen = size; - } - rects->mNumRects = size; - rects->mArea = 0; - rect = &rects->mRects[0]; - - for (PRUint32 i = 0; i < size; i++) { - QRect qRect = array[i]; - - rect->x = qRect.x(); - rect->y = qRect.y(); - rect->width = qRect.width(); - rect->height = qRect.height(); - - rects->mArea += rect->width * rect->height; - - rect++; - } - *aRects = rects; - return NS_OK; -} - -NS_IMETHODIMP nsRegionQT::FreeRects(nsRegionRectSet *aRects) -{ - if (nsnull != aRects) { - PR_Free((void*)aRects); - } - return NS_OK; -} - -NS_IMETHODIMP nsRegionQT::GetNativeRegion(void *&aRegion) const -{ - aRegion = (void*)&mRegion; - return NS_OK; -} - -NS_IMETHODIMP nsRegionQT::GetRegionComplexity(nsRegionComplexity &aComplexity) const -{ - // cast to avoid const-ness problems on some compilers - if (((nsRegionQT*)this)->IsEmpty()) { - aComplexity = eRegionComplexity_empty; - } - else { - aComplexity = eRegionComplexity_rect; - } - return NS_OK; -} - -void nsRegionQT::SetRegionEmpty() -{ - if (!IsEmpty()) { - QRegion empty; - mRegion = empty; - } -} - -NS_IMETHODIMP nsRegionQT::GetNumRects(PRUint32 *aRects) const -{ - *aRects = mRegion.rects().size(); - - return NS_OK; -} diff --git a/gfx/src/qt/nsRegionQT.h b/gfx/src/qt/nsRegionQT.h deleted file mode 100644 index 3341d1a092bb..000000000000 --- a/gfx/src/qt/nsRegionQT.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRegionQT_h___ -#define nsRegionQT_h___ - -#include "nsIRegion.h" - -#include - -class nsRegionQT : public nsIRegion -{ -public: - nsRegionQT(); - virtual ~nsRegionQT(); - - NS_DECL_ISUPPORTS - - virtual nsresult Init(); - - virtual void SetTo(const nsIRegion &aRegion); - virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - void SetTo(const nsRegionQT *aRegion); - virtual void Intersect(const nsIRegion &aRegion); - virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual void Union(const nsIRegion &aRegion); - virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual void Subtract(const nsIRegion &aRegion); - virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); - virtual PRBool IsEmpty(void); - virtual PRBool IsEqual(const nsIRegion &aRegion); - virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight); - virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); - virtual 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; - -private: - virtual void SetRegionEmpty(); - -private: - QRegion mRegion; -#ifdef DEBUG - PRUint32 mID; -#endif -}; - -#endif // nsRegionQT_h___ diff --git a/gfx/src/qt/nsRenderingContextQT.cpp b/gfx/src/qt/nsRenderingContextQT.cpp deleted file mode 100644 index 2b44aa8b2b70..000000000000 --- a/gfx/src/qt/nsRenderingContextQT.cpp +++ /dev/null @@ -1,1563 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsFontMetricsQT.h" -#include "nsRenderingContextQT.h" -#include "nsRegionQT.h" -#include "nsImageQT.h" -#include "nsGfxCIID.h" -#include "nsICharRepresentable.h" -#include -#include -#include -#include "prmem.h" - -#include "qtlog.h" - -static NS_DEFINE_IID(kRenderingContextIID,NS_IRENDERING_CONTEXT_IID); - -#ifdef DEBUG -PRUint32 gRCCount = 0; -PRUint32 gRCID = 0; - -PRUint32 gGSCount = 0; -PRUint32 gGSID = 0; -#endif - -class GraphicsState -{ -public: - GraphicsState(); - ~GraphicsState(); - - nsTransform2D *mMatrix; - nsRect mLocalClip; - nsCOMPtr mClipRegion; - nscolor mColor; - nsLineStyle mLineStyle; - nsIFontMetrics *mFontMetrics; - -private: - PRUint32 mID; -}; - -GraphicsState::GraphicsState() -{ -#ifdef DEBUG - gGSCount++; - mID = gGSID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("GraphicsState CTOR (%p) ID: %d, Count: %d\n", this, mID, gGSCount)); -#endif - mMatrix = nsnull; - mLocalClip.x = mLocalClip.y = mLocalClip.width = mLocalClip.height = 0; - mClipRegion = nsnull; - mColor = NS_RGB(0,0,0); - mLineStyle = nsLineStyle_kSolid; - mFontMetrics = nsnull; -} - -GraphicsState::~GraphicsState() -{ -#ifdef DEBUG - gGSCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("GraphicsState DTOR (%p) ID: %d, Count: %d\n", this, mID, gGSCount)); -#endif -} - -NS_IMPL_THREADSAFE_ISUPPORTS1(nsRenderingContextQT, nsIRenderingContext) - -static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); - -nsRenderingContextQT::nsRenderingContextQT() -{ -#ifdef DEBUG - gRCCount++; - mID = gRCID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsRenderingContextQT CTOR (%p) ID: %d, Count: %d\n", this, mID, gRCCount)); -#endif - - mFontMetrics = nsnull; - mContext = nsnull; - mSurface = nsnull; - mOffscreenSurface = nsnull; - mCurrentColor = NS_RGB(255,255,255); // set it to white - mCurrentLineStyle = nsLineStyle_kSolid; - mCurrentFont = nsnull; - mTranMatrix = nsnull; - mP2T = 1.0f; - mStateCache = new nsVoidArray(); - mClipRegion = nsnull; - - mFunction = Qt::CopyROP; - mQLineStyle = Qt::SolidLine; - - mGC = nsnull; - mPaintDev = nsnull; - - PushState(); -} - -nsRenderingContextQT::~nsRenderingContextQT() -{ -#ifdef DEBUG - gRCCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsRenderingContextQT DTOR (%p) ID: %d, Count: %d\n", this, mID, gRCCount)); -#endif - // Destroy the State Machine - if (nsnull != mStateCache) { - PRInt32 cnt = mStateCache->Count(); - - while (--cnt >= 0) { - PRBool clipstate; - - PopState(clipstate); - } - delete mStateCache; - mStateCache = nsnull; - } - if (mTranMatrix) - delete mTranMatrix; - - NS_IF_RELEASE(mOffscreenSurface); - NS_IF_RELEASE(mFontMetrics); - NS_IF_RELEASE(mContext); -} - -NS_IMETHODIMP nsRenderingContextQT::Init(nsIDeviceContext *aContext, - nsIWidget *aWindow) -{ - mContext = aContext; - NS_IF_ADDREF(mContext); - - mSurface = new nsDrawingSurfaceQT(); - - QPaintDevice *pdevice = (QPaintDevice*)aWindow->GetNativeData(NS_NATIVE_WINDOW); - QPainter *gc = new QPainter(); - - mSurface->Init(pdevice,gc); - - mOffscreenSurface = mSurface; - - NS_ADDREF(mSurface); - - return(CommonInit()); -} - -NS_IMETHODIMP nsRenderingContextQT::Init(nsIDeviceContext *aContext, - nsDrawingSurface aSurface) -{ - mContext = aContext; - NS_IF_ADDREF(mContext); - - mSurface = (nsDrawingSurfaceQT*)aSurface; - NS_ADDREF(mSurface); - return (CommonInit()); -} - -NS_IMETHODIMP nsRenderingContextQT::CommonInit() -{ - float app2dev; - - mContext->GetDevUnitsToAppUnits(mP2T); - mContext->GetAppUnitsToDevUnits(app2dev); - mTranMatrix->AddScale(app2dev,app2dev); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetHints(PRUint32 &aResult) -{ - PRUint32 result = 0; - - // Most X servers implement 8 bit text rendering alot 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; - - // 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 nsRenderingContextQT::LockDrawingSurface(PRInt32 aX, - PRInt32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - void **aBits, - PRInt32 *aStride, - PRInt32 *aWidthBytes, - PRUint32 aFlags) -{ - PushState(); - return mSurface->Lock(aX,aY,aWidth,aHeight,aBits,aStride, - aWidthBytes,aFlags); -} - -NS_IMETHODIMP nsRenderingContextQT::UnlockDrawingSurface(void) -{ - PRBool clipstate; - - PopState(clipstate); - mSurface->Unlock(); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::SelectOffScreenDrawingSurface(nsDrawingSurface aSurface) -{ - if (nsnull == aSurface) - mSurface = mOffscreenSurface; - else - mSurface = (nsDrawingSurfaceQT*)aSurface; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::GetDrawingSurface(nsDrawingSurface *aSurface) -{ - *aSurface = mSurface; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::Reset() -{ - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::GetDeviceContext(nsIDeviceContext *&aContext) -{ - NS_IF_ADDREF(mContext); - aContext = mContext; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::PushState(void) -{ -#ifdef USE_GS_POOL - nsGraphicsState *state = nsGraphicsStatePool::GetNewGS(); -#else - GraphicsState *state = new GraphicsState(); -#endif - if (!state) - return NS_ERROR_FAILURE; - - // Push into this state object, add to vector - state->mMatrix = mTranMatrix; - - if (nsnull == mTranMatrix) - mTranMatrix = new nsTransform2D(); - else - mTranMatrix = new nsTransform2D(mTranMatrix); - - state->mClipRegion = mClipRegion; - - NS_IF_ADDREF(mFontMetrics); - state->mFontMetrics = mFontMetrics; - - state->mColor = mCurrentColor; - state->mLineStyle = mCurrentLineStyle; - - mStateCache->AppendElement(state); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::PopState(PRBool &aClipEmpty) -{ - GraphicsState *state; - PRUint32 cnt = mStateCache->Count(); - - if (cnt > 0) { - state = (GraphicsState*)mStateCache->ElementAt(cnt - 1); - mStateCache->RemoveElementAt(cnt - 1); - - // Assign all local attributes from the state object just popped - if (state->mMatrix) { - if (mTranMatrix) - delete mTranMatrix; - mTranMatrix = state->mMatrix; - } - mClipRegion = state->mClipRegion; - - if (state->mColor != mCurrentColor) - SetColor(state->mColor); - - if (state->mLineStyle != mCurrentLineStyle) - SetLineStyle(state->mLineStyle); - - if (state->mFontMetrics && (mFontMetrics != state->mFontMetrics)) - SetFont(state->mFontMetrics); - - // Delete this graphics state object -#ifdef USE_GS_POOL - nsGraphicsStatePool::ReleaseGS(state); -#else - delete state; -#endif - } - if (mClipRegion) { - aClipEmpty = mClipRegion->IsEmpty(); - } - else { - aClipEmpty = PR_TRUE; - } - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::IsVisibleRect(const nsRect &aRect, - PRBool &aVisible) -{ - aVisible = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetClipRect(nsRect &aRect, - PRBool &aClipValid) -{ - PRInt32 x,y,w,h; - - if (!mClipRegion) - return NS_ERROR_FAILURE; - - if (!mClipRegion->IsEmpty()) { - mClipRegion->GetBoundingBox(&x,&y,&w,&h); - aRect.SetRect(x,y,w,h); - aClipValid = PR_TRUE; - } - else { - aRect.SetRect(0,0,0,0); - aClipValid = PR_FALSE; - } - return NS_OK; -} - -/** - * Fills in |aRegion| with a copy of the current clip region. - */ -NS_IMETHODIMP nsRenderingContextQT::CopyClipRegion(nsIRegion &aRegion) -{ - if (!mClipRegion) - return NS_ERROR_FAILURE; - - aRegion.SetTo(*mClipRegion); - return NS_OK; -} - -void nsRenderingContextQT::CreateClipRegion() -{ - if (mClipRegion) - return; - - mClipRegion = do_CreateInstance(kRegionCID); - if (mClipRegion) { - PRUint32 w,h; - - mSurface->GetDimensions(&w,&h); - mClipRegion->Init(); - mClipRegion->SetTo(0,0,w,h); - } -} - -NS_IMETHODIMP nsRenderingContextQT::SetClipRect(const nsRect &aRect, - nsClipCombine aCombine, - PRBool &aClipEmpty) -{ - GraphicsState *state = nsnull; - PRUint32 cnt = mStateCache->Count(); - - if (cnt > 0) { - state = (GraphicsState*)mStateCache->ElementAt(cnt - 1); - } - if (state) { - if (state->mClipRegion) { - if (state->mClipRegion == mClipRegion) { - nsCOMPtr tmpRgn; - - GetClipRegion(getter_AddRefs(tmpRgn)); - mClipRegion = tmpRgn; - } - } - } - CreateClipRegion(); - - nsRect trect = aRect; - - mTranMatrix->TransformCoord(&trect.x,&trect.y, - &trect.width,&trect.height); - - switch (aCombine) { - case nsClipCombine_kIntersect: - mClipRegion->Intersect(trect.x,trect.y,trect.width,trect.height); - break; - - case nsClipCombine_kUnion: - mClipRegion->Union(trect.x,trect.y,trect.width,trect.height); - break; - - case nsClipCombine_kSubtract: - mClipRegion->Subtract(trect.x,trect.y,trect.width,trect.height); - break; - - case nsClipCombine_kReplace: - mClipRegion->SetTo(trect.x,trect.y,trect.width,trect.height); - break; - } - aClipEmpty = mClipRegion->IsEmpty(); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::SetClipRegion(const nsIRegion &aRegion, - nsClipCombine aCombine, - PRBool &aClipEmpty) -{ - PRUint32 cnt = mStateCache->Count(); - GraphicsState *state = nsnull; - - if (cnt > 0) { - state = (GraphicsState *)mStateCache->ElementAt(cnt - 1); - } - if (state) { - if (state->mClipRegion) { - if (state->mClipRegion == mClipRegion) { - nsCOMPtr tmpRgn; - - GetClipRegion(getter_AddRefs(tmpRgn)); - mClipRegion = tmpRgn; - } - } - } - CreateClipRegion(); - - 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; - } - aClipEmpty = mClipRegion->IsEmpty(); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetClipRegion(nsIRegion **aRegion) -{ - nsresult rv = NS_ERROR_FAILURE; - - if (!aRegion || !mClipRegion) - return NS_ERROR_NULL_POINTER; - - if (*aRegion) { - (*aRegion)->SetTo(*mClipRegion); - rv = NS_OK; - } - else { - nsCOMPtr newRegion = do_CreateInstance(kRegionCID,&rv); - if (NS_SUCCEEDED(rv)) { - newRegion->Init(); - newRegion->SetTo(*mClipRegion); - NS_ADDREF(*aRegion = newRegion); - } - } - return rv; -} - -NS_IMETHODIMP nsRenderingContextQT::SetColor(nscolor aColor) -{ - if (nsnull == mContext) - return NS_ERROR_FAILURE; - - mCurrentColor = aColor; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetColor(nscolor &aColor) const -{ - aColor = mCurrentColor; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::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 nsRenderingContextQT::SetFont(nsIFontMetrics *aFontMetrics) -{ - NS_IF_RELEASE(mFontMetrics); - mFontMetrics = aFontMetrics; - NS_IF_ADDREF(mFontMetrics); - - if (mFontMetrics) { - nsFontHandle fontHandle; - - mFontMetrics->GetFontHandle(fontHandle); - mCurrentFont = (nsFontQT*)fontHandle; - } - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::SetLineStyle(nsLineStyle aLineStyle) -{ - if (aLineStyle != mCurrentLineStyle) { - switch (aLineStyle) { - case nsLineStyle_kSolid: - mQLineStyle = QPen::SolidLine; - break; - - case nsLineStyle_kDashed: - mQLineStyle = QPen::DashLine; - break; - - case nsLineStyle_kDotted: - mQLineStyle = QPen::DotLine; - break; - - default: - break; - } - mCurrentLineStyle = aLineStyle ; - } - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetLineStyle(nsLineStyle &aLineStyle) -{ - aLineStyle = mCurrentLineStyle; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::GetFontMetrics(nsIFontMetrics *&aFontMetrics) -{ - NS_IF_ADDREF(mFontMetrics); - aFontMetrics = mFontMetrics; - return NS_OK; -} - -// add the passed in translation to the current translation -NS_IMETHODIMP nsRenderingContextQT::Translate(nscoord aX,nscoord aY) -{ - mTranMatrix->AddTranslation((float)aX,(float)aY); - return NS_OK; -} - -// add the passed in scale to the current scale -NS_IMETHODIMP nsRenderingContextQT::Scale(float aSx,float aSy) -{ - mTranMatrix->AddScale(aSx,aSy); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::GetCurrentTransform(nsTransform2D *&aTransform) -{ - aTransform = mTranMatrix; - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::CreateDrawingSurface(const nsRect& aBounds, - PRUint32 aSurfFlags, - nsDrawingSurface &aSurface) -{ - if (nsnull == mSurface) { - aSurface = nsnull; - return NS_ERROR_FAILURE; - } - if (aBounds.width <= 0 || aBounds.height <= 0) - return NS_ERROR_FAILURE; - - nsDrawingSurfaceQT *surface = new nsDrawingSurfaceQT(); - - if (surface) { - QPainter *gc = new QPainter(); - NS_ADDREF(surface); - surface->Init(gc,aBounds.width,aBounds.height,aSurfFlags); - } - else { - aSurface = nsnull; - return NS_ERROR_FAILURE; - } - aSurface = (nsDrawingSurface)surface; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DestroyDrawingSurface(nsDrawingSurface aDS) -{ - nsDrawingSurfaceQT *surface = (nsDrawingSurfaceQT*)aDS; - - if (surface == NULL) - return NS_ERROR_FAILURE; - - NS_IF_RELEASE(surface); - return NS_OK; -} - -void nsRenderingContextQT::UpdateGC() -{ - QPainter *pGC; - QColor color(NS_GET_R(mCurrentColor), - NS_GET_G(mCurrentColor), - NS_GET_B(mCurrentColor)); - QPen pen(color,0,mQLineStyle); - QBrush brush(color); - - pGC = mSurface->GetGC(); - pGC->setPen(pen); - pGC->setBrush(brush); - pGC->setRasterOp(mFunction); - if (mCurrentFont) - pGC->setFont(*(mCurrentFont->GetQFont())); - if (mClipRegion) { - QRegion *rgn = nsnull; - - pGC->setClipping(TRUE); - mClipRegion->GetNativeRegion((void*&)rgn); - pGC->setClipRegion(*rgn); - } - else { - pGC->setClipping(FALSE); - } -} - -NS_IMETHODIMP nsRenderingContextQT::DrawLine(nscoord aX0,nscoord aY0, - nscoord aX1,nscoord aY1) -{ - nscoord diffX,diffY; - - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return 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(); - mSurface->GetGC()->drawLine(aX0,aY0,aX1 - diffX,aY1 - diffY); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DrawStdLine(nscoord aX0,nscoord aY0, - nscoord aX1,nscoord aY1) -{ - nscoord diffX,diffY; - - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return 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(); - mSurface->GetGC()->drawLine(aX0,aY0,aX1 - diffX,aY1 - diffY); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DrawPolyline(const nsPoint aPoints[], - PRInt32 aNumPoints) -{ - PRInt32 i; - - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - QPointArray *pts = new QPointArray(aNumPoints); - for (i = 0; i < aNumPoints; i++) { - nsPoint p = aPoints[i]; - - mTranMatrix->TransformCoord(&p.x,&p.y); - pts->setPoint(i,p.x,p.y); - } - UpdateGC(); - - mSurface->GetGC()->drawPolyline(*pts); - delete pts; - return NS_OK; -} - -void nsRenderingContextQT::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; - } -} - -NS_IMETHODIMP nsRenderingContextQT::DrawRect(const nsRect &aRect) -{ - return DrawRect(aRect.x,aRect.y,aRect.width,aRect.height); -} - -NS_IMETHODIMP nsRenderingContextQT::DrawRect(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return 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); - - if (w && h) { - UpdateGC(); - mSurface->GetGC()->drawRect(x,y,w,h); - } - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::FillRect(const nsRect &aRect) -{ - return FillRect(aRect.x,aRect.y,aRect.width,aRect.height); -} - -NS_IMETHODIMP nsRenderingContextQT::FillRect(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return 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); - UpdateGC(); - - QColor color(NS_GET_R(mCurrentColor), - NS_GET_G(mCurrentColor), - NS_GET_B(mCurrentColor)); - - mSurface->GetGC()->fillRect(x,y,w,h,color); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::InvertRect(const nsRect &aRect) -{ - return InvertRect(aRect.x,aRect.y,aRect.width,aRect.height); -} - -NS_IMETHODIMP nsRenderingContextQT::InvertRect(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return 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); - - // Set XOR drawing mode - mFunction = Qt::XorROP; - UpdateGC(); - - // Fill the rect - QColor color(NS_GET_R(mCurrentColor), - NS_GET_G(mCurrentColor), - NS_GET_B(mCurrentColor)); - - mSurface->GetGC()->fillRect(x,y,w,h,color); - - // Back to normal copy drawing mode - mFunction = Qt::CopyROP; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DrawPolygon(const nsPoint aPoints[], - PRInt32 aNumPoints) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - QPointArray *pts = new QPointArray(aNumPoints); - for (PRInt32 i = 0; i < aNumPoints; i++) { - nsPoint p = aPoints[i]; - - mTranMatrix->TransformCoord(&p.x,&p.y); - pts->setPoint(i,p.x,p.y); - } - UpdateGC(); - - mSurface->GetGC()->drawPolyline(*pts); - delete pts; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::FillPolygon(const nsPoint aPoints[], - PRInt32 aNumPoints) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - QPointArray *pts = new QPointArray(aNumPoints); - for (PRInt32 i = 0; i < aNumPoints; i++) { - nsPoint p = aPoints[i]; - - mTranMatrix->TransformCoord(&p.x,&p.y); - pts->setPoint(i,p.x,p.y); - } - UpdateGC(); - - mSurface->GetGC()->drawPolygon(*pts); - delete pts; - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DrawEllipse(const nsRect &aRect) -{ - return DrawEllipse(aRect.x,aRect.y,aRect.width,aRect.height); -} - -NS_IMETHODIMP nsRenderingContextQT::DrawEllipse(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - mTranMatrix->TransformCoord(&x,&y,&w,&h); - UpdateGC(); - - mSurface->GetGC()->drawEllipse(x,y,w,h); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::FillEllipse(const nsRect &aRect) -{ - return FillEllipse(aRect.x,aRect.y,aRect.width,aRect.height); -} - -NS_IMETHODIMP nsRenderingContextQT::FillEllipse(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - mTranMatrix->TransformCoord(&x,&y,&w,&h); - UpdateGC(); - - mSurface->GetGC()->drawChord(x,y,w,h,0,16 * 360); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DrawArc(const nsRect &aRect, - float aStartAngle,float aEndAngle) -{ - return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height, - aStartAngle,aEndAngle); -} - -NS_IMETHODIMP nsRenderingContextQT::DrawArc(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight, - float aStartAngle,float aEndAngle) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - mTranMatrix->TransformCoord(&x,&y,&w,&h); - UpdateGC(); - - mSurface->GetGC()->drawArc(x,y,w,h,NSToIntRound(aStartAngle * 16.0f), - NSToIntRound(aEndAngle * 16.0f)); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::FillArc(const nsRect &aRect, - float aStartAngle,float aEndAngle) -{ - return FillArc(aRect.x,aRect.y,aRect.width,aRect.height, - aStartAngle,aEndAngle); -} - -NS_IMETHODIMP nsRenderingContextQT::FillArc(nscoord aX,nscoord aY, - nscoord aWidth,nscoord aHeight, - float aStartAngle,float aEndAngle) -{ - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) - return NS_ERROR_FAILURE; - - nscoord x,y,w,h; - - x = aX; - y = aY; - w = aWidth; - h = aHeight; - mTranMatrix->TransformCoord(&x,&y,&w,&h); - UpdateGC(); - - mSurface->GetGC()->drawPie(x,y,w,h,NSToIntRound(aStartAngle * 16.0f), - NSToIntRound(aEndAngle * 16.0f)); - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetWidth(char aC,nscoord &aWidth) -{ - if (aC == ' ' && nsnull != mFontMetrics) { - nsFontMetricsQT *fontMetrics = (nsFontMetricsQT*)mFontMetrics; - return fontMetrics->GetSpaceWidth(aWidth); - } - return GetWidth(&aC,1,aWidth); -} - -NS_IMETHODIMP nsRenderingContextQT::GetWidth(PRUnichar aC,nscoord &aWidth, - PRInt32 *aFontID) -{ - return GetWidth(&aC,1,aWidth,aFontID); -} - -NS_IMETHODIMP nsRenderingContextQT::GetWidth(const nsString &aString, - nscoord &aWidth,PRInt32 *aFontID) -{ - return GetWidth(aString.get(),aString.Length(),aWidth,aFontID); -} - -NS_IMETHODIMP nsRenderingContextQT::GetWidth(const char *aString, - nscoord &aWidth) -{ - return GetWidth(aString,strlen(aString),aWidth); -} - -NS_IMETHODIMP nsRenderingContextQT::GetWidth(const char *aString, - PRUint32 aLength,nscoord &aWidth) -{ - if (0 == aLength) - aWidth = 0; - else if (nsnull == aString || nsnull == mCurrentFont) - return NS_ERROR_FAILURE; - else { - QFontMetrics curFontMetrics(*(mCurrentFont->GetQFont())); - int rawWidth = curFontMetrics.width(aString,aLength); - - aWidth = NSToCoordRound(rawWidth * mP2T); - } - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::GetWidth(const PRUnichar *aString, - PRUint32 aLength,nscoord &aWidth, - PRInt32 *aFontID) -{ - if (aFontID) - *aFontID = 0; - if (0 == aLength) { - aWidth = 0; - return NS_OK; - } - if (!aString || !mFontMetrics) - return NS_ERROR_FAILURE; - - nsFontMetricsQT *metrics = (nsFontMetricsQT*)mFontMetrics; - nsFontQT *prevFont = nsnull; - int rawWidth = 0; - PRUint32 start = 0; - PRUint32 i; - - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontQT* currFont = nsnull; - if (mCurrentFont->SupportsChar(c)) { - currFont = mCurrentFont; - goto FoundFont; - } - else { - nsFontQT **font = metrics->mLoadedFonts; - nsFontQT **lastFont = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < lastFont) { - if ((*font)->SupportsChar(c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; - } - currFont = metrics->FindFont(c); - } -FoundFont: - 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); - - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::GetTextDimensions(const char* aString, PRUint32 aLength, - nsTextDimensions& aDimensions) -{ - mFontMetrics->GetMaxAscent(aDimensions.ascent); - mFontMetrics->GetMaxDescent(aDimensions.descent); - return GetWidth(aString, aLength, aDimensions.width); -} - -NS_IMETHODIMP -nsRenderingContextQT::GetTextDimensions(const PRUnichar *aString, - PRUint32 aLength, - nsTextDimensions &aDimensions, - PRInt32 *aFontID) -{ - aDimensions.Clear(); - if (0 == aLength) - return NS_OK; - if (nsnull == aString) - return NS_ERROR_FAILURE; - - nsFontMetricsQT *metrics = (nsFontMetricsQT*)mFontMetrics; - nsFontQT *prevFont = nsnull; - int rawWidth = 0, rawAscent = 0, rawDescent = 0; - PRUint32 start = 0; - PRUint32 i; - - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontQT* currFont = nsnull; - if (mCurrentFont->SupportsChar(c)) { - currFont = mCurrentFont; - goto FoundFont; - } - else { - nsFontQT **font = metrics->mLoadedFonts; - nsFontQT **lastFont = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < lastFont) { - if ((*font)->SupportsChar(c)) { - currFont = *font; - goto FoundFont; // for speed -- avoid "if" statement - } - font++; - } - currFont = metrics->FindFont(c); - } -FoundFont: - if (prevFont && prevFont->mFontMetrics) { - if (currFont != prevFont) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - if (rawAscent < prevFont->mFontMetrics->ascent()) - rawAscent = prevFont->mFontMetrics->ascent(); - if (rawDescent < prevFont->mFontMetrics->descent()) - rawDescent = prevFont->mFontMetrics->descent(); - prevFont = currFont; - start = i; - } - } - else { - prevFont = currFont; - start = i; - } - } - if (prevFont && prevFont->mFontMetrics) { - rawWidth += prevFont->GetWidth(&aString[start], i - start); - if (rawAscent < prevFont->mFontMetrics->ascent()) - rawAscent = prevFont->mFontMetrics->ascent(); - if (rawDescent < prevFont->mFontMetrics->descent()) - rawDescent = prevFont->mFontMetrics->descent(); - } - - 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 -nsRenderingContextQT::GetTextDimensions(const char* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID) -{ - NS_NOTREACHED("nsRenderingContextQT::GetTextDimensions not implemented\n"); - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP -nsRenderingContextQT::GetTextDimensions(const PRUnichar* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID) -{ - NS_NOTREACHED("nsRenderingContextQT::GetTextDimensions not implemented\n"); - return NS_ERROR_NOT_IMPLEMENTED; -} - - -NS_IMETHODIMP nsRenderingContextQT::DrawString(const char *aString, - PRUint32 aLength, - nscoord aX, nscoord aY, - const nscoord *aSpacing) -{ - if (0 != aLength) { - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice() - || nsnull == aString) - return NS_ERROR_FAILURE; - - nscoord x = aX; - nscoord y = aY; - - UpdateGC(); - - 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); - QString str; - str = ch; - mSurface->GetGC()->drawText(xx,yy,str,1); - x += *aSpacing++; - } - } - else { - QString qStr(aString); - qStr[aLength] = '\0'; - mTranMatrix->TransformCoord(&x,&y); - mSurface->GetGC()->drawText(x,y,qStr,aLength); - } - } - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextQT::DrawString(const PRUnichar *aString, - PRUint32 aLength, - nscoord aX,nscoord aY, - PRInt32 aFontID, - const nscoord *aSpacing) -{ - if (aLength && mFontMetrics) { - if (nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetGC() - || nsnull == mSurface->GetPaintDevice() || nsnull == aString) - return NS_ERROR_FAILURE; - - nscoord x = aX; - nscoord y = aY; - - mTranMatrix->TransformCoord(&x,&y); - - nsFontMetricsQT *metrics = (nsFontMetricsQT*)mFontMetrics; - nsFontQT *prevFont = nsnull; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontQT *currFont = nsnull; - - if (mCurrentFont->SupportsChar(c)) { - currFont = mCurrentFont; - goto FoundFont; - } - else { - nsFontQT **font = metrics->mLoadedFonts; - nsFontQT **lastFont = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < lastFont) { - if ((*font)->SupportsChar(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 mCurrentFont and set it so that we cache correctly - nsFontQT *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 { - nsFontQT *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) { - nsFontQT *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 nsRenderingContextQT::DrawString(const nsString &aString, - nscoord aX,nscoord aY, - PRInt32 aFontID, - const nscoord *aSpacing) -{ - return DrawString(aString.get(),aString.Length(),aX,aY,aFontID, - aSpacing); -} - -void nsRenderingContextQT::MyDrawString(QPainter *aGC, - nscoord aX,nscoord aY, - QString &aText) -{ - if (nsnull == aGC || aText.isEmpty() || aText.isNull()) { - return; - } - aGC->drawText(aX,aY,aText); -} - -NS_IMETHODIMP -nsRenderingContextQT::CopyOffScreenBits(nsDrawingSurface aSrcSurf, - PRInt32 aSrcX, - PRInt32 aSrcY, - const nsRect &aDestBounds, - PRUint32 aCopyFlags) -{ - PRInt32 x = aSrcX; - PRInt32 y = aSrcY; - nsRect drect = aDestBounds; - nsDrawingSurfaceQT *destsurf; - - if (nsnull == aSrcSurf || nsnull == mTranMatrix || nsnull == mSurface - || nsnull == mSurface->GetPaintDevice() || nsnull == mSurface->GetGC()) - return NS_ERROR_FAILURE; - - if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER) { - NS_ASSERTION(!(nsnull == mSurface), "no back buffer"); - destsurf = mSurface; - } - else - destsurf = mOffscreenSurface; - - if (aCopyFlags & NS_COPYBITS_XFORM_SOURCE_VALUES) - mTranMatrix->TransformCoord(&x,&y); - - 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(); - - destsurf->GetGC()->drawPixmap(x,y, - *(QPixmap*)((nsDrawingSurfaceQT*)aSrcSurf)->GetPaintDevice(), - drect.x,drect.y,drect.width,drect.height); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::RetrieveCurrentNativeGraphicData(PRUint32 *ngd) -{ - return NS_OK; -} - -#ifdef MOZ_MATHML -NS_IMETHODIMP -nsRenderingContextQT::GetBoundingMetrics(const char *aString,PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics) -{ - aBoundingMetrics.Clear(); - if (0 >= aLength || !aString || !mCurrentFont) { - return(NS_ERROR_FAILURE); - } - else { - QChar *buf = new QChar[aLength]; - - for (int i = 0; i < aLength; i++) { - buf[i] = QChar(aString[i]); - } - QString qStr(buf,aLength); - QFontMetrics qFM(*(mCurrentFont->mFont)); - - aBoundingMetrics.width = qFM.width(qStr); - aBoundingMetrics.leftBearing = qFM.leftBearing(buf[0]); - aBoundingMetrics.rightBearing = qFM.rightBearing(buf[aLength - 1]); - aBoundingMetrics.ascent = qFM.ascent(); - aBoundingMetrics.descent = qFM.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); - delete [] buf; - } - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextQT::GetBoundingMetrics(const PRUnichar *aString, - PRUint32 aLength, - nsBoundingMetrics &aBoundingMetrics, - PRInt32 *aFontID) -{ - aBoundingMetrics.Clear(); - if (0 < aLength) { - if (aString == NULL) - return NS_ERROR_FAILURE; - - nsFontMetricsQT *metrics = (nsFontMetricsQT*)mFontMetrics; - nsFontQT *prevFont = nsnull; - - nsBoundingMetrics rawbm; - PRBool firstTime = PR_TRUE; - PRUint32 start = 0; - PRUint32 i; - for (i = 0; i < aLength; i++) { - PRUnichar c = aString[i]; - nsFontQT *currFont = nsnull; - nsFontQT **font = metrics->mLoadedFonts; - nsFontQT **end = &metrics->mLoadedFonts[metrics->mLoadedFontsCount]; - while (font < end) { - if ((*font)->SupportsChar( 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 */ diff --git a/gfx/src/qt/nsRenderingContextQT.h b/gfx/src/qt/nsRenderingContextQT.h deleted file mode 100644 index 839037f61147..000000000000 --- a/gfx/src/qt/nsRenderingContextQT.h +++ /dev/null @@ -1,243 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsRenderingContextQT_h___ -#define nsRenderingContextQT_h___ - -#include "nsRenderingContextImpl.h" -#include "nsUnitConversion.h" -#include "nsFont.h" -#include "nsIFontMetrics.h" -#include "nsPoint.h" -#include "nsString.h" -#include "nsCRT.h" -#include "nsTransform2D.h" -#include "nsIWidget.h" -#include "nsRect.h" -#include "nsIDeviceContext.h" -#include "nsVoidArray.h" -#include "nsCOMPtr.h" - -#include "nsRegionQT.h" -#include "nsDrawingSurfaceQT.h" -#include "prlog.h" - -class nsFontQT; - -class nsRenderingContextQT : public nsRenderingContextImpl -{ -public: - nsRenderingContextQT(); - virtual ~nsRenderingContextQT(); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - NS_DECL_ISUPPORTS - - NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow); - NS_IMETHOD Init(nsIDeviceContext* aContext, nsDrawingSurface 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(nsDrawingSurface aSurface); - NS_IMETHOD GetDrawingSurface(nsDrawingSurface *aSurface); - NS_IMETHOD GetHints(PRUint32& aResult); - - NS_IMETHOD PushState(void); - NS_IMETHOD PopState(PRBool &aClipEmpty); - - NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible); - - NS_IMETHOD SetClipRect(const nsRect& aRect,nsClipCombine aCombine, - PRBool &aClipEmpty); - NS_IMETHOD CopyClipRegion(nsIRegion &aRegion); - NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid); - NS_IMETHOD SetClipRegion(const nsIRegion& aRegion,nsClipCombine aCombine, - PRBool &aClipEmpty); - 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, - nsDrawingSurface &aSurface); - NS_IMETHOD DestroyDrawingSurface(nsDrawingSurface aDS); - - NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); - NS_IMETHOD DrawStdLine(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 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); - - NS_IMETHOD GetTextDimensions(const PRUnichar* aString, - PRInt32 aLength, - PRInt32 aAvailWidth, - PRInt32* aBreaks, - PRInt32 aNumBreaks, - nsTextDimensions& aDimensions, - PRInt32& aNumCharsFit, - nsTextDimensions& aLastWordDimensions, - PRInt32* aFontID); - -#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 MyDrawString(QPainter *aGC,nscoord aX,nscoord aY,QString &aText); - 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 CopyOffScreenBits(nsDrawingSurface aSrcSurf, - PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, - PRUint32 aCopyFlags); - - NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 *ngd); - - //locals - NS_IMETHOD CommonInit(); - void UpdateGC(); - void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h); - void CreateClipRegion(); - -protected: - nsDrawingSurfaceQT *mOffscreenSurface; - nsDrawingSurfaceQT *mSurface; - nsIDeviceContext *mContext; - nsIFontMetrics *mFontMetrics; - nsCOMPtr mClipRegion; - float mP2T; - - // graphic state stack (GraphicsState) - nsVoidArray *mStateCache; - - nscolor mCurrentColor; - nsLineStyle mCurrentLineStyle; - - nsFontQT *mCurrentFont; - Qt::PenStyle mQLineStyle; - Qt::RasterOp mFunction; - QPainter *mGC; - QPaintDevice *mPaintDev; - PRUint32 mID; -}; - -#endif /* nsRenderingContextQT_h___ */ diff --git a/gfx/src/qt/nsScreenManagerQT.cpp b/gfx/src/qt/nsScreenManagerQT.cpp deleted file mode 100644 index 6bc89efec2b9..000000000000 --- a/gfx/src/qt/nsScreenManagerQT.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScreenManagerQT.h" -#include "nsScreenQT.h" - -#include "qtlog.h" - -#ifdef DEBUG -PRUint32 gSMCount = 0; -PRUint32 gSMID = 0; -#endif - -nsScreenManagerQT::nsScreenManagerQT() -{ -#ifdef DEBUG - gSMCount++; - mID = gSMID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsScreenManagerQT CTOR (%p) ID: %d, Count: %d\n", this, mID, gSMCount)); -#endif - - // 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. -} - - -nsScreenManagerQT::~nsScreenManagerQT() -{ -#ifdef DEBUG - gSMCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsScreenManagerQT DTOR (%p) ID: %d, Count: %d\n", this, mID, gSMCount)); -#endif - // nothing to see here. -} - -// addref, release, QI -NS_IMPL_ISUPPORTS1(nsScreenManagerQT, 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* -nsScreenManagerQT::CreateNewScreenObject() -{ - nsIScreen *retval = nsnull; - if (!mCachedMainScreen) - mCachedMainScreen = new nsScreenQT(); - 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 -nsScreenManagerQT::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 -nsScreenManagerQT::GetPrimaryScreen(nsIScreen **aPrimaryScreen) -{ - *aPrimaryScreen = CreateNewScreenObject(); // addrefs - return NS_OK; -} // GetPrimaryScreen - -// -// GetNumberOfScreens -// -// Returns how many physical screens are available. -// -NS_IMETHODIMP -nsScreenManagerQT::GetNumberOfScreens(PRUint32 *aNumberOfScreens) -{ - *aNumberOfScreens = 1; - return NS_OK; -} // GetNumberOfScreens diff --git a/gfx/src/qt/nsScreenManagerQT.h b/gfx/src/qt/nsScreenManagerQT.h deleted file mode 100644 index dea178b5623c..000000000000 --- a/gfx/src/qt/nsScreenManagerQT.h +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsScreenManagerQt_h___ -#define nsScreenManagerQt_h___ - -#include "nsIScreenManager.h" -#include "nsIScreen.h" -#include "nsCOMPtr.h" - -//------------------------------------------------------------------------ - -class nsScreenManagerQT : public nsIScreenManager -{ -public: - nsScreenManagerQT ( ); - virtual ~nsScreenManagerQT(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCREENMANAGER - -private: - - nsIScreen* CreateNewScreenObject ( ) ; - - // cache the primary screen object to avoid memory allocation every time - nsCOMPtr mCachedMainScreen; - -#ifdef DEBUG - PRUint32 mID; -#endif - -}; - -#endif // nsScreenManagerQt_h___ diff --git a/gfx/src/qt/nsScreenQT.cpp b/gfx/src/qt/nsScreenQT.cpp deleted file mode 100644 index fc00e03610a4..000000000000 --- a/gfx/src/qt/nsScreenQT.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScreenQT.h" - -#include -#include - -#include "qtlog.h" - -#ifdef DEBUG -PRUint32 gScreenCount = 0; -PRUint32 gScreenID = 0; -#endif - -nsScreenQT::nsScreenQT() -{ -#ifdef DEBUG - gScreenCount++; - mID = gScreenID++; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsScreenQT CTOR (%p) ID: %d, Count: %d\n", this, mID, gScreenCount)); -#endif - // 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. -} - -nsScreenQT::~nsScreenQT() -{ -#ifdef DEBUG - gScreenCount--; - PR_LOG(gQTLogModule, QT_BASIC, - ("nsScreenQT DTOR (%p) ID: %d, Count: %d\n", this, mID, gScreenCount)); -#endif - // nothing to see here. -} - -// addref, release, QI -NS_IMPL_ISUPPORTS1(nsScreenQT, nsIScreen) - -NS_IMETHODIMP -nsScreenQT::GetRect(PRInt32 *outLeft,PRInt32 *outTop, - PRInt32 *outWidth,PRInt32 *outHeight) -{ - *outTop = 0; - *outLeft = 0; - *outWidth = QApplication::desktop()->width(); - *outHeight = QApplication::desktop()->height(); - - return NS_OK; -} // GetRect - -NS_IMETHODIMP -nsScreenQT::GetAvailRect(PRInt32 *outLeft,PRInt32 *outTop, - PRInt32 *outWidth,PRInt32 *outHeight) -{ - *outTop = 0; - *outLeft = 0; - *outWidth = QApplication::desktop()->width(); - *outHeight = QApplication::desktop()->height(); - - return NS_OK; -} // GetAvailRect - -NS_IMETHODIMP -nsScreenQT::GetPixelDepth(PRInt32 *aPixelDepth) -{ - *aPixelDepth = (PRInt32)QColor::numBitPlanes(); - return NS_OK; -} // GetPixelDepth - -NS_IMETHODIMP -nsScreenQT::GetColorDepth(PRInt32 *aColorDepth) -{ - return GetPixelDepth(aColorDepth); -} // GetColorDepth diff --git a/gfx/src/qt/nsScreenQT.h b/gfx/src/qt/nsScreenQT.h deleted file mode 100644 index 8ae95dc868a5..000000000000 --- a/gfx/src/qt/nsScreenQT.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsScreenQT_h___ -#define nsScreenQT_h___ - -#include "nsIScreen.h" - -//------------------------------------------------------------------------ - -class nsScreenQT : public nsIScreen -{ -public: - nsScreenQT ( ); - virtual ~nsScreenQT(); - - NS_DECL_ISUPPORTS - NS_DECL_NSISCREEN - -private: -#ifdef DEBUG - PRUint32 mID; -#endif - -}; - -#endif // nsScreenQT_h___ diff --git a/gfx/src/qt/qtlog.h b/gfx/src/qt/qtlog.h deleted file mode 100644 index 191097570c46..000000000000 --- a/gfx/src/qt/qtlog.h +++ /dev/null @@ -1,49 +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 QT Port logging code. - * - * The Initial Developer of the Original Code is - * Christian Biesinger . - * Portions created by the Initial Developer are Copyright (C) 2002 - * 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 QT_LOG_H__ -#define QT_LOG_H__ - -#define FORCE_PR_LOG -#include "prlog.h" - -extern PRLogModuleInfo *gQTLogModule; - -const int QT_BASIC = 3; -const int QT_FONTS = 4; -const int QT_EXTRA_FONTS = 5; - -#endif diff --git a/modules/plugin/base/src/Makefile.in b/modules/plugin/base/src/Makefile.in index ec399ca567bf..48d7acc01e62 100644 --- a/modules/plugin/base/src/Makefile.in +++ b/modules/plugin/base/src/Makefile.in @@ -155,9 +155,3 @@ CFLAGS += $(TK_CFLAGS) endif #MOZ_MONOLITHIC_TOOLKIT endif #MOZ_ENABLE_XLIB -ifdef MOZ_ENABLE_QT -EXTRA_DSO_LDOPTS += $(MOZ_QT_LDFLAGS) -CXXFLAGS += $(MOZ_QT_CFLAGS) -CFLAGS += $(MOZ_QT_CFLAGS) -endif #MOZ_ENABLE_QT - diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index 892c248c8cce..93b35df6d795 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -41,11 +41,6 @@ #include "nscore.h" #include "nsPluginHostImpl.h" -#ifdef MOZ_WIDGET_QT -#undef CursorShape /*X.h defines it as 0, - qnamespace.h makes an enum type by that name - */ -#endif #include #include "prio.h" #include "prmem.h" @@ -171,8 +166,6 @@ #ifdef XP_UNIX #if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2) #include // for GDK_DISPLAY() -#elif defined(MOZ_WIDGET_QT) -#include // for qt_xdisplay() #elif defined(MOZ_WIDGET_XLIB) #include "xlibrgb.h" // for xlib_rgb_get_display() #endif @@ -2653,8 +2646,6 @@ NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void Display** value = NS_REINTERPRET_CAST(Display**, aValue); #if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2) *value = GDK_DISPLAY(); -#elif defined(MOZ_WIDGET_QT) - *value = qt_xdisplay(); #elif defined(MOZ_WIDGET_XLIB) *value = xxlib_rgb_get_display(xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE)); #endif diff --git a/webshell/tests/viewer/.cvsignore b/webshell/tests/viewer/.cvsignore index d1d6233e2338..ece6200a6f25 100644 --- a/webshell/tests/viewer/.cvsignore +++ b/webshell/tests/viewer/.cvsignore @@ -2,7 +2,4 @@ Makefile viewer viewer_gtk viewer_xlib -viewer_qt -viewer_motif - diff --git a/webshell/tests/viewer/Makefile.in b/webshell/tests/viewer/Makefile.in index d0dc7de8984e..89c4d74d1be8 100644 --- a/webshell/tests/viewer/Makefile.in +++ b/webshell/tests/viewer/Makefile.in @@ -155,7 +155,6 @@ LIBS = \ $(PROFILER_LIBS) \ $(NULL) -QT_LIBS = unix/qt/libviewer_qt_s.a $(XP_LIBS) $(MOZ_QT_LDFLAGS) XLIB_LIBS = unix/xlib/libviewer_xlib_s.a $(XP_LIBS) $(MOZ_XLIB_LDFLAGS) GTK_LIBS = unix/gtk/libviewer_gtk_s.a -lgtksuperwin $(XP_LIBS) $(MOZ_GTK_LDFLAGS) @@ -189,7 +188,6 @@ ifneq ($(OS_ARCH),WINNT) EXTRA_LIBS += -L$(DEPTH)/dist/lib/components endif # !WINNT EXTRA_LIBS += $(EXTRA_DSO_LIBS) $(STATIC_EXTRA_LIBS) -QT_LIBS += $(EXTRA_LIBS) XLIB_LIBS += $(EXTRA_LIBS) GTK_LIBS += $(EXTRA_LIBS) DEFINES += $(STATIC_DEFINES) @@ -216,7 +214,7 @@ ifeq ($(OS_ARCH),WINNT) DEFINES += -DUSE_LOCAL_WIDGETS endif -GARBAGE += $(PROGRAM)_gtk $(PROGRAM)_qt $(PROGRAM)_xlib +GARBAGE += $(PROGRAM)_gtk $(PROGRAM)_xlib ifeq ($(OS_ARCH),WINNT) OS_LIBS += shell32.lib ole32.lib oleaut32.lib oleacc.lib \ @@ -238,9 +236,6 @@ endif unix/gtk/libviewer_gtk_s.a: @$(MAKE) -C $(@D) $(@F) -unix/qt/libviewer_qt_s.a: - @$(MAKE) -C $(@D) $(@F) - unix/xlib/libviewer_xlib_s.a: @$(MAKE) -C $(@D) $(@F) @@ -250,12 +245,6 @@ ifdef ENABLE_STRIP $(STRIP) $@ endif -$(PROGRAM)_qt: $(PROGOBJS) $(EXTRA_DEPS) Makefile Makefile.in unix/qt/libviewer_qt_s.a - $(CCC) $(CXXFLAGS) -o $@ $(PROGOBJS) $(LDFLAGS) $(LIBS_DIR) $(QT_LIBS) $(OS_LIBS) $(PROFILER_LIBS) -ifdef ENABLE_STRIP - $(STRIP) $@ -endif - $(PROGRAM)_xlib: $(PROGOBJS) $(EXTRA_DEPS) Makefile Makefile.in unix/xlib/libviewer_xlib_s.a $(CCC) $(CXXFLAGS) -o $@ $(PROGOBJS) $(LDFLAGS) $(LIBS_DIR) $(XLIB_LIBS) $(OS_LIBS) $(PROFILER_LIBS) ifdef ENABLE_STRIP @@ -267,11 +256,6 @@ libs:: $(PROGRAM)_gtk $(INSTALL) -m 555 $< $(DIST)/bin endif -ifdef MOZ_ENABLE_QT -libs:: $(PROGRAM)_qt - $(INSTALL) -m 555 $< $(DIST)/bin -endif - ifdef MOZ_ENABLE_XLIB libs:: $(PROGRAM)_xlib $(INSTALL) -m 555 $< $(DIST)/bin diff --git a/widget/src/Makefile.in b/widget/src/Makefile.in index 910f4fbf682c..5d80969aa939 100644 --- a/widget/src/Makefile.in +++ b/widget/src/Makefile.in @@ -62,10 +62,6 @@ DIRS += xlibxtbin DIRS += xlib endif -ifdef MOZ_ENABLE_QT -DIRS += qt -endif - ifdef MOZ_ENABLE_PHOTON DIRS += photon endif diff --git a/widget/src/qt/.cvsignore b/widget/src/qt/.cvsignore deleted file mode 100644 index e02025c2849e..000000000000 --- a/widget/src/qt/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -Makefile -moc_nsQApplication.cpp -moc_nsLabel.cpp -moc_nsScrollbar.cpp -moc_nsButton.cpp -moc_nsCheckButton.cpp -moc_nsTextWidget.cpp -moc_nsTabWidget.cpp -moc_nsQEventHandler.cpp -moc_nsWindow.cpp diff --git a/widget/src/qt/Makefile.in b/widget/src/qt/Makefile.in deleted file mode 100644 index bf605fe8f550..000000000000 --- a/widget/src/qt/Makefile.in +++ /dev/null @@ -1,113 +0,0 @@ -# -# The contents of this file are subject to the Netscape 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/NPL/ -# -# 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 Netscape are -# Copyright (C) 1998 Netscape Communications Corporation. All -# Rights Reserved. -# -# Contributor(s): -# John C. Griggs -# - -DEPTH = ../../.. -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -MODULE = widget -LIBRARY_NAME = widget_qt -EXPORT_LIBRARY = 1 -IS_COMPONENT = 1 -MODULE_NAME = nsWidgetQTModule -GRE_MODULE = 1 - -REQUIRES = xpcom \ - string \ - gfx \ - layout \ - content \ - dom \ - appshell \ - pref \ - uconv \ - $(NULL) - -CPPSRCS = \ - $(MOCSRCS) \ - nsQApplication.cpp \ - nsAppShell.cpp \ - nsBidiKeyboard.cpp \ - nsScrollbar.cpp \ - nsLookAndFeel.cpp \ - nsToolkit.cpp \ - nsQWidget.cpp \ - nsWidget.cpp \ - nsWindow.cpp \ - nsDragService.cpp \ - nsClipboard.cpp \ - nsWidgetFactory.cpp \ - nsMime.cpp \ - $(NULL) - -MOCSRCS = \ - moc_nsQApplication.cpp \ - moc_nsScrollbar.cpp \ - moc_nsQWidget.cpp \ - moc_nsMime.cpp \ - $(NULL) - -SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a - -EXTRA_DSO_LDOPTS = \ - $(MOZ_COMPONENT_LIBS) \ - -lgkgfx \ - -I$(topsrcdir)/gfx/src/qt \ - $(MOZ_JS_LIBS) \ - $(NULL) - -EXTRA_DSO_LDOPTS += -L$(DIST)/lib $(MOZ_QT_LDFLAGS) $(MOZ_XLIB_LDFLAGS) - -# If not primary toolkit, install in secondary path -ifneq (qt,$(MOZ_WIDGET_TOOLKIT)) -INACTIVE_COMPONENT = 1 -endif - -include $(topsrcdir)/config/rules.mk - -CXXFLAGS += $(MOZ_QT_CFLAGS) -CFLAGS += $(MOZ_QT_CFLAGS) - -DEFINES += -D_IMPL_NS_WIDGET - -ifeq ($(OS_ARCH), Linux) -DEFINES += -D_BSD_SOURCE -endif -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 - -LOCAL_INCLUDES = -I$(srcdir)/../xpwidgets \ - -I$(srcdir) \ - -I$(topsrcdir)/gfx/src/qt \ - $(NULL) - diff --git a/widget/src/qt/nsAppShell.cpp b/widget/src/qt/nsAppShell.cpp deleted file mode 100644 index fbed3a77e053..000000000000 --- a/widget/src/qt/nsAppShell.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCOMPtr.h" -#include "nsAppShell.h" -#include "nsIServiceManager.h" -#include "nsIEventQueueService.h" -#include "nsICmdLineService.h" - -//JCG #define DBG_JCG 1 - -#ifdef DBG_JCG -PRInt32 gAppShellCount = 0; -PRInt32 gAppShellID = 0; -#endif - -//------------------------------------------------------------------------- -// -// XPCOM CIDs -// -//------------------------------------------------------------------------- -static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_IID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); - -//------------------------------------------------------------------------- -// -// nsAppShell constructor -// -//------------------------------------------------------------------------- -nsAppShell::nsAppShell() : - mDispatchListener(0), - mApplication(nsnull) -{ -#ifdef DBG_JCG - gAppShellCount++; - mID = gAppShellID++; - printf("JCG: nsAppShell CTOR (%p) ID: %d, Count: %d\n",this,mID,gAppShellCount); -#endif -} - -//------------------------------------------------------------------------- -// -// nsAppShell destructor -// -//------------------------------------------------------------------------- -nsAppShell::~nsAppShell() -{ - if (mApplication) { - mApplication->Release(); - } - mApplication = nsnull; -#ifdef DBG_JCG - gAppShellCount--; - printf("JCG: nsAppShell DTOR (%p) ID: %d, Count: %d\n",this,mID,gAppShellCount); -#endif -} - -//------------------------------------------------------------------------- -// -// nsISupports implementation macro -// -//------------------------------------------------------------------------- -NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell) - -//------------------------------------------------------------------------- -NS_METHOD -nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener) -{ - mDispatchListener = aDispatchListener; - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Create the application shell -// -//------------------------------------------------------------------------- - -NS_METHOD nsAppShell::Create(int *bac, char **bav) -{ - int argc = bac ? *bac : 0; - char **argv = bav; - nsresult rv; - - nsCOMPtr cmdLineArgs = do_GetService(kCmdLineServiceCID); - if (cmdLineArgs) { - rv = cmdLineArgs->GetArgc(&argc); - if (NS_FAILED(rv)) { - argc = bac ? *bac : 0; - } - rv = cmdLineArgs->GetArgv(&argv); - if (NS_FAILED(rv)) { - argv = bav; - } - } - mApplication = nsQApplication::Instance(argc,argv); - if (!mApplication) { - return NS_ERROR_NOT_INITIALIZED; - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Spinup - do any preparation necessary for running a message loop -// -//------------------------------------------------------------------------- -NS_METHOD nsAppShell::Spinup() -{ - nsresult rv = NS_OK; - - if (mApplication == nsnull) - return NS_ERROR_NOT_INITIALIZED; - - // Get the event queue service - nsCOMPtr eventQService = do_GetService(kEventQueueServiceCID,&rv); - if (NS_FAILED(rv)) { - NS_ASSERTION("Could not obtain event queue service",PR_FALSE); - return rv; - } - //Get the event queue for the thread. - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(mEventQueue)); - - // If a queue already present use it. - if (mEventQueue) { - goto done; - } - // Create the event queue for the thread - rv = eventQService->CreateThreadEventQueue(); - if (NS_FAILED(rv)) { - NS_ASSERTION("Could not create the thread event queue",PR_FALSE); - return rv; - } - //Get the event queue for the thread - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(mEventQueue)); - if (NS_FAILED(rv)) { - NS_ASSERTION("Could not obtain the thread event queue",PR_FALSE); - return rv; - } -done: - mApplication->AddEventProcessorCallback(mEventQueue); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Spindown - do any cleanup necessary for finishing a message loop -// -//------------------------------------------------------------------------- -NS_METHOD nsAppShell::Spindown() -{ - if (mApplication == nsnull) - return NS_ERROR_NOT_INITIALIZED; - - if (mEventQueue) { - mApplication->RemoveEventProcessorCallback(mEventQueue); - mEventQueue = nsnull; - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Run -// -//------------------------------------------------------------------------- -NS_METHOD nsAppShell::Run() -{ - if (mApplication == nsnull) - return NS_ERROR_NOT_INITIALIZED; - - if (!mEventQueue) { - Spinup(); - } - if (!mEventQueue) { - return NS_ERROR_NOT_INITIALIZED; - } - mApplication->exec(); - - Spindown(); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Exit a message handler loop -// -//------------------------------------------------------------------------- - -NS_METHOD nsAppShell::Exit() -{ - if (mApplication == nsnull) - return NS_ERROR_NOT_INITIALIZED; - - mApplication->exit(0); - return NS_OK; -} - -NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *& aEvent) -{ - aRealEvent = PR_FALSE; - aEvent = 0; - return NS_OK; -} - -NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent) -{ - if (mApplication == nsnull) - return NS_ERROR_NOT_INITIALIZED; - - mApplication->processEvents(1); - return NS_OK; -} - -NS_IMETHODIMP nsAppShell::ListenToEventQueue(nsIEventQueue *aQueue, - PRBool aListen) -{ - if (mApplication == nsnull) - return NS_ERROR_NOT_INITIALIZED; - - if (aListen) { - mApplication->AddEventProcessorCallback(aQueue); - } - else { - mApplication->RemoveEventProcessorCallback(aQueue); - } - return NS_OK; -} diff --git a/widget/src/qt/nsAppShell.h b/widget/src/qt/nsAppShell.h deleted file mode 100644 index 3a8b4f83846c..000000000000 --- a/widget/src/qt/nsAppShell.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsAppShell_h__ -#define nsAppShell_h__ - -#include "nsIAppShell.h" -#include "nsIEventQueue.h" -#include "nsQApplication.h" - -/* Native QT Application shell wrapper */ -class nsAppShell : public nsIAppShell -{ -public: - nsAppShell(); - virtual ~nsAppShell(); - - NS_DECL_ISUPPORTS - - NS_DECL_NSIAPPSHELL - -private: - nsDispatchListener *mDispatchListener; - nsCOMPtr mEventQueue; - nsQApplication *mApplication; - PRInt32 mID; -}; - -#endif // nsAppShell_h__ diff --git a/widget/src/qt/nsBidiKeyboard.cpp b/widget/src/qt/nsBidiKeyboard.cpp deleted file mode 100644 index 4d2a6626238c..000000000000 --- a/widget/src/qt/nsBidiKeyboard.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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. - * - * Contributor(s): Simon Montagu - */ - -#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_OK; -} - -NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) -{ - // XXX Insert platform specific code to set keyboard language - return NS_OK; -} diff --git a/widget/src/qt/nsBidiKeyboard.h b/widget/src/qt/nsBidiKeyboard.h deleted file mode 100644 index 107f09a4501e..000000000000 --- a/widget/src/qt/nsBidiKeyboard.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * 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. - * - * Contributor(s): Simon Montagu - */ - -#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/widget/src/qt/nsButton.cpp b/widget/src/qt/nsButton.cpp deleted file mode 100644 index de629d823f61..000000000000 --- a/widget/src/qt/nsButton.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsButton.h" -#include "nsToolkit.h" -#include "nsColor.h" -#include "nsGUIEvent.h" -#include "nsString.h" - -//============================================================================= -// -// nsQPushButton class -// -//============================================================================= -nsQPushButton::nsQPushButton(nsWidget * widget, - QWidget * parent, - const char * name) - : QPushButton(parent, name), nsQBaseWidget(widget) -{ -} - -nsQPushButton::~nsQPushButton() -{ -} - -NS_IMPL_ADDREF_INHERITED(nsButton, nsWidget) -NS_IMPL_RELEASE_INHERITED(nsButton, nsWidget) -NS_IMPL_QUERY_INTERFACE2(nsButton, nsIButton, nsIWidget) - -//------------------------------------------------------------------------- -// -// nsButton constructor -// -//------------------------------------------------------------------------- -nsButton::nsButton() : nsWidget() , nsIButton() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsButton::nsButton()\n")); -} - -//------------------------------------------------------------------------- -// -// nsButton destructor -// -//------------------------------------------------------------------------- -nsButton::~nsButton() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsButton::~nsButton()\n")); - if (mWidget) - { - delete ((QPushButton *) mWidget); - mWidget = nsnull; - } -} - -void nsButton::InitCallbacks(char * aName) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsButton::InitCallbacks()\n")); -} - -//------------------------------------------------------------------------- -// -// Set this button label -// -//------------------------------------------------------------------------- -NS_METHOD nsButton::SetLabel(const nsString& aText) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, - ("nsButton::SetLabel to %s()\n", - NS_LossyConvertUCS2toASCII(aText).get())); - - ((QPushButton *)mWidget)->setText(NS_LossyConvertUCS2toASCII(aText).get()); - - return (NS_OK); -} - -//------------------------------------------------------------------------- -// -// Get this button label -// -//------------------------------------------------------------------------- -NS_METHOD nsButton::GetLabel(nsString& aBuffer) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsButton::GetLabel()\n")); - QString string = ((QPushButton *)mWidget)->text(); - - aBuffer.SetLength(0); - aBuffer.AppendWithConversion((const char *) string); - - return (NS_OK); -} - diff --git a/widget/src/qt/nsButton.h b/widget/src/qt/nsButton.h deleted file mode 100644 index 6709bfbfb047..000000000000 --- a/widget/src/qt/nsButton.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsButton_h__ -#define nsButton_h__ - -#include "nsWidget.h" -#include "nsIButton.h" -#include - -//============================================================================= -// -// nsQPushButton class -// -//============================================================================= -class nsQPushButton : public QPushButton, public nsQBaseWidget -{ - Q_OBJECT -public: - nsQPushButton(nsWidget * widget, - QWidget * parent = 0, - const char * name = 0); - ~nsQPushButton(); - -protected: -#if 0 - bool eventFilter(QObject * object, QEvent * event); - virtual void mousePressedEvent(QMouseEvent * event); - virtual void mouseReleasedEvent(QMouseEvent * event); -#endif -}; - -/** - * Native QT button wrapper - */ -class nsButton : public nsWidget, - public nsIButton -{ - -public: - nsButton(); - virtual ~nsButton(); - - NS_DECL_ISUPPORTS_INHERITED - - // nsIButton - NS_IMETHOD SetLabel(const nsString& aText); - NS_IMETHOD GetLabel(nsString& aBuffer); - - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY) { return PR_FALSE; } - virtual PRBool OnPaint(nsPaintEvent &aEvent) { return PR_FALSE; } - virtual PRBool OnResize(nsRect &aRect) { return PR_FALSE; } - -protected: - virtual void InitCallbacks(char * aName = nsnull); -}; - -#endif // nsButton_h__ diff --git a/widget/src/qt/nsCheckButton.cpp b/widget/src/qt/nsCheckButton.cpp deleted file mode 100644 index 75492013631b..000000000000 --- a/widget/src/qt/nsCheckButton.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsCheckButton.h" -#include "nsColor.h" -#include "nsGUIEvent.h" -#include "nsString.h" - -//============================================================================= -// -// nsQCheckBox class -// -//============================================================================= -nsQCheckBox::nsQCheckBox(nsWidget * widget, - QWidget * parent, - const char * name) - : QCheckBox(parent, name), nsQBaseWidget(widget) -{ -} - -nsQCheckBox::~nsQCheckBox() -{ -} - -NS_IMPL_ADDREF_INHERITED(nsCheckButton, nsWidget) -NS_IMPL_RELEASE_INHERITED(nsCheckButton, nsWidget) -NS_IMPL_QUERY_INTERFACE2(nsCheckButton, nsICheckButton, nsIWidget) - -//------------------------------------------------------------------------- -// -// nsCheckButton constructor -// -//------------------------------------------------------------------------- -nsCheckButton::nsCheckButton() : nsWidget() , nsICheckButton() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsCheckButton::nsCheckButton()\n")); - mWidget = nsnull; -} - -//------------------------------------------------------------------------- -// -// nsCheckButton destructor -// -//------------------------------------------------------------------------- -nsCheckButton::~nsCheckButton() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsCheckButton::~nsCheckButton()\n")); - if (mWidget) - { - delete ((QCheckBox *)mWidget); - mWidget = nsnull; - } -} - -//------------------------------------------------------------------------- -// -// Set this Checkbox state -// -//------------------------------------------------------------------------- -NS_METHOD nsCheckButton::SetState(const PRBool aState) -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsCheckButton::SetState() %p:%d\n", this, aState)); - ((QCheckBox *)mWidget)->setChecked(aState); - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Get this Checkbox state -// -//------------------------------------------------------------------------- -NS_METHOD nsCheckButton::GetState(PRBool& aState) -{ - aState = ((QCheckBox *)mWidget)->isChecked(); - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsCheckButton::GetState() %p:%d\n", this, aState)); - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Set this Checkbox label -// -//------------------------------------------------------------------------- -NS_METHOD nsCheckButton::SetLabel(const nsString& aText) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsCheckButton::SetLabel()\n")); - ((QButton *)mWidget)->setText(NS_LossyConvertUCS2toASCII(aText).get()); - return (NS_OK); -} - - -//------------------------------------------------------------------------- -// -// Get this button label -// -//------------------------------------------------------------------------- -NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsCheckButton::GetLabel()\n")); - QString string = ((QButton *)mWidget)->text(); - - aBuffer.SetLength(0); - aBuffer.AppendWithConversion((const char *) string); - - return (NS_OK); -} - diff --git a/widget/src/qt/nsCheckButton.h b/widget/src/qt/nsCheckButton.h deleted file mode 100644 index 8ebd971c5359..000000000000 --- a/widget/src/qt/nsCheckButton.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsCheckButton_h__ -#define nsCheckButton_h__ - -#include "nsWidget.h" -#include "nsICheckButton.h" -#include - -//============================================================================= -// -// nsQCheckBox class -// -//============================================================================= -class nsQCheckBox : public QCheckBox, public nsQBaseWidget -{ - Q_OBJECT -public: - nsQCheckBox(nsWidget * widget, - QWidget * parent = 0, - const char * name = 0); - ~nsQCheckBox(); -}; - -/** - * Native QT Checkbox wrapper - */ - -class nsCheckButton : public nsWidget, - public nsICheckButton -{ - -public: - nsCheckButton(); - virtual ~nsCheckButton(); - - NS_DECL_ISUPPORTS_INHERITED - - // nsICheckButton - NS_IMETHOD SetLabel(const nsString &aText); - NS_IMETHOD GetLabel(nsString &aBuffer); - NS_IMETHOD SetState(const PRBool aState); - NS_IMETHOD GetState(PRBool& aState); - - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY) { return PR_FALSE; } - virtual PRBool OnPaint(nsPaintEvent & aEvent) { return PR_FALSE; } - virtual PRBool OnResize(nsRect &aRect) { return PR_FALSE; } - -protected: - QWidget *mLabel; -}; - -#endif // nsCheckButton_h__ diff --git a/widget/src/qt/nsClipboard.cpp b/widget/src/qt/nsClipboard.cpp deleted file mode 100644 index c1ab33317a25..000000000000 --- a/widget/src/qt/nsClipboard.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * Denis Issoupov - * John C. Griggs - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifdef NDEBUG -#define NO_DEBUG -#endif - -#include "nsClipboard.h" -#include "nsMime.h" -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsString.h" -#include "nsISupportsArray.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsXPIDLString.h" -#include "nsPrimitiveHelpers.h" -#include "nsIComponentManager.h" -#include "nsWidgetsCID.h" - -#include -#include -#include - -// interface definitions -static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); - -NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard); - -//------------------------------------------------------------------------- -// -// nsClipboard constructor -// -//------------------------------------------------------------------------- -nsClipboard::nsClipboard() : - mSelectionOwner (nsnull), - mGlobalOwner (nsnull), - mSelectionTransferable (nsnull), - mGlobalTransferable (nsnull), - mIgnoreEmptyNotification (PR_FALSE) -{ -} - -//------------------------------------------------------------------------- -// -// nsClipboard destructor -// -//------------------------------------------------------------------------- -nsClipboard::~nsClipboard() -{ -} - -#ifdef DEBUG_timeless -// XXX nsBaseClipboard will have an init method to allow for constructors to fail -NS_IMETHODIMP nsClipboard::Init() -{ - return NS_OK; -} -#endif - -NS_IMETHODIMP nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard) -{ - mIgnoreEmptyNotification = PR_TRUE; - - nsCOMPtr transferable(getter_AddRefs(GetTransferable(aWhichClipboard))); - - // make sure we have a good transferable - if (nsnull == transferable) { -#ifdef NS_DEBUG - printf("nsClipboard::SetNativeClipboardData(): no transferable!\n"); -#endif - 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)) { -#ifdef NS_DEBUG - printf("nsClipboard::SetNativeClipboardData(): no FlavorsTransferable !\n"); -#endif - return NS_ERROR_FAILURE; - } - QClipboard *cb = QApplication::clipboard(); - nsMimeStore* mimeStore = new nsMimeStore(); - PRUint32 cnt; - - flavorList->Count(&cnt); - 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)); - - // add these types as selection targets - PRUint32 len; - void* data; - nsCOMPtr clip; - - transferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len); - - nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr,clip,&data,len); - mimeStore->AddFlavorData(flavorStr,data,len); - } - } - cb->setData(mimeStore); - mIgnoreEmptyNotification = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsClipboard::GetNativeClipboardData(nsITransferable *aTransferable, - PRInt32 aWhichClipboard) -{ - // make sure we have a good transferable - if (nsnull == aTransferable) { -#ifdef NS_DEBUG - 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)) { -#ifdef NS_DEBUG - printf("nsClipboard::GetNativeClipboardData(): no FlavorsTransferable %i !\n", - errCode); -#endif - return NS_ERROR_FAILURE; - } - QClipboard *cb = QApplication::clipboard(); - QMimeSource *ms = cb->data(); - - // Walk through flavors and see which flavor matches the one being pasted: - PRUint32 cnt; - - flavorList->Count(&cnt); - - nsCAutoString foundFlavor; - 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)); - foundFlavor = nsCAutoString(flavorStr); - - if (ms->provides((const char*)flavorStr)) { - QByteArray ba = ms->encodedData((const char*)flavorStr); - nsCOMPtr genericDataWrapper; - PRUint32 len = (PRUint32)ba.count(); - - nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor.get(), - (void*)ba.data(),len, - getter_AddRefs(genericDataWrapper)); - aTransferable->SetTransferData(foundFlavor.get(),genericDataWrapper,len); - } - } - } - return NS_OK; -} - -NS_IMETHODIMP nsClipboard::ForceDataToClipboard(PRInt32 aWhichClipboard) -{ - // make sure we have a good transferable - nsCOMPtr transferable(getter_AddRefs(GetTransferable(aWhichClipboard))); - if (nsnull == transferable) { - return NS_ERROR_FAILURE; - } - return NS_OK; -} - -/* inline */ -nsITransferable *nsClipboard::GetTransferable(PRInt32 aWhichClipboard) -{ - nsITransferable *transferable = nsnull; - - switch (aWhichClipboard) { - case kGlobalClipboard: - transferable = mGlobalTransferable; - break; - - case kSelectionClipboard: - transferable = mSelectionTransferable; - break; - } - NS_IF_ADDREF(transferable); - return transferable; -} - -//------------------------------------------------------------------------- -NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(nsISupportsArray *aFlavorList, - PRInt32 aWhichClipboard, - PRBool *_retval) -{ - *_retval = PR_FALSE; - if (aWhichClipboard != kGlobalClipboard) - return NS_OK; - - QClipboard *cb = QApplication::clipboard(); - QMimeSource *ms = cb->data(); - PRUint32 cnt; - - aFlavorList->Count(&cnt); - for (PRUint32 i = 0;i < cnt; ++i) { - nsCOMPtr genericFlavor; - - aFlavorList->GetElementAt(i,getter_AddRefs(genericFlavor)); - - nsCOMPtr currentFlavor(do_QueryInterface(genericFlavor)); - if (currentFlavor) { - nsXPIDLCString flavorStr; - - currentFlavor->ToString(getter_Copies(flavorStr)); - -#ifdef NS_DEBUG - if (strcmp(flavorStr,kTextMime) == 0) - NS_WARNING("DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode INSTEAD"); -#endif - - if (ms->provides((const char*)flavorStr)) { - *_retval = PR_TRUE; -#ifdef NS_DEBUG - printf("GetFormat %s\n",(const char*)flavorStr); -#endif - break; - } - } - } - return NS_OK; -} - -/** - * 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; - break; - } - QApplication::clipboard()->clear(); - return SetNativeClipboardData(aWhichClipboard); -} - -/** - * Gets the transferable object - */ -NS_IMETHODIMP nsClipboard::GetData(nsITransferable *aTransferable,PRInt32 aWhichClipboard) -{ - if (nsnull != aTransferable) { - return GetNativeClipboardData(aTransferable,aWhichClipboard); -#ifdef NS_DEBUG - } else { - 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; -} diff --git a/widget/src/qt/nsClipboard.h b/widget/src/qt/nsClipboard.h deleted file mode 100644 index 888bc8b7ed3c..000000000000 --- a/widget/src/qt/nsClipboard.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * Denis Issoupov - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsClipboard_h__ -#define nsClipboard_h__ - -#include "nsIClipboard.h" -#include "nsITransferable.h" -#include "nsIClipboardOwner.h" -#include "nsCOMPtr.h" - -#include -#include -#include - -/* Native QT Clipboard wrapper */ -class nsClipboard : public nsIClipboard -{ -public: - nsClipboard(); - virtual ~nsClipboard(); - - //nsISupports - NS_DECL_ISUPPORTS - - // nsIClipboard - NS_DECL_NSICLIPBOARD - -protected: - NS_IMETHOD SetNativeClipboardData(PRInt32 aWhichClipboard); - NS_IMETHOD GetNativeClipboardData(nsITransferable *aTransferable, - PRInt32 aWhichClipboard); - - inline nsITransferable *GetTransferable(PRInt32 aWhichClipboard); - - nsCOMPtr mSelectionOwner; - nsCOMPtr mGlobalOwner; - nsCOMPtr mSelectionTransferable; - nsCOMPtr mGlobalTransferable; - - PRBool mIgnoreEmptyNotification; -}; - -#endif // nsClipboard_h__ diff --git a/widget/src/qt/nsDragService.cpp b/widget/src/qt/nsDragService.cpp deleted file mode 100644 index cb71f53e35fe..000000000000 --- a/widget/src/qt/nsDragService.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 - * Denis Issoupov - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifdef NDEBUG -#define NO_DEBUG -#endif - -#include "nsDragService.h" -#include "nsIServiceManager.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsCOMPtr.h" -#include "nsXPIDLString.h" -#include "nsPrimitiveHelpers.h" -#include "nsMime.h" -#include "nsWidgetsCID.h" -#include "nsString.h" - -static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID); -static NS_DEFINE_IID(kIDragSessionQtIID, NS_IDRAGSESSIONQT_IID); -static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID); - -NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService) -NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService) -NS_IMPL_QUERY_INTERFACE3(nsDragService, nsIDragService, nsIDragSession, nsIDragSessionQt ) - -//------------------------------------------------------------------------- -// static variables -//------------------------------------------------------------------------- -static PRBool gHaveDrag = PR_FALSE; - -//------------------------------------------------------------------------- -// -// DragService constructor -// -//------------------------------------------------------------------------- -nsDragService::nsDragService() -{ - // our hidden source widget - mHiddenWidget = new QWidget(0,QWidget::tr("DragDrop"),0); -} - -//------------------------------------------------------------------------- -// -// DragService destructor -// -//------------------------------------------------------------------------- -nsDragService::~nsDragService() -{ - delete mHiddenWidget; -} - -//--------------------------------------------------------- -NS_IMETHODIMP -nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, - nsISupportsArray *aArrayTransferables, - nsIScriptableRegion *aRegion, - PRUint32 aActionType) -{ - PRUint32 numItemsToDrag = 0; - - 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; - - mSourceDataItems->Count(&numItemsToDrag); - if (!numItemsToDrag) { - return NS_ERROR_FAILURE; - } - if (numItemsToDrag > 1) { - return NS_ERROR_FAILURE; - } - nsCOMPtr genericItem; - - mSourceDataItems->GetElementAt(0,getter_AddRefs(genericItem)); - - nsCOMPtr transferable(do_QueryInterface(genericItem)); - - mDragObject = RegisterDragFlavors(transferable); - gHaveDrag = PR_TRUE; - - if (aActionType == DRAGDROP_ACTION_MOVE) - mDragObject->dragMove(); - else - mDragObject->dragCopy(); - - gHaveDrag = PR_FALSE; - mDragObject = 0; - return NS_OK; -} - -QDragObject *nsDragService::RegisterDragFlavors(nsITransferable *transferable) -{ - nsMimeStore *pMimeStore = new nsMimeStore(); - nsCOMPtr flavorList; - - if (NS_SUCCEEDED(transferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList)))) { - PRUint32 numFlavors; - - flavorList->Count(&numFlavors); - - for (PRUint32 flavorIndex = 0; flavorIndex < numFlavors; ++flavorIndex) { - nsCOMPtr genericWrapper; - - flavorList->GetElementAt(flavorIndex,getter_AddRefs(genericWrapper)); - - nsCOMPtr currentFlavor(do_QueryInterface(genericWrapper)); - - if (currentFlavor) { - nsXPIDLCString flavorStr; - - currentFlavor->ToString(getter_Copies(flavorStr)); - - PRUint32 len; - void* data; - nsCOMPtr clip; - - transferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len); - nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr,clip,&data,len); - pMimeStore->AddFlavorData(flavorStr,data,len); - } - } // foreach flavor in item - } // if valid flavor list -#ifdef NS_DEBUG - else - printf(" DnD ERROR: cannot export any flavor\n"); -#endif - return new nsDragObject(pMimeStore,mHiddenWidget); -} // RegisterDragItemsAndFlavors - -NS_IMETHODIMP nsDragService::StartDragSession() -{ -#ifdef NS_DEBUG - printf(" DnD: StartDragSession\n"); -#endif - return nsBaseDragService::StartDragSession(); -} - -NS_IMETHODIMP nsDragService::EndDragSession() -{ -#ifdef NS_DEBUG - printf(" DnD: EndDragSession\n"); -#endif - mDragObject = 0; - return nsBaseDragService::EndDragSession(); -} - -// nsIDragSession -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) -{ - *aNumItems = 1; - return NS_OK; -} - -NS_IMETHODIMP nsDragService::GetData(nsITransferable *aTransferable, - PRUint32 aItemIndex) -{ - // make sure that we have a transferable - 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; - - // count the number of flavors - PRUint32 cnt; - - flavorList->Count(&cnt); - - // 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 (unsigned int 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 (mDragObject && mDragObject->provides(flavorStr)) { - QByteArray ba = mDragObject->encodedData((const char*)flavorStr); - nsCOMPtr genericDataWrapper; - PRUint32 len = (PRUint32)ba.count(); - - nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor.get(), - (void*)ba.data(),len, - getter_AddRefs(genericDataWrapper)); - - aTransferable->SetTransferData(foundFlavor.get(),genericDataWrapper,len); - } - } - } - return NS_OK; -} - -NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char *aDataFlavor, - PRBool *_retval) -{ - if (!_retval) - return NS_ERROR_INVALID_ARG; - - *_retval = PR_FALSE; - - if (mDragObject) - *_retval = mDragObject->provides(aDataFlavor); - -#ifdef NS_DEBUG - if (!*_retval) - printf("nsDragService::IsDataFlavorSupported not provides [%s] \n", aDataFlavor); -#endif - return NS_OK; -} - -NS_IMETHODIMP nsDragService::SetDragReference(QMimeSource* aDragRef) -{ - nsMimeStore* pMimeStore = new nsMimeStore(); - int c = 0; - const char* format; - - while ((format = aDragRef->format(c++)) != 0) { - // this is usualy between different processes - // so, we need to copy datafrom one to onother - - QByteArray ba = aDragRef->encodedData(format); - char *data = new char[ba.size()]; - memcpy(data,ba.data(),ba.size()); - pMimeStore->AddFlavorData(format,data,ba.size()); - } - mDragObject = new nsDragObject(pMimeStore,mHiddenWidget); - return NS_OK; -} diff --git a/widget/src/qt/nsDragService.h b/widget/src/qt/nsDragService.h deleted file mode 100644 index 2629e7c11e4a..000000000000 --- a/widget/src/qt/nsDragService.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * Denis Issoupov - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsDragService_h__ -#define nsDragService_h__ - -#include "nsBaseDragService.h" -#include "nsClipboard.h" -#include "nsIDragSessionQt.h" - -#include -#include - -//---------------------------------------------------------- -/* Native Qt DragService wrapper */ -class nsDragService : public nsBaseDragService, public nsIDragSessionQt -{ -public: - nsDragService(); - virtual ~nsDragService(); - - //nsISupports - NS_DECL_ISUPPORTS_INHERITED - - //nsIDragService - NS_IMETHOD InvokeDragSession(nsIDOMNode *aDOMNode, - nsISupportsArray *anArrayTransferables, - nsIScriptableRegion *aRegion, - PRUint32 aActionType); - NS_IMETHOD StartDragSession(); - NS_IMETHOD EndDragSession(); - - // 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); - - // nsIDragSessionQt - NS_IMETHOD SetDragReference(QMimeSource* aDragRef); - -protected: - QDragObject *RegisterDragFlavors(nsITransferable* transferable); - -private: - // the source of our drags - QWidget *mHiddenWidget; - QDragObject *mDragObject; - - // our source data items - nsCOMPtr mSourceDataItems; -}; - -#endif // nsDragService_h__ diff --git a/widget/src/qt/nsIDragSessionQt.h b/widget/src/qt/nsIDragSessionQt.h deleted file mode 100644 index 021f5ef6f80d..000000000000 --- a/widget/src/qt/nsIDragSessionQt.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * Denis Issoupov - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsIDragSessionQt_h__ -#define nsIDragSessionQt_h__ - -#include "nsISupports.h" -#include - -#define NS_IDRAGSESSIONQT_IID \ -{ 0x36c4c381, 0x09e3, 0x11d4, { 0xb0, 0x33, 0xa4, 0x20, 0xf4, 0x2c, 0xfd, 0x7c } }; - -class nsIDragSessionQt : public nsISupports -{ - public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDRAGSESSIONQT_IID) - - /** - * Since the drag may originate in an external application, we need some - * way of communicating the QDragObject to the session so it can use it - * when filling in data requests. - * - */ - NS_IMETHOD SetDragReference(QMimeSource* aDragRef) = 0; -}; - -#endif diff --git a/widget/src/qt/nsLabel.cpp b/widget/src/qt/nsLabel.cpp deleted file mode 100644 index 71b7959c1cb2..000000000000 --- a/widget/src/qt/nsLabel.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsLabel.h" -#include "nsToolkit.h" -#include "nsColor.h" -#include "nsGUIEvent.h" -#include "nsString.h" - - -//============================================================================= -// -// nsQLabel class -// -//============================================================================= -nsQLabel::nsQLabel(nsWidget * widget, - QWidget * parent, - const char * name, WFlags f) - : QLabel(parent, name, f), nsQBaseWidget(widget) -{ -} - -nsQLabel::~nsQLabel() -{ -} - -NS_IMPL_ADDREF_INHERITED(nsLabel,nsWidget) -NS_IMPL_RELEASE_INHERITED(nsLabel,nsWidget) -NS_IMPL_QUERY_INTERFACE2(nsLabel, nsILabel, nsIWidget) - -//------------------------------------------------------------------------- -// -// nsLabel constructor -// -//------------------------------------------------------------------------- -nsLabel::nsLabel() : nsWidget(), nsILabel() -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::nsLabel()\n")); - mAlignment = eAlign_Left; -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -NS_METHOD nsLabel::PreCreateWidget(nsWidgetInitData *aInitData) -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::PreCreateWidget()\n")); - if (nsnull != aInitData) - { - nsLabelInitData* data = (nsLabelInitData *) aInitData; - mAlignment = data->mAlignment; - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Set alignment -// -//------------------------------------------------------------------------- -NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment) -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::SetAlignment()\n")); - mAlignment = aAlignment; - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// nsLabel destructor -// -//------------------------------------------------------------------------- -nsLabel::~nsLabel() -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::~nsLabel()\n")); -} - -//------------------------------------------------------------------------- -// -// -// -//------------------------------------------------------------------------- -int nsLabel::GetNativeAlignment() -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::GetNativeAlignment()\n")); - int alignment = QLabel::AlignVCenter; - - switch (mAlignment) - { - case eAlign_Right: - alignment |= QLabel::AlignRight; - break; - case eAlign_Left: - alignment |= QLabel::AlignLeft; - break; - case eAlign_Center: - alignment |= QLabel::AlignCenter; - break; - default: - alignment |= QLabel::AlignCenter; - break; - } - - return alignment; -} - -//------------------------------------------------------------------------- -// -// Set this button label -// -//------------------------------------------------------------------------- -NS_METHOD nsLabel::SetLabel(const nsString& aText) -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::SetLabel()\n")); - ((QLabel *)mWidget)->setText(NS_LossyConvertUCS2toASCII(aText).get()); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Get this button label -// -//------------------------------------------------------------------------- -NS_METHOD nsLabel::GetLabel(nsString& aBuffer) -{ - PR_LOG(QtWidgetsLM, - PR_LOG_DEBUG, - ("nsLabel::GetLabel()\n")); - QString string = ((QLabel *)mWidget)->text(); - - aBuffer.SetLength(0); - aBuffer.AppendWithConversion((const char *)string); - - return NS_OK; -} diff --git a/widget/src/qt/nsLabel.h b/widget/src/qt/nsLabel.h deleted file mode 100644 index 8773b3d27ec2..000000000000 --- a/widget/src/qt/nsLabel.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsLabel_h__ -#define nsLabel_h__ - -#include "nsWidget.h" -#include "nsIAppShell.h" -#include "nsILabel.h" -#include - -//============================================================================= -// -// nsQLabel class -// -//============================================================================= -class nsQLabel : public QLabel, public nsQBaseWidget -{ - Q_OBJECT -public: - nsQLabel(nsWidget * widget, - QWidget * parent = 0, - const char * name = 0, - WFlags f = 0); - ~nsQLabel(); -}; - -/** - * Native QT Label wrapper - */ -class nsLabel : public nsWidget, - public nsILabel -{ - -public: - - nsLabel(); - virtual ~nsLabel(); - - NS_DECL_ISUPPORTS_INHERITED - - // nsILabel part - NS_IMETHOD SetLabel(const nsString &aText); - NS_IMETHOD GetLabel(nsString &aBuffer); - NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment); - - NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); - - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY) { return PR_FALSE; } - virtual PRBool OnPaint(nsPaintEvent & aEvent) { return PR_FALSE; } - virtual PRBool OnResize(nsRect &aRect) { return PR_FALSE; } - -protected: - int GetNativeAlignment(); - nsLabelAlignment mAlignment; -}; - -#endif // nsLabel_h__ diff --git a/widget/src/qt/nsLookAndFeel.cpp b/widget/src/qt/nsLookAndFeel.cpp deleted file mode 100644 index da7e3231382b..000000000000 --- a/widget/src/qt/nsLookAndFeel.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#include "nsLookAndFeel.h" -#include "nsQApplication.h" - -#include - -#define QCOLOR_TO_NS_RGB(c) \ - ((nscolor)NS_RGB(c.red(),c.green(),c.blue())) - -//------------------------------------------------------------------------- -// -// Query interface implementation -// -//------------------------------------------------------------------------- -nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() -{ -} - -nsLookAndFeel::~nsLookAndFeel() -{ -} - -nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID,nscolor &aColor) -{ - nsresult res = NS_OK; - - if (!qApp) - return NS_ERROR_FAILURE; - - QPalette palette = qApp->palette(); - QColorGroup normalGroup = palette.inactive(); - QColorGroup activeGroup = palette.active(); - QColorGroup disabledGroup = palette.disabled(); - - switch (aID) { - case eColor_WindowBackground: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_WindowForeground: - aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground()); - break; - - case eColor_WidgetBackground: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_WidgetForeground: - aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground()); - break; - - case eColor_WidgetSelectBackground: - aColor = QCOLOR_TO_NS_RGB(activeGroup.background()); - break; - - case eColor_WidgetSelectForeground: - aColor = QCOLOR_TO_NS_RGB(activeGroup.foreground()); - 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 = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_TextForeground: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor_TextSelectBackground: - aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight()); - break; - - case eColor_TextSelectForeground: - aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText()); - break; - - case eColor_activeborder: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_activecaption: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_appworkspace: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_background: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_captiontext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor_graytext: - aColor = QCOLOR_TO_NS_RGB(disabledGroup.text()); - break; - - case eColor_highlight: - aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight()); - break; - - case eColor_highlighttext: - aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText()); - break; - - case eColor_inactiveborder: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_inactivecaption: - aColor = QCOLOR_TO_NS_RGB(disabledGroup.background()); - break; - - case eColor_inactivecaptiontext: - aColor = QCOLOR_TO_NS_RGB(disabledGroup.text()); - break; - - case eColor_infobackground: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_infotext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor_menu: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_menutext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor_scrollbar: - aColor = QCOLOR_TO_NS_RGB(activeGroup.background()); - break; - - case eColor_threedface: - case eColor_buttonface: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_buttonhighlight: - case eColor_threedhighlight: - aColor = QCOLOR_TO_NS_RGB(normalGroup.light()); - break; - - case eColor_buttontext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor_buttonshadow: - case eColor_threedshadow: - aColor = QCOLOR_TO_NS_RGB(normalGroup.shadow()); - break; - - case eColor_threeddarkshadow: - aColor = QCOLOR_TO_NS_RGB(normalGroup.dark()); - break; - - case eColor_threedlightshadow: - aColor = QCOLOR_TO_NS_RGB(normalGroup.light()); - break; - - case eColor_window: - case eColor_windowframe: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor_windowtext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - 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 = QCOLOR_TO_NS_RGB(normalGroup.base()); - break; - - case eColor__moz_fieldtext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor__moz_dialog: - aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); - break; - - case eColor__moz_dialogtext: - aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); - break; - - case eColor__moz_dragtargetzone: - aColor = QCOLOR_TO_NS_RGB(activeGroup.background()); - break; - - default: - aColor = 0; - res = NS_ERROR_FAILURE; - break; - } - return res; -} - -NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric) -{ - nsresult 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: - // There was once code in nsDeviceContextQT::GetSystemAttribute to - // use the border width obtained from a widget in its Init method. - break; - - case eMetric_WindowBorderHeight: - // There was once code in nsDeviceContextQT::GetSystemAttribute to - // use the border width obtained from a widget in its Init method. - break; - - case eMetric_Widget3DBorder: - aMetric = 4; - break; - - case eMetric_TextFieldHeight: - aMetric = 15; - 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_SingleLineCaretWidth: - case eMetric_MultiLineCaretWidth: - 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_DragFullWindow: - aMetric = 1; - break; - - case eMetric_ScrollArrowStyle: - aMetric = eMetric_ScrollArrowStyleSingle; - break; - - case eMetric_ScrollSliderStyle: - aMetric = eMetric_ScrollThumbStyleProportional; - break; - - default: - aMetric = 0; - res = NS_ERROR_FAILURE; - } - return res; -} - -NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, - float &aMetric) -{ - 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; // 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; - - default: - aMetric = -1.0; - res = NS_ERROR_FAILURE; - } - return res; -} diff --git a/widget/src/qt/nsLookAndFeel.h b/widget/src/qt/nsLookAndFeel.h deleted file mode 100644 index e82239db2bfb..000000000000 --- a/widget/src/qt/nsLookAndFeel.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, 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/widget/src/qt/nsMime.cpp b/widget/src/qt/nsMime.cpp deleted file mode 100644 index 86547b03273f..000000000000 --- a/widget/src/qt/nsMime.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * Denis Issoupov - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsDragService.h" -#include "nsIServiceManager.h" -#include "nsWidget.h" -#include "nsXPCOM.h" -#include "nsISupportsPrimitives.h" -#include "nsXPIDLString.h" -#include "nsPrimitiveHelpers.h" -#include "nsReadableUtils.h" -#include "nsClipboard.h" -#include "nsMime.h" -#include "nsCRT.h" - -#include -#include - -//---------------------------------------------------------- -nsMimeStoreData::nsMimeStoreData(QCString& name, QByteArray& data) -{ - flavorName = name; - flavorData = data; -} - -nsMimeStoreData::nsMimeStoreData(const char* name,void* rawdata,PRInt32 rawlen) -{ - flavorName = name; - flavorData.assign((char*)rawdata,(unsigned int)rawlen); -} - -//---------------------------------------------------------- -nsMimeStore::nsMimeStore() -{ - mMimeStore.setAutoDelete(TRUE); -} - -nsMimeStore::~nsMimeStore() -{ -} - -const char* nsMimeStore::format(int n) const -{ - if (n >= (int)mMimeStore.count()) - return 0; - - // because of const - QList *pMimeStore = (QList*)&mMimeStore; - - nsMimeStoreData* msd; - msd = pMimeStore->at((unsigned int)n); - return msd->flavorName; -} - -QByteArray nsMimeStore::encodedData(const char* name) const -{ - QByteArray qba; - - // because of const - QList *pMimeStore = (QList*)&mMimeStore; - - nsMimeStoreData* msd; - for (msd = pMimeStore->first(); msd != 0; msd = pMimeStore->next()) { - if (strcmp(name, msd->flavorName) == 0) { - qba = msd->flavorData; - return qba; - } - } -#ifdef NS_DEBUG - printf("nsMimeStore::encodedData requested unknown %s\n", name); -#endif - return qba; -} - -PRBool nsMimeStore::ContainsFlavor(const char* name) -{ - for (nsMimeStoreData *msd = mMimeStore.first(); msd; msd = mMimeStore.next()) { - if (!strcmp(name, msd->flavorName)) - return PR_TRUE; - } - return PR_FALSE; -} - -PRBool nsMimeStore::AddFlavorData(const char* name, void* data, PRInt32 len) -{ - if (ContainsFlavor(name)) - return PR_FALSE; - mMimeStore.append(new nsMimeStoreData(name, data, len)); - - // we're done unless we're given text/unicode, - // and text/plain is not already advertised, - if (strcmp(name, kUnicodeMime) || ContainsFlavor(kTextMime)) - return PR_TRUE; - // in which case we also advertise text/plain - // which we will convert on our own in nsDataObj::GetText(). - - char *as = ToNewCString(nsDependentString((PRUnichar*)data)); - - // let's text/plain be first for stupid programs - // Ownership of |as| is transfered to mMimeStore - mMimeStore.insert(0,new nsMimeStoreData(kTextMime,as,nsCRT::strlen(as) + 1)); - return PR_TRUE; -} - -//---------------------------------------------------------- -nsDragObject::nsDragObject(nsMimeStore* mimeStore,QWidget* dragSource, - const char* name) - : QDragObject(dragSource, name) -{ - if (!mimeStore) - NS_ASSERTION(PR_TRUE, "Invalid pointer."); - - mMimeStore = mimeStore; -} - -nsDragObject::~nsDragObject() -{ - delete mMimeStore; -} - -const char* nsDragObject::format(int i) const -{ - if (i >= (int)mMimeStore->count()) - return 0; - - const char* frm = mMimeStore->format(i); -#ifdef NS_DEBUG - printf("nsDragObject::format i=%i %s\n",i, frm); -#endif - return frm; -} - -QByteArray nsDragObject::encodedData(const char* frm) const -{ -#ifdef NS_DEBUG - printf("nsDragObject::encodedData %s\n",frm); -#endif - return mMimeStore->encodedData(frm); -} diff --git a/widget/src/qt/nsMime.h b/widget/src/qt/nsMime.h deleted file mode 100644 index 5eb5cfd10a58..000000000000 --- a/widget/src/qt/nsMime.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * Denis Issoupov - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsMime_h__ -#define nsMime_h__ - -#include "nsITransferable.h" -#include "nsCOMPtr.h" - -#include -#include -#include -#include -#include - -class nsMimeStoreData -{ -public: - nsMimeStoreData(QCString& name, QByteArray& data); - nsMimeStoreData(const char* name, void* rawdata, PRInt32 rawlen); - - QCString flavorName; - QByteArray flavorData; -}; - -class nsMimeStore: public QMimeSource -{ -public: - nsMimeStore(); - virtual ~nsMimeStore(); - - virtual const char* format(int n = 0) const ; - virtual QByteArray encodedData(const char*) const; - - PRBool AddFlavorData(const char* name, void* data, PRInt32 len); - PRBool ContainsFlavor(const char* name); - PRUint32 count(); - -protected: - QList mMimeStore; - nsMimeStoreData* at(int n); -}; - -inline PRUint32 nsMimeStore::count() { return mMimeStore.count(); } - -//---------------------------------------------------------- -class nsDragObject : public QDragObject -{ - Q_OBJECT -public: - nsDragObject(nsMimeStore* mimeStore,QWidget* dragSource = 0, - const char* name = 0); - ~nsDragObject(); - - const char* format(int i) const; - virtual QByteArray encodedData(const char*) const; - -protected: - nsMimeStore* mMimeStore; -}; - -#endif diff --git a/widget/src/qt/nsQApplication.cpp b/widget/src/qt/nsQApplication.cpp deleted file mode 100644 index a200e5897ec4..000000000000 --- a/widget/src/qt/nsQApplication.cpp +++ /dev/null @@ -1,443 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -//JCG #define DBG_JCG 1 - -#include "nsQApplication.h" -#include "nsQWidget.h" - -#if QT_VERSION >= 300 -#include -#else -#include -#endif -#include - -#ifdef DBG_JCG -/* Required for x11EventFilter & _x_error debugging hooks */ -#include -#include - -PRInt32 gQAppID = 0; -PRInt32 gQAppCount = 0; - -PRInt32 gQQueueID = 0; -PRInt32 gQQueueCount = 0; -#endif - -nsQApplication *nsQApplication::mInstance = nsnull; -QIntDict nsQApplication::mQueueDict; -PRUint32 nsQApplication::mRefCnt = 0; -QWidget *nsQApplication::mMasterWidget = nsnull; - -#ifdef DBG_JCG -int _x_error(Display *display, XErrorEvent *error) -{ - if (error->error_code) { - char buf[64]; - - XGetErrorText (display, error->error_code, buf, 63); - - fprintf(stderr, - "X-ERROR **: %s\n serial %ld error_code %d request_code %d minor_code %d, resourceId: %ld\n", - buf, error->serial, error->error_code, error->request_code, - error->minor_code,error->resourceid); - - printf("X-ERROR **: %s\n serial %ld error_code %d request_code %d minor_code %d, resourceId: %ld\n", - buf, error->serial, error->error_code, error->request_code, - error->minor_code,error->resourceid); - - assert(0); - } - return 0; -} -#endif //DBG_JCG - -nsQApplication* nsQApplication::Instance(int argc,char** argv) -{ - printf("Enter nsQApplication::Instance\n"); - if (!mInstance) - mInstance = new nsQApplication(argc,argv); - - mRefCnt++; - - printf("Exit nsQApplication::Instance\n"); - return mInstance; -} - -void nsQApplication::Release() -{ - printf("Enter nsQApplication::Release\n"); - mRefCnt--; - if (mRefCnt <= 0) { - if (mMasterWidget) { - delete mMasterWidget; - mMasterWidget = nsnull; - } - delete mInstance; - mInstance = nsnull; - } - printf("Exit nsQApplication::Release\n"); -} - -QWidget *nsQApplication::GetMasterWidget() -{ - printf("Enter nsQApplication::GetMasterWidget\n"); - if (!mMasterWidget) - mMasterWidget = new QWidget(); - - printf("Exit nsQApplication::GetMasterWidget\n"); - return mMasterWidget; -} - -nsQApplication::nsQApplication(int argc,char** argv) - : QApplication(argc,argv) -{ - printf("Enter: QApplication::QApplication\n"); -#ifdef DBG_JCG - gQAppCount++; - mID = gQAppID++; - printf("JCG nsQApplication CTOR (%p) ID: %d, Count: %d\n",this,mID,gQAppCount); - - XSetErrorHandler (_x_error); -#endif - NS_ASSERTION(!mInstance, "Attempt to create duplicate QApplication Object."); - mInstance = this; - setGlobalMouseTracking(true); -#if QT_VERSION >= 300 - setStyle(QStyleFactory::create("windows")); -#else - //XXX this line seems to have linking problems w/ debian - // this code should eventually be changed anyway for nsITheme reasons - setStyle(new QWindowsStyle()); -#endif - setOverrideCursor(QCursor(ArrowCursor),PR_TRUE); - connect(this,SIGNAL(lastWindowClosed()),this,SLOT(quit())); - printf("Exit: QApplication::QApplication\n"); -} - -nsQApplication::~nsQApplication() -{ - printf("Enter: QApplication::~QApplication\n"); -#ifdef DBG_JCG - gQAppCount--; - printf("JCG nsQApplication DTOR (%p) ID: %d, Count: %d\n",this,mID,gQAppCount); -#endif - setGlobalMouseTracking(false); - printf("Exit: QApplication::~QApplication\n"); -} - -void nsQApplication::AddEventProcessorCallback(nsIEventQueue* EQueue) -{ - nsQtEventQueue* que = nsnull; - - if ((que = mQueueDict.find(EQueue->GetEventQueueSelectFD()))) { - que->IncRefCnt(); - } - else { - mQueueDict.insert(EQueue->GetEventQueueSelectFD(), - new nsQtEventQueue(EQueue)); - } -} - -void nsQApplication::RemoveEventProcessorCallback(nsIEventQueue* EQueue) -{ - nsQtEventQueue* que = nsnull; - - if ((que = mQueueDict.find(EQueue->GetEventQueueSelectFD()))) { - que->DataReceived(); - if (que->DecRefCnt() <= 0) { - mQueueDict.take(EQueue->GetEventQueueSelectFD()); - delete que; - } - } -} - -/* Hook for capturing X11 Events before they are processed by Qt */ -bool nsQApplication::x11EventFilter(XEvent* event) -{ -#ifdef DBG_JCG - switch (event->type) { - case ButtonPress: - case ButtonRelease: - { - XButtonPressedEvent *ptr = (XButtonPressedEvent*)event; - printf("JCG: ButtonPress/Release: serial %ld, Window: %ld, Root: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow); - } - break; - - case CirculateNotify: - { - XCirculateEvent *ptr = (XCirculateEvent*)event; - printf("JCG: CirculateNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window); - } - break; - - case CirculateRequest: - { - XCirculateRequestEvent *ptr = (XCirculateRequestEvent*)event; - printf("JCG: CirculateRequest: serial %ld, Parent: %ld, Window: %ld\n",ptr->serial,ptr->parent,ptr->window); - } - break; - - case ClientMessage: - { - XClientMessageEvent *ptr = (XClientMessageEvent*)event; - printf("JCG: ClientMessage: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case ColormapNotify: - { - XColormapEvent *ptr = (XColormapEvent*)event; - printf("JCG: ColormapNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case ConfigureNotify: - { - XConfigureEvent *ptr = (XConfigureEvent*)event; - printf("JCG: ConfigureNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window); - } - break; - - case ConfigureRequest: - { - XConfigureRequestEvent *ptr = (XConfigureRequestEvent*)event; - printf("JCG: ConfigureRequest: serial %ld, Parent: %ld, Window: %ld\n",ptr->serial,ptr->parent,ptr->window); - } - break; - - case CreateNotify: - { - XCreateWindowEvent *ptr = (XCreateWindowEvent*)event; - printf("JCG: CreateNotify: serial %ld, Parent: %ld, Window: %ld\n",ptr->serial,ptr->parent,ptr->window); - } - break; - - case DestroyNotify: - { - XDestroyWindowEvent *ptr = (XDestroyWindowEvent*)event; - printf("JCG: DestroyNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window); - } - break; - - case EnterNotify: - case LeaveNotify: - { - XCrossingEvent *ptr = (XCrossingEvent*)event; - printf("JCG: Enter/LeaveNotify: serial %ld, Window: %ld, Parent: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow); - } - break; - - case Expose: - { - XExposeEvent *ptr = (XExposeEvent*)event; - printf("JCG: Expose: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case FocusIn: - case FocusOut: - { - XFocusChangeEvent *ptr = (XFocusChangeEvent*)event; - printf("JCG: FocusIn/Out: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case GraphicsExpose: - case NoExpose: - { - printf("JCG: Graphics/NoExpose\n"); - } - break; - - case GravityNotify: - { - XGravityEvent *ptr = (XGravityEvent*)event; - printf("JCG: GravityNotify: serial %ld, Event: %ld, Window: %ld\n",ptr->serial,ptr->event,ptr->window); - } - break; - - case KeymapNotify: - { - XKeymapEvent *ptr = (XKeymapEvent*)event; - printf("JCG: KeymapNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case KeyPress: - case KeyRelease: - { - XKeyEvent *ptr = (XKeyEvent*)event; - printf("JCG: KeyPress/Release: serial %ld, Window: %ld, Parent: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow); - } - break; - - case MapNotify: - case UnmapNotify: - { - XMapEvent *ptr = (XMapEvent*)event; - printf("JCG: Map/UnmapNotify: serial %ld, Window: %ld, Event: %ld\n",ptr->serial,ptr->window,ptr->event); - } - break; - - case MappingNotify: - { - XMappingEvent *ptr = (XMappingEvent*)event; - printf("JCG: MappingNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case MapRequest: - { - XMapRequestEvent *ptr = (XMapRequestEvent*)event; - printf("JCG: MapRequest: serial %ld, Window: %ld, Parent: %ld\n",ptr->serial,ptr->window,ptr->parent); - } - break; - - case MotionNotify: - { - XMotionEvent *ptr = (XMotionEvent*)event; - printf("JCG: MotionNotify: serial %ld, Window: %ld, Parent: %ld, Child: %ld\n",ptr->serial,ptr->window,ptr->root,ptr->subwindow); - } - break; - - case PropertyNotify: - { - XPropertyEvent *ptr = (XPropertyEvent*)event; - printf("JCG: PropertyNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case ReparentNotify: - { - XReparentEvent *ptr = (XReparentEvent*)event; - printf("JCG: ReparentNotify: serial %ld, Window: %ld, Parent: %ld, Event: %ld\n",ptr->serial,ptr->window,ptr->parent,ptr->event); - } - break; - - case ResizeRequest: - { - XResizeRequestEvent *ptr = (XResizeRequestEvent*)event; - printf("JCG: ResizeRequest: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case SelectionClear: - { - XSelectionClearEvent *ptr = (XSelectionClearEvent*)event; - printf("JCG: SelectionClear: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - case SelectionNotify: - { - XSelectionEvent *ptr = (XSelectionEvent*)event; - printf("JCG: SelectionNotify: serial %ld, Requestor: %ld\n",ptr->serial,ptr->requestor); - } - break; - - case SelectionRequest: - { - XSelectionRequestEvent *ptr = (XSelectionRequestEvent*)event; - printf("JCG: SelectionRequest: serial %ld, Owner: %ld, Requestor: %ld\n",ptr->serial,ptr->owner,ptr->requestor); - } - break; - - case VisibilityNotify: - { - XVisibilityEvent *ptr = (XVisibilityEvent*)event; - printf("JCG: VisibilityNotify: serial %ld, Window: %ld\n",ptr->serial,ptr->window); - } - break; - - default: - { - printf("JCG: Unknown Event: %d\n",event->type); - } - break; - } -#endif //DBG_JCG - return FALSE; -} - -nsQtEventQueue::nsQtEventQueue(nsIEventQueue* EQueue) -{ -#ifdef DBG_JCG - mID = gQQueueID++; - gQQueueCount++; - printf("JCG nsQtEventQueue CTOR (%p) ID: %d, Count: %d\n",this,mID,gQQueueCount); -#endif - mQSocket = nsnull; - mEventQueue = EQueue; - NS_IF_ADDREF(mEventQueue); - mRefCnt = 1; - - mQSocket = new QSocketNotifier(mEventQueue->GetEventQueueSelectFD(), - QSocketNotifier::Read,this); - if (mQSocket) - connect(mQSocket,SIGNAL(activated(int)),this,SLOT(DataReceived())); -} - -nsQtEventQueue::~nsQtEventQueue() -{ -#ifdef DBG_JCG - gQQueueCount--; - printf("JCG nsQtEventQueue DTOR (%p) ID: %d, Count: %d\n",this,mID,gQQueueCount); -#endif - if (mQSocket) - delete mQSocket; - NS_IF_RELEASE(mEventQueue); -} - -unsigned long nsQtEventQueue::IncRefCnt() -{ - return ++mRefCnt; -} - -unsigned long nsQtEventQueue::DecRefCnt() -{ - return --mRefCnt; -} - -void nsQtEventQueue::DataReceived() -{ - if (mEventQueue) - mEventQueue->ProcessPendingEvents(); -} diff --git a/widget/src/qt/nsQApplication.h b/widget/src/qt/nsQApplication.h deleted file mode 100644 index d10ae01e8830..000000000000 --- a/widget/src/qt/nsQApplication.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsQApplication_h__ -#define nsQApplication_h__ - -#include "nsIEventQueue.h" -#include -#include -#include - -class nsQtEventQueue : public QObject -{ - Q_OBJECT -public: - nsQtEventQueue(nsIEventQueue *EQueue); - ~nsQtEventQueue(); - unsigned long IncRefCnt(); - unsigned long DecRefCnt(); - -public slots: - void DataReceived(); - -private: - nsIEventQueue *mEventQueue; - QSocketNotifier *mQSocket; - PRUint32 mRefCnt; - PRInt32 mID; -}; - -class nsQApplication : public QApplication -{ - Q_OBJECT -public: - static nsQApplication *Instance(int argc,char **argv); - - static void Release(); - - static void AddEventProcessorCallback(nsIEventQueue *EQueue); - static void RemoveEventProcessorCallback(nsIEventQueue *EQueue); - - static QWidget *GetMasterWidget(); - - ///Hook for debugging X11 Events - bool x11EventFilter(XEvent *event); - -protected: - nsQApplication(int argc,char **argv); - ~nsQApplication(); - -private: - PRInt32 mID; - static QIntDict mQueueDict; - static nsQApplication *mInstance; - static PRUint32 mRefCnt; - static QWidget *mMasterWidget; -}; - -#endif // nsQApplication_h__ diff --git a/widget/src/qt/nsQEventHandler.cpp b/widget/src/qt/nsQEventHandler.cpp deleted file mode 100644 index 8b6de7ac84e1..000000000000 --- a/widget/src/qt/nsQEventHandler.cpp +++ /dev/null @@ -1,806 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsWidget.h" -#include "nsWindow.h" -#include "nsGUIEvent.h" -#include "nsQEventHandler.h" - -//JCG #define DBG_JCG 1 -#ifdef DBG_JCG -PRUint32 gQEventHandlerCount = 0; -#endif - -static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID); -static NS_DEFINE_IID(kCChild, NS_CHILD_CID); - -#if 0 //JCG -struct nsKeyConverter -{ - int vkCode; // Platform independent key code - int keysym; // QT key code -}; - -struct nsKeyConverter nsKeycodes[] = -{ -// { NS_VK_CANCEL, Qt::Key_Cancel }, - { NS_VK_BACK, Qt::Key_BackSpace }, - { NS_VK_TAB, Qt::Key_Tab }, -// { NS_VK_CLEAR, Qt::Key_Clear }, - { NS_VK_RETURN, Qt::Key_Return }, - { NS_VK_RETURN, Qt::Key_Enter }, - { NS_VK_SHIFT, Qt::Key_Shift }, - { NS_VK_CONTROL, Qt::Key_Control }, - { NS_VK_ALT, Qt::Key_Alt }, - { NS_VK_ALT, Qt::Key_Meta }, - { NS_VK_PAUSE, Qt::Key_Pause }, - { NS_VK_CAPS_LOCK, Qt::Key_CapsLock }, - { NS_VK_ESCAPE, Qt::Key_Escape }, - { NS_VK_SPACE, Qt::Key_Space }, - { NS_VK_PAGE_UP, Qt::Key_PageUp }, - { NS_VK_PAGE_DOWN, Qt::Key_PageDown }, - { NS_VK_END, Qt::Key_End }, - { NS_VK_HOME, Qt::Key_Home }, - { NS_VK_LEFT, Qt::Key_Left }, - { NS_VK_UP, Qt::Key_Up }, - { NS_VK_RIGHT, Qt::Key_Right }, - { NS_VK_DOWN, Qt::Key_Down }, - { NS_VK_PRINTSCREEN, Qt::Key_Print }, - { NS_VK_INSERT, Qt::Key_Insert }, - { NS_VK_DELETE, Qt::Key_Delete }, - - { NS_VK_0, Qt::Key_0 }, - { NS_VK_1, Qt::Key_1 }, - { NS_VK_2, Qt::Key_2 }, - { NS_VK_3, Qt::Key_3 }, - { NS_VK_4, Qt::Key_4 }, - { NS_VK_5, Qt::Key_5 }, - { NS_VK_6, Qt::Key_6 }, - { NS_VK_7, Qt::Key_7 }, - { NS_VK_8, Qt::Key_8 }, - { NS_VK_9, Qt::Key_9 }, - - { NS_VK_SEMICOLON, Qt::Key_Semicolon }, - { NS_VK_EQUALS, Qt::Key_Equal }, - - { NS_VK_A, Qt::Key_A }, - { NS_VK_B, Qt::Key_B }, - { NS_VK_C, Qt::Key_C }, - { NS_VK_D, Qt::Key_D }, - { NS_VK_E, Qt::Key_E }, - { NS_VK_F, Qt::Key_F }, - { NS_VK_G, Qt::Key_G }, - { NS_VK_H, Qt::Key_H }, - { NS_VK_I, Qt::Key_I }, - { NS_VK_J, Qt::Key_J }, - { NS_VK_K, Qt::Key_K }, - { NS_VK_L, Qt::Key_L }, - { NS_VK_M, Qt::Key_M }, - { NS_VK_N, Qt::Key_N }, - { NS_VK_O, Qt::Key_O }, - { NS_VK_P, Qt::Key_P }, - { NS_VK_Q, Qt::Key_Q }, - { NS_VK_R, Qt::Key_R }, - { NS_VK_S, Qt::Key_S }, - { NS_VK_T, Qt::Key_T }, - { NS_VK_U, Qt::Key_U }, - { NS_VK_V, Qt::Key_V }, - { NS_VK_W, Qt::Key_W }, - { NS_VK_X, Qt::Key_X }, - { NS_VK_Y, Qt::Key_Y }, - { NS_VK_Z, Qt::Key_Z }, - - { NS_VK_NUMPAD0, Qt::Key_0 }, - { NS_VK_NUMPAD1, Qt::Key_1 }, - { NS_VK_NUMPAD2, Qt::Key_2 }, - { NS_VK_NUMPAD3, Qt::Key_3 }, - { NS_VK_NUMPAD4, Qt::Key_4 }, - { NS_VK_NUMPAD5, Qt::Key_5 }, - { NS_VK_NUMPAD6, Qt::Key_6 }, - { NS_VK_NUMPAD7, Qt::Key_7 }, - { NS_VK_NUMPAD8, Qt::Key_8 }, - { NS_VK_NUMPAD9, Qt::Key_9 }, - { NS_VK_MULTIPLY, Qt::Key_Asterisk }, - { NS_VK_ADD, Qt::Key_Plus }, -// { NS_VK_SEPARATOR, Qt::Key_Separator }, - { NS_VK_SUBTRACT, Qt::Key_Minus }, - { NS_VK_DECIMAL, Qt::Key_Period }, - { NS_VK_DIVIDE, Qt::Key_Slash }, - { NS_VK_F1, Qt::Key_F1 }, - { NS_VK_F2, Qt::Key_F2 }, - { NS_VK_F3, Qt::Key_F3 }, - { NS_VK_F4, Qt::Key_F4 }, - { NS_VK_F5, Qt::Key_F5 }, - { NS_VK_F6, Qt::Key_F6 }, - { NS_VK_F7, Qt::Key_F7 }, - { NS_VK_F8, Qt::Key_F8 }, - { NS_VK_F9, Qt::Key_F9 }, - { NS_VK_F10, Qt::Key_F10 }, - { NS_VK_F11, Qt::Key_F11 }, - { NS_VK_F12, Qt::Key_F12 }, - { NS_VK_F13, Qt::Key_F13 }, - { NS_VK_F14, Qt::Key_F14 }, - { NS_VK_F15, Qt::Key_F15 }, - { NS_VK_F16, Qt::Key_F16 }, - { NS_VK_F17, Qt::Key_F17 }, - { NS_VK_F18, Qt::Key_F18 }, - { NS_VK_F19, Qt::Key_F19 }, - { NS_VK_F20, Qt::Key_F20 }, - { NS_VK_F21, Qt::Key_F21 }, - { NS_VK_F22, Qt::Key_F22 }, - { NS_VK_F23, Qt::Key_F23 }, - { NS_VK_F24, Qt::Key_F24 }, - - { NS_VK_NUM_LOCK, Qt::Key_NumLock }, - { NS_VK_SCROLL_LOCK, Qt::Key_ScrollLock }, - - { NS_VK_COMMA, Qt::Key_Comma }, - { NS_VK_PERIOD, Qt::Key_Period }, - { NS_VK_SLASH, Qt::Key_Slash }, - { NS_VK_BACK_QUOTE, Qt::Key_QuoteLeft }, - { NS_VK_OPEN_BRACKET, Qt::Key_ParenLeft }, - { NS_VK_CLOSE_BRACKET, Qt::Key_ParenRight }, - { NS_VK_QUOTE, Qt::Key_QuoteDbl } -}; -#endif //JCG - -PRLogModuleInfo * QtEventsLM = PR_NewLogModule("QtEvents"); - -/** - * Constructor for QT event handler. - * - */ -nsQEventHandler::nsQEventHandler(nsWidget *aWidget) : QObject() -{ - PR_LOG(QtEventsLM, PR_LOG_DEBUG, ("nsQEventHandler::nsQEventHandler()\n")); - mEnabled = true; - mDestroyed = false; - mWidget = aWidget; -#ifdef DBG_JCG - gQEventHandlerCount++; - printf("JCG: nsQEventHandler CTOR. Count: %d\n",gQEventHandlerCount); -#endif -} - -nsQEventHandler::~nsQEventHandler() -{ - PR_LOG(QtEventsLM, PR_LOG_DEBUG, ("nsQEventHandler::~nsQEventHandler()\n")); - mWidget = nsnull; -#ifdef DBG_JCG - gQEventHandlerCount--; - printf("JCG: nsQEventHandler DTOR. Count: %d\n",gQEventHandlerCount); -#endif -} - -void nsQEventHandler::Enable(bool aEnable) -{ - mEnabled = aEnable; -} - -void nsQEventHandler::Destroy() -{ - mDestroyed = true; - mWidget = nsnull; -} - -bool nsQEventHandler::eventFilter(QObject* object, QEvent* event) -{ - bool handled = false; - - if (mDestroyed) - return true; - - switch (event->type()) { -#if 0 //JCG - case QEvent::MouseButtonPress: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Mouse Button Pushed. Widget: %p\n",mWidget); -#endif - handled = MouseButtonEvent((QMouseEvent*)event, mWidget, true, 1); - } - else - handled = true; - break; - - case QEvent::MouseButtonRelease: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Mouse Button Released widget: %p\n",mWidget); -#endif - handled = MouseButtonEvent((QMouseEvent*)event, mWidget, false, 1); - } - else - handled = true; - break; - - case QEvent::MouseButtonDblClick: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Mouse Button Double-clicked widget: %p\n",mWidget); -#endif - handled = MouseButtonEvent((QMouseEvent*)event, mWidget, true, 2); - } - else - handled = true; - break; -#endif //JCG - - case QEvent::MouseMove: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Mouse Moved widget: %p\n",mWidget); -#endif - handled = MouseMovedEvent((QMouseEvent*)event, mWidget); - } - else - handled = true; - break; - -#if 0 //JCG - case QEvent::KeyPress: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Key Pressed widget: %p\n",mWidget); -#endif - handled = KeyPressEvent((QKeyEvent*)event, mWidget); - } - else - handled = true; - break; - - case QEvent::KeyRelease: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Key Released widget: %p\n",mWidget); -#endif - handled = KeyReleaseEvent((QKeyEvent*)event, mWidget); - } - else - handled = true; - break; - - case QEvent::Enter: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Mouse Enter widget: %p\n",mWidget); -#endif - handled = MouseEnterEvent(event, mWidget); - } - else - handled = true; - break; - - case QEvent::Leave: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Mouse Exit widget: %p\n",mWidget); -#endif - handled = MouseExitEvent(event, mWidget); - } - else - handled = true; - break; - - case QEvent::Close: - if (!mWidget->IsPopup()) { -#ifdef DBG_JCG - printf("JCG: Close widget: %p\n",mWidget); -#endif - handled = DestroyEvent((QCloseEvent*)event, mWidget); - } - break; - - case QEvent::Destroy: -#ifdef DBG_JCG - printf("JCG: Destroy widget: %p\n",mWidget); -#endif - handled = DestroyEvent((QCloseEvent*)event, mWidget); - break; - - case QEvent::Resize: -#ifdef DBG_JCG - printf("JCG: Resize widget: %p\n",mWidget); -#endif - handled = ResizeEvent((QResizeEvent*)event, mWidget); - break; - - case QEvent::Move: -#ifdef DBG_JCG - printf("JCG: Move widget: %p\n",mWidget); -#endif - handled = MoveEvent((QMoveEvent*)event, mWidget); - break; -#endif //JCG - - case QEvent::Paint: -#ifdef DBG_JCG - printf("JCG: Paint widget: %p\n",mWidget); -#endif - handled = PaintEvent((QPaintEvent*)event, mWidget); - break; - -#if 0 //JCG - case QEvent::FocusIn: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Focus In widget: %p\n",mWidget); -#endif - handled = FocusInEvent((QFocusEvent*)event, mWidget); - } - else - handled = true; - break; - - case QEvent::FocusOut: - if (mEnabled) { -#ifdef DBG_JCG - printf("JCG: Focus In widget: %p\n",mWidget); -#endif - handled = FocusOutEvent((QFocusEvent*)event, mWidget); - } - else - handled = true; - break; -#endif //JCG - - default: -#ifdef DBG_JCG - printf("JCG: widget: %p, Other: %d\n",mWidget,event->type()); -#endif - break; - } - return handled; -} - - -bool nsQEventHandler::MouseButtonEvent(QMouseEvent *event, - nsWidget *widget, - bool buttonDown, - int clickCnt) -{ - if (event && widget) { - nsMouseEvent nsEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::MouseButtonEvent for %s(%p) at (%d,%y)\n", - widget->GetName(), widget, event->x(), event->y())); - - switch (event->button()) { - case LeftButton: - nsEvent.message = buttonDown ? NS_MOUSE_LEFT_BUTTON_DOWN - : NS_MOUSE_LEFT_BUTTON_UP; - break; - - case RightButton: - nsEvent.message = buttonDown ? NS_MOUSE_RIGHT_BUTTON_DOWN - : NS_MOUSE_RIGHT_BUTTON_UP; - break; - - case MidButton: - nsEvent.message = buttonDown ? NS_MOUSE_MIDDLE_BUTTON_DOWN - : NS_MOUSE_MIDDLE_BUTTON_UP; - break; - - default: - // This shouldn't happen! - NS_ASSERTION(0, "Bad MousePressedEvent!"); - nsEvent.message = NS_MOUSE_MOVE; - break; - } - - nsEvent.point.x = event->x(); - nsEvent.point.y = event->y(); - nsEvent.widget = widget; - nsEvent.nativeMsg = (void*)event; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.clickCount = clickCnt; - nsEvent.isShift = (event->state() & ShiftButton) ? PR_TRUE : PR_FALSE; - nsEvent.isControl = (event->state() & ControlButton) ? PR_TRUE : PR_FALSE; - nsEvent.isAlt = (event->state() & AltButton) ? PR_TRUE : PR_FALSE; - nsEvent.isMeta = PR_FALSE; - nsEvent.time = PR_IntervalNow(); - widget->AddRef(); - widget->DispatchMouseEvent(nsEvent); - widget->Release(); - } - /* Below are a series of slimey hacks to do the right thing with */ - /* Mouse Events - Qt gets a go at all events for native widgets */ - /* (i.e. NOT nsWidget or nsWindow) and at Button Press Events for */ - /* nsWidget & nsWindow, unless either the EventHandler is destroyed */ - /* (i.e. "widget" is NULL) or the widget is deleted (i.e. IsInDTOR */ - /* returns TRUE). The last item is particularly slimey... */ - bool handled = true; - if (widget && !widget->IsInDTOR()) { - if (widget->GetName() == QWidget::tr("nsWindow") - || widget->GetName() == QWidget::tr("nsWidget")) { - if (buttonDown) { - handled = false; - } - } - else { - handled = false; - } - } - return handled; -} - -bool nsQEventHandler::MouseMovedEvent(QMouseEvent *event, - nsWidget *widget) -{ - if (event && widget) { - // Generate XPFE mouse moved event - nsMouseEvent nsEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::MouseMovedEvent for %s(%p) at (%d,%d)\n", - widget->GetName(), widget, event->x(), event->y())); - - nsEvent.point.x = event->x(); - nsEvent.point.y = event->y(); - nsEvent.message = NS_MOUSE_MOVE; - nsEvent.widget = widget; - nsEvent.nativeMsg = (void*)event; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.time = PR_IntervalNow(); - nsEvent.isShift = (event->state() & ShiftButton) ? PR_TRUE : PR_FALSE; - nsEvent.isControl = (event->state() & ControlButton) ? PR_TRUE : PR_FALSE; - nsEvent.isAlt = (event->state() & AltButton) ? PR_TRUE : PR_FALSE; - nsEvent.isMeta = PR_FALSE; - - widget->AddRef(); - widget->DispatchMouseEvent(nsEvent); - widget->Release(); - } - /* Below are a series of slimey hacks to do the right thing with */ - /* Mouse Move Events - Qt only gets a go at events for non-deleted */ - /* native widgets (i.e. NOT nsWidget or nsWindow AND IsInDTOR */ - /* returns FALSE) Using IsInDTOR like this is particularly slimey! */ - - bool handled = false; - if (widget && !widget->IsInDTOR()) { - if (widget->GetName() == QWidget::tr("nsWindow") - || widget->GetName() == QWidget::tr("nsWidget")) { - handled = true; - } - } - else - handled = true; - - return handled; -} - -bool nsQEventHandler::MouseEnterEvent(QEvent *event, - nsWidget *widget) -{ - if (event && widget) { - nsMouseEvent nsEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::MouseEnterEvent for %s\n", - widget->GetName())); - - nsEvent.message = NS_MOUSE_ENTER; - nsEvent.widget = widget; - nsEvent.nativeMsg = (void*)event; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.time = PR_IntervalNow(); - - widget->AddRef(); - widget->DispatchMouseEvent(nsEvent); - widget->Release(); - } - return true; -} - -bool nsQEventHandler::MouseExitEvent(QEvent *event, - nsWidget *widget) -{ - if (event && widget) { - nsMouseEvent nsEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::MouseExitEvent for %s\n", - widget->GetName())); - - nsEvent.message = NS_MOUSE_EXIT; - nsEvent.widget = widget; - nsEvent.nativeMsg = (void*)event; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.time = PR_IntervalNow(); - - widget->AddRef(); - widget->DispatchMouseEvent(nsEvent); - widget->Release(); - } - return true; -} - -bool nsQEventHandler::DestroyEvent(QCloseEvent *event, - nsWidget *widget) -{ - if (event && widget) { - // Generate XPFE destroy event - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::DestroyEvent for %s\n", - widget->GetName())); - - widget->Destroy(); - } - return true; -} - -bool nsQEventHandler::ResizeEvent(QResizeEvent *event, - nsWidget *widget) -{ - if (event && widget) { - // Generate XPFE resize event - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::ResizeEvent for %s(%p)\n", - widget->GetName(), - widget)); - - nsRect rect; - widget->GetBounds(rect); - rect.width = event->size().width(); - rect.height = event->size().height(); - - widget->OnResize(rect); - } - return false; -} - -bool nsQEventHandler::MoveEvent(QMoveEvent *event, - nsWidget *widget) -{ - if (event && widget) { - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::MoveEvent for %s\n", - widget->GetName())); - - // Generate XPFE move event - widget->OnMove(event->pos().x(),event->pos().y()); - } - return true; -} - -bool nsQEventHandler::PaintEvent(QPaintEvent *event, - nsWidget *widget) -{ - if (event && widget) { - // Generate XPFE paint event - nsPaintEvent nsEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::PaintEvent for %s(%p)\n", - widget->GetName(), - widget)); - - nsEvent.message = NS_PAINT; - nsEvent.widget = widget; - nsEvent.eventStructType = NS_PAINT_EVENT; - nsEvent.time = PR_IntervalNow(); - - PR_LOG(QtEventsLM,PR_LOG_DEBUG, - ("nsQEventHandler::PaintEvent: need to paint:x=%d,y=%d,w=%d,h=%d\n", - event->rect().x(),event->rect().y(), - event->rect().width(),event->rect().height())); - - nsRect rect(event->rect().x(),event->rect().y(), - event->rect().width(),event->rect().height()); - nsEvent.rect = ▭ - - widget->AddRef(); - widget->OnPaint(nsEvent); - widget->Release(); - } - if (widget && widget->GetName() == QWidget::tr("nsWindow") - || widget->GetName() == QWidget::tr("nsWidget")) { - return true; - } - else { - return false; - } -} - -bool nsQEventHandler::KeyPressEvent(QKeyEvent *event, - nsWidget *widget) -{ - if (event && widget) { - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::KeyPressEvent for %s\n", - widget->GetName())); - - if (event->key() == Qt::Key_Shift - || event->key() == Qt::Key_Control - || event->key() == Qt::Key_Alt) - return false; - - nsKeyEvent nsEvent; - - nsEvent.message = NS_KEY_DOWN; - nsEvent.eventStructType = NS_KEY_EVENT; - nsEvent.widget = widget; - nsEvent.keyCode = GetNSKey(event->key(),event->state()); - nsEvent.isShift = event->state() & ShiftButton; - nsEvent.isControl = event->state() & ControlButton; - nsEvent.isAlt = event->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - nsEvent.time = PR_IntervalNow(); - - nsEvent.charCode = 0; - widget->AddRef(); - ((nsWindow*)widget)->OnKey(nsEvent); - - nsEvent.message = NS_KEY_PRESS; - nsEvent.eventStructType = NS_KEY_EVENT; - nsEvent.widget = widget; - nsEvent.isShift = event->state() & ShiftButton; - nsEvent.isControl = event->state() & ControlButton; - nsEvent.isAlt = event->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - nsEvent.time = PR_IntervalNow(); - if (event->text().length() && event->text()[0].isPrint()) { - nsEvent.charCode = (PRInt32)event->text()[0].unicode(); - } - else { - nsEvent.charCode = 0; - } - if (nsEvent.charCode) { - nsEvent.keyCode = 0; - } - else - nsEvent.keyCode = GetNSKey(event->key(),event->state()); - - ((nsWindow*)widget)->OnKey(nsEvent); - widget->Release(); - } - return true; -} - -bool nsQEventHandler::KeyReleaseEvent(QKeyEvent *event, - nsWidget *widget) -{ - if (event && widget) { - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::KeyReleaseEvent for %s\n", - widget->GetName())); - - if (event->key() == Qt::Key_Shift || event->key() == Qt::Key_Control - || event->key() == Qt::Key_Alt) - return false; - - nsKeyEvent nsEvent; - - nsEvent.message = NS_KEY_UP; - nsEvent.eventStructType = NS_KEY_EVENT; - nsEvent.widget = widget; - nsEvent.charCode = 0; - nsEvent.keyCode = GetNSKey(event->key(), event->state()); - nsEvent.isShift = event->state() & ShiftButton; - nsEvent.isControl = event->state() & ControlButton; - nsEvent.isAlt = event->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.time = PR_IntervalNow(); - - widget->AddRef(); - ((nsWindow*)widget)->OnKey(nsEvent); - widget->Release(); - } - return true; -} - -#if 0 //JCG -PRInt32 nsQEventHandler::GetNSKey(PRInt32 key,PRInt32 state) -{ - PRInt32 length = sizeof(nsKeycodes) / sizeof(nsKeyConverter); - - for (PRInt32 i = 0; i < length; i++) { - if (nsKeycodes[i].keysym == key) { - return nsKeycodes[i].vkCode; - } - } - return 0; -} -#endif //JCG - -bool nsQEventHandler::FocusInEvent(QFocusEvent *event, - nsWidget *widget) -{ - if (event && widget) { - nsGUIEvent aEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::FocusInEvent for %s\n", - widget->GetName())); - - aEvent.message = NS_GOTFOCUS; - aEvent.eventStructType = NS_GUI_EVENT; - aEvent.widget = widget; - aEvent.time = PR_IntervalNow(); - aEvent.point.x = 0; - aEvent.point.y = 0; - - widget->AddRef(); - ((nsWindow*)widget)->DispatchFocus(aEvent); - widget->Release(); - } - return true; -} - -bool nsQEventHandler::FocusOutEvent(QFocusEvent *event, - nsWidget *widget) -{ - if (event && widget) { - nsGUIEvent aEvent; - - PR_LOG(QtEventsLM, - PR_LOG_DEBUG, - ("nsQEventHandler::FocusOutEvent for %s\n", - widget->GetName())); - - aEvent.message = NS_LOSTFOCUS; - aEvent.eventStructType = NS_GUI_EVENT; - aEvent.widget = widget; - aEvent.time = PR_IntervalNow(); - aEvent.point.x = 0; - aEvent.point.y = 0; - - widget->AddRef(); - ((nsWindow*)widget)->DispatchFocus(aEvent); - widget->Release(); - } - return true; -} diff --git a/widget/src/qt/nsQEventHandler.h b/widget/src/qt/nsQEventHandler.h deleted file mode 100644 index d27c778b51fc..000000000000 --- a/widget/src/qt/nsQEventHandler.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef __nsQTEventHandler_h -#define __nsQTEventHandler_h - -#include "nsWidget.h" - -#include -#include - -class nsQEventHandler : public QObject -{ - Q_OBJECT - -public: - nsQEventHandler(nsWidget *aWidget); - ~nsQEventHandler(); - - void Enable(bool aEnable); - void Destroy(); - bool eventFilter(QObject * object, QEvent * event); - - bool MouseButtonEvent(QMouseEvent *event,nsWidget *widget, - bool buttonDown,int clickCnt); - bool MouseMovedEvent(QMouseEvent * event, nsWidget * widget); - bool MouseEnterEvent(QEvent * event, nsWidget * widget); - bool MouseExitEvent(QEvent * event, nsWidget * widget); - bool DestroyEvent(QCloseEvent * event, nsWidget * widget); - bool HideEvent(QHideEvent * event, nsWidget * widget); - bool ResizeEvent(QResizeEvent * event, nsWidget * widget); - bool MoveEvent(QMoveEvent * event, nsWidget * widget); - bool PaintEvent(QPaintEvent * event, nsWidget * widget); - bool KeyPressEvent(QKeyEvent * event, nsWidget * widget); - bool KeyReleaseEvent(QKeyEvent * event, nsWidget * widget); - bool FocusInEvent(QFocusEvent * event, nsWidget * widget); - bool FocusOutEvent(QFocusEvent * event, nsWidget * widget); - -protected: - PRInt32 GetNSKey(PRInt32 key, PRInt32 state); - -private: - nsWidget *mWidget; - bool mEnabled; - bool mDestroyed; -}; - -#endif // __nsQEventHandler.h diff --git a/widget/src/qt/nsQWidget.cpp b/widget/src/qt/nsQWidget.cpp deleted file mode 100644 index f304e00bf3de..000000000000 --- a/widget/src/qt/nsQWidget.cpp +++ /dev/null @@ -1,1127 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Denis Issoupov - * Wes Morgan - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIServiceManager.h" -#include "nsGUIEvent.h" -#include "nsQWidget.h" -#include "nsWidget.h" -#include "nsClipboard.h" -#include "nsDragService.h" -#include "nsFontMetricsQT.h" -#include "nsQApplication.h" - -#include -#include - -//JCG #define DBG_JCG 1 -//JCG #define DBG_JCG_EVENT 1 - -#ifdef DBG_JCG -PRUint32 gQBaseWidgetCount = 0; -PRUint32 gQBaseWidgetID = 0; - -PRUint32 gQWidgetCount = 0; -PRUint32 gQWidgetID = 0; -#endif - -static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID); - -struct nsKeyConverter -{ - int vkCode; // Platform independent key code - int keysym; // QT key code -}; - -struct nsKeyConverter nsKeycodes[] = -{ -// { NS_VK_CANCEL, Qt::Key_Cancel }, - { NS_VK_BACK, Qt::Key_BackSpace }, - { NS_VK_TAB, Qt::Key_Tab }, -// { NS_VK_CLEAR, Qt::Key_Clear }, - { NS_VK_RETURN, Qt::Key_Return }, - { NS_VK_RETURN, Qt::Key_Enter }, - { NS_VK_SHIFT, Qt::Key_Shift }, - { NS_VK_CONTROL, Qt::Key_Control }, - { NS_VK_ALT, Qt::Key_Alt }, - { NS_VK_PAUSE, Qt::Key_Pause }, - { NS_VK_CAPS_LOCK, Qt::Key_CapsLock }, - { NS_VK_ESCAPE, Qt::Key_Escape }, - { NS_VK_SPACE, Qt::Key_Space }, - { NS_VK_PAGE_UP, Qt::Key_PageUp }, - { NS_VK_PAGE_DOWN, Qt::Key_PageDown }, - { NS_VK_END, Qt::Key_End }, - { NS_VK_HOME, Qt::Key_Home }, - { NS_VK_LEFT, Qt::Key_Left }, - { NS_VK_UP, Qt::Key_Up }, - { NS_VK_RIGHT, Qt::Key_Right }, - { NS_VK_DOWN, Qt::Key_Down }, - { NS_VK_PRINTSCREEN, Qt::Key_Print }, - { NS_VK_INSERT, Qt::Key_Insert }, - { NS_VK_DELETE, Qt::Key_Delete }, - - { NS_VK_0, Qt::Key_0 }, - { NS_VK_1, Qt::Key_1 }, - { NS_VK_2, Qt::Key_2 }, - { NS_VK_3, Qt::Key_3 }, - { NS_VK_4, Qt::Key_4 }, - { NS_VK_5, Qt::Key_5 }, - { NS_VK_6, Qt::Key_6 }, - { NS_VK_7, Qt::Key_7 }, - { NS_VK_8, Qt::Key_8 }, - { NS_VK_9, Qt::Key_9 }, - - { NS_VK_SEMICOLON, Qt::Key_Semicolon }, - { NS_VK_EQUALS, Qt::Key_Equal }, - - { NS_VK_A, Qt::Key_A }, - { NS_VK_B, Qt::Key_B }, - { NS_VK_C, Qt::Key_C }, - { NS_VK_D, Qt::Key_D }, - { NS_VK_E, Qt::Key_E }, - { NS_VK_F, Qt::Key_F }, - { NS_VK_G, Qt::Key_G }, - { NS_VK_H, Qt::Key_H }, - { NS_VK_I, Qt::Key_I }, - { NS_VK_J, Qt::Key_J }, - { NS_VK_K, Qt::Key_K }, - { NS_VK_L, Qt::Key_L }, - { NS_VK_M, Qt::Key_M }, - { NS_VK_N, Qt::Key_N }, - { NS_VK_O, Qt::Key_O }, - { NS_VK_P, Qt::Key_P }, - { NS_VK_Q, Qt::Key_Q }, - { NS_VK_R, Qt::Key_R }, - { NS_VK_S, Qt::Key_S }, - { NS_VK_T, Qt::Key_T }, - { NS_VK_U, Qt::Key_U }, - { NS_VK_V, Qt::Key_V }, - { NS_VK_W, Qt::Key_W }, - { NS_VK_X, Qt::Key_X }, - { NS_VK_Y, Qt::Key_Y }, - { NS_VK_Z, Qt::Key_Z }, - - { NS_VK_NUMPAD0, Qt::Key_0 }, - { NS_VK_NUMPAD1, Qt::Key_1 }, - { NS_VK_NUMPAD2, Qt::Key_2 }, - { NS_VK_NUMPAD3, Qt::Key_3 }, - { NS_VK_NUMPAD4, Qt::Key_4 }, - { NS_VK_NUMPAD5, Qt::Key_5 }, - { NS_VK_NUMPAD6, Qt::Key_6 }, - { NS_VK_NUMPAD7, Qt::Key_7 }, - { NS_VK_NUMPAD8, Qt::Key_8 }, - { NS_VK_NUMPAD9, Qt::Key_9 }, - { NS_VK_MULTIPLY, Qt::Key_Asterisk }, - { NS_VK_ADD, Qt::Key_Plus }, -// { NS_VK_SEPARATOR, Qt::Key_Separator }, - { NS_VK_SUBTRACT, Qt::Key_Minus }, - { NS_VK_DECIMAL, Qt::Key_Period }, - { NS_VK_DIVIDE, Qt::Key_Slash }, - { NS_VK_F1, Qt::Key_F1 }, - { NS_VK_F2, Qt::Key_F2 }, - { NS_VK_F3, Qt::Key_F3 }, - { NS_VK_F4, Qt::Key_F4 }, - { NS_VK_F5, Qt::Key_F5 }, - { NS_VK_F6, Qt::Key_F6 }, - { NS_VK_F7, Qt::Key_F7 }, - { NS_VK_F8, Qt::Key_F8 }, - { NS_VK_F9, Qt::Key_F9 }, - { NS_VK_F10, Qt::Key_F10 }, - { NS_VK_F11, Qt::Key_F11 }, - { NS_VK_F12, Qt::Key_F12 }, - { NS_VK_F13, Qt::Key_F13 }, - { NS_VK_F14, Qt::Key_F14 }, - { NS_VK_F15, Qt::Key_F15 }, - { NS_VK_F16, Qt::Key_F16 }, - { NS_VK_F17, Qt::Key_F17 }, - { NS_VK_F18, Qt::Key_F18 }, - { NS_VK_F19, Qt::Key_F19 }, - { NS_VK_F20, Qt::Key_F20 }, - { NS_VK_F21, Qt::Key_F21 }, - { NS_VK_F22, Qt::Key_F22 }, - { NS_VK_F23, Qt::Key_F23 }, - { NS_VK_F24, Qt::Key_F24 }, - - { NS_VK_NUM_LOCK, Qt::Key_NumLock }, - { NS_VK_SCROLL_LOCK, Qt::Key_ScrollLock }, - - { NS_VK_COMMA, Qt::Key_Comma }, - { NS_VK_PERIOD, Qt::Key_Period }, - { NS_VK_SLASH, Qt::Key_Slash }, - { NS_VK_BACK_QUOTE, Qt::Key_QuoteLeft }, - { NS_VK_OPEN_BRACKET, Qt::Key_ParenLeft }, - { NS_VK_CLOSE_BRACKET, Qt::Key_ParenRight }, - { NS_VK_QUOTE, Qt::Key_QuoteDbl }, - - { NS_VK_META, Qt::Key_Meta } -}; - -static PRInt32 NS_GetKey(PRInt32 aKey) -{ - PRInt32 length = sizeof(nsKeycodes) / sizeof(nsKeyConverter); - - for (PRInt32 i = 0; i < length; i++) { - if (nsKeycodes[i].keysym == aKey) { - return nsKeycodes[i].vkCode; - } - } - return 0; -} - -PRBool NS_IsMouseInWindow(void *aWin,PRInt32 aMouseX,PRInt32 aMouseY) -{ - QWidget *qWin = (QWidget*)aWin; - QPoint origin = qWin->mapToGlobal(QPoint(0,0)); - - if (aMouseX > origin.x() && aMouseX < (origin.x() + qWin->width()) - && aMouseY > origin.y() && aMouseY < (origin.y() + qWin->height())) { - return PR_TRUE; - } - return PR_FALSE; -} - -unsigned int NS_GetQWFlags(nsBorderStyle aBorder,nsWindowType aType) -{ - QWidget::WFlags w = 0; - - if (aBorder != eBorderStyle_default) { - if (aBorder & eBorderStyle_border) { - w |= Qt::WStyle_DialogBorder; - } - if (aBorder & eBorderStyle_resizeh) { - w |= Qt::WStyle_NormalBorder; - } - if (aBorder & eBorderStyle_title) { - w |= Qt::WStyle_Title; - } - if (aBorder & eBorderStyle_menu) { - w |= Qt::WStyle_SysMenu | Qt::WStyle_Title; - } - if (aBorder & eBorderStyle_minimize) { - w |= Qt::WStyle_Minimize; - } - if (aBorder & eBorderStyle_maximize) { - w |= Qt::WStyle_Maximize; - } - if (aBorder & eBorderStyle_close) { -#ifdef DEBUG - printf("JCG: eBorderStyle_close isn't handled yet... please fix me\n"); -#endif - } - } - w |= (w) ? Qt::WStyle_Customize : 0; - - switch (aType) { - case eWindowType_toplevel: - w |= Qt::WType_TopLevel | Qt::WDestructiveClose | Qt::WGroupLeader; - break; - - case eWindowType_dialog: - w |= Qt::WType_TopLevel | Qt::WStyle_Dialog; - break; - - case eWindowType_popup: - w |= Qt::WType_Popup; - break; - - case eWindowType_child: - break; - } - w |= Qt::WRepaintNoErase | Qt::WResizeNoErase; - - return((unsigned int)w); -} - -//============================================================================= -// -// nsQBaseWidget class -// -//============================================================================= -nsQBaseWidget::nsQBaseWidget(nsWidget* aWidget) -{ - mWidget = aWidget; - mEnabled = PR_TRUE; - mDestroyed = PR_FALSE; - -#ifdef DBG_JCG - gQBaseWidgetCount++; - mQBaseID = gQBaseWidgetID++; - printf("JCG: nsQBaseWidget CTOR (%p), ID: %d, Count: %d, nsWidget: %p\n", - this,mQBaseID,gQBaseWidgetCount,mWidget); -#endif -} - -nsQBaseWidget::~nsQBaseWidget() -{ -#ifdef DBG_JCG - gQBaseWidgetCount--; - printf("JCG: nsQBaseWidget DTOR (%p), ID: %d, Count: %d, nsWidget: %p\n", - this,mQBaseID,gQBaseWidgetCount,mWidget); -#endif - Destroy(); - if (mQWidget) { - delete mQWidget; - mQWidget = nsnull; - } -} - -PRBool nsQBaseWidget::CreateNative(QWidget *aParent,const char* aName, - unsigned int aFlags) -{ - if (!(mQWidget = new nsQWidget(aParent,aName,(QWidget::WFlags)aFlags))) { - return PR_FALSE; - } - mQWidget->installEventFilter(this); - return PR_TRUE; -} - -void nsQBaseWidget::Destroy() -{ -#ifdef DBG_JCG - printf("JCG: nsQBaseWidget Destroy (%p), ID: %d, Count: %d\n", - this,mQBaseID,gQBaseWidgetCount); -#endif - mDestroyed = PR_TRUE; - - if (mWidget) { - mWidget = nsnull; - } - if (mQWidget) { - const QObjectList *kids; - QObject *kid = nsnull; - - kids = mQWidget->children(); - if (kids) { - QObjectListIt it(*kids); - QPoint pt(0,0); - - while ((kid = it.current())) { -#ifdef DBG_JCG - printf("JCG: (%p) Reparent: %p\n",this,kid); -#endif - ((QWidget*)kid)->reparent(nsQApplication::GetMasterWidget(),pt); - } - } - } -} - -void nsQBaseWidget::Enable(PRBool aState) -{ - mEnabled = aState; -} - -PRBool nsQBaseWidget::HandlePopup(void *aEvent) -{ - QMouseEvent *qEvent = (QMouseEvent*)aEvent; - - if (mWidget) { - return(mWidget->HandlePopup(qEvent->globalX(),qEvent->globalY())); - } - return(PR_FALSE); -} - -void nsQBaseWidget::SetCursor(nsCursor aCursor) -{ - PRBool cursorSet = PR_FALSE; - QCursor newCursor(ArrowCursor); - - switch (aCursor) { - case eCursor_select: - newCursor.setShape(IbeamCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_wait: - newCursor.setShape(WaitCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_hyperlink: - newCursor.setShape(PointingHandCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_standard: - cursorSet = PR_TRUE; - break; - - case eCursor_sizeNS: - case eCursor_arrow_south: - case eCursor_arrow_south_plus: - case eCursor_arrow_north: - case eCursor_arrow_north_plus: - newCursor.setShape(SizeVerCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_sizeWE: - case eCursor_arrow_east: - case eCursor_arrow_east_plus: - case eCursor_arrow_west: - case eCursor_arrow_west_plus: - newCursor.setShape(SizeHorCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_sizeNW: - case eCursor_sizeSE: - newCursor.setShape(SizeFDiagCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_sizeNE: - case eCursor_sizeSW: - newCursor.setShape(SizeBDiagCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_crosshair: - newCursor.setShape(CrossCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_move: - newCursor.setShape(SizeAllCursor); - cursorSet = PR_TRUE; - break; - - case eCursor_help: -/* Question + Arrow */ - case eCursor_cell: -/* Plus */ - case eCursor_grab: - case eCursor_grabbing: -/* Hand1 */ - case eCursor_spinning: -/* Exchange */ - - case eCursor_copy: // CSS3 - case eCursor_alias: - case eCursor_context_menu: - - // XXX: these CSS3 cursors need to be implemented - // For CSS3 Cursor Definitions, See: - // www.w3.org/TR/css3-userint - case eCursor_count_up: - case eCursor_count_down: - case eCursor_count_up_down: - break; - // XXX: these CSS3 cursors need to be implemented - - default: - NS_ASSERTION(PR_FALSE, "Invalid cursor type"); - break; - } - if (cursorSet) { - // Since nsEventStateManager::UpdateCursor() doesn't use the same - // nsWidget* that is given in DispatchEvent(). - qApp->setOverrideCursor(newCursor,PR_TRUE); - } -} - -void nsQBaseWidget::SetFont(nsFontQT *aFont) -{ - QFont *qtFont = aFont->GetQFont(); - if (qtFont) - mQWidget->setFont(*qtFont); -} - -bool nsQBaseWidget::eventFilter(QObject *aObj,QEvent *aEvent) -{ - bool handled = false; - - if (mDestroyed) { -#ifdef DBG_JCG_EVENT - printf("JCG: Destroyed\n"); -#endif - return true; - } - switch (aEvent->type()) { - case QEvent::MouseButtonPress: -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Button Pushed. Widget: %p\n",mWidget); -#endif - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Handled\n"); -#endif - handled = MouseButtonEvent((QMouseEvent*)aEvent,PR_TRUE,1); - } - else - handled = true; - break; - - case QEvent::MouseButtonRelease: -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Button Released widget: %p\n",mWidget); -#endif - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Handled\n"); -#endif - handled = MouseButtonEvent((QMouseEvent*)aEvent,PR_FALSE,1); - } - else - handled = true; - break; - - case QEvent::MouseButtonDblClick: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Button Double-clicked widget: %p\n",mWidget); -#endif - handled = MouseButtonEvent((QMouseEvent*)aEvent,PR_TRUE,2); - } - else - handled = true; - break; - - case QEvent::MouseMove: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Moved widget: %p\n",mWidget); -#endif - handled = MouseMovedEvent((QMouseEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::Wheel: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Wheel widget: %p\n",mWidget); -#endif - handled = MouseWheelEvent((QWheelEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::KeyPress: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Key Pressed widget: %p\n",mWidget); -#endif - handled = KeyPressEvent((QKeyEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::KeyRelease: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Key Released widget: %p\n",mWidget); -#endif - handled = KeyReleaseEvent((QKeyEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::Enter: -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Enter widget: %p\n",mWidget); -#endif - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Handled\n"); -#endif - handled = MouseEnterEvent(aEvent); - } - else - handled = true; - break; - - case QEvent::Leave: -#ifdef DBG_JCG_EVENT - printf("JCG: Mouse Exit widget: %p\n",mWidget); -#endif - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Handled\n"); -#endif - handled = MouseExitEvent(aEvent); - } - else - handled = true; - break; - - case QEvent::Close: - if (!mWidget->IsPopup()) { -#ifdef DBG_JCG_EVENT - printf("JCG: Close widget: %p\n",mWidget); -#endif - handled = DestroyEvent(); - } - break; - - case QEvent::Destroy: -#ifdef DBG_JCG_EVENT - printf("JCG: Destroy widget: %p\n",mWidget); -#endif - handled = DestroyEvent(); - break; - - case QEvent::Resize: -#ifdef DBG_JCG_EVENT - printf("JCG: Resize widget: %p\n",mWidget); -#endif - handled = ResizeEvent((QResizeEvent*)aEvent); - break; - - case QEvent::Move: -#ifdef DBG_JCG_EVENT - printf("JCG: Move widget: %p\n",mWidget); -#endif - handled = MoveEvent((QMoveEvent*)aEvent); - break; - - case QEvent::Paint: -#ifdef DBG_JCG_EVENT - printf("JCG: Paint widget: %p\n",mWidget); -#endif - handled = PaintEvent((QPaintEvent*)aEvent); - break; - - case QEvent::FocusIn: -#ifdef DBG_JCG_EVENT - printf("JCG: Focus In widget: %p\n",mWidget); -#endif - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Handled\n"); -#endif - handled = FocusInEvent(); - } - else - handled = true; - break; - - case QEvent::FocusOut: -#ifdef DBG_JCG_EVENT - printf("JCG: Focus Out widget: %p\n",mWidget); -#endif - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Handled\n"); -#endif - handled = FocusOutEvent(); - } - else - handled = true; - break; - - case QEvent::DragEnter: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Drag Enter widget: %p\n",mWidget); -#endif - handled = DragEnterEvent((QDragEnterEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::DragLeave: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Drag Leave widget: %p\n",mWidget); -#endif - handled = DragLeaveEvent((QDragLeaveEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::DragMove: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Drag Move widget: %p\n",mWidget); -#endif - handled = DragMoveEvent((QDragMoveEvent*)aEvent); - } - else - handled = true; - break; - - case QEvent::Drop: - if (mEnabled) { -#ifdef DBG_JCG_EVENT - printf("JCG: Drop widget: %p\n",mWidget); -#endif - handled = DropEvent((QDropEvent*)aEvent); - } - else - handled = true; - break; - - default: -#ifdef DBG_JCG_EVENT - printf("JCG: widget: %p, Other: %d\n",mWidget,aEvent->type()); -#endif - break; - } - return handled; -} - -PRBool nsQBaseWidget::MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown, - int aClickCount) -{ - if (aEvent && mWidget) { - nsMouseEvent nsEvent; - - switch (aEvent->button()) { - case LeftButton: - nsEvent.message = aButtonDown ? NS_MOUSE_LEFT_BUTTON_DOWN - : NS_MOUSE_LEFT_BUTTON_UP; - break; - - case RightButton: - nsEvent.message = aButtonDown ? NS_MOUSE_RIGHT_BUTTON_DOWN - : NS_MOUSE_RIGHT_BUTTON_UP; - break; - - case MidButton: - nsEvent.message = aButtonDown ? NS_MOUSE_MIDDLE_BUTTON_DOWN - : NS_MOUSE_MIDDLE_BUTTON_UP; - break; - - default: - // This shouldn't happen! - NS_ASSERTION(0, "Bad MousePressedEvent!"); - nsEvent.message = NS_MOUSE_MOVE; - break; - } - nsEvent.point.x = nscoord(aEvent->x()); - nsEvent.point.y = nscoord(aEvent->y()); - nsEvent.widget = mWidget; - nsEvent.nativeMsg = (void*)aEvent; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.clickCount = aClickCount; - nsEvent.isShift = aEvent->state() & ShiftButton; - nsEvent.isControl = aEvent->state() & ControlButton; - nsEvent.isAlt = aEvent->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.time = 0; - - mWidget->DispatchMouseEvent(nsEvent); - } - if (aButtonDown) - return PR_FALSE; - else - return PR_TRUE; -} - -PRBool nsQBaseWidget::MouseMovedEvent(QMouseEvent *aEvent) -{ - if (aEvent && mWidget) { - // Generate XPFE mouse moved event - nsMouseEvent nsEvent; - - nsEvent.point.x = nscoord(aEvent->x()); - nsEvent.point.y = nscoord(aEvent->y()); - nsEvent.message = NS_MOUSE_MOVE; - nsEvent.widget = mWidget; - nsEvent.nativeMsg = (void*)aEvent; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.time = 0; - nsEvent.isShift = aEvent->state() & ShiftButton; - nsEvent.isControl = aEvent->state() & ControlButton; - nsEvent.isAlt = aEvent->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - - mWidget->DispatchMouseEvent(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::MouseEnterEvent(QEvent *aEvent) -{ - if (aEvent && mWidget) { - nsMouseEvent nsEvent; - - nsEvent.message = NS_MOUSE_ENTER; - nsEvent.widget = mWidget; - nsEvent.nativeMsg = (void*)aEvent; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.time = 0; - - mWidget->DispatchMouseEvent(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::MouseExitEvent(QEvent *aEvent) -{ - if (aEvent && mWidget) { - nsMouseEvent nsEvent; - - nsEvent.message = NS_MOUSE_EXIT; - nsEvent.widget = mWidget; - nsEvent.nativeMsg = (void*)aEvent; - nsEvent.eventStructType = NS_MOUSE_EVENT; - nsEvent.time = 0; - - mWidget->DispatchMouseEvent(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::MouseWheelEvent(QWheelEvent *aEvent) -{ - if (aEvent && mWidget) { - nsMouseScrollEvent nsEvent; - - nsEvent.scrollFlags = nsMouseScrollEvent::kIsVertical; - nsEvent.delta = (int)((aEvent->delta()/120) * -3); - nsEvent.message = NS_MOUSE_SCROLL; - nsEvent.widget = mWidget; - nsEvent.nativeMsg = (void*)aEvent; - nsEvent.eventStructType = NS_MOUSE_SCROLL_EVENT; - nsEvent.time = 0; - nsEvent.point.x = nscoord(aEvent->x()); - nsEvent.point.y = nscoord(aEvent->y()); - nsEvent.isShift = aEvent->state() & ShiftButton; - nsEvent.isControl = aEvent->state() & ControlButton; - nsEvent.isAlt = aEvent->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - - mWidget->DispatchMouseScrollEvent(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::DestroyEvent() -{ - if (mWidget) { - // Generate XPFE destroy event - mWidget->Destroy(); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::ResizeEvent(QResizeEvent *aEvent) -{ - if (aEvent && mWidget) { - nsRect rect; - - // Generate XPFE resize event - mWidget->GetBounds(rect); - rect.width = aEvent->size().width(); - rect.height = aEvent->size().height(); - - mWidget->OnResize(rect); - } - return PR_FALSE; -} - -PRBool nsQBaseWidget::MoveEvent(QMoveEvent *aEvent) -{ - if (aEvent && mWidget) { - // Generate XPFE move event - mWidget->OnMove(aEvent->pos().x(),aEvent->pos().y()); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::PaintEvent(QPaintEvent *aEvent) -{ - if (aEvent && mWidget) { - nsPaintEvent nsEvent; - nsRect rect(aEvent->rect().x(),aEvent->rect().y(), - aEvent->rect().width(),aEvent->rect().height()); - - // Generate XPFE paint event - nsEvent.message = NS_PAINT; - nsEvent.widget = mWidget; - nsEvent.eventStructType = NS_PAINT_EVENT; - nsEvent.time = 0; - nsEvent.rect = ▭ - - mWidget->OnPaint(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::KeyPressEvent(QKeyEvent *aEvent) -{ - if (aEvent && mWidget) { - if (aEvent->key() == Qt::Key_Shift || aEvent->key() == Qt::Key_Control - || aEvent->key() == Qt::Key_Alt) { - return PR_FALSE; - } - nsKeyEvent nsEvent; - - nsEvent.message = NS_KEY_DOWN; - nsEvent.eventStructType = NS_KEY_EVENT; - nsEvent.widget = mWidget; - nsEvent.keyCode = NS_GetKey(aEvent->key()); - nsEvent.isShift = aEvent->state() & ShiftButton; - nsEvent.isControl = aEvent->state() & ControlButton; - nsEvent.isAlt = aEvent->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - nsEvent.time = 0; - nsEvent.charCode = 0; - - mWidget->OnKey(nsEvent); - - nsEvent.message = NS_KEY_PRESS; - nsEvent.eventStructType = NS_KEY_EVENT; - nsEvent.widget = mWidget; - nsEvent.isShift = aEvent->state() & ShiftButton; - nsEvent.isControl = aEvent->state() & ControlButton; - nsEvent.isAlt = aEvent->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - nsEvent.time = 0; - if (aEvent->text().length() && aEvent->text()[0].isPrint()) { - nsEvent.charCode = (PRInt32)aEvent->text()[0].unicode(); - } - else { - nsEvent.charCode = 0; - } - if (nsEvent.charCode) { - nsEvent.keyCode = 0; - } - else - nsEvent.keyCode = NS_GetKey(aEvent->key()); - - mWidget->OnKey(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::KeyReleaseEvent(QKeyEvent *aEvent) -{ - if (aEvent && mWidget) { - if (aEvent->key() == Qt::Key_Shift || aEvent->key() == Qt::Key_Control - || aEvent->key() == Qt::Key_Alt) { - return PR_FALSE; - } - nsKeyEvent nsEvent; - - nsEvent.message = NS_KEY_UP; - nsEvent.eventStructType = NS_KEY_EVENT; - nsEvent.widget = mWidget; - nsEvent.charCode = 0; - nsEvent.keyCode = NS_GetKey(aEvent->key()); - nsEvent.isShift = aEvent->state() & ShiftButton; - nsEvent.isControl = aEvent->state() & ControlButton; - nsEvent.isAlt = aEvent->state() & AltButton; - nsEvent.isMeta = PR_FALSE; - nsEvent.time = 0; - - mWidget->OnKey(nsEvent); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::FocusInEvent() -{ - if (mWidget) { - mWidget->DispatchFocusInEvent(); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::FocusOutEvent() -{ - if (mWidget) { - mWidget->DispatchFocusOutEvent(); - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::DragEnterEvent(QDragEnterEvent *aEvent) -{ - if (mWidget && aEvent) { - int res; - nsMouseEvent nsEvent; - - nsEvent.message = NS_DRAGDROP_ENTER; - nsEvent.eventStructType = NS_DRAGDROP_EVENT; - nsEvent.widget = mWidget; - nsEvent.point.x = aEvent->pos().x(); - nsEvent.point.y = aEvent->pos().y(); - - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - if (dragService != 0) { - dragService->StartDragSession(); - - nsCOMPtr qtSession(do_QueryInterface(dragService)); - if (qtSession) { - qtSession->SetDragReference(aEvent); - aEvent->accept(0); - } - } - res = mWidget->DispatchMouseEvent(nsEvent); -#ifdef NS_DEBUG - printf("NS_DRAGDROP_ENTER %i\n",res); -#endif - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::DragMoveEvent(QDragMoveEvent *aEvent) -{ - if (mWidget && aEvent) { - nsMouseEvent nsEvent; - - nsEvent.message = NS_DRAGDROP_OVER; - nsEvent.eventStructType = NS_DRAGDROP_EVENT; - nsEvent.widget = mWidget; - nsEvent.point.x = aEvent->pos().x(); - nsEvent.point.y = aEvent->pos().y(); - - mWidget->DispatchMouseEvent(nsEvent); - - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - if (dragService != 0) { - nsCOMPtr dragSession = do_QueryInterface(dragService); - if (dragSession != 0) { - PRBool aCanDrop; - - dragSession->GetCanDrop(&aCanDrop); - aEvent->accept(aCanDrop); - dragSession->SetCanDrop(0); - } - } - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::DragLeaveEvent(QDragLeaveEvent *aEvent) -{ - if (mWidget) { - nsMouseEvent nsEvent; - - nsEvent.message = NS_DRAGDROP_EXIT; - nsEvent.eventStructType = NS_DRAGDROP_EVENT; - nsEvent.widget = mWidget; - - mWidget->DispatchMouseEvent(nsEvent); -#ifdef NS_DEBUG - printf("NS_DRAGDROP_EXIT\n"); -#endif - - nsCOMPtr dragService = do_GetService(kCDragServiceCID); - if (dragService != 0) { - nsCOMPtr dragSession = do_QueryInterface(dragService); - if (dragSession != 0) - dragSession->SetCanDrop(0); - dragService->EndDragSession(); - } - } - return PR_TRUE; -} - -PRBool nsQBaseWidget::DropEvent(QDropEvent *aEvent) -{ - if (mWidget && aEvent) { - nsMouseEvent nsEvent; - int res; - - nsEvent.message = NS_DRAGDROP_DROP; - nsEvent.eventStructType = NS_DRAGDROP_EVENT; - nsEvent.widget = mWidget; - nsEvent.point.x = aEvent->pos().x(); - nsEvent.point.y = aEvent->pos().y(); - - res = mWidget->DispatchMouseEvent(nsEvent); -#ifdef NS_DEBUG - printf("NS_DRAGDROP_DROP %i\n",res); -#endif - } - return PR_TRUE; -} - -//============================================================================= -// -// nsQWidget class -// -//============================================================================= -nsQWidget::nsQWidget(QWidget *aParent,const char *aName,unsigned int aFlags) - : QWidget(aParent,aName,(WFlags)aFlags) -{ - setAcceptDrops(PR_TRUE); - setBackgroundMode(QWidget::NoBackground); - setMouseTracking(PR_TRUE); - setFocusPolicy(QWidget::WheelFocus); - -#ifdef DBG_JCG - gQWidgetCount++; - mQWidgetID = gQWidgetID++; - printf("JCG: nsQWidget CTOR (%p), ID: %d, Count: %d, Parent: %p\n", - this,mQWidgetID,gQWidgetCount,aParent); -#endif -} - -nsQWidget::~nsQWidget() -{ -#ifdef DBG_JCG - gQWidgetCount--; - printf("JCG: nsQWidget DTOR (%p), ID: %d, Count: %d\n", - this,mQWidgetID,gQWidgetCount); -#endif -} - -void qt_enter_modal(QWidget*); // defined in qapplication_x11.cpp -void qt_leave_modal(QWidget*); // --- "" --- - -#if QT_VERSION < 300 -#define NS_QT_SHOW_MODAL Qt::WType_Modal -#else -#define NS_QT_SHOW_MODAL Qt::WShowModal -#endif -void nsQWidget::SetModal(PRBool aState) -{ - if (aState) { - setWFlags(NS_QT_SHOW_MODAL); - qt_enter_modal(this); - } - else { - clearWFlags(NS_QT_SHOW_MODAL); - qt_leave_modal(this); - } -} diff --git a/widget/src/qt/nsQWidget.h b/widget/src/qt/nsQWidget.h deleted file mode 100644 index e29593a6f316..000000000000 --- a/widget/src/qt/nsQWidget.h +++ /dev/null @@ -1,189 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Denis Issoupov - * Wes Morgan - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsQWidget_h__ -#define nsQWidget_h__ - -#include -#include - -#include "nsIWidget.h" - -class nsFontQT; -class nsWidget; - -/* Utility Functions */ -PRBool NS_IsMouseInWindow(void *aWin,PRInt32 aMouseX,PRInt32 aMouseY); -unsigned int NS_GetQWFlags(nsBorderStyle aBorder,nsWindowType aType); - -//============================================================================= -// nsQWidget class: -// Customizes QWidget for use in XPFE -//============================================================================= -class nsQWidget : public QWidget -{ - Q_OBJECT -public: - nsQWidget(QWidget *aParent,const char *aName = 0,WFlags aFlags = WResizeNoErase); - virtual ~nsQWidget(); - - virtual void SetModal(PRBool aState); - -private: - PRUint32 mQWidgetID; -}; - -//============================================================================= -// nsQBaseWidget class -// Provides a "two-way" interface, allowing XPFE to access Qt Widget -// functionality and hooking the relevant Qt Events into the XPFE Event -// Handling -//============================================================================= -class nsQBaseWidget : public QObject -{ - Q_OBJECT -public: - nsQBaseWidget(nsWidget *aWidget); - virtual ~nsQBaseWidget(); - - /*** Lifecycle Management ***/ - PRBool CreateNative(QWidget *aParent = 0,const char *aName = 0, - unsigned int aFlags = WResizeNoErase); - virtual void Destroy(); - - /*** Interface to Qt Widget functionality for XPFE ***/ - void Enable(PRBool aState); - PRBool HandlePopup(void *aEvent); - virtual void SetCursor(nsCursor aCursor); - virtual void SetFont(nsFontQT *aFont); - virtual void SetModal(PRBool aState) - { - ((nsQWidget*)mQWidget)->SetModal(aState); - }; - virtual const char *Name() {return mQWidget->name();}; - virtual int Width() {return mQWidget->width();}; - virtual int Height() {return mQWidget->height();}; - virtual int BoundsX() {return 0;}; - virtual int BoundsY() {return 0;}; - virtual void OffsetXYToGlobal(PRInt32 *aX,PRInt32 *aY) - { - QPoint offset(0,0); - offset = mQWidget->mapToGlobal(offset); - *aX = offset.x(); - *aY = offset.y(); - }; - virtual void OffsetXYFromGlobal(PRInt32 *aX,PRInt32 *aY) - { - QPoint offset(0,0); - offset = mQWidget->mapFromGlobal(offset); - *aX = offset.x(); - *aY = offset.y(); - }; - virtual void Move(PRInt32 aX,PRInt32 aY) {mQWidget->move(aX,aY);}; - virtual void Resize(PRInt32 aW,PRInt32 aH) {mQWidget->resize(aW,aH);}; - virtual void Scroll(PRInt32 aDx,PRInt32 aDy) {mQWidget->scroll(aDx,aDy);}; - virtual void Show() { printf("ESBEN: Show called\n"); mQWidget->show();}; - virtual void Hide() {mQWidget->hide();}; - virtual PRBool IsVisible() {return mQWidget->isVisible();}; - virtual void SetFocus() {mQWidget->setFocus();}; - virtual void SetTopLevelFocus() {mQWidget->topLevelWidget()->setFocus();}; - virtual void RaiseTopLevel() {mQWidget->topLevelWidget()->raise();}; - virtual PRBool IsTopLevelActive() - { - return(mQWidget->topLevelWidget()->isActiveWindow()); - }; - virtual void SetTitle(const char *aTitleStr) - { - mQWidget->setCaption(QString::fromLocal8Bit(aTitleStr)); - }; - virtual void SetBackgroundColor(const nscolor &aColor) - { - QColor color(NS_GET_R(aColor),NS_GET_G(aColor),NS_GET_B(aColor)); - mQWidget->setBackgroundColor(color); - }; - virtual void Polish() {mQWidget->polish();}; - virtual void Repaint(PRBool aErase) {mQWidget->repaint(aErase);}; - virtual void Repaint(PRInt32 aX,PRInt32 aY,PRInt32 aW, PRInt32 aH,PRBool aErase) - { - mQWidget->repaint(aX,aY,aW,aH,aErase); - }; - virtual void Update() {mQWidget->update();}; - virtual void Update(PRInt32 aX,PRInt32 aY,PRInt32 aW, PRInt32 aH) - { - mQWidget->update(aX,aY,aW,aH); - }; - virtual void *GetNativeWindow() {return((void*)(QPaintDevice*)mQWidget);}; - virtual void *GetNativeWidget() {return((void*)mQWidget);}; - - virtual void* X11Display() {return (void*)mQWidget->x11Display();}; - virtual void* WinID() {return (void*)mQWidget->winId();}; - - /*** Interface to XPFE Event Handling from Qt ***/ - bool eventFilter(QObject *aObj,QEvent *aEvent); - - virtual PRBool MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown, - int aClickCount); - virtual PRBool MouseMovedEvent(QMouseEvent *aEvent); - virtual PRBool MouseEnterEvent(QEvent *aEvent); - virtual PRBool MouseExitEvent(QEvent *aEvent); - virtual PRBool MouseWheelEvent(QWheelEvent *aEvent); - virtual PRBool DestroyEvent(); - virtual PRBool ResizeEvent(QResizeEvent *aEvent); - virtual PRBool MoveEvent(QMoveEvent *aEvent); - virtual PRBool PaintEvent(QPaintEvent *aEvent); - virtual PRBool KeyPressEvent(QKeyEvent *aEvent); - virtual PRBool KeyReleaseEvent(QKeyEvent *aEvent); - virtual PRBool FocusInEvent(); - virtual PRBool FocusOutEvent(); - virtual PRBool DragEnterEvent(QDragEnterEvent *aEvent); - virtual PRBool DragMoveEvent(QDragMoveEvent *aEvent); - virtual PRBool DragLeaveEvent(QDragLeaveEvent *aEvent); - virtual PRBool DropEvent(QDropEvent *aEvent); - -protected: - nsWidget *mWidget; - QWidget *mQWidget; - PRBool mEnabled; - PRBool mDestroyed; - -private: - PRUint32 mQBaseID; -}; - -#endif //nsQWidget_h__ diff --git a/widget/src/qt/nsScrollbar.cpp b/widget/src/qt/nsScrollbar.cpp deleted file mode 100644 index f325b650877c..000000000000 --- a/widget/src/qt/nsScrollbar.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsScrollbar.h" -#include "nsGUIEvent.h" - -//JCG #define DBG_JCG 1 - -#ifdef DBG_JCG -PRUint32 gQBaseSBCount = 0; -PRUint32 gQBaseSBID = 0; - -PRUint32 gQSBCount = 0; -PRUint32 gQSBID = 0; - -PRUint32 gNsSBCount = 0; -PRUint32 gNsSBID = 0; -#endif - -//============================================================================= -// nsQBaseScrollBar class -//============================================================================= -nsQBaseScrollBar::nsQBaseScrollBar(nsWidget *aWidget) - : nsQBaseWidget(aWidget) -{ -#ifdef DBG_JCG - gQBaseSBCount++; - mQBaseSBID = gQBaseSBID++; - printf("JCG: nsQBaseScrollBar CTOR (%p) ID: %d, Count: %d\n", - this,mQBaseSBID,gQBaseSBCount); -#endif -} - -nsQBaseScrollBar::~nsQBaseScrollBar() -{ -#ifdef DBG_JCG - gQBaseSBCount--; - printf("JCG: nsQBaseScrollBar DTOR (%p) ID: %d, Count: %d\n", - this,mQBaseSBID,gQBaseSBCount); -#endif -} - -void nsQBaseScrollBar::ValueChanged(int aValue) -{ - ScrollBarMoved(NS_SCROLLBAR_POS,aValue); -} - -void nsQBaseScrollBar::ScrollBarMoved(int aMessage,int aValue) -{ - if (mWidget) { - nsScrollbarEvent nsEvent; - - nsEvent.message = aMessage; - nsEvent.widget = mWidget; - nsEvent.eventStructType = NS_SCROLLBAR_EVENT; - nsEvent.position = aValue; - - ((nsScrollbar*)mWidget)->OnScroll(nsEvent,aValue); - } -} - -PRBool nsQBaseScrollBar::CreateNative(int aMinValue,int aMaxValue, - int aLineStep,int aPageStep,int aValue, - Orientation aOrientation,QWidget *aParent, - const char *aName) -{ - if (!(mQWidget = new nsQScrollBar(aMinValue,aMaxValue,aLineStep,aPageStep,aValue, - aOrientation,aParent,aName))) { - return PR_FALSE; - } - connect((QScrollBar*)mQWidget,SIGNAL(valueChanged(int)),this,SLOT(ValueChanged(int))); - mQWidget->installEventFilter(this); - return PR_TRUE; -} - -void nsQBaseScrollBar::Destroy() -{ - mEnabled = PR_FALSE; - - if (mWidget) { - mWidget = nsnull; - } -} - -PRBool nsQBaseScrollBar::MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown, - int aClickCount) -{ - return PR_FALSE; -} - -PRBool nsQBaseScrollBar::MouseMovedEvent(QMouseEvent *aEvent) -{ - return PR_FALSE; -} - -PRBool nsQBaseScrollBar::PaintEvent(QPaintEvent *aEvent) -{ - return PR_FALSE; -} - -//============================================================================= -// nsQScrollBar class -//============================================================================= -nsQScrollBar::nsQScrollBar(int aMinValue,int aMaxValue, - int aLineStep,int aPageStep,int aValue, - Orientation aOrientation,QWidget *aParent, - const char *aName) - : QScrollBar(aMinValue,aMaxValue,aLineStep,aPageStep,aValue, - aOrientation,aParent,aName) -{ -#ifdef DBG_JCG - gQSBCount++; - mQSBID = gQSBID++; - printf("JCG: nsQScrollBar CTOR (%p) ID: %d, Count: %d\n",this,mQSBID,gQSBCount); -#endif - setMouseTracking(PR_TRUE); - setTracking(PR_TRUE); -} - -nsQScrollBar::~nsQScrollBar() -{ -#ifdef DBG_JCG - gQSBCount--; - printf("JCG: nsQScrollBar DTOR (%p) ID: %d, Count: %d\n",this,mQSBID,gQSBCount); -#endif -} - -void nsQScrollBar::closeEvent(QCloseEvent *aEvent) -{ - aEvent->ignore(); -} - -//============================================================================= -// nsScrollBar class -//============================================================================= -NS_IMPL_ADDREF_INHERITED(nsScrollbar,nsWidget); -NS_IMPL_RELEASE_INHERITED(nsScrollbar,nsWidget); -NS_IMPL_QUERY_INTERFACE2(nsScrollbar,nsIScrollbar,nsIWidget) - -//------------------------------------------------------------------------- -// nsScrollbar constructor -//------------------------------------------------------------------------- -nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget(), nsIScrollbar() -{ -#ifdef DBG_JCG - gNsSBCount++; - mNsSBID = gNsSBID++; - printf("JCG: nsScrollBar CTOR (%p) ID: %d, Count: %d\n",this,mNsSBID,gNsSBCount); -#endif - mOrientation = aIsVertical ? QScrollBar::Vertical : QScrollBar::Horizontal; - mLineStep = 1; - mPageStep = 10; - mMaxValue = 100; - mValue = 0; - mListenForResizes = PR_TRUE; -} - -//------------------------------------------------------------------------- -// nsScrollbar destructor -//------------------------------------------------------------------------- -nsScrollbar::~nsScrollbar() -{ -#ifdef DBG_JCG - gNsSBCount--; - printf("JCG: nsScrollBar DTOR (%p) ID: %d, Count: %d\n",this,mNsSBID,gNsSBCount); -#endif -} - -//------------------------------------------------------------------------- -// Define the range settings -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange) -{ - mMaxValue = aEndRange; - ((nsQBaseScrollBar*)mWidget)->SetRange(0,mMaxValue - mPageStep); - return NS_OK; -} - -//------------------------------------------------------------------------- -// Return the range settings -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::GetMaxRange(PRUint32 &aMaxRange) -{ - aMaxRange = mMaxValue; - return NS_OK; -} - -//------------------------------------------------------------------------- -// Set the thumb position -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos) -{ - mValue = aPos; - ((nsQBaseScrollBar*)mWidget)->SetValue(mValue); - return NS_OK; -} - -//------------------------------------------------------------------------- -// Get the current thumb position. -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::GetPosition(PRUint32 &aPos) -{ - aPos = mValue; - return NS_OK; -} - -//------------------------------------------------------------------------- -// Set the thumb size -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize) -{ - if (aSize > 0) { - mPageStep = aSize; - - ((nsQBaseScrollBar*)mWidget)->SetSteps(mLineStep,mPageStep); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Get the thumb size -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::GetThumbSize(PRUint32 &aThumbSize) -{ - aThumbSize = mPageStep; - return NS_OK; -} - -//------------------------------------------------------------------------- -// Set the line increment for this scrollbar -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement) -{ - if (aLineIncrement > 0) { - mLineStep = aLineIncrement; - - ((nsQBaseScrollBar*)mWidget)->SetSteps(mLineStep,mPageStep); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Get the line increment for this scrollbar -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::GetLineIncrement(PRUint32 &aLineInc) -{ - aLineInc = mLineStep; - return NS_OK; -} - -//------------------------------------------------------------------------- -// Set all scrolling parameters -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange,PRUint32 aThumbSize, - PRUint32 aPosition,PRUint32 aLineIncrement) -{ - mPageStep = (aThumbSize > 0) ? aThumbSize : 1; - mValue = (aPosition > 0) ? aPosition : 0; - mLineStep = (aLineIncrement > 0) ? aLineIncrement : 1; - mMaxValue = (aMaxRange > 0) ? aMaxRange : 10; - - ((nsQBaseScrollBar*)mWidget)->SetValue(mValue); - ((nsQBaseScrollBar*)mWidget)->SetSteps(mLineStep,mPageStep); - ((nsQBaseScrollBar*)mWidget)->SetRange(0,mMaxValue - mPageStep); - return NS_OK; -} - -//------------------------------------------------------------------------- -// Deal with scrollbar messages (actually implemented only in nsScrollbar) -//------------------------------------------------------------------------- -PRBool nsScrollbar::OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos) -{ - PRBool result = PR_TRUE; - - switch (aEvent.message) { - // scroll one line right or down - case NS_SCROLLBAR_LINE_NEXT: - ((nsQBaseScrollBar*)mWidget)->AddLine(); - mValue = ((nsQBaseScrollBar*)mWidget)->Value(); - - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = (PRUint32)mValue; - result = ConvertStatus((*mEventCallback)(&aEvent)); - mValue = aEvent.position; - } - break; - - // scroll one line left or up - case NS_SCROLLBAR_LINE_PREV: - ((nsQBaseScrollBar*)mWidget)->SubtractLine(); - mValue = ((nsQBaseScrollBar*)mWidget)->Value(); - - // if an event callback is registered, give it the chance - // to change the decrement - if (mEventCallback) { - aEvent.position = (PRUint32)mValue; - result = ConvertStatus((*mEventCallback)(&aEvent)); - mValue = aEvent.position; - } - break; - - // Scrolls one page right or down - case NS_SCROLLBAR_PAGE_NEXT: - ((nsQBaseScrollBar*)mWidget)->AddPage(); - mValue = ((nsQBaseScrollBar*)mWidget)->Value(); - - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = (PRUint32)mValue; - result = ConvertStatus((*mEventCallback)(&aEvent)); - mValue = aEvent.position; - } - break; - - // Scrolls one page left or up. - case NS_SCROLLBAR_PAGE_PREV: - ((nsQBaseScrollBar*)mWidget)->SubtractPage(); - mValue = ((nsQBaseScrollBar*)mWidget)->Value(); - - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = (PRUint32)mValue; - result = ConvertStatus((*mEventCallback)(&aEvent)); - mValue = aEvent.position; - } - break; - - // Scrolls to the absolute position. The current position is specified by - // the cPos parameter. - case NS_SCROLLBAR_POS: - mValue = cPos; - - // if an event callback is registered, give it the chance - // to change the increment - if (mEventCallback) { - aEvent.position = (PRUint32)mValue; - result = ConvertStatus((*mEventCallback)(&aEvent)); - mValue = aEvent.position; - } - break; - } - return result; -} - -//------------------------------------------------------------------------- -// Create the native scrollbar widget -//------------------------------------------------------------------------- -NS_METHOD nsScrollbar::CreateNative(QWidget *aParentWindow) -{ - mWidget = new nsQBaseScrollBar(this); - - if (!mWidget) - return NS_ERROR_OUT_OF_MEMORY; - - if (!((nsQBaseScrollBar*)mWidget)->CreateNative(0,mMaxValue,mLineStep,mPageStep, - mValue,mOrientation,aParentWindow, - QScrollBar::tr("nsScrollBar"))) { - delete mWidget; - mWidget = nsnull; - return NS_ERROR_OUT_OF_MEMORY; - } - return nsWidget::CreateNative(aParentWindow); -} diff --git a/widget/src/qt/nsScrollbar.h b/widget/src/qt/nsScrollbar.h deleted file mode 100644 index 05a1f8e1d564..000000000000 --- a/widget/src/qt/nsScrollbar.h +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsScrollbar_h__ -#define nsScrollbar_h__ - -#include "nsWidget.h" -#include "nsQWidget.h" -#include "nsIScrollbar.h" - -#include - -//============================================================================= -// nsQScrollBar class: -// Provides a "two-way" interface, allowing XPFE to access Qt Scrollbar -// functionality and hooking the relevant Qt Events into the XPFE Event -// Handling. Inherits basic functionality from nsQBaseWidget. -//============================================================================= -class nsQBaseScrollBar : public nsQBaseWidget -{ - Q_OBJECT -public: - nsQBaseScrollBar(nsWidget *aWidget); - ~nsQBaseScrollBar(); - - /*** Lifecycle Management ***/ - PRBool CreateNative(int aMinValue,int aMaxValue, - int aLineStep,int aPageStep,int aValue, - Orientation aOrientation,QWidget *aParent, - const char *aName = 0); - virtual void Destroy(); - - /*** Interface to Qt ScrollBar functionality for XPFE ***/ - virtual void SetModal(PRBool aState) {}; - void SetRange(PRUint32 aMin,PRUint32 aMax) {((QScrollBar*)mQWidget)->setRange(aMin,aMax);}; - void SetValue(PRUint32 aValue) {((QScrollBar*)mQWidget)->setValue(aValue);}; - void SetSteps(PRUint32 aLineStep,PRUint32 aPageStep) - { - ((QScrollBar*)mQWidget)->setSteps(aLineStep,aPageStep); - }; - void AddLine() {((QScrollBar*)mQWidget)->addLine();}; - void SubtractLine() {((QScrollBar*)mQWidget)->subtractLine();}; - void AddPage() {((QScrollBar*)mQWidget)->addPage();}; - void SubtractPage() {((QScrollBar*)mQWidget)->subtractPage();}; - int Value() {return(((QScrollBar*)mQWidget)->value());}; - - /*** Interface to XPFE Event Handling from Qt ***/ - virtual PRBool MouseButtonEvent(QMouseEvent *aEvent,PRBool aButtonDown, - int aClickCount); - virtual PRBool MouseMovedEvent(QMouseEvent *aEvent); - virtual PRBool PaintEvent(QPaintEvent *aEvent); - - void ScrollBarMoved(int aMessage,int aValue = -1); - -public slots: - void ValueChanged(int aValue); - -private: - PRUint32 mQBaseSBID; -}; - -//============================================================================= -// nsQScrollBar class: -// Customizes QScrollBar for use by XPFE -//============================================================================= -class nsQScrollBar : public QScrollBar -{ - Q_OBJECT -public: - nsQScrollBar(int aMinValue,int aMaxValue,int aLineStep,int aPageStep,int aValue, - Orientation aOrientation,QWidget *aParent,const char *aName = 0); - ~nsQScrollBar(); - - void closeEvent(QCloseEvent *aEvent); - -private: - PRUint32 mQSBID; -}; - -//============================================================================= -// nsScrollBar class: -// the XPFE Scrollbar -//============================================================================= -class nsScrollbar : public nsWidget, public nsIScrollbar -{ -public: - nsScrollbar(PRBool aIsVertical); - virtual ~nsScrollbar(); - - // nsISupports - NS_DECL_ISUPPORTS_INHERITED - - // nsIScrollBar implementation - NS_IMETHOD SetMaxRange(PRUint32 aEndRange); - NS_IMETHOD GetMaxRange(PRUint32& aMaxRange); - NS_IMETHOD SetPosition(PRUint32 aPos); - NS_IMETHOD GetPosition(PRUint32& aPos); - NS_IMETHOD SetThumbSize(PRUint32 aSize); - NS_IMETHOD GetThumbSize(PRUint32& aSize); - NS_IMETHOD SetLineIncrement(PRUint32 aSize); - NS_IMETHOD GetLineIncrement(PRUint32& aSize); - NS_IMETHOD SetParameters(PRUint32 aMaxRange,PRUint32 aThumbSize, - PRUint32 aPosition,PRUint32 aLineIncrement); - - virtual PRBool OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos); - - virtual PRBool IsScrollBar() const { return PR_TRUE; }; - -protected: - NS_IMETHOD CreateNative(QWidget *aParentWindow); - -private: - QScrollBar::Orientation mOrientation; - int mMaxValue; - int mLineStep; - int mPageStep; - int mValue; - PRUint32 mNsSBID; -}; - -#endif // nsScrollbar_h__ diff --git a/widget/src/qt/nsTextHelper.cpp b/widget/src/qt/nsTextHelper.cpp deleted file mode 100644 index 456bf59a7ec3..000000000000 --- a/widget/src/qt/nsTextHelper.cpp +++ /dev/null @@ -1,351 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsTextHelper.h" -#include "nsTextWidget.h" -#include "nsToolkit.h" -#include "nsColor.h" -#include "nsGUIEvent.h" -#include "nsString.h" -#include "nsReadableUtils.h" - -#include "nsWindow.h" - -#include -#include - -#define DBG 0 - -//------------------------------------------------------------------------- -// -// nsTextHelper constructor -// -//------------------------------------------------------------------------- - -nsTextHelper::nsTextHelper() : nsWidget(), nsITextWidget() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::nsTextHelper()\n")); - mIsReadOnly = PR_FALSE; - mIsPassword = PR_FALSE; -} - -//------------------------------------------------------------------------- -// -// nsTextHelper destructor -// -//------------------------------------------------------------------------- -nsTextHelper::~nsTextHelper() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::~nsTextHelper()\n")); -} - -//------------------------------------------------------------------------- -// -// Set initial parameters -// -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::PreCreateWidget()\n")); - if (nsnull != aInitData) - { - nsTextWidgetInitData* data = (nsTextWidgetInitData *) aInitData; - mIsPassword = data->mIsPassword; - mIsReadOnly = data->mIsReadOnly; - } - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SetMaxTextLength()\n")); - if (mWidget->isA("nsQLineEdit")) - { - ((QLineEdit *)mWidget)->setMaxLength((int) aChars); - } - else - { - //((QMultiLineEdit *)mWidget)->setMaxLength((int) aChars); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, - PRUint32 aBufferSize, - PRUint32& aActualSize) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::GetText()\n")); - QString string; - - if (mWidget->isA("nsQLineEdit")) - { - string = ((QLineEdit *)mWidget)->text(); - } - else - { - string = ((QMultiLineEdit *)mWidget)->text(); - } - - aTextBuffer.SetLength(0); - aTextBuffer.AppendWithConversion((const char *) string); - - aActualSize = (PRUint32) string.length(); - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SetText(const nsString& aText, PRUint32& aActualSize) -{ - char *buf = ToNewCString(aText); - - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SetText to \"%s\"\n", - buf)); - - QString string = buf; - - //mWidget->setUpdatesEnabled(PR_FALSE); - if (mWidget->isA("nsQLineEdit")) - { - ((QLineEdit *)mWidget)->setText(string); - } - else - { - ((QMultiLineEdit *)mWidget)->setText(string); - } - //mWidget->setUpdatesEnabled(PR_TRUE); - aActualSize = aText.Length(); - - delete[] buf; - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::InsertText(const nsString &aText, - PRUint32 aStartPos, - PRUint32 aEndPos, - PRUint32& aActualSize) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::InsertText()\n")); - nsString currentText; - PRUint32 actualSize; - GetText(currentText, 256, actualSize); - nsString newText(aText); - currentText.Insert(newText, aStartPos); - SetText(currentText,actualSize); - aActualSize = aText.Length(); - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::RemoveText() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::RemoveText()\n")); - if (mWidget->isA("nsQLineEdit")) - { - ((QLineEdit *)mWidget)->clear(); - } - else - { - ((QMultiLineEdit *)mWidget)->clear(); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SetPassword()\n")); - if (mWidget->isA("nsQLineEdit")) - { - QLineEdit::EchoMode mode = aIsPassword ? - QLineEdit::Password : - QLineEdit::Normal; - ((QLineEdit *)mWidget)->setEchoMode(mode); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, - PRBool& aOldReadOnlyFlag) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SetReadOnly()\n")); - NS_ASSERTION(nsnull != mWidget, - "SetReadOnly - Widget is NULL, Create may not have been called!"); - - aOldReadOnlyFlag = mIsReadOnly; - - mIsReadOnly = aReadOnlyFlag?PR_FALSE:PR_TRUE; - - if (mWidget->isA("nsQLineEdit")) - { - ((QLineEdit *)mWidget)->setEnabled(mIsReadOnly); - } - else - { - ((QMultiLineEdit *)mWidget)->setReadOnly(mIsReadOnly); - } - - return NS_OK; -} - - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SelectAll() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SelectAll()\n")); - if (mWidget->isA("nsQLineEdit")) - { - ((QLineEdit *)mWidget)->selectAll(); - } - else - { - ((QMultiLineEdit *)mWidget)->selectAll(); - } - - return NS_OK; -} - - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SetSelection()\n")); - if (mWidget->isA("nsQLineEdit")) - { - if (aStartSel || aEndSel) - { - ((QLineEdit *)mWidget)->setSelection(aStartSel, aEndSel - aStartSel); - } - else - { - ((QLineEdit *)mWidget)->deselect(); - } - } - else - { - //((QMultiLineEdit *)mWidget)->setSelection(aStartSel, - // aEndSel - aStartSel); - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::GetSelection()\n")); - if (mWidget->isA("nsQLineEdit")) - { - if (((QLineEdit *)mWidget)->hasMarkedText()) - { - QString string = ((QLineEdit *)mWidget)->markedText(); - PRUint32 actualSize = 0; - nsString text; - - GetText(text, 0, actualSize); - - PRInt32 start = text.Find((const char *)string); - - if (start >= 0) - { - *aStartSel = start; - *aEndSel = *aStartSel + string.length(); - } - else - { - return NS_ERROR_FAILURE; - } - } - else - { - *aStartSel = 0; - *aEndSel = 0; - } - } - else - { - return NS_ERROR_FAILURE; - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::SetCaretPosition()\n")); - if (mWidget->isA("nsQLineEdit")) - { - ((QLineEdit *)mWidget)->setCursorPosition((int) aPosition); - } - else - { - // based on the index into the text field, calculate the row and - // column. - - int row = 0; - int col = 0; - - ((QMultiLineEdit *)mWidget)->setCursorPosition(row, col); - } - - - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPosition) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::GetCaretPosition()\n")); - if (mWidget->isA("nsQLineEdit")) - { - aPosition = (PRUint32) ((QLineEdit *)mWidget)->cursorPosition(); - } - return NS_OK; -} diff --git a/widget/src/qt/nsTextHelper.h b/widget/src/qt/nsTextHelper.h deleted file mode 100644 index d1b83f6d9a99..000000000000 --- a/widget/src/qt/nsTextHelper.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsTextHelper_h__ -#define nsTextHelper_h__ - -#include "nsITextWidget.h" -#include "nsWidget.h" - -/** - * Base class for nsTextAreaWidget (obsolete) and nsTextWidget - */ - -class nsTextHelper : public nsWidget, - public nsITextWidget -{ - -public: - nsTextHelper(); - virtual ~nsTextHelper(); - NS_IMETHOD SelectAll(); - NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); - NS_IMETHOD SetMaxTextLength(PRUint32 aChars); - NS_IMETHOD GetText(nsString& aTextBuffer, - PRUint32 aBufferSize, - PRUint32& aActualSize); - NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize); - NS_IMETHOD InsertText(const nsString &aText, - PRUint32 aStartPos, - PRUint32 aEndPos, - PRUint32& aActualSize); - NS_IMETHOD RemoveText(); - NS_IMETHOD SetPassword(PRBool aIsPassword); - NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, - PRBool& aOldReadOnlyFlag); - NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel); - NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel); - NS_IMETHOD SetCaretPosition(PRUint32 aPosition); - NS_IMETHOD GetCaretPosition(PRUint32& aPosition); - -protected: - PRBool mIsPassword; - PRBool mIsReadOnly; -}; - -#endif // nsTextHelper_h__ diff --git a/widget/src/qt/nsTextWidget.cpp b/widget/src/qt/nsTextWidget.cpp deleted file mode 100644 index 66351e7c3c53..000000000000 --- a/widget/src/qt/nsTextWidget.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsTextWidget.h" -#include "nsToolkit.h" -#include "nsColor.h" -#include "nsGUIEvent.h" -#include "nsString.h" - -#define DBG 0 - -extern int mIsPasswordCallBacksInstalled; - - -//============================================================================= -// -// nsQLineEdit class -// -//============================================================================= -nsQLineEdit::nsQLineEdit(nsWidget * widget, - QWidget * parent, - const char * name) - : QLineEdit(parent, name), nsQBaseWidget(widget) -{ -} - -nsQLineEdit::~nsQLineEdit() -{ -} - -NS_IMPL_ADDREF_INHERITED(nsTextWidget, nsWidget) -NS_IMPL_RELEASE_INHERITED(nsTextWidget, nsWidget) -NS_IMPL_QUERY_INTERFACE2(nsTextWidget, nsITextWidget, nsIWidget) - -//------------------------------------------------------------------------- -// -// nsTextWidget constructor -// -//------------------------------------------------------------------------- -nsTextWidget::nsTextWidget() : nsTextHelper() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextWidget::nsTextWidget()\n")); -} - -//------------------------------------------------------------------------- -// -// nsTextWidget destructor -// -//------------------------------------------------------------------------- -nsTextWidget::~nsTextWidget() -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextWidget::~nsTextWidget()\n")); -} - -//------------------------------------------------------------------------- -// -// paint, resizes message - ignore -// -//------------------------------------------------------------------------- -PRBool nsTextWidget::OnPaint(nsPaintEvent & aEvent) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextWidget::OnPaint()\n")); - return PR_FALSE; -} - - -//-------------------------------------------------------------- -PRBool nsTextWidget::OnResize(nsRect &aRect) -{ - PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextWidget::OnResize()\n")); - return PR_FALSE; -} - - diff --git a/widget/src/qt/nsTextWidget.h b/widget/src/qt/nsTextWidget.h deleted file mode 100644 index b1c626604bd7..000000000000 --- a/widget/src/qt/nsTextWidget.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsTextWidget_h__ -#define nsTextWidget_h__ - -#include "nsWidget.h" -#include "nsTextHelper.h" -#include "nsITextWidget.h" -#include - -//============================================================================= -// -// nsQLineEdit class -// -//============================================================================= -class nsQLineEdit : public QLineEdit, public nsQBaseWidget -{ - Q_OBJECT -public: - nsQLineEdit(nsWidget * widget, - QWidget * parent = 0, - const char * name = 0); - ~nsQLineEdit(); -}; - -/** - * Native QT single line edit control wrapper. - */ - -class nsTextWidget : public nsTextHelper -{ - -public: - nsTextWidget(); - virtual ~nsTextWidget(); - - NS_DECL_ISUPPORTS_INHERITED - - virtual PRBool OnPaint(nsPaintEvent & aEvent); - virtual PRBool OnResize(nsRect &aRect); -}; - -#endif // nsTextWidget_h__ diff --git a/widget/src/qt/nsToolkit.cpp b/widget/src/qt/nsToolkit.cpp deleted file mode 100644 index 07b1cf455760..000000000000 --- a/widget/src/qt/nsToolkit.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nscore.h" // needed for 'nsnull' -#include "nsToolkit.h" -#include "nsGUIEvent.h" -#include "plevent.h" - -// Static thread local storage index of the Toolkit -// object associated with a given thread... -static PRUintn gToolkitTLSIndex = 0; - -//------------------------------------------------------------------------- -// constructor -//------------------------------------------------------------------------- -nsToolkit::nsToolkit() -{ -} - -//------------------------------------------------------------------------- -// destructor -//------------------------------------------------------------------------- -nsToolkit::~nsToolkit() -{ - // Remove the TLS reference to the toolkit... - PR_SetThreadPrivate(gToolkitTLSIndex, nsnull); -} - -//------------------------------------------------------------------------- -// nsISupports implementation macro -//------------------------------------------------------------------------- -NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit) - -//------------------------------------------------------------------------- -NS_IMETHODIMP nsToolkit::Init(PRThread *aThread) -{ - 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/widget/src/qt/nsToolkit.h b/widget/src/qt/nsToolkit.h deleted file mode 100644 index 72217c96bdba..000000000000 --- a/widget/src/qt/nsToolkit.h +++ /dev/null @@ -1,58 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsToolkit_h__ -#define nsToolkit_h__ - -#include "nsIToolkit.h" - -/** - * 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); -}; - -#endif // nsToolkit_h__ diff --git a/widget/src/qt/nsWidget.cpp b/widget/src/qt/nsWidget.cpp deleted file mode 100644 index 4fd65bb2f6b4..000000000000 --- a/widget/src/qt/nsWidget.cpp +++ /dev/null @@ -1,892 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Wes Morgan - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsWidget.h" -#include "nsIDeviceContext.h" -#include "nsGfxCIID.h" -#include "nsIComponentManager.h" -#include "nsIMenuRollup.h" -#include "nsFontMetricsQT.h" -#include "nsReadableUtils.h" - -#include - -static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); -static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); - -static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); - -nsCOMPtr nsWidget::gRollupListener; -nsWeakPtr nsWidget::gRollupWidget; -PRBool nsWidget::gRollupConsumeRollupEvent = PR_FALSE; - -//JCG #define DBG_JCG 1 - -#ifdef DBG_JCG -PRUint32 gWidgetCount = 0; -PRUint32 gWidgetID = 0; -#endif - -nsWidget::nsWidget() -{ - // get the proper color from the look and feel code - nsILookAndFeel *lookAndFeel; - if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, - nsnull, - kILookAndFeelIID, - (void**)&lookAndFeel)) { - lookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, - mBackground); - } - NS_IF_RELEASE(lookAndFeel); - mWidget = nsnull; - mParent = nsnull; - mPreferredWidth = 0; - mPreferredHeight = 0; - mBounds.x = 0; - mBounds.y = 0; - mBounds.width = 0; - mBounds.height = 0; - mListenForResizes = PR_FALSE; - mIsToplevel = PR_FALSE; - mUpdateArea = do_CreateInstance(kRegionCID); - if (mUpdateArea) { - mUpdateArea->Init(); - mUpdateArea->SetTo(0,0,0,0); - } -#ifdef DBG_JCG - gWidgetCount++; - mWidgetID = gWidgetID++; - printf("JCG: nsWidget CTOR (%p). ID: %d, Count: %d\n",this,mWidgetID,gWidgetCount); -#endif -} - -nsWidget::~nsWidget() -{ - Destroy(); - if (mWidget) { - delete mWidget; - mWidget = nsnull; - } -#ifdef DBG_JCG - gWidgetCount--; - if (mIsToplevel) { - printf("JCG: nsWidget DTOR (%p, ID: %d) of toplevel: %d widgets still exist.\n", - this,mWidgetID,gWidgetCount); - } - else { - printf("JCG: nsWidget DTOR (%p). ID: %d, Count: %d\n",this,mWidgetID,gWidgetCount); - } -#endif -} - -NS_IMPL_ISUPPORTS_INHERITED2(nsWidget,nsBaseWidget,nsIKBStateControl,nsISupportsWeakReference) - -const char *nsWidget::GetName() -{ - return ((mWidget != nsnull) ? mWidget->Name() : ""); -} - -NS_IMETHODIMP nsWidget::WidgetToScreen(const nsRect& aOldRect,nsRect& aNewRect) -{ - aNewRect.width = aOldRect.width; - aNewRect.height = aOldRect.height; - - if (mWidget) { - PRInt32 X,Y; - - mWidget->OffsetXYToGlobal(&X,&Y); - aNewRect.x = aOldRect.x + X; - aNewRect.y = aOldRect.y + Y; - } - return NS_OK; -} - -NS_METHOD nsWidget::ScreenToWidget(const nsRect& aOldRect,nsRect& aNewRect) -{ - if (mWidget) { - PRInt32 X,Y; - - mWidget->OffsetXYFromGlobal(&X,&Y); - aNewRect.x = aOldRect.x + X; - aNewRect.y = aOldRect.y + Y; - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Close this nsWidget -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::Destroy(void) -{ - if (mIsDestroying) - return NS_OK; - - mIsDestroying = PR_TRUE; - nsBaseWidget::Destroy(); - if (mWidget) { - mWidget->Destroy(); - } - if (PR_FALSE == mOnDestroyCalled) - OnDestroy(); - - mEventCallback = nsnull; - return NS_OK; -} - -// make sure that we clean up here -void nsWidget::OnDestroy() -{ - // release references to children, device context, toolkit + app shell - mOnDestroyCalled = PR_TRUE; - nsBaseWidget::OnDestroy(); - - // dispatch the event - // dispatching of the event may cause the reference count to drop to 0 - // and result in this object being destroyed. To avoid that, add a - // reference and then release it after dispatching the event - nsCOMPtr kungFuDeathGrip = this; - DispatchStandardEvent(NS_DESTROY); -} - -//------------------------------------------------------------------------- -// Get this nsWidget parent -//------------------------------------------------------------------------- -nsIWidget *nsWidget::GetParent(void) -{ - nsIWidget *ret; - - ret = mParent; - NS_IF_ADDREF(ret); - return ret; -} - -//------------------------------------------------------------------------- -// Hide or show this component -//------------------------------------------------------------------------- -NS_METHOD nsWidget::Show(PRBool bState) -{ - printf("Show. bState=%s, mWidget=%p\n", bState?"true":"false", mWidget); - if (!mWidget) { - return NS_OK; // Will be null during printing - } - if (bState) { - mWidget->Show(); - } - else { - mWidget->Hide(); - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::CaptureRollupEvents(nsIRollupListener *aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent) -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::SetModal(PRBool aModal) -{ - if (mWidget) - mWidget->SetModal(aModal); - else - return NS_ERROR_FAILURE; - return NS_OK; -} - -NS_METHOD nsWidget::IsVisible(PRBool &aState) -{ - if (mWidget) { - aState = mWidget->IsVisible(); - } - else { - aState = PR_FALSE; - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Constrain a potential move so that it remains onscreen -//------------------------------------------------------------------------- -NS_METHOD nsWidget::ConstrainPosition(PRBool aAllowSlop, - PRInt32 *aX, PRInt32 *aY) -{ - return NS_OK; -} - -//------------------------------------------------------------------------- -// Move this component -//------------------------------------------------------------------------- -NS_METHOD nsWidget::Move(PRInt32 aX, PRInt32 aY) -{ - if (aX == mBounds.x && aY == mBounds.y) { - return NS_OK; - } - mBounds.x = aX; - mBounds.y = aY; - if (mWidget) { - mWidget->Move(aX, aY); - } - return NS_OK; -} - -NS_METHOD nsWidget::Resize(PRInt32 aWidth,PRInt32 aHeight,PRBool aRepaint) -{ - if (mWidget && (mWidget->Width() != aWidth - || mWidget->Height() != aHeight)) { - mBounds.width = aWidth; - mBounds.height = aHeight; - - mWidget->Resize(aWidth,aHeight); - - if (mListenForResizes) { - nsSizeEvent sevent; - nsRect rect(0,0,aWidth,aHeight); - - sevent.message = NS_SIZE; - sevent.widget = this; - sevent.eventStructType = NS_SIZE_EVENT; - sevent.windowSize = ▭ - sevent.point.x = 0; - sevent.point.y = 0; - sevent.mWinWidth = aWidth; - sevent.mWinHeight = aHeight; - sevent.time = PR_IntervalNow(); - NS_ADDREF_THIS(); - OnResize(sevent); - NS_RELEASE_THIS(); - } - if (aRepaint) { - if (mWidget->IsVisible()) { - mWidget->Repaint(false); - } - } - } - return NS_OK; -} - -NS_METHOD 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; - PRBool ret; - - InitEvent(event, NS_SIZE); - event.eventStructType = NS_SIZE_EVENT; - - nsRect foo(0,0,aRect.width,aRect.height); - event.windowSize = &foo; - - event.point.x = 0; - event.point.y = 0; - event.mWinWidth = aRect.width; - event.mWinHeight = aRect.height; - - NS_ADDREF_THIS(); - ret = OnResize(event); - NS_RELEASE_THIS(); - - return ret; -} - -PRBool nsWidget::OnMove(PRInt32 aX, PRInt32 aY) -{ - nsGUIEvent event; - - mBounds.x = aX; - mBounds.y = aY; - InitEvent(event,NS_MOVE); - event.point.x = aX; - event.point.y = aY; - event.eventStructType = NS_GUI_EVENT; - PRBool result = DispatchWindowEvent(&event); - return result; -} - -//------------------------------------------------------------------------- -// Enable/disable this component -//------------------------------------------------------------------------- -NS_METHOD nsWidget::Enable(PRBool aState) -{ - if (mWidget) { - mWidget->Enable(aState); - } - return NS_OK; -} - -NS_METHOD nsWidget::IsEnabled(PRBool *aState) -{ - NS_ENSURE_ARG_POINTER(aState); - *aState = PR_TRUE; - return NS_ERROR_NOT_IMPLEMENTED; -} - -//------------------------------------------------------------------------- -// Give the focus to this component -//------------------------------------------------------------------------- -NS_METHOD nsWidget::SetFocus(PRBool aRaise) -{ - if (mWidget) { - mWidget->SetFocus(); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Get this component font -//------------------------------------------------------------------------- -nsIFontMetrics *nsWidget::GetFont(void) -{ - NS_NOTYETIMPLEMENTED("nsWidget::GetFont"); - return nsnull; -} - -//------------------------------------------------------------------------- -// Set this component font -//------------------------------------------------------------------------- -NS_METHOD nsWidget::SetFont(const nsFont &aFont) -{ - nsCOMPtr fontMetrics; - mContext->GetMetricsFor(aFont,*getter_AddRefs(fontMetrics)); - - if (!fontMetrics) - return NS_ERROR_FAILURE; - - nsFontHandle fontHandle; - fontMetrics->GetFontHandle(fontHandle); - - if (fontHandle && mWidget) { - nsFontQT *qtFontHandle = (nsFontQT*)fontHandle; - - mWidget->SetFont(qtFontHandle); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Set the background color -//------------------------------------------------------------------------- -NS_METHOD nsWidget::SetBackgroundColor(const nscolor &aColor) -{ - nsBaseWidget::SetBackgroundColor(aColor); - - if (mWidget) { - mWidget->SetBackgroundColor(aColor); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// Set this component cursor -//------------------------------------------------------------------------- -NS_METHOD nsWidget::SetCursor(nsCursor aCursor) -{ - if (mWidget) { - if (mCursor != aCursor) { - mWidget->SetCursor(aCursor); - mCursor = aCursor; - } - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -NS_METHOD nsWidget::Invalidate(PRBool aIsSynchronous) -{ - if (!mWidget) - return NS_OK; // mWidget will be null during printing. - - if (aIsSynchronous) { - mWidget->Repaint(false); - mUpdateArea->SetTo(0,0,0,0); - } - else { - mWidget->Update(); - mUpdateArea->SetTo(0,0,mBounds.width,mBounds.height); - } - return NS_OK; -} - -NS_METHOD nsWidget::Invalidate(const nsRect &aRect,PRBool aIsSynchronous) -{ - if (mWidget == nsnull) { - return NS_OK; // mWidget is null during printing - } - mUpdateArea->Union(aRect.x,aRect.y,aRect.width,aRect.height); - if (aIsSynchronous) { - mWidget->Repaint(aRect.x,aRect.y,aRect.width,aRect.height,false); - } - else { - mWidget->Update(aRect.x,aRect.y,aRect.width,aRect.height); - } - return NS_OK; -} - -NS_IMETHODIMP nsWidget::InvalidateRegion(const nsIRegion *aRegion, - PRBool aIsSynchronous) -{ - nsRegionRectSet *regionRectSet = nsnull; - - if (!mWidget) - return NS_OK; - - mUpdateArea->Union(*aRegion); - - if (NS_FAILED(mUpdateArea->GetRects(®ionRectSet))) - return NS_ERROR_FAILURE; - - PRUint32 len; - PRUint32 i; - - len = regionRectSet->mRectsLen; - - for (i = 0; i < len; ++i) { - nsRegionRect *r = &(regionRectSet->mRects[i]); - - if (aIsSynchronous) - mWidget->Repaint(r->x,r->y,r->width,r->height,false); - else - mWidget->Update(r->x,r->y,r->width,r->height); - } - // drop the const.. whats the right thing to do here? - ((nsIRegion*)aRegion)->FreeRects(regionRectSet); - - return NS_OK; -} - -NS_METHOD nsWidget::Update(void) -{ - if (mIsDestroying) - return NS_ERROR_FAILURE; - - 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 mWidget->GetNativeWindow(); - break; - - case NS_NATIVE_DISPLAY: - if (mWidget) - return mWidget->X11Display(); - break; - - case NS_NATIVE_WIDGET: - if (mWidget) - return mWidget->GetNativeWidget(); - break; - - case NS_NATIVE_PLUGIN_PORT: - if (mWidget) - return mWidget->WinID(); - break; - - default: - break; - } - return nsnull; -} - -//------------------------------------------------------------------------- -// Set the colormap of the window -//------------------------------------------------------------------------- -NS_METHOD nsWidget::SetColorMap(nsColorMap *aColorMap) -{ - return NS_OK; -} - -//Stub for nsWindow functionality -NS_METHOD nsWidget::Scroll(PRInt32 aDx,PRInt32 aDy,nsRect *aClipRect) -{ - return NS_ERROR_FAILURE; -} - -NS_METHOD nsWidget::BeginResizingChildren(void) -{ - return NS_OK; -} - -NS_METHOD nsWidget::EndResizingChildren(void) -{ - return NS_OK; -} - -NS_METHOD nsWidget::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) -{ - aWidth = mPreferredWidth; - aHeight = mPreferredHeight; - return (mPreferredWidth != 0 && mPreferredHeight != 0) ? NS_OK - : NS_ERROR_FAILURE; -} - -NS_METHOD nsWidget::SetPreferredSize(PRInt32 aWidth,PRInt32 aHeight) -{ - mPreferredWidth = aWidth; - mPreferredHeight = aHeight; - return NS_OK; -} - -NS_METHOD nsWidget::SetTitle(const nsString &aTitle) -{ - if (mWidget) { - char *title = ToNewCString(aTitle); - - mWidget->SetTitle(title); - nsMemory::Free(title); - } - return NS_OK; -} - -nsresult nsWidget::CreateWidget(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData, - nsNativeWidget aNativeParent) -{ - QWidget *parentWidget = nsnull; - nsIWidget *baseParent; - - baseParent = aInitData - && (aInitData->mWindowType == eWindowType_dialog - || aInitData->mWindowType == eWindowType_toplevel) - ? nsnull : aParent; - - BaseCreate(baseParent,aRect,aHandleEventFunction,aContext, - aAppShell,aToolkit,aInitData); - - mParent = aParent; - if (aNativeParent) { - parentWidget = (QWidget*)aNativeParent; - mListenForResizes = PR_TRUE; - } - else if (aParent) { - parentWidget = (QWidget*)aParent->GetNativeData(NS_NATIVE_WIDGET); - } - mBounds = aRect; - - CreateNative(parentWidget); - Resize(aRect.width,aRect.height,PR_FALSE); - mWidget->Polish(); - if (mIsToplevel) { - /* We have to Spin the Qt Event loop to make top level windows */ - /* come up with the correct size, but it creates problems for */ - /* menus, etc. */ - qApp->processEvents(1); - } - DispatchStandardEvent(NS_CREATE); - return NS_OK; -} - -//------------------------------------------------------------------------- -// create with nsIWidget parent -//------------------------------------------------------------------------- -NS_METHOD 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_METHOD 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, - PRUint32 aEventType, - nsPoint* aPoint) -{ - event.widget = this; - - if (aPoint == nsnull) { - event.point.x = 0; - event.point.y = 0; - } - else { - // use the point override if provided - event.point.x = aPoint->x; - event.point.y = aPoint->y; - } - event.time = PR_IntervalNow(); - event.message = aEventType; -} - -PRBool nsWidget::ConvertStatus(nsEventStatus aStatus) -{ - switch(aStatus) { - case nsEventStatus_eIgnore: - return(PR_FALSE); - - case nsEventStatus_eConsumeNoDefault: - return(PR_TRUE); - - case nsEventStatus_eConsumeDoDefault: - return(PR_FALSE); - - default: - NS_ASSERTION(0,"Illegal nsEventStatus enumeration value"); - break; - } - return(PR_FALSE); -} - -PRBool nsWidget::DispatchWindowEvent(nsGUIEvent* event) -{ - nsEventStatus status; - DispatchEvent(event,status); - return ConvertStatus(status); -} - -//------------------------------------------------------------------------- -// Dispatch standard event -//------------------------------------------------------------------------- -PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg) -{ - nsGUIEvent event; - event.eventStructType = NS_GUI_EVENT; - InitEvent(event,aMsg); - - PRBool result = DispatchWindowEvent(&event); - return result; -} - -//------------------------------------------------------------------------- -// Invokes callback and ProcessEvent method on Event Listener object -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent *event, - nsEventStatus &aStatus) -{ - NS_IF_ADDREF(event->widget); - if (nsnull != mMenuListener) { - if (NS_MENU_EVENT == event->eventStructType) - aStatus = mMenuListener->MenuSelected(NS_STATIC_CAST(nsMenuEvent&, - *event)); - } - aStatus = nsEventStatus_eIgnore; - if (nsnull != mEventCallback) { - aStatus = (*mEventCallback)(event); - } - // Dispatch to event listener if event was not consumed - if (aStatus != nsEventStatus_eIgnore && nsnull != mEventListener) { - aStatus = mEventListener->ProcessEvent(*event); - } - NS_IF_RELEASE(event->widget); - return NS_OK; -} - -PRBool nsWidget::DispatchMouseScrollEvent(nsMouseScrollEvent& aEvent) -{ - if (nsnull != mEventCallback) { - return DispatchWindowEvent(&aEvent); - } - return PR_FALSE; -} - -//------------------------------------------------------------------------- -// Deal with all sorts of mouse event -//------------------------------------------------------------------------- -PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) -{ - PRBool result = PR_FALSE; - - if (nsnull == mWidget - || (nsnull == mEventCallback && nsnull == mMouseListener)) { - return result; - } - if (aEvent.message == NS_MOUSE_LEFT_BUTTON_DOWN - || aEvent.message == NS_MOUSE_RIGHT_BUTTON_DOWN - || aEvent.message == NS_MOUSE_MIDDLE_BUTTON_DOWN) { - if (mWidget->HandlePopup((void*)aEvent.nativeMsg)) - return result; - } - // call the event callback - if (nsnull != mEventCallback) { - result = DispatchWindowEvent(&aEvent); - - return result; - } - if (nsnull != mMouseListener) { - switch (aEvent.message) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: - result = ConvertStatus(mMouseListener->MousePressed(aEvent)); - break; - - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: - result = ConvertStatus(mMouseListener->MouseReleased(aEvent)); - result = ConvertStatus(mMouseListener->MouseClicked(aEvent)); - break; - - default: - break; - } // switch - } - return result; -} - -// HandlePopup -// Deal with rollup of popups (xpmenus, etc) -PRBool nsWidget::HandlePopup(PRInt32 inMouseX,PRInt32 inMouseY) -{ - PRBool retVal = PR_FALSE; - nsCOMPtr rollupWidget = do_QueryReferent(gRollupWidget); - if (rollupWidget && gRollupListener) { - void *currentPopup = rollupWidget->GetNativeData(NS_NATIVE_WIDGET); - if (currentPopup - && !NS_IsMouseInWindow(currentPopup,inMouseX,inMouseY)) { - PRBool rollup = PR_TRUE; - // if we're dealing with menus, we probably have submenus and we don't - // want to rollup if the clickis in a parent menu of the current submenu - 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) { - void *currWindow = widget->GetNativeData(NS_NATIVE_WIDGET); - if (currWindow - && NS_IsMouseInWindow(currWindow,inMouseX,inMouseY)) { - rollup = PR_FALSE; - break; - } - } - } // foreach parent menu widget - } - } // if rollup listener knows about menus - // if we've determined that we should still rollup, do it. - if (rollup) { - gRollupListener->Rollup(); - retVal = PR_TRUE; - } - } - } - else { - gRollupWidget = nsnull; - gRollupListener = nsnull; - } - return retVal; -} // HandlePopup - -//------------------------------------------------------------------------- -// Base implementation of CreateNative. -//------------------------------------------------------------------------- -NS_METHOD nsWidget::CreateNative(QWidget *parentWindow) -{ - if (!mWidget) - return NS_ERROR_FAILURE; - - return NS_OK; -} - -NS_IMETHODIMP nsWidget::ResetInputState() -{ - return NS_OK; -} - -NS_IMETHODIMP nsWidget::PasswordFieldInit() -{ - return NS_OK; -} diff --git a/widget/src/qt/nsWidget.h b/widget/src/qt/nsWidget.h deleted file mode 100644 index 3828540ed753..000000000000 --- a/widget/src/qt/nsWidget.h +++ /dev/null @@ -1,199 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * Wes Morgan - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef nsWidget_h__ -#define nsWidget_h__ - -#include "nsBaseWidget.h" -#include "nsWeakReference.h" -#include "nsIKBStateControl.h" -#include "nsWidgetsCID.h" -#include "nsIRegion.h" -#include "nsIRollupListener.h" -#include "nsLookAndFeel.h" -#include "nsQWidget.h" - -class nsIAppShell; -class nsIToolkit; - -class nsWidget : public nsBaseWidget, public nsIKBStateControl, 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); - - NS_IMETHOD Destroy(void); - nsIWidget* GetParent(void); - - NS_IMETHOD SetModal(PRBool aModal); - 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); - - PRBool OnResize(nsSizeEvent event); - virtual PRBool OnResize(nsRect &aRect); - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - - 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); - - NS_IMETHOD SetTitle(const nsString& 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); - NS_IMETHOD SetMenuBar(nsIMenuBar *aMenuBar) { return NS_ERROR_FAILURE; } - NS_IMETHOD ShowMenuBar(PRBool aShow) { return NS_ERROR_FAILURE; } - NS_IMETHOD CaptureMouse(PRBool aCapture) { return NS_ERROR_FAILURE; } - virtual PRBool OnPaint(nsPaintEvent &event) { return PR_FALSE; }; - virtual PRBool OnKey(nsKeyEvent &aEvent) { return PR_FALSE; }; - virtual PRBool OnText(nsTextEvent &aEvent) { return PR_FALSE; }; - virtual PRBool OnComposition(nsCompositionEvent &aEvent) { return PR_FALSE; }; - virtual PRBool DispatchFocus(nsGUIEvent &aEvent) { return PR_FALSE; }; - virtual PRBool DispatchFocusInEvent() { return PR_FALSE; }; - virtual PRBool DispatchFocusOutEvent() { return PR_FALSE; }; - virtual PRBool DispatchActivateEvent() { return PR_FALSE; }; - - 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 PasswordFieldInit(); - - void InitEvent(nsGUIEvent& event,PRUint32 aEventType,nsPoint* aPoint = nsnull); - - // Utility functions - const char *GetName(); - PRBool ConvertStatus(nsEventStatus aStatus); - PRBool DispatchMouseEvent(nsMouseEvent& aEvent); - PRBool DispatchStandardEvent(PRUint32 aMsg); - PRBool DispatchMouseScrollEvent(nsMouseScrollEvent& aEvent); - - virtual PRBool IsPopup() const { return PR_FALSE; }; - virtual PRBool IsDialog() const { return PR_FALSE; }; - - // Deal with rollup for popups - PRBool HandlePopup(PRInt32 inMouseX,PRInt32 inMouseY); - -protected: - virtual void InitCallbacks(char * aName = nsnull); - virtual void OnDestroy(); - - NS_IMETHOD CreateNative(QWidget *parentWindow); - - 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); - -protected: - nsQBaseWidget *mWidget; - nsCOMPtr mParent; - - // composite update area - union of all Invalidate calls - nsCOMPtr mUpdateArea; - PRUint32 mPreferredWidth; - PRUint32 mPreferredHeight; - PRBool mListenForResizes; - PRBool mIsToplevel; - PRUint32 mWidgetID; - - // this is the rollup listener variables - static nsCOMPtr gRollupListener; - static nsWeakPtr gRollupWidget; - static PRBool gRollupConsumeRollupEvent; -}; - -#endif /* nsWidget_h__ */ diff --git a/widget/src/qt/nsWidgetFactory.cpp b/widget/src/qt/nsWidgetFactory.cpp deleted file mode 100644 index 18691b3442e8..000000000000 --- a/widget/src/qt/nsWidgetFactory.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * 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 NPL, 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 NPL, 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 "nsScrollbar.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(nsBidiKeyboard) - -static nsresult nsHorizScrollbarConstructor(nsISupports *aOuter,REFNSIID aIID, - void **aResult) -{ - nsresult rv; - nsISupports *inst = nsnull; - - if (NULL == aResult) { - rv = NS_ERROR_NULL_POINTER; - return rv; - } - *aResult = NULL; - if (NULL != aOuter) { - rv = NS_ERROR_NO_AGGREGATION; - return rv; - } - inst = (nsISupports*)(nsBaseWidget*)(nsWidget*)new nsScrollbar(PR_FALSE); - if (inst == NULL) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(inst); - rv = inst->QueryInterface(aIID,aResult); - NS_RELEASE(inst); - - return rv; -} - -static nsresult nsVertScrollbarConstructor(nsISupports *aOuter,REFNSIID aIID, - void **aResult) -{ - nsresult rv; - nsISupports *inst = nsnull; - - if (NULL == aResult) { - rv = NS_ERROR_NULL_POINTER; - return rv; - } - *aResult = NULL; - if (NULL != aOuter) { - rv = NS_ERROR_NO_AGGREGATION; - return rv; - } - inst = (nsISupports*)(nsBaseWidget*)(nsWidget*)new nsScrollbar(PR_TRUE); - if (inst == NULL) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(inst); - rv = inst->QueryInterface(aIID, aResult); - NS_RELEASE(inst); - - return rv; -} - -static const nsModuleComponentInfo components[] = -{ - { "Qt nsWindow", - NS_WINDOW_CID, - "@mozilla.org/widgets/window/qt;1", - nsWindowConstructor }, - { "Qt Child nsWindow", - NS_CHILD_CID, - "@mozilla.org/widgets/child_window/qt;1", - ChildWindowConstructor }, - { "Qt Horiz Scrollbar", - NS_HORZSCROLLBAR_CID, - "@mozilla.org/widgets/horizscroll/qt;1", - nsHorizScrollbarConstructor }, - { "Qt Vert Scrollbar", - NS_VERTSCROLLBAR_CID, - "@mozilla.org/widgets/vertscroll/qt;1", - nsVertScrollbarConstructor }, - { "Qt AppShell", - NS_APPSHELL_CID, - "@mozilla.org/widget/appshell/qt;1", - nsAppShellConstructor }, - { "Qt Toolkit", - NS_TOOLKIT_CID, - "@mozilla.org/widget/toolkit/qt;1", - nsToolkitConstructor }, - { "Qt Look And Feel", - NS_LOOKANDFEEL_CID, - "@mozilla.org/widget/lookandfeel/qt;1", - nsLookAndFeelConstructor }, - { "Transferrable", - NS_TRANSFERABLE_CID, - "@mozilla.org/widget/transferable;1", - nsTransferableConstructor }, - { "Qt Clipboard", - NS_CLIPBOARD_CID, - "@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/qt;1", - nsHTMLFormatConverterConstructor }, - { "Qt Drag Service", - NS_DRAGSERVICE_CID, - "@mozilla.org/widget/dragservice;1", - nsDragServiceConstructor }, - { "Qt Bidi Keyboard", - NS_BIDIKEYBOARD_CID, - "@mozilla.org/widget/bidikeyboard;1", - nsBidiKeyboardConstructor } -}; - -NS_IMPL_NSGETMODULE(nsWidgetQTModule,components) diff --git a/widget/src/qt/nsWindow.cpp b/widget/src/qt/nsWindow.cpp deleted file mode 100644 index 0db6f4a7eaaa..000000000000 --- a/widget/src/qt/nsWindow.cpp +++ /dev/null @@ -1,537 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsIServiceManager.h" -#include "nsQWidget.h" -#include "nsWindow.h" -#include "nsGUIEvent.h" -#include "nsIRenderingContext.h" -#include "nsRect.h" -#include "nsGfxCIID.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" - -#include - -//JCG #define DBG_JCG = 1 - -#ifdef DBG_JCG -static PRInt32 gWindowCount = 0; -static PRInt32 gWindowID = 0; -static PRInt32 gChildCount = 0; -static PRInt32 gChildID = 0; -#endif - -PRBool nsWindow::mIsGrabbing = PR_FALSE; -nsWindow *nsWindow::mGrabWindow = NULL; -nsQBaseWidget *nsWindow::mFocusWidget = NULL; -PRBool nsWindow::mGlobalsInitialized = PR_FALSE; -PRBool nsWindow::mRaiseWindows = PR_TRUE; -PRBool nsWindow::mGotActivate = PR_FALSE; - -NS_IMPL_ISUPPORTS_INHERITED0(nsWindow, nsWidget) - -//------------------------------------------------------------------------- -// nsWindow constructor -//------------------------------------------------------------------------- -nsWindow::nsWindow() -{ -#ifdef DBG_JCG - gWindowCount++; - mWindowID = gWindowID++; - printf("JCG: nsWindow CTOR. (%p) ID: %d, Count: %d\n",this,mWindowID,gWindowCount); -#endif - mIsDialog = PR_FALSE; - mIsPopup = PR_FALSE; - mBlockFocusEvents = PR_FALSE; - mWindowType = eWindowType_child; - mBorderStyle = eBorderStyle_default; - // initialize globals - if (!mGlobalsInitialized) { - mGlobalsInitialized = PR_TRUE; - - // check to see if we should set our raise pref - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - PRBool val = PR_TRUE; - nsresult rv = prefBranch->GetBoolPref("mozilla.widget.raise-on-setfocus", - &val); - if (NS_SUCCEEDED(rv)) - mRaiseWindows = val; - } - } -} - -//------------------------------------------------------------------------- -// nsWindow destructor -//------------------------------------------------------------------------- -nsWindow::~nsWindow() -{ -#ifdef DBG_JCG - gWindowCount--; - printf("JCG: nsWindow DTOR. (%p) ID: %d, Count: %d\n",this,mWindowID,gWindowCount); -#endif - // make sure that we release the grab indicator here - if (mGrabWindow == this) { - mIsGrabbing = PR_FALSE; - mGrabWindow = NULL; - } -} - -//------------------------------------------------------------------------- -PRBool nsWindow::IsChild() const -{ - return PR_FALSE; -} - -//------------------------------------------------------------------------- -void nsWindow::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY) -{ -} - -//------------------------------------------------------------------------- -// Setup initial tooltip rectangles -//------------------------------------------------------------------------- -NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips, - nsRect *aTooltipAreas[]) -{ - return NS_OK; -} - -//------------------------------------------------------------------------- -// Update all tooltip rectangles -//------------------------------------------------------------------------- -NS_METHOD nsWindow::UpdateTooltips(nsRect* aNewTips[]) -{ - return NS_OK; -} - -//------------------------------------------------------------------------- -// Remove all tooltip rectangles -//------------------------------------------------------------------------- -NS_METHOD nsWindow::RemoveTooltips() -{ - return NS_OK; -} - -NS_METHOD nsWindow::SetFocus(PRBool aRaise) -{ - if (mBlockFocusEvents) { - return NS_OK; - } - PRBool sendActivate = mGotActivate; - - mGotActivate = PR_FALSE; - if (mWidget) { - if (!mWidget->IsTopLevelActive()) { - if (aRaise && mRaiseWindows) { - mWidget->RaiseTopLevel(); - } - mBlockFocusEvents = PR_TRUE; - mWidget->SetTopLevelFocus(); - mBlockFocusEvents = PR_FALSE; - mGotActivate = PR_TRUE; - } - else { - if (mWidget == mFocusWidget) { - return NS_OK; - } - else { - mFocusWidget = mWidget; - } - } - } - DispatchFocusInEvent(); - if (sendActivate) { - mGotActivate = PR_FALSE; - DispatchActivateEvent(); - } - return NS_OK; -} - -NS_METHOD nsWindow::PreCreateWidget(nsWidgetInitData *aInitData) -{ - if (nsnull != aInitData) { - SetWindowType(aInitData->mWindowType); - SetBorderStyle(aInitData->mBorderStyle); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -//------------------------------------------------------------------------- -// Create the native widget -//------------------------------------------------------------------------- -NS_METHOD nsWindow::CreateNative(QWidget *parentWidget) -{ - switch (mWindowType) { - case eWindowType_toplevel: -#ifdef DBG_JCG - printf("JCG: Top Level Create: %p\n",this); -#endif - break; - - case eWindowType_dialog: -#ifdef DBG_JCG - printf("JCG: Dialog Create: %p\n",this); -#endif - mIsDialog = PR_TRUE; - break; - - case eWindowType_popup: -#ifdef DBG_JCG - printf("JCG: Popup Create: %p\n",this); -#endif - mIsPopup = PR_TRUE; - break; - - case eWindowType_child: -#ifdef DBG_JCG - printf("JCG: Child Create: %p\n",this); -#endif - break; - } - mWidget = new nsQBaseWidget(this); - - if (!mWidget) - return NS_ERROR_OUT_OF_MEMORY; - - if (!mWidget->CreateNative(parentWidget,QWidget::tr("nsWindow"), - NS_GetQWFlags(mBorderStyle,mWindowType))) { - delete mWidget; - mWidget = nsnull; - return NS_ERROR_OUT_OF_MEMORY; - } - if (!parentWidget && !mIsDialog) { - // This is a top-level window. I'm not sure what special actions - // need to be taken here. - mIsToplevel = PR_TRUE; - mListenForResizes = PR_TRUE; - } - else { - mIsToplevel = PR_FALSE; - } - return nsWidget::CreateNative(parentWidget); -} - - -//------------------------------------------------------------------------- -// Initialize all the Callbacks -//------------------------------------------------------------------------- -void nsWindow::InitCallbacks(char *aName) -{ -} - -//------------------------------------------------------------------------- -// Set the colormap of the window -//------------------------------------------------------------------------- -NS_METHOD nsWindow::SetColorMap(nsColorMap *aColorMap) -{ - return NS_OK; -} - -//------------------------------------------------------------------------- -// Scroll the bits of a window -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Scroll(PRInt32 aDx,PRInt32 aDy,nsRect *aClipRect) -{ - if (mWidget) { - mWidget->Scroll(aDx,aDy); - } - return NS_OK; -} - -/* Processes an Expose Event */ -PRBool nsWindow::OnPaint(nsPaintEvent &event) -{ - nsresult result; - PRInt32 x; - PRInt32 y; - PRInt32 width; - PRInt32 height; - - // call the event callback - if (mEventCallback) { - event.renderingContext = nsnull; - if (event.rect) { - x = event.rect->x; - y = event.rect->y; - width = event.rect->width; - height = event.rect->height; - } - else { - x = 0; - y = 0; - if (mWidget) { - width = mWidget->Width(); - height = mWidget->Height(); - } - else { - width = 0; - height = 0; - } - } - static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID); - static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID); - if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID, - nsnull, - kRenderingContextIID, - (void **)&event.renderingContext)) { - if (mBounds.width && mBounds.height) { - event.renderingContext->Init(mContext, this); - result = DispatchWindowEvent(&event); - NS_IF_RELEASE(event.renderingContext); - } - } - else { - result = PR_FALSE; - } - } - return result; -} - -NS_METHOD nsWindow::BeginResizingChildren(void) -{ - return NS_OK; -} - -NS_METHOD nsWindow::EndResizingChildren(void) -{ - return NS_OK; -} - -PRBool nsWindow::OnKey(nsKeyEvent &aEvent) -{ - if (mEventCallback) { - return DispatchWindowEvent(&aEvent); - } - return PR_FALSE; -} - -PRBool nsWindow::OnText(nsTextEvent &aEvent) -{ - if (mEventCallback) { - return DispatchWindowEvent(&aEvent); - } - return PR_FALSE; -} - -PRBool nsWindow::OnComposition(nsCompositionEvent &aEvent) -{ - if (mEventCallback) { - return DispatchWindowEvent(&aEvent); - } - return PR_FALSE; -} - -PRBool nsWindow::DispatchActivateEvent() -{ - nsGUIEvent nsEvent; - - nsEvent.message = NS_ACTIVATE; - nsEvent.eventStructType = NS_GUI_EVENT; - nsEvent.widget = this; - nsEvent.time = 0; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - - return DispatchFocus(nsEvent); -} - -PRBool nsWindow::DispatchFocusOutEvent() -{ - nsGUIEvent nsEvent; - - if (mFocusWidget == mWidget) - mFocusWidget = nsnull; - - nsEvent.message = NS_LOSTFOCUS; - nsEvent.eventStructType = NS_GUI_EVENT; - nsEvent.widget = this; - nsEvent.time = 0; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - - return DispatchFocus(nsEvent); -} - -PRBool nsWindow::DispatchFocusInEvent() -{ - if (mBlockFocusEvents) { - return PR_TRUE; - } - PRBool ret; - nsGUIEvent nsEvent; - - nsEvent.message = NS_GOTFOCUS; - nsEvent.eventStructType = NS_GUI_EVENT; - nsEvent.widget = this; - nsEvent.time = 0; - nsEvent.point.x = 0; - nsEvent.point.y = 0; - - mBlockFocusEvents = PR_TRUE; - ret = DispatchFocus(nsEvent); - mBlockFocusEvents = PR_FALSE; - return ret; -} - -PRBool nsWindow::DispatchFocus(nsGUIEvent &aEvent) -{ - if (mEventCallback) { - return DispatchWindowEvent(&aEvent); - } - return PR_FALSE; -} - -NS_METHOD nsWindow::GetClientBounds(nsRect &aRect) -{ - return GetBounds(aRect); -} - -NS_METHOD nsWindow::GetBounds(nsRect &aRect) -{ - nsRect Rct(mWidget->BoundsX(),mWidget->BoundsX(), - mWidget->Width(),mWidget->Height()); - - aRect = Rct; - return NS_OK; -} - -NS_IMETHODIMP nsWindow::GetScreenBounds(nsRect &aRect) -{ - nsRect nBounds(0,0,mBounds.width,mBounds.height); - - aRect = nBounds; - return NS_OK; -} - -NS_METHOD nsWindow::GetBoundsAppUnits(nsRect &aRect, float aAppUnits) -{ - GetBounds(aRect); - - // Convert to twips - aRect.x = nscoord((PRFloat64)aRect.x * aAppUnits); - aRect.y = nscoord((PRFloat64)aRect.y * aAppUnits); - aRect.width = nscoord((PRFloat64)aRect.width * aAppUnits); - aRect.height = nscoord((PRFloat64)aRect.height * aAppUnits); - return NS_OK; -} - -PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos) -{ - return PR_FALSE; -} - -NS_METHOD nsWindow::ConstrainPosition(PRBool aAllowSlop, - PRInt32 *aX, PRInt32 *aY) -{ - return NS_OK; -} - -NS_METHOD nsWindow::Move(PRInt32 aX, PRInt32 aY) -{ - if (mWidget && mParent && mWindowType == eWindowType_popup) { - nsRect oldrect, newrect; - - mBounds.x = aX; - mBounds.y = aY; - - oldrect.x = aX; - oldrect.y = aY; - mParent->WidgetToScreen(oldrect,newrect); - mWidget->Move(newrect.x,newrect.y); - - return NS_OK; - } - else - return(nsWidget::Move(aX,aY)); -} - -NS_IMETHODIMP nsWindow::CaptureRollupEvents(nsIRollupListener *aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent) -{ - if (aDoCapture) { - /* Create a pointer region */ - mIsGrabbing = PR_TRUE; - mGrabWindow = this; - - gRollupConsumeRollupEvent = PR_TRUE; - gRollupListener = aListener; - gRollupWidget = getter_AddRefs(NS_GetWeakReference(NS_STATIC_CAST(nsIWidget*,this))); - } - else { - // make sure that the grab window is marked as released - if (mGrabWindow == this) { - mGrabWindow = NULL; - } - mIsGrabbing = PR_FALSE; - - gRollupListener = nsnull; - gRollupWidget = nsnull; - } - return NS_OK; -} - -////////////////////////////////////////////////////////////////////// -ChildWindow::ChildWindow() -{ -#ifdef DBG_JCG - gChildCount++; - mChildID = gChildID++; - printf("JCG: nsChildWindow CTOR. (%p) ID: %d, Count: %d\n",this,mChildID,gChildCount); -#endif -} - -ChildWindow::~ChildWindow() -{ -#ifdef NOISY_DESTROY - IndentByDepth(stdout); - printf("ChildWindow::~ChildWindow:%p\n", this); -#endif -#ifdef DBG_JCG - gChildCount--; - printf("JCG: nsChildWindow DTOR. (%p) ID: %d, Count: %d\n",this,mChildID,gChildCount); -#endif -} - -PRBool ChildWindow::IsChild() const -{ - return PR_TRUE; -} diff --git a/widget/src/qt/nsWindow.h b/widget/src/qt/nsWindow.h deleted file mode 100644 index 82e270b6ddce..000000000000 --- a/widget/src/qt/nsWindow.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Netscape 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/NPL/ - * - * 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): - * John C. Griggs - * - * 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 NPL, 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 NPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#ifndef Window_h__ -#define Window_h__ - -#include "nsWidget.h" - -/* Native QT window wrapper */ -class nsWindow : public nsWidget -{ -public: - nsWindow(); - virtual ~nsWindow(); - - // nsIsupports - NS_DECL_ISUPPORTS_INHERITED - - // nsIWidget interface - virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY); - - NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData); - - NS_IMETHOD SetColorMap(nsColorMap *aColorMap); - NS_IMETHOD Scroll(PRInt32 aDx,PRInt32 aDy,nsRect *aClipRect); - - NS_IMETHOD ConstrainPosition(PRBool aAllowSlop, PRInt32 *aX,PRInt32 *aY); - NS_IMETHOD Move(PRInt32 aX,PRInt32 aY); - - NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener, - PRBool aDoCapture, - PRBool aConsumeRollupEvent); - NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); - NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]); - NS_IMETHOD RemoveTooltips(); - - NS_IMETHOD BeginResizingChildren(void); - NS_IMETHOD EndResizingChildren(void); - NS_IMETHOD SetFocus(PRBool aRaise); - - NS_IMETHOD GetBounds(nsRect &aRect); - NS_IMETHOD GetBoundsAppUnits(nsRect &aRect,float aAppUnits); - NS_IMETHOD GetClientBounds(nsRect &aRect); - NS_IMETHOD GetScreenBounds(nsRect &aRect); - - virtual PRBool IsChild() const; - virtual PRBool IsPopup() const { return mIsPopup; }; - virtual PRBool IsDialog() const { return mIsDialog; }; - - // Utility methods - virtual PRBool OnPaint(nsPaintEvent &event); - virtual PRBool OnKey(nsKeyEvent &aEvent); - virtual PRBool OnText(nsTextEvent &aEvent); - virtual PRBool OnComposition(nsCompositionEvent &aEvent); - virtual PRBool DispatchFocusInEvent(); - virtual PRBool DispatchFocusOutEvent(); - virtual PRBool DispatchActivateEvent(); - virtual PRBool DispatchFocus(nsGUIEvent &aEvent); - virtual PRBool OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos); - -protected: - virtual void InitCallbacks(char *aName = nsnull); - NS_IMETHOD CreateNative(QWidget *parentWidget); - - PRBool mIsDialog; - PRBool mIsPopup; - PRBool mBlockFocusEvents; - - // are we doing a grab? - static PRBool mIsGrabbing; - static nsWindow *mGrabWindow; - static nsQBaseWidget *mFocusWidget; - static PRBool mGlobalsInitialized; - static PRBool mRaiseWindows; - static PRBool mGotActivate; - PRInt32 mWindowID; -}; - -// -// A child window is a window with different style -// -class ChildWindow : public nsWindow -{ -public: - ChildWindow(); - ~ChildWindow(); - virtual PRBool IsChild() const; - - PRInt32 mChildID; -}; - -#endif // Window_h__