From 9867c7247cef5a1c976e8e44c53a13d630bcf0ae Mon Sep 17 00:00:00 2001 From: "shaver%netscape.com" Date: Tue, 27 Oct 1998 15:43:49 +0000 Subject: [PATCH] ancient GTK port, as starting point git-svn-id: svn://10.0.0.236/trunk@13557 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/gtk/Makefile | 37 ++ mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp | 189 +++++++ mozilla/gfx/src/gtk/nsDeviceContextGTK.h | 84 +++ mozilla/gfx/src/gtk/nsDrawingSurfaceGTK.h | 14 + mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp | 137 +++++ mozilla/gfx/src/gtk/nsFontMetricsGTK.h | 82 +++ mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp | 172 +++++++ mozilla/gfx/src/gtk/nsImageGTK.cpp | 87 ++++ mozilla/gfx/src/gtk/nsImageGTK.h | 90 ++++ mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp | 477 ++++++++++++++++++ mozilla/gfx/src/gtk/nsRenderingContextGTK.h | 145 ++++++ 11 files changed, 1514 insertions(+) create mode 100644 mozilla/gfx/src/gtk/Makefile create mode 100644 mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp create mode 100644 mozilla/gfx/src/gtk/nsDeviceContextGTK.h create mode 100644 mozilla/gfx/src/gtk/nsDrawingSurfaceGTK.h create mode 100644 mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp create mode 100644 mozilla/gfx/src/gtk/nsFontMetricsGTK.h create mode 100644 mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp create mode 100644 mozilla/gfx/src/gtk/nsImageGTK.cpp create mode 100644 mozilla/gfx/src/gtk/nsImageGTK.h create mode 100644 mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp create mode 100644 mozilla/gfx/src/gtk/nsRenderingContextGTK.h diff --git a/mozilla/gfx/src/gtk/Makefile b/mozilla/gfx/src/gtk/Makefile new file mode 100644 index 00000000000..2b426d3ff20 --- /dev/null +++ b/mozilla/gfx/src/gtk/Makefile @@ -0,0 +1,37 @@ +#!gmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH = ../../.. + +include $(DEPTH)/config/config.mk + +LIBRARY_NAME = gfxgtk + +MODULE=raptor + +REQUIRES=util img xpcom raptor netlib + +LCFLAGS+=-D_IMPL_NS_GFXONXP -I/usr/lib/glib/include + +LLIBS+=$(DIST)/lib/libxpcom.a $(DIST)/lib/libraptorbase.a $(DIST)/lib/libraptorgfx.a + +CPPSRCS=nsDeviceContextGTK.cpp nsFontMetricsGTK.cpp nsGfxFactoryGTK.cpp \ + nsRenderingContextGTK.cpp nsImageGTK.cpp + +include $(DEPTH)/config/rules.mk + + diff --git a/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp b/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp new file mode 100644 index 00000000000..8d35c53c58b --- /dev/null +++ b/mozilla/gfx/src/gtk/nsDeviceContextGTK.cpp @@ -0,0 +1,189 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsDeviceContextGTK.h" +#include "nsRenderingContextGTK.h" +#include "../nsGfxCIID.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID); + +nsDeviceContextGTK :: nsDeviceContextGTK() +{ + NS_INIT_REFCNT(); + + mFontCache = nsnull; + mSurface = nsnull; +} + +nsDeviceContextGTK :: ~nsDeviceContextGTK() +{ + NS_IF_RELEASE(mFontCache); + + if (mSurface) delete mSurface; +} + +NS_IMPL_QUERY_INTERFACE(nsDeviceContextGTK, kDeviceContextIID) +NS_IMPL_ADDREF(nsDeviceContextGTK) +NS_IMPL_RELEASE(nsDeviceContextGTK) + +nsresult nsDeviceContextGTK :: Init() +{ + return NS_OK; +} + +float nsDeviceContextGTK :: GetTwipsToDevUnits() const +{ + return 0.0; +} + +float nsDeviceContextGTK :: GetDevUnitsToTwips() const +{ + return 0.0; +} + +void nsDeviceContextGTK :: SetAppUnitsToDevUnits(float aAppUnits) +{ +} + +void nsDeviceContextGTK :: SetDevUnitsToAppUnits(float aDevUnits) +{ +} + +float nsDeviceContextGTK :: GetAppUnitsToDevUnits() const +{ + return 0.0; +} + +float nsDeviceContextGTK :: GetDevUnitsToAppUnits() const +{ + return 0.0; +} + +float nsDeviceContextGTK :: GetScrollBarWidth() const +{ + return 0.0; +} + +float nsDeviceContextGTK :: GetScrollBarHeight() const +{ + return 0.0; +} + +nsIRenderingContext * nsDeviceContextGTK :: CreateRenderingContext(nsIView *aView) +{ + nsIRenderingContext *pContext = nsnull; + nsIWidget *win = aView->GetWidget(); + nsresult rv; + + mSurface = new nsDrawingSurfaceGTK(); + + mSurface->drawable = (GdkDrawable *)win->GetNativeData(NS_NATIVE_WINDOW); + mSurface->gc = (GdkGC *)win->GetNativeData(NS_NATIVE_GRAPHIC); + + static NS_DEFINE_IID(kRCCID, NS_RENDERING_CONTEXT_CID); + static NS_DEFINE_IID(kRCIID, NS_IRENDERING_CONTEXT_IID); + + rv = NSRepository::CreateInstance(kRCCID, nsnull, kRCIID, (void **)&pContext); + + if (NS_OK == rv) + InitRenderingContext(pContext, win); + + return pContext; +} + +void nsDeviceContextGTK :: InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWin) +{ + aContext->Init(this, aWin); +} + +nsIFontCache* nsDeviceContextGTK::GetFontCache() +{ + if (nsnull == mFontCache) { + if (NS_OK != CreateFontCache()) { + return nsnull; + } + } + NS_ADDREF(mFontCache); + return mFontCache; +} + +nsresult nsDeviceContextGTK::CreateFontCache() +{ +#if 0 + nsresult rv = NS_NewFontCache(&mFontCache); + if (NS_OK != rv) { + return rv; + } + mFontCache->Init(this); +#endif + return NS_OK; +} + +void nsDeviceContextGTK::FlushFontCache() +{ +} + + +nsIFontMetrics* nsDeviceContextGTK::GetMetricsFor(const nsFont& aFont) +{ + return nsnull; +} + +void nsDeviceContextGTK :: SetZoom(float aZoom) +{ +} + +float nsDeviceContextGTK :: GetZoom() const +{ + return 0.0; +} + +nsDrawingSurface nsDeviceContextGTK :: GetDrawingSurface(nsIRenderingContext &aContext) +{ + return ( aContext.CreateDrawingSurface(nsnull)); +} + +float nsDeviceContextGTK :: GetGamma(void) +{ + return mGammaValue; +} + +void nsDeviceContextGTK :: SetGamma(float aGamma) +{ + if (aGamma != mGammaValue) + { + //we don't need to-recorrect existing images for this case + //so pass in 1.0 for the current gamma regardless of what it + //really happens to be. existing images will get a one time + //re-correction when they're rendered the next time. MMP + + mGammaValue = aGamma; + } +} + +PRUint8 * nsDeviceContextGTK :: GetGammaTable(void) +{ + //XXX we really need to ref count this somehow. MMP + + return nsnull; +} + + + + diff --git a/mozilla/gfx/src/gtk/nsDeviceContextGTK.h b/mozilla/gfx/src/gtk/nsDeviceContextGTK.h new file mode 100644 index 00000000000..075835fabc1 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsDeviceContextGTK.h @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsDeviceContextGTK_h___ +#define nsDeviceContextGTK_h___ + +#include "nsIDeviceContext.h" +#include "nsUnitConversion.h" +#include "nsIFontCache.h" +#include "nsIWidget.h" +#include "nsIView.h" +#include "nsIRenderingContext.h" + +#include "nsDrawingSurfaceGTK.h" +#include "nsRenderingContextGTK.h" +#include + +class nsDeviceContextGTK : public nsIDeviceContext +{ +public: + nsDeviceContextGTK(); + + NS_DECL_ISUPPORTS + + virtual nsresult Init(); + + virtual nsIRenderingContext * CreateRenderingContext(nsIView *aView); + virtual void InitRenderingContext(nsIRenderingContext *aContext, nsIWidget *aWidget); + + virtual float GetTwipsToDevUnits() const; + virtual float GetDevUnitsToTwips() const; + + virtual void SetAppUnitsToDevUnits(float aAppUnits); + virtual void SetDevUnitsToAppUnits(float aDevUnits); + + virtual float GetAppUnitsToDevUnits() const; + virtual float GetDevUnitsToAppUnits() const; + + virtual float GetScrollBarWidth() const; + virtual float GetScrollBarHeight() const; + + virtual nsIFontCache * GetFontCache(); + virtual void FlushFontCache(); + + virtual nsIFontMetrics* GetMetricsFor(const nsFont& aFont); + + virtual void SetZoom(float aZoom); + virtual float GetZoom() const; + + virtual nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext); + + //functions for handling gamma correction of output device + virtual float GetGamma(void); + virtual void SetGamma(float aGamma); + + //XXX the return from this really needs to be ref counted somehow. MMP + virtual PRUint8 * GetGammaTable(void); + +protected: + ~nsDeviceContextGTK(); + nsresult CreateFontCache(); + + nsIFontCache *mFontCache; + float mGammaValue; + nsDrawingSurfaceGTK *mSurface; + +}; + +#endif /* nsDeviceContextGTK_h___ */ diff --git a/mozilla/gfx/src/gtk/nsDrawingSurfaceGTK.h b/mozilla/gfx/src/gtk/nsDrawingSurfaceGTK.h new file mode 100644 index 00000000000..fa564f86e29 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsDrawingSurfaceGTK.h @@ -0,0 +1,14 @@ +#ifndef nsDrawingSurfaceGTK_h__ +#define nsDrawingSurfaceGTK_h__ + +#include + +struct nsDrawingSurfaceGTK { + GdkDrawable *drawable; + GdkGC *gc; +}; + +typedef nsDrawingSurfaceGTK nsDrawingSurfaceGTK; + +#endif nsDrawingSurfaceGTK_h__ + diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp b/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp new file mode 100644 index 00000000000..635a240962e --- /dev/null +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.cpp @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsFontMetricsGTK.h" +#include + +static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID); + +nsFontMetricsGTK :: nsFontMetricsGTK() +{ + NS_INIT_REFCNT(); +} + +nsFontMetricsGTK :: ~nsFontMetricsGTK() +{ +} + +NS_IMPL_ISUPPORTS(nsFontMetricsGTK, kIFontMetricsIID) + +nsresult nsFontMetricsGTK :: Init(const nsFont& aFont, nsIDeviceContext* aCX) +{ + mFont = new nsFont(aFont); + mContext = aCX ; + + // QueryFont(); + return NS_OK; +} + +void nsFontMetricsGTK::QueryFont() +{ + const char * str = mFont->name.ToNewCString(); + mGdkFont = gdk_font_load(str); + delete str; + + // Get character sizes + float p2t = mContext->GetDevUnitsToAppUnits(); + for (int i = 0; i < 256; i++) + mCharWidths[i] = nscoord((gdk_char_width(mGdkFont, (gchar)i)), p2t); + +} + +nscoord nsFontMetricsGTK :: GetWidth(char ch) +{ + return mCharWidths[PRUint8(ch)]; +} + +nscoord nsFontMetricsGTK :: GetWidth(PRUnichar ch) +{ + if (ch < 256) + return mCharWidths[ch]; + return 0; /* XXX */ +} + +nscoord nsFontMetricsGTK :: GetWidth(const nsString& aString) +{ + const char *str = aString.ToNewCString(); + nscoord width = GetWidth(str); + delete str; + return width; +} + +nscoord nsFontMetricsGTK :: GetWidth(const char *aString) +{ + float p2t = mContext->GetDevUnitsToAppUnits(); + return nscoord((gdk_string_width(mGdkFont, (const gchar *)aString)), p2t); +} + +nscoord nsFontMetricsGTK :: GetWidth(const PRUnichar *aString, PRUint32 aLength) +{ + // XXX use native text measurement routine + nscoord sum = 0; + + PRUint8 ch; + while ((ch = PRUint8(*aString++)) != 0) { + sum += mCharWidths[ch]; + } + return sum; +} + +nscoord nsFontMetricsGTK :: GetHeight() +{ + return mGdkFont->descent + mGdkFont->ascent; +} + +nscoord nsFontMetricsGTK :: GetLeading() +{ + return 0; +} + +nscoord nsFontMetricsGTK :: GetMaxAscent() +{ + return mGdkFont->ascent; +} + +nscoord nsFontMetricsGTK :: GetMaxDescent() +{ + return mGdkFont->descent; +} + +nscoord nsFontMetricsGTK :: GetMaxAdvance() +{ + return ((XFontStruct *)GDK_FONT_XFONT(mGdkFont))->max_bounds.width; +} + +const nscoord * nsFontMetricsGTK :: GetWidths() +{ + return mCharWidths; +} + +const nsFont& nsFontMetricsGTK :: GetFont() +{ + return *mFont; +} + +nsFontHandle nsFontMetricsGTK :: GetFontHandle() +{ + return ((nsFontHandle)mGdkFont); +} + + + + diff --git a/mozilla/gfx/src/gtk/nsFontMetricsGTK.h b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h new file mode 100644 index 00000000000..4a90df3f33e --- /dev/null +++ b/mozilla/gfx/src/gtk/nsFontMetricsGTK.h @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsFontMetricsGTK_h__ +#define nsFontMetricsGTK_h__ + +#include "nsIFontMetrics.h" +#include "nsFont.h" +#include "nsString.h" +#include "nsUnitConversion.h" +#include "nsIDeviceContext.h" +#include "nsCRT.h" + +#include + +class nsFontMetricsGTK : public nsIFontMetrics +{ +public: + nsFontMetricsGTK(); + ~nsFontMetricsGTK(); + + void* operator new(size_t sz) { + void* rv = new char[sz]; + nsCRT::zero(rv, sz); + return rv; + } + + NS_DECL_ISUPPORTS + + virtual nsresult Init(const nsFont& aFont, nsIDeviceContext* aContext); + virtual nscoord GetWidth(char aC); + virtual nscoord GetWidth(PRUnichar aC); + virtual nscoord GetWidth(const nsString& aString); + virtual nscoord GetWidth(const char *aString); + virtual nscoord GetWidth(const PRUnichar *aString, PRUint32 aLength); + virtual nscoord GetHeight(); + virtual nscoord GetLeading(); + virtual nscoord GetMaxAscent(); + virtual nscoord GetMaxDescent(); + virtual nscoord GetMaxAdvance(); + virtual const nscoord *GetWidths(); + virtual const nsFont& GetFont(); + virtual nsFontHandle GetFontHandle(); + +protected: + void QueryFont(); + + nsFont *mFont; + nsIDeviceContext *mContext; + GdkFont *mGdkFont; + nscoord mCharWidths[256]; + nscoord mHeight; + nscoord mWidth; + nscoord mAscent; + nscoord mDescent; + nsFontMetricsGTK *mFontMetrics; + /* + XFontStruct *mFontInfo; + Font mFontHandle; + */ +}; + +#endif + + + + diff --git a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp new file mode 100644 index 00000000000..8f045f17ae5 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nscore.h" +#include "nsIFactory.h" +#include "nsISupports.h" +#include "../nsGfxCIID.h" +#include "nsFontMetricsGTK.h" +#include "nsRenderingContextGTK.h" +#include "nsImageGTK.h" +#include "nsDeviceContextGTK.h" +#include + +static NS_DEFINE_IID(kCFontMetrics, NS_FONT_METRICS_CID); +static NS_DEFINE_IID(kCRenderingContext, NS_RENDERING_CONTEXT_CID); +static NS_DEFINE_IID(kCImage, NS_IMAGE_CID); +static NS_DEFINE_IID(kCDeviceContext, NS_DEVICE_CONTEXT_CID); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + +class nsGfxFactoryGTK : public nsIFactory +{ + public: + // nsISupports methods + NS_IMETHOD QueryInterface(const nsIID &aIID, + void **aResult); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIFactory methods + NS_IMETHOD CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock); + + nsGfxFactoryGTK(const nsCID &aClass); + ~nsGfxFactoryGTK(); + + private: + nsrefcnt mRefCnt; + nsCID mClassID; +}; + +nsGfxFactoryGTK::nsGfxFactoryGTK(const nsCID &aClass) +{ + mRefCnt = 0; + mClassID = aClass; +} + +nsGfxFactoryGTK::~nsGfxFactoryGTK() +{ + NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); +} + +nsresult nsGfxFactoryGTK::QueryInterface(const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) { + return NS_ERROR_NULL_POINTER; + } + + // Always NULL result, in case of failure + *aResult = NULL; + + if (aIID.Equals(kISupportsIID)) { + *aResult = (void *)(nsISupports*)this; + } else if (aIID.Equals(kIFactoryIID)) { + *aResult = (void *)(nsIFactory*)this; + } + + if (*aResult == NULL) { + return NS_NOINTERFACE; + } + + AddRef(); // Increase reference count for caller + return NS_OK; +} + +nsrefcnt nsGfxFactoryGTK::AddRef() +{ + return ++mRefCnt; +} + +nsrefcnt nsGfxFactoryGTK::Release() +{ + if (--mRefCnt == 0) { + delete this; + return 0; // Don't access mRefCnt after deleting! + } + return mRefCnt; +} + +nsresult nsGfxFactoryGTK::CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) { + return NS_ERROR_NULL_POINTER; + } + + *aResult = NULL; + + nsISupports *inst = nsnull; + + if (mClassID.Equals(kCFontMetrics)) { + inst = (nsISupports *)new nsFontMetricsGTK(); + } + else if (mClassID.Equals(kCDeviceContext)) { + inst = (nsISupports *)new nsDeviceContextGTK(); + } + else if (mClassID.Equals(kCRenderingContext)) { + inst = (nsISupports *)new nsRenderingContextGTK(); + } + else if (mClassID.Equals(kCImage)) { + inst = (nsISupports *)new nsImageGTK(); + } + + if (inst == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + + nsresult res = inst->QueryInterface(aIID, aResult); + + if (res != NS_OK) { + // We didn't get the right interface, so clean up + delete inst; + } +// else { +// inst->Release(); +// } + + return res; +} + +nsresult nsGfxFactoryGTK::LockFactory(PRBool aLock) +{ + // Not implemented in simplest case. + return NS_OK; +} + +// return the proper factory to the caller +extern "C" NS_GFXNONXP nsresult NSGetFactory(const nsCID &aClass, nsIFactory **aFactory) +{ + if (nsnull == aFactory) { + return NS_ERROR_NULL_POINTER; + } + + *aFactory = new nsGfxFactoryGTK(aClass); + + if (nsnull == aFactory) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory); +} diff --git a/mozilla/gfx/src/gtk/nsImageGTK.cpp b/mozilla/gfx/src/gtk/nsImageGTK.cpp new file mode 100644 index 00000000000..9d2cebe0eb9 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsImageGTK.cpp @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsImageGTK.h" +#include "nsRenderingContextGTK.h" +#include + +static NS_DEFINE_IID(kIImageIID, NS_IIMAGE_IID); + +//------------------------------------------------------------ + +nsImageGTK :: nsImageGTK() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------ + +nsImageGTK :: ~nsImageGTK() +{ +} + +NS_IMPL_ISUPPORTS(nsImageGTK, kIImageIID); + +//------------------------------------------------------------ + +nsresult nsImageGTK :: Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth,nsMaskRequirements aMaskRequirements) +{ + return NS_OK; +} + +//------------------------------------------------------------ + +// set up the pallete to the passed in color array, RGB only in this array +void nsImageGTK :: ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect) +{ +} + + +//------------------------------------------------------------ + +// Draw the bitmap, this method has a source and destination coordinates +PRBool nsImageGTK :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, + PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight) +{ + return PR_TRUE; +} + +//------------------------------------------------------------ + +// Draw the bitmap, this draw just has destination coordinates +PRBool nsImageGTK :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, + PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) +{ + return PR_TRUE; +} + +//------------------------------------------------------------ + +void nsImageGTK::CompositeImage(nsIImage *aTheImage, nsPoint *aULLocation,nsBlendQuality aBlendQuality) +{ + +} + +//------------------------------------------------------------ + +// lets build an alpha mask from this image +PRBool nsImageGTK::SetAlphaMask(nsIImage *aTheMask) +{ + return(PR_FALSE); +} + diff --git a/mozilla/gfx/src/gtk/nsImageGTK.h b/mozilla/gfx/src/gtk/nsImageGTK.h new file mode 100644 index 00000000000..a46f1003a66 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsImageGTK.h @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsImageGTK_h___ +#define nsImageGTK_h___ + +#include "nsIImage.h" + +class nsImageGTK : public nsIImage +{ +public: + nsImageGTK(); + ~nsImageGTK(); + + NS_DECL_ISUPPORTS + + /** + @see nsIImage.h + */ + virtual PRInt32 GetHeight() { return 0; } + virtual PRInt32 GetWidth() { return 0; } + virtual PRUint8* GetBits() { return nsnull; } + virtual PRInt32 GetLineStride() {return 0; } + virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); + virtual PRBool Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, + PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight); + virtual nsColorMap* GetColorMap() {return nsnull;} + virtual void ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect); + virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements); + virtual PRBool IsOptimized() { return PR_FALSE; } + virtual nsresult Optimize(nsDrawingSurface aSurface); + virtual PRUint8* GetAlphaBits() { return nsnull; } + virtual PRInt32 GetAlphaWidth() { return 0;} + virtual PRInt32 GetAlphaHeight() {return 0;} + virtual PRInt32 GetAlphaXLoc() {return 0;} + virtual PRInt32 GetAlphaYLoc() {return 0;} + virtual PRInt32 GetAlphaLineStride(){ return 0; } + virtual void CompositeImage(nsIImage *aTheImage,nsPoint *aULLocation,nsBlendQuality aQuality); + + virtual nsIImage* DuplicateImage(); + + /** + * Return the image size of the Device Independent Bitmap(DIB). + * @return size of image in bytes + */ + PRIntn GetSizeImage(){ return 0; } + + /** + * Make a palette for the DIB. + * @return true or false if the palette was created + */ + PRBool MakePalette(); + + /** + * 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); + + PRBool SetAlphaMask(nsIImage *aTheMask); + + virtual void SetAlphaLevel(PRInt32 aAlphaLevel) {mAlphaLevel=aAlphaLevel;} + + virtual PRInt32 GetAlphaLevel() {return(mAlphaLevel);} + + void MoveAlphaMask(PRInt32 aX, PRInt32 aY){} + +private: + PRInt16 mAlphaLevel; // an alpha level every pixel uses + + +}; + +#endif diff --git a/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp b/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp new file mode 100644 index 00000000000..09277bdb8e2 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -0,0 +1,477 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsRenderingContextGTK.h" +#include +#include + +typedef unsigned char BYTE; + +#define RGB(r,g,b) ((unsigned long) (((BYTE) (r) | ((unsigned long) ((BYTE) (g)) <<8)) | (((unsigned long)(BYTE)(b)) << 16))) + +static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID); + +class GraphicsState { + public: + GraphicsState(GraphicsState &gs) { + gc = gdk_gc_new(NULL); + gdk_gc_copy(gs.gc, gc); + if (gs.clipRegion) { + GdkRegion *leak = gdk_region_new(); + clipRegion = gdk_regions_union(leak, gs.clipRegion); + gdk_region_destroy(leak); + } else + clipRegion = NULL; + + mCurrentColor = gs.mCurrentColor; + } + + ~GraphicsState() { + gdk_gc_unref(gc); + if (clipRegion) + gdk_region_destroy(clipRegion); + } + + GdkGC *gc; + GdkRegion *clipRegion; + nsRect clipRect; + nscolor mCurrentColor; +}; + +nsRenderingContextGTK :: nsRenderingContextGTK() +{ + NS_INIT_REFCNT(); + + mFontCache = nsnull ; + mFontMetrics = nsnull ; + mContext = nsnull ; + mRenderingSurface = nsnull ; + mOffscreenSurface = nsnull ; + mTMatrix = nsnull; +} + +nsRenderingContextGTK :: ~nsRenderingContextGTK() +{ + NS_IF_RELEASE(mContext); + NS_IF_RELEASE(mFontCache); + NS_IF_RELEASE(mFontMetrics); +} + +NS_IMPL_QUERY_INTERFACE(nsRenderingContextGTK, kRenderingContextIID) +NS_IMPL_ADDREF(nsRenderingContextGTK) +NS_IMPL_RELEASE(nsRenderingContextGTK) + +nsresult nsRenderingContextGTK :: Init(nsIDeviceContext* aContext, + nsIWidget *aWindow) +{ + + mContext = aContext; + NS_IF_ADDREF(mContext); + + mRenderingSurface = new nsDrawingSurfaceGTK(); + + mRenderingSurface->drawable = (GdkDrawable *)aWindow->GetNativeData(NS_NATIVE_WINDOW); + mRenderingSurface->gc = (GdkGC *)aWindow->GetNativeData(NS_NATIVE_GRAPHIC); + + return NS_OK; +#if 0 + mFontCache = mContext->GetFontCache(); +#endif +} + +nsresult nsRenderingContextGTK :: Init(nsIDeviceContext* aContext, + nsDrawingSurface aSurface) +{ + mContext = aContext; + NS_IF_ADDREF(mContext); + + mRenderingSurface = (nsDrawingSurfaceGTK *) aSurface; + return NS_OK; +} + +nsresult nsRenderingContextGTK :: SelectOffScreenDrawingSurface(nsDrawingSurface aSurface) +{ + mOffscreenSurface = mRenderingSurface; + mRenderingSurface = (nsDrawingSurfaceGTK *) aSurface; + return NS_OK; +} + +void nsRenderingContextGTK :: Reset() +{ +} + +nsIDeviceContext * nsRenderingContextGTK :: GetDeviceContext(void) +{ + return mContext; +} + +void nsRenderingContextGTK :: PushState() +{ + GraphicsState state = new GraphicsState(mStates->data); + mStates = g_list_prepend(mStates, state); +} + +void nsRenderingContextGTK :: PopState() +{ + GraphicsState *state = (GraphicsState *)mStates->data; + GList *tempList = mStates; + mStates = mStates->next; + g_list_free_1(tempList); + delete state; +} + +PRBool nsRenderingContextGTK :: IsVisibleRect(const nsRect& aRect) +{ + return PR_TRUE; +} + +#define NSRECT_TO_GDKRECT(ns,gdk) \ + PR_BEGIN_MACRO \ + gdk.x = ns.x; \ + gdk.y = ns.y; \ + gdk.width = ns.width; \ + gdk.height = ns.height; \ + PR_END_MACRO + +void nsRenderingContextGTK :: SetClipRect(const nsRect& aRect, PRBool aIntersect) +{ + GdkRectangle rect; + GraphicsState *state = ((GraphicsState *)mStates->data); + state->clipRect = aRect; + NSRECT_TO_GDKRECT(aRect, rect); + + /* Create new region matching desired clip rect */ + GdkRegion *leak = gdk_region_new(); + GdkRegion *region = gdk_region_union_with_rect(leak, &rect); + gdk_region_destroy(leak); + + if (aIntersect == PR_TRUE) { + if (state->clipRegion) { + GdkRegion * tempRegion = region; + region = gdk_regions_intersect(tempRegion, state->clipRegion); + gdk_region_destroy(tempRegion); + } + } + + if (state->clipRegion) + gdk_region_destroy(state->clipRegion); + state->clipRegion = region; + + gdk_gc_set_clip_region(state->gc, state->clipRegion); +} + +PRBool nsRenderingContextGTK :: GetClipRect(nsRect &aRect) +{ + aRect = ((GraphicsState *)mStates->data)->clipRect; + return PR_TRUE; +} + +void nsRenderingContextGTK :: SetClipRegion(const nsIRegion& aRegion, PRBool aIntersect) +{ + //XXX wow, needs to do something. +} + +void nsRenderingContextGTK :: SetColor(nscolor aColor) +{ + GraphicsState * state = ((GraphicsState *)mStates->data); + GdkColor color; + state->mCurrentColor = aColor; + + color.red = NS_GET_R(aColor); + color.blue = NS_GET_B(aColor); + color.green = NS_GET_G(aColor); + gdk_color_alloc(&color); + gdk_gc_set_foreground(state->gc, &color); + /* no need to set background? */ +} + +nscolor nsRenderingContextGTK :: GetColor() const +{ + GraphicsState state = ((GraphicsState *)mStates->data); + return state->mCurrentColor; +} + +void nsRenderingContextGTK :: SetFont(const nsFont& aFont) +{ + if (mFontMetrics) + delete mFontMetrics; + mFontMetrics = new nsFontMetricsGTK(); + mFontMetrics.Init(aFont); +} + +const nsFont& nsRenderingContextGTK :: GetFont() +{ + return mFontMetrics->GetFont(); +} + +nsIFontMetrics* nsRenderingContextGTK :: GetFontMetrics() +{ + return mFontMetrics; +} + +// add the passed in translation to the current translation +void nsRenderingContextGTK :: Translate(nscoord aX, nscoord aY) +{ + mTMatrix->Translate((float)aX, (float)aY); +} + +// add the passed in scale to the current scale +void nsRenderingContextGTK :: Scale(float aSx, float aSy) +{ + mTMatrix->AddScale(aSx, aSy); +} + +nsTransform2D * nsRenderingContextGTK :: GetCurrentTransform() +{ + return mTMatrix; +} + +nsDrawingSurface nsRenderingContextGTK :: CreateDrawingSurface(nsRect *aBounds) +{ + GdkPixmap *pixmap = gdk_pixmap_new(mRenderingSurface->drawable, aBounds->width, + aBounds->height, -1); + + nsDrawingSurfaceGTK * surface = new nsDrawingSurfaceGTK(); + + surface->drawable = pixmap ; + surface->gc = mRenderingSurface->gc; + + return ((nsDrawingSurface)surface); +} + +void nsRenderingContextGTK :: DestroyDrawingSurface(nsDrawingSurface aDS) +{ + nsDrawingSurfaceGTK * surface = (nsDrawingSurfaceGTK *) aDS; + + gdk_pixmap_unref(surface->drawable); + + delete aDS; +} + +void nsRenderingContextGTK :: DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) +{ + mTMatrix->TransformCoord(&aX0, &aY0); + mTMatrix->TransformCoord(&aX1, &aY1); + gdk_draw_line(mRenderingSurface->drawable, mRenderingSurface->gc, aX0, aX1, aY0, aY1); +} + +void nsRenderingContextGTK :: DrawRect(const nsRect& aRect) +{ + DrawRect(aRect.x, aRect.y, aRect.width, aRect.height); +} + +void nsRenderingContextGTK :: DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) +{ + mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight); + gdk_draw_rect(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE, aX, aY, aWidth, aHeight); +} + +void nsRenderingContextGTK :: FillRect(const nsRect& aRect) +{ + FillRect(aRect.x, aRect.y, aRect.width, aRect.height); +} + +void nsRenderingContextGTK :: FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) +{ + mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight); + gdk_draw_rect(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE, aX, aY, aWidth, aHeight); +} + + +void nsRenderingContextGTK::DrawPolygon(nsPoint aPoints[], PRInt32 aNumPoints) +{ + GdkPoint *pts = new GdkPoint[aNumPoints]; + for (PRInt32 i = 0; i < aNumPoints; i++) + { + nsPoint p = aPoints[i]; + mTMatrix->TransformCoord(&p.x,&p.y); + pts[i]->x = p.x; + pts[i]->y = p.y; + } + gdk_draw_polygon(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE, pts, aNumPoints); +} + +void nsRenderingContextGTK::FillPolygon(nsPoint aPoints[], PRInt32 aNumPoints) +{ + GdkPoint *pts = new GdkPoint[aNumPoints]; + for (PRInt32 i = 0; i < aNumPoints; i++) + { + nsPoint p = aPoints[i]; + mTMatrix->TransformCoord(&p.x,&p.y); + pts[i]->x = p.x; + pts[i]->y = p.y; + } + /* XXXshaver common code! */ + gdk_draw_polygon(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE, pts, aNumPoints); +} + +void nsRenderingContextGTK :: DrawEllipse(const nsRect& aRect) +{ + DrawEllipse(aRect.x, aRect.y, aRect.width, aRect.height); +} + +void nsRenderingContextGTK :: DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) +{ + mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight); + gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE, aX, aY, aWidth, aHeight, + 0, 360 * 64); +} + +void nsRenderingContextGTK :: FillEllipse(const nsRect& aRect) +{ + FillEllipse(aRect.x, aRect.y, aRect.width, aRect.height); +} + +void nsRenderingContextGTK :: FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) +{ + mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight); + gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE, aX, aY, aWidth, aHeight, + 0, 360 * 64); +} + +void nsRenderingContextGTK :: DrawArc(const nsRect& aRect, + float aStartAngle, float aEndAngle) +{ + this->DrawArc(aRect.x,aRect.y,aRect.width,aRect.height,aStartAngle,aEndAngle); +} + +void nsRenderingContextGTK :: DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, + float aStartAngle, float aEndAngle) +{ + mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight); + gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, FALSE, aX, aY, aWidth, aHeight, + aStartAngle * 64, aEndAngle * 64); +} + +void nsRenderingContextGTK :: FillArc(const nsRect& aRect, + float aStartAngle, float aEndAngle) +{ + this->FillArc(aRect.x, aRect.y, aRect.width, aRect.height, aStartAngle, aEndAngle); +} + +void nsRenderingContextGTK :: FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, + float aStartAngle, float aEndAngle) +{ + mTMatrix->TransformCoord(&aX,&aY,&aWidth,&aHeight); + gdk_draw_arc(mRenderingSurface->drawable, mRenderingSurface->gc, TRUE, aX, aY, aWidth, aHeight, + aStartAngle * 64, aEndAngle * 64); +} + +void nsRenderingContextGTK :: DrawString(const char *aString, PRUint32 aLength, + nscoord aX, nscoord aY, + nscoord aWidth) +{ + mTMatrix->TransformCoord(&aX, &aY); + gdk_draw_string(mRenderingSurface->drawable, NULL, mRenderingSurface->gc, aX, aY); +} + +void nsRenderingContextGTK :: DrawString(const PRUnichar *aString, PRUint32 aLength, + nscoord aX, nscoord aY, nscoord aWidth) +{ + PR_ASSERT(0); +} + +void nsRenderingContextGTK :: DrawString(const nsString& aString, + nscoord aX, nscoord aY, nscoord aWidth) +{ + mTMatrix->TransformCoord(&aX, &aY); + if (aString.Length() > 0) { + char * buf ; + + buf = (char *) malloc(sizeof(char) * (aString.Length()+1)); + + buf[aString.Length()] = '\0'; + + aString.ToCString(buf, aString.Length()); + + gdk_draw_string(mRenderingSurface->drawable, NULL, mRenderingSurface->gc, + aX, aY, buf); + + free(buf); + } +} + +void nsRenderingContextGTK :: DrawImage(nsIImage *aImage, nscoord aX, nscoord aY) +{ + nscoord width, height; + + width = NS_TO_INT_ROUND(mP2T * aImage->GetWidth()); + height = NS_TO_INT_ROUND(mP2T * aImage->GetHeight()); + + this->DrawImage(aImage, aX, aY, width, height); +} + +void nsRenderingContextGTK :: DrawImage(nsIImage *aImage, nscoord aX, nscoord aY, + nscoord aWidth, nscoord aHeight) +{ + nsRect tr; + + tr.x = aX; + tr.y = aY; + tr.width = aWidth; + tr.height = aHeight; + + this->DrawImage(aImage, tr); +} + +void nsRenderingContextGTK :: DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect) +{ + nsRect sr,dr; + + sr = aSRect; + mTMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height); + + dr = aDRect; + mTMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height); + + ((nsImageGTK *)aImage)->Draw(*this, mDC, sr.x, sr.y, sr.width, sr.height, dr.x, dr.y, dr.width, dr.height); +} + +void nsRenderingContextGTK :: DrawImage(nsIImage *aImage, const nsRect& aRect) +{ + nsRect tr; + + tr = aRect; + mTMatrix->TransformCoord(&tr.x, &tr.y, &tr.width, &tr.height); + + ((nsImageGTK *)aImage)->Draw(*this, mDC, tr.x, tr.y, tr.width, tr.height); +} + +nsresult nsRenderingContextGTK :: CopyOffScreenBits(nsRect &aBounds) +{ + gdk_window_copy_area(mRenderingSurface->drawable, mRenderingSurface->gc, + aBounds.x, aBounds.y, mOffScreenSurface->drawable, + 0, 0, aBounds.width, aBounds.height); + + return NS_OK; +} + + + + + + + + + + + + + + + diff --git a/mozilla/gfx/src/gtk/nsRenderingContextGTK.h b/mozilla/gfx/src/gtk/nsRenderingContextGTK.h new file mode 100644 index 00000000000..bc20f492a62 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsRenderingContextGTK.h @@ -0,0 +1,145 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsRenderingContextGTK_h___ +#define nsRenderingContextGTK_h___ + +#include "nsIRenderingContext.h" +#include "nsUnitConversion.h" +#include "nsFont.h" +#include "nsIFontMetrics.h" +#include "nsPoint.h" +#include "nsString.h" +#include "nsCRT.h" +#include "nsTransform2D.h" +#include "nsIViewManager.h" +#include "nsIWidget.h" +#include "nsRect.h" +#include "nsIFontCache.h" +#include "nsImageGTK.h" +#include "nsIDeviceContext.h" +#include "nsVoidArray.h" + +#include + +#include "nsDeviceContextGTK.h" +#include "nsDrawingSurfaceGTK.h" + +class nsRenderingContextGTK : public nsIRenderingContext +{ +public: + nsRenderingContextGTK(); + ~nsRenderingContextGTK(); + + void* operator new(size_t sz) { + void* rv = new char[sz]; + nsCRT::zero(rv, sz); + return rv; + } + + NS_DECL_ISUPPORTS + + virtual nsresult Init(nsIDeviceContext* aContext, nsIWidget *aWindow); + virtual nsresult Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface); + + virtual void Reset(); + + virtual nsIDeviceContext * GetDeviceContext(void); + + virtual nsresult SelectOffScreenDrawingSurface(nsDrawingSurface aSurface); + + virtual void PushState(); + virtual void PopState(); + + virtual PRBool IsVisibleRect(const nsRect& aRect); + + virtual void SetClipRect(const nsRect& aRect, PRBool aIntersect); + virtual PRBool GetClipRect(nsRect &aRect); + virtual void SetClipRegion(const nsIRegion& aRegion, PRBool aIntersect); + + + virtual void SetColor(nscolor aColor); + virtual nscolor GetColor() const; + + virtual void SetFont(const nsFont& aFont); + virtual const nsFont& GetFont(); + + virtual nsIFontMetrics * GetFontMetrics(); + + virtual void Translate(nscoord aX, nscoord aY); + virtual void Scale(float aSx, float aSy); + virtual nsTransform2D * GetCurrentTransform(); + + virtual nsDrawingSurface CreateDrawingSurface(nsRect *aBounds); + virtual void DestroyDrawingSurface(nsDrawingSurface aDS); + + virtual void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); + + virtual void DrawRect(const nsRect& aRect); + virtual void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); + virtual void FillRect(const nsRect& aRect); + virtual void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); + + virtual void DrawPolygon(nsPoint aPoints[], PRInt32 aNumPoints); + virtual void FillPolygon(nsPoint aPoints[], PRInt32 aNumPoints); + + virtual void DrawEllipse(const nsRect& aRect); + virtual void DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); + virtual void FillEllipse(const nsRect& aRect); + virtual void FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); + + virtual void DrawArc(const nsRect& aRect, + float aStartAngle, float aEndAngle); + virtual void DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, + float aStartAngle, float aEndAngle); + virtual void FillArc(const nsRect& aRect, + float aStartAngle, float aEndAngle); + virtual void FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, + float aStartAngle, float aEndAngle); + + virtual void DrawString(const char *aString, PRUint32 aLength, + nscoord aX, nscoord aY, + nscoord aWidth); + virtual void DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, + nscoord aWidth); + virtual void DrawString(const nsString& aString, nscoord aX, nscoord aY, + nscoord aWidth); + + virtual void DrawImage(nsIImage *aImage, nscoord aX, nscoord aY); + virtual void DrawImage(nsIImage *aImage, nscoord aX, nscoord aY, + nscoord aWidth, nscoord aHeight); + virtual void DrawImage(nsIImage *aImage, const nsRect& aRect); + virtual void DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect); + + virtual nsresult CopyOffScreenBits(nsRect &aBounds); + +protected: + + nscolor mCurrentColor ; + + GList *mStates; // graphic state stack (GraphicsState) + nsDrawingSurfaceGTK *mOffscreenSurface; + nsDrawingSurfaceGTK *mRenderingSurface; + nsIDeviceContext *mContext; + nsIFontMetrics *mFontMetrics; + nsIFontCache *mFontCache; + nsTransform2D *mTMatrix; + +}; + +#endif /* nsRenderingContextGTK_h___ */