mcmullen's scrollbar fixes (use 32-bit control values), some tweaks of Mac control visibility to avoid drawing controls in the wrong places, add a couple of utility methods for creating and adjusting Mac controls.

This commit is contained in:
sfraser%netscape.com 1999-01-16 00:39:28 +00:00
parent ec9d3ae727
commit a4ce9963ca
2 changed files with 96 additions and 34 deletions

View File

@ -57,20 +57,13 @@ NS_IMETHODIMP nsMacControl::Create(nsIWidget *aParent,
{ {
Inherited::Create(aParent, aRect, aHandleEventFunction, Inherited::Create(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData); aContext, aAppShell, aToolkit, aInitData);
// create native control // create native control. mBounds has been set up at this point
nsRect ctlRect = aRect; nsresult theResult = CreateOrReplaceMacControl(mControlType);
ctlRect.x = ctlRect.y = 0;
Rect macRect;
nsRectToMacRect(ctlRect, macRect);
if(nsnull != mWindowPtr){
mControl = ::NewControl(mWindowPtr, &macRect, "\p", true, 0, 0, 1, mControlType, nil);
}
mLastBounds = ctlRect;
return NS_OK; mLastBounds = mBounds;
return theResult;
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -95,17 +88,9 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
{ {
if (mControl && mVisible) if (mControl && mVisible)
{ {
#if 0 // turn off drawing for setup to avoid ugliness
// set the control text attributes Boolean isVisible = IsControlVisible(mControl);
// (the rendering context has already set these attributes for ::SetControlVisibility(mControl, false, false);
// the window: we just have to transfer them over to the control)
ControlFontStyleRec fontStyleRec;
fontStyleRec.flags = (kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask);
fontStyleRec.font = mWindowPtr->txFont;
fontStyleRec.size = mWindowPtr->txSize;
fontStyleRec.style = mWindowPtr->txFace;
::SetControlFontStyle(mControl, &fontStyleRec);
#endif
// draw the control // draw the control
if (mLabel != mLastLabel) if (mLabel != mLastLabel)
@ -119,8 +104,8 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
if (mBounds != mLastBounds) if (mBounds != mLastBounds)
{ {
mLastBounds = mBounds; mLastBounds = mBounds;
nsRect ctlRect = mBounds; nsRect ctlRect;
ctlRect.x = ctlRect.y = 0; GetRectForMacControl(ctlRect);
Rect macRect; Rect macRect;
nsRectToMacRect(ctlRect, macRect); nsRectToMacRect(ctlRect, macRect);
::MoveControl(mControl, macRect.left, macRect.top); ::MoveControl(mControl, macRect.left, macRect.top);
@ -130,7 +115,11 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
if (mValue != mLastValue) if (mValue != mLastValue)
{ {
mLastValue = mValue; mLastValue = mValue;
#if APPEARANCE1_1
::SetControl32BitValue(mControl, mValue);
#else
::SetControlValue(mControl, mValue); ::SetControlValue(mControl, mValue);
#endif
} }
PRInt16 hilite; PRInt16 hilite;
@ -144,7 +133,8 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
::HiliteControl(mControl, hilite); ::HiliteControl(mControl, hilite);
} }
::Draw1Control(mControl); ::SetControlVisibility(mControl, isVisible, false);
::DrawOneControl(mControl);
::ValidRect(&(*mControl)->contrlRect); ::ValidRect(&(*mControl)->contrlRect);
} }
return PR_FALSE; return PR_FALSE;
@ -208,10 +198,7 @@ NS_IMETHODIMP nsMacControl::Show(PRBool bState)
Inherited::Show(bState); Inherited::Show(bState);
if (mControl) if (mControl)
{ {
if (bState) ::SetControlVisibility(mControl, bState, false); // don't redraw
::ShowControl(mControl);
else
::HideControl(mControl);
} }
return NS_OK; return NS_OK;
} }
@ -225,6 +212,73 @@ NS_IMETHODIMP nsMacControl::SetFont(const nsFont &aFont)
{ {
Inherited::SetFont(aFont); Inherited::SetFont(aFont);
SetupMacControlFont();
return NS_OK;
}
#pragma mark -
//-------------------------------------------------------------------------
//
// Get the rect which the Mac control uses. This may be different for
// different controls, so this method allows overriding
//
//-------------------------------------------------------------------------
void nsMacControl::GetRectForMacControl(nsRect &outRect)
{
outRect = mBounds;
outRect.x = outRect.y = 0;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsMacControl::CreateOrReplaceMacControl(short inControlType)
{
nsRect controlRect;
GetRectForMacControl(controlRect);
Rect macRect;
nsRectToMacRect(controlRect, macRect);
if(nsnull != mWindowPtr)
{
if (mControl)
::DisposeControl(mControl);
#ifdef DEBUG
// we should have a root control at this point. If not, something's wrong.
// it's made in nsMacWindow
ControlHandle rootControl = nil;
OSErr err = ::GetRootControl(mWindowPtr, &rootControl);
NS_ASSERTION((err == noErr && rootControl != nil), "No root control exists for the window");
#endif
mControl = ::NewControl(mWindowPtr, &macRect, "\p", true, 0, 0, 1, inControlType, nil);
// need to reset the font now
// XXX to do: transfer the text in the old control over too
if (mControl && mFontMetrics)
{
SetupMacControlFont();
}
}
return (mControl) ? NS_OK : NS_ERROR_NULL_POINTER;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
void nsMacControl::SetupMacControlFont()
{
NS_PRECONDITION(mFontMetrics != nsnull, "No font metrics in SetupMacControlFont");
NS_PRECONDITION(mContext != nsnull, "No context metrics in SetupMacControlFont");
TextStyle theStyle; TextStyle theStyle;
nsFontMetricsMac::GetNativeTextStyle(*mFontMetrics, *mContext, theStyle); nsFontMetricsMac::GetNativeTextStyle(*mFontMetrics, *mContext, theStyle);
@ -234,6 +288,7 @@ NS_IMETHODIMP nsMacControl::SetFont(const nsFont &aFont)
fontStyleRec.size = theStyle.tsSize; fontStyleRec.size = theStyle.tsSize;
fontStyleRec.style = theStyle.tsFace; fontStyleRec.style = theStyle.tsFace;
::SetControlFontStyle(mControl, &fontStyleRec); ::SetControlFontStyle(mControl, &fontStyleRec);
return NS_OK;
} }

View File

@ -22,6 +22,7 @@
#include "nsWindow.h" #include "nsWindow.h"
#include <Controls.h> #include <Controls.h>
#define APPEARANCE1_1 1
class nsMacControl : public nsWindow class nsMacControl : public nsWindow
{ {
@ -52,16 +53,22 @@ public:
NS_IMETHODIMP SetFont(const nsFont &aFont); NS_IMETHODIMP SetFont(const nsFont &aFont);
protected: protected:
NS_METHOD CreateOrReplaceMacControl(short inControlType);
virtual void GetRectForMacControl(nsRect &outRect);
void SetupMacControlFont();
nsString mLabel; nsString mLabel;
PRBool mWidgetArmed; PRBool mWidgetArmed;
PRBool mMouseInButton; PRBool mMouseInButton;
PRInt16 mValue;
PRInt32 mValue;
ControlHandle mControl; ControlHandle mControl;
short mControlType; short mControlType;
nsString mLastLabel; nsString mLastLabel;
nsRect mLastBounds; nsRect mLastBounds;
PRInt16 mLastValue; PRInt32 mLastValue;
PRInt16 mLastHilite; PRInt16 mLastHilite;
}; };