From d6fb7c48abc4b1b7e3d8b062eac9d997df45ccb8 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Tue, 23 Feb 1999 02:39:44 +0000 Subject: [PATCH] Changing selection in the tree. --- layout/xul/base/src/nsTreeCellFrame.cpp | 110 +++++++++++++----------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/layout/xul/base/src/nsTreeCellFrame.cpp b/layout/xul/base/src/nsTreeCellFrame.cpp index 4e0bb73f17c1..fa6ea5c5b800 100644 --- a/layout/xul/base/src/nsTreeCellFrame.cpp +++ b/layout/xul/base/src/nsTreeCellFrame.cpp @@ -163,10 +163,10 @@ nsTreeCellFrame::HandleEvent(nsIPresContext& aPresContext, if(nsEventStatus_eConsumeNoDefault != aEventStatus) { aEventStatus = nsEventStatus_eConsumeDoDefault; - if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) - HandleMouseDownEvent(aPresContext, aEvent, aEventStatus); - else if (aEvent->message == NS_MOUSE_LEFT_DOUBLECLICK) - HandleDoubleClickEvent(aPresContext, aEvent, aEventStatus); + if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) + HandleMouseDownEvent(aPresContext, aEvent, aEventStatus); + else if (aEvent->message == NS_MOUSE_LEFT_DOUBLECLICK) + HandleDoubleClickEvent(aPresContext, aEvent, aEventStatus); } return NS_OK; @@ -184,11 +184,11 @@ nsTreeCellFrame::HandleMouseDownEvent(nsIPresContext& aPresContext, else { // Perform a selection - if (((nsMouseEvent *)aEvent)->isShift) - mTreeFrame->RangedSelection(aPresContext, this); // Applying a ranged selection. - else if (((nsMouseEvent *)aEvent)->isControl) - mTreeFrame->ToggleSelection(aPresContext, this); // Applying a toggle selection. - else mTreeFrame->SetSelection(aPresContext, this); // Doing a single selection only. + if (((nsMouseEvent *)aEvent)->isShift) + mTreeFrame->RangedSelection(aPresContext, this); // Applying a ranged selection. + else if (((nsMouseEvent *)aEvent)->isControl) + mTreeFrame->ToggleSelection(aPresContext, this); // Applying a toggle selection. + else mTreeFrame->SetSelection(aPresContext, this); // Doing a single selection only. } return NS_OK; } @@ -201,53 +201,52 @@ nsTreeCellFrame::HandleDoubleClickEvent(nsIPresContext& aPresContext, if (!mIsHeader) { // Perform an expand/collapse - // Iterate up the chain to the row and then to the item. - nsCOMPtr pTreeItemContent; - mContent->GetParent(*getter_AddRefs(pTreeItemContent)); - - // Take the tree item content and toggle the value of its open attribute. - nsString attrValue; + // Iterate up the chain to the row and then to the item. + nsCOMPtr pTreeItemContent; + mContent->GetParent(*getter_AddRefs(pTreeItemContent)); + + // Take the tree item content and toggle the value of its open attribute. + nsString attrValue; nsCOMPtr kOpenAtom ( dont_AddRef(NS_NewAtom("open")) ); nsresult result = pTreeItemContent->GetAttribute(nsXULAtoms::nameSpaceID, kOpenAtom, attrValue); attrValue.ToLowerCase(); PRBool isExpanded = (result == NS_CONTENT_ATTR_NO_VALUE || (result == NS_CONTENT_ATTR_HAS_VALUE && attrValue=="true")); if (isExpanded) - { - // We're collapsing and need to remove frames from the flow. - pTreeItemContent->UnsetAttribute(nsXULAtoms::nameSpaceID, kOpenAtom, PR_FALSE); - } - else - { - // We're expanding and need to add frames to the flow. - pTreeItemContent->SetAttribute(nsXULAtoms::nameSpaceID, kOpenAtom, "true", PR_FALSE); - } + { + // We're collapsing and need to remove frames from the flow. + pTreeItemContent->UnsetAttribute(nsXULAtoms::nameSpaceID, kOpenAtom, PR_FALSE); + } + else + { + // We're expanding and need to add frames to the flow. + pTreeItemContent->SetAttribute(nsXULAtoms::nameSpaceID, kOpenAtom, "true", PR_FALSE); + } - // Ok, try out the hack of doing frame reconstruction - nsCOMPtr pShell; - aPresContext.GetShell(getter_AddRefs(pShell)); - nsCOMPtr pStyleSet; - pShell->GetStyleSet(getter_AddRefs(pStyleSet)); - nsCOMPtr pDocument; - pShell->GetDocument(getter_AddRefs(pDocument)); - nsCOMPtr pRoot ( dont_AddRef(pDocument->GetRootContent()) ); - - if (pRoot) { - nsIFrame* docElementFrame; - nsIFrame* parentFrame; + // Ok, try out the hack of doing frame reconstruction + nsCOMPtr pShell; + aPresContext.GetShell(getter_AddRefs(pShell)); + nsCOMPtr pStyleSet; + pShell->GetStyleSet(getter_AddRefs(pStyleSet)); + nsCOMPtr pDocument; + pShell->GetDocument(getter_AddRefs(pDocument)); + nsCOMPtr pRoot ( dont_AddRef(pDocument->GetRootContent()) ); + + if (pRoot) { + nsIFrame* docElementFrame; + nsIFrame* parentFrame; - // Get the frame that corresponds to the document element - pShell->GetPrimaryFrameFor(pRoot, &docElementFrame); - if (nsnull != docElementFrame) { - docElementFrame->GetParent(&parentFrame); + // Get the frame that corresponds to the document element + pShell->GetPrimaryFrameFor(pRoot, &docElementFrame); + if (nsnull != docElementFrame) { + docElementFrame->GetParent(&parentFrame); - pShell->EnterReflowLock(); - pStyleSet->ReconstructFrames(&aPresContext, pRoot, - parentFrame, docElementFrame); - pShell->ExitReflowLock(); - } + pShell->EnterReflowLock(); + pStyleSet->ReconstructFrames(&aPresContext, pRoot, + parentFrame, docElementFrame); + pShell->ExitReflowLock(); + } } - } return NS_OK; } @@ -256,17 +255,24 @@ nsTreeCellFrame::HandleDoubleClickEvent(nsIPresContext& aPresContext, void nsTreeCellFrame::Select(nsIPresContext& aPresContext, PRBool isSelected, PRBool notifyForReflow) { - nsCOMPtr kSelectedAtom ( dont_AddRef(NS_NewAtom("selected")) ); - if (isSelected) + nsCOMPtr kSelectedCellAtom(dont_AddRef(NS_NewAtom("selectedcell"))); + nsCOMPtr kSelectedAtom(dont_AddRef(NS_NewAtom("selected"))); + + nsIContent* pParentContent; + mContent->GetParent(pParentContent); + + if (isSelected) { // We're selecting the node. - mContent->SetAttribute(nsXULAtoms::nameSpaceID, kSelectedAtom, "true", notifyForReflow); - + mContent->SetAttribute(nsXULAtoms::nameSpaceID, kSelectedCellAtom, "true", notifyForReflow); + pParentContent->SetAttribute(nsXULAtoms::nameSpaceID, kSelectedAtom, "true", notifyForReflow); } else { - // We're unselecting the node. - mContent->UnsetAttribute(nsXULAtoms::nameSpaceID, kSelectedAtom, notifyForReflow); + // We're deselecting the node. + mContent->UnsetAttribute(nsXULAtoms::nameSpaceID, kSelectedCellAtom, notifyForReflow); + pParentContent->UnsetAttribute(nsXULAtoms::nameSpaceID, kSelectedAtom, notifyForReflow); } + NS_IF_RELEASE(pParentContent); }