From 5ce31b67c665e90834d8d18f2d19e52248afdb18 Mon Sep 17 00:00:00 2001 From: "mozilla.mano%sent.com" Date: Sat, 20 Aug 2005 07:14:24 +0000 Subject: [PATCH] Bug 118025 - nsITheme menupopup/menuitem implementations (Mac). r=pinkerton sr=smfr (for gfx) r=kmgerich (for pinstripe) --- widget/src/mac/nsNativeThemeMac.cpp | 45 +++++++++++++++++++++++++---- widget/src/mac/nsNativeThemeMac.h | 4 +++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/widget/src/mac/nsNativeThemeMac.cpp b/widget/src/mac/nsNativeThemeMac.cpp index fe4db2dbd6d..65f40400103 100644 --- a/widget/src/mac/nsNativeThemeMac.cpp +++ b/widget/src/mac/nsNativeThemeMac.cpp @@ -48,6 +48,7 @@ #include "nsIContent.h" #include "nsIDocument.h" #include "nsIFrame.h" +#include "nsIAtom.h" #include "nsIEventStateManager.h" #include "nsINameSpaceManager.h" #include "nsPresContext.h" @@ -100,6 +101,8 @@ nsNativeThemeMac::nsNativeThemeMac() sListboxBGTransparent = PR_TRUE; sTextfieldDisabledBGColorID = nsILookAndFeel::eColor__moz_field; } + + mMenuActiveAtom = do_GetAtom("_moz-menuactive"); } nsNativeThemeMac::~nsNativeThemeMac() @@ -284,6 +287,31 @@ nsNativeThemeMac::DrawTab ( const Rect& inBoxRect, PRBool inIsDisabled, PRBool i ::DrawThemeTab(&inBoxRect, style, direction, nsnull, 0L); } +void +nsNativeThemeMac::DrawMenu ( const Rect& inBoxRect, PRBool inIsDisabled ) +{ + ::EraseRect(&inBoxRect); + ThemeMenuType menuType = inIsDisabled ? kThemeMenuTypeInactive : kThemeMenuTypePopUp; + ::DrawThemeMenuBackground(&inBoxRect, menuType); +} + +void +nsNativeThemeMac::DrawMenuItem ( const Rect& inBoxRect, ThemeMenuItemType itemType, PRBool inIsDisabled, + PRBool inHover) +{ + ThemeMenuState menuItemState; + if (inIsDisabled) + menuItemState = kThemeMenuDisabled; + else if (inHover) + menuItemState = kThemeMenuSelected; + else + menuItemState = kThemeMenuActive; + + // XXXmano: pass the right menu rect! + ::DrawThemeMenuItem(&inBoxRect, &inBoxRect, inBoxRect.top, + inBoxRect.bottom, menuItemState, itemType, NULL, 0); +} + NS_IMETHODIMP nsNativeThemeMac::DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame* aFrame, PRUint8 aWidgetType, const nsRect& aRect, const nsRect& aClipRect) @@ -329,10 +357,16 @@ nsNativeThemeMac::DrawWidgetBackground(nsIRenderingContext* aContext, nsIFrame* ::EraseRect(&macRect); ::SetThemeBackground(kThemeBrushWhite, 24, true); break; - + case NS_THEME_MENUPOPUP: ::SetThemeBackground(kThemeBrushDialogBackgroundActive, 24, true); - ::EraseRect(&macRect); + DrawMenu(macRect, IsDisabled(aFrame)); + ::SetThemeBackground(kThemeBrushWhite, 24, true); + break; + + case NS_THEME_MENUITEM: + ::SetThemeBackground(kThemeBrushDialogBackgroundActive, 24, true); + DrawMenuItem(macRect, kThemeMenuItemPlain, IsDisabled(aFrame), CheckBooleanAttr(aFrame, mMenuActiveAtom)); ::SetThemeBackground(kThemeBrushWhite, 24, true); break; @@ -724,7 +758,7 @@ nsNativeThemeMac::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType, // disabled, checked, dlgtype, default, etc. *aShouldRepaint = PR_FALSE; if (aAttribute == mDisabledAtom || aAttribute == mCheckedAtom || - aAttribute == mSelectedAtom) + aAttribute == mSelectedAtom || aAttribute == mMenuActiveAtom) *aShouldRepaint = PR_TRUE; } @@ -758,7 +792,8 @@ nsNativeThemeMac::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFr switch ( aWidgetType ) { case NS_THEME_DIALOG: case NS_THEME_WINDOW: - // case NS_THEME_MENUPOPUP: // no support for painting menu backgrounds + case NS_THEME_MENUPOPUP: + case NS_THEME_MENUITEM: case NS_THEME_TOOLTIP: case NS_THEME_CHECKBOX: @@ -808,7 +843,7 @@ nsNativeThemeMac::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFr case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: retVal = PR_TRUE; break; - + case NS_THEME_LISTBOX: case NS_THEME_DROPDOWN: case NS_THEME_DROPDOWN_BUTTON: diff --git a/widget/src/mac/nsNativeThemeMac.h b/widget/src/mac/nsNativeThemeMac.h index db718ebd82d..3f7d6e469cf 100644 --- a/widget/src/mac/nsNativeThemeMac.h +++ b/widget/src/mac/nsNativeThemeMac.h @@ -114,8 +114,12 @@ protected: PRBool inDisabled, ThemeButtonValue inValue, ThemeButtonAdornment inAdornment, PRInt32 inState ) ; void DrawCheckboxRadio ( ThemeButtonKind inKind, const Rect& inBoxRect, PRBool inChecked, PRBool inDisabled, PRInt32 inState ) ; + void DrawMenu ( const Rect& inBoxRect, PRBool inIsDisabled ) ; + void DrawMenuItem ( const Rect& inBoxRect, ThemeMenuItemType itemType, PRBool inIsDisabled, + PRBool inHover) ; private: ThemeEraseUPP mEraseProc; + nsCOMPtr mMenuActiveAtom; };