From: ishmal Date: Fri, 21 Mar 2008 19:34:33 +0000 (+0000) Subject: Start working toward multiple inheritance X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=cd54e98d4b5cfdfe4c5c064892ba432e197c8431;p=inkscape.git Start working toward multiple inheritance --- diff --git a/src/bind/dobinding.cpp b/src/bind/dobinding.cpp index 639e27062..6f9010533 100644 --- a/src/bind/dobinding.cpp +++ b/src/bind/dobinding.cpp @@ -75,29 +75,41 @@ typedef struct //# BASE OBJECT //######################################################################## +static jmethodID _getPointer_id = NULL; + static jlong getPointer(JNIEnv *env, jobject obj) { - jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J"); - if (!id) + if (!_getPointer_id) { - err("getPointer: %s", EXCEPTION); - return 0; - } - jlong val = env->GetLongField(obj, id); + _getPointer_id = env->GetMethodID(env->GetObjectClass(obj), "getPointer", "()J"); + if (!_getPointer_id) + { + err("getPointer(): %s", EXCEPTION); + return 0; + } + } + jlong val = env->CallLongMethod(obj, _getPointer_id); return val; } + +static jmethodID _setPointer_id = NULL; + static void setPointer(JNIEnv *env, jobject obj, jlong val) { - jfieldID id = env->GetFieldID(env->GetObjectClass(obj), "_pointer", "J"); - if (!id) + if (!_setPointer_id) { - err("setPointer: %s", EXCEPTION); - return; + _setPointer_id = env->GetMethodID(env->GetObjectClass(obj), "setPointer", "(J)V"); + if (!_setPointer_id) + { + err("setPointer(): %s", EXCEPTION); + return; + } } - env->SetLongField(obj, id, val); + env->CallVoidMethod(obj, _setPointer_id, val); } + static void JNICALL BaseObject_construct (JNIEnv *env, jobject obj) { @@ -107,7 +119,7 @@ static void JNICALL BaseObject_construct static void JNICALL BaseObject_destruct (JNIEnv *env, jobject obj) { - NodePtr *ptr = (NodePtr *)getPointer(env, obj); + BaseObject *ptr = (BaseObject *)getPointer(env, obj); if (ptr) { delete ptr; diff --git a/src/bind/java/org/inkscape/cmn/BaseInterface.java b/src/bind/java/org/inkscape/cmn/BaseInterface.java new file mode 100644 index 000000000..2cc1228f5 --- /dev/null +++ b/src/bind/java/org/inkscape/cmn/BaseInterface.java @@ -0,0 +1,85 @@ +/** + * This is a simple mechanism to bind Inkscape to Java, and thence + * to all of the nice things that can be layered upon that. + * + * Authors: + * Bob Jamison + * + * Copyright (C) 2007-2008 Bob Jamison + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package org.inkscape.cmn; + +/** + * A BaseInterface is not an object of its down, but is owned + * by a parent BaseObject. It has no mapping to a C++ object of + * its own, but is merely the delegate that a BaseObject calls. + * This is how we provide some semblance of multiple inheritance, + * and keep the native method count down. + */ +public class BaseInterface extends BaseObject +{ +BaseObject parent; + + +public void setParent(BaseObject par) +{ + parent = par; +} + +/** + * Overloaded. getPointer() means that -any- java instance rooted on + * either BaseObject or BaseInterface can call getPointer() to get the + * handle to the associated C++ object pointer. The difference is that + * BaseObject holds the actual pointer, while BaseInterface refers to + * its owner BaseObject. + */ +protected long getPointer() +{ + if (parent == null) + return 0L; + else + return parent.getPointer(); +} + +/** + * Since this is an interface, construct() + * means nothing. Nothing must happen + */ +protected void construct() +{ +} + +/** + * Since this is an interface, destruct() + * means nothing. Nothing must happen + */ +protected void destruct() +{ +} + + +/** + * Instances of this "interface" can only exist parasitically attached + * to a BaseObject + */ +public BaseInterface() +{ + setParent(null); +} + +} diff --git a/src/bind/java/org/inkscape/cmn/BaseObject.java b/src/bind/java/org/inkscape/cmn/BaseObject.java index 5e496b67d..b2c7aac8f 100644 --- a/src/bind/java/org/inkscape/cmn/BaseObject.java +++ b/src/bind/java/org/inkscape/cmn/BaseObject.java @@ -24,15 +24,55 @@ package org.inkscape.cmn; +/** + * This is the base of all classes which map to a corresponding + * C++ object. The _pointer value is storage for the C++ object's + * pointer. Construct() and destruct() are called for when things + * need to be setup or cleaned up on the C++ side during creation or + * destruction of this object. + * + * @see BaseInterface for how we add multiple inheritance to classes + * which are rooted on this class. + */ public class BaseObject { private long _pointer; +/** + * getPointer() means that -any- java instance rooted on + * either BaseObject or BaseInterface can call getPointer() to get the + * handle to the associated C++ object pointer. The difference is that + * BaseObject holds the actual pointer, while BaseInterface refers to + * its owner BaseObject. + */ +protected long getPointer() +{ + return _pointer; +} + +/** + * sets the pointer to the associated C++ object to a new value + */ +protected void setPointer(long val) +{ + _pointer = val; +} + protected native void construct(); protected native void destruct(); +protected BaseInterface imbue(BaseInterface intf) +{ + intf.setParent(this); + return intf; +} + + +/** + * Simple constructor + */ public BaseObject() { construct(); diff --git a/src/bind/java/org/inkscape/dom/DOMBase.java b/src/bind/java/org/inkscape/dom/DOMBase.java index 88a3e7de1..4ab1409f0 100644 --- a/src/bind/java/org/inkscape/dom/DOMBase.java +++ b/src/bind/java/org/inkscape/dom/DOMBase.java @@ -31,17 +31,20 @@ package org.inkscape.dom; * all of the DOM classes are rooted */ public class DOMBase + extends org.inkscape.cmn.BaseObject { -protected long _pointer; - /** - * @see dobinding.cpp: DOMBase_construct() + * @see dobinding.cpp: DOMBase_construct(). + * + * Overloaded from BaseObject so that we can do 'special' construction */ protected native void construct(); /** * @see dobinding.cpp: DOMBase_destruct() + * + * Overloaded from BaseObject so that we can do 'special' destruction */ protected native void destruct(); @@ -60,7 +63,6 @@ protected void finalize() public DOMBase() { construct(); - _pointer = 0; } } diff --git a/src/bind/java/org/inkscape/dom/NodeImpl.java b/src/bind/java/org/inkscape/dom/NodeImpl.java index a2cea09b3..e6071df42 100644 --- a/src/bind/java/org/inkscape/dom/NodeImpl.java +++ b/src/bind/java/org/inkscape/dom/NodeImpl.java @@ -40,6 +40,7 @@ import org.w3c.dom.UserDataHandler; public class NodeImpl + extends DOMBase implements org.w3c.dom.Node { diff --git a/src/bind/java/org/inkscape/dom/events/EventTargetImpl.java b/src/bind/java/org/inkscape/dom/events/EventTargetImpl.java index e1996f4ee..34778f03b 100644 --- a/src/bind/java/org/inkscape/dom/events/EventTargetImpl.java +++ b/src/bind/java/org/inkscape/dom/events/EventTargetImpl.java @@ -35,6 +35,8 @@ import org.w3c.dom.events.EventListener; public class EventTargetImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.events.EventTarget { diff --git a/src/bind/java/org/inkscape/dom/svg/SVGAElementImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGAElementImpl.java index 120683570..59c02120d 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGAElementImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGAElementImpl.java @@ -55,75 +55,122 @@ public class SVGAElementImpl implements org.w3c.dom.svg.SVGAElement { //from SVGURIReference -public native SVGAnimatedString getHref( ); +private SVGURIReferenceImpl _SVGURIReference; +public SVGAnimatedString getHref( ) +{ + return _SVGURIReference.getHref( ); +} //end SVGURIReference //from SVGTests -public native SVGStringList getRequiredFeatures( ); -public native SVGStringList getRequiredExtensions( ); -public native SVGStringList getSystemLanguage( ); -public native boolean hasExtension ( String extension ); +private SVGTestsImpl _SVGTests; +public SVGStringList getRequiredFeatures() + { return _SVGTests.getRequiredFeatures(); } +public SVGStringList getRequiredExtensions() + { return _SVGTests.getRequiredExtensions(); } +public SVGStringList getSystemLanguage() + { return _SVGTests.getSystemLanguage(); } +public boolean hasExtension (String extension) + { return _SVGTests.hasExtension(extension); } //end SVGTests //from SVGLangSpace -public native String getXMLlang( ); -public native void setXMLlang( String xmllang ) - throws DOMException; -public native String getXMLspace( ); -public native void setXMLspace( String xmlspace ) - throws DOMException; +private SVGLangSpaceImpl _SVGLangSpace; +public String getXMLlang() + { return _SVGLangSpace.getXMLlang(); } +public void setXMLlang(String xmllang) + throws DOMException + { _SVGLangSpace.setXMLlang(xmllang); } +public String getXMLspace() + { return _SVGLangSpace.getXMLspace(); } +public void setXMLspace(String xmlspace) + throws DOMException + { _SVGLangSpace.setXMLspace(xmlspace); } //end SVGLangSpace //from SVGExternalResourcesRequired -public native SVGAnimatedBoolean getExternalResourcesRequired( ); +private SVGExternalResourcesRequiredImpl _SVGExternalResourcesRequired; +public SVGAnimatedBoolean getExternalResourcesRequired() + { return _SVGExternalResourcesRequired.getExternalResourcesRequired(); } //end SVGExternalResourcesRequired //from SVGStylable -public native SVGAnimatedString getClassName( ); -public native CSSStyleDeclaration getStyle( ); -public native CSSValue getPresentationAttribute ( String name ); +private SVGStylableImpl _SVGStylable; +public SVGAnimatedString getClassName() + { return _SVGStylable.getClassName(); } +public CSSStyleDeclaration getStyle() + { return _SVGStylable.getStyle(); } +public CSSValue getPresentationAttribute(String name) + { return _SVGStylable.getPresentationAttribute(name); } //end SVGStylable //from SVGTransformable -public native SVGAnimatedTransformList getTransform( ); +private SVGTransformableImpl _SVGTransformable; +public SVGAnimatedTransformList getTransform() + { return _SVGTransformable.getTransform(); } //end SVGTransformable //from SVGLocatable (from SVGTransformable) -public native SVGElement getNearestViewportElement( ); -public native SVGElement getFarthestViewportElement( ); - -public native SVGRect getBBox ( ); -public native SVGMatrix getCTM ( ); -public native SVGMatrix getScreenCTM ( ); -public native SVGMatrix getTransformToElement ( SVGElement element ) - throws SVGException; +public SVGElement getNearestViewportElement() + { return _SVGTransformable.getNearestViewportElement(); } +public SVGElement getFarthestViewportElement() + { return _SVGTransformable.getFarthestViewportElement(); } +public SVGRect getBBox() + { return _SVGTransformable.getBBox(); } +public SVGMatrix getCTM() + { return _SVGTransformable.getCTM(); } +public SVGMatrix getScreenCTM() + { return _SVGTransformable.getScreenCTM(); } +public SVGMatrix getTransformToElement (SVGElement element) + throws SVGException + { return _SVGTransformable.getTransformToElement(element); } //end SVGLocatable //from EventTarget -public native void addEventListener(String type, +private org.inkscape.dom.events.EventTargetImpl _EventTarget; +public void addEventListener(String type, EventListener listener, - boolean useCapture); -public native void removeEventListener(String type, + boolean useCapture) + { _EventTarget.addEventListener(type, listener, useCapture); } +public void removeEventListener(String type, EventListener listener, - boolean useCapture); -public native boolean dispatchEvent(Event evt) - throws EventException; -public native void addEventListenerNS(String namespaceURI, + boolean useCapture) + { _EventTarget.removeEventListener(type, listener, useCapture); } +public boolean dispatchEvent(Event evt) + throws EventException + { return _EventTarget.dispatchEvent(evt); } +public void addEventListenerNS(String namespaceURI, String type, EventListener listener, boolean useCapture, - Object evtGroup); -public native void removeEventListenerNS(String namespaceURI, + Object evtGroup) + { _EventTarget.addEventListenerNS(namespaceURI, type, listener, useCapture, evtGroup); } +public void removeEventListenerNS(String namespaceURI, String type, EventListener listener, - boolean useCapture); -public native boolean willTriggerNS(String namespaceURI, - String type); -public native boolean hasEventListenerNS(String namespaceURI, - String type); + boolean useCapture) + { _EventTarget.removeEventListenerNS(namespaceURI, type, listener, useCapture); } +public boolean willTriggerNS(String namespaceURI, + String type) + { return _EventTarget.willTriggerNS(namespaceURI, type); } +public boolean hasEventListenerNS(String namespaceURI, + String type) + { return _EventTarget.hasEventListenerNS(namespaceURI, type); } //end EventTarget public native SVGAnimatedString getTarget( ); + +public SVGAElementImpl() +{ + imbue(_SVGURIReference = new SVGURIReferenceImpl()); + imbue(_SVGTests = new SVGTestsImpl()); + imbue(_SVGLangSpace = new SVGLangSpaceImpl()); + imbue(_SVGExternalResourcesRequired = new SVGExternalResourcesRequiredImpl()); + imbue(_SVGStylable = new SVGStylableImpl()); + imbue(_SVGTransformable = new SVGTransformableImpl()); + imbue(_EventTarget = new org.inkscape.dom.events.EventTargetImpl()); +} + } diff --git a/src/bind/java/org/inkscape/dom/svg/SVGExternalResourcesRequiredImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGExternalResourcesRequiredImpl.java index b4830d9a0..08fac8312 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGExternalResourcesRequiredImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGExternalResourcesRequiredImpl.java @@ -34,6 +34,8 @@ import org.w3c.dom.svg.SVGAnimatedBoolean; public class SVGExternalResourcesRequiredImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.svg.SVGExternalResourcesRequired { diff --git a/src/bind/java/org/inkscape/dom/svg/SVGLangSpaceImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGLangSpaceImpl.java index 4a35f0539..5caed0330 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGLangSpaceImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGLangSpaceImpl.java @@ -34,6 +34,8 @@ import org.w3c.dom.DOMException; public class SVGLangSpaceImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.svg.SVGLangSpace { public native String getXMLlang( ); diff --git a/src/bind/java/org/inkscape/dom/svg/SVGLocatableImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGLocatableImpl.java index f7045fb04..df9a0d59b 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGLocatableImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGLocatableImpl.java @@ -36,6 +36,8 @@ import org.w3c.dom.svg.SVGMatrix; public class SVGLocatableImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.svg.SVGLocatable { public native SVGElement getNearestViewportElement( ); diff --git a/src/bind/java/org/inkscape/dom/svg/SVGStylableImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGStylableImpl.java index 54df62696..7523d456d 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGStylableImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGStylableImpl.java @@ -35,6 +35,8 @@ import org.w3c.dom.css.CSSValue; import org.w3c.dom.svg.SVGAnimatedString; public class SVGStylableImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.svg.SVGStylable { diff --git a/src/bind/java/org/inkscape/dom/svg/SVGTestsImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGTestsImpl.java index c31291fc4..5f0a8c727 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGTestsImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGTestsImpl.java @@ -34,6 +34,8 @@ import org.w3c.dom.svg.SVGStringList; public class SVGTestsImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.svg.SVGTests { public native SVGStringList getRequiredFeatures( ); diff --git a/src/bind/java/org/inkscape/dom/svg/SVGURIReferenceImpl.java b/src/bind/java/org/inkscape/dom/svg/SVGURIReferenceImpl.java index c2e53d11a..2e3bb0bd4 100644 --- a/src/bind/java/org/inkscape/dom/svg/SVGURIReferenceImpl.java +++ b/src/bind/java/org/inkscape/dom/svg/SVGURIReferenceImpl.java @@ -34,6 +34,8 @@ import org.w3c.dom.svg.SVGAnimatedString; public class SVGURIReferenceImpl + extends + org.inkscape.cmn.BaseInterface implements org.w3c.dom.svg.SVGURIReference { public native SVGAnimatedString getHref( ); diff --git a/src/bind/javabind.h b/src/bind/javabind.h index c73afa581..144e633e7 100644 --- a/src/bind/javabind.h +++ b/src/bind/javabind.h @@ -41,6 +41,28 @@ namespace Bind typedef Glib::ustring String; +/** + * This is the base class of all things which will be C++ object + * instances + */ +class BaseObject +{ +public: + + /** + * Simple constructor + */ + BaseObject() + {} + + /** + * Destructor + */ + virtual ~BaseObject() + {} + +}; + /** *