diff --git a/widget/public/nsIToolbar.h b/widget/public/nsIToolbar.h deleted file mode 100644 index 3bfb4034704f..000000000000 --- a/widget/public/nsIToolbar.h +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsIToolbar_h___ -#define nsIToolbar_h___ - -#include "nsISupports.h" -#include "nsString.h" -#include "nsGUIEvent.h" - -class nsIWidget; -class nsIThrobber; -class nsIToolbarItem; - -// deb24690-35f8-11d2-9248-00805f8a7ab6 -#define NS_ITOOLBAR_IID \ - { 0xdeb24690, 0x35f8, 0x11d2, \ - {0x92, 0x48, 0x00, 0x80, 0x5f, 0x8a, 0x7a, 0xb6} } - -enum nsToolbarBorderType { - // no border - eToolbarBorderType_none, - // draws partial border - eToolbarBorderType_partial, - // draws border on all sides - eToolbarBorderType_full - }; - -class nsIToolbar : public nsISupports -{ -public: - static const nsIID& GetIID() { static nsIID iid = NS_ITOOLBAR_IID; return iid; } - - /** - * Adds a widget to the toolbar and indicates the left side gap - * - */ - NS_IMETHOD AddItem(nsIToolbarItem* anItem, PRInt32 aLeftGap, PRBool aStretchable) = 0; - - /** - * Inserts a item into the toolbar at a specified position - * - */ - NS_IMETHOD InsertItemAt(nsIToolbarItem* anItem, - PRInt32 aLeftGap, - PRBool aStretchable, - PRInt32 anIndex) = 0; - - /** - * Returns an item from the toolbar at a specified position - * - */ - NS_IMETHOD GetItemAt(nsIToolbarItem*& anItem, PRInt32 anIndex) = 0; - - /** - * Get the preferred size of the toolbar - * - */ - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) = 0; - - /** - * Returns whether the toolbar is visible - * - */ - NS_IMETHOD IsVisible(PRBool & aIsVisible) = 0; - - /** - * Sets the horizontal gap in between the last item and the margin - * - */ - NS_IMETHOD SetHGap(PRInt32 aGap) = 0; - - /** - * Sets the vertical gap (if the toolbar "wraps") - * - */ - NS_IMETHOD SetVGap(PRInt32 aGap) = 0; - - /** - * Set the "margin", the space from the edge of the toolbar to the top of the widgets - * - */ - NS_IMETHOD SetMargin(PRInt32 aMargin) = 0; - - /** - * Forces the toolbar to layout - * - */ - NS_IMETHOD DoLayout() = 0; - - /** - * Forces the toolbar to layout horizontally - * - */ - NS_IMETHOD SetHorizontalLayout(PRBool aDoHorizontalLayout) = 0; - - /** - * Indicates that the last item is right justifed - * - */ - NS_IMETHOD SetLastItemIsRightJustified(const PRBool & aState) = 0; - - /** - * Indicates that the next to the last item will be stretched - * - */ - NS_IMETHOD SetNextLastItemIsStretchy(const PRBool & aState) = 0; - - /** - * Tells the toolbar to draw the border on all 4 sides, instead of just top and bottom - * - */ - NS_IMETHOD SetBorderType(nsToolbarBorderType aBorderType) = 0; - - /** - * Tells the toolbar to wrap - * - */ - NS_IMETHOD SetWrapping(PRBool aDoWrap) = 0; - - /** - * Indicates whether the toolbar is to wrap - * - */ - NS_IMETHOD GetWrapping(PRBool & aDoWrap) = 0; - - /** - * Get the preferred size of the toolbar when constrainted horizontally or vertically - * - */ - NS_IMETHOD GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight, - PRInt32& aWidth, PRInt32& aHeight) = 0; - - /** - * HandleGUI Events - * - */ - NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent) = 0; - - /** - * Handle OnPaint - * - */ - NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) = 0; - - -}; - -#endif /* nsIToolbar_h___ */ - diff --git a/widget/public/nsIToolbarItem.h b/widget/public/nsIToolbarItem.h deleted file mode 100644 index 6ffbe8970b3f..000000000000 --- a/widget/public/nsIToolbarItem.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsIToolbarItem_h___ -#define nsIToolbarItem_h___ - -#include "nsISupports.h" - -struct nsRect; - -// {1F9EE621-5234-11d2-8DC1-00609703C14E} -#define NS_ITOOLBARITEM_IID \ -{ 0x1f9ee621, 0x5234, 0x11d2, \ - { 0x8d, 0xc1, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } } - -class nsIToolbarItem : public nsISupports -{ - -public: - static const nsIID& GetIID() { static nsIID iid = NS_ITOOLBARITEM_IID; return iid; } - - /** - * Forces the item to repaint - * - */ - NS_IMETHOD Repaint(PRBool aIsSynchronous) = 0; - - /** - * Get this widget's dimension - * - * @param aRect on return it holds the x. y, width and height of this widget - * - */ - NS_IMETHOD GetBounds(nsRect &aRect) = 0; - - /** - * Show or hide this widget - * - * @param aState PR_TRUE to show the Widget, PR_FALSE to hide it - * - */ - NS_IMETHOD SetVisible(PRBool aState) = 0; - - /** - * Returns whether the window is visible - * - */ - NS_IMETHOD IsVisible(PRBool & aState) = 0; - - /** - * Move this widget. - * - * @param aX the new x position expressed in the parent's coordinate system - * @param aY the new y position expressed in the parent's coordinate system - * - **/ - NS_IMETHOD SetLocation(PRUint32 aX, PRUint32 aY) = 0; - - /** - * Resize this widget. - * - * @param aWidth the new width expressed in the parent's coordinate system - * @param aHeight the new height expressed in the parent's coordinate system - * @param aRepaint whether the widget should be repainted - * - */ - NS_IMETHOD SetBounds(PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint) = 0; - - /** - * Move or resize this widget. - * - * @param aX the new x position expressed in the parent's coordinate system - * @param aY the new y position expressed in the parent's coordinate system - * @param aWidth the new width expressed in the parent's coordinate system - * @param aHeight the new height expressed in the parent's coordinate system - * @param aRepaint whether the widget should be repainted if the size changes - * - */ - NS_IMETHOD SetBounds(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint) = 0; - - /** - * Returns the preferred width and height for the widget - * - */ - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) = 0; - - /** - * Set the preferred width and height for the widget - * - */ - NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) = 0; - - -}; - -#endif /* nsIToolbarItem_h___ */ - diff --git a/widget/public/nsIToolbarItemHolder.h b/widget/public/nsIToolbarItemHolder.h deleted file mode 100644 index 74e35dae456f..000000000000 --- a/widget/public/nsIToolbarItemHolder.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsIToolbarItemHolder_h___ -#define nsIToolbarItemHolder_h___ - -#include "nsISupports.h" - -class nsIWidget; - -// {8556F9D2-5235-11d2-8DC1-00609703C14E} -#define NS_ITOOLBARITEMHOLDER_IID \ -{ 0x8556f9d2, 0x5235, 0x11d2, \ - { 0x8d, 0xc1, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } } - -class nsIToolbarItemHolder : public nsISupports -{ - -public: - - /** - * Set the widget into the holder - * - */ - NS_IMETHOD SetWidget(nsIWidget * aWidget) = 0; - - - /** - * Gets the widget from the holder - */ - NS_IMETHOD GetWidget(nsIWidget *&aWidget) = 0; - -}; - -#endif /* nsIToolbarItemHolder_h___ */ - diff --git a/widget/public/nsIToolbarManager.h b/widget/public/nsIToolbarManager.h deleted file mode 100644 index 50cf05b3dcce..000000000000 --- a/widget/public/nsIToolbarManager.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsIToolbarManager_h___ -#define nsIToolbarManager_h___ - -#include "nsISupports.h" - -class nsIToolbar; -class nsIToolbarManagerListener; -class nsIImageButton; - -// {19F205F1-5193-11d2-8DC1-00609703C14E} -#define NS_ITOOLBARMANAGER_IID \ -{ 0x19f205f1, 0x5193, 0x11d2, \ - { 0x8d, 0xc1, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } } - -class nsIToolbarManager : public nsISupports -{ - -public: - - /** - * Adds a toolbar to the toolbar manager - * - */ - NS_IMETHOD AddToolbar(nsIToolbar* aToolbar) = 0; - - /** - * Adds a toolbar to the toolbar manager - * - */ - NS_IMETHOD InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anIndex) = 0; - - /** - * Get a toolbar to the toolbar manager - * - */ - NS_IMETHOD GetNumToolbars(PRInt32 & aNumToolbars) = 0; - - /** - * Get a toolbar to the toolbar manager - * - */ - NS_IMETHOD GetToolbarAt(nsIToolbar*& aToolbar, PRInt32 anIndex) = 0; - - /** - * Forces the toolbar manager to layout - * - */ - NS_IMETHOD DoLayout() = 0; - - /** - * Adds a Listener to the toolbar manager - * - */ - NS_IMETHOD AddToolbarListener(nsIToolbarManagerListener * aListener) = 0; - - /** - * Registers the URLS for the Toolbar Tab Images that enable - * the Toolbar to collapse - * - */ - NS_IMETHOD SetCollapseTabURLs(const nsString& aUpURL, - const nsString& aPressedURL, - const nsString& aDisabledURL, - const nsString& aRollOverURL) = 0; - - /** - * Get the URLS for the Toolbar Tab Images that enable - * the Toolbar to collapse - * - */ - NS_IMETHOD GetCollapseTabURLs(nsString& aUpURL, - nsString& aPressedURL, - nsString& aDisabledURL, - nsString& aRollOverURL) = 0; - - /** - * Registers the URLS for the Tab Images for the manager for - * making toolbars expand - * - */ - NS_IMETHOD SetExpandTabURLs(const nsString& aUpURL, - const nsString& aPressedURL, - const nsString& aDisabledURL, - const nsString& aRollOverURL) = 0; - -}; - -#endif /* nsIToolbarManager_h___ */ - diff --git a/widget/public/nsIToolbarManagerListener.h b/widget/public/nsIToolbarManagerListener.h deleted file mode 100644 index 5ffe9a98d343..000000000000 --- a/widget/public/nsIToolbarManagerListener.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsIToolbarManagerListener_h___ -#define nsIToolbarManagerListener_h___ - -#include "nsISupports.h" - -class nsIToolbarManager; - -// {ECF9C251-5194-11d2-8DC1-00609703C14E} -#define NS_ITOOLBARMANAGERLISTENER_IID \ -{ 0xecf9c251, 0x5194, 0x11d2, \ - { 0x8d, 0xc1, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } } - -class nsIToolbarManagerListener : public nsISupports -{ - -public: - static const nsIID& GetIID() { static nsIID iid = NS_ITOOLBARMANAGERLISTENER_IID; return iid; } - - /** - * Notifies - * - */ - NS_IMETHOD NotifyToolbarManagerChangedSize(nsIToolbarManager* aToolbarMgr) = 0; - - -}; - -#endif /* nsIToolbarManagerListener_h___ */ - diff --git a/widget/public/nsITreeView.h b/widget/public/nsITreeView.h deleted file mode 100644 index 2347c5192602..000000000000 --- a/widget/public/nsITreeView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -// -// IMPORTANT -// pinkerton 98-12-11 -// -// This file is currently obsolete. There is no "tree view interface" presented to -// the world. There is only the DOM. However, I'm leaving this file in place in the -// tree in case we ever need something like it. The IID will have to change, however, -// because it has been appropriated by nsIContentConnector. -// - -#ifndef nsITreeView_h___ -#define nsITreeView_h___ - -#include "nsGUIEvent.h" - -class nsIContent; - -// {FC41CD61-796E-11d2-BF86-00105A1B0627} -// NO LONGER VALID -- USED BY nsIContentConnector -#define NS_ITREEVIEW_IID \ -{ 0xfc41cd61, 0x796e, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } - -class nsITreeView : public nsISupports -{ - -public: - NS_IMETHOD SetContentRoot(nsIContent* pContent) = 0; - - NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent) = 0; -}; - -#endif /* nsITreeView_h___ */ - diff --git a/widget/src/xpwidgets/nsDataModelWidget.h b/widget/src/xpwidgets/nsDataModelWidget.h deleted file mode 100644 index 35d58c81aaba..000000000000 --- a/widget/src/xpwidgets/nsDataModelWidget.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsDataModelWidget_h___ -#define nsDataModelWidget_h___ - -#include "nsWindow.h" - -class nsHierarchicalDataItem; - - -class nsDataModelWidget : public ChildWindow -{ -public: - virtual ~nsDataModelWidget() {}; - - virtual void HandleDataModelEvent(int event, nsHierarchicalDataItem* pItem) = 0; - -protected: - - nsDataModelWidget() {}; - -}; - -#endif diff --git a/widget/src/xpwidgets/nsHTColumn.cpp b/widget/src/xpwidgets/nsHTColumn.cpp deleted file mode 100644 index a390fa9dcaf2..000000000000 --- a/widget/src/xpwidgets/nsHTColumn.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nspr.h" -#include "nsString.h" -#include "nsFont.h" -#include "nsTreeColumn.h" -#include "nsHTColumn.h" -#include "nsIContent.h" -#include "nsHTDataModel.h" - -nsHTColumn::nsHTColumn(nsIContent* pContent) : nsTreeColumn() -{ - mPixelWidth = 25; - mDesiredPercentage = 0.33; - mContentNode = pContent; - NS_ADDREF(mContentNode); -} - -//-------------------------------------------------------------------- -nsHTColumn::~nsHTColumn() -{ - NS_IF_RELEASE(mContentNode); -} - - -// TreeColumn Implementation --------------------- -int nsHTColumn::GetPixelWidth() const -{ - return mPixelWidth; -} - -double nsHTColumn::GetDesiredPercentage() const -{ - return mDesiredPercentage; -} - -void nsHTColumn::GetColumnName(nsString& name) const -{ - // Need to look at our content node and get its tag name. - nsIAtom* pAtom = nsnull; - mContentNode->GetTag(pAtom); - pAtom->ToString(name); - NS_IF_RELEASE(pAtom); -} - -void nsHTColumn::GetColumnDisplayText(nsString& displayText) const -{ - nsHTDataModel::GetChildTextForNode(mContentNode, displayText); -} - -PRBool nsHTColumn::IsSortColumn() const -{ - return PR_FALSE; -} - -void nsHTColumn::SetPixelWidth(int newWidth) -{ - mPixelWidth = newWidth; -} - -void nsHTColumn::SetDesiredPercentage(double newPercentage) -{ - mDesiredPercentage = newPercentage; -} diff --git a/widget/src/xpwidgets/nsHTColumn.h b/widget/src/xpwidgets/nsHTColumn.h deleted file mode 100644 index 9bfc1f747f55..000000000000 --- a/widget/src/xpwidgets/nsHTColumn.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTColumn_h___ -#define nsHTColumn_h___ - -#include "nsTreeColumn.h" - -class nsIContent; - -//------------------------------------------------------------ -// This class functions as the data source for column information (things like -// width, desired percentage, and sorting). - -class nsHTColumn : public nsTreeColumn - -{ -public: - nsHTColumn(nsIContent* pContentNode); - virtual ~nsHTColumn(); - - // Inspectors - virtual int GetPixelWidth() const; - virtual double GetDesiredPercentage() const; - virtual PRBool IsSortColumn() const; - virtual void GetColumnName(nsString& name) const; - virtual void GetColumnDisplayText(nsString& displayText) const; - - // Setters - virtual void SetPixelWidth(int newWidth); - virtual void SetDesiredPercentage(double newPercentage); - -protected: - int mPixelWidth; - double mDesiredPercentage; - - nsIContent* mContentNode; -}; - -#endif /* nsHTColumn_h___ */ diff --git a/widget/src/xpwidgets/nsHTControlStripItem.cpp b/widget/src/xpwidgets/nsHTControlStripItem.cpp deleted file mode 100644 index fb4203236b21..000000000000 --- a/widget/src/xpwidgets/nsHTControlStripItem.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nspr.h" -#include "nsString.h" -#include "nsHTControlStripItem.h" - -nsHTControlStripItem::nsHTControlStripItem() : nsTreeControlStripItem() -{ -} - -void nsHTControlStripItem::GetText(nsString& text) const -{ - text = "Blah"; -} diff --git a/widget/src/xpwidgets/nsHTControlStripItem.h b/widget/src/xpwidgets/nsHTControlStripItem.h deleted file mode 100644 index 93a5f43ddc76..000000000000 --- a/widget/src/xpwidgets/nsHTControlStripItem.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTControlStripItem_h___ -#define nsHTControlStripItem_h___ - -#include "nsTreeControlStripItem.h" - -class nsHTControlStripItem : public nsTreeControlStripItem - -{ -public: - nsHTControlStripItem(); - virtual ~nsHTControlStripItem() {}; - - virtual void GetText(nsString& text) const; -}; - -#endif /* nsHTControlStripItem_h___ */ diff --git a/widget/src/xpwidgets/nsHTDataModel.cpp b/widget/src/xpwidgets/nsHTDataModel.cpp deleted file mode 100644 index b7e5d94fb725..000000000000 --- a/widget/src/xpwidgets/nsHTDataModel.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nspr.h" -#include "nsString.h" -#include "nsFont.h" -#include "nsHTTreeDataModel.h" -#include "nsWidgetsCID.h" -#include "nsDataModelWidget.h" -#include "nsTreeColumn.h" -#include "nsHTTreeItem.h" -#include "nsIDeviceContext.h" -#include "nsIDocument.h" -#include "nsIContent.h" -#include "nsVoidArray.h" -#include "nsIDOMNode.h" -#include "nsINameSpaceManager.h" - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -nsHTDataModel::nsHTDataModel() -{ - mListener = nsnull; - mImageGroup = nsnull; - mContentRoot = nsnull; - mDocument = nsnull; -} - -//-------------------------------------------------------------------- -nsHTDataModel::~nsHTDataModel() -{ - if (mImageGroup) - { - mImageGroup->Interrupt(); - NS_RELEASE(mImageGroup); - } - - // TODO: Destroy visibility array -} - -void nsHTDataModel::SetDataModelListenerDelegate(nsDataModelWidget* pWidget) -{ - NS_IF_RELEASE(mImageGroup); - mListener = pWidget; - if (pWidget != nsnull && NS_NewImageGroup(&mImageGroup) == NS_OK) - { - nsIDeviceContext * deviceCtx = pWidget->GetDeviceContext(); - mImageGroup->Init(deviceCtx, nsnull); - NS_RELEASE(deviceCtx); - } -} - -// Hierarchical Data Model Implementation --------------------- - -void nsHTDataModel::SetContentRootDelegate(nsIContent* pContent) -{ - NS_IF_RELEASE(mDocument); - NS_IF_RELEASE(mContentRoot); - - mContentRoot = pContent; - pContent->GetDocument(mDocument); // I'm assuming this addrefs the document. - NS_ADDREF(mContentRoot); - - // Destroy our old visibility list. - // TODO - - // Reconstruct our visibility list (so that all items that are visible - // are instantiated). Need to only look for folder and item children. All other children should be ignored. - AddNodesToArray(mContentRoot, 0); -} - -void nsHTDataModel::AddNodesToArray(nsIContent* pContent, PRUint32 indentLevel) -{ - // Add this child to the array (unless it is the root node). - nsHierarchicalDataItem* pDataItem = CreateDataItemWithContentNode(pContent); - if (pContent != mContentRoot) - { - // Add to our array - mVisibleItemArray.AppendElement(pDataItem); - // Set the correct indent level for the item. - pDataItem->SetIndentationLevel(indentLevel); - indentLevel++; - } - else mRootNode = pDataItem; - - if (pContent == mContentRoot || pDataItem->IsExpanded()) - { - nsHTItem* pItem = NS_STATIC_CAST(nsHTItem*, pDataItem->GetImplData()); - nsIContent* pChildrenNode = nsHTDataModel::FindChildWithName(pItem->GetContentNode(), "children"); - if (pChildrenNode) - { - PRInt32 numChildren = 0; - pChildrenNode->ChildCount(numChildren); - for (PRInt32 i = 0; i < numChildren; i++) - { - nsIContent* child = nsnull; - pChildrenNode->ChildAt(i, child); - if (child) - { - AddNodesToArray(child, indentLevel); - } - - NS_IF_RELEASE(child); - } - } - } -} - -nsHierarchicalDataItem* nsHTDataModel::GetRootDelegate() const -{ - return mRootNode; -} - - -PRUint32 nsHTDataModel::GetFirstVisibleItemIndexDelegate() const -{ - return 0; -} - -void nsHTDataModel::SetFirstVisibleItemIndexDelegate(PRUint32 n) -{ -} - -nsHierarchicalDataItem* nsHTDataModel::GetNthItemDelegate(PRUint32 n) const -{ - PRUint32 itemCount = (PRUint32)(mVisibleItemArray.Count()); - - if (n < itemCount) - return (nsHierarchicalDataItem*)(mVisibleItemArray[n]); - else return nsnull; -} - - -void nsHTDataModel::SetSelectionDelegate(nsHierarchicalDataItem* pDataItem) -{ - ClearSelectionDelegate(); // First clear our selection. - - ToggleSelectionDelegate(pDataItem); // Add this node to the selection. -} - -void nsHTDataModel::ToggleSelectionDelegate(nsHierarchicalDataItem* pDataItem) -{ - nsString attrValue; - // Need to set the attribute's value. - if (pDataItem->IsSelected()) - attrValue = "false"; - else attrValue = "true"; - - // Set it and wait for the callback. - nsHTItem* pItem = NS_STATIC_CAST(nsHTItem*, pDataItem->GetImplData()); - nsIAtom* selectedAtom = NS_NewAtom("selected"); - pItem->GetContentNode()->SetAttribute(kNameSpaceID_None, selectedAtom, attrValue, PR_TRUE); - NS_RELEASE(selectedAtom); - - // TODO: Remove this and put it in the callback instead. - pItem->FinishSelectionChange(); -} - -void nsHTDataModel::RangedSelectionDelegate(PRUint32 n, PRUint32 count) -{ -} - -void nsHTDataModel::ClearSelectionDelegate() -{ - // Iterate over our array and clear the selection. - PRInt32 count = mSelectedItemArray.Count(); - for (PRInt32 i = 0; i < count; i++) - { - nsHierarchicalDataItem* pItem = (nsHierarchicalDataItem*)mSelectedItemArray[0]; - ToggleSelectionDelegate(pItem); - } -} - -void nsHTDataModel::ImageLoaded(nsHierarchicalDataItem* pItem) -{ - if (mListener) - { - // Send it on along. Let the view know what happened. - mListener->HandleDataModelEvent(cDMImageLoaded, pItem); - } -} - -// Static Helper functions -void nsHTDataModel::GetChildTextForNode(nsIContent* pChildNode, nsString& text) -{ - nsIContent* pChild; - pChildNode->ChildAt(0, pChild); - nsIDOMNode* pTextChild = nsnull; - -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); - - if (NS_SUCCEEDED(pChild->QueryInterface(kIDOMNodeIID, (void**)&pTextChild))) - { - pTextChild->GetNodeValue(text); - NS_IF_RELEASE(pTextChild); - } - else text = "null"; - - NS_IF_RELEASE(pChild); -} - -nsIContent* nsHTDataModel::FindChildWithName(nsIContent* pNode, const nsString& name) -{ - PRInt32 count; - pNode->ChildCount(count); - for (PRInt32 i = 0; i < count; i++) - { - nsIAtom* pAtom = nsnull; - nsIContent* pChild = nsnull; - pNode->ChildAt(i, pChild); - pChild->GetTag(pAtom); - nsString answer; - pAtom->ToString(answer); - NS_IF_RELEASE(pAtom); - if (answer.EqualsIgnoreCase(name)) - return pChild; - else NS_IF_RELEASE(pChild); - } - - return nsnull; -} diff --git a/widget/src/xpwidgets/nsHTDataModel.h b/widget/src/xpwidgets/nsHTDataModel.h deleted file mode 100644 index 132ddadc9fd3..000000000000 --- a/widget/src/xpwidgets/nsHTDataModel.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTDataModel_h___ -#define nsHTDataModel_h___ - -#include "nsWindow.h" -#include "nsHierarchicalDataModel.h" -#include "nsIImageGroup.h" - -class nsDataModelWidget; -class nsHTItem; -class nsIDocument; -class nsIContent; - -//------------------------------------------------------------ -// The HyperTree Base Class -// This class is a simplified API that wraps calls into the DOM -// interfaces. It is shared by the HT Tree Widget and the HT -// Toolbar. -// ----------------------------------------------------------- - -class nsHTDataModel - -{ -public: - nsHTDataModel(); - virtual ~nsHTDataModel(); - - // Set the content root - void SetContentRootDelegate(nsIContent* pContent); - - // Retrieve the root node of the data model. - virtual nsHierarchicalDataItem* GetRootDelegate() const; - - // A visibility hint can be stored and retrieved (e.g., the leftmost or topmost - // item in the current scrolled view). - virtual PRUint32 GetFirstVisibleItemIndexDelegate() const; - virtual void SetFirstVisibleItemIndexDelegate(PRUint32 index); - virtual nsHierarchicalDataItem* GetNthItemDelegate(PRUint32 n) const; - - virtual void SetDataModelListenerDelegate(nsDataModelWidget* pListener); - - // Selection APIs - virtual void SetSelectionDelegate(nsHierarchicalDataItem* pDataItem); - // Sets the selection to be only the node passed in. All other nodes are deselected - // prior to the selection of the new node. - virtual void ToggleSelectionDelegate(nsHierarchicalDataItem* pDataItem); - // Toggles the selection on the item specified without affecting other selected nodes. - virtual void RangedSelectionDelegate(PRUint32 n, PRUint32 count); - // Selects the number of items specified by count, starting from position n. - virtual void ClearSelectionDelegate(); - // Deselects all items. - -public: - virtual nsHierarchicalDataItem* CreateDataItemWithContentNode(nsIContent* pContent) = 0; - - static void GetChildTextForNode(nsIContent* pChildNode, nsString& text); - static nsIContent* FindChildWithName(nsIContent* pNode, const nsString& name); - - void ImageLoaded(nsHierarchicalDataItem* pItem); - nsIImageGroup* GetImageGroup() const { NS_ADDREF(mImageGroup); return mImageGroup; } - -public: - nsVoidArray* GetVisibilityArray() { return &mVisibleItemArray; }; - nsVoidArray* GetSelectionArray() { return &mSelectedItemArray; }; - -protected: - void AddNodesToArray(nsIContent* pContent, PRUint32 indentLevel); - // This recursive function is called to add nodes to the visibility array. - - enum { cDMImageLoaded = 0 } ; - - nsDataModelWidget* mListener; // Events are sent to the listening widget. - nsIImageGroup* mImageGroup; // Image group used for loading all images in the model. - -protected: - // The document being observed (and the content node that serves as the root for the - // widget attached to the model). - nsIDocument* mDocument; - nsIContent* mContentRoot; - - nsHierarchicalDataItem* mRootNode; - nsVoidArray mVisibleItemArray; // A flat view of the hierarchy, i.e., a list of all currently exposed items. - nsVoidArray mSelectedItemArray; // A list of all nodes in the hierarchy that are currently selected. -}; - -#endif /* nsToolbar_h___ */ diff --git a/widget/src/xpwidgets/nsHTItem.cpp b/widget/src/xpwidgets/nsHTItem.cpp deleted file mode 100644 index 605228980a00..000000000000 --- a/widget/src/xpwidgets/nsHTItem.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nspr.h" -#include "nsString.h" -#include "nsHierarchicalDataItem.h" -#include "nsHTDataModel.h" -#include "nsHTItem.h" -#include "nsIContent.h" -#include "nsVoidArray.h" -#include "nsINameSpaceManager.h" - -static nsIAtom* kOpenAtom; -static nsIAtom* kSelectedAtom; - -nsHTItem::nsHTItem(nsIContent* pContent, nsHierarchicalDataModel* pDataModel) -{ - NS_ADDREF(pContent); - mContentNode = pContent; - mDataModel = pDataModel; - mIndentationLevel = 0; - - if (nsnull == kOpenAtom) { - kOpenAtom = NS_NewAtom("open"); - kSelectedAtom = NS_NewAtom("open"); - } - else { - NS_ADDREF(kOpenAtom); - NS_ADDREF(kSelectedAtom); - } -} - -//-------------------------------------------------------------------- -nsHTItem::~nsHTItem() -{ - NS_IF_RELEASE(mContentNode); - - nsrefcnt refCnt; - NS_RELEASE2(kOpenAtom, refCnt); - NS_RELEASE2(kSelectedAtom, refCnt); -} - -PRBool nsHTItem::IsExpandedDelegate() const -{ - nsString attrValue; - nsresult result = mContentNode->GetAttribute(kNameSpaceID_None, kOpenAtom, attrValue); - attrValue.ToLowerCase(); - return (result == NS_CONTENT_ATTR_NO_VALUE || - (result == NS_CONTENT_ATTR_HAS_VALUE && attrValue=="true")); -} - -void nsHTItem::ToggleOpenStateDelegate() -{ - nsString attrValue; - // Need to set the attribute's value. - if (IsExpandedDelegate()) - attrValue = "false"; - else attrValue = "true"; - - // Set it and wait for the callback. - mContentNode->SetAttribute(kNameSpaceID_None, kOpenAtom, attrValue, PR_TRUE); - - // TODO: Remove this and put it in the callback instead. - FinishToggle(); -} - -void nsHTItem::FinishToggle() -{ - nsHTDataModel* pDataModel = NS_STATIC_CAST(nsHTDataModel*, mDataModel->GetImplData()); - nsVoidArray* pArray = pDataModel->GetVisibilityArray(); - - nsHierarchicalDataItem* self = GetDataItem(); - PRInt32 index = pArray->IndexOf((void*)self) + 1; - - PRUint32 childCount = self->GetChildCount(); - - if (IsExpandedDelegate()) - { - // We just opened the node. Add the children to our visibility array. - for (PRUint32 i = 0; i < childCount; i++) - { - nsIContent* child = GetNthChildContentNode(i); - nsHierarchicalDataItem* pDataItem = pDataModel->CreateDataItemWithContentNode(child); - pDataItem->SetIndentationLevel(mIndentationLevel + 1); - pArray->InsertElementAt((void*)pDataItem, index); - index++; - - NS_IF_RELEASE(child); - } - } - else - { - // We just closed the node. Remove the children from our visibility array. - for (PRUint32 i = 0; i < childCount; i++) - { - nsHierarchicalDataItem* pItem = (nsHierarchicalDataItem*)((*pArray)[index]); - pArray->RemoveElementAt(index); - delete pItem; - } - } -} - -PRUint32 nsHTItem::GetChildCountDelegate() const -{ - PRInt32 childCount; - mContentNode->ChildCount(childCount); - - return childCount; -} - -nsIContent* nsHTItem::GetNthChildContentNode(PRUint32 n) const -{ - nsIContent* childNode; - mContentNode->ChildAt(n, childNode); - - return childNode; -} - -PRBool nsHTItem::IsSelectedDelegate() const -{ - nsString attrValue; - nsresult result = mContentNode->GetAttribute(kNameSpaceID_None, kSelectedAtom, attrValue); - attrValue.ToLowerCase(); - return (result == NS_CONTENT_ATTR_NO_VALUE || - (result == NS_CONTENT_ATTR_HAS_VALUE && attrValue=="true")); -} - -void nsHTItem::FinishSelectionChange() -{ - nsHTDataModel* pDataModel = NS_STATIC_CAST(nsHTDataModel*, mDataModel->GetImplData()); - nsVoidArray* pArray = pDataModel->GetSelectionArray(); - - nsHierarchicalDataItem* self = GetDataItem(); - PRInt32 index = pArray->IndexOf((void*)self); - - if (IsSelectedDelegate() && index == -1) - { - // The item is not in the array and needs to be added. - pArray->AppendElement(self); - } - else if (!IsSelectedDelegate() && index != -1) - { - pArray->RemoveElementAt(index); - } -} - -PRUint32 nsHTItem::GetIndentationLevelDelegate() const -{ - return mIndentationLevel; -} - -void nsHTItem::SetIndentationLevelDelegate(PRUint32 n) -{ - mIndentationLevel = n; -} diff --git a/widget/src/xpwidgets/nsHTItem.h b/widget/src/xpwidgets/nsHTItem.h deleted file mode 100644 index e3e1cc73fca4..000000000000 --- a/widget/src/xpwidgets/nsHTItem.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTItem_h___ -#define nsHTItem_h___ - -class nsHierarchicalDataModel; -class nsIContent; - -class nsHTItem - -{ -public: - nsHTItem(nsIContent* pContent, nsHierarchicalDataModel* pDataModel); - virtual ~nsHTItem(); - - virtual PRBool IsExpandedDelegate() const; - virtual void ToggleOpenStateDelegate(); - virtual PRUint32 GetChildCountDelegate() const; - - virtual PRBool IsSelectedDelegate() const; - - virtual PRUint32 GetIndentationLevelDelegate() const; - virtual void SetIndentationLevelDelegate(PRUint32 n); - - nsIContent* GetContentNode() const { return mContentNode; }; - - virtual void FinishToggle(); // Completes the toggle initiated by ToggleOpenState() - virtual void FinishSelectionChange(); // Completes a selection change for this item. - -protected: - virtual nsHierarchicalDataItem* GetDataItem() { return nsnull; }; - virtual nsIContent* GetNthChildContentNode(PRUint32 n) const; - -protected: - nsHierarchicalDataModel* mDataModel; - nsIContent* mContentNode; - PRUint32 mIndentationLevel; -}; - -#endif /* nsHTItem_h___ */ diff --git a/widget/src/xpwidgets/nsHTToolbarDataModel.cpp b/widget/src/xpwidgets/nsHTToolbarDataModel.cpp deleted file mode 100644 index f0eb0fbf4d76..000000000000 --- a/widget/src/xpwidgets/nsHTToolbarDataModel.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nsHTToolbarDataModel.h" - -#include "nspr.h" -#include "nsString.h" -#include "nsFont.h" -#include "nsWidgetsCID.h" -#include "nsDataModelWidget.h" -#include "nsIDeviceContext.h" -#include "nsIImageObserver.h" -#include "nsIImageRequest.h" -#include "nsIImageGroup.h" -#include "nsIContent.h" - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID); - -NS_IMPL_ADDREF(nsHTToolbarDataModel) -NS_IMPL_RELEASE(nsHTToolbarDataModel) - -nsHTToolbarDataModel::nsHTToolbarDataModel() : nsToolbarDataModel(), nsHTDataModel(), - mBGRequest(nsnull) -{ - NS_INIT_REFCNT(); - -} - -//-------------------------------------------------------------------- -nsHTToolbarDataModel::~nsHTToolbarDataModel() -{ - NS_IF_RELEASE(mBGRequest); -} - - -// ISupports Implementation -------------------------------------------------------------------- -nsresult nsHTToolbarDataModel::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) (nsISupports *)(nsIImageRequestObserver*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kIImageObserverIID)) { - *aInstancePtr = (void*)(nsIImageRequestObserver*)this; - AddRef(); - return NS_OK; - } - return NS_ERROR_NULL_POINTER; -} - -// Hierarchical Tree Data Model Implementation --------------------- - -void -nsHTToolbarDataModel::SetContentRoot(nsIContent* pContent) -{ - // Construct our visible items array - SetContentRootDelegate(pContent); -} - - -// -// GetToolbarStyle -// -// Loads up all the style information from the DOM/CSS. -// NOTE: right now this is just hard-coded stuff. THis may all go away when the toolbar -// is integrated with the frame system. -// -void -nsHTToolbarDataModel::GetToolbarStyle ( nsIDeviceContext* dc, nsBasicStyleInfo& styleInfo ) const -{ - // Initialize the font. - nsString fontFamily("Helvetica"); - int fontSize = 12; - int fontWeight = 400; - int fontStyle = NS_FONT_STYLE_NORMAL; - int fontDecoration = NS_FONT_DECORATION_NONE; - - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL, - fontWeight, fontDecoration, - nscoord(t2d * NSIntPointsToTwips(fontSize))); - - styleInfo.font = theFont; - - // Init the colors - styleInfo.foregroundColor = NS_RGB(255,255,255); - styleInfo.backgroundColor = NS_RGB(0,0,0); - - styleInfo.pBackgroundImage = GetBGImage(); -} - - -// -// GetBGImage -// -// Fetch the bg image of this toolbar -// -nsIImage* -nsHTToolbarDataModel :: GetBGImage() const -{ - nsString url("http://www.shadowland.org/images/ancient_glyphs.jpg"); - - if (mBGRequest == nsnull) { - // cast away const because we can't use mutable - nsHTToolbarDataModel* self = NS_CONST_CAST(nsHTToolbarDataModel*, this); - self->mBGRequest = RequestImage(url); - } - return mBGRequest->GetImage(); - -} // GetBGImage - - -// -// RequestImage -// -// Actually kick off the image request. -// -nsIImageRequest* -nsHTToolbarDataModel :: RequestImage(nsString& reqUrl) const -{ - nsIImageGroup* pGroup = GetImageGroup(); - - char * url = reqUrl.ToNewCString(); //*** candidate for auto_ptr - nsIImageRequest *request = pGroup->GetImage(url, - (nsIImageRequestObserver*)this, - NULL, 0, 0, - 0); - delete[] url; - - return request; -} // RequestImage - - -// -// Notify -// -// image request observer implementation -// -void -nsHTToolbarDataModel::Notify(nsIImageRequest *aImageRequest, - nsIImage *aImage, - nsImageNotification aNotificationType, - PRInt32 aParam1, PRInt32 aParam2, - void *aParam3) -{ - if (aNotificationType == nsImageNotification_kImageComplete) - { - // Notify the data source that we loaded. It can then inform the data source listener - // regarding what happened. - ImageLoaded(nsnull); - } -} // Notify - - -// -// NotifyError -// -// Called when the image observer gets an error -// -void -nsHTToolbarDataModel::NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType) -{ - //*** what should we do here? -} - - -// -// CreateDataItemWithContentNode -// -// Build one of our special data items hooked up to the given content node. -// -nsHierarchicalDataItem* -nsHTToolbarDataModel :: CreateDataItemWithContentNode(nsIContent* aContent) -{ - //nsHTTreeItem* pItem = new nsHTTreeItem(pContent, this); - return nsnull; -} diff --git a/widget/src/xpwidgets/nsHTToolbarDataModel.h b/widget/src/xpwidgets/nsHTToolbarDataModel.h deleted file mode 100644 index 59d6404a331a..000000000000 --- a/widget/src/xpwidgets/nsHTToolbarDataModel.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTToolbarDataModel_h___ -#define nsHTToolbarDataModel_h___ - -#include "nsHTDataModel.h" -#include "nsToolbarDataModel.h" -#include "nsIImageObserver.h" - - - -//------------------------------------------------------------ -// An abstract API for communication with a hierarchical store of -// information. Iteration over children in the model is provided. -// The model also provides a flattened view of the toolbar (a list -// of visible nodes). -//------------------------------------------------------------ - -class nsHTToolbarDataModel : public nsHTDataModel, public nsToolbarDataModel, public nsIImageRequestObserver -{ -public: - nsHTToolbarDataModel(); - virtual ~nsHTToolbarDataModel(); - - // Isupports interface ------------------ - NS_DECL_ISUPPORTS - - // IImageRequestObserver Interface ---------------- - void Notify(nsIImageRequest *aImageRequest, - nsIImage *aImage, - nsImageNotification aNotificationType, - PRInt32 aParam1, PRInt32 aParam2, - void *aParam3); - void NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType); - - // ---------------- End of interfaces - - // Functions inherited from abstract hierarchical data model should be delegated to our - // concrete base class - virtual void SetContentRoot(nsIContent* pContent); - virtual nsHierarchicalDataItem* GetRoot() const { return GetRootDelegate(); } - virtual PRUint32 GetFirstVisibleItemIndex() const { return GetFirstVisibleItemIndexDelegate(); }; - virtual void SetFirstVisibleItemIndex(PRUint32 index) { SetFirstVisibleItemIndexDelegate(index); }; - virtual nsHierarchicalDataItem* GetNthItem(PRUint32 n) const { return GetNthItemDelegate(n) ;}; - virtual void SetDataModelListener(nsDataModelWidget* pListener) { SetDataModelListenerDelegate(pListener); }; - - virtual void SetSelection(nsHierarchicalDataItem* pDataItem) - { SetSelectionDelegate(pDataItem); }; - - virtual void ToggleSelection(nsHierarchicalDataItem* pDataItem) - { ToggleSelectionDelegate(pDataItem); }; - - virtual void RangedSelection(PRUint32 n, PRUint32 count) - { RangedSelectionDelegate(n, count); }; - - virtual void ClearSelection() - { ClearSelectionDelegate(); }; - - // ---------------- End of delegated functions - - // Style Retrievers - virtual void GetToolbarStyle(nsIDeviceContext* pContext, - nsBasicStyleInfo& styleInfo) const; - - // Inherited functions from HTDataModel go here. - nsHierarchicalDataItem* CreateDataItemWithContentNode(nsIContent* pContent); - -protected: - - nsIImageRequest* RequestImage(nsString& reqUrl) const; // Helper to kick off the image load. - nsIImage* GetBGImage() const; - -private: - - nsIImageRequest* mBGRequest; // The toolbar background image. ***should be com_auto_ptr - -}; - -#endif /* nsHTTreeDataModel_h___ */ diff --git a/widget/src/xpwidgets/nsHTTreeDataModel.cpp b/widget/src/xpwidgets/nsHTTreeDataModel.cpp deleted file mode 100644 index 1d00468f331b..000000000000 --- a/widget/src/xpwidgets/nsHTTreeDataModel.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nspr.h" -#include "nsString.h" -#include "nsFont.h" -#include "nsHTTreeDataModel.h" -#include "nsWidgetsCID.h" -#include "nsDataModelWidget.h" -#include "nsHTColumn.h" -#include "nsHTControlStripItem.h" -#include "nsIDeviceContext.h" -#include "nsIImageObserver.h" -#include "nsIImageRequest.h" -#include "nsIImageGroup.h" -#include "nsHTTreeItem.h" -#include "nsIContent.h" - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID); - -NS_IMPL_ADDREF(nsHTTreeDataModel) -NS_IMPL_RELEASE(nsHTTreeDataModel) - -nsHTTreeDataModel::nsHTTreeDataModel() : nsTreeDataModel(), nsHTDataModel() -{ - NS_INIT_REFCNT(); - SetImplData((void*)(nsHTDataModel*)this); - - // Image Request Inits - mTitleBGRequest = nsnull; - mControlStripBGRequest = nsnull; - mColumnHeaderBGRequest = nsnull; - - mSelectedColumnIndex = -1; - - // Hard-coded values. - mVisibleColumnCount = 3; - - mSingleControlStripItem = new nsHTControlStripItem(); -} - -//-------------------------------------------------------------------- -nsHTTreeDataModel::~nsHTTreeDataModel() -{ - // Delete hard-coded value - delete mSingleControlStripItem; -} - -// ISupports Implementation -------------------------------------------------------------------- -nsresult nsHTTreeDataModel::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) (nsISupports *)(nsIImageRequestObserver*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kIImageObserverIID)) { - *aInstancePtr = (void*)(nsIImageRequestObserver*)this; - AddRef(); - return NS_OK; - } - return NS_ERROR_NULL_POINTER; -} - -// Hierarchical Tree Data Model Implementation --------------------- - -void nsHTTreeDataModel::SetContentRoot(nsIContent* pContent) -{ - // Construct our visible items array - SetContentRootDelegate(pContent); - - // Destroy our old columns list. TODO - - // Create our new columns list. - // Column headers come from the root node. - if (mRootNode) - { - nsHTItem* pItem = (nsHTItem*)(mRootNode->GetImplData()); - nsIContent* pColumnNode = nsHTDataModel::FindChildWithName(pItem->GetContentNode(), "columns"); - if (pColumnNode) - { - PRInt32 numChildren; - pColumnNode->ChildCount(numChildren); - for (PRInt32 i = 0; i < numChildren; i++) - { - nsIContent* child = nsnull; - pColumnNode->ChildAt(i, child); - if (child) - { - // We have a column to add to our array. - nsHTColumn* pColumn = new nsHTColumn(child); - mColumnArray.AppendElement(pColumn); - } - - NS_IF_RELEASE(child); - } - - // For now make only the name column visible. - mVisibleColumnCount = 1; - mTotalColumnCount = mColumnArray.Count(); - } - } -} - - -PRUint32 nsHTTreeDataModel::GetVisibleColumnCount() const -{ - return mVisibleColumnCount; -} - -PRUint32 nsHTTreeDataModel::GetColumnCount() const -{ - return mTotalColumnCount; -} - -nsTreeColumn* nsHTTreeDataModel::GetNthColumn(PRUint32 n) const -{ - if (n < mTotalColumnCount) - return (nsTreeColumn*)mColumnArray[n]; - else return nsnull; -} - -void nsHTTreeDataModel::SetVisibleColumnCount(PRUint32 columnCount) -{ - mVisibleColumnCount = columnCount; -} - -PRUint32 nsHTTreeDataModel::GetControlStripItemCount() const -{ - return 2; -} - -nsTreeControlStripItem* nsHTTreeDataModel::GetNthControlStripItem(PRUint32 n) const -{ - return mSingleControlStripItem; -} - -void nsHTTreeDataModel::GetControlStripCloseText(nsString& closeText) const -{ - closeText = "Close"; -} - -PRBool nsHTTreeDataModel::ShowTitleBar() const -{ - return PR_TRUE; -} - -PRBool nsHTTreeDataModel::ShowTitleBarText() const -{ - return PR_TRUE; -} - -PRBool nsHTTreeDataModel::ShowControlStrip() const -{ - return PR_TRUE; -} - -PRBool nsHTTreeDataModel::ShowColumnHeaders() const -{ - return PR_TRUE; -} - -void nsHTTreeDataModel::GetTitleBarStyle(nsIDeviceContext* dc, nsBasicStyleInfo& styleInfo) const -{ - // Initialize the font. - nsString fontFamily("Haettenschweiler"); - int fontSize = 24; - int fontWeight = 400; - int fontStyle = NS_FONT_STYLE_NORMAL; - int fontDecoration = NS_FONT_DECORATION_NONE; - - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL, - fontWeight, fontDecoration, - nscoord(t2d * NSIntPointsToTwips(fontSize))); - - styleInfo.font = theFont; - - // Init the colors - styleInfo.foregroundColor = NS_RGB(255,255,255); - styleInfo.backgroundColor = NS_RGB(0,0,0); - - styleInfo.pBackgroundImage = nsnull; //GetTitleBGImage(); -} - -void nsHTTreeDataModel::GetColumnHeaderStyle(nsIDeviceContext* dc, nsColumnHeaderStyleInfo& styleInfo) const -{ - // Initialize the font. - nsString fontFamily("Lucida Handwriting"); - int fontSize = 12; - int fontWeight = 400; - int fontStyle = NS_FONT_STYLE_NORMAL; - int fontDecoration = NS_FONT_DECORATION_NONE; - - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL, - fontWeight, fontDecoration, - nscoord(t2d * NSIntPointsToTwips(fontSize))); - - styleInfo.font = theFont; - - // Init the colors - styleInfo.foregroundColor = NS_RGB(0,0,0); - styleInfo.backgroundColor = NS_RGB(192,192,192); - styleInfo.sortFGColor = NS_RGB(0,0,0); - styleInfo.sortBGColor = NS_RGB(64,64,64); - styleInfo.disabledColor = NS_RGB(128,128,128); - - styleInfo.pBackgroundImage = nsnull; //GetColumnHeaderBGImage(); -} - -void nsHTTreeDataModel::GetControlStripStyle(nsIDeviceContext* dc, nsBasicStyleInfo& styleInfo) const -{ - // Initialize the font. - nsString fontFamily("Arial Narrow"); - int fontSize = 12; - int fontWeight = 400; - int fontStyle = NS_FONT_STYLE_NORMAL; - int fontDecoration = NS_FONT_DECORATION_NONE; - - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont theFont(fontFamily, fontStyle, NS_FONT_VARIANT_NORMAL, - fontWeight, fontDecoration, - nscoord(t2d * NSIntPointsToTwips(fontSize))); - - styleInfo.font = theFont; - - // Init the colors - styleInfo.foregroundColor = NS_RGB(255,255,255); - styleInfo.backgroundColor = NS_RGB(0,0,0); - - styleInfo.pBackgroundImage = nsnull; //GetControlStripBGImage(); -} - -void nsHTTreeDataModel::GetTitleBarText(nsString& text) const -{ - text = "Bookmarks"; -} - -// Protected Helpers -nsIImage* nsHTTreeDataModel::GetTitleBGImage() const -{ - // cast away const because we can't use mutable - nsHTTreeDataModel* self = NS_CONST_CAST(nsHTTreeDataModel*,this); - - nsString url("http://www.shadowland.org/images/ancient_glyphs.jpg"); - if (mTitleBGRequest == nsnull) - self->mTitleBGRequest = RequestImage(url); - return mTitleBGRequest->GetImage(); -} - -nsIImage* nsHTTreeDataModel::GetControlStripBGImage() const -{ - // cast away const because we can't use mutable - nsHTTreeDataModel* self = NS_CONST_CAST(nsHTTreeDataModel*,this); - - nsString url("http://www.shadowland.org/images/minute_bumps.jpg"); - if (mControlStripBGRequest == nsnull) - self->mControlStripBGRequest = RequestImage(url); - return mControlStripBGRequest->GetImage(); -} - -nsIImage* nsHTTreeDataModel::GetColumnHeaderBGImage() const -{ - // cast away const because we can't use mutable - nsHTTreeDataModel* self = NS_CONST_CAST(nsHTTreeDataModel*,this); - - nsString url("http://www.shadowland.org/images/tapestry.jpg"); - if (mColumnHeaderBGRequest == nsnull) - self->mColumnHeaderBGRequest = RequestImage(url); - return mColumnHeaderBGRequest->GetImage(); -} - -nsIImageRequest* nsHTTreeDataModel::RequestImage(nsString& reqUrl) const -{ - nsIImageGroup* pGroup = GetImageGroup(); - - char * url = reqUrl.ToNewCString(); - - nsIImageRequest * request; - request = pGroup->GetImage(url, - (nsIImageRequestObserver*)this, - NULL, 0, 0, - 0); - delete[] url; - - return request; -} - -// image request observer implementation -void nsHTTreeDataModel::Notify(nsIImageRequest *aImageRequest, - nsIImage *aImage, - nsImageNotification aNotificationType, - PRInt32 aParam1, PRInt32 aParam2, - void *aParam3) -{ - if (aNotificationType == nsImageNotification_kImageComplete) - { - // Notify the data source that we loaded. It can then inform the data source listener - // regarding what happened. - ImageLoaded(nsnull); - } -} - -void nsHTTreeDataModel::NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType) -{ -} - -// Inherited functions from nsHTDataModel -nsHierarchicalDataItem* nsHTTreeDataModel::CreateDataItemWithContentNode(nsIContent* pContent) -{ - nsHTTreeItem* pItem = new nsHTTreeItem(pContent, this); - - // Register our item as an event listener on the DOM node. - return pItem; -} diff --git a/widget/src/xpwidgets/nsHTTreeDataModel.h b/widget/src/xpwidgets/nsHTTreeDataModel.h deleted file mode 100644 index b884dc0d247f..000000000000 --- a/widget/src/xpwidgets/nsHTTreeDataModel.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTTreeDataModel_h___ -#define nsHTTreeDataModel_h___ - -#include "nsHTDataModel.h" -#include "nsTreeDataModel.h" -#include "nsIImageObserver.h" - -class nsTreeColumn; -class nsTreeControlStripItem; - -//------------------------------------------------------------ -// An abstract API for communication with a hierarchical store of -// information. Iteration over children in the model is provided. -// The model also provides a flattened view of the tree (a list -// of visible nodes). -//------------------------------------------------------------ - -class nsHTTreeDataModel : public nsHTDataModel, public nsTreeDataModel, public nsIImageRequestObserver - -{ -public: - nsHTTreeDataModel(); - virtual ~nsHTTreeDataModel(); - - // Isupports interface ------------------ - NS_DECL_ISUPPORTS - - // IImageRequestObserver Interface ---------------- - void Notify(nsIImageRequest *aImageRequest, - nsIImage *aImage, - nsImageNotification aNotificationType, - PRInt32 aParam1, PRInt32 aParam2, - void *aParam3); - - void NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType); - // End of interfaces - - // Functions inherited from abstract hierarchical data model should be delegated to our - // concrete base class - // Setting the Content Root for the tree - virtual void SetContentRoot(nsIContent* pContent); - virtual nsHierarchicalDataItem* GetRoot() const { return GetRootDelegate(); } - virtual PRUint32 GetFirstVisibleItemIndex() const { return GetFirstVisibleItemIndexDelegate(); }; - virtual void SetFirstVisibleItemIndex(PRUint32 index) { SetFirstVisibleItemIndexDelegate(index); }; - virtual nsHierarchicalDataItem* GetNthItem(PRUint32 n) const { return GetNthItemDelegate(n) ;}; - virtual void SetDataModelListener(nsDataModelWidget* pListener) { SetDataModelListenerDelegate(pListener); }; - - virtual void SetSelection(nsHierarchicalDataItem* pDataItem) - { SetSelectionDelegate(pDataItem); }; - - virtual void ToggleSelection(nsHierarchicalDataItem* pDataItem) - { ToggleSelectionDelegate(pDataItem); }; - - virtual void RangedSelection(PRUint32 n, PRUint32 count) - { RangedSelectionDelegate(n, count); }; - - virtual void ClearSelection() - { ClearSelectionDelegate(); }; - - // End of delegated functions - - // Column Iteration - virtual PRUint32 GetVisibleColumnCount() const; - virtual PRUint32 GetColumnCount() const; - virtual nsTreeColumn* GetNthColumn(PRUint32 n) const; - virtual void SetVisibleColumnCount(PRUint32 n); - - // Control Strip Iteration - virtual PRUint32 GetControlStripItemCount() const; - virtual nsTreeControlStripItem* GetNthControlStripItem(PRUint32 n) const; - virtual void GetControlStripCloseText(nsString& closeText) const; - - // Visibility Queries - virtual PRBool ShowTitleBar() const; - virtual PRBool ShowTitleBarText() const; - virtual PRBool ShowColumnHeaders() const; - virtual PRBool ShowControlStrip() const; - - // Style Retrievers - virtual void GetTitleBarStyle(nsIDeviceContext* pContext, - nsBasicStyleInfo& styleInfo) const; - virtual void GetColumnHeaderStyle(nsIDeviceContext* pContext, - nsColumnHeaderStyleInfo& styleInfo) const; - virtual void GetControlStripStyle(nsIDeviceContext* pContext, - nsBasicStyleInfo& styleInfo) const; - - virtual PRInt32 GetSelectedColumnIndex() const { return mSelectedColumnIndex; }; - virtual void SetSelectedColumnIndex(PRInt32 n) { mSelectedColumnIndex = n; }; - - // Text for the title bar, control strip and column headers - virtual void GetTitleBarText(nsString& text) const; - -public: - // Inherited functions from HTDataModel go here. - nsHierarchicalDataItem* CreateDataItemWithContentNode(nsIContent* pContent); - -protected: - nsIImageRequest* RequestImage(nsString& reqUrl) const; // Helper to kick off the image load. - nsIImage* GetTitleBGImage() const; - nsIImage* GetControlStripBGImage() const; - nsIImage* GetColumnHeaderBGImage() const; - -private: - nsVoidArray mColumnArray; - nsTreeControlStripItem *mSingleControlStripItem; - - PRUint32 mVisibleColumnCount; - PRUint32 mTotalColumnCount; - nsIImageRequest* mTitleBGRequest; // The title bar background image - nsIImageRequest* mControlStripBGRequest;// The control strip bg image - nsIImageRequest* mColumnHeaderBGRequest;// The column header background image - - PRInt32 mSelectedColumnIndex; -}; - -#endif /* nsHTTreeDataModel_h___ */ diff --git a/widget/src/xpwidgets/nsHTTreeItem.cpp b/widget/src/xpwidgets/nsHTTreeItem.cpp deleted file mode 100644 index 939fdb258430..000000000000 --- a/widget/src/xpwidgets/nsHTTreeItem.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nsRect.h" -#include "nspr.h" -#include "nsString.h" -#include "nsHTColumn.h" -#include "nsHTTreeItem.h" -#include "nsHTTreeDataModel.h" -#include "nsWidgetsCID.h" -#include "nsIComponentManager.h" -#include "nsIImageObserver.h" -#include "nsIImageRequest.h" -#include "nsIImageGroup.h" -#include "nsIContent.h" - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID); - -NS_IMPL_ADDREF(nsHTTreeItem) -NS_IMPL_RELEASE(nsHTTreeItem) - -nsHTTreeItem::nsHTTreeItem(nsIContent* pContent, nsHierarchicalDataModel* pModel) -: nsTreeItem(), nsHTItem(pContent, pModel) -{ - NS_INIT_REFCNT(); - mClosedIconRequest = nsnull; - mOpenIconRequest = nsnull; - mClosedTriggerRequest = nsnull; - mOpenTriggerRequest = nsnull; - mBackgroundRequest = nsnull; - - SetImplData((void*)(nsHTItem*)this); -} - -//-------------------------------------------------------------------- -nsHTTreeItem::~nsHTTreeItem() -{ - NS_IF_RELEASE(mContentNode); - - // Empty out our rectangle array - PRInt32 count = mColumnRectArray.Count(); - for (PRInt32 i = 0; i < count; i++) - { - nsRect* rect = (nsRect*)mColumnRectArray[i]; - delete rect; - } - - mColumnRectArray.Clear(); -} - -// ISupports Implementation -------------------------------------------------------------------- -nsresult nsHTTreeItem::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) (nsISupports *)(nsIImageRequestObserver*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kIImageObserverIID)) { - *aInstancePtr = (void*)(nsIImageRequestObserver*)this; - AddRef(); - return NS_OK; - } - return NS_ERROR_NULL_POINTER; -} - -// TreeItem Implementation --------------------- - -void nsHTTreeItem::GetItemStyle(nsIDeviceContext* dc, nsTreeItemStyleInfo& styleInfo) const -{ - styleInfo.foregroundColor = NS_RGB(0,0,0); - styleInfo.backgroundColor = NS_RGB(240,240,240); - styleInfo.showTrigger = PR_TRUE; - styleInfo.showIcon = PR_TRUE; - styleInfo.leftJustifyTrigger = PR_FALSE; - - styleInfo.rolloverFGColor = NS_RGB(0,0,255); - - styleInfo.selectionBGColor = NS_RGB(0,0,128); - styleInfo.selectionFGColor = NS_RGB(255,255,255); - - styleInfo.showHorizontalDivider = PR_TRUE; - styleInfo.showVerticalDivider = PR_TRUE; - styleInfo.horizontalDividerColor = NS_RGB(255,255,255); - styleInfo.verticalDividerColor = NS_RGB(255,255,255); - - if (styleInfo.showTrigger) - styleInfo.pTriggerImage = GetTriggerImage(); - - if (styleInfo.showIcon) - styleInfo.pIconImage = GetIconImage(); - - styleInfo.pBackgroundImage = nsnull; //GetBackgroundImage(); -} - -nsIImage* nsHTTreeItem::GetTriggerImage() const -{ - // cast away const because we can't use mutable - nsHTTreeItem* self = NS_CONST_CAST(nsHTTreeItem*,this); - - // TODO: Really read in these properties - nsString openTriggerURL("http://www.shadowland.org/client/images/overlay.gif"); - nsString closedTriggerURL("http://www.shadowland.org/client/images/overlay.gif"); - - if (IsExpanded()) - { - if (mOpenTriggerRequest == nsnull) - { - // Request the image. - self->mOpenTriggerRequest = RequestImage(openTriggerURL); - } - return mOpenTriggerRequest->GetImage(); - } - else - { - if (mClosedTriggerRequest == nsnull) - self->mClosedTriggerRequest = RequestImage(closedTriggerURL); - return mClosedTriggerRequest->GetImage(); - } -} - -nsIImage* nsHTTreeItem::GetIconImage() const -{ - // cast away const because we can't use mutable - nsHTTreeItem* self = NS_CONST_CAST(nsHTTreeItem*,this); - - nsString openIconURL("http://www.shadowland.org/CLIENT/IMAGES/OpenRead.gif"); - nsString closedIconURL("http://www.shadowland.org/CLIENT/IMAGES/ClosedRead.gif"); - - if (IsExpanded()) - { - if (mOpenIconRequest == nsnull) - self->mOpenIconRequest = RequestImage(openIconURL); - return mOpenIconRequest->GetImage(); - } - else - { - if (mClosedIconRequest == nsnull) - self->mClosedIconRequest = RequestImage(closedIconURL); - return mClosedIconRequest->GetImage(); - } -} - -nsIImage* nsHTTreeItem::GetBackgroundImage() const -{ - // cast away const because we can't use mutable - nsHTTreeItem* self = NS_CONST_CAST(nsHTTreeItem*,this); - - nsString bgURL("http://www.shadowland.org/images/chalk.jpg"); - if (mBackgroundRequest == nsnull) - self->mBackgroundRequest = RequestImage(bgURL); - return mBackgroundRequest->GetImage(); -} - -nsIImageRequest* nsHTTreeItem::RequestImage(nsString& reqUrl) const -{ - nsHTTreeDataModel* pDataModel = (nsHTTreeDataModel*)(mDataModel); - nsIImageGroup* pGroup = pDataModel->GetImageGroup(); - - char * url = reqUrl.ToNewCString(); - - nsIImageRequest * request; - request = pGroup->GetImage(url, - (nsIImageRequestObserver*)this, - NULL, 0, 0, - 0); - delete[] url; - - return request; -} - -void nsHTTreeItem::GetTextForColumn(nsTreeColumn* pColumn, nsString& nodeText) const -{ - nsString columnName; - pColumn->GetColumnName(columnName); - - // Look for a child of the content node that has this name as its tag. - nsIContent* pColumnNode = nsHTDataModel::FindChildWithName(mContentNode, "columns"); - if (pColumnNode) - { - nsIContent* pChildNode = nsHTDataModel::FindChildWithName(pColumnNode, columnName); - if (pChildNode) - nsHTDataModel::GetChildTextForNode(pChildNode, nodeText); - } -} - -// image request observer implementation -void nsHTTreeItem::Notify(nsIImageRequest *aImageRequest, - nsIImage *aImage, - nsImageNotification aNotificationType, - PRInt32 aParam1, PRInt32 aParam2, - void *aParam3) -{ - if (aNotificationType == nsImageNotification_kImageComplete) - { - // Notify the data source that we loaded. It can then inform the data source listener - // regarding what happened. - nsHTTreeDataModel* pDataModel = (nsHTTreeDataModel*)(mDataModel); - if (pDataModel) - pDataModel->ImageLoaded(this); - } -} - -void nsHTTreeItem::NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType) -{ -} - - -PRUint32 nsHTTreeItem::GetChildCount() const -{ - nsIContent* pChildrenNode = nsHTDataModel::FindChildWithName(mContentNode, "children"); - PRInt32 childCount = 0; - if (pChildrenNode) - pChildrenNode->ChildCount(childCount); - - return childCount; -} - -nsIContent* nsHTTreeItem::GetNthChildContentNode(PRUint32 n) const -{ - nsIContent* pGrandchild = nsnull; - nsIContent* pChildrenNode = nsHTDataModel::FindChildWithName(mContentNode, "children"); - if (pChildrenNode) - { - pChildrenNode->ChildAt(n, pGrandchild); - } - return pGrandchild; -} - -void nsHTTreeItem::SetContentRectangle(const nsRect& rect, PRUint32 n) -{ - PRInt32 count = mColumnRectArray.Count(); - if (count == (PRInt32)n) - mColumnRectArray.AppendElement(new nsRect(rect)); - else - { - nsRect* existingRect = (nsRect*)(mColumnRectArray[n]); - *existingRect = rect; - } -} diff --git a/widget/src/xpwidgets/nsHTTreeItem.h b/widget/src/xpwidgets/nsHTTreeItem.h deleted file mode 100644 index 8e8fc3c9018a..000000000000 --- a/widget/src/xpwidgets/nsHTTreeItem.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHTTreeItem_h___ -#define nsHTTreeItem_h___ - -#include "nsTreeItem.h" -#include "nsVoidArray.h" -#include "nsHTItem.h" -#include "nsIImageObserver.h" - -class nsHTDataModel; -class nsIImageGroup; -class nsIContent; - -//------------------------------------------------------------ -// This class functions as the data source for column information (things like -// width, desired percentage, and sorting). - -class nsHTTreeItem : public nsTreeItem, public nsHTItem, public nsIImageRequestObserver - -{ -public: - nsHTTreeItem(nsIContent* pContent, nsHierarchicalDataModel* pModel); - virtual ~nsHTTreeItem(); - - // Isupports interface ------------------ - NS_DECL_ISUPPORTS - - // IImageRequestObserver Interface ---------------- - void Notify(nsIImageRequest *aImageRequest, - nsIImage *aImage, - nsImageNotification aNotificationType, - PRInt32 aParam1, PRInt32 aParam2, - void *aParam3); - - void NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType); - // End of interfaces - - // All functions inherited from HierarchicalDataItem are delegated to - // the concrete implementation. - virtual PRBool IsExpanded() const { return IsExpandedDelegate(); }; - virtual void ToggleOpenState() { ToggleOpenStateDelegate(); }; - virtual PRUint32 GetChildCount() const; - virtual PRBool IsSelected() const { return IsSelectedDelegate(); }; - virtual PRUint32 GetIndentationLevel() const { return GetIndentationLevelDelegate(); }; - virtual void SetIndentationLevel(PRUint32 n) { SetIndentationLevelDelegate(n); }; - // End of delegated functions - - virtual void GetItemStyle(nsIDeviceContext* dc, - nsTreeItemStyleInfo& styleInfo) const; - - virtual void GetTextForColumn(nsTreeColumn* pColumn, nsString& nodeText) const; - - virtual void GetTreeItemRectangle(nsRect& rect) const { rect = mRowRectangle; }; - virtual void SetTreeItemRectangle(const nsRect& rect) { mRowRectangle = rect; }; - virtual void GetTriggerRectangle(nsRect& rect) const { rect = mTriggerRectangle; }; - virtual void SetTriggerRectangle(const nsRect& rect) { mTriggerRectangle = rect; }; - virtual void GetContentRectangle(nsRect& rect, PRUint32 n) const - { rect = *((nsRect*)mColumnRectArray[n]); }; - virtual void SetContentRectangle(const nsRect& rect, PRUint32 n); - - virtual nsHierarchicalDataItem* GetDataItem() { return this; } // Used by nsHTItem. - virtual nsIContent* GetNthChildContentNode(PRUint32 n) const; - -protected: - nsIImageRequest* RequestImage(nsString& reqUrl) const; // Helper to kick off the image load. - nsIImage* GetTriggerImage() const; - nsIImage* GetIconImage() const; - nsIImage* GetBackgroundImage() const; - -protected: - nsIImageRequest* mClosedIconRequest; // Closed image - nsIImageRequest* mOpenIconRequest; // Open image - nsIImageRequest* mClosedTriggerRequest; // Closed trigger image - nsIImageRequest* mOpenTriggerRequest; // Open trigger image - nsIImageRequest* mBackgroundRequest; // The background image - - nsRect mRowRectangle; // A cached copy of our position within the tree view. - nsRect mTriggerRectangle; // A cached copy of our trigger rectangle - nsVoidArray mColumnRectArray; // A cached copy of our content rectangles -}; - -#endif /* nsHTTreeItem_h___ */ diff --git a/widget/src/xpwidgets/nsHierarchicalDataItem.h b/widget/src/xpwidgets/nsHierarchicalDataItem.h deleted file mode 100644 index 2a6df1772a83..000000000000 --- a/widget/src/xpwidgets/nsHierarchicalDataItem.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHierarchicalDataItem_h___ -#define nsHierarchicalDataItem_h___ - -class nsHierarchicalDataModel; - -//------------------------------------------------------------ -// A single item in a hierarchical data model. -//------------------------------------------------------------ - -class nsHierarchicalDataItem - -{ -protected: - nsHierarchicalDataItem() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsHierarchicalDataItem() {}; - - virtual PRBool IsExpanded() const = 0; - virtual void ToggleOpenState() = 0; - virtual PRUint32 GetChildCount() const = 0; // Gets the number of children that reside underneath this node. - - virtual PRBool IsSelected() const = 0; - - virtual PRUint32 GetIndentationLevel() const = 0; - virtual void SetIndentationLevel(PRUint32 n) = 0; - -public: - void* GetImplData() { return mImplData; } - void SetImplData(void* pData) { mImplData = pData; } - -protected: - void* mImplData; -}; - -#endif /* nsHierarchicalDataItem_h___ */ diff --git a/widget/src/xpwidgets/nsHierarchicalDataModel.h b/widget/src/xpwidgets/nsHierarchicalDataModel.h deleted file mode 100644 index 6770079965c3..000000000000 --- a/widget/src/xpwidgets/nsHierarchicalDataModel.h +++ /dev/null @@ -1,93 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsHierarchicalDataModel_h___ -#define nsHierarchicalDataModel_h___ - -#include "nsFont.h" -#include "nsColor.h" - -class nsHierarchicalDataItem; -class nsDataModelWidget; -class nsIContent; -class nsIImage; - -// Style info helper struct shared by most widgets. -struct nsBasicStyleInfo -{ - nsFont font; - nscolor foregroundColor; - nscolor backgroundColor; - nsIImage* pBackgroundImage; //*** com_auto_ptr? - - nsIImage* BackgroundImage ( ) const { return pBackgroundImage; } - - nsBasicStyleInfo(const nsFont& aFont) - :font(aFont), pBackgroundImage(nsnull) { } - -}; - -// ----------------------------------------------------------------- -// An abstract API for communication with a hierarchical store of -// information. Iteration over children in the model is provided. -// The model also provides a flattened view of the tree (a list -// of visible nodes). -//------------------------------------------------------------ - -class nsHierarchicalDataModel - -{ -protected: - nsHierarchicalDataModel() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsHierarchicalDataModel() {}; - - // Retrieve the root node of the data model. - // Setting the Content Root for the tree - virtual void SetContentRoot(nsIContent* pContent) = 0; - virtual nsHierarchicalDataItem* GetRoot() const = 0; - - // A visibility hint can be stored and retrieved (e.g., the leftmost or topmost - // item in the current scrolled view). - virtual PRUint32 GetFirstVisibleItemIndex() const = 0; - virtual void SetFirstVisibleItemIndex(PRUint32 index) = 0; - virtual nsHierarchicalDataItem* GetNthItem(PRUint32 n) const = 0; - - virtual void SetDataModelListener(nsDataModelWidget* pListener) = 0; - - // Selection APIs - virtual void SetSelection(nsHierarchicalDataItem* pDataItem) = 0; - // Sets the selection to be only the node passed in. All other nodes are deselected - // prior to the selection of the new node. - virtual void ToggleSelection(nsHierarchicalDataItem* pDataItem) = 0; - // Toggles the selection on the item specified without affecting other selected nodes. - virtual void RangedSelection(PRUint32 n, PRUint32 count) = 0; - // Selects the number of items specified by count, starting from position n. - virtual void ClearSelection() = 0; - // Deselects all items. - -public: - void* GetImplData() { return mImplData; } - void SetImplData(void* pData) { mImplData = pData; } - -protected: - void* mImplData; -}; - -#endif /* nsHierarchicalDataModel_h___ */ diff --git a/widget/src/xpwidgets/nsToolbar.cpp b/widget/src/xpwidgets/nsToolbar.cpp deleted file mode 100644 index cbe821627d0a..000000000000 --- a/widget/src/xpwidgets/nsToolbar.cpp +++ /dev/null @@ -1,959 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -// -// pinkerton ToDo: -// - make this talk to DOM for its children. -// - rip out nsIToolbar stuff -// - -#include "nsToolbar.h" -#include "nsHTToolbarDataModel.h" -#include "nsWidgetsCID.h" -#include "nspr.h" -#include "nsIWidget.h" -#include "nsIToolbarItemHolder.h" -#include "nsImageButton.h" -#include "nsIComponentManager.h" -#include "nsIDeviceContext.h" -#include "nsCOMPtr.h" - - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kCToolbarCID, NS_TOOLBAR_CID); -static NS_DEFINE_IID(kCIToolbarIID, NS_ITOOLBAR_IID); -static NS_DEFINE_IID(kIToolbarIID, NS_ITOOLBAR_IID); - - -const PRInt32 gMaxInfoItems = 32; - -NS_IMPL_ADDREF(nsToolbar) -NS_IMPL_RELEASE(nsToolbar) - -static NS_DEFINE_IID(kIImageButtonIID, NS_IIMAGEBUTTON_IID); -static NS_DEFINE_IID(kImageButtonCID, NS_IMAGEBUTTON_CID); -static NS_DEFINE_IID(kIToolbarItemIID, NS_ITOOLBARITEM_IID); -static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); - -static NS_DEFINE_IID(kIToolbarItemHolderIID, NS_ITOOLBARITEMHOLDER_IID); -static NS_DEFINE_IID(kToolbarItemHolderCID, NS_TOOLBARITEMHOLDER_CID); -static NS_DEFINE_IID(kIImageButtonListenerIID, NS_IIMAGEBUTTONLISTENER_IID); - -static NS_DEFINE_IID(kIContentConnectorIID, NS_ICONTENTCONNECTOR_IID); - - - - - -//------------------------------------------------------------ -class ToolbarLayoutInfo { -public: - nsCOMPtr mItem; - PRInt32 mGap; - PRBool mStretchable; - - ToolbarLayoutInfo(nsIToolbarItem * aItem, PRInt32 aGap, PRBool isStretchable) - { - mItem = aItem; - mGap = aGap; - mStretchable = isStretchable; - } - -}; - - - -//-------------------------------------------------------------------- -//-- nsToolbar Constructor -//-------------------------------------------------------------------- -nsToolbar::nsToolbar() : nsDataModelWidget(), nsIToolbar(), - mDataModel(new nsHTToolbarDataModel) -{ - NS_INIT_REFCNT(); - - mMargin = 0; - mWrapMargin = 15; - mHGap = 0; - mVGap = 0; - - mBorderType = eToolbarBorderType_partial; - mLastItemIsRightJustified = PR_FALSE; - mNextLastItemIsStretchy = PR_FALSE; - mWrapItems = PR_FALSE; - mDoHorizontalLayout = PR_TRUE; - - mItems = (ToolbarLayoutInfo **) new PRInt32[gMaxInfoItems]; - mNumItems = 0; -} - -//-------------------------------------------------------------------- -nsToolbar::~nsToolbar() -{ - delete mDataModel; - - PRInt32 i; - for (i=0;i toolbar ( aEvent->widget ); - if ( toolbar ) - result = toolbar->HandleEvent(aEvent); - return result; -} - - -// -// Create -// -// Override to setup event listeners at widget creation time. -// -NS_METHOD -nsToolbar :: Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - nsresult answer = ChildWindow::Create(aParent, aRect, - aHandleEventFunction ? aHandleEventFunction : HandleToolbarEvent, - aContext, aAppShell, aToolkit, aInitData); - - if (mDataModel) - mDataModel->SetDataModelListener(this); - - return answer; - -} // Create - - -// -// SetContentRoot -// -// Hook up the toolbar to the content model rooted at the given node -// -NS_METHOD -nsToolbar::SetContentRoot(nsIContent* pContent) -{ - if (mDataModel) - mDataModel->SetContentRoot(pContent); - - return NS_OK; -} - - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::AddItem(nsIToolbarItem* anItem, PRInt32 aLeftGap, PRBool aStretchable) -{ - mItems[mNumItems++] = new ToolbarLayoutInfo(anItem, aLeftGap, aStretchable); - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::InsertItemAt(nsIToolbarItem* anItem, - PRInt32 aLeftGap, - PRBool aStretchable, - PRInt32 anIndex) -{ - - if ((anIndex < 0 || anIndex > mNumItems-1) && !(anIndex == 0 && mNumItems == 0)) { - return NS_ERROR_FAILURE; - } - - if (mNumItems > 0) { - // Shift them down to make room - PRInt32 i; - PRInt32 downToInx = anIndex + 1; - for (i=mNumItems;i>downToInx;i--) { - mItems[i] = mItems[i-1]; - - } - - // Insert the new widget - mItems[downToInx] = new ToolbarLayoutInfo(anItem, aLeftGap, aStretchable); - } else { - mItems[0] = new ToolbarLayoutInfo(anItem, aLeftGap, aStretchable); - } - mNumItems++; - - return NS_OK; -} -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::GetItemAt(nsIToolbarItem*& anItem, PRInt32 anIndex) -{ - if (anIndex < 0 || anIndex > mNumItems-1) { - anItem = nsnull; - return NS_ERROR_FAILURE; - } - - anItem = mItems[anIndex]->mItem; - NS_ADDREF(anItem); - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::DoLayout() -{ - nsRect tbRect; - nsWindow::GetBounds(tbRect); - - if (mDoHorizontalLayout) { - DoHorizontalLayout(tbRect); - } else { - DoVerticalLayout(tbRect); - } - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetHorizontalLayout(PRBool aDoHorizontalLayout) -{ - mDoHorizontalLayout = aDoHorizontalLayout; - return NS_OK; -} - -//-------------------------------------------------------------------- -void nsToolbar::GetMargins(PRInt32 &aX, PRInt32 &aY) -{ - - switch (mBorderType) { - case eToolbarBorderType_none: - aX = 0; - aY = 0; - break; - - case eToolbarBorderType_partial: - aX = 0; - aY = mMargin; - break; - - case eToolbarBorderType_full: - aX = mMargin; - aY = mMargin; - break; - - default: - aX = 0; - aY = 0; - } // switch -} - -//-------------------------------------------------------------------- -void nsToolbar::DoVerticalLayout(const nsRect& aTBRect) -{ - PRInt32 i; - PRInt32 x; - PRInt32 y; - - GetMargins(x, y); - - PRInt32 maxWidth = 0; - - // First layout all the items - for (i=0;imItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width, height; - - if (NS_OK != mItems[i]->mItem->GetPreferredSize(width, height)) { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - width = rect.width; - height = rect.height; - } - if (!mItems[i]->mStretchable) { - maxWidth = maxWidth > height? maxWidth:height; - } - - if (((y + height + mItems[i]->mGap) > aTBRect.height) && mWrapItems) { - y = mWrapMargin; - x += maxWidth; - maxWidth = 0; - } - - PRInt32 xLoc; - if (mWrapItems) { - xLoc = x; - } else { - xLoc = ((aTBRect.width - width) / 2); - xLoc = xLoc > -1 ? xLoc : mMargin; - } - // Gap is added before hand because it is the left hand gap - y += mItems[i]->mGap; - mItems[i]->mItem->SetBounds(xLoc, y, width, height, PR_FALSE); - y += width; - } - } - - // Right justify the last item - PRBool rightGotJustified = PR_FALSE; - - if (mNumItems > 1 && mLastItemIsRightJustified) { - PRInt32 index = mNumItems-1; - PRBool isVisible; - mItems[index]->mItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width, height; - if (NS_OK != mItems[index]->mItem->GetPreferredSize(width, height)) { - nsRect rect; - mItems[index]->mItem->GetBounds(rect); - width = rect.width; - height = rect.height; - } - PRInt32 yLoc = aTBRect.height - height - mItems[index]->mGap - mMargin; - PRInt32 xLoc; - if (mWrapItems) { - xLoc = x; - } else { - xLoc = (aTBRect.width - width) / 2; - xLoc = xLoc > -1 ? xLoc : mMargin; - } - mItems[index]->mItem->SetBounds(xLoc, yLoc, width, height, PR_FALSE); - rightGotJustified = PR_TRUE; - } - } - - // Make the next to the last item strechy - if (mNumItems > 1 && mNextLastItemIsStretchy) { - PRInt32 lastIndex = mNumItems-1; - PRInt32 nextLastIndex = mNumItems-2; - - if (!rightGotJustified) { // last item is not visible, so stretch to end - nsRect nextLastRect; - mItems[nextLastIndex]->mItem->GetBounds(nextLastRect); - nextLastRect.height = aTBRect.height - nextLastRect.y - mMargin; - mItems[nextLastIndex]->mItem->SetBounds(nextLastRect.x, nextLastRect.y, nextLastRect.width, nextLastRect.height, PR_TRUE); - } else { - - PRBool isVisible; - mItems[nextLastIndex]->mItem->IsVisible(isVisible); - if (isVisible) { // stretch if visible - nsRect lastRect; - nsRect nextLastRect; - - mItems[lastIndex]->mItem->GetBounds(lastRect); - mItems[nextLastIndex]->mItem->GetBounds(nextLastRect); - - nextLastRect.height = lastRect.y - nextLastRect.y - mItems[lastIndex]->mGap; - mItems[nextLastIndex]->mItem->SetBounds(nextLastRect.x, nextLastRect.y, nextLastRect.width, nextLastRect.height, PR_TRUE); - } - } - } - - for (i=0;imStretchable) { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - mItems[i]->mItem->SetBounds(rect.x, rect.y, rect.width, y+maxWidth, PR_TRUE); - } else { - mItems[i]->mItem->Repaint(PR_TRUE); - } - } - - Invalidate(PR_TRUE); // repaint toolbar -} - -//-------------------------------------------------------------------- -void nsToolbar::DoHorizontalLayout(const nsRect& aTBRect) -{ - PRInt32 i; - PRInt32 x; - PRInt32 y; - - GetMargins(x, y); - - PRInt32 maxHeight = 0; - - // First layout all the items - for (i=0;imItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width, height; - - if (NS_OK != mItems[i]->mItem->GetPreferredSize(width, height)) { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - width = rect.width; - height = rect.height; - } - - if (((x + width + mItems[i]->mGap) > aTBRect.width) && mWrapItems) { - x = mMargin + mWrapMargin; - y += maxHeight; - maxHeight = 0; - } - if (!mItems[i]->mStretchable) { - maxHeight = maxHeight > height? maxHeight:height; - } - - PRInt32 yLoc; - if (mWrapItems) { - yLoc = y; - } else { - yLoc = ((aTBRect.height - height) / 2); - yLoc = yLoc > -1 ? yLoc : mMargin; - } - // Gap is added before hand because it is the left hand gap - // Don't set the bounds on the last item if it is right justified - x += mItems[i]->mGap; - if (((i == (mNumItems-1) && !mLastItemIsRightJustified)) || (i != (mNumItems-1))) { - mItems[i]->mItem->SetBounds(x, yLoc, width, height, PR_FALSE); - } - x += width; - } - } - - // Right justify the last item - PRBool rightGotJustified = PR_FALSE; - - if (mNumItems > 1 && mLastItemIsRightJustified) { - PRInt32 index = mNumItems-1; - PRBool isVisible; - mItems[index]->mItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width, height; - if (NS_OK != mItems[index]->mItem->GetPreferredSize(width, height)) { - nsRect rect; - mItems[index]->mItem->GetBounds(rect); - width = rect.width; - height = rect.height; - } - PRInt32 xLoc = aTBRect.width - width - mItems[index]->mGap - mMargin; - PRInt32 yLoc; - if (mWrapItems) { - yLoc = y; - } else { - yLoc = (aTBRect.height - height) / 2; - yLoc = yLoc > -1 ? yLoc : mMargin; - } - mItems[index]->mItem->SetBounds(xLoc, yLoc, width, height, PR_FALSE); - rightGotJustified = PR_TRUE; - } - } - - // Make the next to the last item strechy - if (mNumItems > 1 && mNextLastItemIsStretchy) { - PRInt32 lastIndex = mNumItems-1; - PRInt32 nextLastIndex = mNumItems-2; - - if (!rightGotJustified) { // last item is not visible, so stretch to end - nsRect nextLastRect; - mItems[nextLastIndex]->mItem->GetBounds(nextLastRect); - nextLastRect.width = aTBRect.width - nextLastRect.x - mMargin; - mItems[nextLastIndex]->mItem->SetBounds(nextLastRect.x, nextLastRect.y, nextLastRect.width, nextLastRect.height, PR_TRUE); - } else { - - PRBool isVisible; - mItems[nextLastIndex]->mItem->IsVisible(isVisible); - if (isVisible) { // stretch if visible - nsRect lastRect; - nsRect nextLastRect; - - mItems[lastIndex]->mItem->GetBounds(lastRect); - mItems[nextLastIndex]->mItem->GetBounds(nextLastRect); - - nextLastRect.width = lastRect.x - nextLastRect.x - mItems[lastIndex]->mGap; - mItems[nextLastIndex]->mItem->SetBounds(nextLastRect.x, nextLastRect.y, nextLastRect.width, nextLastRect.height, PR_TRUE); - } - } - } - - for (i=0;imStretchable) { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - mItems[i]->mItem->SetBounds(rect.x, rect.y, rect.width, y+maxHeight, PR_TRUE); - } else { - mItems[i]->mItem->Repaint(PR_TRUE); - } - } - - Invalidate(PR_TRUE); // repaint toolbar -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetLastItemIsRightJustified(const PRBool & aState) -{ - mLastItemIsRightJustified = aState; - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetNextLastItemIsStretchy(const PRBool & aState) -{ - mNextLastItemIsStretchy = aState; - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) -{ - nsRect rect; - nsWindow::GetBounds(rect); - - if (mDoHorizontalLayout) { - aWidth = mMargin*2; - aHeight = 0; - PRInt32 i; - for (i=0;imItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width; - PRInt32 height; - if (NS_OK == mItems[i]->mItem->GetPreferredSize(width, height)) { - aWidth += width + mItems[i]->mGap; - if (!mItems[i]->mStretchable) { - aHeight = height > aHeight? height : aHeight; - } - } else { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - aWidth += rect.width + mItems[i]->mGap; - if (!mItems[i]->mStretchable) { - aHeight = rect.height > aHeight? rect.height : aHeight; - } - } - } - } - aWidth += mHGap; - - if (aHeight == 0) { - aHeight = 32; - } - aHeight += (mMargin*2); - } else { - aHeight = mMargin*2; - aWidth = 0; - PRInt32 i; - for (i=0;imItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width; - PRInt32 height; - if (NS_OK == mItems[i]->mItem->GetPreferredSize(width, height)) { - aHeight += height + mItems[i]->mGap; - if (!mItems[i]->mStretchable) { - aWidth = width > aWidth? width : aWidth; - } - } else { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - aHeight += rect.height + mItems[i]->mGap; - if (!mItems[i]->mStretchable) { - aWidth = rect.width > aWidth? rect.width : aWidth; - } - } - } - } - aHeight += mHGap; - - if (aWidth == 0) { - aWidth = 32; - } - } - - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetHGap(PRInt32 aGap) -{ - mHGap = aGap; - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetVGap(PRInt32 aGap) -{ - mVGap = aGap; - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetMargin(PRInt32 aMargin) -{ - mMargin = aMargin; - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetBorderType(nsToolbarBorderType aBorderType) -{ - mBorderType = aBorderType; - return NS_OK; -} - - -//-------------------------------------------------------------------- -// -// Resize this component -// -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) -{ - nsresult result = nsWindow::Resize(aWidth, aHeight, aRepaint); - DoLayout(); - return result; -} - - -//------------------------------------------------------------------------- -// -// Resize this component -// -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::Resize(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint) -{ - nsresult result = nsWindow::Resize(aX, aY, aWidth, aHeight, aRepaint); - DoLayout(); - return result; -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::Repaint(PRBool aIsSynchronous) - -{ - Invalidate(aIsSynchronous); - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetBounds(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) -{ - return Resize(aWidth, aHeight, aRepaint); -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::SetBounds(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint) -{ - return Resize(aX, aY, aWidth, aHeight, aRepaint); -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::SetVisible(PRBool aState) -{ - nsWindow::Show(aState); - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::SetLocation(PRUint32 aX, PRUint32 aY) -{ - nsWindow::Move(aX, aY); - return NS_OK; -} - - -//------------------------------------------------------------------------- -NS_METHOD nsToolbar::IsVisible(PRBool & aState) -{ - nsWindow::IsVisible(aState); - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbar::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) -{ - nsWindow::SetPreferredSize(aWidth, aHeight); - return NS_OK; -} - -//------------------------------------------------------------------- -NS_METHOD nsToolbar::GetBounds(nsRect & aRect) -{ - nsWindow::GetBounds(aRect); - return NS_OK; -} - -//----------------------------------------------------------------------------- -nsEventStatus nsToolbar::OnPaint(nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect) -{ - nsresult res = NS_OK; - nsRect r = aDirtyRect; - - aRenderingContext.SetColor(GetBackgroundColor()); - aRenderingContext.FillRect(r); - r.width--; - - nsCOMPtr dc ( dont_AddRef(GetDeviceContext()) ); - if ( !dc ) - return nsEventStatus_eIgnore; - - nsFont titleBarFont("MS Sans Serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - 400, NS_FONT_DECORATION_NONE, - 12); - nsBasicStyleInfo styleInfo(titleBarFont); - mDataModel->GetToolbarStyle(dc, styleInfo); - - // If there is a background image, draw it. - if ( styleInfo.BackgroundImage() ) - PaintBackgroundImage(aRenderingContext, styleInfo.BackgroundImage(), r); - - if (mBorderType != eToolbarBorderType_none) - { - nsRect rect(r); - // draw top & left - aRenderingContext.SetColor(NS_RGB(255,255,255)); - aRenderingContext.DrawLine(0,0,rect.width,0); - if (mBorderType == eToolbarBorderType_full) { - aRenderingContext.DrawLine(0,0,0,rect.height); - } - - // draw bottom & right - aRenderingContext.SetColor(NS_RGB(128,128,128)); - aRenderingContext.DrawLine(0,rect.height-1,rect.width,rect.height-1); - if (mBorderType == eToolbarBorderType_full) { - aRenderingContext.DrawLine(rect.width,0,rect.width,rect.height); - } - } - - return nsEventStatus_eIgnore; -} - -//----------------------------------------------------------------------------- -nsEventStatus nsToolbar::HandleEvent(nsGUIEvent *aEvent) -{ - - if (aEvent->message == NS_PAINT) - { - nsRect r; - aEvent->widget->GetBounds(r); - r.x = 0; - r.y = 0; - nsCOMPtr drawCtx(NS_STATIC_CAST(nsPaintEvent*, aEvent)->renderingContext); - return (OnPaint(*drawCtx,r)); - } - - return nsEventStatus_eIgnore; - -} - - -//------------------------------------------------------------------- -void nsToolbar::HandleDataModelEvent(int anEvent, nsHierarchicalDataItem* pItem) -{ - Invalidate(PR_FALSE); -} - - -//------------------------------------------------------------------- -NS_METHOD nsToolbar::SetWrapping(PRBool aDoWrap) -{ - mWrapItems = aDoWrap; - return NS_OK; -} - -//------------------------------------------------------------------- -NS_METHOD nsToolbar::GetWrapping(PRBool & aDoWrap) -{ - aDoWrap = mWrapItems; - return NS_OK; -} - -//------------------------------------------------------------------- -NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight, - PRInt32& aWidth, PRInt32& aHeight) -{ - nsRect rect; - nsWindow::GetBounds(rect); - - PRInt32 rows = 1; - PRInt32 calcSize = mMargin; - PRInt32 maxSize = 0; - PRInt32 maxRowSize = 0; - PRInt32 currentSize = mMargin; // the current height of the "growing" toolbar - - PRInt32 i; - // Loop throgh each item in the toolbar - // Skip it if it is not visible - for (i=0;imItem->IsVisible(isVisible); - if (isVisible) { - PRInt32 width; - PRInt32 height; - // Get the item's Preferred width, height - if (NS_OK != mItems[i]->mItem->GetPreferredSize(width, height)) { - nsRect rect; - mItems[i]->mItem->GetBounds(rect); - width = rect.width; - height = rect.height; - } - - // If it is greater than the suggested width than add 1 to the number of rows - // and start the x over - if (mDoHorizontalLayout) { - if ((calcSize + width + mItems[i]->mGap) > aSuggestedWidth) { - currentSize += maxRowSize; - maxRowSize = 0; - calcSize = mMargin + mWrapMargin + width + mItems[i]->mGap; - } else { - calcSize += width + mItems[i]->mGap; - } - if (!mItems[i]->mStretchable) { - maxRowSize = height > maxRowSize? height : maxRowSize; - } - } else { // vertical - if (calcSize + height + mItems[i]->mGap > aSuggestedHeight) { - currentSize += maxRowSize; - maxRowSize = 0; - calcSize = mMargin; - } else { - calcSize += height + mItems[i]->mGap; - } - if (!mItems[i]->mStretchable) { - maxRowSize = width > maxRowSize? width : maxRowSize; - } - } - } // isVisible - } - - // Now set the width and height accordingly - if (mDoHorizontalLayout) { - aWidth = aSuggestedWidth; - aHeight = currentSize + mMargin + maxRowSize; - } else { - aHeight = aSuggestedHeight; - aWidth = currentSize + mMargin + maxRowSize; - } - - return NS_OK; -} - - - -// -// PaintBackgroundImage -// -// Given a rendering context and a bg image, this will tile the image across the -// background. -// NOTE: When the toolbar becomes a frame, we should get all this for free so this -// code can probably go away. -// -void -nsToolbar::PaintBackgroundImage(nsIRenderingContext& ctx, - nsIImage* bgImage, const nsRect& constraintRect, - int xSrcOffset, int ySrcOffset) -{ - // This code gets a bit intense. Will comment heavily. - - int imageWidth = bgImage->GetWidth(); // The dimensions of the background image being tiled. - int imageHeight = bgImage->GetHeight(); - - int totalWidth = constraintRect.width; // The dimensions of the space we're - int totalHeight = constraintRect.height; // drawing into. - - if (imageWidth <= 0 || imageHeight <= 0) // Don't draw anything if we don't have a sane image. - return; - - int xSize = imageWidth - xSrcOffset; // The dimensions of the actual tile we'll end - int ySize = imageHeight - ySrcOffset; // up drawing. A subset of the full BG image. - - xSize = (xSize > totalWidth) ? totalWidth : xSize; - ySize = (ySize > totalHeight) ? totalHeight : ySize; - - int rightMostPoint = constraintRect.x + constraintRect.width; // Edges of the space we're - int bottomMostPoint = constraintRect.y + constraintRect.height; // drawing into. - - int xDstOffset = constraintRect.x; // Top-left coordinates in the space where - int yDstOffset = constraintRect.y; // we'll be drawing. Where we'll place the tile. - - int initXOffset = xSrcOffset; - - // Tile vertically until we move out of the constraining rect. - while (yDstOffset < bottomMostPoint) - { - // Tile horizontally until we move out of the constraining rect. - while (xDstOffset < rightMostPoint) - { - // Draw the subimage. Pull the subimage from the larger image - // and then draw it. - ctx.DrawImage(bgImage, nsRect(xSrcOffset, ySrcOffset, xSize, ySize), - nsRect(xDstOffset, yDstOffset, xSize, ySize)); - - // The next subimage will be as much of the full BG image as can fit in the - // constraining rect. If we're at the edge, we don't draw quite as much. - xSrcOffset = 0; - xDstOffset += xSize; - xSize = (xDstOffset + imageWidth) > rightMostPoint ? imageWidth - (xDstOffset + imageWidth) + rightMostPoint : imageWidth; - } - - xSrcOffset = initXOffset; // Start of all rows will be at the same initial x offset. - xDstOffset = constraintRect.x; // Reset our x-position for drawing the next row. - xSize = (xDstOffset + imageWidth) > rightMostPoint ? rightMostPoint - xDstOffset : imageWidth; - - // Determine the height of the next row. Will be as much of the BG image - // as can fit in the constraining rect. If we're at the bottom edge, we don't - // draw quite as much. - ySrcOffset = 0; - yDstOffset += ySize; - ySize = (yDstOffset + imageHeight) > bottomMostPoint ? bottomMostPoint - yDstOffset : imageHeight; - } -} - diff --git a/widget/src/xpwidgets/nsToolbar.h b/widget/src/xpwidgets/nsToolbar.h deleted file mode 100644 index 74e89220e698..000000000000 --- a/widget/src/xpwidgets/nsToolbar.h +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsToolbar_h___ -#define nsToolbar_h___ - -#include "nsIToolbar.h" //*** not for long -#include "nsIContentConnector.h" -#include "nsWindow.h" -#include "nsIToolbarItem.h" -#include "nsDataModelWidget.h" - - -class ToolbarLayoutInfo; -class nsIImageGroup; -class nsToolbarDataModel; - - -// -// pinkerton's notes -// -// The only access to the toolbars should be through the DOM. As a result, -// we don't need a separate toolbar interface to the outside world besides the -// minimum required to be loaded by the loader (nsILoader or something). The -// |nsIToolbar| interface will probably go away soon. -// - -//------------------------------------------------------------ -class nsToolbar : public nsDataModelWidget, - public nsIToolbar, //*** not for long - public nsIContentConnector, - public nsIToolbarItem -{ -public: - nsToolbar(); - virtual ~nsToolbar(); - - NS_DECL_ISUPPORTS - - // nsIContentConnector Interface -------------------------------- - NS_IMETHOD SetContentRoot(nsIContent* pContent); - NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent); - - // nsIToolbar interface that won't be around much longer.... - NS_IMETHOD AddItem(nsIToolbarItem* anItem, PRInt32 aLeftGap, PRBool aStretchable); - NS_IMETHOD InsertItemAt(nsIToolbarItem* anItem, - PRInt32 aLeftGap, - PRBool aStretchable, - PRInt32 anIndex); - NS_IMETHOD GetItemAt(nsIToolbarItem*& anItem, PRInt32 anIndex); - NS_IMETHOD DoLayout(); - NS_IMETHOD SetHorizontalLayout(PRBool aDoHorizontalLayout); - NS_IMETHOD SetHGap(PRInt32 aGap); - NS_IMETHOD SetVGap(PRInt32 aGap); - NS_IMETHOD SetMargin(PRInt32 aMargin); - NS_IMETHOD SetLastItemIsRightJustified(const PRBool & aState); - NS_IMETHOD SetNextLastItemIsStretchy(const PRBool & aState); - NS_IMETHOD SetBorderType(nsToolbarBorderType aBorderType); - NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext, - const nsRect& aDirtyRect); - virtual void HandleDataModelEvent(int event, nsHierarchicalDataItem* pItem) ; - - // nsIToolbarItem Interface -------------------------------- - NS_IMETHOD Repaint(PRBool aIsSynchronous); - NS_IMETHOD GetBounds(nsRect &aRect); - NS_IMETHOD SetVisible(PRBool aState); - //NS_IMETHOD IsVisible(PRBool & aState); - NS_IMETHOD SetLocation(PRUint32 aX, PRUint32 aY); - NS_IMETHOD SetBounds(PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint); - NS_IMETHOD SetBounds(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint); - //NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); - NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); - - - // Overriding nsWindow & nsIToolbarItem - NS_IMETHOD IsVisible(PRBool & aIsVisible); - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); - - NS_IMETHOD Resize(PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint); - - NS_IMETHOD Resize(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint); - - NS_IMETHOD SetWrapping(PRBool aDoWrap); - NS_IMETHOD GetWrapping(PRBool & aDoWrap); - - NS_IMETHOD GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight, - PRInt32& aWidth, PRInt32& aHeight); - // Override the widget creation method - NS_IMETHOD Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData); - -protected: - void GetMargins(PRInt32 &aX, PRInt32 &aY); - void DoHorizontalLayout(const nsRect& aTBRect); - void DoVerticalLayout(const nsRect& aTBRect); - - // General function for painting a background image. - void PaintBackgroundImage(nsIRenderingContext& drawCtx, - nsIImage* bgImage, const nsRect& constraintRect, - int xSrcOffset = 0, int ySrcOffset = 0); - - //*** these should be smart pointers *** - nsToolbarDataModel* mDataModel; // The data source from which everything to draw is obtained. - - //*** This will all be stored in the DOM - ToolbarLayoutInfo ** mItems; - PRInt32 mNumItems; - - PRBool mLastItemIsRightJustified; - PRBool mNextLastItemIsStretchy; - - PRInt32 mMargin; - PRInt32 mWrapMargin; - PRInt32 mHGap; - PRInt32 mVGap; - - PRBool mBorderType; - - PRBool mWrapItems; - PRBool mDoHorizontalLayout; - -}; - -#endif /* nsToolbar_h___ */ diff --git a/widget/src/xpwidgets/nsToolbarDataModel.h b/widget/src/xpwidgets/nsToolbarDataModel.h deleted file mode 100644 index 54a3011164ab..000000000000 --- a/widget/src/xpwidgets/nsToolbarDataModel.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsToolbarDataModel_h___ -#define nsToolbarDataModel_h___ - -#include "nsHierarchicalDataModel.h" - - -//*** placeholder for style info to come later -struct nsToolbarItemStyleInfo : public nsBasicStyleInfo -{ - PRBool selectWholeLine; -/* - nscolor selectionFGColor; - nscolor selectionBGColor; - nsIImage* pSelectionBackgroundImage; - PRBool transparentSelection; - nsFont selectionFont; - - PRBool rolloverWholeLine; - nscolor rolloverFGColor; - nscolor rolloverBGColor; - nsIImage* pRolloverBackgroundImage; - PRBool transparentRollover; - nsFont rolloverFont; - - nscolor sortFGColor; - nscolor sortBGColor; - nsIImage* pSortBackgroundImage; - PRBool transparentSort; - nsFont sortFont; - - PRBool showTrigger; - PRBool leftJustifyTrigger; - PRBool showIcon; - - nsIImage* pTriggerImage; - nsIImage* pIconImage; - - nscolor showHorizontalDivider; - nscolor horizontalDividerColor; - - nscolor showVerticalDivider; - nscolor verticalDividerColor; -*/ - nsToolbarItemStyleInfo(const nsFont& aFont) - : nsBasicStyleInfo(aFont) - { - }; - -}; - - -// -// class nsToolbarDataModel -// -// An abstract API for communication with a hierarchical store of -// information that is designed to go into a toolbar widget -// -// ***right now this is just a placeholder layer so that we can insert -// ***things later. Don't fret that it doesn't contain much of anything -// - -class nsToolbarDataModel : public nsHierarchicalDataModel -{ -protected: - nsToolbarDataModel() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsToolbarDataModel() {}; - - // Style Retrievers - virtual void GetToolbarStyle(nsIDeviceContext* pContext, - nsBasicStyleInfo& styleInfo) const = 0; - -}; - -#endif /* nsToolbarDataModel_h___ */ diff --git a/widget/src/xpwidgets/nsToolbarItemHolder.cpp b/widget/src/xpwidgets/nsToolbarItemHolder.cpp deleted file mode 100644 index b901abd44e97..000000000000 --- a/widget/src/xpwidgets/nsToolbarItemHolder.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nsToolbarItemHolder.h" -#include "nsWidgetsCID.h" -#include "nsIWidget.h" -#include "nsIComponentManager.h" -#include "nsIToolbarItem.h" - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - -static NS_DEFINE_IID(kCToolbarItemHolderCID, NS_TOOLBARITEMHOLDER_CID); -static NS_DEFINE_IID(kCIToolbarItemHolderIID, NS_ITOOLBARITEMHOLDER_IID); -static NS_DEFINE_IID(kIToolbarItemHolderIID, NS_ITOOLBARITEMHOLDER_IID); - -static NS_DEFINE_IID(kCIToolbarItemIID, NS_ITOOLBARITEM_IID); - -NS_IMPL_ADDREF(nsToolbarItemHolder) -NS_IMPL_RELEASE(nsToolbarItemHolder) - -//static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); - -//-------------------------------------------------------------------- -//-- nsToolbarItemHolder Constructor -//-------------------------------------------------------------------- -nsToolbarItemHolder::nsToolbarItemHolder() : nsIToolbarItemHolder(), nsIToolbarItem() -{ - NS_INIT_REFCNT(); - -} - -//-------------------------------------------------------------------- -nsToolbarItemHolder::~nsToolbarItemHolder() -{ - -} - -//-------------------------------------------------------------------- -nsresult nsToolbarItemHolder::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); - - if (aIID.Equals(kCIToolbarItemHolderIID)) { - *aInstancePtr = (void*) (nsIToolbarItemHolder *)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kCIToolbarItemIID)) { - *aInstancePtr = (void*) (nsIToolbarItem *)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*) (this); - AddRef(); - return NS_OK; - } - return mWidget->QueryInterface(aIID, aInstancePtr); -} - - - - -//---------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::SetWidget(nsIWidget * aWidget) -{ - mWidget = aWidget; - return NS_OK; -} - - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::GetWidget(nsIWidget *&aWidget) -{ - aWidget = mWidget; - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::Repaint(PRBool aIsSynchronous) - -{ - if ( mWidget ) - mWidget->Invalidate(aIsSynchronous); - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::GetBounds(nsRect & aRect) -{ - if ( mWidget ) - mWidget->GetBounds(aRect); - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::SetBounds(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) -{ - if ( mWidget ) - mWidget->Resize(aWidth, aHeight, aRepaint); - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::SetBounds(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint) -{ - if ( mWidget ) - mWidget->Resize(aX, aY, aWidth, aHeight, aRepaint); - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::SetVisible(PRBool aState) -{ - if (mWidget) { - mWidget->Show(aState); - } - return NS_OK; -} -//------------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::IsVisible(PRBool & aState) -{ - if (mWidget) { - return mWidget->IsVisible(aState); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::SetLocation(PRUint32 aX, PRUint32 aY) -{ - if (mWidget) { - mWidget->Move(aX, aY); - } - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) -{ - if (mWidget) { - return mWidget->GetPreferredSize(aWidth, aHeight); - } - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarItemHolder::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) -{ - if (mWidget) { - return mWidget->SetPreferredSize(aWidth, aHeight); - } - return NS_OK; -} - diff --git a/widget/src/xpwidgets/nsToolbarItemHolder.h b/widget/src/xpwidgets/nsToolbarItemHolder.h deleted file mode 100644 index 741a52fbf61b..000000000000 --- a/widget/src/xpwidgets/nsToolbarItemHolder.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsToolbarItemHolder_h___ -#define nsToolbarItemHolder_h___ - -#include "nsIToolbarItemHolder.h" -#include "nsIToolbarItem.h" -#include "nsCOMPtr.h" -#include "nsIWidget.h" - -struct nsRect; - -//------------------------------------------------------------ -class nsToolbarItemHolder : public nsIToolbarItemHolder, public nsIToolbarItem - - -{ -public: - nsToolbarItemHolder(); - virtual ~nsToolbarItemHolder(); - - NS_DECL_ISUPPORTS - - // nsIToolbarItemHolder - NS_IMETHOD SetWidget(nsIWidget * aWidget); - NS_IMETHOD GetWidget(nsIWidget *&aWidget); - - // nsIToolbarItem - NS_IMETHOD Repaint(PRBool aIsSynchronous); - NS_IMETHOD GetBounds(nsRect & aRect); - NS_IMETHOD SetBounds(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint); - NS_IMETHOD SetBounds(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint); - NS_IMETHOD SetVisible(PRBool aState); - NS_IMETHOD IsVisible(PRBool & aState); - NS_IMETHOD SetLocation(PRUint32 aX, PRUint32 aY); - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); - NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); - -protected: - - nsCOMPtr mWidget; - -}; - -#endif /* nsToolbarItemHolder_h___ */ diff --git a/widget/src/xpwidgets/nsToolbarManager.cpp b/widget/src/xpwidgets/nsToolbarManager.cpp deleted file mode 100644 index c103a979bce9..000000000000 --- a/widget/src/xpwidgets/nsToolbarManager.cpp +++ /dev/null @@ -1,643 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nsIToolbar.h" -#include "nsToolbarManager.h" -#include "nsIToolbarItemHolder.h" - -#include "nsIRenderingContext.h" -#include "nsWidgetsCID.h" -#include "nsIWidget.h" -#include "nsIComponentManager.h" -#include "nsImageButton.h" - - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kCToolbarManagerCID, NS_TOOLBARMANAGER_CID); -static NS_DEFINE_IID(kCIToolbarManagerIID, NS_ITOOLBARMANAGER_IID); -static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); -static NS_DEFINE_IID(kIImageButtonIID, NS_IIMAGEBUTTON_IID); -static NS_DEFINE_IID(kImageButtonCID, NS_IMAGEBUTTON_CID); -static NS_DEFINE_IID(kIToolbarItemHolderIID, NS_ITOOLBARITEMHOLDER_IID); -static NS_DEFINE_IID(kToolbarItemHolderCID, NS_TOOLBARITEMHOLDER_CID); -static NS_DEFINE_IID(kIToolbarItemIID, NS_ITOOLBARITEM_IID); -static NS_DEFINE_IID(kIToolbarIID, NS_ITOOLBAR_IID); -static NS_DEFINE_IID(kCIImageButtonListenerIID, NS_IIMAGEBUTTONLISTENER_IID); -static NS_DEFINE_IID(kIContentConnectorIID, NS_ICONTENTCONNECTOR_IID); - - -NS_IMPL_ADDREF(nsToolbarManager) -NS_IMPL_RELEASE(nsToolbarManager) - - -// *** These values need to come from the -// images instead of being hard coded -const int EXPAND_TAB_WIDTH = 56; -const int EXPAND_TAB_HEIGHT = 10; - - -const PRInt32 kMaxNumToolbars = 32; - - -//-------------------------------------------------------------------- -//-- nsToolbarManager Constructor -//-------------------------------------------------------------------- -nsToolbarManager::nsToolbarManager() : ChildWindow(), nsIToolbarManager(), - mGrippyHilighted(kNoGrippyHilighted), mNumToolbars(0), mTabsCollapsed(0) -{ - NS_INIT_REFCNT(); - - // XXX Needs to be changed to a Vector class - mToolbars = new nsCOMPtr [kMaxNumToolbars]; -} - -//-------------------------------------------------------------------- -nsToolbarManager::~nsToolbarManager() -{ - delete [] mToolbars; -} - -//-------------------------------------------------------------------- -nsresult nsToolbarManager::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kCIToolbarManagerIID)) { - *aInstancePtr = (void*) (nsIToolbarManager *)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(kIContentConnectorIID)) { - *aInstancePtr = (void*) (nsIContentConnector *)this; - AddRef(); - return NS_OK; - } - return (ChildWindow::QueryInterface(aIID, aInstancePtr)); -} - - -// -// [static] HandleToolbarMgrEvent -// -// Static event handler function to target events to the correct widget -// -static nsEventStatus PR_CALLBACK -HandleToolbarMgrEvent ( nsGUIEvent *aEvent ) -{ - nsEventStatus result = nsEventStatus_eIgnore; - nsCOMPtr manager(aEvent->widget); - if ( manager ) - result = manager->HandleEvent(aEvent); - return result; -} - - -// -// Create -// -// Override to setup event listeners at widget creation time. -// -NS_METHOD -nsToolbarManager :: Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - nsresult answer = ChildWindow::Create(aParent, aRect, - aHandleEventFunction ? aHandleEventFunction : HandleToolbarMgrEvent, - aContext, aAppShell, aToolkit, aInitData); -#if PINK_NOT_YET_IMPLEMENTED - if (mDataModel) - mDataModel->SetDataModelListener(this); -#endif - - return answer; - -} // Create - - -// -// SetContentRoot -// -// Hook up the toolbar to the content model rooted at the given node -// -NS_METHOD -nsToolbarManager::SetContentRoot(nsIContent* pContent) -{ -#if PINK_NOT_YET_IMPLEMENTED - if (mDataModel) - mDataModel->SetContentRoot(pContent); -#endif - - return NS_OK; -} - - -// -// HandleEvent -// -// Events come from the DOM and they wind up here. Handle them. -// -nsEventStatus -nsToolbarManager::HandleEvent(nsGUIEvent *aEvent) -{ - if ( !aEvent ) - return nsEventStatus_eIgnore; - - switch ( aEvent->message ) { - case NS_PAINT: - { - nsRect r; - GetBounds(r); - r.x = 0; - r.y = 0; - - nsRect rect(r); - -// if (mDataModel) { - nsDrawingSurface ds; - nsCOMPtr ctx (NS_STATIC_CAST(nsPaintEvent*, aEvent)->renderingContext); - - ctx->CreateDrawingSurface(&r, 0, ds); - ctx->SelectOffScreenDrawingSurface(ds); - - // fill in the bg area - ctx->SetColor ( NS_RGB(0xDD,0xDD,0xDD) ); - ctx->FillRect ( rect ); - - // Paint the grippy bar for each toolbar - DrawGrippies(ctx); - - ctx->CopyOffScreenBits(ds, 0, 0, rect, NS_COPYBITS_USE_SOURCE_CLIP_REGION); - ctx->DestroyDrawingSurface(ds); -// } - } - break; - -// case NS_MOUSE_LEFT_CLICK: - case NS_MOUSE_LEFT_BUTTON_UP: - OnMouseLeftClick ( *NS_STATIC_CAST(nsMouseEvent*, aEvent) ); - break; - - case NS_MOUSE_MOVE: - OnMouseMove ( aEvent->point ); - break; - - case NS_MOUSE_EXIT: - OnMouseExit(); - break; - - default: - break; - } // switch on event - - return nsEventStatus_eIgnore; - -} // HandleEvent - - - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::AddToolbar(nsIToolbar* aToolbar) -{ - mToolbars[mNumToolbars] = aToolbar; - mTabs[mNumToolbars].mToolbar = aToolbar; // hook this toolbar up to a grippy - mTabs[mNumToolbars].mCollapsed = PR_FALSE; - mNumToolbars++; - - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anIndex) -{ - if (anIndex < 0 || anIndex > mNumToolbars-1) { - return NS_ERROR_FAILURE; - } - - // Shift them down to make room - PRInt32 i; - PRInt32 downToInx = anIndex + 1; - for (i=mNumToolbars;i>downToInx;i--) { - mToolbars[i] = mToolbars[i-1]; - } - - // Insert the new widget - mToolbars[downToInx] = aToolbar; - mTabs[downToInx].mToolbar = aToolbar; // hook this toolbar up to a grippy - mTabs[mNumToolbars].mCollapsed = PR_FALSE; - mNumToolbars++; - - return NS_OK; -} - - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::GetNumToolbars(PRInt32 & aNumToolbars) -{ - aNumToolbars = mNumToolbars; - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::GetToolbarAt(nsIToolbar*& aToolbar, PRInt32 anIndex) -{ - if (anIndex < 0 || anIndex > mNumToolbars-1) { - return NS_ERROR_FAILURE; - } - - aToolbar = mToolbars[anIndex]; - NS_ADDREF(aToolbar); - - return NS_OK; -} - - -// -// CollapseToolbar -// -// Given the tab that was clicked on, collapse its corresponding toolbar. This -// assumes that the tab is expanded. -// -void -nsToolbarManager::CollapseToolbar ( TabInfo & inTab ) -{ - nsCOMPtr widget ( inTab.mToolbar ); - if ( widget ) { - // mark the tab as collapsed. We don't actually have to set the new - // bounding rect because that will be done for us when the bars are - // relaid out. - inTab.mCollapsed = PR_TRUE; - ++mTabsCollapsed; - - // hide the toolbar - widget->Show(PR_FALSE); - - DoLayout(); - - if ( mListener ) - mListener->NotifyToolbarManagerChangedSize(this); - } - -} // CollapseToolbar - - -// -// ExpandToolbar -// -// Given the collapsed (horizontal) tab that was clicked on, expand its -// corresponding toolbar. This assumes the tab is collapsed. -// -void -nsToolbarManager::ExpandToolbar ( TabInfo & inTab ) -{ - nsCOMPtr widget ( inTab.mToolbar ); - if ( widget ) { - // mark the tab as expanded. We don't actually have to set the new - // bounding rect because that will be done for us when the bars are - // relaid out. - inTab.mCollapsed = PR_FALSE; - --mTabsCollapsed; - - // show the toolbar - widget->Show(PR_TRUE); - - DoLayout(); - - if ( mListener ) - mListener->NotifyToolbarManagerChangedSize(this); - } - -} // ExpandToolbar - - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::AddToolbarListener(nsIToolbarManagerListener * aListener) -{ - mListener = aListener; - return NS_OK; -} - - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::SetCollapseTabURLs(const nsString& aUpURL, - const nsString& aPressedURL, - const nsString& aDisabledURL, - const nsString& aRollOverURL) -{ - mCollapseUpURL = aUpURL; - mCollapsePressedURL = aPressedURL; - mCollapseDisabledURL = aDisabledURL; - mCollapseRollOverURL = aRollOverURL; - - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::GetCollapseTabURLs(nsString& aUpURL, - nsString& aPressedURL, - nsString& aDisabledURL, - nsString& aRollOverURL) -{ - aUpURL = mCollapseUpURL; - aPressedURL = mCollapsePressedURL; - aDisabledURL = mCollapseDisabledURL; - aRollOverURL = mCollapseRollOverURL; - - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::SetExpandTabURLs(const nsString& aUpURL, - const nsString& aPressedURL, - const nsString& aDisabledURL, - const nsString& aRollOverURL) -{ - mExpandUpURL = aUpURL; - mExpandPressedURL = aPressedURL; - mExpandDisabledURL = aDisabledURL; - mExpandRollOverURL = aRollOverURL; - - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::DoLayout() -{ - PRInt32 i; - PRInt32 x = 0; - PRInt32 y = 1; - - nsRect tbRect; - GetBounds(tbRect); - -const kGrippyIndent = 10; - - // First layout all the items - for (i=0;iIsVisible(visible); - if (visible) { - nsCOMPtr widget (mToolbars[i]); - if ( widget ) { - PRInt32 width = 0, height = 0; - PRBool isToolbarWrapped; - mToolbars[i]->GetWrapping(isToolbarWrapped); - if (isToolbarWrapped) - mToolbars[i]->GetPreferredConstrainedSize(tbRect.width, tbRect.height, width, height); - else - widget->GetPreferredSize(width, height); - - widget->Resize(kGrippyIndent, y, tbRect.width - kGrippyIndent, height, PR_TRUE); - mTabs[i].mBoundingRect = nsRect(0, y, 9, height); // cache the location of this grippy for hit testing - mTabs[i].mToolbarHeight = height; - - y += height; - } - } - } - - // If there are any collapsed toolbars, we need to fix up the positions of the - // tabs associated with them to lie horizontally (make them as wide as their - // corresponding toolbar is tall). - if (mTabsCollapsed > 0) { - unsigned int horiz = 0; - for ( i = 0; i < mNumToolbars; ++i ) { - if ( mTabs[i].mCollapsed ) { - mTabs[i].mBoundingRect = nsRect ( horiz, y, mTabs[i].mToolbarHeight, 9 ); - horiz += mTabs[i].mToolbarHeight; - } - } - } - - return NS_OK; -} - -//-------------------------------------------------------------------- -NS_METHOD nsToolbarManager::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) -{ - PRInt32 suggestedWidth = aWidth; - PRInt32 suggestedHeight = aHeight; - - // compute heights of all the toolbars - aWidth = 0; - aHeight = 0; - PRInt32 i; - for (i=0;iIsVisible(visible); - if (visible) { - nsCOMPtr widget ( mToolbars[i] ); - if ( widget ) { - PRBool isToolbarWrapped; - mToolbars[i]->GetWrapping(isToolbarWrapped); - if (isToolbarWrapped) { - mToolbars[i]->GetPreferredConstrainedSize(suggestedWidth, suggestedHeight, width, height); - } else { - if (NS_OK != widget->GetPreferredSize(width, height)) { - nsRect rect; - widget->GetBounds(rect); - width = rect.width; - height = rect.height; - } - } - } - aWidth = width > aWidth? width : aWidth; - aHeight += height; - } - } - - // If there are any collapsed toolbars, make the toolbox bigger by a bit to allow room - // at the bottom for the collapsed tabs - if (mTabsCollapsed > 0) - aHeight += EXPAND_TAB_HEIGHT; - - return NS_OK; -} - -//-------------------------------------------------------------------- -// -// Resize this component -// -//------------------------------------------------------------------------- -NS_METHOD nsToolbarManager::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) -{ - nsresult result = nsWindow::Resize(aWidth, aHeight, aRepaint); - DoLayout(); - return result; -} - - -//------------------------------------------------------------------------- -// -// Resize this component -// -//------------------------------------------------------------------------- -NS_METHOD nsToolbarManager::Resize(PRUint32 aX, - PRUint32 aY, - PRUint32 aWidth, - PRUint32 aHeight, - PRBool aRepaint) -{ - nsresult result = nsWindow::Resize(aX, aY, aWidth, aHeight, aRepaint); - DoLayout(); - return result; -} - - -// -// DrawGrippies -// -// Redraws all the grippies in the toolbox by iterating over each toolbar in the DOM -// and figuring out how to draw the grippies based on size/visibility information -// -void -nsToolbarManager :: DrawGrippies ( nsIRenderingContext* aContext ) const -{ -//*** THIS IS THROWAWAY CODE RIGHT NOW BECAUSE TOOLBARS WILL BE FOUND IN THE DOM - nsRect tbRect; - int y = 0; - for (int i=0;iIsVisible(visible); - if (visible) { - nsCOMPtr widget ( mToolbars[i] ); - if ( widget ) { - PRInt32 width = 0, height = 0; - PRBool isToolbarWrapped; - mToolbars[i]->GetWrapping(isToolbarWrapped); - if (isToolbarWrapped) - mToolbars[i]->GetPreferredConstrainedSize(tbRect.width, tbRect.height, width, height); - else - widget->GetPreferredSize(width, height); - - if ( ! mTabs[i].mCollapsed ) - DrawGrippy ( aContext, mTabs[i].mBoundingRect, PR_FALSE ); - - y += height; - } - } - } - -} // DrawGrippies - - -// -// DrawGrippy -// -// Draw a single grippy in the given rectangle, either with or without rollover feedback. -// -void -nsToolbarManager :: DrawGrippy ( nsIRenderingContext* aContext, const nsRect & aBoundingRect, - PRBool aDrawHilighted ) const -{ - aContext->PushState(); - - - if ( aDrawHilighted ) { - aContext->SetColor(NS_RGB(0,0,0xFF)); - } - else { - aContext->SetColor(NS_RGB(0xdd,0xdd,0xdd)); - } - - aContext->FillRect(aBoundingRect); - - PRBool clipState; - aContext->PopState(clipState); - -} // DrawGrippy - - -// -// OnMouseMove -// -// Handle mouse move events for hilighting and unhilighting the grippies -// -void -nsToolbarManager :: OnMouseMove ( nsPoint & aMouseLoc ) -{ - for ( int i = 0; i < mNumToolbars; ++i ) { - if ( mTabs[i].mBoundingRect.Contains(aMouseLoc) ) { - nsCOMPtr ctx (dont_AddRef(GetRenderingContext())); - if ( ctx ) { - if ( i != mGrippyHilighted ) { - // unhilight the old one - if ( mGrippyHilighted != kNoGrippyHilighted ) - DrawGrippy ( ctx, mTabs[mGrippyHilighted].mBoundingRect, PR_FALSE ); - - // hilight the new one and remember it - DrawGrippy ( ctx, mTabs[i].mBoundingRect, PR_TRUE ); - mGrippyHilighted = i; - } // if in a new tab - } // if we got a rendering context. - } - } // for each toolbar - -} // OnMouseMove - - -// -// OnMouseLeftClick -// -// Check if a click is in a grippy and expand/collapse appropriately. -// -void -nsToolbarManager :: OnMouseLeftClick ( nsMouseEvent & aEvent ) -{ - for ( int i = 0; i < mNumToolbars; ++i ) { - if ( mTabs[i].mBoundingRect.Contains(aEvent.point) ) { - TabInfo & clickedTab = mTabs[i]; - if ( clickedTab.mCollapsed ) - ExpandToolbar ( clickedTab ); - else - CollapseToolbar ( clickedTab ); - - // don't keep repeating this process since toolbars have now be - // relaid out and a new toolbar may be under the current mouse - // location! - break; - } - } - -} // OnMouseLeftClick - - -// -// OnMouseExit -// -// Update the grippies that may have been hilighted while the mouse was within the -// manager. -// -void -nsToolbarManager :: OnMouseExit ( ) -{ - if ( mGrippyHilighted != kNoGrippyHilighted ) { - nsCOMPtr ctx (dont_AddRef(GetRenderingContext())); - if ( ctx ) { - DrawGrippy ( ctx, mTabs[mGrippyHilighted].mBoundingRect, PR_FALSE ); - mGrippyHilighted = kNoGrippyHilighted; - } - } -} // OnMouseExit diff --git a/widget/src/xpwidgets/nsToolbarManager.h b/widget/src/xpwidgets/nsToolbarManager.h deleted file mode 100644 index 9521000c1499..000000000000 --- a/widget/src/xpwidgets/nsToolbarManager.h +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C); 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsToolbarManager_h___ -#define nsToolbarManager_h___ - -#include "nsIImageRequest.h" -#include "nsIToolbarManager.h" -#include "nsIToolbarItem.h" -#include "nsIToolbar.h" -#include "nsIToolbarManagerListener.h" // needed for VC4.2 -#include "nsIContentConnector.h" -#include "nsWindow.h" - -#include "nsCOMPtr.h" - -class nsIWidget; - -struct nsRect; - - -struct TabInfo { - TabInfo ( ) : mCollapsed(PR_TRUE), mToolbarHeight(0) { }; - - nsCOMPtr mToolbar; - nsRect mBoundingRect; - PRBool mCollapsed; - unsigned int mToolbarHeight; -}; - - -// -// pinkerton's notes -// -// The only access to the toolbars this manages should be through the DOM. As a result, -// we don't need a separate toolbar manager interface to the outside world besides the -// minimum required to be loaded by the loader (nsILoader or something). The -// |nsIToolbarManager| interface will probably go away soon. -// - - -//------------------------------------------------------------ -class nsToolbarManager : public ChildWindow, - public nsIToolbarManager, //*** for now - public nsIContentConnector -{ -public: - nsToolbarManager(); - virtual ~nsToolbarManager(); - - NS_DECL_ISUPPORTS - - // nsIContentConnector Interface -------------------------------- - NS_IMETHOD SetContentRoot(nsIContent* pContent); - NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent); - - NS_IMETHOD AddToolbar(nsIToolbar* aToolbar); - NS_IMETHOD InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anIndex); - NS_IMETHOD GetNumToolbars(PRInt32 & aNumToolbars); - NS_IMETHOD GetToolbarAt(nsIToolbar*& aToolbar, PRInt32 anIndex); - NS_IMETHOD AddToolbarListener(nsIToolbarManagerListener * aListener); - NS_IMETHOD DoLayout(); - NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); - NS_IMETHOD Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint); - NS_IMETHOD Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint); - NS_IMETHOD SetCollapseTabURLs(const nsString& aUpURL, - const nsString& aPressedURL, - const nsString& aDisabledURL, - const nsString& aRollOverURL); - NS_IMETHOD GetCollapseTabURLs(nsString& aUpURL, - nsString& aPressedURL, - nsString& aDisabledURL, - nsString& aRollOverURL); - - NS_IMETHOD SetExpandTabURLs(const nsString& aUpURL, - const nsString& aPressedURL, - const nsString& aDisabledURL, - const nsString& aRollOverURL); - - // Override the widget creation method - NS_IMETHOD Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData); - -protected: - enum { kNoGrippyHilighted = -1 } ; - - void DrawGrippies ( nsIRenderingContext* aContext ) const ; - void DrawGrippy ( nsIRenderingContext* aContext, const nsRect & aBoundingRect, - PRBool aDrawHilighted ) const ; - - void CollapseToolbar ( TabInfo & inTab ) ; - void ExpandToolbar ( TabInfo & inTab ) ; - - void OnMouseMove ( nsPoint & aMouseLoc ) ; - void OnMouseExit ( ) ; - void OnMouseLeftClick ( nsMouseEvent & aEvent ) ; - - nsCOMPtr mListener; - - //*** this should be smart pointers *** -//nsToolbarDataModel* mDataModel; // The data source from which everything to draw is obtained. - - // CollapseTab URLs - nsString mCollapseUpURL; - nsString mCollapsePressedURL; - nsString mCollapseDisabledURL; - nsString mCollapseRollOverURL; - - // Expand Tab URLs - nsString mExpandUpURL; - nsString mExpandPressedURL; - nsString mExpandDisabledURL; - nsString mExpandRollOverURL; - - // XXX these will be changed to Vectors - nsCOMPtr * mToolbars; - PRInt32 mNumToolbars; - - TabInfo mTabs[10]; - int mGrippyHilighted; // used to indicate which grippy the mouse is inside - int mTabsCollapsed; // how many tabs are collapsed? - - // Images for the pieces of the grippy panes. They are composites of a set of urls - // which specify the top, middle, and bottom of the grippy. - //*** should these be in an imageGroup? - nsCOMPtr mGrippyNormalTop; // Image for grippy in normal state - nsCOMPtr mGrippyNormalMiddle; // Image for grippy in normal state - nsCOMPtr mGrippyNormalBottom; // Image for grippy in normal state - - nsCOMPtr mGrippyRolloverTop; // image for grippy in rollover state - nsCOMPtr mGrippyRolloverMiddle; // image for grippy in rollover state - nsCOMPtr mGrippyRolloverBottom; // image for grippy in rollover state - -}; // class nsToolbarManager - -#endif /* nsToolbarManager_h___ */ diff --git a/widget/src/xpwidgets/nsTreeColumn.h b/widget/src/xpwidgets/nsTreeColumn.h deleted file mode 100644 index 134d24466c2e..000000000000 --- a/widget/src/xpwidgets/nsTreeColumn.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsTreeColumn_h___ -#define nsTreeColumn_h___ - -class nsTreeColumn - -{ -protected: - nsTreeColumn() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsTreeColumn() {}; - - // Inspectors - virtual int GetPixelWidth() const = 0; - virtual double GetDesiredPercentage() const = 0; - virtual PRBool IsSortColumn() const = 0; - virtual void GetColumnName(nsString& name) const = 0; - virtual void GetColumnDisplayText(nsString& displayText) const = 0; - - // Setters - virtual void SetPixelWidth(int newWidth) = 0; - virtual void SetDesiredPercentage(double newPercentage) = 0; - -}; - -#endif /* nsTreeColumn_h___ */ diff --git a/widget/src/xpwidgets/nsTreeControlStripItem.h b/widget/src/xpwidgets/nsTreeControlStripItem.h deleted file mode 100644 index 8d5fddb075b3..000000000000 --- a/widget/src/xpwidgets/nsTreeControlStripItem.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsTreeControlStripItem_h___ -#define nsTreeControlStripItem_h___ - -class nsTreeControlStripItem - -{ -protected: - nsTreeControlStripItem() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsTreeControlStripItem() {}; - - virtual void GetText(nsString& text) const = 0; -}; - -#endif /* nsTreeControlStripItem_h___ */ diff --git a/widget/src/xpwidgets/nsTreeDataModel.h b/widget/src/xpwidgets/nsTreeDataModel.h deleted file mode 100644 index 991862481534..000000000000 --- a/widget/src/xpwidgets/nsTreeDataModel.h +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsTreeDataModel_h___ -#define nsTreeDataModel_h___ - -#include "nsHierarchicalDataModel.h" - -class nsTreeItem; -class nsTreeColumn; -class nsTreeControlStripItem; - -struct nsColumnHeaderStyleInfo: public nsBasicStyleInfo -{ - nscolor sortFGColor; - nscolor sortBGColor; - nsIImage* pSortBackgroundImage; - PRBool transparentSort; - nsFont sortFont; - - nscolor disabledColor; // Used for the pushers. - - nsColumnHeaderStyleInfo(const nsFont& aFont) - :nsBasicStyleInfo(aFont), sortFont(aFont) - { pSortBackgroundImage = nsnull; }; -}; - -struct nsTreeItemStyleInfo: public nsBasicStyleInfo -{ - PRBool selectWholeLine; - nscolor selectionFGColor; - nscolor selectionBGColor; - nsIImage* pSelectionBackgroundImage; - PRBool transparentSelection; - nsFont selectionFont; - - PRBool rolloverWholeLine; - nscolor rolloverFGColor; - nscolor rolloverBGColor; - nsIImage* pRolloverBackgroundImage; - PRBool transparentRollover; - nsFont rolloverFont; - - nscolor sortFGColor; - nscolor sortBGColor; - nsIImage* pSortBackgroundImage; - PRBool transparentSort; - nsFont sortFont; - - PRBool showTrigger; - PRBool leftJustifyTrigger; - PRBool showIcon; - - nsIImage* pTriggerImage; - nsIImage* pIconImage; - - nscolor showHorizontalDivider; - nscolor horizontalDividerColor; - - nscolor showVerticalDivider; - nscolor verticalDividerColor; - - nsTreeItemStyleInfo(const nsFont& aFont) - :nsBasicStyleInfo(aFont), sortFont(aFont), selectionFont(aFont), rolloverFont(aFont) - { - pSelectionBackgroundImage = pSortBackgroundImage = - pTriggerImage = pIconImage = nsnull; - }; -}; - -//------------------------------------------------------------ -// An abstract API for communication with a hierarchical store of -// information that is designed to go into a tree widget (a widget -// with tree lines and multiple columns). -//------------------------------------------------------------ - -class nsTreeDataModel : public nsHierarchicalDataModel - -{ -protected: - nsTreeDataModel() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsTreeDataModel() {}; - - // Column APIs - virtual PRUint32 GetVisibleColumnCount() const = 0; - virtual PRUint32 GetColumnCount() const = 0; - virtual nsTreeColumn* GetNthColumn(PRUint32 n) const = 0; - virtual void SetVisibleColumnCount(PRUint32 n) = 0; - - // Control Strip Iteration - virtual PRUint32 GetControlStripItemCount() const = 0; - virtual nsTreeControlStripItem* GetNthControlStripItem(PRUint32 n) const = 0; - virtual void GetControlStripCloseText(nsString& closeText) const = 0; - - // Visibility Queries - virtual PRBool ShowTitleBar() const = 0; - virtual PRBool ShowTitleBarText() const = 0; - virtual PRBool ShowColumnHeaders() const = 0; - virtual PRBool ShowControlStrip() const = 0; - - // Style Retrievers - virtual void GetTitleBarStyle(nsIDeviceContext* pContext, - nsBasicStyleInfo& styleInfo) const = 0; - virtual void GetColumnHeaderStyle(nsIDeviceContext* pContext, - nsColumnHeaderStyleInfo& styleInfo) const = 0; - virtual void GetControlStripStyle(nsIDeviceContext* pContext, - nsBasicStyleInfo& styleInfo) const = 0; - - // Selection - virtual PRInt32 GetSelectedColumnIndex() const = 0; - virtual void SetSelectedColumnIndex(PRInt32 n) = 0; - - // Text for the title bar - virtual void GetTitleBarText(nsString& text) const = 0; -}; - -#endif /* nsTreeDataModel_h___ */ diff --git a/widget/src/xpwidgets/nsTreeItem.h b/widget/src/xpwidgets/nsTreeItem.h deleted file mode 100644 index 7e0a0cd1f84c..000000000000 --- a/widget/src/xpwidgets/nsTreeItem.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsTreeItem_h___ -#define nsTreeItem_h___ - -class nsTreeColumn; -class nsIDeviceContext; -class nsIImage; - -#include "nsColor.h" -#include "nsFont.h" -#include "nsTreeDataModel.h" - -//------------------------------------------------------------ -// A single item in a hierarchical data model for a tree widget -// with columns. -//------------------------------------------------------------ - -#include "nsHierarchicalDataItem.h" - -class nsTreeItem : public nsHierarchicalDataItem - -{ -protected: - nsTreeItem() {}; // Disallow instantiation of abstract class. - -public: - virtual ~nsTreeItem() {}; - - virtual void GetItemStyle(nsIDeviceContext* dc, - nsTreeItemStyleInfo& styleInfo) const = 0; - - virtual void GetTextForColumn(nsTreeColumn* pColumn, nsString& nodeText) const = 0; - - virtual void GetTreeItemRectangle(nsRect& rect) const = 0; - virtual void SetTreeItemRectangle(const nsRect& rect) = 0; - virtual void GetTriggerRectangle(nsRect& rect) const = 0; - virtual void SetTriggerRectangle(const nsRect& rect) = 0; - virtual void GetContentRectangle(nsRect& rect, PRUint32 n) const = 0; - virtual void SetContentRectangle(const nsRect& rect, PRUint32 n) = 0; -}; - -#endif /* nsTreeItem_h___ */ diff --git a/widget/src/xpwidgets/nsTreeView.cpp b/widget/src/xpwidgets/nsTreeView.cpp deleted file mode 100644 index 436319bb3cea..000000000000 --- a/widget/src/xpwidgets/nsTreeView.cpp +++ /dev/null @@ -1,1251 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#include "nspr.h" -#include "nsString.h" -#include "nsIComponentManager.h" -#include "nsFont.h" -#include "nsIFontMetrics.h" -#include "nsIDeviceContext.h" -#include "nsIImageGroup.h" -#include "nsIImage.h" -#include "nsTreeView.h" -#include "nsHTTreeDataModel.h" - -static NS_DEFINE_IID(kIContentConnectorIID, NS_ICONTENTCONNECTOR_IID); - -NS_IMPL_ADDREF(nsTreeView) -NS_IMPL_RELEASE(nsTreeView) - -static nsEventStatus PR_CALLBACK -HandleTreeEvent(nsGUIEvent *aEvent) -{ - nsEventStatus result = nsEventStatus_eIgnore; - nsIContentConnector * tree; - if (NS_OK == aEvent->widget->QueryInterface(kIContentConnectorIID,(void**)&tree)) { - result = tree->HandleEvent(aEvent); - NS_RELEASE(tree); - } - return result; -} - -NS_METHOD nsTreeView::Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData) -{ - nsresult answer = ChildWindow::Create(aParent, aRect, - nsnull != aHandleEventFunction ? aHandleEventFunction : HandleTreeEvent, - aContext, aAppShell, aToolkit, aInitData); - - if (mDataModel) - mDataModel->SetDataModelListener(this); - - return answer; -} - -nsTreeView::nsTreeView() : nsIContentConnector(), nsDataModelWidget() -{ - NS_INIT_REFCNT(); - mDataModel = nsnull; - mMouseDown = PR_FALSE; - mMouseDragging = PR_FALSE; - mDraggingColumnHeader = PR_FALSE; - mDraggingColumnEdge = PR_FALSE; - mLastXPosition = 0; - mMousedColumnIndex = 0; - - // The data model is created and bound to the widget. - mDataModel = new nsHTTreeDataModel(); -} - -//-------------------------------------------------------------------- -nsTreeView::~nsTreeView() -{ - // The tree has the responsibility of deleting the data model. - delete mDataModel; -} - -// ISupports Implementation -------------------------------------------------------------------- -nsresult nsTreeView::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kIContentConnectorIID)) { - *aInstancePtr = (void*) (nsIContentConnector *)this; - AddRef(); - return NS_OK; - } - return (nsWindow::QueryInterface(aIID, aInstancePtr)); -} - -NS_METHOD nsTreeView::SetContentRoot(nsIContent* pContent) -{ - if (mDataModel) - { - mDataModel->SetContentRoot(pContent); - } - - return NS_OK; -} - -void nsTreeView::HandleDataModelEvent(int anEvent, nsHierarchicalDataItem* pItem) -{ - Invalidate(PR_FALSE); -} - -//----------------------------------------------------- -nsEventStatus nsTreeView::HandleEvent(nsGUIEvent *aEvent) -{ - if (aEvent->message == NS_SIZE) - { - nsRect r; - aEvent->widget->GetBounds(r); - - // Adjust our column headers' positions. - ResizeColumns(r.width); - - // Do a repaint. - if (mTitleBarRect.width != r.width) - aEvent->widget->Invalidate(PR_FALSE); - } - else if (aEvent->message == NS_PAINT) - { - nsRect r; - aEvent->widget->GetBounds(r); - r.x = 0; - r.y = 0; - - nsRect rect(r); - - nsDrawingSurface ds; - nsIRenderingContext * ctx = ((nsPaintEvent*)aEvent)->renderingContext; - - ctx->CreateDrawingSurface(&r, 0, ds); - ctx->SelectOffScreenDrawingSurface(ds); - - if (mDataModel) - { - // Paint the title bar. - PaintTitleBar(ctx, r); - - // Paint the control strip. - PaintControlStrip(ctx, r); - - // Paint the column bar. - PaintColumnBar(ctx, r); - - // Paint the tree. - PaintTreeRows(ctx, r); - } - ctx->CopyOffScreenBits(ds, 0, 0, rect, NS_COPYBITS_USE_SOURCE_CLIP_REGION); - ctx->DestroyDrawingSurface(ds); - } - else if (aEvent->message == NS_MOUSE_EXIT) - { - aEvent->widget->Invalidate(PR_FALSE); // Makes sure we ditch rollover feedback on exit. - } - else if (aEvent->message == NS_MOUSE_MOVE) - { - HandleMouseMove(aEvent); - } - else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) - { - mCachedDownPoint.x = aEvent->point.x; - mCachedDownPoint.y = aEvent->point.y; - - mMouseDown = PR_TRUE; // We could potentially initiate a drag. Don't kick it off until - // we know for sure. - } - else if (aEvent->message == NS_MOUSE_LEFT_BUTTON_UP) - { - HandleMouseUp(aEvent); - } - return nsEventStatus_eIgnore; -} - -void nsTreeView::HandleMouseMove(nsGUIEvent* aEvent) -{ - // Remember our point for easy reference. - mCachedMovePoint.x = aEvent->point.x; - mCachedMovePoint.y = aEvent->point.y; - - if (mMouseDown) - { - // The user has the left mouse button down. - if (!mMouseDragging) - { - // We have the left mouse button down and we're moving. Check to see if we should - // initiate a drag and drop operation. - if (mCachedMovePoint.x < mCachedDownPoint.x - 3 || - mCachedMovePoint.x > mCachedDownPoint.x + 3 || - mCachedMovePoint.y < mCachedDownPoint.y - 3 || - mCachedMovePoint.y > mCachedDownPoint.y + 3) - { - // We're dragging baby. - mMouseDragging = PR_TRUE; - - // Question is, just what are we dragging? - if (mColumnBarRect.Contains(mCachedDownPoint.x, mCachedDownPoint.y)) - { - // The user is messing with the columns. Either a column header - // is being resized or a column is being dragged. - if (DownOnColumnEdge(mCachedDownPoint)) - { - mDraggingColumnEdge = PR_TRUE; - mLastXPosition = mCachedDownPoint.x; - DragColumnEdge(mCachedMovePoint.x); - } - } - else if (mTreeRect.Contains(mCachedDownPoint.x, mCachedDownPoint.y)) - { - // The user is dragging a tree item - } - } - } - else - { - // The user is dragging. - if (mDraggingColumnEdge) - { - // Keep on dragging. - DragColumnEdge(mCachedMovePoint.x); - } - // Will add code for dragging column headers and tree items here. - } - } - else - { - // The user doesn't have a mouse down. Just rolling over items. - aEvent->widget->Invalidate(PR_FALSE); - - if (mColumnBarRect.Contains(mCachedMovePoint.x, mCachedMovePoint.y) && - DownOnColumnEdge(mCachedMovePoint)) - { - // Change the cursor to a WE resize if on a column edge. - aEvent->widget->SetCursor(eCursor_sizeWE); - } - else aEvent->widget->SetCursor(eCursor_standard); - } -} - -void nsTreeView::HandleMouseUp(nsGUIEvent* aEvent) -{ - if (mMouseDown) - { - mCachedMovePoint.x = aEvent->point.x; - mCachedMovePoint.y = aEvent->point.y; - - mMouseDown = PR_FALSE; - mMouseDragging = PR_FALSE; - - if (mDraggingColumnEdge) - { - // Finish up. - DragColumnEdge(mCachedMovePoint.x); - - RecomputeColumnPercentages(); - - mDraggingColumnEdge = PR_FALSE; - } - - if (mColumnBarRect.Contains(mCachedMovePoint.x, mCachedMovePoint.y) && - mColumnBarRect.Contains(mCachedDownPoint.x, mCachedDownPoint.y)) - { - int currentPosition = 0; - int remainingSpace = mColumnBarRect.width; - int totalSpace = mColumnBarRect.width; - PRUint32 count = mDataModel->GetVisibleColumnCount(); - - // The user boinked a column or a pusher. Figure out which. - for (PRUint32 n = 0; n < count; n++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(n); - if (pColumn) { - int pixelWidth = pColumn->GetPixelWidth(); - remainingSpace -= pixelWidth; - currentPosition += pixelWidth; - - // TODO: See if we hit this column header - if (mCachedMovePoint.x < currentPosition) - { - // We hit this column header. - return; - } - } - } - - // Must have hit a pusher - if (mCachedMovePoint.x < (currentPosition + (remainingSpace / 2))) - ShowColumn(); // Hit the left pusher - else HideColumn(); // Hit the right pusher - } - else if (mTreeRect.Contains(mCachedMovePoint.x, mCachedMovePoint.y) && - mTreeRect.Contains(mCachedDownPoint.x, mCachedDownPoint.y)) - { - // The user clicked on a location in the tree. - // Determine the click location. Can be one of three things: - // The background of the tree view, the trigger for a node, - // or the text in a specific column. - PRUint32 row, column; - nsHitLocation type; - DetermineHitLocation(mCachedMovePoint, row, column, type); - - // If the user clicked the trigger, then we need to open or close the node. - if (type == eTriggerHit) - { - nsHierarchicalDataItem* pItem = mDataModel->GetNthItem(row); - if (pItem) pItem->ToggleOpenState(); - } - else if (type == eContentHit) - { - // The user clicked on content (a text or icon). Select it. - nsHierarchicalDataItem* pItem = mDataModel->GetNthItem(row); - mDataModel->SetSelection(pItem); - mDataModel->SetSelectedColumnIndex(column); - - // TODO: REMOVE THIS! - Invalidate(PR_FALSE); - } - else - { - // The user clicked on the background. Deselect all items. - } - } - } -} - -void nsTreeView::DetermineHitLocation(const nsPoint& point, - PRUint32& row, PRUint32& column, nsHitLocation& location) -{ - int yPosition = mTreeRect.y; - PRUint32 n = mDataModel->GetFirstVisibleItemIndex(); - nsTreeItem* pItem = (nsTreeItem*)mDataModel->GetNthItem(n); - - while (pItem && yPosition < mTreeRect.y + mTreeRect.height) - { - // Retrieve our cached rectangle data for the item. - nsRect rowRect, triggerRect, contentRect; - pItem->GetTreeItemRectangle(rowRect); - pItem->GetTriggerRectangle(triggerRect); - - if (rowRect.Contains(point.x, point.y)) - { - row = n; - - // Determine which column we hit. - PRUint32 count = mDataModel->GetVisibleColumnCount(); - int currentPosition = 0; - for (PRUint32 m = 0; m < count; m++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(m); - if (pColumn) - { - // Retrieve the column's current pixel width. - int pixelWidth = pColumn->GetPixelWidth(); - if (point.x >= currentPosition && point.x < currentPosition+pixelWidth) - { - // The user hit this column. - column = m; - - // Now we need to determine what the user clicked on. - pItem->GetContentRectangle(contentRect, m); - - if (triggerRect.Contains(point.x, point.y)) - { - location = eTriggerHit; - } - else if (contentRect.Contains(point.x, point.y)) - { - location = eContentHit; - } - else - { - // See if we hit the text rectangle. - location = eBackgroundHit; - } - - return; - } - // Augment our current position - currentPosition += pixelWidth; - } - } - } - - n++; - pItem = (nsTreeItem*)mDataModel->GetNthItem(n); - } -} - -void nsTreeView::PaintTitleBar(nsIRenderingContext* drawCtx, - nsRect& rect) -{ - mTitleBarRect.SetRect(0,0,0,0); - if (mDataModel) // There is no title bar shown unless we have a valid data model to query. - { - nsRect titleBarRect(rect); - int titleBarHeight = 0; - int fontHeight = 0; - - if (mDataModel->ShowTitleBar()) - { - titleBarHeight = 30; // Assume an initial height of 30. Change if font doesn't fit. - nsIDeviceContext* dc = GetDeviceContext(); - float t2d; - dc->GetTwipsToDevUnits(t2d); - - // Need to figure out our style info for the title bar. - nsFont titleBarFont("MS Sans Serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - 400, NS_FONT_DECORATION_NONE, - nscoord(t2d * NSIntPointsToTwips(10))); - - nsBasicStyleInfo styleInfo(titleBarFont); - - mDataModel->GetTitleBarStyle(dc, styleInfo); - - NS_RELEASE(dc); - drawCtx->SetFont(styleInfo.font); - nsIFontMetrics* fontMetrics; - drawCtx->GetFontMetrics(fontMetrics); - fontMetrics->GetHeight(fontHeight); - titleBarHeight = fontHeight + 4; // Pad just a little. - NS_RELEASE(fontMetrics); - - // Modify the rect we'll be returning for future painting. - titleBarRect.height = titleBarHeight; - rect.y = titleBarRect.height; - rect.height -= titleBarRect.height; - mTitleBarRect = titleBarRect; - - // First we lay down the background, and then we draw the text. - drawCtx->SetColor(styleInfo.backgroundColor); - drawCtx->FillRect(titleBarRect); - - // If there is a background image, draw it. - if (styleInfo.pBackgroundImage) - PaintBackgroundImage(drawCtx, styleInfo.pBackgroundImage, mTitleBarRect); - - if (mDataModel->ShowTitleBarText()) // Only show the text if we should. - { - drawCtx->SetColor(styleInfo.foregroundColor); - nsString titleBarText; - mDataModel->GetTitleBarText(titleBarText); - DrawCroppedString(drawCtx, titleBarText, mTitleBarRect); - } - } - } -} - -void nsTreeView::PaintControlStrip(nsIRenderingContext* drawCtx, - nsRect& rect) -{ - // Paint the add box, the edit box, and the close box. - mControlStripRect.SetRect(0,0,0,0); - if (mDataModel) // There is no title bar shown unless we have a valid data source to query. - { - nsRect controlStripRect(rect); - int controlStripHeight = 0; // Assume an initial height of 0. - int fontHeight = 0; - nsIDeviceContext* dc = GetDeviceContext(); - - if (mDataModel->ShowControlStrip()) - { - // Need to figure out which font we're using for the control strip - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont controlStripFont("MS Sans Serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - 400, NS_FONT_DECORATION_NONE, - nscoord(t2d * NSIntPointsToTwips(10))); - - nsBasicStyleInfo styleInfo(controlStripFont); - mDataModel->GetControlStripStyle(dc, styleInfo); - - NS_RELEASE(dc); - - drawCtx->SetFont(styleInfo.font); - nsIFontMetrics* fontMetrics; - drawCtx->GetFontMetrics(fontMetrics); - fontMetrics->GetHeight(fontHeight); - controlStripHeight = fontHeight + 4; // Pad just a little. - NS_RELEASE(fontMetrics); - - // Modify the rect we'll be returning for future painting. - controlStripRect.height = controlStripHeight; - rect.y += controlStripRect.height; - rect.height -= controlStripRect.height; - mControlStripRect = controlStripRect; - - // We now know the size of the control strip. Retrieve the color information. - - // First we lay down the background, and then we draw the text. - drawCtx->SetColor(styleInfo.backgroundColor); - drawCtx->FillRect(controlStripRect); - - // If there is a background image, draw it. - if (styleInfo.pBackgroundImage) - PaintBackgroundImage(drawCtx, styleInfo.pBackgroundImage, mControlStripRect); - - drawCtx->SetColor(styleInfo.foregroundColor); - - // Iterate over the control strip items. - PRUint32 itemCount = mDataModel->GetControlStripItemCount(); - int xOffset = 2; - for (PRUint32 i = 0; i < itemCount; i++) - { - nsTreeControlStripItem* pItem = mDataModel->GetNthControlStripItem(i); - nsString itemText; - pItem->GetText(itemText); - - drawCtx->DrawString(itemText, xOffset, controlStripRect.y + 2); // Indent slightly - - // Offset by the width of the text + 10. - int strWidth = 0; - drawCtx->GetWidth(itemText, strWidth); - - nsRect itemRect(xOffset-2, controlStripRect.y, - strWidth + 4, controlStripRect.height); - - xOffset += strWidth + 10; - - if (itemRect.Contains(mCachedMovePoint.x, mCachedMovePoint.y)) - drawCtx->DrawRect(itemRect); - } - - // Draw the close text at the rightmost side of the tree. - nsString nsCloseText; - mDataModel->GetControlStripCloseText(nsCloseText); - int strWidth = 0; - drawCtx->GetWidth(nsCloseText, strWidth); - drawCtx->DrawString(nsCloseText, controlStripRect.width - strWidth - 2, - controlStripRect.y + 2); - nsRect closeRect = nsRect(controlStripRect.width - strWidth - 4, - controlStripRect.y, - strWidth + 4, - controlStripRect.height); - - if (closeRect.Contains(mCachedMovePoint.x, mCachedMovePoint.y)) - drawCtx->DrawRect(closeRect); - } - } -} - -void nsTreeView::PaintColumnBar(nsIRenderingContext* drawCtx, - nsRect& rect) -{ - // The painting of the column headers along with the pushers. - if (mDataModel) - { - // The very first step is to find out exactly how tall the column - // bar needs to be given the font being used. - - PRBool needToResizeColumns = FALSE; - if (mDataModel->ShowColumnHeaders() && mColumnBarRect == nsRect(0,0,0,0)) - { - // Column sizes haven't been properly computed yet. Let's make - // sure we're sane. - needToResizeColumns = PR_TRUE; - } - - mColumnBarRect.SetRect(0,0,0,0); - - nsRect columnBarRect(rect); - int columnBarHeight = 0; // Assume an initial height of 0. - int fontHeight = 0; - - if (mDataModel->ShowColumnHeaders()) // Default assumption is that we show it. - { - // Need to figure out our style info. - nsIDeviceContext* dc = GetDeviceContext(); - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont columnHeaderFont("MS Sans Serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - 400, NS_FONT_DECORATION_NONE, - nscoord(t2d * NSIntPointsToTwips(10))); - - nsColumnHeaderStyleInfo styleInfo(columnHeaderFont); - mDataModel->GetColumnHeaderStyle(dc, styleInfo); - - NS_RELEASE(dc); - drawCtx->SetFont(styleInfo.font); - nsIFontMetrics* fontMetrics; - drawCtx->GetFontMetrics(fontMetrics); - fontMetrics->GetHeight(fontHeight); - columnBarHeight = fontHeight + 4; // Pad just a little. - NS_RELEASE(fontMetrics); - - // Modify the rect we'll be returning for future painting. - columnBarRect.height = columnBarHeight; - rect.y += columnBarRect.height; - rect.height -= columnBarRect.height; - mColumnBarRect = columnBarRect; - - // We now know the size of the column bar - // If our size info was screwy before, let's sync it up now. - // Don't move this. Code ordering is critical here. - if (needToResizeColumns) - ResizeColumns(columnBarRect.width); - - // First we lay down the background color and image if there is one - drawCtx->SetColor(styleInfo.backgroundColor); - drawCtx->FillRect(mColumnBarRect); - // If there is a background image, draw it. - if (styleInfo.pBackgroundImage) - PaintBackgroundImage(drawCtx, styleInfo.pBackgroundImage, - mColumnBarRect); - - // Draw the columns. - PRUint32 count = mDataModel->GetVisibleColumnCount(); - PRUint32 currentPosition = 0; - for (PRUint32 n = 0; n < count; n++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(n); - if (pColumn) - { - PaintColumnHeader(drawCtx, pColumn, currentPosition, - styleInfo); - } - } - - // Draw the column pushers - int pusherWidth = (int)(mColumnBarRect.height * 1.25); - if (pusherWidth%2 != 0) - pusherWidth++; - int singlePusher = pusherWidth / 2; - - drawCtx->SetColor(styleInfo.foregroundColor); - drawCtx->DrawRect(currentPosition-1, mColumnBarRect.y, - singlePusher+1, mColumnBarRect.height); - - drawCtx->DrawRect(currentPosition+singlePusher-1, - mColumnBarRect.y, singlePusher+1, - mColumnBarRect.height); - - // Are our pushers enabled or disabled? - PRUint32 visColumns = mDataModel->GetVisibleColumnCount(); - PRUint32 totalColumns = mDataModel->GetColumnCount(); - - // Left pusher - PRBool enabled = PR_TRUE; - if (visColumns == totalColumns) - enabled = PR_FALSE; - if (enabled) - drawCtx->SetColor(styleInfo.foregroundColor); - else drawCtx->SetColor(styleInfo.disabledColor); - PaintPusherArrow(drawCtx, PR_TRUE, currentPosition, singlePusher); - - // Right pusher - enabled = PR_TRUE; - if (visColumns<=1) - enabled = PR_FALSE; - if (enabled) - drawCtx->SetColor(styleInfo.foregroundColor); - else drawCtx->SetColor(styleInfo.disabledColor); - PaintPusherArrow(drawCtx, PR_FALSE, currentPosition+singlePusher, singlePusher); - } - } -} - -void nsTreeView::PaintColumnHeader(nsIRenderingContext* drawCtx, - nsTreeColumn* pColumn, - PRUint32& currentPosition, - const nsColumnHeaderStyleInfo& styleInfo) -{ - // If we're sorted, then fill with a sort column header color. - PRBool isSortColumn = pColumn->IsSortColumn(); - if (isSortColumn) - drawCtx->SetColor(styleInfo.sortBGColor); - else drawCtx->SetColor(styleInfo.backgroundColor); - - // Compute this column's rectangle. - int pixelWidth = pColumn->GetPixelWidth(); - nsRect colRect(currentPosition, mColumnBarRect.y, pixelWidth, mColumnBarRect.height); - - // Set to foreground color to draw the framing rect and text. - if (isSortColumn) - drawCtx->SetColor(styleInfo.sortFGColor); - else drawCtx->SetColor(styleInfo.foregroundColor); - - // Draw the frame rect. - colRect.x--; // The next two lines assure that there's no ugly left border on the first column - // and that the borderlines of each column header overlap. - colRect.width++; - drawCtx->DrawRect(colRect); - - // Now draw the text. - nsString columnName("Name"); - pColumn->GetColumnDisplayText(columnName); - - colRect.x++; - colRect.width--; - DrawCroppedString(drawCtx, columnName, colRect); - - if (isSortColumn) - { - // TODO: Now draw the sort indicator (up or down arrow) as needed. - } - - // Update the current position for the next column. - currentPosition += pixelWidth; -} - -void nsTreeView::PaintPusherArrow(nsIRenderingContext* drawCtx, - PRBool isLeftArrow, int left, int width) -{ - int horStart; - int horEnd; - int change; - if (isLeftArrow) - { - horStart = left+3; - horEnd = left+width-5; - change = 1; - } - else - { - horStart = left+width-5; - horEnd = left+3; - change = -1; - } - - int lineHeight = 0; - for (int i = horStart; i != horEnd; i += change, lineHeight += 2) - { - int vertStart = mColumnBarRect.y + (mColumnBarRect.height - lineHeight)/2; - int vertEnd = vertStart + lineHeight; - - if (vertStart < mColumnBarRect.y + 2) - break; - - drawCtx->DrawLine(i, vertStart, i, vertEnd); - } -} - -void nsTreeView::PaintTreeRows(nsIRenderingContext* drawCtx, - nsRect& rect) -{ - // The fun part. Painting of the individual lines of the tree. - - // Start at the top line, getting the hint for what the top line is - // from the data model.. Let each line paint itself and update its - // position so that the next line knows where to begin. Stop when you run out of lines - // or when you're dealing with lines that are no longer visible. - if (!mDataModel) - return; - - int yPosition = rect.y; - mTreeRect = rect; - - PRUint32 n = mDataModel->GetFirstVisibleItemIndex(); - nsTreeItem* pItem = (nsTreeItem*)mDataModel->GetNthItem(n); - - while (pItem && yPosition < rect.y + rect.height) - { - PaintTreeRow(drawCtx, pItem, yPosition); - n++; - pItem = (nsTreeItem*)mDataModel->GetNthItem(n); - } - - if (yPosition < rect.y + rect.height) - { - // Fill the remaining area. TODO: Account for sort highlighting - nsRect remainderRect(0, yPosition, rect.width, rect.height); - nscolor viewBGColor = NS_RGB(240,240,240); - drawCtx->SetColor(viewBGColor); - drawCtx->FillRect(remainderRect); - } -} - -void nsTreeView::PaintTreeRow(nsIRenderingContext* drawCtx, nsTreeItem* pItem, int& yPosition) -{ - // Determine the height of this tree line. It is going to be the max of - // three objects: the trigger image, the icon, and the font height. - // Will take whichever of these three is the largest, and we will add on 5 pixels. - // 4 pixels of padding, and 1 pixel for the horizontal divider line. - // Need to figure out which font we're using for the title bar. - nsIDeviceContext* dc = GetDeviceContext(); - float t2d; - dc->GetTwipsToDevUnits(t2d); - nsFont treeItemFont("MS Sans Serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, - 400, NS_FONT_DECORATION_NONE, - nscoord(t2d * NSIntPointsToTwips(10))); - nsTreeItemStyleInfo styleInfo(treeItemFont); - - pItem->GetItemStyle(dc, styleInfo); - - int lineHeight = 19; - int fontHeight = 0; - - NS_RELEASE(dc); - drawCtx->SetFont(styleInfo.font); - nsIFontMetrics* fontMetrics; - drawCtx->GetFontMetrics(fontMetrics); - fontMetrics->GetHeight(fontHeight); - - int fontWithPadding = fontHeight + 4; - - int triggerHeight = 0; - int iconHeight = 0; - nsIImage* pTriggerImage = styleInfo.pTriggerImage; - nsIImage* pIconImage = styleInfo.pIconImage; - PRBool showTrigger = styleInfo.showTrigger; - PRBool leftJustifyTrigger = styleInfo.leftJustifyTrigger; - PRBool showIcon = styleInfo.showIcon; - - if (pTriggerImage && showTrigger) - triggerHeight = pTriggerImage->GetHeight(); - if (pIconImage && showIcon) - iconHeight = pIconImage->GetHeight(); - - lineHeight = fontWithPadding + 1; - if (triggerHeight + 5 > lineHeight) - lineHeight = triggerHeight + 5; // Ensure 2 pixels of padding on either side + 1 for div. - if (iconHeight + 5 > lineHeight) - lineHeight = iconHeight + 5; // Ensure pixel padding plus 1 for div. - - NS_RELEASE(fontMetrics); - - // Modify the position we'll be returning for future painting. - nsRect lineRect(0, yPosition, mColumnBarRect.width, lineHeight); - yPosition += lineHeight; - - // Cache our line rect with the tree item to make hit testing easier. - pItem->SetTreeItemRectangle(lineRect); - - // Fill the rect with our BGColor. TODO: Fetch properties etc. - drawCtx->SetColor(styleInfo.backgroundColor); - drawCtx->FillRect(lineRect); - if (styleInfo.pBackgroundImage) - { - PaintBackgroundImage(drawCtx, styleInfo.pBackgroundImage, lineRect); - } - - // Draw the horizontal divider - if (styleInfo.showHorizontalDivider) - { - drawCtx->SetColor(styleInfo.horizontalDividerColor); - drawCtx->DrawLine(0, yPosition-1, mColumnBarRect.width, yPosition-1); - } - - // Iterate over the visible columns and paint the data specified. - PRUint32 count = mDataModel->GetVisibleColumnCount(); - int currentPosition = 0; - for (PRUint32 n = 0; n < count; n++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(n); - if (pColumn) - { - // Retrieve the column's current pixel width. - int pixelWidth = pColumn->GetPixelWidth(); - - // Draw our text indented slightly, centered in our line rect, and cropped. - nsString nodeText("Column Data"); - pItem->GetTextForColumn(pColumn, nodeText); - - int textStart = currentPosition + 2; - int iconStart = currentPosition + 2; - if (n == 0) - { - // This is the image column. - // Draw the trigger image at the appropriate spot. - int indentation = pItem->GetIndentationLevel(); - int pixelIndent = cIndentAmount * indentation; - int iconMargin = cIconMargin; // Distance from trigger edge to icon edge - int triggerStart = 4; - - int triggerWidth = (pTriggerImage && showTrigger ? pTriggerImage->GetWidth() : 0); - iconStart = triggerStart + triggerWidth + - cIconMargin + pixelIndent; - if (!leftJustifyTrigger) - { - triggerStart = 4 + pixelIndent; - iconStart = triggerStart + triggerWidth + cIconMargin; - } - - // Cache our trigger rect to make hit testing easier. - nsRect triggerRect(0,0,0,0); - if (pTriggerImage && showTrigger) - { - triggerRect = nsRect(triggerStart-1, lineRect.y - 1 + (lineHeight-1-triggerHeight)/2, - triggerWidth+2, triggerHeight+2); - } - pItem->SetTriggerRectangle(triggerRect); - - // Paint the trigger and icon - if (pTriggerImage && showTrigger) - drawCtx->DrawImage(pTriggerImage, triggerStart, - lineRect.y + (lineHeight-1-triggerHeight)/2); - if (pIconImage && showIcon) - drawCtx->DrawImage(pIconImage, iconStart, - lineRect.y + (lineHeight-1-iconHeight)/2); - - textStart = iconStart + (showIcon && pIconImage ? pIconImage->GetWidth() : 0) + 2; - } - - // Determine the rect to use. - int start = lineRect.y + (lineHeight-fontWithPadding-1)/2; - nsRect textRect(textStart, start, pixelWidth-2-(textStart-currentPosition), fontWithPadding); - nsRect resultRect = DrawCroppedString(drawCtx, nodeText, textRect, PR_FALSE); - - // Modify the result rect so it is the appropriate size for the drawing of rollover and - // selection. - resultRect.y = lineRect.y; - resultRect.height = lineRect.height; - - // Now we really draw the string, using the appropriate colors/styles. - // Options are ROLLOVER, SELECTION, or NORMAL. - if (resultRect.Contains(mCachedMovePoint.x, mCachedMovePoint.y)) - { - // Rollover style should be applied. - drawCtx->SetColor(styleInfo.rolloverFGColor); - - // TODO: Handle Rollover BACKGROUND color. Could be applied to text, to cell, or to line. - } - else drawCtx->SetColor(styleInfo.foregroundColor); - - if (pItem->IsSelected()) // Supercedes rollover color. - { - PRInt32 columnIndex = mDataModel->GetSelectedColumnIndex(); - if (columnIndex != -1 && (PRUint32(columnIndex) == n)) - { - drawCtx->SetColor(styleInfo.selectionBGColor); - drawCtx->FillRect(nsRect(resultRect.x, resultRect.y+2, resultRect.width, resultRect.height-5)); - drawCtx->SetColor(styleInfo.selectionFGColor); - } - } - - // Set the content rectangle for hit testing - nsRect contentRect(resultRect); - int growth = textStart - iconStart; - contentRect.width += growth; - contentRect.x -= growth; - pItem->SetContentRectangle(contentRect, n); - - // Now draw the column data for real. - DrawCroppedString(drawCtx, nodeText, textRect); - - currentPosition += pixelWidth; - - // Draw the vertical divider - if (styleInfo.showVerticalDivider) - { - drawCtx->SetColor(styleInfo.verticalDividerColor); - drawCtx->DrawLine(textStart+textRect.width + 1, lineRect.y, - textStart+textRect.width + 1, lineRect.y + lineRect.height); - } - } - } -} - -void nsTreeView::PaintBackgroundImage(nsIRenderingContext* ctx, - nsIImage* bgImage, const nsRect& constraintRect, - int xSrcOffset, int ySrcOffset) -{ - // This code gets a bit intense. Will comment heavily. - - int imageWidth = bgImage->GetWidth(); // The dimensions of the background image being tiled. - int imageHeight = bgImage->GetHeight(); - - int totalWidth = constraintRect.width; // The dimensions of the space we're - int totalHeight = constraintRect.height; // drawing into. - - if (imageWidth <= 0 || imageHeight <= 0) // Don't draw anything if we don't have a sane image. - return; - - int xSize = imageWidth - xSrcOffset; // The dimensions of the actual tile we'll end - int ySize = imageHeight - ySrcOffset; // up drawing. A subset of the full BG image. - - xSize = (xSize > totalWidth) ? totalWidth : xSize; - ySize = (ySize > totalHeight) ? totalHeight : ySize; - - int rightMostPoint = constraintRect.x + constraintRect.width; // Edges of the space we're - int bottomMostPoint = constraintRect.y + constraintRect.height; // drawing into. - - int xDstOffset = constraintRect.x; // Top-left coordinates in the space where - int yDstOffset = constraintRect.y; // we'll be drawing. Where we'll place the tile. - - int initXOffset = xSrcOffset; - - // Tile vertically until we move out of the constraining rect. - while (yDstOffset < bottomMostPoint) - { - // Tile horizontally until we move out of the constraining rect. - while (xDstOffset < rightMostPoint) - { - // Draw the subimage. Pull the subimage from the larger image - // and then draw it. - ctx->DrawImage(bgImage, nsRect(xSrcOffset, ySrcOffset, xSize, ySize), - nsRect(xDstOffset, yDstOffset, xSize, ySize)); - - // The next subimage will be as much of the full BG image as can fit in the - // constraining rect. If we're at the edge, we don't draw quite as much. - xSrcOffset = 0; - xDstOffset += xSize; - xSize = (xDstOffset + imageWidth) > rightMostPoint ? imageWidth - (xDstOffset + imageWidth) + rightMostPoint : imageWidth; - } - - xSrcOffset = initXOffset; // Start of all rows will be at the same initial x offset. - xDstOffset = constraintRect.x; // Reset our x-position for drawing the next row. - xSize = (xDstOffset + imageWidth) > rightMostPoint ? rightMostPoint - xDstOffset : imageWidth; - - // Determine the height of the next row. Will be as much of the BG image - // as can fit in the constraining rect. If we're at the bottom edge, we don't - // draw quite as much. - ySrcOffset = 0; - yDstOffset += ySize; - ySize = (yDstOffset + imageHeight) > bottomMostPoint ? bottomMostPoint - yDstOffset : imageHeight; - } -} - -void nsTreeView::ShowColumn() -{ - int pusherWidth = (int)(mColumnBarRect.height * 1.25); - if (pusherWidth % 2 != 0) - pusherWidth++; - - int totalSpace = mColumnBarRect.width - pusherWidth; - int remainingSpace = totalSpace; - PRUint32 visColumns = mDataModel->GetVisibleColumnCount(); - PRUint32 totalColumns = mDataModel->GetColumnCount(); - - if (visColumns < totalColumns) - { - visColumns++; - mDataModel->SetVisibleColumnCount(visColumns); - - nsTreeColumn* pShownColumn = mDataModel->GetNthColumn(visColumns-1); - double totalPercentage = 1.0 + pShownColumn->GetDesiredPercentage(); - - // Do a recomputation of column widths and percentages - for (PRUint32 i = 0; i < visColumns; i++) - { - nsTreeColumn* pColumn = mDataModel->GetNthColumn(i); - pColumn->SetDesiredPercentage(pColumn->GetDesiredPercentage() / - totalPercentage); - - pColumn->SetPixelWidth((int)(pColumn->GetDesiredPercentage() * totalSpace)); - remainingSpace -= pColumn->GetPixelWidth(); - if (i == visColumns-1) - pColumn->SetPixelWidth(pColumn->GetPixelWidth() + remainingSpace); - } - - Invalidate(PR_FALSE); - } -} - - -void nsTreeView::HideColumn() -{ - int pusherWidth = (int)(mColumnBarRect.height * 1.25); - if (pusherWidth % 2 != 0) - pusherWidth++; - - int totalSpace = mColumnBarRect.width - pusherWidth; - int remainingSpace = totalSpace; - PRUint32 visColumns = mDataModel->GetVisibleColumnCount(); - PRUint32 totalColumns = mDataModel->GetColumnCount(); - - if (visColumns > 1) - { - visColumns--; - mDataModel->SetVisibleColumnCount(visColumns); - - // Do a recomputation of column widths and percentages - nsTreeColumn* pHiddenColumn = mDataModel->GetNthColumn(visColumns); - - // The hidden column's desired percentage should be changed so that - // if it is subsequently reshown, it will be the same size. - double totalPercentage = 1.0 - pHiddenColumn->GetDesiredPercentage(); - pHiddenColumn->SetDesiredPercentage(pHiddenColumn->GetDesiredPercentage() / totalPercentage); - - for (PRUint32 i = 0; i < visColumns; i++) - { - nsTreeColumn* pColumn = mDataModel->GetNthColumn(i); - pColumn->SetDesiredPercentage(pColumn->GetDesiredPercentage() / totalPercentage); - pColumn->SetPixelWidth((int)(pColumn->GetDesiredPercentage() * totalSpace)); - remainingSpace -= pColumn->GetPixelWidth(); - if (i == visColumns-1) - pColumn->SetPixelWidth(pColumn->GetPixelWidth() + remainingSpace); - - } - - Invalidate(PR_FALSE); - } -} - -void nsTreeView::RecomputeColumnPercentages() -{ - int width = mColumnBarRect.width; - PRUint32 count = mDataModel->GetVisibleColumnCount(); - int currentPosition = 0; - int pusherWidth = (int)(mColumnBarRect.height * 1.25); - if (pusherWidth % 2 != 0) - pusherWidth++; - - int totalSpace = width - pusherWidth; - - for (PRUint32 n = 0; n < count; n++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(n); - if (pColumn) - { - int pixelWidth = pColumn->GetPixelWidth(); - pColumn->SetDesiredPercentage(((double)pixelWidth)/((double)totalSpace)); - } - } -} - -void nsTreeView::ResizeColumns(int width) -{ - // Need to do the appropriate resizing of the columns. - PRUint32 count = mDataModel->GetVisibleColumnCount(); - int currentPosition = 0; - int pusherWidth = (int)(mColumnBarRect.height * 1.25); - if (pusherWidth % 2 != 0) - pusherWidth++; - - int remainingSpace = width - pusherWidth; - int totalSpace = remainingSpace; - double newColPercentage = 1.0 / count; - - for (PRUint32 n = 0; n < count; n++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(n); - if (pColumn) - { - double desiredPercentage = pColumn->GetDesiredPercentage(); - int newPixelWidth = (int)(desiredPercentage*totalSpace); - pColumn->SetPixelWidth(newPixelWidth); - remainingSpace -= newPixelWidth; - if (n == count-1) - pColumn->SetPixelWidth(newPixelWidth + remainingSpace); - } - } -} - -PRBool nsTreeView::DownOnColumnEdge(const nsPoint& point) -{ - int x = point.x; // Only x coord is relevant. - if (!mDataModel) return PR_FALSE; - - PRUint32 count = mDataModel->GetVisibleColumnCount(); - int currentPosition = 0; - - for (PRUint32 n = 0; n < count-1; n++) - { - // Fetch each column. - nsTreeColumn* pColumn = mDataModel->GetNthColumn(n); - if (pColumn) - { - int pixelWidth = pColumn->GetPixelWidth(); - if (currentPosition + pixelWidth - 2 <= x && - x <= currentPosition + pixelWidth + 2) - { - // Cache the column hit in case we end up dragging it around. - mMousedColumnIndex = n; - return PR_TRUE; - } - - if (x < currentPosition + pixelWidth) - return PR_FALSE; - - currentPosition += pixelWidth; - } - } - return PR_FALSE; -} - -void nsTreeView::DragColumnEdge(int xPos) -{ - nsTreeColumn* pLeftColumn = mDataModel->GetNthColumn(mMousedColumnIndex); - nsTreeColumn* pRightColumn = mDataModel->GetNthColumn(mMousedColumnIndex+1); - if (pLeftColumn && pRightColumn) - { - // Adjust the two columns' pixel widths. - int leftPixelWidth = pLeftColumn->GetPixelWidth(); - int rightPixelWidth = pRightColumn->GetPixelWidth(); - int dragDiff = ((int)xPos) - ((int)mLastXPosition); - int newLeft = leftPixelWidth+dragDiff; - int newRight = rightPixelWidth-dragDiff; - if (newLeft > cMinColumnWidth && newRight > cMinColumnWidth) - { - pLeftColumn->SetPixelWidth(newLeft); - pRightColumn->SetPixelWidth(newRight); - - mLastXPosition = xPos; - Invalidate(PR_FALSE); - } - } -} - -// Helpers -void nsTreeView::ParseColor(char* colorString, nscolor& colorValue) -{ - if (!NS_ColorNameToRGB(colorString, &colorValue)) - NS_HexToRGB(colorString, &colorValue); -} - -nsRect nsTreeView::DrawCroppedString(nsIRenderingContext* drawCtx, nsString text, - const nsRect& rect, PRBool drawText) -{ - int strWidth = 0; - drawCtx->GetWidth(text, strWidth); - nsString cropString(text); - if (strWidth + 4 > rect.width) - { - int length = text.Length(); - if (length > 3) - { - cropString = ""; - text.Left(cropString, length - 3); - cropString += "..."; - - drawCtx->GetWidth(cropString, strWidth); - while (strWidth + 4 > rect.width && length > 3) - { - length--; - cropString = ""; - text.Left(cropString, length - 3); - cropString += "..."; - drawCtx->GetWidth(cropString, strWidth); - } - } - } - - if (drawText) - { - // Draw the cropString. - drawCtx->DrawString(cropString, rect.x + 2, rect.y + 2); - } - - int width = strWidth + 4; - if (width > rect.width) - width = rect.width; - return nsRect(rect.x, rect.y, width, rect.height); -} - diff --git a/widget/src/xpwidgets/nsTreeView.h b/widget/src/xpwidgets/nsTreeView.h deleted file mode 100644 index e495ebd64ec0..000000000000 --- a/widget/src/xpwidgets/nsTreeView.h +++ /dev/null @@ -1,160 +0,0 @@ -/* -*- 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 "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef nsTreeView_h___ -#define nsTreeView_h___ - -#include "nsIContentConnector.h" -#include "nsTreeDataModel.h" -#include "nsTreeItem.h" -#include "nsTreeColumn.h" -#include "nsTreeControlStripItem.h" -#include "nsDataModelWidget.h" - -class nsIImageGroup; -class nsIImage; - -enum nsHitLocation { eTriggerHit, eContentHit, eBackgroundHit }; - -//------------------------------------------------------------ -// A tree view consists of several components: a title bar, a control strip, -// a column bar, the actual tree contents, and an accompanying scrollbar for the -// tree contents. -// -// The actual tree view knows nothing about the data it is displaying. It queries -// a data model for all properties, and then just uses the values it obtains -// to display the data. It passes all expand/collapse/deletion/etc. events back -// to the data model. - -class nsTreeView : public nsIContentConnector, - public nsDataModelWidget -{ -public: - nsTreeView(); - virtual ~nsTreeView(); - - // nsISupports Interface -------------------------------- - NS_DECL_ISUPPORTS - - // nsIContentConnector Interface -------------------------------- - NS_IMETHOD SetContentRoot(nsIContent* pContent); - NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent); - - // Override the widget creation method - NS_IMETHOD Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData); - - - void HandleDataModelEvent(int event, nsHierarchicalDataItem* pItem); - -protected: - - enum { cIndentAmount = 19, cIconMargin = 2, cMinColumnWidth = 30 }; - - // These functions are all used in painting. - void PaintTitleBar(nsIRenderingContext* drawCtx, - nsRect& rect); - void PaintControlStrip(nsIRenderingContext* drawCtx, - nsRect& rect); - - // These functions are used in painting the column bar. - void PaintColumnBar(nsIRenderingContext* drawCtx, - nsRect& rect); - void PaintColumnHeader(nsIRenderingContext* drawCtx, - nsTreeColumn* pColumn, - PRUint32& currentPosition, - const nsColumnHeaderStyleInfo& styleInfo); - void PaintPusherArrow(nsIRenderingContext* drawCtx, - PRBool isLeftArrow, int left, int width); - - // These functions are used to paint the rows in the tree. - void PaintTreeRows(nsIRenderingContext* drawCtx, nsRect& rect); - void PaintTreeRow(nsIRenderingContext* drawCtx, nsTreeItem* pItem, int& yPosition); - - // General function for painting a background image. - void PaintBackgroundImage(nsIRenderingContext* drawCtx, - nsIImage* bgImage, const nsRect& constraintRect, - int xSrcOffset = 0, int ySrcOffset = 0); - - // Helper to parse color strings. - void ParseColor(char* colorString, nscolor& colorValue); - - // Column Adjusters/Routines - void ResizeColumns(int width); - void RecomputeColumnPercentages(); - void ShowColumn(); - void HideColumn(); - void DragColumnEdge(int xPos); - PRBool DownOnColumnEdge(const nsPoint& point); - - // String drawing helper. Crops left, inserts ellipses, and left justifies string. - // Assumption is that the font has been set in the - // rendering context, so the font metrics can be retrieved and used. - nsRect DrawCroppedString(nsIRenderingContext* drawCtx, nsString text, - const nsRect& rect, PRBool drawText=PR_TRUE); - - - // Event handlers for specific mouse actions - void HandleMouseMove(nsGUIEvent* aEvent); - void HandleMouseUp(nsGUIEvent* aEvent); - - // Helper for determining hit locations. - void DetermineHitLocation(const nsPoint& point, - PRUint32& row, PRUint32& column, nsHitLocation& location); - -protected: - // Data members (*** these should both be smart pointers***) - nsTreeDataModel* mDataModel; // The data source from which everything to draw is obtained. - nsIImageGroup* mImageGroup; // Used to make requests for tree images. - - // Cached rects for fast hit testing computation. - nsRect mTitleBarRect; - nsRect mControlStripRect; - nsRect mColumnBarRect; - nsRect mTreeRect; - - // This rect is an area that needs to be invalidated once the mouse leaves it. - // Used on mouse move events. - nsRect mCachedMoveRect; // Is either the control strip or lines in the tree. Only - // these items can possibly be invalidated on a mouse move. - nsPoint mCachedMovePoint; // Cache the last mouse move. - nsPoint mCachedDownPoint; // Cache the mouse down point. - - PRBool mMouseDown; // Whether or not the mouse is pressed. - PRBool mMouseDragging; // Whether or not we're dragging something. - - // These members all have to do with dragging the edges of columns to resize them. - int mMousedColumnIndex; // The index of the column edge hit on a mouse down. - int mLastXPosition; // The last X position of the dragged column edge. - PRBool mDraggingColumnEdge; // Whether or not we're dragging a column edge. - - PRBool mDraggingColumnHeader; // Whether or not we're dragging a column header - -private: - // tree views are widgets which exist in one-to-one correspondence with objects on - // the screen. Copying them does not make sense, so we outlaw it explicitly. - nsTreeView ( const nsTreeView & ) ; // DON'T IMPLEMENT - nsTreeView & operator= ( const nsTreeView & ); // DON'T IMPLEMENT -}; - -#endif /* nsTreeView_h___ */