File Removed.

This commit is contained in:
pinkerton%netscape.com 1999-06-08 21:23:36 +00:00
parent a89dfbd4ab
commit 3b1d98eb67
7 changed files with 0 additions and 2411 deletions

View File

@ -1,240 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIImageButton_h___
#define nsIImageButton_h___
#include "nsISupports.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsColor.h"
class nsIImageButtonListener;
//f58c2550-4a7c-11d2-bee2-00805f8a8dbd
#define NS_IIMAGEBUTTON_IID \
{ 0xf58c2550, 0x4a7c, 0x11d2, \
{0xbe, 0xe2, 0x00, 0x80, 0x5f, 0x8a, 0x8d, 0xbd} }
typedef enum {
eButtonVerticalAligment_Top,
eButtonVerticalAligment_Center,
eButtonVerticalAligment_Bottom
} nsButtonVerticalAligment;
typedef enum {
eButtonHorizontalAligment_Left,
eButtonHorizontalAligment_Middle,
eButtonHorizontalAligment_Right
} nsButtonHorizontalAligment;
//---------------------------------------------------------------------------
class nsIImageButton : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEBUTTON_IID)
/**
* Sets the label on the Image Button
*
*/
NS_IMETHOD SetLabel(const nsString& aString) = 0;
/**
* Gets the label on the Image Button
*
*/
NS_IMETHOD GetLabel(nsString& aString) = 0;
/**
* Gets the command for the Image Button
*
*/
NS_IMETHOD GetCommand(PRInt32 &aCommand) = 0;
/**
* Sets the command for the Image Button
*
*/
NS_IMETHOD SetCommand(PRInt32 aCommand) = 0;
/**
* Sets the description that is available when the mouse enters the control
*
*/
NS_IMETHOD SetRollOverDesc(const nsString& aString) = 0;
/**
* Gets the description that is available when the mouse enters the control
*
*/
NS_IMETHOD GetRollOverDesc(nsString& aString) = 0;
/**
* Sets the border highlight color
*
*/
NS_IMETHOD SetHighlightColor(const nscolor &aColor) = 0;
/**
* Gets the border highlight color
*
*/
NS_IMETHOD GetHighlightColor(nscolor &aColor) = 0;
/**
* Gets the Shadow highlight color
*
*/
NS_IMETHOD GetShadowColor(nscolor &aColor) = 0;
/**
* Sets the Shadow highlight color
*
*/
NS_IMETHOD SetShadowColor(const nscolor &aColor) = 0;
/**
* Sets the Dimensions of the Image in the button
* (The dimensions should come from the image)
*
*/
NS_IMETHOD SetImageDimensions(const PRInt32 & aWidth, const PRInt32 & aHeight) = 0;
/**
* Gets the Dimensions of the Image in the button
*
*/
NS_IMETHOD GetImageDimensions(PRInt32 & aWidth, PRInt32 & aHeight) = 0;
/**
* Sets the URLs for the Buttons images
*
*/
NS_IMETHOD SetImageURLs(const nsString& aUpURL,
const nsString& aPressedURL,
const nsString& aDisabledURL,
const nsString& aRollOverURL) = 0;
NS_IMETHOD SetImageUpURL(const nsString& aUpURL) = 0;
NS_IMETHOD SetImagePressedURL(const nsString& aPressedURL) = 0;
NS_IMETHOD SetImageDisabledURL(const nsString& aDisabledURL) = 0;
NS_IMETHOD SetImageRollOverURL(const nsString& aRollOverURL) = 0;
/**
* Sets the width of the border
*
*/
NS_IMETHOD SetBorderWidth(PRInt32 aWidth) = 0;
/**
* Sets the width of the space between the border and the text or image
*
*/
NS_IMETHOD SetBorderOffset(PRInt32 aWidth) = 0;
/**
* Sets whether the Border show be shown
*
*/
NS_IMETHOD SetShowBorder(PRBool aState) = 0;
/**
* Sets whether the Border show be shown
*
*/
NS_IMETHOD SetShowButtonBorder(PRBool aState) = 0;
/**
* Sets whether the text should be shown
*
*/
NS_IMETHOD SetShowText(PRBool aState) = 0;
/**
* Sets whether the image should be shown
*
*/
NS_IMETHOD SetShowImage(PRBool aState) = 0;
/**
* Sets the image's vertical alignment
*
*/
NS_IMETHOD SetImageVerticalAlignment(nsButtonVerticalAligment aAlign) = 0;
/**
* Sets the image's horizontal alignment
*
*/
NS_IMETHOD SetImageHorizontalAlignment(nsButtonHorizontalAligment aAlign) = 0;
/**
* Sets the text's vertical alignment
*
*/
NS_IMETHOD SetTextVerticalAlignment(nsButtonVerticalAligment aAlign) = 0;
/**
* Sets the text's horizontal alignment
*
*/
NS_IMETHOD SetTextHorizontalAlignment(nsButtonHorizontalAligment aAlign) = 0;
/**
* Show border at all times
*
*/
NS_IMETHOD SetAlwaysShowBorder(PRBool aState) = 0;
/**
* Show border at all times
*
*/
NS_IMETHOD SwapHighlightShadowColors() = 0;
/**
* Add Image Button Listener
*
*/
NS_IMETHOD AddListener(nsIImageButtonListener * aListener) = 0;
/**
* Removes Image Button Listener
*
*/
NS_IMETHOD RemoveListener(nsIImageButtonListener * aListener) = 0;
/**
* HandleGUI Events
*
*/
NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent) = 0;
/**
* Handle OnPaint
*
*/
NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect) = 0;
};
#endif /* nsIImageButton_h___ */

View File

@ -1,48 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIImageButtonListener_h___
#define nsIImageButtonListener_h___
#include "nsISupports.h"
#include "nsGUIEvent.h"
class nsIImageButton;
// {D3C3B8B2-55B5-11d2-9A2A-000000000000}
#define NS_IIMAGEBUTTONLISTENER_IID \
{ 0xd3c3b8b2, 0x55b5, 0x11d2, \
{ 0x9a, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
class nsIImageButtonListener : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEBUTTONLISTENER_IID)
/**
* Notifies
*
*/
NS_IMETHOD NotifyImageButtonEvent(nsIImageButton * aImgBtn, nsGUIEvent* anEvent) = 0;
};
#endif /* nsIImageButtonListener_h___ */

View File

@ -1,263 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIMenuButton_h___
#define nsIMenuButton_h___
#include "nsISupports.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsColor.h"
#include "nsIImageButton.h"
#define NS_IMENUBUTTON_IID \
{ 0x67b8e261, 0x53c3, 0x11d2, \
{ 0x8d, 0xc4, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
/*
typedef enum {
eButtonVerticalAligment_Top,
eButtonVerticalAligment_Center,
eButtonVerticalAligment_Bottom
} nsButtonVerticalAligment;
typedef enum {
eButtonHorizontalAligment_Left,
eButtonHorizontalAligment_Middle,
eButtonHorizontalAligment_Right
} nsButtonHorizontalAligment;
*/
//---------------------------------------------------------------------------
class nsIMenuButton : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMENUBUTTON_IID)
/**
* Sets the label on the Menu Button
*
*/
NS_IMETHOD SetLabel(const nsString& aString) = 0;
/**
* Gets the label on the Menu Button
*
*/
NS_IMETHOD GetLabel(nsString& aString) = 0;
/**
* Sets the description that is available when the mouse enters the control
*
*/
NS_IMETHOD SetRollOverDesc(const nsString& aString) = 0;
/**
* Gets the description that is available when the mouse enters the control
*
*/
NS_IMETHOD GetRollOverDesc(nsString& aString) = 0;
/**
* Gets the command for the Menu Button
*
*/
NS_IMETHOD GetCommand(PRInt32 &aCommand) = 0;
/**
* Sets the command for the Menu Button
*
*/
NS_IMETHOD SetCommand(PRInt32 aCommand) = 0;
/**
* Sets the border highlight color
*
*/
NS_IMETHOD SetHighlightColor(const nscolor &aColor) = 0;
/**
* Gets the border highlight color
*
*/
NS_IMETHOD GetHighlightColor(nscolor &aColor) = 0;
/**
* Gets the Shadow highlight color
*
*/
NS_IMETHOD GetShadowColor(nscolor &aColor) = 0;
/**
* Sets the Shadow highlight color
*
*/
NS_IMETHOD SetShadowColor(const nscolor &aColor) = 0;
/**
* Sets the Dimensions of the Image in the button
* (The dimensions should come from the image)
*
*/
NS_IMETHOD SetImageDimensions(const PRInt32 & aWidth, const PRInt32 & aHeight) = 0;
/**
* Sets the URLs for the Buttons images
*
*/
NS_IMETHOD SetImageURLs(const nsString& aUpURL,
const nsString& aPressedURL,
const nsString& aDisabledURL,
const nsString& aRollOverURL) = 0;
NS_IMETHOD SetImageUpURL(const nsString& aUpURL) = 0;
NS_IMETHOD SetImagePressedURL(const nsString& aPressedURL) = 0;
NS_IMETHOD SetImageDisabledURL(const nsString& aDisabledURL) = 0;
NS_IMETHOD SetImageRollOverURL(const nsString& aRollOverURL) = 0;
/**
* Sets the width of the border
*
*/
NS_IMETHOD SetBorderWidth(PRInt32 aWidth) = 0;
/**
* Sets the width of the space between the border and the text or image
*
*/
NS_IMETHOD SetBorderOffset(PRInt32 aWidth) = 0;
/**
* Sets whether the Border show be shown
*
*/
NS_IMETHOD SetShowBorder(PRBool aState) = 0;
/**
* Sets whether the Border show be shown
*
*/
NS_IMETHOD SetShowButtonBorder(PRBool aState) = 0;
/**
* Sets whether the text should be shown
*
*/
NS_IMETHOD SetShowText(PRBool aState) = 0;
/**
* Sets whether the image should be shown
*
*/
NS_IMETHOD SetShowImage(PRBool aState) = 0;
/**
* Sets the image's vertical alignment
*
*/
NS_IMETHOD SetImageVerticalAlignment(nsButtonVerticalAligment aAlign) = 0;
/**
* Sets the image's horizontal alignment
*
*/
NS_IMETHOD SetImageHorizontalAlignment(nsButtonHorizontalAligment aAlign) = 0;
/**
* Sets the text's vertical alignment
*
*/
NS_IMETHOD SetTextVerticalAlignment(nsButtonVerticalAligment aAlign) = 0;
/**
* Sets the text's horizontal alignment
*
*/
NS_IMETHOD SetTextHorizontalAlignment(nsButtonHorizontalAligment aAlign) = 0;
/**
* Show border at all times
*
*/
NS_IMETHOD SetAlwaysShowBorder(PRBool aState) = 0;
/**
* Show border at all times
*
*/
NS_IMETHOD SwapHighlightShadowColors() = 0;
/**
* HandleGUI Events
*
*/
NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent) = 0;
/**
* Handle OnPaint
*
*/
NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect) = 0;
/**
* Gets the PopUp on the Image Button
*
*/
NS_IMETHOD GetPopUpMenu(nsIPopUpMenu *& aPopUpMenu) = 0;
/**
* Appends a MenuItem to the PopUp
*
*/
NS_IMETHOD AddMenuItem(const nsString& aMenuLabel, PRInt32 aCommand) = 0;
/**
* Inserts a MenuItem into the PopUp
*
*/
NS_IMETHOD InsertMenuItem(const nsString& aMenuLabel, PRInt32 aCommand, PRInt32 aPos) = 0;
/**
* Removes a MenuItem from the PopUp at a specified location
*
*/
NS_IMETHOD RemovesMenuItem(PRInt32 aPos) = 0;
/**
* Removes all the MenuItems from the PopUp
*
*/
NS_IMETHOD RemoveAllMenuItems(PRInt32 aPos) = 0;
/**
* Add Menu Button Listener
*
*/
NS_IMETHOD AddListener(nsIImageButtonListener * aListener) = 0;
/**
* Removes Menu Button Listener
*
*/
NS_IMETHOD RemoveListener(nsIImageButtonListener * aListener) = 0;
};
#endif /* nsIMenuButton_h___ */

File diff suppressed because it is too large Load Diff

View File

@ -1,217 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsImageButton_h___
#define nsImageButton_h___
#include "nsIImageButton.h"
#include "nsIImageRequest.h"
#include "nsIImageGroup.h"
#include "nsIRenderingContext.h"
#include "nsWindow.h"
#include "nsColor.h"
#include "nsFont.h"
#include "nsIImageObserver.h"
#include "nsIImageButtonListener.h"
#define eButtonState_up 1
#define eButtonState_rollover 2
#define eButtonState_pressed 4
#define eButtonState_disabled 8
//--------------------------------------------------------------
class nsImageButton : public ChildWindow,
public nsIImageButton,
public nsIImageRequestObserver
{
public:
nsImageButton();
virtual ~nsImageButton();
NS_DECL_ISUPPORTS
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_IMETHOD_(nsEventStatus) PaintBackground(nsIRenderingContext& aRenderingContext,
const nsRect & aDirtyRect,
const nsRect & aEntireRect,
nsIImageRequest * anImage,
const nsRect & aRect);
NS_IMETHOD_(nsEventStatus) PaintForeground(nsIRenderingContext& aRenderingContext,
const nsRect & aDirtyRect,
const nsRect & aEntireRect,
const nsString & aLabel,
const nsRect & aRect);
NS_IMETHOD_(nsEventStatus) PaintBorder(nsIRenderingContext& aRenderingContext,
const nsRect & aDirtyRect,
const nsRect & aEntireRect);
NS_IMETHOD_(nsEventStatus) OnMouseEnter(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnMouseExit(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnMouseMove(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnLeftButtonDown(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnLeftButtonUp(nsGUIEvent *aEvent);
NS_IMETHOD CreateImageGroup();
NS_IMETHOD_(nsIImageRequest *) RequestImage(nsString aUrl);
/**
* Save canvas graphical state
* @param aRenderingContext, rendering context to save state to
* @result nsresult, NS_OK if successful
*/
NS_IMETHOD PushState(nsIRenderingContext& aRenderingContext);
/**
* Get and and set RenderingContext to this graphical state
* @param aRenderingContext, rendering context to get previously saved state from
* @return if PR_TRUE, indicates that the clipping region after
* popping state is empty, else PR_FALSE
*/
NS_IMETHOD_(PRBool) PopState(nsIRenderingContext& aRenderingContext);
NS_IMETHOD GetLabel(nsString&);
NS_IMETHOD SetLabel(const nsString& aString);
NS_IMETHOD GetRollOverDesc(nsString& aString);
NS_IMETHOD SetRollOverDesc(const nsString& aString);
NS_IMETHOD GetCommand(PRInt32 & aCommand);
NS_IMETHOD SetCommand(PRInt32 aCommand);
NS_IMETHOD GetHighlightColor(nscolor &aColor);
NS_IMETHOD SetHighlightColor(const nscolor &aColor);
NS_IMETHOD GetShadowColor(nscolor &aColor);
NS_IMETHOD SetShadowColor(const nscolor &aColor);
NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent);
NS_IMETHOD SetImageDimensions(const PRInt32 & aWidth, const PRInt32 & aHeight);
NS_IMETHOD GetImageDimensions(PRInt32 & aWidth, PRInt32 & aHeight);
NS_IMETHOD SetImageURLs(const nsString& aUpURL,
const nsString& aPressedURL,
const nsString& aDisabledURL,
const nsString& aRollOverURL);
NS_IMETHOD SetImageUpURL(const nsString& aUpURL);
NS_IMETHOD SetImagePressedURL(const nsString& aPressedURL);
NS_IMETHOD SetImageDisabledURL(const nsString& aDisabledURL);
NS_IMETHOD SetImageRollOverURL(const nsString& aRollOverURL);
NS_IMETHOD SetShowBorder(PRBool aState);
NS_IMETHOD SetShowButtonBorder(PRBool aState);
NS_IMETHOD SetBorderWidth(PRInt32 aWidth);
NS_IMETHOD SetBorderOffset(PRInt32 aWidth);
NS_IMETHOD SetShowText(PRBool aState);
NS_IMETHOD SetShowImage(PRBool aState);
NS_IMETHOD SetAlwaysShowBorder(PRBool aState);
NS_IMETHOD SwapHighlightShadowColors();
// Alignment Methods
NS_IMETHOD SetImageVerticalAlignment(nsButtonVerticalAligment aAlign);
NS_IMETHOD SetImageHorizontalAlignment(nsButtonHorizontalAligment aAlign);
NS_IMETHOD SetTextVerticalAlignment(nsButtonVerticalAligment aAlign);
NS_IMETHOD SetTextHorizontalAlignment(nsButtonHorizontalAligment aAlign);
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD AddListener(nsIImageButtonListener * aListener);
NS_IMETHOD RemoveListener(nsIImageButtonListener * aListener);
// nsIImageRequestObserver
virtual void Notify(nsIImageRequest *aImageRequest,
nsIImage *aImage,
nsImageNotification aNotificationType,
PRInt32 aParam1, PRInt32 aParam2,
void *aParam3);
virtual void NotifyError(nsIImageRequest *aImageRequest,
nsImageError aErrorType);
// nsWindow
NS_IMETHOD Enable(PRBool aState);
protected:
nsIImageRequest * GetImageForPainting();
void PerformAlignment(const nsRect & aRect,
const nsIImageRequest * anImage, nsRect & aImgRect,
const nsString & aText, nsRect & aTxtRect,
PRInt32 &aWhichAlignment, PRInt32 &aMaxWidth, PRInt32 &aMaxHeight);
nsIImageRequest* mUpImageRequest;
nsIImageRequest* mPressedImageRequest;
nsIImageRequest* mDisabledImageRequest;
nsIImageRequest* mRollOverImageRequest;
PRUint32 mState;
nsIImageRequest* mImageRequest;
nsIImageGroup* mImageGroup;
nsIRenderingContext *mRenderingContext;
nsButtonVerticalAligment mTextVAlignment;
nsButtonHorizontalAligment mTextHAlignment;
nsButtonVerticalAligment mImageVAlignment;
nsButtonHorizontalAligment mImageHAlignment;
PRBool mShowImage;
PRBool mShowText;
nscolor mBackgroundColor;
nscolor mForegroundColor;
nscolor mHighlightColor;
nscolor mShadowColor;
nsFont mFont;
nsString mLabel;
nsString mRollOverDesc;
PRInt32 mCommand;
PRInt32 mTextGap;
PRUint32 mImageWidth;
PRUint32 mImageHeight;
PRBool mShowBorder; // If true border show on mouse over
PRBool mShowButtonBorder; // controls just the black rect around the button
PRBool mAlwaysShowBorder; // controls whether up/dwn border is always drawn
PRInt32 mBorderWidth;
PRInt32 mBorderOffset;
// Temporary
// XXX will be switching to a nsDeque
nsIImageButtonListener * mListeners[32];
PRInt32 mNumListeners;
};
#endif /* nsImageButton_h___ */

View File

@ -1,495 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsMenuButton.h"
#include "nsWidgetsCID.h"
#include "nspr.h"
#include "nsIFontMetrics.h"
#include "nsIDeviceContext.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIWidget.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
static NS_DEFINE_IID(kCMenuButtonCID, NS_MENUBUTTON_CID);
static NS_DEFINE_IID(kCIMenuButtonIID, NS_IMENUBUTTON_IID);
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
static NS_DEFINE_IID(kPopUpMenuCID, NS_POPUPMENU_CID);
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID);
NS_IMPL_ADDREF(nsMenuButton)
NS_IMPL_RELEASE(nsMenuButton)
//------------------------------------------------------------
nsMenuButton::nsMenuButton() : nsIMenuButton(), nsImageButton()
{
NS_INIT_REFCNT();
mPopUpMenu = nsnull;
mMenuIsPoppedUp = PR_FALSE;
}
//------------------------------------------------------------
nsMenuButton::~nsMenuButton()
{
NS_IF_RELEASE(mPopUpMenu);
}
//------------------------------------------------------------
nsresult nsMenuButton::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kClassIID, kCMenuButtonCID);
if (aIID.Equals(kCIMenuButtonIID)) {
*aInstancePtr = (void*) (nsIMenuButton *)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kClassIID)) {
*aInstancePtr = (void*) (nsMenuButton *)this;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) (this);
AddRef();
return NS_OK;
}
return (nsImageButton::QueryInterface(aIID, aInstancePtr));
}
//------------------------------------------------------------
void nsMenuButton::CreatePopUpMenu()
{
if (nsnull != mPopUpMenu) {
return;
}
// Create and place back button
nsresult rv = nsComponentManager::CreateInstance(kPopUpMenuCID, nsnull, kIPopUpMenuIID,
(void**)&mPopUpMenu);
if (NS_OK == rv) {
nsIWidget * menuParentWidget;
if (NS_OK != this->QueryInterface(kIWidgetIID,(void**)&menuParentWidget)) {
return;
}
nsIWidget * popupWidget;
nsRect rect;
if (NS_OK == mPopUpMenu->QueryInterface(kIWidgetIID,(void**)&popupWidget)) {
popupWidget->Create(menuParentWidget, rect, nsnull, nsnull);
NS_RELEASE(popupWidget);
}
NS_RELEASE(menuParentWidget);
}
return;
}
//------------------------------------------------------------
NS_METHOD nsMenuButton::GetPopUpMenu(nsIPopUpMenu *& aPopUpMenu)
{
CreatePopUpMenu();
NS_ADDREF(mPopUpMenu);
aPopUpMenu = mPopUpMenu;
return NS_OK;
}
//------------------------------------------------------------
NS_METHOD nsMenuButton::AddMenuItem(const nsString& aMenuLabel, PRInt32 aCommand)
{
CreatePopUpMenu();
nsIMenuItem * menuItem = nsnull;
nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&menuItem);
menuItem->Create(mPopUpMenu, aMenuLabel, aCommand);
if (NS_OK == rv) {
mPopUpMenu->AddItem(menuItem);
NS_RELEASE(menuItem);
}
return NS_OK;
}
//------------------------------------------------------------
NS_METHOD nsMenuButton::InsertMenuItem(const nsString& aMenuLabel, PRInt32 aCommand, PRInt32 aPos)
{
CreatePopUpMenu();
return NS_OK;
}
//------------------------------------------------------------
NS_METHOD nsMenuButton::RemovesMenuItem(PRInt32 aPos)
{
CreatePopUpMenu();
return NS_OK;
}
//------------------------------------------------------------
NS_METHOD nsMenuButton::RemoveAllMenuItems(PRInt32 aPos)
{
CreatePopUpMenu();
return NS_OK;
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::OnLeftButtonDown(nsGUIEvent *aEvent)
{
mState |= eButtonState_pressed;
Invalidate(PR_TRUE);
nsRect rect;
GetBounds(rect);
if (mPopUpMenu) {
mMenuIsPoppedUp = PR_TRUE;
mPopUpMenu->ShowMenu(0, rect.height);
mMenuIsPoppedUp = PR_FALSE;
}
return nsEventStatus_eIgnore;
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::PaintBorder(nsIRenderingContext & aRenderingContext,
const nsRect & aDirtyRect,
const nsRect & aEntireRect)
{
nsRect rect(aEntireRect);
if ((mState == eButtonState_up || (mState & eButtonState_disabled)) && !mAlwaysShowBorder && !mMenuIsPoppedUp) {
return nsEventStatus_eConsumeNoDefault;
}
rect.x = 0;
rect.y = 0;
rect.width--;
rect.height--;
if (mShowButtonBorder) {
aRenderingContext.SetColor(NS_RGB(0,0,0));
aRenderingContext.DrawRect(0,0, rect.width, rect.height);
rect.x++;
rect.y++;
rect.width -= 2;
rect.height -= 2;
}
if ((mState & eButtonState_pressed) || mMenuIsPoppedUp) {
aRenderingContext.SetColor(mHighlightColor);
} else {
aRenderingContext.SetColor(mShadowColor);
}
aRenderingContext.DrawLine(rect.x, rect.height, rect.width, rect.height);
aRenderingContext.DrawLine(rect.width, rect.y, rect.width, rect.height);
if ((mState & eButtonState_pressed) || mMenuIsPoppedUp) {
aRenderingContext.SetColor(mShadowColor);
} else {
aRenderingContext.SetColor(mHighlightColor);
}
aRenderingContext.DrawLine(rect.x,rect.y, rect.width,rect.y);
aRenderingContext.DrawLine(rect.x,rect.y, rect.x, rect.height);
return nsEventStatus_eConsumeNoDefault;
}
//------------------------------------------------------------
nsresult nsMenuButton::SetBounds(const nsRect &aBounds)
{
return nsImageButton::SetBounds(aBounds);
}
//------------------------------------------------------------
nsEventStatus nsMenuButton::OnPaint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
// draw the button, as normal
nsEventStatus rv = nsImageButton::OnPaint(aRenderingContext, aDirtyRect);
// draw the triangle in the top right corner to indicate this is a dropdown,
// but only if the dirty rect contains that area
if ( aDirtyRect.YMost() > mBounds.YMost() - 11 ) {
aRenderingContext.PushState();
nscolor triangleColor = 0;
if ( mState & eButtonState_disabled )
triangleColor = nscolor(NS_RGB(0xaa,0xaa,0xaa)); //*** this should go to l&f object
aRenderingContext.SetColor(triangleColor);
// it would be great if I could just use a polygon here, but this
// way guarantees it will be a nice triangle shape on all gfx platforms
int lineWidth = 10;
int hStart = mBounds.width - 14;
for (int i = 5; lineWidth >= 0; ++i, lineWidth -= 2, hStart += 1)
{
int hEnd = hStart + lineWidth;
aRenderingContext.DrawLine(hStart, i, hEnd, i);
}
PRBool ignored;
aRenderingContext.PopState(ignored);
}
return rv;
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::OnMouseMove(nsGUIEvent *aEvent)
{
return nsImageButton::OnMouseMove(aEvent);
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::OnMouseEnter(nsGUIEvent *aEvent)
{
return nsImageButton::OnMouseEnter(aEvent);
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::OnMouseExit(nsGUIEvent *aEvent)
{
return nsImageButton::OnMouseExit(aEvent);
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::OnLeftButtonUp(nsGUIEvent *aEvent)
{
return nsImageButton::OnLeftButtonUp(aEvent);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::GetLabel(nsString & aString)
{
return nsImageButton::GetLabel(aString);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::SetLabel(const nsString& aString)
{
return nsImageButton::SetLabel(aString);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::GetRollOverDesc(nsString & aString)
{
return nsImageButton::GetRollOverDesc(aString);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::SetRollOverDesc(const nsString& aString)
{
return nsImageButton::SetRollOverDesc(aString);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::GetCommand(PRInt32 & aCommand)
{
return nsImageButton::GetCommand(aCommand);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::SetCommand(PRInt32 aCommand)
{
return nsImageButton::SetCommand(aCommand);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::GetHighlightColor(nscolor &aColor)
{
return nsImageButton::GetHighlightColor(aColor);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::SetHighlightColor(const nscolor &aColor)
{
return nsImageButton::SetHighlightColor(aColor);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::GetShadowColor(nscolor &aColor)
{
return nsImageButton::GetShadowColor(aColor);
}
//-----------------------------------------------------------------------------
NS_METHOD nsMenuButton::SetShadowColor(const nscolor &aColor)
{
return nsImageButton::SetShadowColor(aColor);
}
//-----------------------------------------------------------------------------
nsEventStatus nsMenuButton::HandleEvent(nsGUIEvent *aEvent)
{
return nsImageButton::HandleEvent(aEvent);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageDimensions(const PRInt32 & aWidth, const PRInt32 & aHeight)
{
return nsImageButton::SetImageDimensions(aWidth, aHeight);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageURLs(const nsString& aUpURL,
const nsString& aPressedURL,
const nsString& aDisabledURL,
const nsString& aRollOverURL)
{
return nsImageButton::SetImageURLs(aUpURL, aPressedURL, aDisabledURL, aRollOverURL);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageUpURL(const nsString& aUpURL)
{
return nsImageButton::SetImageUpURL(aUpURL);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImagePressedURL(const nsString& aPressedURL)
{
return nsImageButton::SetImagePressedURL(aPressedURL);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageDisabledURL(const nsString& aDisabledURL)
{
return nsImageButton::SetImageDisabledURL(aDisabledURL);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageRollOverURL(const nsString& aRollOverURL)
{
return nsImageButton::SetImageRollOverURL(aRollOverURL);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetShowBorder(PRBool aState)
{
return nsImageButton::SetShowBorder(aState);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetAlwaysShowBorder(PRBool aState)
{
return nsImageButton::SetAlwaysShowBorder(aState);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SwapHighlightShadowColors()
{
return nsImageButton::SwapHighlightShadowColors();
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetShowButtonBorder(PRBool aState)
{
return nsImageButton::SetShowButtonBorder(aState);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetBorderWidth(PRInt32 aWidth)
{
return nsImageButton::SetBorderWidth(aWidth);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetBorderOffset(PRInt32 aOffset)
{
return nsImageButton::SetBorderOffset(aOffset);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetShowText(PRBool aState)
{
return nsImageButton::SetShowText(aState);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetShowImage(PRBool aState)
{
return nsImageButton::SetShowImage(aState);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageVerticalAlignment(nsButtonVerticalAligment aAlign)
{
return nsImageButton::SetImageVerticalAlignment(aAlign);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetImageHorizontalAlignment(nsButtonHorizontalAligment aAlign)
{
return nsImageButton::SetImageHorizontalAlignment(aAlign);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetTextVerticalAlignment(nsButtonVerticalAligment aAlign)
{
return nsImageButton::SetTextVerticalAlignment(aAlign);
}
//----------------------------------------------------------------
NS_METHOD nsMenuButton::SetTextHorizontalAlignment(nsButtonHorizontalAligment aAlign)
{
return nsImageButton::SetTextHorizontalAlignment(aAlign);
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuButton::AddListener(nsIImageButtonListener * aListener)
{
return nsImageButton::AddListener(aListener);
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuButton::RemoveListener(nsIImageButtonListener * aListener)
{
return nsImageButton::RemoveListener(aListener);
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuButton::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
{
return nsImageButton::GetPreferredSize(aWidth, aHeight);
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuButton::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight)
{
return nsImageButton::SetPreferredSize(aWidth, aHeight);
}
//-------------------------------------------------------------------------
NS_METHOD nsMenuButton::Enable(PRBool aState)
{
return nsImageButton::Enable(aState);
}

View File

@ -1,123 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsMenuButton_h___
#define nsMenuButton_h___
#include "nsIPopUpMenu.h"
#include "nsIMenuButton.h"
#include "nsImageButton.h"
#include "nsIRenderingContext.h"
#include "nsColor.h"
#include "nsFont.h"
#include "nsGUIEvent.h"
#include "nsIImageButtonListener.h"
//--------------------------------------------------------------
class nsMenuButton : public nsIMenuButton,
public nsImageButton
{
public:
nsMenuButton();
virtual ~nsMenuButton();
NS_DECL_ISUPPORTS
NS_IMETHOD GetPopUpMenu(nsIPopUpMenu *& aPopUpMenu);
NS_IMETHOD AddMenuItem(const nsString& aMenuLabel, PRInt32 aCommand);
NS_IMETHOD InsertMenuItem(const nsString& aMenuLabel, PRInt32 aCommand, PRInt32 aPos);
NS_IMETHOD RemovesMenuItem(PRInt32 aPos);
NS_IMETHOD RemoveAllMenuItems(PRInt32 aPos);
NS_IMETHOD_(nsEventStatus) OnLeftButtonDown(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) PaintBorder(nsIRenderingContext& aRenderingContext,
const nsRect & aDirtyRect,
const nsRect & aEntireRect);
NS_IMETHOD SetBounds(const nsRect& aBounds);
NS_IMETHOD_(nsEventStatus) OnPaint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_IMETHOD_(nsEventStatus) OnMouseEnter(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnMouseExit(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnMouseMove(nsGUIEvent *aEvent);
NS_IMETHOD_(nsEventStatus) OnLeftButtonUp(nsGUIEvent *aEvent);
NS_IMETHOD GetLabel(nsString&);
NS_IMETHOD SetLabel(const nsString& aString);
NS_IMETHOD GetRollOverDesc(nsString& aString);
NS_IMETHOD SetRollOverDesc(const nsString& aString);
NS_IMETHOD GetCommand(PRInt32 & aCommand);
NS_IMETHOD SetCommand(PRInt32 aCommand);
NS_IMETHOD GetHighlightColor(nscolor &aColor);
NS_IMETHOD SetHighlightColor(const nscolor &aColor);
NS_IMETHOD GetShadowColor(nscolor &aColor);
NS_IMETHOD SetShadowColor(const nscolor &aColor);
NS_IMETHOD_(nsEventStatus) HandleEvent(nsGUIEvent *aEvent);
NS_IMETHOD SetImageDimensions(const PRInt32 & aWidth, const PRInt32 & aHeight);
NS_IMETHOD SetImageURLs(const nsString& aUpURL,
const nsString& aPressedURL,
const nsString& aDisabledURL,
const nsString& aRollOverURL);
NS_IMETHOD SetImageUpURL(const nsString& aUpURL);
NS_IMETHOD SetImagePressedURL(const nsString& aPressedURL);
NS_IMETHOD SetImageDisabledURL(const nsString& aDisabledURL);
NS_IMETHOD SetImageRollOverURL(const nsString& aRollOverURL);
NS_IMETHOD SetShowBorder(PRBool aState);
NS_IMETHOD SetShowButtonBorder(PRBool aState);
NS_IMETHOD SetBorderWidth(PRInt32 aWidth);
NS_IMETHOD SetBorderOffset(PRInt32 aWidth);
NS_IMETHOD SetShowText(PRBool aState);
NS_IMETHOD SetShowImage(PRBool aState);
NS_IMETHOD SetAlwaysShowBorder(PRBool aState);
NS_IMETHOD SwapHighlightShadowColors();
// Alignment Methods
NS_IMETHOD SetImageVerticalAlignment(nsButtonVerticalAligment aAlign);
NS_IMETHOD SetImageHorizontalAlignment(nsButtonHorizontalAligment aAlign);
NS_IMETHOD SetTextVerticalAlignment(nsButtonVerticalAligment aAlign);
NS_IMETHOD SetTextHorizontalAlignment(nsButtonHorizontalAligment aAlign);
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD AddListener(nsIImageButtonListener * aListener);
NS_IMETHOD RemoveListener(nsIImageButtonListener * aListener);
// nsWindow
NS_IMETHOD Enable(PRBool aState);
protected:
void CreatePopUpMenu();
nsIPopUpMenu * mPopUpMenu;
PRBool mMenuIsPoppedUp;
};
#endif /* nsMenuButton_h___ */