Implemented all of the tree widget selection APIs but ranged selection (which will

be fun and nasty).
This commit is contained in:
hyatt%netscape.com 1999-08-22 06:17:16 +00:00
Родитель 850b37e110
Коммит b8cf1c5a5d
4 изменённых файлов: 144 добавлений и 6 удалений

Просмотреть файл

@ -26,12 +26,21 @@
#include "nsCOMPtr.h"
#include "nsRDFCID.h"
#include "nsXULTreeElement.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
nsIAtom* nsXULTreeElement::kSelectedAtom;
int nsXULTreeElement::gRefCnt = 0;
NS_IMPL_ISUPPORTS_INHERITED(nsXULTreeElement, nsXULElement, nsIDOMXULTreeElement);
nsXULTreeElement::nsXULTreeElement(nsIDOMXULElement* aOuter)
:nsXULElement(aOuter)
{
if (gRefCnt++ == 0) {
kSelectedAtom = NS_NewAtom("selected");
}
nsresult rv;
nsRDFDOMNodeList* children;
@ -53,6 +62,10 @@ nsXULTreeElement::~nsXULTreeElement()
{
NS_IF_RELEASE(mSelectedItems);
NS_IF_RELEASE(mSelectedCells);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kSelectedAtom);
}
}
NS_IMETHODIMP
@ -74,24 +87,59 @@ nsXULTreeElement::GetSelectedCells(nsIDOMNodeList** aSelectedCells)
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
{
// First clear our selection.
ClearSelection();
// Now add ourselves to the selection by setting our selected attribute.
AddItemToSelection(aTreeItem);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectCell(nsIDOMXULElement* aTreeCell)
{
// First clear our selection.
ClearSelection();
// Now add ourselves to the selection by setting our selected attribute.
AddCellToSelection(aTreeCell);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::ClearSelection()
{
// Enumerate the elements and remove them from the selection.
PRUint32 length;
mSelectedItems->GetLength(&length);
PRUint32 i;
for (i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
mSelectedItems->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
mSelectedCells->GetLength(&length);
for (i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
mSelectedCells->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
{
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, "true", PR_TRUE);
return NS_OK;
}
@ -99,18 +147,26 @@ nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
NS_IMETHODIMP
nsXULTreeElement::RemoveItemFromSelection(nsIDOMXULElement* aTreeItem)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::AddCellToSelection(nsIDOMXULElement* aTreeCell)
{
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeCell);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, "true", PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeCell);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
return NS_OK;
}
@ -118,23 +174,33 @@ nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)
NS_IMETHODIMP
nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)
{
// XXX Fill in.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)
{
// XXX Fill in.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectAll()
{
// Do a clear.
ClearSelection();
// Now do an invert. That will select everything.
InvertSelection();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::InvertSelection()
{
// XXX Woo hoo. Write this later.
// Yikes. Involves an enumeration of the whole tree.
return NS_OK;
}

Просмотреть файл

@ -50,10 +50,13 @@ public:
// nsIDOMXULTreeElement interface
NS_DECL_IDOMXULTREEELEMENT
static nsIAtom* kSelectedAtom;
static int gRefCnt;
protected:
nsIDOMNodeList* mSelectedItems;
nsIDOMNodeList* mSelectedCells;
nsRDFDOMNodeList* mSelectedItems;
nsRDFDOMNodeList* mSelectedCells;
};

Просмотреть файл

@ -26,12 +26,21 @@
#include "nsCOMPtr.h"
#include "nsRDFCID.h"
#include "nsXULTreeElement.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
nsIAtom* nsXULTreeElement::kSelectedAtom;
int nsXULTreeElement::gRefCnt = 0;
NS_IMPL_ISUPPORTS_INHERITED(nsXULTreeElement, nsXULElement, nsIDOMXULTreeElement);
nsXULTreeElement::nsXULTreeElement(nsIDOMXULElement* aOuter)
:nsXULElement(aOuter)
{
if (gRefCnt++ == 0) {
kSelectedAtom = NS_NewAtom("selected");
}
nsresult rv;
nsRDFDOMNodeList* children;
@ -53,6 +62,10 @@ nsXULTreeElement::~nsXULTreeElement()
{
NS_IF_RELEASE(mSelectedItems);
NS_IF_RELEASE(mSelectedCells);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kSelectedAtom);
}
}
NS_IMETHODIMP
@ -74,24 +87,59 @@ nsXULTreeElement::GetSelectedCells(nsIDOMNodeList** aSelectedCells)
NS_IMETHODIMP
nsXULTreeElement::SelectItem(nsIDOMXULElement* aTreeItem)
{
// First clear our selection.
ClearSelection();
// Now add ourselves to the selection by setting our selected attribute.
AddItemToSelection(aTreeItem);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectCell(nsIDOMXULElement* aTreeCell)
{
// First clear our selection.
ClearSelection();
// Now add ourselves to the selection by setting our selected attribute.
AddCellToSelection(aTreeCell);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::ClearSelection()
{
// Enumerate the elements and remove them from the selection.
PRUint32 length;
mSelectedItems->GetLength(&length);
PRUint32 i;
for (i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
mSelectedItems->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
mSelectedCells->GetLength(&length);
for (i = 0; i < length; i++) {
nsCOMPtr<nsIDOMNode> node;
mSelectedCells->Item(0, getter_AddRefs(node));
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
}
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
{
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, "true", PR_TRUE);
return NS_OK;
}
@ -99,18 +147,26 @@ nsXULTreeElement::AddItemToSelection(nsIDOMXULElement* aTreeItem)
NS_IMETHODIMP
nsXULTreeElement::RemoveItemFromSelection(nsIDOMXULElement* aTreeItem)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeItem);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::AddCellToSelection(nsIDOMXULElement* aTreeCell)
{
// Without clearing the selection, perform the add.
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeCell);
content->SetAttribute(kNameSpaceID_None, kSelectedAtom, "true", PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aTreeCell);
content->UnsetAttribute(kNameSpaceID_None, kSelectedAtom, PR_TRUE);
return NS_OK;
}
@ -118,23 +174,33 @@ nsXULTreeElement::RemoveCellFromSelection(nsIDOMXULElement* aTreeCell)
NS_IMETHODIMP
nsXULTreeElement::SelectItemRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)
{
// XXX Fill in.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectCellRange(nsIDOMXULElement* aStartItem, nsIDOMXULElement* aEndItem)
{
// XXX Fill in.
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::SelectAll()
{
// Do a clear.
ClearSelection();
// Now do an invert. That will select everything.
InvertSelection();
return NS_OK;
}
NS_IMETHODIMP
nsXULTreeElement::InvertSelection()
{
// XXX Woo hoo. Write this later.
// Yikes. Involves an enumeration of the whole tree.
return NS_OK;
}

Просмотреть файл

@ -50,10 +50,13 @@ public:
// nsIDOMXULTreeElement interface
NS_DECL_IDOMXULTREEELEMENT
static nsIAtom* kSelectedAtom;
static int gRefCnt;
protected:
nsIDOMNodeList* mSelectedItems;
nsIDOMNodeList* mSelectedCells;
nsRDFDOMNodeList* mSelectedItems;
nsRDFDOMNodeList* mSelectedCells;
};