From 6fa63c6ee6753c2c3265a67c091fa7d8f802d7d6 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Wed, 27 Jan 1999 07:31:14 +0000 Subject: [PATCH] Adding tree cell frame. git-svn-id: svn://10.0.0.236/trunk@18758 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/xul/base/src/Makefile.in | 1 + mozilla/layout/xul/base/src/makefile.win | 2 + .../layout/xul/base/src/nsTreeCellFrame.cpp | 174 ++++++++++++++++++ mozilla/layout/xul/base/src/nsTreeCellFrame.h | 53 ++++++ 4 files changed, 230 insertions(+) create mode 100644 mozilla/layout/xul/base/src/nsTreeCellFrame.cpp create mode 100644 mozilla/layout/xul/base/src/nsTreeCellFrame.h diff --git a/mozilla/layout/xul/base/src/Makefile.in b/mozilla/layout/xul/base/src/Makefile.in index 4e07ca0f0c1..cdef3a2d133 100644 --- a/mozilla/layout/xul/base/src/Makefile.in +++ b/mozilla/layout/xul/base/src/Makefile.in @@ -43,6 +43,7 @@ CPPSRCS = \ nsToolboxFrame.cpp \ nsTreeFrame.cpp \ nsTreeIndentationFrame.cpp \ + nsTreeCellFrame.cpp \ $(NULL) EXPORTS = \ diff --git a/mozilla/layout/xul/base/src/makefile.win b/mozilla/layout/xul/base/src/makefile.win index 4b2b0865c99..e32da95db90 100644 --- a/mozilla/layout/xul/base/src/makefile.win +++ b/mozilla/layout/xul/base/src/makefile.win @@ -28,6 +28,7 @@ CPPSRCS= \ nsToolbarFrame.cpp \ nsTreeFrame.cpp \ nsTreeIndentationFrame.cpp \ + nsTreeCellFrame.cpp \ $(NULL) CPP_OBJS= \ @@ -35,6 +36,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsToolbarFrame.obj \ .\$(OBJDIR)\nsTreeFrame.obj \ .\$(OBJDIR)\nsTreeIndentationFrame.obj \ + .\$(OBJDIR)\nsTreeCellFrame.obj \ $(NULL) EXPORTS = \ diff --git a/mozilla/layout/xul/base/src/nsTreeCellFrame.cpp b/mozilla/layout/xul/base/src/nsTreeCellFrame.cpp new file mode 100644 index 00000000000..50048e8a6f3 --- /dev/null +++ b/mozilla/layout/xul/base/src/nsTreeCellFrame.cpp @@ -0,0 +1,174 @@ +/* -*- 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 "nsINameSpaceManager.h" +#include "nsHTMLAtoms.h" +#include "nsTreeCellFrame.h" +#include "nsIStyleContext.h" +#include "nsIPresContext.h" +#include "nsIViewManager.h" +#include "nsCSSRendering.h" + +// Constants (styles used for selection rendering) +const char * kNormal = ""; +const char * kSelected = "TREESELECTION"; +const char * kSelectedFocus = "TREESELECTIONFOCUS"; + +static void ForceDrawFrame(nsIFrame * aFrame) +{ + if (aFrame == nsnull) { + return; + } + nsRect rect; + nsIView * view; + nsPoint pnt; + aFrame->GetOffsetFromView(pnt, view); + aFrame->GetRect(rect); + rect.x = pnt.x; + rect.y = pnt.y; + if (view != nsnull) { + nsIViewManager * viewMgr; + view->GetViewManager(viewMgr); + if (viewMgr != nsnull) { + viewMgr->UpdateView(view, rect, 0); + NS_RELEASE(viewMgr); + } + } + +} + +// +// NS_NewTreeCellFrame +// +// Creates a new tree cell frame +// +nsresult +NS_NewTreeCellFrame (nsIFrame*& aNewFrame) +{ + nsTreeCellFrame* theFrame = new nsTreeCellFrame; + if (theFrame == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + + aNewFrame = theFrame; + return NS_OK; + +} // NS_NewTreeCellFrame + + +// Constructor +nsTreeCellFrame::nsTreeCellFrame() +:nsTableCellFrame() { mIsHeader = PR_FALSE; } + +// Destructor +nsTreeCellFrame::~nsTreeCellFrame() +{ +} + +NS_IMETHODIMP +nsTreeCellFrame::Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext) +{ + // Determine if we're a column header or not. + + // Get row group frame + nsIFrame* pRowGroupFrame = nsnull; + aParent->GetParent(pRowGroupFrame); + if (pRowGroupFrame != nsnull) + { + // Get the display type of the row group frame and see if it's a header or body + nsIStyleContext* parentContext = nsnull; + pRowGroupFrame->GetStyleContext(parentContext); + if (parentContext) + { + const nsStyleDisplay* display = (const nsStyleDisplay*) + parentContext->GetStyleData(eStyleStruct_Display); + if (display->mDisplay == NS_STYLE_DISPLAY_TABLE_HEADER_GROUP) + { + mIsHeader = PR_TRUE; + } + else mIsHeader = PR_FALSE; + NS_IF_RELEASE(parentContext); + } + } + return nsTableCellFrame::Init(aPresContext, aContent, aParent, aContext); +} + +NS_IMETHODIMP +nsTreeCellFrame::GetFrameForPoint(const nsPoint& aPoint, + nsIFrame** aFrame) +{ + *aFrame = this; // Capture all events so that we can perform selection and expand/collapse. + return NS_OK; +} + +NS_IMETHODIMP +nsTreeCellFrame::HandleEvent(nsIPresContext& aPresContext, + nsGUIEvent* aEvent, + nsEventStatus& aEventStatus) +{ + if (nsEventStatus_eConsumeNoDefault == aEventStatus) { + return NS_OK; + } + + const nsStyleDisplay* disp = (const nsStyleDisplay*)mStyleContext->GetStyleData(eStyleStruct_Display); + if (!disp->mVisible) { + return NS_OK; + } + + if(nsEventStatus_eConsumeNoDefault != aEventStatus) { + + aEventStatus = nsEventStatus_eConsumeNoDefault; + if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) + HandleMouseDownEvent(aPresContext, aEvent, aEventStatus); + } + + return NS_OK; +} + +nsresult +nsTreeCellFrame::HandleMouseDownEvent(nsIPresContext& aPresContext, + nsGUIEvent* aEvent, + nsEventStatus& aEventStatus) +{ + if (mIsHeader) + { + // Toggle the sort state + } + else + { + // Perform a selection + SetSelection(aPresContext); + + } + return NS_OK; +} + +void +nsTreeCellFrame::SetSelection(nsIPresContext& aPresContext) +{ + nsIAtom * selectedPseudo = NS_NewAtom(":TREE-SELECTION"); + mSelectedContext = aPresContext.ResolvePseudoStyleContextFor(mContent, selectedPseudo, mStyleContext); + SetStyleContext(&aPresContext, mSelectedContext); + + ForceDrawFrame(this); + + NS_RELEASE(selectedPseudo); +} diff --git a/mozilla/layout/xul/base/src/nsTreeCellFrame.h b/mozilla/layout/xul/base/src/nsTreeCellFrame.h new file mode 100644 index 00000000000..8d35c046203 --- /dev/null +++ b/mozilla/layout/xul/base/src/nsTreeCellFrame.h @@ -0,0 +1,53 @@ +/* -*- 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 "nsTableCellFrame.h" + +class nsTreeCellFrame : public nsTableCellFrame +{ +public: + friend nsresult NS_NewTreeCellFrame(nsIFrame*& aNewFrame); + + NS_IMETHOD GetFrameForPoint(const nsPoint& aPoint, // Overridden to capture events + nsIFrame** aFrame); + + NS_IMETHOD HandleEvent(nsIPresContext& aPresContext, + nsGUIEvent* aEvent, + nsEventStatus& aEventStatus); + + NS_IMETHOD Init(nsIPresContext& aPresContext, + nsIContent* aContent, + nsIFrame* aParent, + nsIStyleContext* aContext); // Overridden to set whether we're a column header + +protected: + nsTreeCellFrame(); + virtual ~nsTreeCellFrame(); + + nsresult HandleMouseDownEvent(nsIPresContext& aPresContext, + nsGUIEvent* aEvent, + nsEventStatus& aEventStatus); + + void SetSelection(nsIPresContext& aPresContext); + +protected: + // Data members + PRBool mIsHeader; // Whether or not we're a column header + nsIStyleContext* mSelectedContext; // The style context to use when the tree item is selected +}; // class nsTableCellFrame