diff --git a/widget/src/xpwidgets/nsToolbar.cpp b/widget/src/xpwidgets/nsToolbar.cpp index 135c9d785a3a..086e9638f21c 100644 --- a/widget/src/xpwidgets/nsToolbar.cpp +++ b/widget/src/xpwidgets/nsToolbar.cpp @@ -88,7 +88,8 @@ static CNavTokenDeallocator gItemInfoKiller;*/ //-------------------------------------------------------------------- //-- nsToolbar Constructor //-------------------------------------------------------------------- -nsToolbar::nsToolbar() : nsDataModelWidget(), nsIToolbar() +nsToolbar::nsToolbar() : nsDataModelWidget(), nsIToolbar(), + mImageGroup(nsnull) { NS_INIT_REFCNT(); @@ -114,6 +115,7 @@ nsToolbar::nsToolbar() : nsDataModelWidget(), nsIToolbar() nsToolbar::~nsToolbar() { NS_IF_RELEASE(mToolbarMgr); + NS_IF_RELEASE(mImageGroup); //delete mItemDeque; @@ -207,6 +209,22 @@ HandleTabEvent(nsGUIEvent *aEvent) } +// +// SetContentRoot +// +// Hook up the toolbar to the content model rooted at the given node +// +NS_METHOD +nsToolbar::SetContentRoot(nsIContent* pContent) +{ +#if PINK_NOT_YET_IMPLEMENTED + if (mDataModel) + mDataModel->SetContentRoot(pContent); +#endif + + return NS_OK; +} + //-------------------------------------------------------------------- NS_METHOD nsToolbar::AddItem(nsIToolbarItem* anItem, PRInt32 aLeftGap, PRBool aStretchable) @@ -919,25 +937,17 @@ NS_METHOD nsToolbar::CreateTab(nsIWidget *& aTab) { nsresult rv; - // Get the toolbar's widget (the parent of the tab) - nsIWidget* parent; - if (NS_OK != QueryInterface(kIWidgetIID,(void**)&parent)) { - return NS_ERROR_FAILURE; - } - // Create the generic toolbar holder for the tab widget nsIToolbarItemHolder * toolbarItemHolder; rv = nsRepository::CreateInstance(kToolbarItemHolderCID, nsnull, kIToolbarItemHolderIID, (void**)&toolbarItemHolder); if (NS_OK != rv) { - NS_RELEASE(parent); return rv; } // Get the ToolbarItem interface for adding it to the toolbar nsIToolbarItem * toolbarItem; if (NS_OK != toolbarItemHolder->QueryInterface(kIToolbarItemIID,(void**)&toolbarItem)) { - NS_RELEASE(parent); NS_RELEASE(toolbarItemHolder); return NS_OK; } @@ -948,7 +958,6 @@ NS_METHOD nsToolbar::CreateTab(nsIWidget *& aTab) rv = nsRepository::CreateInstance(kImageButtonCID, nsnull, kIImageButtonIID, (void**)&tab); if (NS_OK != rv) { - NS_RELEASE(parent); NS_RELEASE(toolbarItem); NS_RELEASE(toolbarItemHolder); return rv; @@ -958,9 +967,9 @@ NS_METHOD nsToolbar::CreateTab(nsIWidget *& aTab) // and it can be put into the generic ToolbarItemHolder nsIWidget * widget = nsnull; if (NS_OK == tab->QueryInterface(kIWidgetIID,(void**)&widget)) { - widget->Create(parent, rt, NULL, NULL); + widget->Create(this, rt, NULL, NULL); widget->Show(PR_TRUE); - widget->SetClientData((void *)parent); + widget->SetClientData(NS_STATIC_CAST(void*, this)); widget->Resize(0, 1, TAB_WIDTH, TAB_HEIGHT, PR_FALSE); @@ -986,7 +995,6 @@ NS_METHOD nsToolbar::CreateTab(nsIWidget *& aTab) aTab = widget; } - NS_RELEASE(parent); NS_RELEASE(tab); NS_RELEASE(toolbarItem); NS_RELEASE(toolbarItemHolder); diff --git a/widget/src/xpwidgets/nsToolbar.h b/widget/src/xpwidgets/nsToolbar.h index 17b42e996c62..7153dfd27f29 100644 --- a/widget/src/xpwidgets/nsToolbar.h +++ b/widget/src/xpwidgets/nsToolbar.h @@ -19,7 +19,8 @@ #ifndef nsToolbar_h___ #define nsToolbar_h___ -#include "nsIToolbar.h" +#include "nsIToolbar.h" //*** not for long +#include "nsIContentConnector.h" #include "nsWindow.h" #include "nsIImageButton.h" #include "nsIToolbarItem.h" @@ -27,10 +28,22 @@ class ToolbarLayoutInfo; +class nsIImageGroup; + + +// +// 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, + public nsIToolbar, //*** not for long + public nsIContentConnector, public nsIToolbarItem { @@ -40,33 +53,32 @@ public: 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 SetToolbarManager(nsIToolbarManager * aToolbarManager); NS_IMETHOD GetToolbarManager(nsIToolbarManager *& aToolbarManager); NS_IMETHOD SetBorderType(nsToolbarBorderType aBorderType); - - NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent); NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); virtual void HandleDataModelEvent(int event, nsHierarchicalDataItem* pItem) ; - // nsIToolbarItem + // nsIToolbarItem Interface -------------------------------- NS_IMETHOD Repaint(PRBool aIsSynchronous); NS_IMETHOD GetBounds(nsRect &aRect); NS_IMETHOD SetVisible(PRBool aState); @@ -115,6 +127,10 @@ protected: const nsString& aRollOverURL); + //*** these should be smart pointers *** +//nsToolbarDataModel* mDataModel; // The data source from which everything to draw is obtained. + nsIImageGroup* mImageGroup; // Used to make requests for toolbar images. + // This will be changed to a nsVoidArray or a Deque ToolbarLayoutInfo ** mItems; PRInt32 mNumItems;