From 97616613d0e7cc8d75f5f7a79fa71e0b072b04e5 Mon Sep 17 00:00:00 2001 From: "dcone%netscape.com" Date: Wed, 2 Sep 1998 21:46:53 +0000 Subject: [PATCH] added better tracking --- widget/src/mac/nsButton.cpp | 43 +++++++++++++++++++++++++------------ widget/src/mac/nsButton.h | 4 ++-- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/widget/src/mac/nsButton.cpp b/widget/src/mac/nsButton.cpp index 7b4281a9877a..3e0b05266f0a 100644 --- a/widget/src/mac/nsButton.cpp +++ b/widget/src/mac/nsButton.cpp @@ -26,6 +26,7 @@ #include "nsUnitConversion.h" #include +#include #define DBG 0 @@ -37,6 +38,7 @@ nsButton::nsButton(nsISupports *aOuter) : nsWindow(aOuter) { strcpy(gInstanceClassName, "nsButton"); + mWidgetArmed = PR_FALSE; } @@ -127,15 +129,15 @@ void nsButton::Create(nsIWidget *aParent, Rect r; nsRectToMacRect(aRect,r); - mControl = NewControl ( window, &r, title, visible, - initialValue, minValue, maxValue, - ctrlType, (long)this); + //mControl = NewControl ( window, &r, title, visible, + //initialValue, minValue, maxValue, + //ctrlType, (long)this); mWindowRegion = NewRgn(); SetRectRgn(mWindowRegion,aRect.x,aRect.y,aRect.x+aRect.width,aRect.y+aRect.height); - if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mControl, this); + //if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mControl, this); // save the event callback function mEventCallback = aHandleEventFunction; @@ -200,11 +202,8 @@ void nsButton::StringToStr255(const nsString& aText, Str255& aStr255) memcpy(&aStr255[1],buffer,len); aStr255[0] = len; - } - - //------------------------------------------------------------------------- // // Set this button label @@ -212,13 +211,13 @@ void nsButton::StringToStr255(const nsString& aText, Str255& aStr255) //------------------------------------------------------------------------- void nsButton::SetLabel(const nsString& aText) { + NS_ASSERTION(mControl != nsnull,"Control must not be null"); - if (mControl != nsnull) - { - Str255 s; - StringToStr255(aText,s); - SetControlTitle(mControl,s); - } + //if (mControl != nsnull) + //{ + StringToStr255(aText,mLabel); + //SetControlTitle(mControl,s); + //} } @@ -325,11 +324,13 @@ PRBool result; void nsButton::DrawWidget(PRBool aMouseInside) { +PRInt16 width,x,y; nsRect therect; Rect macrect; GrafPtr theport; RGBColor blackcolor = {0,0,0}; RgnHandle thergn; +//FontInfo fi; GetPort(&theport); @@ -343,9 +344,23 @@ RgnHandle thergn; ::RGBForeColor(&blackcolor); ::EraseRoundRect(¯ect,10,10); - ::PenSize(3,3); + ::PenSize(1,1); ::FrameRoundRect(¯ect,10,10); + + width = ::StringWidth(mLabel); + x = (macrect.left+macrect.right)/2 - (width/2); + + ::TextFont(0); + ::TextSize(12); + ::TextFace(bold); + //::GetFontInfo(&fi); + //height = fi.ascent; + //height = 6; + y = (macrect.top+macrect.bottom)/2 + 6; + ::MoveTo(x,y); + ::DrawString(mLabel); + if(mMouseDownInButton && aMouseInside) ::InvertRoundRect(¯ect,10,10); diff --git a/widget/src/mac/nsButton.h b/widget/src/mac/nsButton.h index 19d6471b4f63..36c935b90e86 100644 --- a/widget/src/mac/nsButton.h +++ b/widget/src/mac/nsButton.h @@ -62,7 +62,7 @@ public: // Mac specific methods void LocalToWindowCoordinate(nsPoint& aPoint); void LocalToWindowCoordinate(nsRect& aRect); - ControlHandle GetControl() { return mControl; } + //ControlHandle GetControl() { return mControl; } // Overriden from nsWindow @@ -98,7 +98,7 @@ private: AggButton mAggWidget; friend class AggButton; - ControlHandle mControl; + Str255 mLabel; PRBool mMouseDownInButton; PRBool mWidgetArmed;