Added mValue.

This commit is contained in:
pierre%netscape.com 1998-11-04 06:42:26 +00:00
parent 8d718109c8
commit c41f1dfb00
2 changed files with 73 additions and 32 deletions

View File

@ -26,11 +26,16 @@
//-------------------------------------------------------------------------
nsMacControl::nsMacControl() : nsWindow()
{
mButtonSet = PR_FALSE;
mValue = 0;
mWidgetArmed = PR_FALSE;
mMouseInButton = PR_FALSE;
mControl = nsnull;
mControlType = pushButProc;
mLastLabel = "";
mLastBounds.SetRect(0,0,0,0);
mLastValue = 0;
mLastHilite = 0;
}
//-------------------------------------------------------------------------
@ -45,7 +50,7 @@ NS_IMETHODIMP nsMacControl::Create(nsIWidget *aParent,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
nsWindow::Create(aParent, aRect, aHandleEventFunction,
Inherited::Create(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData);
@ -56,6 +61,8 @@ NS_IMETHODIMP nsMacControl::Create(nsIWidget *aParent,
nsRectToMacRect(ctlRect, macRect);
mControl = ::NewControl(mWindowPtr, &macRect, "\p", true, 0, 0, 1, mControlType, nil);
mLastBounds = ctlRect;
return NS_OK;
}
@ -72,6 +79,7 @@ nsMacControl::~nsMacControl()
}
}
#pragma mark -
//-------------------------------------------------------------------------
//
//
@ -90,43 +98,49 @@ PRBool nsMacControl::OnPaint(nsPaintEvent &aEvent)
fontStyleRec.style = mWindowPtr->txFace;
::SetControlFontStyle(mControl, &fontStyleRec);
/*
// set the background color
//ĽTODO: this should be done by the rendering context
#define COLOR8TOCOLOR16(color8) (color8 == 0xFF ? 0xFFFF : (color8 << 8))
nscolor backColor = GetBackgroundColor();
RGBColor macColor;
macColor.red = COLOR8TOCOLOR16(NS_GET_R(backColor));
macColor.green = COLOR8TOCOLOR16(NS_GET_G(backColor));
macColor.blue = COLOR8TOCOLOR16( NS_GET_B(backColor));
::RGBBackColor(&macColor);
*/
// draw the control
Str255 aStr;
StringToStr255(mLabel, aStr);
::SetControlTitle(mControl, aStr);
if (mLabel != mLastLabel)
{
mLastLabel = mLabel;
Str255 aStr;
StringToStr255(mLabel, aStr);
::SetControlTitle(mControl, aStr);
}
::SetControlValue(mControl, (mButtonSet ? 1 : 0));
if (mBounds != mLastBounds)
{
mLastBounds = mBounds;
nsRect ctlRect = mBounds;
ctlRect.x = ctlRect.y = 0;
Rect macRect;
nsRectToMacRect(ctlRect, macRect);
::MoveControl(mControl, macRect.left, macRect.top);
::SizeControl(mControl, ctlRect.width, ctlRect.height);
}
if (mValue != mLastValue)
{
mLastValue = mValue;
::SetControlValue(mControl, mValue);
}
PRInt16 hilite;
if (mEnabled)
::HiliteControl(mControl, (mWidgetArmed && mMouseInButton ? 1 : 0));
hilite = (mWidgetArmed && mMouseInButton ? 1 : 0);
else
::HiliteControl(mControl, kControlInactivePart);
hilite = kControlInactivePart;
if (hilite != mLastHilite)
{
mLastHilite = hilite;
::HiliteControl(mControl, hilite);
}
::ValidRect(&(*mControl)->contrlRect);
::Draw1Control(mControl);
//¥¥ ::ValidRect(&(*mControl)->contrlRect);
}
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
PRBool nsMacControl::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
//
@ -172,5 +186,23 @@ PRBool nsMacControl::DispatchMouseEvent(nsMouseEvent &aEvent)
}
if (eatEvent)
return PR_TRUE;
return (nsWindow::DispatchMouseEvent(aEvent));
return (Inherited::DispatchMouseEvent(aEvent));
}
#pragma mark -
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsMacControl::Show(PRBool bState)
{
Inherited::Show(bState);
if (mControl)
{
if (bState)
::ShowControl(mControl);
else
::HideControl(mControl);
}
return NS_OK;
}

View File

@ -25,6 +25,8 @@
class nsMacControl : public nsWindow
{
private:
typedef nsWindow Inherited;
public:
nsMacControl();
@ -39,20 +41,27 @@ public:
nsWidgetInitData *aInitData = nsnull);
virtual void SetControlType(short type) {mControlType = type;}
short GetControlType() {return mControlType;}
// event handling
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
// nsIWidget interface
NS_IMETHOD Show(PRBool aState);
protected:
nsString mLabel;
PRBool mWidgetArmed;
PRBool mMouseInButton;
PRBool mButtonSet;
PRInt16 mValue;
ControlHandle mControl;
short mControlType;
nsString mLastLabel;
nsRect mLastBounds;
PRInt16 mLastValue;
PRInt16 mLastHilite;
};
#endif // nsMacControl_h__