зеркало из https://github.com/mozilla/gecko-dev.git
File Removed.
This commit is contained in:
Родитель
da5a91388e
Коммит
91a1ba7c85
|
@ -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___ */
|
||||
|
|
@ -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___ */
|
||||
|
|
@ -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___ */
|
||||
|
|
@ -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___ */
|
||||
|
|
@ -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___ */
|
||||
|
|
@ -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___ */
|
||||
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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___ */
|
|
@ -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";
|
||||
}
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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___ */
|
|
@ -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___ */
|
|
@ -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___ */
|
|
@ -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<nsIToolbarItem> 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<mNumItems;i++) {
|
||||
delete mItems[i];
|
||||
}
|
||||
delete[] mItems;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
nsresult nsToolbar::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult retval = NS_OK;
|
||||
|
||||
if (NULL == aInstancePtr) {
|
||||
retval = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
else if (aIID.Equals(kCIToolbarIID)) {
|
||||
*aInstancePtr = (void*) (nsIToolbar *)this;
|
||||
AddRef();
|
||||
}
|
||||
else if (aIID.Equals(kIContentConnectorIID)) {
|
||||
*aInstancePtr = (void*) (nsIContentConnector *)this;
|
||||
AddRef();
|
||||
}
|
||||
else if (aIID.Equals(kIToolbarItemIID)) {
|
||||
*aInstancePtr = (void*) (nsIToolbarItem *)this;
|
||||
AddRef();
|
||||
}
|
||||
else
|
||||
retval = nsDataModelWidget::QueryInterface(aIID, aInstancePtr);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static nsEventStatus PR_CALLBACK
|
||||
HandleToolbarEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
nsCOMPtr<nsIContentConnector> 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;i<mNumItems;i++) {
|
||||
PRBool isVisible;
|
||||
mItems[i]->mItem->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;i<mNumItems;i++) {
|
||||
if (mItems[i]->mStretchable) {
|
||||
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;i<mNumItems;i++) {
|
||||
if (i == 10) {
|
||||
int x = 0;
|
||||
}
|
||||
PRBool isVisible;
|
||||
mItems[i]->mItem->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;i<mNumItems;i++) {
|
||||
if (mItems[i]->mStretchable) {
|
||||
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;i<mNumItems;i++) {
|
||||
PRBool isVisible;
|
||||
mItems[i]->mItem->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;i<mNumItems;i++) {
|
||||
PRBool isVisible;
|
||||
mItems[i]->mItem->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<nsIDeviceContext> 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<nsIRenderingContext> 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;i<mNumItems;i++) {
|
||||
PRBool isVisible;
|
||||
mItems[i]->mItem->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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___ */
|
|
@ -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___ */
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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<nsIWidget> mWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsToolbarItemHolder_h___ */
|
|
@ -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<nsIToolbar> [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<nsIContentConnector> 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<nsIRenderingContext> 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<nsIWidget> 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<nsIWidget> 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;i<mNumToolbars;++i) {
|
||||
PRBool visible;
|
||||
mToolbars[i]->IsVisible(visible);
|
||||
if (visible) {
|
||||
nsCOMPtr<nsIWidget> 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;i<mNumToolbars;i++) {
|
||||
PRInt32 width;
|
||||
PRInt32 height;
|
||||
PRBool visible;
|
||||
mToolbars[i]->IsVisible(visible);
|
||||
if (visible) {
|
||||
nsCOMPtr<nsIWidget> 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;i<mNumToolbars;i++) {
|
||||
PRBool visible;
|
||||
mToolbars[i]->IsVisible(visible);
|
||||
if (visible) {
|
||||
nsCOMPtr<nsIWidget> 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<nsIRenderingContext> 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<nsIRenderingContext> ctx (dont_AddRef(GetRenderingContext()));
|
||||
if ( ctx ) {
|
||||
DrawGrippy ( ctx, mTabs[mGrippyHilighted].mBoundingRect, PR_FALSE );
|
||||
mGrippyHilighted = kNoGrippyHilighted;
|
||||
}
|
||||
}
|
||||
} // OnMouseExit
|
|
@ -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<nsIToolbar> 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<nsIToolbarManagerListener> 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<nsIToolbar> * 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<nsIImageRequest> mGrippyNormalTop; // Image for grippy in normal state
|
||||
nsCOMPtr<nsIImageRequest> mGrippyNormalMiddle; // Image for grippy in normal state
|
||||
nsCOMPtr<nsIImageRequest> mGrippyNormalBottom; // Image for grippy in normal state
|
||||
|
||||
nsCOMPtr<nsIImageRequest> mGrippyRolloverTop; // image for grippy in rollover state
|
||||
nsCOMPtr<nsIImageRequest> mGrippyRolloverMiddle; // image for grippy in rollover state
|
||||
nsCOMPtr<nsIImageRequest> mGrippyRolloverBottom; // image for grippy in rollover state
|
||||
|
||||
}; // class nsToolbarManager
|
||||
|
||||
#endif /* nsToolbarManager_h___ */
|
|
@ -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___ */
|
|
@ -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___ */
|
|
@ -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___ */
|
|
@ -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___ */
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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___ */
|
Загрузка…
Ссылка в новой задаче