зеркало из https://github.com/mozilla/gecko-dev.git
Decouple the toolbars from the toolbox once and for all. Implement collapsing/expanding toolbars with new grippy mechanism.
This commit is contained in:
Родитель
6bb466185c
Коммит
3b684ee62d
|
@ -18,7 +18,6 @@
|
|||
|
||||
//
|
||||
// pinkerton ToDo:
|
||||
// - remove dependence on toolbar manager and grippy
|
||||
// - make this talk to DOM for its children.
|
||||
// - rip out nsIToolbar stuff
|
||||
//
|
||||
|
@ -28,7 +27,6 @@
|
|||
#include "nsWidgetsCID.h"
|
||||
#include "nspr.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIImageButton.h"
|
||||
#include "nsIToolbarItemHolder.h"
|
||||
#include "nsImageButton.h"
|
||||
#include "nsRepository.h"
|
||||
|
@ -41,10 +39,6 @@ static NS_DEFINE_IID(kCToolbarCID, NS_TOOLBAR_CID);
|
|||
static NS_DEFINE_IID(kCIToolbarIID, NS_ITOOLBAR_IID);
|
||||
static NS_DEFINE_IID(kIToolbarIID, NS_ITOOLBAR_IID);
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
#define TAB_WIDTH 9
|
||||
#define TAB_HEIGHT 42
|
||||
#endif
|
||||
|
||||
const PRInt32 gMaxInfoItems = 32;
|
||||
|
||||
|
@ -103,11 +97,6 @@ nsToolbar::nsToolbar() : nsDataModelWidget(), nsIToolbar(),
|
|||
mWrapItems = PR_FALSE;
|
||||
mDoHorizontalLayout = PR_TRUE;
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
mToolbarMgr = nsnull;
|
||||
#endif
|
||||
|
||||
//mItemDeque = new nsDeque(gItemInfoKiller);
|
||||
mItems = (ToolbarLayoutInfo **) new PRInt32[gMaxInfoItems];
|
||||
mNumItems = 0;
|
||||
}
|
||||
|
@ -117,10 +106,6 @@ nsToolbar::~nsToolbar()
|
|||
{
|
||||
delete mDataModel;
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
NS_IF_RELEASE(mToolbarMgr);
|
||||
#endif
|
||||
|
||||
PRInt32 i;
|
||||
for (i=0;i<mNumItems;i++) {
|
||||
delete mItems[i];
|
||||
|
@ -655,26 +640,6 @@ NS_METHOD nsToolbar::SetBorderType(nsToolbarBorderType aBorderType)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbar::SetToolbarManager(nsIToolbarManager * aToolbarManager)
|
||||
{
|
||||
mToolbarMgr = aToolbarManager;
|
||||
NS_ADDREF(mToolbarMgr);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbar::GetToolbarManager(nsIToolbarManager *& aToolbarManager)
|
||||
{
|
||||
aToolbarManager = mToolbarMgr;
|
||||
NS_ADDREF(aToolbarManager);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
|
@ -922,80 +887,6 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
|
|||
}
|
||||
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
NS_METHOD nsToolbar::CreateTab(nsIWidget *& aTab)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Create the generic toolbar holder for the tab widget
|
||||
nsIToolbarItemHolder * toolbarItemHolder;
|
||||
rv = nsRepository::CreateInstance(kToolbarItemHolderCID, nsnull, kIToolbarItemHolderIID,
|
||||
(void**)&toolbarItemHolder);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Get the ToolbarItem interface for adding it to the toolbar
|
||||
nsIToolbarItem * toolbarItem;
|
||||
if (NS_OK != toolbarItemHolder->QueryInterface(kIToolbarItemIID,(void**)&toolbarItem)) {
|
||||
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(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(this, rt, NULL, NULL);
|
||||
widget->Show(PR_TRUE);
|
||||
widget->SetClientData(NS_STATIC_CAST(void*, this));
|
||||
|
||||
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(tab);
|
||||
NS_RELEASE(toolbarItem);
|
||||
NS_RELEASE(toolbarItemHolder);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// PaintBackgroundImage
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "nsIToolbar.h" //*** not for long
|
||||
#include "nsIContentConnector.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsIImageButton.h"
|
||||
#include "nsIToolbarItem.h"
|
||||
#include "nsDataModelWidget.h"
|
||||
|
||||
|
@ -71,10 +70,6 @@ public:
|
|||
NS_IMETHOD SetMargin(PRInt32 aMargin);
|
||||
NS_IMETHOD SetLastItemIsRightJustified(const PRBool & aState);
|
||||
NS_IMETHOD SetNextLastItemIsStretchy(const PRBool & aState);
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
NS_IMETHOD SetToolbarManager(nsIToolbarManager * aToolbarManager);
|
||||
NS_IMETHOD GetToolbarManager(nsIToolbarManager *& aToolbarManager);
|
||||
#endif
|
||||
NS_IMETHOD SetBorderType(nsToolbarBorderType aBorderType);
|
||||
NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
@ -117,10 +112,6 @@ public:
|
|||
|
||||
NS_IMETHOD GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight,
|
||||
PRInt32& aWidth, PRInt32& aHeight);
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
NS_IMETHOD CreateTab(nsIWidget *& aTab);
|
||||
#endif
|
||||
|
||||
// Override the widget creation method
|
||||
NS_IMETHOD Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
|
@ -160,10 +151,6 @@ protected:
|
|||
PRBool mWrapItems;
|
||||
PRBool mDoHorizontalLayout;
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
nsIToolbarManager * mToolbarMgr;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsToolbar_h___ */
|
||||
|
|
|
@ -18,13 +18,11 @@
|
|||
|
||||
#include "nsIToolbar.h"
|
||||
#include "nsToolbarManager.h"
|
||||
#include "nsIToolbarManagerListener.h"
|
||||
#include "nsIToolbarItemHolder.h"
|
||||
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIImageButton.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsImageButton.h"
|
||||
|
||||
|
@ -59,26 +57,19 @@ const PRInt32 kMaxNumToolbars = 32;
|
|||
//--------------------------------------------------------------------
|
||||
//-- nsToolbarManager Constructor
|
||||
//--------------------------------------------------------------------
|
||||
nsToolbarManager::nsToolbarManager() : ChildWindow(), nsIToolbarManager(), nsIImageButtonListener(),
|
||||
mGrippyHilighted(kNoGrippyHilighted), mNumToolbars(0), mNumTabsSave(0)
|
||||
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];
|
||||
mTabsSave = new TabInfo* [kMaxNumToolbars];
|
||||
|
||||
PRInt32 i;
|
||||
for (i=0;i<kMaxNumToolbars;i++) {
|
||||
mTabsSave[i] = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
nsToolbarManager::~nsToolbarManager()
|
||||
{
|
||||
delete [] mToolbars;
|
||||
delete [] mTabsSave;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
@ -92,11 +83,6 @@ nsresult nsToolbarManager::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kCIImageButtonListenerIID)) {
|
||||
*aInstancePtr = (void*) (nsIImageButtonListener *)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIContentConnectorIID)) {
|
||||
*aInstancePtr = (void*) (nsIContentConnector *)this;
|
||||
AddRef();
|
||||
|
@ -106,6 +92,11 @@ nsresult nsToolbarManager::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// [static] HandleToolbarMgrEvent
|
||||
//
|
||||
// Static event handler function to target events to the correct widget
|
||||
//
|
||||
static nsEventStatus PR_CALLBACK
|
||||
HandleToolbarMgrEvent ( nsGUIEvent *aEvent )
|
||||
{
|
||||
|
@ -169,6 +160,9 @@ nsToolbarManager::SetContentRoot(nsIContent* pContent)
|
|||
nsEventStatus
|
||||
nsToolbarManager::HandleEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
if ( !aEvent )
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
switch ( aEvent->message ) {
|
||||
case NS_PAINT:
|
||||
{
|
||||
|
@ -186,7 +180,11 @@ nsToolbarManager::HandleEvent(nsGUIEvent *aEvent)
|
|||
ctx->CreateDrawingSurface(&r, 0, ds);
|
||||
ctx->SelectOffScreenDrawingSurface(ds);
|
||||
|
||||
//*** Paint the grippy bar for each toolbar
|
||||
// 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);
|
||||
|
@ -195,10 +193,15 @@ nsToolbarManager::HandleEvent(nsGUIEvent *aEvent)
|
|||
}
|
||||
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;
|
||||
|
@ -210,86 +213,15 @@ nsToolbarManager::HandleEvent(nsGUIEvent *aEvent)
|
|||
} // HandleEvent
|
||||
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::AddTabToManager(nsIToolbar * aToolbar,
|
||||
const nsString& aUpURL,
|
||||
const nsString& aPressedURL,
|
||||
const nsString& aDisabledURL,
|
||||
const nsString& aRollOverURL)
|
||||
{
|
||||
DebugStr("\pnsToolbarManager::AddTabToManager");
|
||||
if (mNumTabsSave > 0) {
|
||||
TabInfo * tabInfo = mTabsSave[--mNumTabsSave];
|
||||
tabInfo->mToolbar = aToolbar;
|
||||
mTabs[mNumTabs++] = tabInfo;
|
||||
|
||||
nsIWidget * widget;
|
||||
if (NS_OK == tabInfo->mTab->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||
widget->Show(PR_TRUE);
|
||||
NS_RELEASE(widget);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIImageButton * tab;
|
||||
nsresult rv = nsRepository::CreateInstance(kImageButtonCID, nsnull, kIImageButtonIID,
|
||||
(void**)&tab);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsRect rt(0, 0, EXPAND_TAB_WIDTH, EXPAND_TAB_HEIGHT);
|
||||
|
||||
//nsIWidget* parent = nsnull;
|
||||
//if (aParent != nsnull)
|
||||
// aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||
|
||||
nsIWidget* parent;
|
||||
if (NS_OK != QueryInterface(kIWidgetIID,(void**)&parent)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIWidget * widget;
|
||||
if (NS_OK == tab->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||
widget->Create(parent, rt, NULL, NULL);
|
||||
widget->Show(PR_TRUE);
|
||||
|
||||
widget->Resize(0, 1, EXPAND_TAB_WIDTH, EXPAND_TAB_HEIGHT, PR_FALSE);
|
||||
widget->SetClientData((void *)parent);
|
||||
|
||||
tab->SetBorderWidth(0);
|
||||
tab->SetBorderOffset(0);
|
||||
tab->SetShowBorder(PR_FALSE);
|
||||
tab->SetShowText(PR_FALSE);
|
||||
tab->SetLabel("");
|
||||
tab->SetImageDimensions(rt.width, rt.height);
|
||||
tab->SetImageURLs(aUpURL, aPressedURL, aDisabledURL, aRollOverURL);
|
||||
tab->AddListener(this);
|
||||
|
||||
mTabs[mNumTabs] = new TabInfo;
|
||||
mTabs[mNumTabs]->mTab = tab;
|
||||
mTabs[mNumTabs++]->mToolbar = aToolbar;
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
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++;
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
aToolbar->SetToolbarManager(this);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -310,35 +242,12 @@ NS_METHOD nsToolbarManager::InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anInde
|
|||
// Insert the new widget
|
||||
mToolbars[downToInx] = aToolbar;
|
||||
mTabs[downToInx].mToolbar = aToolbar; // hook this toolbar up to a grippy
|
||||
mTabs[mNumToolbars].mCollapsed = PR_FALSE;
|
||||
mNumToolbars++;
|
||||
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
aToolbar->SetToolbarManager(this);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::GetTabIndex(nsIImageButton * aTab, PRInt32 &anIndex)
|
||||
{
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
anIndex = 0;
|
||||
PRInt32 i = 0;
|
||||
while (i < mNumTabs) {
|
||||
if (mTabs[i]->mTab == aTab) {
|
||||
for (anIndex=0;anIndex<mNumToolbars;anIndex++) {
|
||||
if (mToolbars[anIndex] == mTabs[i]->mToolbar) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::GetNumToolbars(PRInt32 & aNumToolbars)
|
||||
|
@ -360,115 +269,73 @@ NS_METHOD nsToolbarManager::GetToolbarAt(nsIToolbar*& aToolbar, PRInt32 anIndex)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::CollapseToolbar(nsIToolbar * aToolbar)
|
||||
|
||||
//
|
||||
// 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 ( aToolbar );
|
||||
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);
|
||||
// AddTabToManager(aToolbar, mExpandUpURL, mExpandPressedURL, mExpandDisabledURL, mExpandRollOverURL);
|
||||
|
||||
DoLayout();
|
||||
|
||||
if ( mListener )
|
||||
mListener->NotifyToolbarManagerChangedSize(this);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
} // CollapseToolbar
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::ExpandToolbar(nsIToolbar * aToolbar)
|
||||
|
||||
//
|
||||
// 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 )
|
||||
{
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
PRInt32 inx = 0;
|
||||
PRBool found = PR_FALSE;
|
||||
nsIWidget * toolbarWidget;
|
||||
|
||||
if (NS_OK == aToolbar->QueryInterface(kIWidgetIID,(void**)&toolbarWidget)) {
|
||||
PRInt32 i;
|
||||
for (i=0;i<mNumTabs;i++) {
|
||||
if (mTabs[i]->mToolbar == aToolbar) {
|
||||
inx = i;
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
PRInt32 i;
|
||||
TabInfo * tabInfo = mTabs[inx];
|
||||
mTabsSave[mNumTabsSave++] = tabInfo;
|
||||
tabInfo->mToolbar = nsnull;
|
||||
|
||||
mNumTabs--;
|
||||
for (i=inx;i<mNumTabs;i++) {
|
||||
mTabs[i] = mTabs[i+1];
|
||||
}
|
||||
nsIWidget * tabWidget;
|
||||
if (NS_OK == tabInfo->mTab->QueryInterface(kIWidgetIID,(void**)&tabWidget)) {
|
||||
tabWidget->Show(PR_FALSE);
|
||||
NS_RELEASE(tabWidget);
|
||||
}
|
||||
}
|
||||
toolbarWidget->Show(PR_TRUE);
|
||||
//DoLayout();
|
||||
if (nsnull != mListener) {
|
||||
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);
|
||||
}
|
||||
NS_RELEASE(toolbarWidget);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
} // ExpandToolbar
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::NotifyImageButtonEvent(nsIImageButton * aImgBtn,
|
||||
nsGUIEvent * aEvent)
|
||||
{
|
||||
#if GRIPPYS_NOT_WIDGETS
|
||||
if (aEvent->message != NS_MOUSE_LEFT_BUTTON_UP) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// First check to see if it is one of our tabs
|
||||
// meaning its a tollbar expansion
|
||||
PRInt32 index;
|
||||
if (NS_OK == GetTabIndex(aImgBtn, index)) {
|
||||
nsIToolbar * tb;
|
||||
GetToolbarAt(tb, index);
|
||||
if (nsnull != tb) {
|
||||
ExpandToolbar(tb);
|
||||
NS_RELEASE(tb);
|
||||
}
|
||||
}
|
||||
|
||||
// If not then a toolbar is collapsing
|
||||
PRInt32 i;
|
||||
for (i=0;i<mNumToolbars;i++) {
|
||||
nsIToolbar * toolbar = mToolbars[i];
|
||||
nsIToolbarItem * item;
|
||||
if (NS_OK == toolbar->GetItemAt(item, 0)) {
|
||||
nsIWidget * widget;
|
||||
if (NS_OK == item->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||
if (widget == aEvent->widget) {
|
||||
CollapseToolbar(toolbar);
|
||||
}
|
||||
NS_RELEASE(widget);
|
||||
}
|
||||
NS_RELEASE(item);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::AddToolbarListener(nsIToolbarManagerListener * aListener)
|
||||
{
|
||||
mListener = aListener;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbarManager::SetCollapseTabURLs(const nsString& aUpURL,
|
||||
const nsString& aPressedURL,
|
||||
|
@ -524,7 +391,7 @@ NS_METHOD nsToolbarManager::DoLayout()
|
|||
const kGrippyIndent = 10;
|
||||
|
||||
// First layout all the items
|
||||
for (i=0;i<mNumToolbars;i++) {
|
||||
for (i=0;i<mNumToolbars;++i) {
|
||||
PRBool visible;
|
||||
mToolbars[i]->IsVisible(visible);
|
||||
if (visible) {
|
||||
|
@ -540,29 +407,26 @@ const kGrippyIndent = 10;
|
|||
|
||||
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 GRIPPYS_NOT_WIDGETS
|
||||
nsRect rect;
|
||||
x = 0;
|
||||
for (i=0;i<mNumTabs;i++) {
|
||||
nsRect rect;
|
||||
nsIWidget * widget;
|
||||
if (NS_OK == mTabs[i]->mTab->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||
widget->GetBounds(rect);
|
||||
rect.x = x;
|
||||
rect.y = y;
|
||||
widget->Resize(rect.x, rect.y, rect.width, rect.height, PR_TRUE);
|
||||
x += rect.width;
|
||||
NS_RELEASE(widget);
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -572,6 +436,7 @@ 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;
|
||||
|
@ -601,9 +466,10 @@ NS_METHOD nsToolbarManager::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
|
|||
}
|
||||
}
|
||||
|
||||
if (mNumToolbars > 0) {
|
||||
// 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;
|
||||
}
|
||||
|
@ -664,7 +530,8 @@ nsToolbarManager :: DrawGrippies ( nsIRenderingContext* aContext ) const
|
|||
else
|
||||
widget->GetPreferredSize(width, height);
|
||||
|
||||
DrawGrippy ( aContext, mTabs[i].mBoundingRect, PR_FALSE );
|
||||
if ( ! mTabs[i].mCollapsed )
|
||||
DrawGrippy ( aContext, mTabs[i].mBoundingRect, PR_FALSE );
|
||||
|
||||
y += height;
|
||||
}
|
||||
|
@ -730,9 +597,36 @@ nsToolbarManager :: OnMouseMove ( nsPoint & aMouseLoc )
|
|||
|
||||
|
||||
//
|
||||
// OnMouseMove
|
||||
// OnMouseLeftClick
|
||||
//
|
||||
// Handle mouse move events for hilighting and unhilighting the grippies
|
||||
// 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 ( )
|
||||
|
@ -744,4 +638,4 @@ nsToolbarManager :: OnMouseExit ( )
|
|||
mGrippyHilighted = kNoGrippyHilighted;
|
||||
}
|
||||
}
|
||||
} // OnMouseMove
|
||||
} // OnMouseExit
|
|
@ -21,24 +21,26 @@
|
|||
|
||||
#include "nsIImageRequest.h"
|
||||
#include "nsIToolbarManager.h"
|
||||
#include "nsIToolbarManagerListener.h"
|
||||
#include "nsIToolbarItem.h"
|
||||
#include "nsIToolbar.h"
|
||||
#include "nsIToolbarManagerListener.h" // needed for VC4.2
|
||||
#include "nsIContentConnector.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsIImageButtonListener.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsIImageButton;
|
||||
class nsIWidget;
|
||||
|
||||
struct nsRect;
|
||||
|
||||
|
||||
struct TabInfo {
|
||||
TabInfo ( ) : mCollapsed(PR_TRUE), mToolbarHeight(0) { };
|
||||
|
||||
nsCOMPtr<nsIToolbar> mToolbar;
|
||||
nsRect mBoundingRect;
|
||||
PRBool mCollapsed;
|
||||
unsigned int mToolbarHeight;
|
||||
};
|
||||
|
||||
|
||||
|
@ -55,8 +57,7 @@ struct TabInfo {
|
|||
//------------------------------------------------------------
|
||||
class nsToolbarManager : public ChildWindow,
|
||||
public nsIToolbarManager, //*** for now
|
||||
public nsIContentConnector,
|
||||
public nsIImageButtonListener
|
||||
public nsIContentConnector
|
||||
{
|
||||
public:
|
||||
nsToolbarManager();
|
||||
|
@ -70,11 +71,8 @@ public:
|
|||
|
||||
NS_IMETHOD AddToolbar(nsIToolbar* aToolbar);
|
||||
NS_IMETHOD InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anIndex);
|
||||
NS_IMETHOD GetTabIndex(nsIImageButton * aTab, PRInt32 &anIndex);
|
||||
NS_IMETHOD GetNumToolbars(PRInt32 & aNumToolbars);
|
||||
NS_IMETHOD GetToolbarAt(nsIToolbar*& aToolbar, PRInt32 anIndex);
|
||||
NS_IMETHOD CollapseToolbar(nsIToolbar * aToolbar);
|
||||
NS_IMETHOD ExpandToolbar(nsIToolbar * aToolbar);
|
||||
NS_IMETHOD AddToolbarListener(nsIToolbarManagerListener * aListener);
|
||||
NS_IMETHOD DoLayout();
|
||||
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
|
||||
|
@ -94,10 +92,6 @@ public:
|
|||
const nsString& aDisabledURL,
|
||||
const nsString& aRollOverURL);
|
||||
|
||||
// nsIImageButtonListener
|
||||
NS_IMETHOD NotifyImageButtonEvent(nsIImageButton * aImgBtn,
|
||||
nsGUIEvent * aEvent);
|
||||
|
||||
// Override the widget creation method
|
||||
NS_IMETHOD Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
|
@ -114,8 +108,12 @@ protected:
|
|||
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;
|
||||
|
||||
|
@ -139,10 +137,8 @@ protected:
|
|||
PRInt32 mNumToolbars;
|
||||
|
||||
TabInfo mTabs[10];
|
||||
int mGrippyHilighted; // used to indicate which grippy the mouse is inside
|
||||
|
||||
TabInfo ** mTabsSave;
|
||||
PRInt32 mNumTabsSave;
|
||||
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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче