Adjusted checkbox gfx-rendering code to make better looking checkboxes

Created nsFormControlHelper::GetBool and nsFormControlHelper::GetBoolString
utility methods for converting strings into booleans and vice versa.
Modified nsCheckboxControlFrame, nsRadioControlFrame, and nsSelectControlFrame
to use these helpers.
This commit is contained in:
kmcclusk%netscape.com 1999-02-05 22:15:35 +00:00
Родитель 1f6789b4e5
Коммит 75802b29d1
9 изменённых файлов: 119 добавлений и 59 удалений

Просмотреть файл

@ -40,7 +40,7 @@ class nsFormFrame;
// using GFX calls, rather than creating a widget. Undefining it
// causes widgets to be used for form elements. @see RequiresWidget method
// to see which widgets will obey this directive.
#undef NS_GFX_RENDER_FORM_ELEMENTS
#define NS_GFX_RENDER_FORM_ELEMENTS
/**
* nsFormControlFrame is the base class for frames of form controls. It

Просмотреть файл

@ -92,6 +92,22 @@ void nsFormControlHelper::ForceDrawFrame(nsIFrame * aFrame)
}
}
PRBool nsFormControlHelper::GetBool(const nsString& aValue)
{
if (aValue == NS_STRING_TRUE)
return(PR_TRUE);
else
return (PR_FALSE);
}
void nsFormControlHelper::GetBoolString(const PRBool aValue, nsString& aResult)
{
if (PR_TRUE == aValue)
aResult = NS_STRING_TRUE;
else
aResult = NS_STRING_FALSE;
}
nsCompatibility
nsFormControlHelper::GetRepChars(nsIPresContext& aPresContext, char& char1, char& char2)
@ -617,27 +633,33 @@ void
nsFormControlHelper::PaintScaledCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, PRUint32 aWidth, PRUint32 aHeight)
{
const int checkpoints = 7;
const float checksize = 8.0f;
const PRUint32 checkpoints = 7;
const PRUint32 checksize = 9; //This is value is determined by added 2 units to the end
//of the 7X& pixel rectangle below to provide some white space
//around the checkmark when it is rendered.
// Points come from the coordinates on a 7X7 pixels
// box with 0,0 at the lower left.
nscoord checkedPolygonDef[] = {0,2, 2,4, 6,0 , 6,2, 2,6, 0,4, 0,2 };
// Location of the center point of the checkmark
const PRUint32 centerx = 3;
const PRUint32 centery = 3;
nsPoint checkedPolygon[checkpoints];
PRUint32 defIndex = 0;
PRUint32 polyIndex = 0;
// Scale the checkmark based on the smallest dimension
float size = aWidth / checksize;
PRUint32 size = aWidth / checksize;
if (aHeight < aWidth) {
size = aHeight / checksize;
}
// Center and offset each point in the polygon definition.
for (defIndex = 0; defIndex < (checkpoints * 2); defIndex++) {
checkedPolygon[polyIndex].x = nscoord(((float(checkedPolygonDef[defIndex]) - 3.0) * (size)) + (aWidth / 2.0));
checkedPolygon[polyIndex].x = nscoord((((checkedPolygonDef[defIndex]) - centerx) * (size)) + (aWidth / 2));
defIndex++;
checkedPolygon[polyIndex].y = nscoord(((float(checkedPolygonDef[defIndex]) - 3.0) * (size)) + (aHeight / 2.0));
checkedPolygon[polyIndex].y = nscoord((((checkedPolygonDef[defIndex]) - centery) * (size)) + (aHeight / 2));
polyIndex++;
}

Просмотреть файл

@ -37,6 +37,9 @@ class nsFormFrame;
#define CSS_NOTSET -1
#define ATTR_NOTSET -1
#define NS_STRING_TRUE "1"
#define NS_STRING_FALSE "0"
/**
* Enumeration of possible mouse states used to detect mouse clicks
*/
@ -106,6 +109,25 @@ public:
static void ForceDrawFrame(nsIFrame * aFrame);
/**
* Utility to convert a string to a PRBool
* @param aValue string to convert to a PRBool
* @returns PR_TRUE if aValue = "1", PR_FALSE otherwise
*/
static PRBool GetBool(const nsString& aValue);
/**
* Utility to convert a PRBool to a string
* @param aValue Boolean value to convert to string.
* @param aResult string to hold the boolean value. It is set to "1"
* if aValue equals PR_TRUE, "0" if aValue equals PR_FALSE.
*/
static void GetBoolString(const PRBool aValue, nsString& aResult);
// XXX similar functionality needs to be added to widget library and these
// need to change to use it.
static nscoord GetScrollbarWidth(float aPixToTwip);

Просмотреть файл

@ -183,9 +183,9 @@ nsCheckboxControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord&
nsresult result = GetDefaultCheckState(&checked);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (PR_TRUE == checked)
SetProperty(nsHTMLAtoms::checked, "1");
SetProperty(nsHTMLAtoms::checked, NS_STRING_TRUE);
else
SetProperty(nsHTMLAtoms::checked, "0");
SetProperty(nsHTMLAtoms::checked, NS_STRING_FALSE);
}
if (mWidget != nsnull) {
@ -374,19 +374,13 @@ void nsCheckboxControlFrame::GetCheckboxControlFrameState(nsString& aValue)
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) {
PRBool state = PR_FALSE;
checkBox->GetState(state);
if (PR_TRUE == state)
aValue = "1";
else
aValue = "0";
nsFormControlHelper::GetBoolString(state, aValue);
NS_RELEASE(checkBox);
}
}
else {
// Get the state for GFX-rendered widgets
if (PR_TRUE == mChecked)
aValue = "1";
else
aValue = "0";
nsFormControlHelper::GetBoolString(mChecked, aValue);
}
}
@ -396,22 +390,14 @@ void nsCheckboxControlFrame::SetCheckboxControlFrameState(const nsString& aValue
if (nsnull != mWidget) {
nsICheckButton* checkBox = nsnull;
if (NS_OK == mWidget->QueryInterface(kICheckButtonIID,(void**)&checkBox)) {
PRBool state = PR_FALSE;
if (aValue == "1")
checkBox->SetState(PR_TRUE);
else
checkBox->SetState(PR_FALSE);
PRBool state = nsFormControlHelper::GetBool(aValue);
checkBox->SetState(state);
NS_RELEASE(checkBox);
}
}
else {
// Set the state for GFX-rendered widgets
if (aValue == "1")
mChecked = PR_TRUE;
else
mChecked = PR_FALSE;
mChecked = nsFormControlHelper::GetBool(aValue);
nsFormControlHelper::ForceDrawFrame(this);
}
}

Просмотреть файл

@ -40,7 +40,7 @@ class nsFormFrame;
// using GFX calls, rather than creating a widget. Undefining it
// causes widgets to be used for form elements. @see RequiresWidget method
// to see which widgets will obey this directive.
#undef NS_GFX_RENDER_FORM_ELEMENTS
#define NS_GFX_RENDER_FORM_ELEMENTS
/**
* nsFormControlFrame is the base class for frames of form controls. It

Просмотреть файл

@ -92,6 +92,22 @@ void nsFormControlHelper::ForceDrawFrame(nsIFrame * aFrame)
}
}
PRBool nsFormControlHelper::GetBool(const nsString& aValue)
{
if (aValue == NS_STRING_TRUE)
return(PR_TRUE);
else
return (PR_FALSE);
}
void nsFormControlHelper::GetBoolString(const PRBool aValue, nsString& aResult)
{
if (PR_TRUE == aValue)
aResult = NS_STRING_TRUE;
else
aResult = NS_STRING_FALSE;
}
nsCompatibility
nsFormControlHelper::GetRepChars(nsIPresContext& aPresContext, char& char1, char& char2)
@ -617,27 +633,33 @@ void
nsFormControlHelper::PaintScaledCheckMark(nsIRenderingContext& aRenderingContext,
float aPixelsToTwips, PRUint32 aWidth, PRUint32 aHeight)
{
const int checkpoints = 7;
const float checksize = 8.0f;
const PRUint32 checkpoints = 7;
const PRUint32 checksize = 9; //This is value is determined by added 2 units to the end
//of the 7X& pixel rectangle below to provide some white space
//around the checkmark when it is rendered.
// Points come from the coordinates on a 7X7 pixels
// box with 0,0 at the lower left.
nscoord checkedPolygonDef[] = {0,2, 2,4, 6,0 , 6,2, 2,6, 0,4, 0,2 };
// Location of the center point of the checkmark
const PRUint32 centerx = 3;
const PRUint32 centery = 3;
nsPoint checkedPolygon[checkpoints];
PRUint32 defIndex = 0;
PRUint32 polyIndex = 0;
// Scale the checkmark based on the smallest dimension
float size = aWidth / checksize;
PRUint32 size = aWidth / checksize;
if (aHeight < aWidth) {
size = aHeight / checksize;
}
// Center and offset each point in the polygon definition.
for (defIndex = 0; defIndex < (checkpoints * 2); defIndex++) {
checkedPolygon[polyIndex].x = nscoord(((float(checkedPolygonDef[defIndex]) - 3.0) * (size)) + (aWidth / 2.0));
checkedPolygon[polyIndex].x = nscoord((((checkedPolygonDef[defIndex]) - centerx) * (size)) + (aWidth / 2));
defIndex++;
checkedPolygon[polyIndex].y = nscoord(((float(checkedPolygonDef[defIndex]) - 3.0) * (size)) + (aHeight / 2.0));
checkedPolygon[polyIndex].y = nscoord((((checkedPolygonDef[defIndex]) - centery) * (size)) + (aHeight / 2));
polyIndex++;
}

Просмотреть файл

@ -37,6 +37,9 @@ class nsFormFrame;
#define CSS_NOTSET -1
#define ATTR_NOTSET -1
#define NS_STRING_TRUE "1"
#define NS_STRING_FALSE "0"
/**
* Enumeration of possible mouse states used to detect mouse clicks
*/
@ -106,6 +109,25 @@ public:
static void ForceDrawFrame(nsIFrame * aFrame);
/**
* Utility to convert a string to a PRBool
* @param aValue string to convert to a PRBool
* @returns PR_TRUE if aValue = "1", PR_FALSE otherwise
*/
static PRBool GetBool(const nsString& aValue);
/**
* Utility to convert a PRBool to a string
* @param aValue Boolean value to convert to string.
* @param aResult string to hold the boolean value. It is set to "1"
* if aValue equals PR_TRUE, "0" if aValue equals PR_FALSE.
*/
static void GetBoolString(const PRBool aValue, nsString& aResult);
// XXX similar functionality needs to be added to widget library and these
// need to change to use it.
static nscoord GetScrollbarWidth(float aPixToTwip);

Просмотреть файл

@ -102,9 +102,9 @@ nsRadioControlFrame::PostCreateWidget(nsIPresContext* aPresContext, nscoord& aWi
nsresult result = GetDefaultCheckState(&checked);
if (NS_CONTENT_ATTR_HAS_VALUE == result) {
if (PR_TRUE == checked)
SetProperty(nsHTMLAtoms::checked, "1");
SetProperty(nsHTMLAtoms::checked, NS_STRING_TRUE);
else
SetProperty(nsHTMLAtoms::checked, "0");
SetProperty(nsHTMLAtoms::checked, NS_STRING_FALSE);
}
if (mWidget != nsnull) {
@ -157,7 +157,7 @@ nsRadioControlFrame::AttributeChanged(nsIPresContext* aPresContext,
void
nsRadioControlFrame::MouseClicked(nsIPresContext* aPresContext)
{
SetProperty(nsHTMLAtoms::checked, "1");
SetProperty(nsHTMLAtoms::checked, NS_STRING_TRUE);
if (mFormFrame) {
// The form frame will determine which radio button needs
@ -192,9 +192,9 @@ nsRadioControlFrame::SetChecked(PRBool aValue, PRBool aSetInitialValue)
}
if (PR_TRUE == aValue)
SetProperty(nsHTMLAtoms::checked, "1");
SetProperty(nsHTMLAtoms::checked, NS_STRING_TRUE);
else
SetProperty(nsHTMLAtoms::checked, "0");
SetProperty(nsHTMLAtoms::checked, NS_STRING_FALSE);
}
@ -364,19 +364,13 @@ void nsRadioControlFrame::GetRadioControlFrameState(nsString& aValue)
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
PRBool state = PR_FALSE;
radio->GetState(state);
if (PR_TRUE == state)
aValue = "1";
else
aValue = "0";
nsFormControlHelper::GetBoolString(state, aValue);
NS_RELEASE(radio);
}
}
else {
// Get the state for GFX-rendered widgets
if (PR_TRUE == mChecked)
aValue = "1";
else
aValue = "0";
nsFormControlHelper::GetBoolString(mChecked, aValue);
}
}
@ -385,7 +379,7 @@ void nsRadioControlFrame::SetRadioControlFrameState(const nsString& aValue)
if (nsnull != mWidget) {
nsIRadioButton* radio = nsnull;
if (NS_OK == mWidget->QueryInterface(kIRadioIID,(void**)&radio)) {
if (aValue == "1")
if (aValue == NS_STRING_TRUE)
radio->SetState(PR_TRUE);
else
radio->SetState(PR_FALSE);
@ -395,11 +389,7 @@ void nsRadioControlFrame::SetRadioControlFrameState(const nsString& aValue)
}
else {
// Set the state for GFX-rendered widgets
if (aValue == "1")
mChecked = PR_TRUE;
else
mChecked = PR_FALSE;
mChecked = nsFormControlHelper::GetBool(aValue);
nsFormControlHelper::ForceDrawFrame(this);
}
}

Просмотреть файл

@ -1059,11 +1059,7 @@ NS_IMETHODIMP nsSelectControlFrame::GetProperty(nsIAtom* aName, nsString& aValue
PRInt32 index = aValue.ToInteger(&error, 10); // Get index from aValue
if (error == 0)
GetOptionSelected(index, &selected);
if (selected) {
aValue = "1";
} else {
aValue = "0";
}
nsFormControlHelper::GetBoolString(selected, aValue);
// For selectedIndex, get the value from the widget
} else if (nsHTMLAtoms::selectedindex == aName) {