Adding builtin support for twisties.

This commit is contained in:
hyatt%netscape.com 1999-08-25 10:57:28 +00:00
parent 9ea8122814
commit a563040dcd
7 changed files with 227 additions and 1 deletions

View File

@ -53,6 +53,7 @@ CPPSRCS = \
nsTreeRowGroupFrame.cpp \
nsTreeIndentationFrame.cpp \
nsTreeCellFrame.cpp \
nsTreeTwistyListener.cpp \
nsTriStateCheckboxFrame.cpp \
nsSpinnerFrame.cpp \
nsScrollbarFrame.cpp \

View File

@ -41,6 +41,7 @@ CPPSRCS= \
nsTreeRowGroupFrame.cpp \
nsTreeIndentationFrame.cpp \
nsTreeCellFrame.cpp \
nsTreeTwistyListener.cpp \
nsTriStateCheckboxFrame.cpp \
nsSpinnerFrame.cpp \
nsScrollbarFrame.cpp \
@ -73,6 +74,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsTreeRowGroupFrame.obj \
.\$(OBJDIR)\nsTreeIndentationFrame.obj \
.\$(OBJDIR)\nsTreeCellFrame.obj \
.\$(OBJDIR)\nsTreeTwistyListener.obj \
.\$(OBJDIR)\nsTriStateCheckboxFrame.obj \
.\$(OBJDIR)\nsSpinnerFrame.obj \
.\$(OBJDIR)\nsScrollbarFrame.obj \

View File

@ -387,3 +387,4 @@ nsTreeCellFrame::Destroy(nsIPresContext& aPresContext)
{
return nsTableCellFrame::Destroy(aPresContext);
}

View File

@ -30,6 +30,8 @@
#include "nsXULAtoms.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMXULTreeElement.h"
#include "nsTreeTwistyListener.h"
//
// NS_NewTreeFrame
//
@ -54,7 +56,7 @@ NS_NewTreeFrame (nsIFrame** aNewFrame)
// Constructor
nsTreeFrame::nsTreeFrame()
:nsTableFrame(),mSlatedForReflow(PR_FALSE) { }
:nsTableFrame(),mSlatedForReflow(PR_FALSE), mTwistyListener(nsnull) { }
// Destructor
nsTreeFrame::~nsTreeFrame()
@ -285,6 +287,9 @@ void nsTreeFrame::MoveToRowCol(nsIPresContext& aPresContext, PRInt32 aRow, PRInt
NS_IMETHODIMP
nsTreeFrame::Destroy(nsIPresContext& aPresContext)
{
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(mContent);
target->RemoveEventListener("mousedown", mTwistyListener, PR_TRUE);
mTwistyListener = nsnull;
return nsTableFrame::Destroy(aPresContext);
}
@ -297,3 +302,22 @@ nsTreeFrame::Reflow(nsIPresContext& aPresContext,
mSlatedForReflow = PR_FALSE;
return nsTableFrame::Reflow(aPresContext, aMetrics, aReflowState, aStatus);
}
NS_IMETHODIMP
nsTreeFrame::Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow)
{
nsresult rv = nsTableFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
// Create the menu bar listener.
mTwistyListener = new nsTreeTwistyListener();
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(mContent);
target->AddEventListener("mousedown", mTwistyListener, PR_TRUE);
return rv;
}

View File

@ -22,6 +22,7 @@
class nsTreeCellFrame;
class nsTreeRowGroupFrame;
class nsTreeTwistyListener;
class nsTreeFrame : public nsTableFrame
{
@ -55,11 +56,19 @@ public:
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD Init(nsIPresContext& aPresContext,
nsIContent* aContent,
nsIFrame* aParent,
nsIStyleContext* aContext,
nsIFrame* aPrevInFlow);
protected:
nsTreeFrame();
virtual ~nsTreeFrame();
protected: // Data Members
PRBool mSlatedForReflow; // If set, don't waste time scheduling excess reflows.
nsTreeTwistyListener* mTwistyListener;
}; // class nsTreeFrame

View File

@ -0,0 +1,135 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsTreeTwistyListener.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMEventListener.h"
#include "nsCOMPtr.h"
#include "nsIDOMUIEvent.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsXULAtoms.h"
/*
* nsTreeTwistyListener implementation
*/
NS_IMPL_ADDREF(nsTreeTwistyListener)
NS_IMPL_RELEASE(nsTreeTwistyListener)
////////////////////////////////////////////////////////////////////////
nsTreeTwistyListener::nsTreeTwistyListener()
{
NS_INIT_REFCNT();
}
////////////////////////////////////////////////////////////////////////
nsTreeTwistyListener::~nsTreeTwistyListener()
{
}
////////////////////////////////////////////////////////////////////////
nsresult
nsTreeTwistyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMEventReceiver>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMEventListener*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsIDOMMouseListener>::GetIID())) {
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMKeyListener*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
static void GetTreeItem(nsIDOMElement* aElement, nsIDOMElement** aResult)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
while (content) {
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag == nsXULAtoms::treeitem) {
nsCOMPtr<nsIDOMElement> result = do_QueryInterface(content);
*aResult = result.get();
NS_IF_ADDREF(*aResult);
return;
}
nsCOMPtr<nsIContent> parent;
content->GetParent(*getter_AddRefs(parent));
content = parent;
}
}
nsresult
nsTreeTwistyListener::MouseDown(nsIDOMEvent* aEvent)
{
// Get the target of the event. If it's a titledbutton, we care.
nsCOMPtr<nsIDOMNode> target;
aEvent->GetTarget(getter_AddRefs(target));
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
if (!element)
return NS_OK;
nsAutoString tagName;
element->GetTagName(tagName);
if (tagName == "titledbutton") {
// Find out if we're the twisty.
nsAutoString classAttr;
element->GetAttribute("class", classAttr);
if (classAttr == "twisty") {
// Retrieve the parent treeitem.
nsCOMPtr<nsIDOMElement> treeItem;
GetTreeItem(element, getter_AddRefs(treeItem));
if (!treeItem)
return NS_OK;
// Eat the event.
aEvent->PreventCapture();
aEvent->PreventBubble();
nsAutoString open;
treeItem->GetAttribute("open", open);
if (open == "true")
treeItem->RemoveAttribute("open");
else treeItem->SetAttribute("open", "true");
}
}
return NS_OK;
}

View File

@ -0,0 +1,54 @@
/* -*- 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 "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsTreeTwistyListener_h__
#define nsTreeTwistyListener_h__
#include "nsIDOMMouseListener.h"
#include "nsIDOMEventReceiver.h"
class nsIPresContext;
/** editor Implementation of the DragListener interface
*/
class nsTreeTwistyListener : public nsIDOMMouseListener
{
public:
/** default constructor
*/
nsTreeTwistyListener();
/** default destructor
*/
virtual ~nsTreeTwistyListener();
virtual nsresult HandleEvent(nsIDOMEvent* aEvent) { return NS_OK; };
virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent) { return NS_OK; };
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent) { return NS_OK; };
NS_DECL_ISUPPORTS
protected:
};
#endif