зеркало из https://github.com/mozilla/gecko-dev.git
Fixed menus and add DispatchEvent to nsIWidget Interface.
This commit is contained in:
Родитель
b01db804a6
Коммит
14703299e4
|
@ -533,7 +533,7 @@ class nsIWidget : public nsISupports {
|
|||
* 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 "nsIMenu.h"
|
||||
#include "nsIMenuItem.h"
|
||||
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
|
@ -32,8 +33,9 @@
|
|||
#include "nsRect.h"
|
||||
#include "nsGfxCIID.h"
|
||||
|
||||
static NS_DEFINE_IID(kMenuIID, NS_IMENU_IID);
|
||||
NS_IMPL_ISUPPORTS(nsMenu, kMenuIID)
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
|
||||
NS_IMPL_ISUPPORTS(nsMenu, kIMenuIID)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
|
@ -43,9 +45,10 @@ NS_IMPL_ISUPPORTS(nsMenu, kMenuIID)
|
|||
nsMenu::nsMenu() : nsIMenu()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mNumMenuItems = 0;
|
||||
mMenu = nsnull;
|
||||
//mParent = nsnull;
|
||||
mNumMenuItems = 0;
|
||||
mMenu = nsnull;
|
||||
mMenuBarParent = nsnull;
|
||||
mMenuParent = nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -55,7 +58,8 @@ nsMenu::nsMenu() : nsIMenu()
|
|||
//-------------------------------------------------------------------------
|
||||
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)
|
||||
{
|
||||
//mParent = aParent;
|
||||
//NS_ADDREF(mParent);
|
||||
mMenuBarParent = aParent;
|
||||
NS_ADDREF(mMenuBarParent);
|
||||
|
||||
mLabel = aLabel;
|
||||
mMenu = CreateMenu();
|
||||
|
@ -79,8 +83,8 @@ NS_METHOD nsMenu::Create(nsIMenuBar *aParent, const nsString &aLabel)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::Create(nsIMenu *aParent, const nsString &aLabel)
|
||||
{
|
||||
//mParent = aParent;
|
||||
//NS_ADDREF(mParent);
|
||||
mMenuParent = aParent;
|
||||
NS_ADDREF(mMenuParent);
|
||||
mLabel = aLabel;
|
||||
|
||||
mMenu = CreateMenu();
|
||||
|
@ -89,6 +93,20 @@ NS_METHOD nsMenu::Create(nsIMenu *aParent, const nsString &aLabel)
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
NS_IMETHOD Create(nsIMenu * aParent, const nsString &aLabel);
|
||||
|
||||
// nsIMenu Methods
|
||||
NS_IMETHOD GetParent(nsISupports *&aParent);
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD AddItem(const nsString &aText);
|
||||
NS_IMETHOD AddItem(nsIMenuItem * aMenuItem);
|
||||
|
@ -61,8 +62,8 @@ protected:
|
|||
PRUint32 mNumMenuItems;
|
||||
HMENU mMenu;
|
||||
|
||||
//nsIMenuBar * mMenuBarParent;
|
||||
//nsIMenu * mMenuParent;
|
||||
nsIMenuBar * mMenuBarParent;
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
NS_IMETHOD Create(nsIWidget * aParent);
|
||||
|
||||
// nsIMenuBar Methods
|
||||
NS_IMETHOD GetParent(nsIWidget *&aParent);
|
||||
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||
NS_IMETHOD GetMenuCount(PRUint32 &aCount);
|
||||
NS_IMETHOD GetMenuAt(const PRUint32 aCount, nsIMenu *& aMenu);
|
||||
|
|
|
@ -20,22 +20,28 @@
|
|||
#include "nsIMenu.h"
|
||||
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
//#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsIAppShell.h"
|
||||
//#include "nsIAppShell.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsGfxCIID.h"
|
||||
//#include "nsIDeviceContext.h"
|
||||
//#include "nsRect.h"
|
||||
//#include "nsGfxCIID.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIMenuBar.h"
|
||||
#include "nsIPopUpMenu.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
static NS_DEFINE_IID(kMenuItemIID, NS_IMENUITEM_IID);
|
||||
NS_IMPL_ISUPPORTS(nsMenuItem, kMenuItemIID)
|
||||
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
|
||||
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)
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -46,7 +52,8 @@ NS_IMPL_ISUPPORTS(nsMenuItem, kMenuItemIID)
|
|||
nsMenuItem::nsMenuItem() : nsIMenuItem()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMenu = nsnull;
|
||||
mMenu = nsnull;
|
||||
mTarget = nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -57,6 +64,48 @@ nsMenuItem::nsMenuItem() : nsIMenuItem()
|
|||
nsMenuItem::~nsMenuItem()
|
||||
{
|
||||
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;
|
||||
mLabel = aLabel;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -74,6 +132,11 @@ NS_METHOD nsMenuItem::Create(nsIPopUpMenu * aParent, const nsString &aLabel, PRU
|
|||
mCommand = aCommand;
|
||||
mLabel = aLabel;
|
||||
aParent->AddItem(this);
|
||||
|
||||
if (NS_OK != aParent->GetParent(mTarget)) {
|
||||
mTarget = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -91,6 +154,13 @@ NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetTarget(nsIWidget *& aTarget)
|
||||
{
|
||||
aTarget = mTarget;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetNativeData(void *& aData)
|
||||
{
|
||||
|
|
|
@ -48,13 +48,17 @@ public:
|
|||
// nsIMenuBar Methods
|
||||
NS_IMETHOD GetLabel(nsString &aText);
|
||||
NS_IMETHOD GetCommand(PRUint32 & aCommand);
|
||||
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
|
||||
NS_IMETHOD GetNativeData(void*& aData);
|
||||
|
||||
|
||||
protected:
|
||||
nsString mLabel;
|
||||
PRUint32 mCommand;
|
||||
nsIMenu * mMenu;
|
||||
nsIWidget * GetMenuBarParent(nsISupports * aParent);
|
||||
|
||||
nsString mLabel;
|
||||
PRUint32 mCommand;
|
||||
nsIWidget * mTarget;
|
||||
nsIMenu * mMenu;
|
||||
};
|
||||
|
||||
#endif // nsMenuItem_h__
|
||||
|
|
|
@ -225,4 +225,11 @@ NS_METHOD nsPopUpMenu::GetNativeData(void *& aData)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsPopUpMenu::GetParent(nsIWidget *& aParent)
|
||||
{
|
||||
aParent = mParent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
NS_IMETHOD RemoveAll();
|
||||
NS_IMETHOD ShowMenu(PRInt32 aX, PRInt32 aY);
|
||||
NS_IMETHOD GetNativeData(void*& aData);
|
||||
NS_IMETHOD GetParent(nsIWidget*& aParent);
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -91,15 +91,16 @@ nsToolbar::nsToolbar() : ChildWindow(), nsIToolbar()
|
|||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mMargin = 0;
|
||||
mHGap = 0;
|
||||
mVGap = 0;
|
||||
mMargin = 0;
|
||||
mWrapMargin = 15;
|
||||
mHGap = 0;
|
||||
mVGap = 0;
|
||||
|
||||
mLastItemIsRightJustified = PR_FALSE;
|
||||
mNextLastItemIsStretchy = PR_FALSE;
|
||||
mDoDrawFullBorder = PR_FALSE;
|
||||
mWrapItems = PR_FALSE;
|
||||
mDoHorizontalLayout = PR_FALSE;
|
||||
mDoHorizontalLayout = PR_TRUE;
|
||||
|
||||
mToolbarMgr = nsnull;
|
||||
|
||||
|
@ -261,7 +262,7 @@ NS_METHOD nsToolbar::DoLayout()
|
|||
nsRect tbRect;
|
||||
nsWindow::GetBounds(tbRect);
|
||||
|
||||
if (tbRect.width > tbRect.height) {
|
||||
if (mDoHorizontalLayout) {
|
||||
DoHorizontalLayout(tbRect);
|
||||
} else {
|
||||
DoVerticalLayout(tbRect);
|
||||
|
@ -269,6 +270,13 @@ NS_METHOD nsToolbar::DoLayout()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
NS_METHOD nsToolbar::SetHorizontalLayout(PRBool aDoHorizontalLayout)
|
||||
{
|
||||
mDoHorizontalLayout = aDoHorizontalLayout;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
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) {
|
||||
y = 10; // 10 is the "mWrapMargin"
|
||||
y = mWrapMargin;
|
||||
x += maxWidth;
|
||||
maxWidth = 0;
|
||||
}
|
||||
|
@ -408,15 +416,15 @@ void nsToolbar::DoHorizontalLayout(const nsRect& aTBRect)
|
|||
width = rect.width;
|
||||
height = rect.height;
|
||||
}
|
||||
if (!mItems[i]->mStretchable) {
|
||||
maxHeight = maxHeight > height? maxHeight:height;
|
||||
}
|
||||
|
||||
if (((x + width + mItems[i]->mGap) > aTBRect.width) && mWrapItems) {
|
||||
x = 10; // 10 is the "mWrapMargin"
|
||||
x = mMargin + mWrapMargin;
|
||||
y += maxHeight;
|
||||
maxHeight = 0;
|
||||
}
|
||||
if (!mItems[i]->mStretchable) {
|
||||
maxHeight = maxHeight > height? maxHeight:height;
|
||||
}
|
||||
|
||||
PRInt32 yLoc;
|
||||
if (mWrapItems) {
|
||||
|
@ -426,6 +434,7 @@ void nsToolbar::DoHorizontalLayout(const nsRect& aTBRect)
|
|||
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);
|
||||
|
@ -522,7 +531,7 @@ NS_METHOD nsToolbar::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
|
|||
nsRect rect;
|
||||
nsWindow::GetBounds(rect);
|
||||
|
||||
if (rect.width > rect.height) {
|
||||
if (mDoHorizontalLayout) {
|
||||
aWidth = mMargin*2;
|
||||
aHeight = 0;
|
||||
PRInt32 i;
|
||||
|
@ -776,18 +785,14 @@ NS_METHOD nsToolbar::GetWrapping(PRBool & aDoWrap)
|
|||
NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt32& aSuggestedHeight,
|
||||
PRInt32& aWidth, PRInt32& aHeight)
|
||||
{
|
||||
|
||||
nsRect 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 calcSize = mMargin;
|
||||
PRInt32 maxSize = 0;
|
||||
PRInt32 maxRowSize = 0;
|
||||
PRInt32 currentSize = mMargin;
|
||||
PRInt32 currentSize = mMargin; // the current height of the "growing" toolbar
|
||||
|
||||
PRInt32 i;
|
||||
// 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
|
||||
// and start the x over
|
||||
if (isHorizontal) {
|
||||
if (mDoHorizontalLayout) {
|
||||
if ((calcSize + width + mItems[i]->mGap) > aSuggestedWidth) {
|
||||
currentSize += maxRowSize;
|
||||
maxRowSize = 0;
|
||||
calcSize = mMargin;
|
||||
calcSize = mMargin + mWrapMargin + width + mItems[i]->mGap;
|
||||
} else {
|
||||
calcSize += width + mItems[i]->mGap;
|
||||
}
|
||||
|
@ -835,7 +840,7 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
|
|||
}
|
||||
|
||||
// Now set the width and height accordingly
|
||||
if (isHorizontal) {
|
||||
if (mDoHorizontalLayout) {
|
||||
aWidth = aSuggestedWidth;
|
||||
aHeight = currentSize + mMargin + maxRowSize;
|
||||
} else {
|
||||
|
@ -843,6 +848,8 @@ NS_METHOD nsToolbar::GetPreferredConstrainedSize(PRInt32& aSuggestedWidth, PRInt
|
|||
aWidth = currentSize + mMargin + maxRowSize;
|
||||
}
|
||||
|
||||
printf("aHeight: %d\n", aHeight);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
|
||||
NS_IMETHOD DoLayout();
|
||||
NS_IMETHOD SetHorizontalLayout(PRBool aDoHorizontalLayout);
|
||||
NS_IMETHOD SetHGap(PRInt32 aGap);
|
||||
NS_IMETHOD SetVGap(PRInt32 aGap);
|
||||
NS_IMETHOD SetMargin(PRInt32 aMargin);
|
||||
|
@ -115,6 +116,7 @@ protected:
|
|||
PRBool mNextLastItemIsStretchy;
|
||||
|
||||
PRInt32 mMargin;
|
||||
PRInt32 mWrapMargin;
|
||||
PRInt32 mHGap;
|
||||
PRInt32 mVGap;
|
||||
|
||||
|
|
|
@ -81,6 +81,10 @@ nsToolbarManager::nsToolbarManager() : ChildWindow(), nsIToolbarManager(), nsIIm
|
|||
nsToolbarManager::~nsToolbarManager()
|
||||
{
|
||||
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);
|
||||
|
||||
AddTabToToolbar(aToolbar);
|
||||
NS_ADDREF(aToolbar);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -321,6 +326,7 @@ NS_METHOD nsToolbarManager::InsertToolbarAt(nsIToolbar* aToolbar, PRInt32 anInde
|
|||
mToolbars[downToInx] = aToolbar;
|
||||
mNumToolbars++;
|
||||
aToolbar->SetToolbarManager(this);
|
||||
NS_ADDREF(aToolbar);
|
||||
|
||||
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) {
|
||||
result = ConvertStatus((*mEventCallback)(event));
|
||||
aStatus = (*mEventCallback)(event);
|
||||
}
|
||||
|
||||
// Dispatch to event listener if event was not consumed
|
||||
if ((result != PR_TRUE) && (nsnull != mEventListener)) {
|
||||
return ConvertStatus(mEventListener->ProcessEvent(*event));
|
||||
}
|
||||
else {
|
||||
return(result);
|
||||
if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) {
|
||||
aStatus = mEventListener->ProcessEvent(*event);
|
||||
}
|
||||
|
||||
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;
|
||||
event.eventStructType = NS_GUI_EVENT;
|
||||
InitEvent(event, aMsg);
|
||||
return(DispatchEvent(&event));
|
||||
|
||||
return DispatchWindowEvent(&event);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -383,7 +390,7 @@ nsWindow::nsWindow() : nsBaseWidget()
|
|||
mPreferredHeight = 0;
|
||||
mFont = nsnull;
|
||||
mIsVisible = PR_FALSE;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -1161,14 +1168,15 @@ BOOL nsWindow::CallMethod(MethodInfo *info)
|
|||
//-------------------------------------------------------------------------
|
||||
PRBool nsWindow::OnKey(PRUint32 aEventType, PRUint32 aKeyCode)
|
||||
{
|
||||
nsKeyEvent event;
|
||||
InitEvent(event, aEventType);
|
||||
event.keyCode = aKeyCode;
|
||||
event.isShift = mIsShiftDown;
|
||||
event.isControl = mIsControlDown;
|
||||
event.isAlt = mIsAltDown;
|
||||
event.eventStructType = NS_KEY_EVENT;
|
||||
return(DispatchEvent(&event));
|
||||
nsKeyEvent event;
|
||||
InitEvent(event, aEventType);
|
||||
event.keyCode = aKeyCode;
|
||||
event.isShift = mIsShiftDown;
|
||||
event.isControl = mIsControlDown;
|
||||
event.isAlt = mIsAltDown;
|
||||
event.eventStructType = NS_KEY_EVENT;
|
||||
|
||||
return DispatchWindowEvent(&event);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -1197,10 +1205,10 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
|||
WORD wNotifyCode = HIWORD(wParam); // notification code
|
||||
if (wNotifyCode == 0) { // Menu selection
|
||||
nsMenuEvent event;
|
||||
event.menuItem = LOWORD(wParam);
|
||||
event.mCommand = LOWORD(wParam);
|
||||
event.eventStructType = NS_MENU_EVENT;
|
||||
InitEvent(event, NS_MENU_SELECTED);
|
||||
result = DispatchEvent(&event);
|
||||
result = DispatchWindowEvent(&event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1223,7 +1231,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
|||
InitEvent(event, NS_SHOW_TOOLTIP);
|
||||
event.tipIndex = (PRUint32)wParam;
|
||||
event.eventStructType = NS_TOOLTIP_EVENT;
|
||||
result = DispatchEvent(&event);
|
||||
result = DispatchWindowEvent(&event);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1598,7 +1606,7 @@ PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY)
|
|||
event.point.x = aX;
|
||||
event.point.y = aY;
|
||||
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))
|
||||
{
|
||||
event.renderingContext->Init(mContext, this);
|
||||
result = DispatchEvent(&event);
|
||||
result = DispatchWindowEvent(&event);
|
||||
NS_RELEASE(event.renderingContext);
|
||||
}
|
||||
else
|
||||
|
@ -1662,16 +1670,16 @@ PRBool nsWindow::OnPaint()
|
|||
//-------------------------------------------------------------------------
|
||||
PRBool nsWindow::OnResize(nsRect &aWindowRect)
|
||||
{
|
||||
// call the event callback
|
||||
if (mEventCallback) {
|
||||
nsSizeEvent event;
|
||||
InitEvent(event, NS_SIZE);
|
||||
event.windowSize = &aWindowRect;
|
||||
event.eventStructType = NS_SIZE_EVENT;
|
||||
return(DispatchEvent(&event));
|
||||
}
|
||||
// call the event callback
|
||||
if (mEventCallback) {
|
||||
nsSizeEvent event;
|
||||
InitEvent(event, NS_SIZE);
|
||||
event.windowSize = &aWindowRect;
|
||||
event.eventStructType = NS_SIZE_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
|
||||
if (nsnull != mEventCallback) {
|
||||
|
||||
result = DispatchEvent(&event);
|
||||
result = DispatchWindowEvent(&event);
|
||||
|
||||
//printf("**result=%d%\n",result);
|
||||
if (aEventType == NS_MOUSE_MOVE) {
|
||||
|
|
|
@ -117,6 +117,7 @@ public:
|
|||
NS_IMETHOD EndResizingChildren(void);
|
||||
NS_IMETHOD GetPreferredSize(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 ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
||||
|
@ -135,6 +136,7 @@ public:
|
|||
protected:
|
||||
|
||||
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
|
||||
// when the window is created or resized.
|
||||
|
@ -164,7 +166,6 @@ protected:
|
|||
DWORD GetBorderStyle(nsBorderStyle aBorderStyle);
|
||||
|
||||
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
|
||||
PRBool DispatchEvent(nsGUIEvent* event);
|
||||
PRBool DispatchStandardEvent(PRUint32 aMsg);
|
||||
void AddTooltip(HWND hwndOwner, nsRect* aRect, int aId);
|
||||
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
|
Загрузка…
Ссылка в новой задаче