From 46340eebe576fc0c1c73b2f519358eec5a37fb34 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Sun, 22 Aug 1999 06:31:00 +0000 Subject: [PATCH] Checking in the selection implementation (with more functions added). --- content/xul/content/src/nsXULTreeElement.cpp | 24 ++++ dom/public/idl/xul/XULTreeElement.idl | 3 + dom/public/xul/nsIDOMXULTreeElement.h | 8 ++ dom/src/xul/nsJSXULTreeElement.cpp | 114 +++++++++++++++++++ rdf/content/public/idl/XULTreeElement.idl | 3 + rdf/content/public/nsIDOMXULTreeElement.h | 8 ++ rdf/content/src/nsJSXULTreeElement.cpp | 114 +++++++++++++++++++ rdf/content/src/nsXULTreeElement.cpp | 24 ++++ 8 files changed, 298 insertions(+) diff --git a/content/xul/content/src/nsXULTreeElement.cpp b/content/xul/content/src/nsXULTreeElement.cpp index 72efb683d788..fade86ebca52 100644 --- a/content/xul/content/src/nsXULTreeElement.cpp +++ b/content/xul/content/src/nsXULTreeElement.cpp @@ -170,6 +170,30 @@ nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell) return NS_OK; } +NS_IMETHODIMP +nsXULTreeElement::ToggleItemSelection(nsIDOMXULElement* aTreeItem) +{ + nsAutoString isSelected; + aTreeItem->GetAttribute("selected", isSelected); + if (isSelected == "true") + RemoveItemFromSelection(aTreeItem); + else AddItemToSelection(aTreeItem); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULTreeElement::ToggleCellSelection(nsIDOMXULElement* aTreeCell) +{ + nsAutoString isSelected; + aTreeCell->GetAttribute("selected", isSelected); + if (isSelected == "true") + RemoveItemFromSelection(aTreeCell); + else AddItemToSelection(aTreeCell); + + return NS_OK; +} + NS_IMETHODIMP nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) diff --git a/dom/public/idl/xul/XULTreeElement.idl b/dom/public/idl/xul/XULTreeElement.idl index 794184b7b4c0..7f16d7fdca83 100644 --- a/dom/public/idl/xul/XULTreeElement.idl +++ b/dom/public/idl/xul/XULTreeElement.idl @@ -15,6 +15,9 @@ interface XULTreeElement : XULElement { void addCellToSelection(in XULElement treeCell); void removeCellFromSelection(in XULElement treeCell); + void toggleItemSelection(in XULElement treeItem); + void toggleCellSelection(in XULElement treeCell); + void selectItemRange(in XULElement startItem, in XULElement endItem); void selectCellRange(in XULElement startItem, in XULElement endItem); diff --git a/dom/public/xul/nsIDOMXULTreeElement.h b/dom/public/xul/nsIDOMXULTreeElement.h index 5af923cb02c9..29c1a49f4bd8 100644 --- a/dom/public/xul/nsIDOMXULTreeElement.h +++ b/dom/public/xul/nsIDOMXULTreeElement.h @@ -54,6 +54,10 @@ public: NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)=0; + NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem)=0; + + NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell)=0; + NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)=0; NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)=0; @@ -74,6 +78,8 @@ public: NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem); \ NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell); \ NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell); \ + NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem); \ + NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell); \ NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem); \ NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem); \ NS_IMETHOD SelectAll(); \ @@ -91,6 +97,8 @@ public: NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem) { return _to RemoveItemFromSelection(aTreeItem); } \ NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell) { return _to AddCellToSelection(aTreeCell); } \ NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell) { return _to RemoveCellFromSelection(aTreeCell); } \ + NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem) { return _to ToggleItemSelection(aTreeItem); } \ + NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell) { return _to ToggleCellSelection(aTreeCell); } \ NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) { return _to SelectItemRange(aStartItem, aEndItem); } \ NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) { return _to SelectCellRange(aStartItem, aEndItem); } \ NS_IMETHOD SelectAll() { return _to SelectAll(); } \ diff --git a/dom/src/xul/nsJSXULTreeElement.cpp b/dom/src/xul/nsJSXULTreeElement.cpp index 87f0e2625369..3072c87ad9bb 100644 --- a/dom/src/xul/nsJSXULTreeElement.cpp +++ b/dom/src/xul/nsJSXULTreeElement.cpp @@ -564,6 +564,118 @@ XULTreeElementRemoveCellFromSelection(JSContext *cx, JSObject *obj, uintN argc, } +// +// Native method ToggleItemSelection +// +PR_STATIC_CALLBACK(JSBool) +XULTreeElementToggleItemSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMXULTreeElement *nativeThis = (nsIDOMXULTreeElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsIDOMXULElementPtr b0; + + *rval = JSVAL_NULL; + + nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); + nsIScriptSecurityManager *secMan; + if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { + return JS_FALSE; + } + { + PRBool ok; + secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.toggleitemselection", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + NS_RELEASE(secMan); + } + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + if (argc < 1) { + JS_ReportError(cx, "Function toggleItemSelection requires 1 parameter"); + return JS_FALSE; + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIXULElementIID, + "XULElement", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ToggleItemSelection(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + +// +// Native method ToggleCellSelection +// +PR_STATIC_CALLBACK(JSBool) +XULTreeElementToggleCellSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMXULTreeElement *nativeThis = (nsIDOMXULTreeElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsIDOMXULElementPtr b0; + + *rval = JSVAL_NULL; + + nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); + nsIScriptSecurityManager *secMan; + if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { + return JS_FALSE; + } + { + PRBool ok; + secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.togglecellselection", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + NS_RELEASE(secMan); + } + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + if (argc < 1) { + JS_ReportError(cx, "Function toggleCellSelection requires 1 parameter"); + return JS_FALSE; + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIXULElementIID, + "XULElement", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ToggleCellSelection(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + // // Native method SelectItemRange // @@ -819,6 +931,8 @@ static JSFunctionSpec XULTreeElementMethods[] = {"removeItemFromSelection", XULTreeElementRemoveItemFromSelection, 1}, {"addCellToSelection", XULTreeElementAddCellToSelection, 1}, {"removeCellFromSelection", XULTreeElementRemoveCellFromSelection, 1}, + {"toggleItemSelection", XULTreeElementToggleItemSelection, 1}, + {"toggleCellSelection", XULTreeElementToggleCellSelection, 1}, {"selectItemRange", XULTreeElementSelectItemRange, 2}, {"selectCellRange", XULTreeElementSelectCellRange, 2}, {"selectAll", XULTreeElementSelectAll, 0}, diff --git a/rdf/content/public/idl/XULTreeElement.idl b/rdf/content/public/idl/XULTreeElement.idl index 794184b7b4c0..7f16d7fdca83 100644 --- a/rdf/content/public/idl/XULTreeElement.idl +++ b/rdf/content/public/idl/XULTreeElement.idl @@ -15,6 +15,9 @@ interface XULTreeElement : XULElement { void addCellToSelection(in XULElement treeCell); void removeCellFromSelection(in XULElement treeCell); + void toggleItemSelection(in XULElement treeItem); + void toggleCellSelection(in XULElement treeCell); + void selectItemRange(in XULElement startItem, in XULElement endItem); void selectCellRange(in XULElement startItem, in XULElement endItem); diff --git a/rdf/content/public/nsIDOMXULTreeElement.h b/rdf/content/public/nsIDOMXULTreeElement.h index 5af923cb02c9..29c1a49f4bd8 100644 --- a/rdf/content/public/nsIDOMXULTreeElement.h +++ b/rdf/content/public/nsIDOMXULTreeElement.h @@ -54,6 +54,10 @@ public: NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)=0; + NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem)=0; + + NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell)=0; + NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)=0; NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)=0; @@ -74,6 +78,8 @@ public: NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem); \ NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell); \ NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell); \ + NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem); \ + NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell); \ NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem); \ NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem); \ NS_IMETHOD SelectAll(); \ @@ -91,6 +97,8 @@ public: NS_IMETHOD RemoveItemFromSelection(nsIDOMXULElement* aTreeItem) { return _to RemoveItemFromSelection(aTreeItem); } \ NS_IMETHOD AddCellToSelection(nsIDOMXULElement* aTreeCell) { return _to AddCellToSelection(aTreeCell); } \ NS_IMETHOD RemoveCellFromSelection(nsIDOMXULElement* aTreeCell) { return _to RemoveCellFromSelection(aTreeCell); } \ + NS_IMETHOD ToggleItemSelection(nsIDOMXULElement* aTreeItem) { return _to ToggleItemSelection(aTreeItem); } \ + NS_IMETHOD ToggleCellSelection(nsIDOMXULElement* aTreeCell) { return _to ToggleCellSelection(aTreeCell); } \ NS_IMETHOD SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) { return _to SelectItemRange(aStartItem, aEndItem); } \ NS_IMETHOD SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem) { return _to SelectCellRange(aStartItem, aEndItem); } \ NS_IMETHOD SelectAll() { return _to SelectAll(); } \ diff --git a/rdf/content/src/nsJSXULTreeElement.cpp b/rdf/content/src/nsJSXULTreeElement.cpp index 87f0e2625369..3072c87ad9bb 100644 --- a/rdf/content/src/nsJSXULTreeElement.cpp +++ b/rdf/content/src/nsJSXULTreeElement.cpp @@ -564,6 +564,118 @@ XULTreeElementRemoveCellFromSelection(JSContext *cx, JSObject *obj, uintN argc, } +// +// Native method ToggleItemSelection +// +PR_STATIC_CALLBACK(JSBool) +XULTreeElementToggleItemSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMXULTreeElement *nativeThis = (nsIDOMXULTreeElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsIDOMXULElementPtr b0; + + *rval = JSVAL_NULL; + + nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); + nsIScriptSecurityManager *secMan; + if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { + return JS_FALSE; + } + { + PRBool ok; + secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.toggleitemselection", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + NS_RELEASE(secMan); + } + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + if (argc < 1) { + JS_ReportError(cx, "Function toggleItemSelection requires 1 parameter"); + return JS_FALSE; + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIXULElementIID, + "XULElement", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ToggleItemSelection(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + +// +// Native method ToggleCellSelection +// +PR_STATIC_CALLBACK(JSBool) +XULTreeElementToggleCellSelection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMXULTreeElement *nativeThis = (nsIDOMXULTreeElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsIDOMXULElementPtr b0; + + *rval = JSVAL_NULL; + + nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx); + nsIScriptSecurityManager *secMan; + if (NS_OK != scriptCX->GetSecurityManager(&secMan)) { + return JS_FALSE; + } + { + PRBool ok; + secMan->CheckScriptAccess(scriptCX, obj, "xultreeelement.togglecellselection", &ok); + if (!ok) { + //Need to throw error here + return JS_FALSE; + } + NS_RELEASE(secMan); + } + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + if (argc < 1) { + JS_ReportError(cx, "Function toggleCellSelection requires 1 parameter"); + return JS_FALSE; + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kIXULElementIID, + "XULElement", + cx, + argv[0])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ToggleCellSelection(b0)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + // // Native method SelectItemRange // @@ -819,6 +931,8 @@ static JSFunctionSpec XULTreeElementMethods[] = {"removeItemFromSelection", XULTreeElementRemoveItemFromSelection, 1}, {"addCellToSelection", XULTreeElementAddCellToSelection, 1}, {"removeCellFromSelection", XULTreeElementRemoveCellFromSelection, 1}, + {"toggleItemSelection", XULTreeElementToggleItemSelection, 1}, + {"toggleCellSelection", XULTreeElementToggleCellSelection, 1}, {"selectItemRange", XULTreeElementSelectItemRange, 2}, {"selectCellRange", XULTreeElementSelectCellRange, 2}, {"selectAll", XULTreeElementSelectAll, 0}, diff --git a/rdf/content/src/nsXULTreeElement.cpp b/rdf/content/src/nsXULTreeElement.cpp index 72efb683d788..fade86ebca52 100644 --- a/rdf/content/src/nsXULTreeElement.cpp +++ b/rdf/content/src/nsXULTreeElement.cpp @@ -170,6 +170,30 @@ nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell) return NS_OK; } +NS_IMETHODIMP +nsXULTreeElement::ToggleItemSelection(nsIDOMXULElement* aTreeItem) +{ + nsAutoString isSelected; + aTreeItem->GetAttribute("selected", isSelected); + if (isSelected == "true") + RemoveItemFromSelection(aTreeItem); + else AddItemToSelection(aTreeItem); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULTreeElement::ToggleCellSelection(nsIDOMXULElement* aTreeCell) +{ + nsAutoString isSelected; + aTreeCell->GetAttribute("selected", isSelected); + if (isSelected == "true") + RemoveItemFromSelection(aTreeCell); + else AddItemToSelection(aTreeCell); + + return NS_OK; +} + NS_IMETHODIMP nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)