forked from mirrors/gecko-dev
Fixed menus and add DispatchEvent to nsIWidget Interface.
This commit is contained in:
parent
b01db804a6
commit
14703299e4
14 changed files with 211 additions and 78 deletions
|
|
@ -533,7 +533,7 @@ class nsIWidget : public nsISupports {
|
||||||
* Dispatches and event to the widget
|
* Dispatches and event to the widget
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD DispatchEvent(nsGUIEvent* event) = 0;
|
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "nsMenu.h"
|
#include "nsMenu.h"
|
||||||
#include "nsIMenu.h"
|
#include "nsIMenu.h"
|
||||||
|
#include "nsIMenuItem.h"
|
||||||
|
|
||||||
#include "nsToolkit.h"
|
#include "nsToolkit.h"
|
||||||
#include "nsColor.h"
|
#include "nsColor.h"
|
||||||
|
|
@ -32,8 +33,9 @@
|
||||||
#include "nsRect.h"
|
#include "nsRect.h"
|
||||||
#include "nsGfxCIID.h"
|
#include "nsGfxCIID.h"
|
||||||
|
|
||||||
static NS_DEFINE_IID(kMenuIID, NS_IMENU_IID);
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
NS_IMPL_ISUPPORTS(nsMenu, kMenuIID)
|
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsMenu, kIMenuIID)
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
|
@ -45,7 +47,8 @@ nsMenu::nsMenu() : nsIMenu()
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
mNumMenuItems = 0;
|
mNumMenuItems = 0;
|
||||||
mMenu = nsnull;
|
mMenu = nsnull;
|
||||||
//mParent = nsnull;
|
mMenuBarParent = nsnull;
|
||||||
|
mMenuParent = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -55,7 +58,8 @@ nsMenu::nsMenu() : nsIMenu()
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
nsMenu::~nsMenu()
|
nsMenu::~nsMenu()
|
||||||
{
|
{
|
||||||
//NS_IF_RELEASE(mParent);
|
NS_IF_RELEASE(mMenuBarParent);
|
||||||
|
NS_IF_RELEASE(mMenuParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,8 +70,8 @@ nsMenu::~nsMenu()
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
NS_METHOD nsMenu::Create(nsIMenuBar *aParent, const nsString &aLabel)
|
NS_METHOD nsMenu::Create(nsIMenuBar *aParent, const nsString &aLabel)
|
||||||
{
|
{
|
||||||
//mParent = aParent;
|
mMenuBarParent = aParent;
|
||||||
//NS_ADDREF(mParent);
|
NS_ADDREF(mMenuBarParent);
|
||||||
|
|
||||||
mLabel = aLabel;
|
mLabel = aLabel;
|
||||||
mMenu = CreateMenu();
|
mMenu = CreateMenu();
|
||||||
|
|
@ -79,8 +83,8 @@ NS_METHOD nsMenu::Create(nsIMenuBar *aParent, const nsString &aLabel)
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
NS_METHOD nsMenu::Create(nsIMenu *aParent, const nsString &aLabel)
|
NS_METHOD nsMenu::Create(nsIMenu *aParent, const nsString &aLabel)
|
||||||
{
|
{
|
||||||
//mParent = aParent;
|
mMenuParent = aParent;
|
||||||
//NS_ADDREF(mParent);
|
NS_ADDREF(mMenuParent);
|
||||||
mLabel = aLabel;
|
mLabel = aLabel;
|
||||||
|
|
||||||
mMenu = CreateMenu();
|
mMenu = CreateMenu();
|
||||||
|
|
@ -89,6 +93,20 @@ NS_METHOD nsMenu::Create(nsIMenu *aParent, const nsString &aLabel)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::GetParent(nsISupports*& aParent)
|
||||||
|
{
|
||||||
|
|
||||||
|
aParent = nsnull;
|
||||||
|
if (nsnull != mMenuParent) {
|
||||||
|
return mMenuParent->QueryInterface(kISupportsIID,(void**)&aParent);
|
||||||
|
} else if (nsnull != mMenuBarParent) {
|
||||||
|
return mMenuBarParent->QueryInterface(kISupportsIID,(void**)&aParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
NS_METHOD nsMenu::GetLabel(nsString &aText)
|
NS_METHOD nsMenu::GetLabel(nsString &aText)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ public:
|
||||||
NS_IMETHOD Create(nsIMenu * aParent, const nsString &aLabel);
|
NS_IMETHOD Create(nsIMenu * aParent, const nsString &aLabel);
|
||||||
|
|
||||||
// nsIMenu Methods
|
// nsIMenu Methods
|
||||||
|
NS_IMETHOD GetParent(nsISupports *&aParent);
|
||||||
NS_IMETHOD GetLabel(nsString &aText);
|
NS_IMETHOD GetLabel(nsString &aText);
|
||||||
NS_IMETHOD AddItem(const nsString &aText);
|
NS_IMETHOD AddItem(const nsString &aText);
|
||||||
NS_IMETHOD AddItem(nsIMenuItem * aMenuItem);
|
NS_IMETHOD AddItem(nsIMenuItem * aMenuItem);
|
||||||
|
|
@ -61,8 +62,8 @@ protected:
|
||||||
PRUint32 mNumMenuItems;
|
PRUint32 mNumMenuItems;
|
||||||
HMENU mMenu;
|
HMENU mMenu;
|
||||||
|
|
||||||
//nsIMenuBar * mMenuBarParent;
|
nsIMenuBar * mMenuBarParent;
|
||||||
//nsIMenu * mMenuParent;
|
nsIMenu * mMenuParent;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,13 @@ NS_METHOD nsMenuBar::Create(nsIWidget *aParent)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::GetParent(nsIWidget *&aParent)
|
||||||
|
{
|
||||||
|
aParent = mParent;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
|
NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ public:
|
||||||
NS_IMETHOD Create(nsIWidget * aParent);
|
NS_IMETHOD Create(nsIWidget * aParent);
|
||||||
|
|
||||||
// nsIMenuBar Methods
|
// nsIMenuBar Methods
|
||||||
|
NS_IMETHOD GetParent(nsIWidget *&aParent);
|
||||||
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||||
NS_IMETHOD GetMenuCount(PRUint32 &aCount);
|
NS_IMETHOD GetMenuCount(PRUint32 &aCount);
|
||||||
NS_IMETHOD GetMenuAt(const PRUint32 aCount, nsIMenu *& aMenu);
|
NS_IMETHOD GetMenuAt(const PRUint32 aCount, nsIMenu *& aMenu);
|
||||||
|
|
|
||||||
|
|
@ -20,22 +20,28 @@
|
||||||
#include "nsIMenu.h"
|
#include "nsIMenu.h"
|
||||||
|
|
||||||
#include "nsToolkit.h"
|
#include "nsToolkit.h"
|
||||||
#include "nsColor.h"
|
//#include "nsColor.h"
|
||||||
#include "nsGUIEvent.h"
|
#include "nsGUIEvent.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsStringUtil.h"
|
#include "nsStringUtil.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include "nsIAppShell.h"
|
//#include "nsIAppShell.h"
|
||||||
#include "nsGUIEvent.h"
|
#include "nsGUIEvent.h"
|
||||||
#include "nsIDeviceContext.h"
|
//#include "nsIDeviceContext.h"
|
||||||
#include "nsRect.h"
|
//#include "nsRect.h"
|
||||||
#include "nsGfxCIID.h"
|
//#include "nsGfxCIID.h"
|
||||||
#include "nsIMenu.h"
|
#include "nsIMenu.h"
|
||||||
|
#include "nsIMenuBar.h"
|
||||||
#include "nsIPopUpMenu.h"
|
#include "nsIPopUpMenu.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
|
||||||
static NS_DEFINE_IID(kMenuItemIID, NS_IMENUITEM_IID);
|
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
|
||||||
NS_IMPL_ISUPPORTS(nsMenuItem, kMenuItemIID)
|
static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
|
||||||
|
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -47,6 +53,7 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
mMenu = nsnull;
|
mMenu = nsnull;
|
||||||
|
mTarget = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -57,6 +64,48 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
|
||||||
nsMenuItem::~nsMenuItem()
|
nsMenuItem::~nsMenuItem()
|
||||||
{
|
{
|
||||||
NS_IF_RELEASE(mMenu);
|
NS_IF_RELEASE(mMenu);
|
||||||
|
NS_IF_RELEASE(mTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
|
||||||
|
{
|
||||||
|
nsIWidget * widget = nsnull; // MenuBar's Parent
|
||||||
|
nsIMenu * menu = nsnull;
|
||||||
|
nsIMenuBar * menuBar = nsnull;
|
||||||
|
nsIPopUpMenu * popup = nsnull;
|
||||||
|
nsISupports * parent = aParent;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (NS_OK == parent->QueryInterface(kIMenuIID,(void**)&menu)) {
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
if (NS_OK != menu->GetParent(parent)) {
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
|
||||||
|
} else if (NS_OK == parent->QueryInterface(kIPopUpMenuIID,(void**)&popup)) {
|
||||||
|
if (NS_OK != popup->GetParent(widget)) {
|
||||||
|
widget = nsnull;
|
||||||
|
}
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
NS_RELEASE(popup);
|
||||||
|
return widget;
|
||||||
|
|
||||||
|
} else if (NS_OK == parent->QueryInterface(kIMenuBarIID,(void**)&menuBar)) {
|
||||||
|
if (NS_OK != menuBar->GetParent(widget)) {
|
||||||
|
widget = nsnull;
|
||||||
|
}
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
NS_RELEASE(menuBar);
|
||||||
|
return widget;
|
||||||
|
} else {
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -65,6 +114,15 @@ NS_METHOD nsMenuItem::Create(nsIMenu * aParent, const nsString &aLabel, PRUint32
|
||||||
mCommand = aCommand;
|
mCommand = aCommand;
|
||||||
mLabel = aLabel;
|
mLabel = aLabel;
|
||||||
aParent->AddItem(this);
|
aParent->AddItem(this);
|
||||||
|
|
||||||
|
nsISupports * sups;
|
||||||
|
if (NS_OK == aParent->QueryInterface(kISupportsIID,(void**)&sups)) {
|
||||||
|
mTarget = GetMenuBarParent(sups);
|
||||||
|
NS_RELEASE(sups);
|
||||||
|
} else {
|
||||||
|
mTarget = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,6 +132,11 @@ NS_METHOD nsMenuItem::Create(nsIPopUpMenu * aParent, const nsString &aLabel, PRU
|
||||||
mCommand = aCommand;
|
mCommand = aCommand;
|
||||||
mLabel = aLabel;
|
mLabel = aLabel;
|
||||||
aParent->AddItem(this);
|
aParent->AddItem(this);
|
||||||
|
|
||||||
|
if (NS_OK != aParent->GetParent(mTarget)) {
|
||||||
|
mTarget = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,6 +154,13 @@ NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetTarget(nsIWidget *& aTarget)
|
||||||
|
{
|
||||||
|
aTarget = mTarget;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
NS_METHOD nsMenuItem::GetNativeData(void *& aData)
|
NS_METHOD nsMenuItem::GetNativeData(void *& aData)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,16 @@ public:
|
||||||
// nsIMenuBar Methods
|
// nsIMenuBar Methods
|
||||||
NS_IMETHOD GetLabel(nsString &aText);
|
NS_IMETHOD GetLabel(nsString &aText);
|
||||||
NS_IMETHOD GetCommand(PRUint32 & aCommand);
|
NS_IMETHOD GetCommand(PRUint32 & aCommand);
|
||||||
|
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
|
||||||
NS_IMETHOD GetNativeData(void*& aData);
|
NS_IMETHOD GetNativeData(void*& aData);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
nsIWidget * GetMenuBarParent(nsISupports * aParent);
|
||||||
|
|
||||||
nsString mLabel;
|
nsString mLabel;
|
||||||
PRUint32 mCommand;
|
PRUint32 mCommand;
|
||||||
|
nsIWidget * mTarget;
|
||||||
nsIMenu * mMenu;
|
nsIMenu * mMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -225,4 +225,11 @@ NS_METHOD nsPopUpMenu::GetNativeData(void *& aData)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::GetParent(nsIWidget *& aParent)
|
||||||
|
{
|
||||||
|
aParent = mParent;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ public:
|
||||||
NS_IMETHOD RemoveAll();
|
NS_IMETHOD RemoveAll();
|
||||||
NS_IMETHOD ShowMenu(PRInt32 aX, PRInt32 aY);
|
NS_IMETHOD ShowMenu(PRInt32 aX, PRInt32 aY);
|
||||||
NS_IMETHOD GetNativeData(void*& aData);
|
NS_IMETHOD GetNativeData(void*& aData);
|
||||||
|
NS_IMETHOD GetParent(nsIWidget*& aParent);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ nsToolbar::nsToolbar() : ChildWindow(), nsIToolbar()
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
mMargin = 0;
|
mMargin = 0;
|
||||||
|
mWrapMargin = 15;
|
||||||
mHGap = 0;
|
mHGap = 0;
|
||||||
mVGap = 0;
|
mVGap = 0;
|
||||||
|
|
||||||
|
|
@ -99,7 +100,7 @@ nsToolbar::nsToolbar() : ChildWindow(), nsIToolbar()
|
||||||
mNextLastItemIsStretchy = PR_FALSE;
|
mNextLastItemIsStretchy = PR_FALSE;
|
||||||
mDoDrawFullBorder = PR_FALSE;
|
mDoDrawFullBorder = PR_FALSE;
|
||||||
mWrapItems = PR_FALSE;
|
mWrapItems = PR_FALSE;
|
||||||
mDoHorizontalLayout = PR_FALSE;
|
mDoHorizontalLayout = PR_TRUE;
|
||||||
|
|
||||||
mToolbarMgr = nsnull;
|
mToolbarMgr = nsnull;
|
||||||
|
|
||||||
|
|
@ -261,7 +262,7 @@ NS_METHOD nsToolbar::DoLayout()
|
||||||
nsRect tbRect;
|
nsRect tbRect;
|
||||||
nsWindow::GetBounds(tbRect);
|
nsWindow::GetBounds(tbRect);
|
||||||
|
|
||||||
if (tbRect.width > tbRect.height) {
|
if (mDoHorizontalLayout) {
|
||||||
DoHorizontalLayout(tbRect);
|
DoHorizontalLayout(tbRect);
|
||||||
} else {
|
} else {
|
||||||
DoVerticalLayout(tbRect);
|
DoVerticalLayout(tbRect);
|
||||||
|
|
@ -269,6 +270,13 @@ NS_METHOD nsToolbar::DoLayout()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------
|
||||||
|
NS_METHOD nsToolbar::SetHorizontalLayout(PRBool aDoHorizontalLayout)
|
||||||
|
{
|
||||||
|
mDoHorizontalLayout = aDoHorizontalLayout;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
void nsToolbar::DoVerticalLayout(const nsRect& aTBRect)
|
void nsToolbar::DoVerticalLayout(const nsRect& aTBRect)
|
||||||
{
|
{
|
||||||
|
|
@ -296,7 +304,7 @@ void nsToolbar::DoVerticalLayout(const nsRect& aTBRect)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((y + height + mItems[i]->mGap) > aTBRect.height) && mWrapItems) {
|
if (((y + height + mItems[i]->mGap) > aTBRect.height) && mWrapItems) {
|
||||||
y = 10; // 10 is the "mWrapMargin"
|
y = mWrapMargin;
|
||||||
x += maxWidth;
|
x += maxWidth;
|
||||||
maxWidth = 0;
|
maxWidth = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -408,15 +416,15 @@ void nsToolbar::DoHorizontalLayout(const nsRect& aTBRect)
|
||||||
width = rect.width;
|
width = rect.width;
|
||||||
height = rect.height;
|
height = rect.height;
|
||||||
}
|
}
|
||||||
if (!mItems[i]->mStretchable) {
|
|
||||||
maxHeight = maxHeight > height? maxHeight:height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((x + width + mItems[i]->mGap) > aTBRect.width) && mWrapItems) {
|
if (((x + width + mItems[i]->mGap) > aTBRect.width) && mWrapItems) {
|
||||||
x = 10; // 10 is the "mWrapMargin"
|
x = mMargin + mWrapMargin;
|
||||||
y += maxHeight;
|
y += maxHeight;
|
||||||
maxHeight = 0;
|
maxHeight = 0;
|
||||||
}
|
}
|
||||||
|
if (!mItems[i]->mStretchable) {
|
||||||
|
maxHeight = maxHeight > height? maxHeight:height;
|
||||||
|
}
|
||||||
|
|
||||||
PRInt32 yLoc;
|
PRInt32 yLoc;
|
||||||
if (mWrapItems) {
|
if (mWrapItems) {
|
||||||
|
|
@ -426,6 +434,7 @@ void nsToolbar::DoHorizontalLayout(const nsRect& aTBRect)
|
||||||
yLoc = yLoc > -1 ? yLoc : mMargin;
|
yLoc = yLoc > -1 ? yLoc : mMargin;
|
||||||
}
|
}
|
||||||
// Gap is added before hand because it is the left hand gap
|
// 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;
|
x += mItems[i]->mGap;
|
||||||
if (((i == (mNumItems-1) && !mLastItemIsRightJustified)) || (i != (mNumItems-1))) {
|
if (((i == (mNumItems-1) && !mLastItemIsRightJustified)) || (i != (mNumItems-1))) {
|
||||||
mItems[i]->mItem->SetBounds(x, yLoc, width, height, PR_FALSE);
|
mItems[i]->mItem->SetBounds(x, yLoc, width, height, PR_FALSE);
|
||||||
|
|
@ -522,7 +531,7 @@ NS_METHOD nsToolbar::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
|
||||||
nsRect rect;
|
nsRect rect;
|
||||||
nsWindow::GetBounds(rect);
|
nsWindow::GetBounds(rect);
|
||||||
|
|
||||||
if (rect.width > rect.height) {
|
if (mDoHorizontalLayout) {
|
||||||
aWidth = mMargin*2;
|
aWidth = mMargin*2;
|
||||||
aHeight = 0;
|
aHeight = 0;
|
||||||
PRInt32 i;
|
PRInt32 i;
|
||||||
|
|
@ -776,18 +785,14 @@ NS_METHOD nsToolbar::GetWrapping(PRBool & aDoWrap)
|
||||||
NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight,
|
NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight,
|
||||||
PRInt32& aWidth, PRInt32& aHeight)
|
PRInt32& aWidth, PRInt32& aHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
nsRect rect;
|
nsRect rect;
|
||||||
nsWindow::GetBounds(rect);
|
nsWindow::GetBounds(rect);
|
||||||
|
|
||||||
// Check to see if it is a horizontal or vertical toolbar
|
|
||||||
PRBool isHorizontal = rect.width > rect.height;
|
|
||||||
|
|
||||||
PRInt32 rows = 1;
|
PRInt32 rows = 1;
|
||||||
PRInt32 calcSize = mMargin;
|
PRInt32 calcSize = mMargin;
|
||||||
PRInt32 maxSize = 0;
|
PRInt32 maxSize = 0;
|
||||||
PRInt32 maxRowSize = 0;
|
PRInt32 maxRowSize = 0;
|
||||||
PRInt32 currentSize = mMargin;
|
PRInt32 currentSize = mMargin; // the current height of the "growing" toolbar
|
||||||
|
|
||||||
PRInt32 i;
|
PRInt32 i;
|
||||||
// Loop throgh each item in the toolbar
|
// Loop throgh each item in the toolbar
|
||||||
|
|
@ -808,11 +813,11 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
|
||||||
|
|
||||||
// If it is greater than the suggested width than add 1 to the number of rows
|
// If it is greater than the suggested width than add 1 to the number of rows
|
||||||
// and start the x over
|
// and start the x over
|
||||||
if (isHorizontal) {
|
if (mDoHorizontalLayout) {
|
||||||
if ((calcSize + width + mItems[i]->mGap) > aSuggestedWidth) {
|
if ((calcSize + width + mItems[i]->mGap) > aSuggestedWidth) {
|
||||||
currentSize += maxRowSize;
|
currentSize += maxRowSize;
|
||||||
maxRowSize = 0;
|
maxRowSize = 0;
|
||||||
calcSize = mMargin;
|
calcSize = mMargin + mWrapMargin + width + mItems[i]->mGap;
|
||||||
} else {
|
} else {
|
||||||
calcSize += width + mItems[i]->mGap;
|
calcSize += width + mItems[i]->mGap;
|
||||||
}
|
}
|
||||||
|
|
@ -835,7 +840,7 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now set the width and height accordingly
|
// Now set the width and height accordingly
|
||||||
if (isHorizontal) {
|
if (mDoHorizontalLayout) {
|
||||||
aWidth = aSuggestedWidth;
|
aWidth = aSuggestedWidth;
|
||||||
aHeight = currentSize + mMargin + maxRowSize;
|
aHeight = currentSize + mMargin + maxRowSize;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -843,6 +848,8 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
|
||||||
aWidth = currentSize + mMargin + maxRowSize;
|
aWidth = currentSize + mMargin + maxRowSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("aHeight: %d\n", aHeight);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHOD DoLayout();
|
NS_IMETHOD DoLayout();
|
||||||
|
NS_IMETHOD SetHorizontalLayout(PRBool aDoHorizontalLayout);
|
||||||
NS_IMETHOD SetHGap(PRInt32 aGap);
|
NS_IMETHOD SetHGap(PRInt32 aGap);
|
||||||
NS_IMETHOD SetVGap(PRInt32 aGap);
|
NS_IMETHOD SetVGap(PRInt32 aGap);
|
||||||
NS_IMETHOD SetMargin(PRInt32 aMargin);
|
NS_IMETHOD SetMargin(PRInt32 aMargin);
|
||||||
|
|
@ -115,6 +116,7 @@ protected:
|
||||||
PRBool mNextLastItemIsStretchy;
|
PRBool mNextLastItemIsStretchy;
|
||||||
|
|
||||||
PRInt32 mMargin;
|
PRInt32 mMargin;
|
||||||
|
PRInt32 mWrapMargin;
|
||||||
PRInt32 mHGap;
|
PRInt32 mHGap;
|
||||||
PRInt32 mVGap;
|
PRInt32 mVGap;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,10 @@ nsToolbarManager::nsToolbarManager() : ChildWindow(), nsIToolbarManager(), nsIIm
|
||||||
nsToolbarManager::~nsToolbarManager()
|
nsToolbarManager::~nsToolbarManager()
|
||||||
{
|
{
|
||||||
NS_IF_RELEASE(mListener);
|
NS_IF_RELEASE(mListener);
|
||||||
|
PRInt32 i;
|
||||||
|
for (i=0;i<kMaxNumToolbars;i++) {
|
||||||
|
NS_RELEASE(mToolbars[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
@ -298,6 +302,7 @@ NS_METHOD nsToolbarManager::AddToolbar(nsIToolbar* aToolbar)
|
||||||
aToolbar->SetToolbarManager(this);
|
aToolbar->SetToolbarManager(this);
|
||||||
|
|
||||||
AddTabToToolbar(aToolbar);
|
AddTabToToolbar(aToolbar);
|
||||||
|
NS_ADDREF(aToolbar);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -321,6 +326,7 @@ NS_METHOD nsToolbarManager::InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anInde
|
||||||
mToolbars[downToInx] = aToolbar;
|
mToolbars[downToInx] = aToolbar;
|
||||||
mNumToolbars++;
|
mNumToolbars++;
|
||||||
aToolbar->SetToolbarManager(this);
|
aToolbar->SetToolbarManager(this);
|
||||||
|
NS_ADDREF(aToolbar);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -287,21 +287,27 @@ void nsWindow::InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint
|
||||||
//
|
//
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
PRBool nsWindow::DispatchEvent(nsGUIEvent* event)
|
NS_IMETHODIMP nsWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus)
|
||||||
{
|
{
|
||||||
PRBool result = PR_FALSE;
|
aStatus = nsEventStatus_eIgnore;
|
||||||
|
|
||||||
if (nsnull != mEventCallback) {
|
if (nsnull != mEventCallback) {
|
||||||
result = ConvertStatus((*mEventCallback)(event));
|
aStatus = (*mEventCallback)(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch to event listener if event was not consumed
|
// Dispatch to event listener if event was not consumed
|
||||||
if ((result != PR_TRUE) && (nsnull != mEventListener)) {
|
if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) {
|
||||||
return ConvertStatus(mEventListener->ProcessEvent(*event));
|
aStatus = mEventListener->ProcessEvent(*event);
|
||||||
}
|
|
||||||
else {
|
|
||||||
return(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsWindow::DispatchWindowEvent(nsGUIEvent* event)
|
||||||
|
{
|
||||||
|
nsEventStatus status;
|
||||||
|
DispatchEvent(event, status);
|
||||||
|
return ConvertStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -315,7 +321,8 @@ PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg)
|
||||||
nsGUIEvent event;
|
nsGUIEvent event;
|
||||||
event.eventStructType = NS_GUI_EVENT;
|
event.eventStructType = NS_GUI_EVENT;
|
||||||
InitEvent(event, aMsg);
|
InitEvent(event, aMsg);
|
||||||
return(DispatchEvent(&event));
|
|
||||||
|
return DispatchWindowEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -1168,7 +1175,8 @@ PRBool nsWindow::OnKey(PRUint32 aEventType, PRUint32 aKeyCode)
|
||||||
event.isControl = mIsControlDown;
|
event.isControl = mIsControlDown;
|
||||||
event.isAlt = mIsAltDown;
|
event.isAlt = mIsAltDown;
|
||||||
event.eventStructType = NS_KEY_EVENT;
|
event.eventStructType = NS_KEY_EVENT;
|
||||||
return(DispatchEvent(&event));
|
|
||||||
|
return DispatchWindowEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -1197,10 +1205,10 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
||||||
WORD wNotifyCode = HIWORD(wParam); // notification code
|
WORD wNotifyCode = HIWORD(wParam); // notification code
|
||||||
if (wNotifyCode == 0) { // Menu selection
|
if (wNotifyCode == 0) { // Menu selection
|
||||||
nsMenuEvent event;
|
nsMenuEvent event;
|
||||||
event.menuItem = LOWORD(wParam);
|
event.mCommand = LOWORD(wParam);
|
||||||
event.eventStructType = NS_MENU_EVENT;
|
event.eventStructType = NS_MENU_EVENT;
|
||||||
InitEvent(event, NS_MENU_SELECTED);
|
InitEvent(event, NS_MENU_SELECTED);
|
||||||
result = DispatchEvent(&event);
|
result = DispatchWindowEvent(&event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -1223,7 +1231,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
||||||
InitEvent(event, NS_SHOW_TOOLTIP);
|
InitEvent(event, NS_SHOW_TOOLTIP);
|
||||||
event.tipIndex = (PRUint32)wParam;
|
event.tipIndex = (PRUint32)wParam;
|
||||||
event.eventStructType = NS_TOOLTIP_EVENT;
|
event.eventStructType = NS_TOOLTIP_EVENT;
|
||||||
result = DispatchEvent(&event);
|
result = DispatchWindowEvent(&event);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -1598,7 +1606,7 @@ PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY)
|
||||||
event.point.x = aX;
|
event.point.x = aX;
|
||||||
event.point.y = aY;
|
event.point.y = aY;
|
||||||
event.eventStructType = NS_GUI_EVENT;
|
event.eventStructType = NS_GUI_EVENT;
|
||||||
return DispatchEvent(&event);
|
return DispatchWindowEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
@ -1637,7 +1645,7 @@ PRBool nsWindow::OnPaint()
|
||||||
if (NS_OK == nsRepository::CreateInstance(kRenderingContextCID, nsnull, kRenderingContextIID, (void **)&event.renderingContext))
|
if (NS_OK == nsRepository::CreateInstance(kRenderingContextCID, nsnull, kRenderingContextIID, (void **)&event.renderingContext))
|
||||||
{
|
{
|
||||||
event.renderingContext->Init(mContext, this);
|
event.renderingContext->Init(mContext, this);
|
||||||
result = DispatchEvent(&event);
|
result = DispatchWindowEvent(&event);
|
||||||
NS_RELEASE(event.renderingContext);
|
NS_RELEASE(event.renderingContext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -1668,7 +1676,7 @@ PRBool nsWindow::OnResize(nsRect &aWindowRect)
|
||||||
InitEvent(event, NS_SIZE);
|
InitEvent(event, NS_SIZE);
|
||||||
event.windowSize = &aWindowRect;
|
event.windowSize = &aWindowRect;
|
||||||
event.eventStructType = NS_SIZE_EVENT;
|
event.eventStructType = NS_SIZE_EVENT;
|
||||||
return(DispatchEvent(&event));
|
return DispatchWindowEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PR_FALSE;
|
return PR_FALSE;
|
||||||
|
|
@ -1702,7 +1710,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint)
|
||||||
// call the event callback
|
// call the event callback
|
||||||
if (nsnull != mEventCallback) {
|
if (nsnull != mEventCallback) {
|
||||||
|
|
||||||
result = DispatchEvent(&event);
|
result = DispatchWindowEvent(&event);
|
||||||
|
|
||||||
//printf("**result=%d%\n",result);
|
//printf("**result=%d%\n",result);
|
||||||
if (aEventType == NS_MOUSE_MOVE) {
|
if (aEventType == NS_MOUSE_MOVE) {
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ public:
|
||||||
NS_IMETHOD EndResizingChildren(void);
|
NS_IMETHOD EndResizingChildren(void);
|
||||||
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
|
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
|
||||||
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
|
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
|
||||||
|
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
|
||||||
|
|
||||||
virtual void SetUpForPaint(HDC aHDC);
|
virtual void SetUpForPaint(HDC aHDC);
|
||||||
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
||||||
|
|
@ -135,6 +136,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
|
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
|
||||||
|
virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
|
||||||
|
|
||||||
// Allow Derived classes to modify the height that is passed
|
// Allow Derived classes to modify the height that is passed
|
||||||
// when the window is created or resized.
|
// when the window is created or resized.
|
||||||
|
|
@ -164,7 +166,6 @@ protected:
|
||||||
DWORD GetBorderStyle(nsBorderStyle aBorderStyle);
|
DWORD GetBorderStyle(nsBorderStyle aBorderStyle);
|
||||||
|
|
||||||
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
|
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
|
||||||
PRBool DispatchEvent(nsGUIEvent* event);
|
|
||||||
PRBool DispatchStandardEvent(PRUint32 aMsg);
|
PRBool DispatchStandardEvent(PRUint32 aMsg);
|
||||||
void AddTooltip(HWND hwndOwner, nsRect* aRect, int aId);
|
void AddTooltip(HWND hwndOwner, nsRect* aRect, int aId);
|
||||||
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
|
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue