mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Slugfest to get HT wired up thru C++ interfaces.
This commit is contained in:
parent
36a07884bf
commit
e254df3794
@ -48,6 +48,7 @@ CPPSRCS= \
|
||||
netglue.cpp \
|
||||
nsRDFDataModel.cpp \
|
||||
nsRDFDataModelItem.cpp \
|
||||
nsRDFFactory.cpp \
|
||||
nsRDFToolbarDataModel.cpp \
|
||||
nsRDFToolbarDataModelItem.cpp \
|
||||
nsRDFTreeColumn.cpp \
|
||||
|
@ -23,6 +23,7 @@ MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME=rdf
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
|
||||
C_OBJS=\
|
||||
.\$(OBJDIR)\vocab.obj \
|
||||
.\$(OBJDIR)\core.obj \
|
||||
@ -39,6 +40,7 @@ CPP_OBJS=\
|
||||
.\$(OBJDIR)\netglue.obj \
|
||||
.\$(OBJDIR)\nsRDFDataModel.obj \
|
||||
.\$(OBJDIR)\nsRDFDataModelItem.obj \
|
||||
.\$(OBJDIR)\nsRDFFactory.obj \
|
||||
.\$(OBJDIR)\nsRDFToolbarDataModel.obj \
|
||||
.\$(OBJDIR)\nsRDFToolbarDataModelItem.obj \
|
||||
.\$(OBJDIR)\nsRDFTreeColumn.obj \
|
||||
|
@ -17,52 +17,81 @@
|
||||
*/
|
||||
|
||||
#include "nsRDFDataModel.h"
|
||||
#include "nsRDFDataModelItem.h"
|
||||
#include "nsIRDFDataBase.h"
|
||||
#include "nsString.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
#include "rdf-int.h"
|
||||
|
||||
// XXX these have just GOT to go away. They're copied from ht.c
|
||||
PRInt32 htCounter = 0;
|
||||
|
||||
char* gNavCenterDataSources1[15] = {
|
||||
"rdf:localStore",
|
||||
"rdf:remoteStore",
|
||||
"rdf:bookmarks",
|
||||
"rdf:remoteStore",
|
||||
"rdf:history",
|
||||
/* "rdf:ldap", */
|
||||
"rdf:esftp",
|
||||
/* "rdf:mail", */
|
||||
#ifdef XP_MAC
|
||||
"rdf:appletalk",
|
||||
#endif
|
||||
"rdf:lfs",
|
||||
"rdf:ht",
|
||||
"rdf:columns",
|
||||
"rdf:find",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFDataModel::nsRDFDataModel(nsIRDFDataBase& db)
|
||||
: mDB(db), mWidget(NULL)
|
||||
nsRDFDataModel::nsRDFDataModel(void)
|
||||
: mDB(NULL), mWidget(NULL)
|
||||
{
|
||||
db.AddRef();
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsRDFDataModel::~nsRDFDataModel(void)
|
||||
{
|
||||
mDB.Release();
|
||||
}
|
||||
if (mRoot)
|
||||
mRoot->Release();
|
||||
|
||||
if (mDB)
|
||||
RDF_ReleaseDB(mDB);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFDataModel);
|
||||
NS_IMPL_RELEASE(nsRDFDataModel);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModel::QueryInterface(const nsIID& iid, void** result)
|
||||
{
|
||||
if (NULL == result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
|
||||
NS_IMPL_QUERY_INTERFACE(nsRDFDataModel, kIDataModelIID);
|
||||
|
||||
*result = NULL;
|
||||
if (iid.Equals(kISupportsIID) ||
|
||||
iid.Equals(kIDataModelIID)) {
|
||||
*result = static_cast<nsIDataModel*>(this);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModel::InitFromURL(const nsString& url)
|
||||
{
|
||||
Initialize(url);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModel::InitFromResource(nsIDMItem* pResource)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModel::GetDMWidget(nsIDMWidget*& widget) const
|
||||
{
|
||||
widget = mWidget;
|
||||
widget = GetWidget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -70,7 +99,7 @@ nsRDFDataModel::GetDMWidget(nsIDMWidget*& widget) const
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModel::SetDMWidget(nsIDMWidget* widget)
|
||||
{
|
||||
mWidget = widget;
|
||||
SetWidget(widget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -88,3 +117,25 @@ nsRDFDataModel::GetIntPropertyValue(PRInt32& value, const nsString& property) co
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
nsRDFDataModel::Initialize(const nsString& aUrl)
|
||||
{
|
||||
// XXX A ghastly simplification of HT_PaneFromURL()
|
||||
char* url = aUrl.ToNewCString();
|
||||
|
||||
const char* dbstr[2];
|
||||
dbstr[0] = getBaseURL(url);
|
||||
dbstr[1] = NULL;
|
||||
|
||||
mDB = RDF_GetDB(dbstr);
|
||||
PL_strfree(const_cast<char*>(dbstr[0]));
|
||||
|
||||
RDF_Resource r = RDF_GetResource(mDB, url, PR_TRUE);
|
||||
if ((mRoot = new nsRDFDataModelItem(*this, r)) != NULL)
|
||||
mRoot->AddRef();
|
||||
|
||||
delete url;
|
||||
}
|
||||
|
@ -20,22 +20,46 @@
|
||||
#define nsRDFDataModel_h__
|
||||
|
||||
#include "nsIDataModel.h"
|
||||
#include "rdf.h" // XXX
|
||||
|
||||
class nsIRDFDataBase;
|
||||
class nsString;
|
||||
class nsRDFDataModelItem;
|
||||
|
||||
enum nsRDFArcType {
|
||||
eRDFArcType_Outbound, // follow outbound arcs (e.g., children-of)
|
||||
eRDFArcType_Inbound // follow inbound arcs (e.g., parent-of)
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsRDFDataModel : public nsIDataModel {
|
||||
private:
|
||||
// XXX eventually, when we XPCOM the back-end
|
||||
//nsIRDFDataBase& mDB;
|
||||
|
||||
RDF mDB;
|
||||
nsRDFDataModelItem* mRoot;
|
||||
nsIDMWidget* mWidget;
|
||||
|
||||
RDF_Resource mArcProperty;
|
||||
nsRDFArcType mArcType;
|
||||
|
||||
public:
|
||||
nsRDFDataModel(nsIRDFDataBase& db);
|
||||
nsRDFDataModel(void);
|
||||
virtual ~nsRDFDataModel(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
// nsISupports
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDataModel interface
|
||||
|
||||
// Initializers
|
||||
NS_IMETHOD InitFromURL(const nsString& url);
|
||||
NS_IMETHOD InitFromResource(nsIDMItem* pResource);
|
||||
|
||||
// Inspectors
|
||||
NS_IMETHOD GetDMWidget(nsIDMWidget*& pWidget) const;
|
||||
|
||||
@ -46,9 +70,33 @@ public:
|
||||
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& property) const;
|
||||
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& property) const;
|
||||
|
||||
private:
|
||||
nsIRDFDataBase& mDB;
|
||||
nsIDMWidget* mWidget;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Initialize(const nsString& url);
|
||||
|
||||
RDF GetDB(void) const {
|
||||
return mDB;
|
||||
}
|
||||
|
||||
nsRDFDataModelItem* GetRoot(void) const {
|
||||
return mRoot;
|
||||
}
|
||||
|
||||
nsIDMWidget* GetWidget(void) const {
|
||||
return mWidget;
|
||||
}
|
||||
|
||||
void SetWidget(nsIDMWidget* widget) {
|
||||
mWidget = widget;
|
||||
}
|
||||
|
||||
RDF_Resource GetArcProperty(void) const {
|
||||
return mArcProperty;
|
||||
}
|
||||
|
||||
nsRDFArcType GetArcType(void) const {
|
||||
return mArcType;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // nsRDFDataModel_h__
|
||||
|
@ -18,11 +18,14 @@
|
||||
|
||||
#include "nsRDFDataModelItem.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDMItemIID, NS_IDMITEM_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFDataModelItem::nsRDFDataModelItem(RDF_Resource& resource)
|
||||
: mResource(resource)
|
||||
nsRDFDataModelItem::nsRDFDataModelItem(nsRDFDataModel& model, RDF_Resource resource)
|
||||
: mDataModel(model),
|
||||
mResource(resource),
|
||||
mOpen(PR_FALSE),
|
||||
mParent(NULL),
|
||||
mCachedSubtreeSize(1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
@ -32,31 +35,14 @@ nsRDFDataModelItem::~nsRDFDataModelItem(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFDataModelItem);
|
||||
NS_IMPL_RELEASE(nsRDFDataModelItem);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
{
|
||||
if (NULL == result) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*result = NULL;
|
||||
if (iid.Equals(kIDMItemIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = static_cast<nsIDMItem*>(this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIDMItemIID, NS_IDMITEM_IID);
|
||||
NS_IMPL_QUERY_INTERFACE(nsRDFDataModelItem, kIDMItemIID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
|
||||
{
|
||||
@ -68,29 +54,35 @@ nsRDFDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModelItem::GetOpenState(PRBool& result) const
|
||||
{
|
||||
result = mOpen;
|
||||
result = IsOpen();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModelItem::GetChildCount(PRUint32& count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
count = mChildren.GetSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 item) const
|
||||
nsRDFDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 n) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
if (n < 0 || n > mChildren.GetUpperBound())
|
||||
return NS_ERROR_UNEXPECTED; // XXX
|
||||
|
||||
pItem = static_cast<nsIDMItem*>(mChildren[n]);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDataModelItem::GetParent(nsIDMItem*& pItem) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
pItem = static_cast<nsIDMItem*>(mParent);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -108,3 +100,70 @@ nsRDFDataModelItem::GetIntPropertyValue(PRInt32& value, const nsString& itemProp
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
nsRDFDataModelItem::InvalidateCachedSubtreeSize(void)
|
||||
{
|
||||
if (mCachedSubtreeSize) {
|
||||
mCachedSubtreeSize = 0;
|
||||
if (mParent)
|
||||
mParent->InvalidateCachedSubtreeSize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
nsRDFDataModelItem::AddChild(nsRDFDataModelItem* child)
|
||||
{
|
||||
mChildren.Add(child);
|
||||
nsRDFDataModelItem* item = this;
|
||||
while (item) {
|
||||
item->mCachedSubtreeSize += child->GetSubtreeSize();
|
||||
item = item->mParent;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsRDFDataModelItem::GetSubtreeSize(void) const
|
||||
{
|
||||
if (! mCachedSubtreeSize) {
|
||||
mCachedSubtreeSize = 1; // me
|
||||
|
||||
for (PRUint32 i = mChildren.GetUpperBound(); i >= 0; --i) {
|
||||
nsRDFDataModelItem* child =
|
||||
static_cast<nsRDFDataModelItem*>(mChildren[i]);
|
||||
|
||||
mCachedSubtreeSize += child->GetSubtreeSize();
|
||||
}
|
||||
}
|
||||
return mCachedSubtreeSize;
|
||||
}
|
||||
|
||||
|
||||
nsRDFDataModelItem*
|
||||
nsRDFDataModelItem::GetNth(PRUint32 n) const
|
||||
{
|
||||
if (n == 0)
|
||||
return const_cast<nsRDFDataModelItem*>(this);
|
||||
|
||||
PRUint32 upperBound = mChildren.GetUpperBound();
|
||||
PRUint32 firstIndexInSubtree = 1;
|
||||
for (PRUint32 i = 0; i < upperBound; ++i) {
|
||||
nsRDFDataModelItem* child =
|
||||
static_cast<nsRDFDataModelItem*>(mChildren[i]);
|
||||
|
||||
PRUint32 subtreeSize = child->GetSubtreeSize();
|
||||
PRUint32 lastIndexInSubtree = firstIndexInSubtree + subtreeSize;
|
||||
|
||||
if (n >= firstIndexInSubtree && n < lastIndexInSubtree)
|
||||
return GetNth(n - firstIndexInSubtree);
|
||||
}
|
||||
|
||||
// n was larger than the total number of elements in the tree!
|
||||
PR_ASSERT(0);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -21,14 +21,31 @@
|
||||
|
||||
#include "rdf.h"
|
||||
#include "nsIDMItem.h"
|
||||
#include "nsVector.h"
|
||||
|
||||
class nsRDFDataModel;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsRDFDataModelItem : public nsIDMItem {
|
||||
private:
|
||||
nsRDFDataModel& mDataModel;
|
||||
RDF_Resource mResource;
|
||||
PRBool mOpen;
|
||||
nsVector mChildren;
|
||||
nsRDFDataModelItem* mParent;
|
||||
mutable PRUint32 mCachedSubtreeSize;
|
||||
|
||||
PRUint32 GetSubtreeSize(void) const;
|
||||
void InvalidateCachedSubtreeSize(void);
|
||||
|
||||
public:
|
||||
nsRDFDataModelItem(RDF_Resource& resource);
|
||||
nsRDFDataModelItem(nsRDFDataModel& model, RDF_Resource resource);
|
||||
virtual ~nsRDFDataModelItem(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@ -51,10 +68,39 @@ public:
|
||||
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& itemProperty) const;
|
||||
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const;
|
||||
|
||||
private:
|
||||
RDF_Resource& mResource;
|
||||
PRBool mOpen;
|
||||
PRBool mEnabled;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFDataModel& GetDataModel(void) const {
|
||||
return mDataModel;
|
||||
}
|
||||
|
||||
RDF_Resource GetResource(void) const {
|
||||
return mResource;
|
||||
}
|
||||
|
||||
PRBool IsOpen(void) const {
|
||||
return mOpen;
|
||||
}
|
||||
|
||||
void SetOpenState(PRBool open) {
|
||||
mOpen = open;
|
||||
}
|
||||
|
||||
nsRDFDataModelItem* ChildAt(PRUint32 index) const {
|
||||
return static_cast<nsRDFDataModelItem*>(mChildren[index]);
|
||||
}
|
||||
|
||||
void AddChild(nsRDFDataModelItem* child);
|
||||
|
||||
PRUint32 GetChildCount(void) const {
|
||||
return mChildren.GetSize();
|
||||
}
|
||||
|
||||
nsRDFDataModelItem* GetParent(void) const {
|
||||
return mParent;
|
||||
}
|
||||
|
||||
nsRDFDataModelItem* GetNth(PRUint32 n) const;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
150
rdf/src/nsRDFFactory.cpp
Normal file
150
rdf/src/nsRDFFactory.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsRDFTreeDataModel.h"
|
||||
#include "nsRDFToolbarDataModel.h"
|
||||
#include "nsRDFCIDs.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_CID(kRDFTreeDataModelCID, NS_RDFTREEDATAMODEL_CID);
|
||||
static NS_DEFINE_CID(kRDFToolbarDataModelCID, NS_RDFTOOLBARDATAMODEL_CID);
|
||||
|
||||
class nsRDFFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
nsRDFFactory(const nsCID &aClass);
|
||||
|
||||
////////////////////////////////////////
|
||||
// nsISupports methods
|
||||
//
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
////////////////////////////////////////
|
||||
// nsIFactory methods
|
||||
//
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~nsRDFFactory();
|
||||
|
||||
private:
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFFactory::nsRDFFactory(const nsCID &aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
nsRDFFactory::~nsRDFFactory()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFFactory::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = static_cast<nsISupports*>(this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = static_cast<nsIFactory*>(this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFFactory);
|
||||
NS_IMPL_RELEASE(nsRDFFactory);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsISupports *inst = NULL;
|
||||
if (mClassID.Equals(kRDFTreeDataModelCID)) {
|
||||
inst = static_cast<nsITreeDataModel*>(new nsRDFTreeDataModel());
|
||||
}
|
||||
else if (mClassID.Equals(kRDFToolbarDataModelCID)) {
|
||||
#if 0
|
||||
inst = static_cast<nsIToolbarDataModel*>(new nsRDFToolbarDataModel());
|
||||
#endif
|
||||
}
|
||||
|
||||
if (! inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult res = inst->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(res))
|
||||
// We didn't get the right interface, so clean up
|
||||
delete inst;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsRDFFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" nsresult
|
||||
NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
|
||||
{
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aFactory = new nsRDFFactory(aClass);
|
||||
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
@ -18,14 +18,16 @@
|
||||
|
||||
#include "nsRDFToolbarDataModel.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
|
||||
static NS_DEFINE_IID(kIToolbarDataModelIID, NS_ITOOLBARDATAMODEL_IID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFToolbarDataModel::nsRDFToolbarDataModel(nsIRDFDataBase& db, RDF_Resource& root)
|
||||
: nsRDFDataModel(db), mRoot(root)
|
||||
nsRDFToolbarDataModel::nsRDFToolbarDataModel(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +36,17 @@ nsRDFToolbarDataModel::~nsRDFToolbarDataModel(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFToolbarDataModel::AddRef(void)
|
||||
{
|
||||
return nsRDFDataModel::AddRef(); // delegate to the superclass
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFToolbarDataModel::Release(void)
|
||||
{
|
||||
return nsRDFDataModel::Release(); // delegate to the superclass
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::QueryInterface(const nsIID& iid, void** result)
|
||||
@ -44,11 +57,57 @@ nsRDFToolbarDataModel::QueryInterface(const nsIID& iid, void** result)
|
||||
*result = NULL;
|
||||
if (iid.Equals(kIToolbarDataModelIID)) {
|
||||
*result = static_cast<nsIToolbarDataModel*>(this);
|
||||
nsRDFDataModel::AddRef(); // delegate to the superclass
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// delegate to the superclass.
|
||||
// delegate to the superclass
|
||||
return nsRDFDataModel::QueryInterface(iid, result);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::InitFromURL(const nsString& url)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::InitFromResource(nsIDMItem* pResource)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::GetDMWidget(nsIDMWidget*& widget) const
|
||||
{
|
||||
widget = mModel.GetWidget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::SetDMWidget(nsIDMWidget* widget)
|
||||
{
|
||||
mModel.SetWidget(widget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::GetStringPropertyValue(nsString& value, const nsString& property) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModel::GetIntPropertyValue(PRInt32& value, const nsString& property) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif
|
||||
|
@ -28,21 +28,40 @@
|
||||
/**
|
||||
* An implementation for the Toolbar widget model.
|
||||
*/
|
||||
class nsRDFToolbarDataModel : public nsRDFDataModel, nsIToolbarDataModel {
|
||||
class nsRDFToolbarDataModel : public nsIToolbarDataModel, public nsRDFDataModel {
|
||||
public:
|
||||
nsRDFToolbarDataModel(nsIRDFDataBase& db, RDF_Resource& root);
|
||||
nsRDFToolbarDataModel(void);
|
||||
virtual ~nsRDFToolbarDataModel(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
// XXX Note that we'll just use the parent class's implementation
|
||||
// of AddRef() and Release()
|
||||
#if 0
|
||||
NS_DECL_ISUPPORTS
|
||||
#endif
|
||||
|
||||
// NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
// NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
|
||||
|
||||
#if 0
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDataModel interface
|
||||
|
||||
// Initializers
|
||||
NS_IMETHOD InitFromURL(const nsString& url);
|
||||
NS_IMETHOD InitFromResource(nsIDMItem* pResource);
|
||||
|
||||
// Inspectors
|
||||
NS_IMETHOD GetDMWidget(nsIDMWidget*& pWidget) const;
|
||||
|
||||
// Setters
|
||||
NS_IMETHOD SetDMWidget(nsIDMWidget* pWidget);
|
||||
|
||||
// Methods to query the data model for property values for an entire widget.
|
||||
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& property) const;
|
||||
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& property) const;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIToolbarDataModel interface
|
||||
@ -50,7 +69,6 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
RDF_Resource& mRoot;
|
||||
};
|
||||
|
||||
|
||||
|
@ -20,12 +20,14 @@
|
||||
#include "nsRDFToolbarDataModel.h"
|
||||
|
||||
static NS_DEFINE_IID(kIToolbarDMItemIID, NS_ITOOLBARDMITEM_IID);
|
||||
static NS_DEFINE_IID(kIDMItemIID, NS_ITOOLBARDMITEM_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFToolbarDataModelItem::nsRDFToolbarDataModelItem(nsRDFToolbarDataModel& Toolbar, RDF_Resource& resource)
|
||||
: nsRDFDataModelItem(resource),
|
||||
mToolbar(Toolbar)
|
||||
nsRDFToolbarDataModelItem::nsRDFToolbarDataModelItem(nsRDFToolbarDataModel& toolbar,
|
||||
RDF_Resource resource)
|
||||
: nsRDFDataModelItem(toolbar, resource)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,6 +36,18 @@ nsRDFToolbarDataModelItem::~nsRDFToolbarDataModelItem(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFToolbarDataModelItem::AddRef(void)
|
||||
{
|
||||
return nsRDFDataModelItem::AddRef();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFToolbarDataModelItem::Release(void)
|
||||
{
|
||||
return nsRDFDataModelItem::Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
@ -44,7 +58,7 @@ nsRDFToolbarDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
*result = NULL;
|
||||
if (iid.Equals(kIToolbarDMItemIID)) {
|
||||
*result = static_cast<nsIToolbarDMItem*>(this);
|
||||
nsRDFDataModelItem::AddRef(); // delegate to the superclass
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -53,3 +67,58 @@ nsRDFToolbarDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetOpenState(PRBool& result) const
|
||||
{
|
||||
result = IsOpen();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetChildCount(PRUint32& count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 item) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetParent(nsIDMItem*& pItem) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetStringPropertyValue(nsString& result, const nsString& property) const
|
||||
{
|
||||
// 1. convert the property to a URI
|
||||
// 2. ask the RDF database for the value of the property
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFToolbarDataModelItem::GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif
|
||||
|
@ -27,26 +27,46 @@ class nsRDFToolbarDataModel;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsRDFToolbarDataModelItem : public nsRDFDataModelItem, nsIToolbarDMItem {
|
||||
class nsRDFToolbarDataModelItem : public nsIToolbarDMItem, public nsRDFDataModelItem
|
||||
{
|
||||
public:
|
||||
nsRDFToolbarDataModelItem(nsRDFToolbarDataModel& Toolbar, RDF_Resource& resource);
|
||||
nsRDFToolbarDataModelItem(nsRDFToolbarDataModel& Toolbar, RDF_Resource resource);
|
||||
virtual ~nsRDFToolbarDataModelItem(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
// XXX Note that we'll just use the parent class's implementation
|
||||
// of AddRef() and Release()
|
||||
// NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
// NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
|
||||
|
||||
#if 0
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDMItem interface
|
||||
|
||||
// Inspectors
|
||||
NS_IMETHOD GetIconImage(nsIImage*& pImage, nsIImageGroup* pGroup) const;
|
||||
NS_IMETHOD GetOpenState(PRBool& answer) const;
|
||||
|
||||
// Methods for iterating over children.
|
||||
NS_IMETHOD GetChildCount(PRUint32& count) const;
|
||||
NS_IMETHOD GetNthChild(nsIDMItem*& pItem, PRUint32 item) const;
|
||||
|
||||
// Parent access
|
||||
NS_IMETHOD GetParent(nsIDMItem*& pItem) const;
|
||||
|
||||
// Setters
|
||||
|
||||
// Methods to query the data model for a specific item displayed within the widget.
|
||||
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& itemProperty) const;
|
||||
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIToolbarItem interface
|
||||
|
||||
|
||||
private:
|
||||
nsRDFToolbarDataModel& mToolbar;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
@ -17,20 +17,30 @@
|
||||
*/
|
||||
|
||||
#include "nsRDFTreeColumn.h"
|
||||
#include "nsRDFTreeDataModel.h"
|
||||
#include "nsIDMWidget.h"
|
||||
#include "nsIDataModel.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
|
||||
static NS_DEFINE_IID(kITreeColumnIID, NS_ITREECOLUMN_IID);
|
||||
|
||||
const PRUint32 nsRDFTreeColumn::kDefaultWidth = 64; // XXX
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFTreeColumn::nsRDFTreeColumn(const nsString& name)
|
||||
: mName(name),
|
||||
mWidth(kDefaultWidth),
|
||||
nsRDFTreeColumn::nsRDFTreeColumn(nsRDFTreeDataModel& tree,
|
||||
const nsString& name,
|
||||
RDF_Resource property,
|
||||
PRUint32 width)
|
||||
: mTree(tree),
|
||||
mName(name),
|
||||
mProperty(property),
|
||||
mWidth(width),
|
||||
mSortState(eColumnSortState_Unsorted),
|
||||
mDesiredPercentage(0.0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mTree.AddRef();
|
||||
}
|
||||
|
||||
|
||||
@ -92,7 +102,32 @@ nsRDFTreeColumn::SetPixelWidth(PRUint32 newWidth)
|
||||
void
|
||||
nsRDFTreeColumn::SetVisibility(PRBool visible)
|
||||
{
|
||||
mVisible = visible;
|
||||
if (visible != mVisible) {
|
||||
mVisible = visible;
|
||||
|
||||
nsIDataModel* model;
|
||||
if (NS_SUCCEEDED(mTree.QueryInterface(kIDataModelIID, (void**) &model))) {
|
||||
nsIDMWidget* dmWidget;
|
||||
|
||||
// XXX if interface inheirits...
|
||||
//if (NS_SUCCEEDED(mTree.GetDMWidget(dmWidget))) {
|
||||
|
||||
if (NS_SUCCEEDED(model->GetDMWidget(dmWidget))) {
|
||||
#if 0
|
||||
// XXX IMO, this should be in its own interface. Need to ask Hyatt...
|
||||
nsITreeWidget* treeWidget;
|
||||
if (NS_SUCCEEDED(dmWidget->QueryInterface(kITreeWidgetIID, &treeWidget))) {
|
||||
treeWidget->OnColumnVisibilityChanged(static_cast<nsITreeColumn*>(this),
|
||||
mVisible);
|
||||
|
||||
treeWidget->Release();
|
||||
}
|
||||
#endif
|
||||
dmWidget->Release();
|
||||
}
|
||||
model->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,14 +21,29 @@
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsITreeColumn.h"
|
||||
#include "rdf.h"
|
||||
|
||||
class nsRDFTreeDataModel;
|
||||
|
||||
class nsRDFTreeColumn : public nsITreeColumn {
|
||||
public:
|
||||
nsRDFTreeColumn(const nsString& name);
|
||||
virtual ~nsRDFTreeColumn(void);
|
||||
private:
|
||||
nsRDFTreeDataModel& mTree;
|
||||
nsString mName;
|
||||
RDF_Resource mProperty;
|
||||
PRUint32 mWidth;
|
||||
nsColumnSortState mSortState;
|
||||
double mDesiredPercentage;
|
||||
PRBool mVisible;
|
||||
|
||||
void SetVisibility(PRBool visible);
|
||||
PRBool IsVisible(void) const;
|
||||
static const PRUint32 kDefaultWidth;
|
||||
|
||||
public:
|
||||
nsRDFTreeColumn(nsRDFTreeDataModel& tree,
|
||||
const nsString& name,
|
||||
const RDF_Resource property,
|
||||
PRUint32 width = kDefaultWidth);
|
||||
|
||||
virtual ~nsRDFTreeColumn(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
@ -47,14 +62,15 @@ public:
|
||||
// Setters
|
||||
NS_IMETHOD SetPixelWidth(PRUint32 newWidth);
|
||||
|
||||
private:
|
||||
nsString mName;
|
||||
PRUint32 mWidth;
|
||||
nsColumnSortState mSortState;
|
||||
double mDesiredPercentage;
|
||||
PRBool mVisible;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const PRUint32 kDefaultWidth;
|
||||
void SetVisibility(PRBool visible);
|
||||
|
||||
PRBool IsVisible(void) const;
|
||||
|
||||
RDF_Resource GetProperty(void) const {
|
||||
return mProperty;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // nsRDFTreeColumn_h__
|
||||
|
@ -18,14 +18,17 @@
|
||||
|
||||
#include "nsRDFTreeDataModel.h"
|
||||
#include "nsRDFTreeColumn.h"
|
||||
#include "nsRDFTreeDataModelItem.h"
|
||||
#include "rdf-int.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
|
||||
static NS_DEFINE_IID(kITreeDataModelIID, NS_ITREEDATAMODEL_IID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFTreeDataModel::nsRDFTreeDataModel(nsIRDFDataBase& db, RDF_Resource& root)
|
||||
: nsRDFDataModel(db), mRoot(root)
|
||||
nsRDFTreeDataModel::nsRDFTreeDataModel(void)
|
||||
{
|
||||
}
|
||||
|
||||
@ -33,8 +36,28 @@ nsRDFTreeDataModel::nsRDFTreeDataModel(nsIRDFDataBase& db, RDF_Resource& root)
|
||||
|
||||
nsRDFTreeDataModel::~nsRDFTreeDataModel(void)
|
||||
{
|
||||
for (PRUint32 i = mColumns.GetUpperBound(); i >= 0; --i) {
|
||||
nsRDFTreeColumn* column = static_cast<nsRDFTreeColumn*>(mColumns[i]);
|
||||
|
||||
PR_ASSERT(column);
|
||||
if (! column)
|
||||
continue;
|
||||
|
||||
column->Release();
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFTreeDataModel::AddRef(void)
|
||||
{
|
||||
return nsRDFDataModel::AddRef(); // delegate to the superclass
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFTreeDataModel::Release(void)
|
||||
{
|
||||
return nsRDFDataModel::Release(); // delegate to the superclass
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::QueryInterface(const nsIID& iid, void** result)
|
||||
@ -45,14 +68,62 @@ nsRDFTreeDataModel::QueryInterface(const nsIID& iid, void** result)
|
||||
*result = NULL;
|
||||
if (iid.Equals(kITreeDataModelIID)) {
|
||||
*result = static_cast<nsITreeDataModel*>(this);
|
||||
nsRDFDataModel::AddRef(); // delegate to the superclass
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// delegate to the superclass.
|
||||
return nsRDFDataModel::QueryInterface(iid, result);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::InitFromURL(const nsString& url)
|
||||
{
|
||||
SetDB(url);
|
||||
SetRoot(url);
|
||||
CreateColumns();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::InitFromResource(nsIDMItem* pResource)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetDMWidget(nsIDMWidget*& widget) const
|
||||
{
|
||||
widget = GetWidget();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::SetDMWidget(nsIDMWidget* widget)
|
||||
{
|
||||
SetWidget(widget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetStringPropertyValue(nsString& value, const nsString& property) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetIntPropertyValue(PRInt32& value, const nsString& property) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -70,6 +141,13 @@ nsRDFTreeDataModel::GetVisibleColumnCount(PRUint32& count) const
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetColumnCount(PRUint32& count) const
|
||||
{
|
||||
return mColumns.GetSize();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetNthColumn(nsITreeColumn*& pColumn, PRUint32 n) const
|
||||
{
|
||||
@ -86,12 +164,15 @@ nsRDFTreeDataModel::GetNthColumn(nsITreeColumn*& pColumn, PRUint32 n) const
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetFirstVisibleItemIndex(PRUint32& index) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
// XXX hack! where do we ever set this???
|
||||
index = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModel::GetNthTreeItem(nsITreeDMItem*& pItem, PRUint32 n) const
|
||||
{
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
@ -101,5 +182,101 @@ nsRDFTreeDataModel::GetItemTextForColumn(nsString& nodeText,
|
||||
nsITreeDMItem* pItem,
|
||||
nsITreeColumn* pColumn) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
// XXX this is a horribly simplified version of what
|
||||
// HT_GetNodeData() does. Hopefully it's enough to do the job for
|
||||
// now.
|
||||
|
||||
// XXX may need to turn off the dynamic_cast stuff...
|
||||
nsRDFTreeDataModelItem* item =
|
||||
dynamic_cast<nsRDFTreeDataModelItem*>(pItem);
|
||||
|
||||
PR_ASSERT(item);
|
||||
if (! item)
|
||||
return NS_ERROR_UNEXPECTED; // XXX
|
||||
|
||||
nsRDFTreeColumn* column =
|
||||
dynamic_cast<nsRDFTreeColumn*>(pColumn);
|
||||
|
||||
PR_ASSERT(column);
|
||||
if (! column)
|
||||
return NS_ERROR_UNEXPECTED; // XXX
|
||||
|
||||
const char* result =
|
||||
(const char*) RDF_GetSlotValue(GetDB(),
|
||||
item->GetResource(), // resource
|
||||
column->GetProperty(), // property
|
||||
RDF_STRING_TYPE,
|
||||
PR_FALSE,
|
||||
PR_TRUE);
|
||||
|
||||
PR_ASSERT(result);
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nodeText = result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
nsRDFTreeDataModel::CreateColumns(void)
|
||||
{
|
||||
// This mostly came over from HT_NewView()
|
||||
nsRDFDataModelItem* root = GetRoot();
|
||||
PR_ASSERT(root);
|
||||
if (! root)
|
||||
return;
|
||||
|
||||
RDF_Cursor cursor;
|
||||
cursor = RDF_GetTargets(GetDB(), root->GetResource(),
|
||||
gNavCenter->RDF_Column,
|
||||
RDF_RESOURCE_TYPE, PR_TRUE);
|
||||
|
||||
PR_ASSERT(cursor != NULL);
|
||||
if (cursor == NULL)
|
||||
return;
|
||||
|
||||
RDF_Resource r;
|
||||
while ((r = static_cast<RDF_Resource>(RDF_NextValue(cursor))) != NULL) {
|
||||
if (resourceID(r) == NULL)
|
||||
break;
|
||||
|
||||
#if 0 // XXX no datatype support yet...
|
||||
PRUint32 type;
|
||||
type = (PRUint32) RDF_GetSlotValue(GetDB(), r, gNavCenter->RDF_ColumnDataType,
|
||||
RDF_INT_TYPE, PR_FALSE, PR_TRUE);
|
||||
|
||||
if (!type)
|
||||
type = HT_COLUMN_STRING;
|
||||
#endif
|
||||
|
||||
PRUint32 width;
|
||||
width = (PRUint32) RDF_GetSlotValue(GetDB(), r, gNavCenter->RDF_ColumnWidth,
|
||||
RDF_INT_TYPE, PR_FALSE, PR_TRUE);
|
||||
|
||||
const char* name;
|
||||
name = (const char *) RDF_GetSlotValue(GetDB(), r, gCoreVocab->RDF_name,
|
||||
RDF_STRING_TYPE, PR_FALSE, PR_TRUE);
|
||||
|
||||
nsRDFTreeColumn* column = new nsRDFTreeColumn(*this, name, r, width);
|
||||
|
||||
PR_ASSERT(column);
|
||||
if (! column)
|
||||
continue;
|
||||
|
||||
column->AddRef();
|
||||
mColumns.Add(column);
|
||||
}
|
||||
RDF_DisposeCursor(cursor);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void
|
||||
nsRDFTreeDataModel::AddColumn(const nsString& name, RDF_Resource property)
|
||||
{
|
||||
nsRDFTreeColumn* column = new nsRDFTreeColumn(*this, name, property);
|
||||
mColumns.Add(column);
|
||||
}
|
||||
|
@ -29,27 +29,47 @@
|
||||
/**
|
||||
* An implementation for the tree widget model.
|
||||
*/
|
||||
class nsRDFTreeDataModel : public nsRDFDataModel, nsITreeDataModel {
|
||||
class nsRDFTreeDataModel : public nsITreeDataModel, public nsRDFDataModel {
|
||||
public:
|
||||
nsRDFTreeDataModel(nsIRDFDataBase& db, RDF_Resource& root);
|
||||
nsRDFTreeDataModel(void);
|
||||
virtual ~nsRDFTreeDataModel(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
// XXX Note that we'll just use the parent class's implementation
|
||||
// of AddRef() and Release()
|
||||
#if 0
|
||||
NS_DECL_ISUPPORTS
|
||||
#endif
|
||||
|
||||
// NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
// NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
|
||||
|
||||
#if 0
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDataModel interface
|
||||
|
||||
// Initializers
|
||||
NS_IMETHOD InitFromURL(const nsString& url);
|
||||
NS_IMETHOD InitFromResource(nsIDMItem* pResource);
|
||||
|
||||
// Inspectors
|
||||
NS_IMETHOD GetDMWidget(nsIDMWidget*& pWidget) const;
|
||||
|
||||
// Setters
|
||||
NS_IMETHOD SetDMWidget(nsIDMWidget* pWidget);
|
||||
|
||||
// Methods to query the data model for property values for an entire widget.
|
||||
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& property) const;
|
||||
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& property) const;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsITreeDataModel interface
|
||||
|
||||
// Column APIs
|
||||
NS_IMETHOD GetVisibleColumnCount(PRUint32& count) const;
|
||||
NS_IMETHOD GetColumnCount(PRUint32& count) const;
|
||||
NS_IMETHOD GetNthColumn(nsITreeColumn*& pColumn, PRUint32 n) const;
|
||||
|
||||
// TreeItem APIs
|
||||
@ -57,10 +77,14 @@ public:
|
||||
NS_IMETHOD GetNthTreeItem(nsITreeDMItem*& pItem, PRUint32 n) const;
|
||||
NS_IMETHOD GetItemTextForColumn(nsString& nodeText, nsITreeDMItem* pItem, nsITreeColumn* pColumn) const;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void AddColumn(const nsString& name, RDF_Resource property);
|
||||
|
||||
private:
|
||||
RDF_Resource& mRoot;
|
||||
nsVector mColumns;
|
||||
nsVector mColumns;
|
||||
|
||||
void CreateColumns(void);
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,15 +21,15 @@
|
||||
|
||||
const PRUint32 nsRDFTreeDataModelItem::kInvalidIndentationLevel = PRUint32(-1);
|
||||
|
||||
static NS_DEFINE_IID(kIDMItemIID, NS_IDMITEM_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kITreeDMItemIID, NS_ITREEDMITEM_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFTreeDataModelItem::nsRDFTreeDataModelItem(nsRDFTreeDataModel& tree, RDF_Resource& resource)
|
||||
: nsRDFDataModelItem(resource),
|
||||
mTree(tree),
|
||||
mOpen(PR_FALSE),
|
||||
mEnabled(PR_FALSE)
|
||||
nsRDFTreeDataModelItem::nsRDFTreeDataModelItem(nsRDFTreeDataModel& tree,
|
||||
RDF_Resource resource)
|
||||
: nsRDFDataModelItem(tree, resource)
|
||||
{
|
||||
}
|
||||
|
||||
@ -39,6 +39,20 @@ nsRDFTreeDataModelItem::~nsRDFTreeDataModelItem(void)
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFTreeDataModelItem::AddRef(void)
|
||||
{
|
||||
return nsRDFDataModelItem::AddRef();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt)
|
||||
nsRDFTreeDataModelItem::Release(void)
|
||||
{
|
||||
return nsRDFDataModelItem::Release();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
{
|
||||
@ -48,7 +62,7 @@ nsRDFTreeDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
*result = NULL;
|
||||
if (iid.Equals(kITreeDMItemIID)) {
|
||||
*result = static_cast<nsITreeDMItem*>(this);
|
||||
nsRDFDataModelItem::AddRef(); // delegate to the superclass
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -57,6 +71,62 @@ nsRDFTreeDataModelItem::QueryInterface(const nsIID& iid, void** result)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if 0
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetOpenState(PRBool& result) const
|
||||
{
|
||||
result = IsOpen();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetChildCount(PRUint32& count) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 item) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetParent(nsIDMItem*& pItem) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetStringPropertyValue(nsString& result, const nsString& property) const
|
||||
{
|
||||
// 1. convert the property to a URI
|
||||
// 2. ask the RDF database for the value of the property
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -70,10 +140,14 @@ nsRDFTreeDataModelItem::GetTriggerImage(nsIImage*& pImage, nsIImageGroup* pGroup
|
||||
NS_IMETHODIMP
|
||||
nsRDFTreeDataModelItem::GetIndentationLevel(PRUint32& indentation) const
|
||||
{
|
||||
// 1. ask the tree what the parent/child URI is.
|
||||
// 2. use it to walk back up to the root, counting as we go
|
||||
// 3. multiply the resulting count by the pixel width
|
||||
PRUint32 i = 0;
|
||||
|
||||
mCachedIndentationLevel = 0; // XXX test "mutable" keyword
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsRDFDataModelItem* item =
|
||||
static_cast<nsRDFDataModelItem*>(const_cast<nsRDFTreeDataModelItem*>(this));
|
||||
|
||||
while ((item = item->GetParent()) != NULL)
|
||||
i += 1; // XXX should this be some pixel value?
|
||||
|
||||
indentation = i;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -28,21 +28,41 @@ class nsRDFTreeDataModel;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsRDFTreeDataModelItem : public nsRDFDataModelItem, nsITreeDMItem {
|
||||
class nsRDFTreeDataModelItem : public nsITreeDMItem, public nsRDFDataModelItem
|
||||
{
|
||||
public:
|
||||
nsRDFTreeDataModelItem(nsRDFTreeDataModel& tree, RDF_Resource& resource);
|
||||
nsRDFTreeDataModelItem(nsRDFTreeDataModel& tree, RDF_Resource resource);
|
||||
virtual ~nsRDFTreeDataModelItem(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
// XXX Note that we'll just use the parent class's implementation
|
||||
// of AddRef() and Release()
|
||||
|
||||
// NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
// NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
|
||||
|
||||
#if 0
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDMItem interface
|
||||
|
||||
// Inspectors
|
||||
NS_IMETHOD GetIconImage(nsIImage*& pImage, nsIImageGroup* pGroup) const;
|
||||
NS_IMETHOD GetOpenState(PRBool& answer) const;
|
||||
|
||||
// Methods for iterating over children.
|
||||
NS_IMETHOD GetChildCount(PRUint32& count) const;
|
||||
NS_IMETHOD GetNthChild(nsIDMItem*& pItem, PRUint32 item) const;
|
||||
|
||||
// Parent access
|
||||
NS_IMETHOD GetParent(nsIDMItem*& pItem) const;
|
||||
|
||||
// Setters
|
||||
|
||||
// Methods to query the data model for a specific item displayed within the widget.
|
||||
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& itemProperty) const;
|
||||
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsITreeItem interface
|
||||
|
||||
@ -55,10 +75,7 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
nsRDFTreeDataModel& mTree;
|
||||
PRBool mOpen;
|
||||
PRBool mEnabled;
|
||||
mutable PRUint32 mCachedIndentationLevel;
|
||||
mutable PRUint32 mCachedIndentationLevel;
|
||||
|
||||
static const PRUint32 kInvalidIndentationLevel;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user