Changed toolbar code to support wrapping in View system

This commit is contained in:
spider%netscape.com 1998-11-05 19:52:50 +00:00
parent 1bafa4a69f
commit 0a03c7babf
7 changed files with 134 additions and 79 deletions

View File

@ -165,6 +165,11 @@ public:
*/
virtual nsEventStatus HandleEvent(nsGUIEvent *aEvent) = 0;
/**
* Create a Tab on this toolbar
*
*/
NS_IMETHOD CreateTab(nsIWidget *& aTab) = 0;
};

View File

@ -99,6 +99,16 @@ public:
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

View File

@ -46,6 +46,7 @@ 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);
//------------------------------------------------------------
class ToolbarLayoutInfo {
@ -883,3 +884,84 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
return NS_OK;
}
//-------------------------------------------------------------------
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;
}
nsRect rt(0, 0, TAB_WIDTH, TAB_HEIGHT);
nsIImageButton * tab;
rv = nsRepository::CreateInstance(kImageButtonCID, nsnull, kIImageButtonIID,
(void**)&tab);
if (NS_OK != rv) {
NS_RELEASE(parent);
NS_RELEASE(toolbarItem);
NS_RELEASE(toolbarItemHolder);
return rv;
}
// Get the nsIWidget interface for the tab so it can be added to the parent widget
// 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->Show(PR_TRUE);
widget->SetClientData((void *)parent);
widget->Resize(0, 1, TAB_WIDTH, TAB_HEIGHT, PR_FALSE);
toolbarItemHolder->SetWidget(widget); // put the widget into the holder
tab->SetBorderWidth(0);
tab->SetBorderOffset(0);
tab->SetShowBorder(PR_FALSE);
tab->SetShowText(PR_FALSE);
tab->SetLabel("");
tab->SetImageDimensions(rt.width, rt.height);
nsString up, pres, dis, roll;
mToolbarMgr->GetCollapseTabURLs(up, pres, dis, roll);
tab->SetImageURLs(up, pres, dis, roll);
InsertItemAt(toolbarItem, 0, PR_TRUE, 0); // add the item with zero gap, stretchable, zero position
nsIImageButtonListener * listener = nsnull;
if (NS_OK == mToolbarMgr->QueryInterface(kIImageButtonListenerIID,(void**)&listener)) {
tab->AddListener(listener);
NS_RELEASE(listener);
}
aTab = widget;
}
NS_RELEASE(parent);
NS_RELEASE(tab);
NS_RELEASE(toolbarItem);
NS_RELEASE(toolbarItemHolder);
return NS_OK;
}

View File

@ -98,6 +98,7 @@ public:
NS_IMETHOD GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight,
PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD CreateTab(nsIWidget *& aTab);
protected:
void GetMargins(PRInt32 &aX, PRInt32 &aY);

View File

@ -46,8 +46,6 @@ NS_IMPL_RELEASE(nsToolbarManager)
// images instead of being hard coded
#define EXPAND_TAB_WIDTH 56
#define EXPAND_TAB_HEIGHT 10
#define COLLAPSE_TAB_WIDTH 9
#define COLLAPSE_TAB_HEIGHT 42
const PRInt32 kMaxNumToolbars = 32;
@ -219,78 +217,6 @@ NS_METHOD nsToolbarManager::AddTabToManager(nsIToolbar * aToolbar,
return NS_OK;
}
//--------------------------------------------------------------------
NS_METHOD nsToolbarManager::AddTabToToolbar(nsIToolbar * aToolbar)
{
nsresult rv;
// Get the toolbar's widget (the parent of the tab)
nsIWidget* parent;
if (NS_OK != aToolbar->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;
}
nsRect rt(0, 0, COLLAPSE_TAB_WIDTH, COLLAPSE_TAB_HEIGHT);
nsIImageButton * tab;
rv = nsRepository::CreateInstance(kImageButtonCID, nsnull, kIImageButtonIID,
(void**)&tab);
if (NS_OK != rv) {
NS_RELEASE(parent);
NS_RELEASE(toolbarItem);
NS_RELEASE(toolbarItemHolder);
return rv;
}
// Get the nsIWidget interface for the tab so it can be added to the parent widget
// and it can be put into the generic ToolbarItemHolder
nsIWidget * widget;
if (NS_OK == tab->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->Create(parent, rt, NULL, NULL);
widget->Show(PR_TRUE);
widget->SetClientData((void *)parent);
widget->Resize(0, 1, COLLAPSE_TAB_WIDTH, COLLAPSE_TAB_HEIGHT, PR_FALSE);
toolbarItemHolder->SetWidget(widget); // put the widget into the holder
tab->SetBorderWidth(0);
tab->SetBorderOffset(0);
tab->SetShowBorder(PR_FALSE);
tab->SetShowText(PR_FALSE);
tab->SetLabel("");
tab->SetImageDimensions(rt.width, rt.height);
tab->SetImageURLs(mCollapseUpURL, mCollapsePressedURL, mCollapseDisabledURL, mCollapseRollOverURL);
aToolbar->InsertItemAt(toolbarItem, 0, PR_TRUE, 0); // add the item with zero gap, stretchable, zero position
tab->AddListener(this);
NS_RELEASE(widget);
}
NS_RELEASE(parent);
NS_RELEASE(tab);
NS_RELEASE(toolbarItem);
NS_RELEASE(toolbarItemHolder);
return NS_OK;
}
//--------------------------------------------------------------------
NS_METHOD nsToolbarManager::AddToolbar(nsIToolbar* aToolbar)
@ -300,7 +226,6 @@ NS_METHOD nsToolbarManager::AddToolbar(nsIToolbar* aToolbar)
// XXX should check here to make sure it isn't already added
aToolbar->SetToolbarManager(this);
AddTabToToolbar(aToolbar);
NS_ADDREF(aToolbar);
return NS_OK;
@ -493,6 +418,20 @@ NS_METHOD nsToolbarManager::SetCollapseTabURLs(const nsString& aUpURL,
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,

View File

@ -63,9 +63,13 @@ public:
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);
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,
@ -77,7 +81,6 @@ public:
nsGUIEvent * aEvent);
protected:
NS_IMETHOD AddTabToToolbar(nsIToolbar * aToolbar);
NS_METHOD AddTabToManager(nsIToolbar * aToolbar,
const nsString& aUpURL,
const nsString& aPressedURL,

View File

@ -1442,6 +1442,11 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
toolbarWidget->Show(PR_TRUE);
mToolbarMgr->AddToolbar(mBtnToolbar);
nsIWidget * tab = nsnull;
mBtnToolbar->CreateTab(tab);
NS_IF_RELEASE(tab);
gBtnWidth = 54;
gBtnHeight = 42;
@ -1538,6 +1543,11 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
urlToolbarWidget->Show(PR_TRUE);
mToolbarMgr->AddToolbar(mURLToolbar);
tab = nsnull;
mURLToolbar->CreateTab(tab);
NS_IF_RELEASE(tab);
//------
// Create and place Bookmark button
//------
@ -1675,6 +1685,11 @@ nsBrowserWindow::CreateToolBar(PRInt32 aWidth)
personalToolbarWidget->Show(PR_TRUE);
mToolbarMgr->AddToolbar(personalToolbar);
tab = nsnull;
personalToolbar->CreateTab(tab);
NS_IF_RELEASE(tab);
// Count number of buttons and create array to hold them
mNumPersonalToolbarBtns = 0;
while (gPersonalToolbarInfo[mNumPersonalToolbarBtns].mImgWidth > 0) {