зеркало из https://github.com/mozilla/gecko-dev.git
Added paint method for printing (and possible future owner draw)
This commit is contained in:
Родитель
43ff6e4a58
Коммит
b05e123c34
|
@ -597,6 +597,12 @@ class nsIWidget : public nsISupports {
|
|||
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
|
||||
|
||||
|
||||
/**
|
||||
* For printing and lightweight widgets
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect) = 0;
|
||||
|
||||
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) = 0;
|
||||
};
|
||||
|
|
|
@ -1625,3 +1625,19 @@ NS_METHOD nsWindow::GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints default border (XXX - this should be done by CSS)
|
||||
* (This method is in nsBaseWidget)
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsWindow::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsRect rect;
|
||||
GetBounds(rect);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
aRenderingContext.DrawRect(rect);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -133,6 +133,7 @@ public:
|
|||
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
|
||||
NS_IMETHOD GetClientBounds(nsRect &aRect);
|
||||
NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect);
|
||||
|
||||
|
||||
virtual PRBool IsChild() { return(PR_FALSE); };
|
||||
|
|
|
@ -24,6 +24,16 @@
|
|||
#include "nsStringUtil.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
|
||||
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsButton)
|
||||
NS_IMPL_RELEASE(nsButton)
|
||||
|
@ -79,6 +89,8 @@ nsresult nsButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsButton::SetLabel(const nsString& aText)
|
||||
{
|
||||
|
||||
mLabel = aText;
|
||||
if (NULL == mWnd) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -95,12 +107,15 @@ NS_METHOD nsButton::SetLabel(const nsString& aText)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsButton::GetLabel(nsString& aBuffer)
|
||||
{
|
||||
int actualSize = ::GetWindowTextLength(mWnd)+1;
|
||||
aBuffer = mLabel;
|
||||
|
||||
/*int actualSize = ::GetWindowTextLength(mWnd)+1;
|
||||
NS_ALLOC_CHAR_BUF(label, 256, actualSize);
|
||||
::GetWindowText(mWnd, label, actualSize);
|
||||
aBuffer.SetLength(0);
|
||||
aBuffer.Append(label);
|
||||
NS_FREE_CHAR_BUF(label);
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -155,4 +170,97 @@ DWORD nsButton::WindowExStyle()
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Button for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsButton::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
float appUnits;
|
||||
float devUnits;
|
||||
float scale;
|
||||
nsIDeviceContext * context;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
|
||||
context->GetCanonicalPixelScale(scale);
|
||||
context->GetAppUnitsToDevUnits(devUnits);
|
||||
context->GetDevUnitsToAppUnits(appUnits);
|
||||
|
||||
nsRect rect;
|
||||
GetBoundsAppUnits(rect, appUnits);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscolor bgColor = NS_RGB(255,255,255);
|
||||
nscolor fgColor = NS_RGB(0,0,0);
|
||||
nscolor hltColor = NS_RGB(240,240,240);
|
||||
nscolor sdwColor = NS_RGB(128,128,128);
|
||||
|
||||
nsILookAndFeel * lookAndFeel;
|
||||
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||
}
|
||||
|
||||
aRenderingContext.SetColor(bgColor);
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
/*aRenderingContext.SetColor(bgColor);
|
||||
for (int i=0;i<int(scale);i++) {
|
||||
aRenderingContext.DrawRect(rect);
|
||||
rect.x += 3;
|
||||
rect.y += 3;
|
||||
rect.width -= 6;
|
||||
rect.height -= 6;
|
||||
}*/
|
||||
|
||||
nscoord onePixel = nscoord(scale);
|
||||
nscoord twoPixels = nscoord(scale*2);
|
||||
|
||||
rect.x += onePixel;
|
||||
rect.y += onePixel;
|
||||
rect.width -= twoPixels;
|
||||
rect.height -= twoPixels;
|
||||
|
||||
nscoord right = rect.x+rect.width;
|
||||
nscoord bottom = rect.y+rect.height;
|
||||
|
||||
|
||||
// Draw Left & Top
|
||||
aRenderingContext.SetColor(NS_RGB(225,225,225));
|
||||
DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top
|
||||
DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left
|
||||
|
||||
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1
|
||||
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1
|
||||
|
||||
// Draw Right & Bottom
|
||||
aRenderingContext.SetColor(NS_RGB(128,128,128));
|
||||
DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right
|
||||
DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom
|
||||
|
||||
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
|
||||
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
|
||||
|
||||
aRenderingContext.SetFont(*mFont);
|
||||
|
||||
nscoord textWidth;
|
||||
nscoord textHeight;
|
||||
aRenderingContext.GetWidth(mLabel, textWidth);
|
||||
|
||||
nsIFontMetrics* metrics;
|
||||
context->GetMetricsFor(*mFont, metrics);
|
||||
metrics->GetMaxAscent(textHeight);
|
||||
|
||||
nscoord x = ((rect.width - textWidth) / 2) + rect.x;
|
||||
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||
aRenderingContext.DrawString(mLabel, x, y, 0);
|
||||
|
||||
|
||||
NS_RELEASE(context);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -46,12 +46,17 @@ public:
|
|||
NS_IMETHOD SetLabel(const nsString& aText);
|
||||
NS_IMETHOD GetLabel(nsString& aBuffer);
|
||||
|
||||
|
||||
// nsBaseWidget
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint();
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
||||
protected:
|
||||
nsString mLabel;
|
||||
|
||||
virtual LPCTSTR WindowClass();
|
||||
virtual DWORD WindowStyle();
|
||||
virtual DWORD WindowExStyle();
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
#include "nsStringUtil.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsCheckButton)
|
||||
NS_IMPL_RELEASE(nsCheckButton)
|
||||
|
@ -33,7 +38,8 @@ NS_IMPL_RELEASE(nsCheckButton)
|
|||
// nsCheckButton constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton()
|
||||
nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton(),
|
||||
mState(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
@ -80,12 +86,15 @@ nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsCheckButton::SetState(const PRBool aState)
|
||||
{
|
||||
BOOL state;
|
||||
if (aState)
|
||||
state = BST_CHECKED;
|
||||
else
|
||||
state = BST_UNCHECKED;
|
||||
::SendMessage(mWnd, BM_SETCHECK, (WPARAM)state, (LPARAM)0);
|
||||
mState = aState;
|
||||
if (mWnd) {
|
||||
BOOL state;
|
||||
if (aState)
|
||||
state = BST_CHECKED;
|
||||
else
|
||||
state = BST_UNCHECKED;
|
||||
::SendMessage(mWnd, BM_SETCHECK, (WPARAM)state, (LPARAM)0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -188,4 +197,57 @@ DWORD nsCheckButton::WindowExStyle()
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* Renders the CheckButton for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsRect rect;
|
||||
float appUnits;
|
||||
float scale;
|
||||
nsIDeviceContext * context;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
|
||||
context->GetCanonicalPixelScale(scale);
|
||||
context->GetDevUnitsToAppUnits(appUnits);
|
||||
|
||||
GetBoundsAppUnits(rect, appUnits);
|
||||
|
||||
nscoord one = nscoord(PRFloat64(rect.height) * 1.0/20.0);
|
||||
nscoord three = nscoord(PRFloat64(rect.width) * 3.0/20.0);
|
||||
nscoord five = nscoord(PRFloat64(rect.width) * 5.0/20.0);
|
||||
nscoord six = nscoord(PRFloat64(rect.height) * 5.0/20.0);
|
||||
nscoord eight = nscoord(PRFloat64(rect.height) * 7.0/20.0);
|
||||
nscoord nine = nscoord(PRFloat64(rect.width) * 9.0/20.0);
|
||||
nscoord ten = nscoord(PRFloat64(rect.height) * 9.0/20.0);
|
||||
|
||||
rect.x += three;
|
||||
rect.y += nscoord(PRFloat64(rect.height) * 3.5 /20.0);
|
||||
rect.width = nscoord(PRFloat64(rect.width) * 12.0/20.0);
|
||||
rect.height = nscoord(PRFloat64(rect.height) * 12.0/20.0);
|
||||
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscoord onePixel = nscoord((appUnits+0.6F));
|
||||
DrawScaledRect(aRenderingContext, rect, scale, appUnits);
|
||||
nscoord x = rect.x;
|
||||
nscoord y = rect.y;
|
||||
|
||||
if (mState) {
|
||||
nscoord inc = nscoord(PRFloat64(rect.height) * 0.75/20.0);
|
||||
nscoord yy = 0;
|
||||
for (nscoord i=0;i<4;i++) {
|
||||
DrawScaledLine(aRenderingContext, x+three, y+eight+yy, x+five, y+ten+yy, scale, appUnits, PR_FALSE); // top
|
||||
DrawScaledLine(aRenderingContext, x+five, y+ten+yy, x+nine, y+six+yy, scale, appUnits, PR_FALSE); // top
|
||||
//aRenderingContext.DrawLine(x+three, y+eight+yy, x+five, y+ten+yy);
|
||||
//aRenderingContext.DrawLine(x+five, y+ten+yy, x+nine, y+six+yy);
|
||||
yy += nscoord(scale);
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(context);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,12 +48,16 @@ public:
|
|||
NS_IMETHOD SetState(const PRBool aState);
|
||||
NS_IMETHOD GetState(PRBool& aState);
|
||||
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint();
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
||||
|
||||
protected:
|
||||
PRBool mState;
|
||||
|
||||
virtual LPCTSTR WindowClass();
|
||||
virtual DWORD WindowStyle();
|
||||
|
|
|
@ -24,6 +24,15 @@
|
|||
#include "nsStringUtil.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
|
||||
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
NS_IMPL_ADDREF(nsComboBox)
|
||||
NS_IMPL_RELEASE(nsComboBox)
|
||||
|
||||
|
@ -279,4 +288,72 @@ NS_METHOD nsComboBox::GetBounds(nsRect &aRect)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the TextWidget for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsComboBox::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||
/*nsRect rect;
|
||||
GetBoundsAppUnits(rect, aTwipsConversion);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscolor bgColor = NS_RGB(255,255,255);
|
||||
nscolor fgColor = NS_RGB(0,0,0);
|
||||
nscolor hltColor = NS_RGB(240,240,240);
|
||||
nscolor sdwColor = NS_RGB(128,128,128);
|
||||
nsILookAndFeel * lookAndFeel;
|
||||
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||
}
|
||||
|
||||
nsIDeviceContext * context;
|
||||
//nsDrawingSurface surface;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
//context->GetDrawingSurface(aRenderingContext, surface);
|
||||
|
||||
//HDC the_hdc = ((nsDrawingSurfaceWin *)&surface)->mDC;
|
||||
|
||||
//::SendMessage(mWnd, WM_PAINT, (WPARAM)the_hdc, NULL);
|
||||
|
||||
|
||||
// shrink by one pixel
|
||||
|
||||
nscoord onePixel = nscoord((aTwipsConversion+0.6F));
|
||||
nscoord twoPixels = onePixel*2;
|
||||
|
||||
nsString text("(ComboBox)");
|
||||
//GetSelectedItem(text);
|
||||
|
||||
|
||||
aRenderingContext.SetColor(bgColor);
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
aRenderingContext.DrawRect(rect);
|
||||
|
||||
|
||||
aRenderingContext.SetFont(*mFont);
|
||||
|
||||
nscoord textWidth;
|
||||
nscoord textHeight;
|
||||
aRenderingContext.GetWidth(text, textWidth);
|
||||
|
||||
nsIFontMetrics* metrics;
|
||||
context->GetMetricsFor(*mFont, metrics);
|
||||
metrics->GetMaxAscent(textHeight);
|
||||
|
||||
nscoord x = (twoPixels * 2) + rect.x;
|
||||
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||
//aRenderingContext.DrawString(text, x, y, 0);
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -61,6 +61,9 @@ public:
|
|||
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||
NS_IMETHOD Deselect() ;
|
||||
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -21,8 +21,14 @@
|
|||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsRadioButton)
|
||||
NS_IMPL_RELEASE(nsRadioButton)
|
||||
|
||||
|
@ -171,6 +177,76 @@ DWORD nsRadioButton::WindowExStyle()
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the RadioButton for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsRadioButton::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
float appUnits;
|
||||
float scale;
|
||||
nsIDeviceContext * context;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
|
||||
context->GetCanonicalPixelScale(scale);
|
||||
context->GetDevUnitsToAppUnits(appUnits);
|
||||
nsRect rect;
|
||||
GetBounds(rect);
|
||||
|
||||
rect.x++;
|
||||
rect.y++;
|
||||
rect.width -= 2;
|
||||
rect.height -= 2;
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscoord one = nscoord(PRFloat64(rect.width) * 1.0/12.0);
|
||||
|
||||
rect.x = nscoord((PRFloat64)rect.x * appUnits);
|
||||
rect.y = nscoord((PRFloat64)rect.y * appUnits);
|
||||
rect.width = nscoord((PRFloat64)rect.width * appUnits);
|
||||
rect.height = nscoord((PRFloat64)rect.height * appUnits);
|
||||
rect.x += one;
|
||||
rect.width = nscoord(PRFloat64(rect.width) * 11.0/12.0);
|
||||
rect.height = nscoord(PRFloat64(rect.height) * 11.0/12.0);
|
||||
|
||||
for (nscoord i=0;i<nscoord(scale*1.25);i++) {
|
||||
aRenderingContext.DrawArc(rect, 0, 180);
|
||||
aRenderingContext.DrawArc(rect, 180, 360);
|
||||
rect.x++;
|
||||
rect.y++;
|
||||
rect.width -= 2;
|
||||
rect.height -= 2;
|
||||
}
|
||||
|
||||
if (fState) {
|
||||
GetBounds(rect);
|
||||
nscoord xHalf = rect.width / 4;
|
||||
nscoord yHalf = rect.height / 4;
|
||||
rect.x += xHalf;
|
||||
rect.y += yHalf;
|
||||
rect.width -= xHalf*2;
|
||||
rect.height -= yHalf*2;
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscoord one = nscoord(PRFloat64(rect.width) * 1.0/12.0);
|
||||
|
||||
rect.x = nscoord((PRFloat64)rect.x * appUnits);
|
||||
rect.y = nscoord((PRFloat64)rect.y * appUnits);
|
||||
rect.width = nscoord((PRFloat64)rect.width * appUnits);
|
||||
rect.height = nscoord((PRFloat64)rect.height * appUnits);
|
||||
rect.x += one;
|
||||
rect.width = nscoord(PRFloat64(rect.width) * 11.0/12.0);
|
||||
rect.height = nscoord(PRFloat64(rect.height) * 11.0/12.0);
|
||||
|
||||
aRenderingContext.FillArc(rect, 0, 180);
|
||||
aRenderingContext.FillArc(rect, 180, 360);
|
||||
|
||||
}
|
||||
|
||||
NS_RELEASE(context);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
NS_IMETHOD SetState(const PRBool aState);
|
||||
NS_IMETHOD GetState(PRBool& aState);
|
||||
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint();
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
|
|
@ -22,6 +22,18 @@
|
|||
#include "nsString.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
|
||||
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
|
||||
|
||||
|
||||
/*NS_IMPL_ADDREF(nsTextAreaWidget)
|
||||
//NS_IMPL_RELEASE(nsTextAreaWidget)
|
||||
nsrefcnt nsTextAreaWidget::Release(void)
|
||||
|
@ -165,4 +177,93 @@ NS_METHOD nsTextAreaWidget::GetBounds(nsRect &aRect)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the TextWidget for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsRect rect;
|
||||
float appUnits;
|
||||
float scale;
|
||||
nsIDeviceContext * context;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
|
||||
context->GetCanonicalPixelScale(scale);
|
||||
context->GetDevUnitsToAppUnits(appUnits);
|
||||
|
||||
GetBoundsAppUnits(rect, appUnits);
|
||||
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscolor bgColor = NS_RGB(255,255,255);
|
||||
nscolor fgColor = NS_RGB(0,0,0);
|
||||
nscolor hltColor = NS_RGB(240,240,240);
|
||||
nscolor sdwColor = NS_RGB(128,128,128);
|
||||
nscolor txtBGColor = NS_RGB(255,255,255);
|
||||
nscolor txtFGColor = NS_RGB(0,0,0);
|
||||
nsILookAndFeel * lookAndFeel;
|
||||
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, txtBGColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, txtFGColor);
|
||||
}
|
||||
|
||||
aRenderingContext.SetColor(txtBGColor);
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
// Paint Black border
|
||||
//nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||
|
||||
nscoord onePixel = nscoord(scale);
|
||||
nscoord twoPixels = nscoord(scale*2);
|
||||
|
||||
rect.x += onePixel;
|
||||
rect.y += onePixel;
|
||||
rect.width -= twoPixels+onePixel;
|
||||
rect.height -= twoPixels+onePixel;
|
||||
|
||||
nscoord right = rect.x+rect.width;
|
||||
nscoord bottom = rect.y+rect.height;
|
||||
|
||||
|
||||
// Draw Left & Top
|
||||
aRenderingContext.SetColor(NS_RGB(128,128,128));
|
||||
DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top
|
||||
DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left
|
||||
|
||||
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1
|
||||
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1
|
||||
|
||||
// Draw Right & Bottom
|
||||
aRenderingContext.SetColor(NS_RGB(192,192,192));
|
||||
DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right
|
||||
DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom
|
||||
|
||||
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
|
||||
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
|
||||
|
||||
|
||||
aRenderingContext.SetFont(*mFont);
|
||||
|
||||
nscoord textWidth;
|
||||
nscoord textHeight;
|
||||
aRenderingContext.GetWidth(mText, textWidth);
|
||||
|
||||
nsIFontMetrics* metrics;
|
||||
context->GetMetricsFor(*mFont, metrics);
|
||||
metrics->GetMaxAscent(textHeight);
|
||||
|
||||
nscoord x = (twoPixels * 2) + rect.x;
|
||||
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||
aRenderingContext.SetColor(txtFGColor);
|
||||
aRenderingContext.DrawString(mText, x, y, 0);
|
||||
|
||||
NS_RELEASE(context);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
virtual PRBool OnPaint();
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
|
||||
virtual void SetUpForPaint(HDC aHDC);
|
||||
|
|
|
@ -56,6 +56,8 @@ NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PR
|
|||
|
||||
NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize)
|
||||
{
|
||||
mText = aText;
|
||||
|
||||
NS_ALLOC_STR_BUF(buf, aText, 512);
|
||||
SetWindowText(mWnd, buf);
|
||||
NS_FREE_STR_BUF(buf);
|
||||
|
@ -66,13 +68,16 @@ NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize)
|
|||
NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize)
|
||||
{
|
||||
nsString currentText;
|
||||
|
||||
|
||||
PRUint32 actualSize;
|
||||
GetText(currentText, 256, actualSize);
|
||||
nsString newText(aText);
|
||||
currentText.Insert(newText, aStartPos, aText.Length());
|
||||
SetText(currentText,actualSize);
|
||||
aActualSize = aText.Length();
|
||||
|
||||
mText = currentText;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_METHOD nsTextHelper::RemoveText()
|
||||
|
|
|
@ -56,9 +56,9 @@ public:
|
|||
virtual PRBool AutoErase();
|
||||
|
||||
protected:
|
||||
|
||||
PRBool mIsPassword;
|
||||
PRBool mIsReadOnly;
|
||||
nsString mText;
|
||||
PRBool mIsPassword;
|
||||
PRBool mIsReadOnly;
|
||||
|
||||
virtual DWORD WindowExStyle();
|
||||
|
||||
|
|
|
@ -23,6 +23,17 @@
|
|||
#include "nsString.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
|
||||
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsTextWidget)
|
||||
NS_IMPL_RELEASE(nsTextWidget)
|
||||
|
||||
|
@ -176,4 +187,105 @@ NS_METHOD nsTextWidget::GetBounds(nsRect &aRect)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the TextWidget for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsTextWidget::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsRect rect;
|
||||
float appUnits;
|
||||
float scale;
|
||||
nsIDeviceContext * context;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
|
||||
context->GetCanonicalPixelScale(scale);
|
||||
context->GetDevUnitsToAppUnits(appUnits);
|
||||
|
||||
GetBoundsAppUnits(rect, appUnits);
|
||||
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscolor bgColor = NS_RGB(255,255,255);
|
||||
nscolor fgColor = NS_RGB(0,0,0);
|
||||
nscolor hltColor = NS_RGB(240,240,240);
|
||||
nscolor sdwColor = NS_RGB(128,128,128);
|
||||
nscolor txtBGColor = NS_RGB(255,255,255);
|
||||
nscolor txtFGColor = NS_RGB(0,0,0);
|
||||
nsILookAndFeel * lookAndFeel;
|
||||
if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, txtBGColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, txtFGColor);
|
||||
}
|
||||
|
||||
aRenderingContext.SetColor(txtBGColor);
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
// Paint Black border
|
||||
//nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||
|
||||
nscoord onePixel = nscoord(scale);
|
||||
nscoord twoPixels = nscoord(scale*2);
|
||||
|
||||
rect.x += onePixel;
|
||||
rect.y += onePixel;
|
||||
rect.width -= twoPixels+onePixel;
|
||||
rect.height -= twoPixels+onePixel;
|
||||
|
||||
nscoord right = rect.x+rect.width;
|
||||
nscoord bottom = rect.y+rect.height;
|
||||
|
||||
|
||||
// Draw Left & Top
|
||||
aRenderingContext.SetColor(NS_RGB(128,128,128));
|
||||
DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top
|
||||
DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left
|
||||
|
||||
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1
|
||||
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1
|
||||
|
||||
// Draw Right & Bottom
|
||||
aRenderingContext.SetColor(NS_RGB(192,192,192));
|
||||
DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right
|
||||
DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom
|
||||
|
||||
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
|
||||
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
|
||||
|
||||
|
||||
aRenderingContext.SetFont(*mFont);
|
||||
|
||||
nscoord textWidth;
|
||||
nscoord textHeight;
|
||||
aRenderingContext.GetWidth(mText, textWidth);
|
||||
|
||||
nsIFontMetrics* metrics;
|
||||
context->GetMetricsFor(*mFont, metrics);
|
||||
metrics->GetMaxAscent(textHeight);
|
||||
|
||||
nscoord x = (twoPixels * 2) + rect.x;
|
||||
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||
aRenderingContext.SetColor(txtFGColor);
|
||||
if (!mIsPassword) {
|
||||
aRenderingContext.DrawString(mText, x, y, 0);
|
||||
} else {
|
||||
nsString astricks;
|
||||
PRInt32 i;
|
||||
for (i=0;i<mText.Length();i++) {
|
||||
astricks.Append("*");
|
||||
}
|
||||
aRenderingContext.DrawString(astricks, x, y, 0);
|
||||
|
||||
}
|
||||
|
||||
NS_RELEASE(context);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -47,6 +47,9 @@ public:
|
|||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
virtual void SubclassWindow(BOOL bState);
|
||||
|
||||
|
||||
|
|
|
@ -667,6 +667,9 @@ NS_METHOD nsWindow::IsVisible(PRBool & bState)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsWindow::Move(PRUint32 aX, PRUint32 aY)
|
||||
{
|
||||
mBounds.x = aX;
|
||||
mBounds.y = aY;
|
||||
|
||||
if (mWnd) {
|
||||
nsIWidget *par = GetParent();
|
||||
HDWP deferrer = NULL;
|
||||
|
@ -697,6 +700,10 @@ NS_METHOD nsWindow::Move(PRUint32 aX, PRUint32 aY)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsWindow::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint)
|
||||
{
|
||||
// Set cached value for lightweight and printing
|
||||
mBounds.width = aWidth;
|
||||
mBounds.height = aHeight;
|
||||
|
||||
if (mWnd) {
|
||||
nsIWidget *par = GetParent();
|
||||
HDWP deferrer = NULL;
|
||||
|
@ -736,6 +743,12 @@ NS_METHOD nsWindow::Resize(PRUint32 aX,
|
|||
PRUint32 aHeight,
|
||||
PRBool aRepaint)
|
||||
{
|
||||
// Set cached value for lightweight and printing
|
||||
mBounds.x = aX;
|
||||
mBounds.y = aY;
|
||||
mBounds.width = aWidth;
|
||||
mBounds.height = aHeight;
|
||||
|
||||
if (mWnd) {
|
||||
nsIWidget *par = GetParent();
|
||||
HDWP deferrer = NULL;
|
||||
|
@ -830,7 +843,7 @@ NS_METHOD nsWindow::GetBounds(nsRect &aRect)
|
|||
aRect.x = r.left;
|
||||
aRect.y = r.top;
|
||||
} else {
|
||||
aRect.SetRect(0,0,0,0);
|
||||
aRect = mBounds;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -927,27 +940,29 @@ nsIFontMetrics* nsWindow::GetFont(void)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsWindow::SetFont(const nsFont &aFont)
|
||||
{
|
||||
if (nsnull == mContext) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// Cache Font for owner draw
|
||||
if (mFont == nsnull) {
|
||||
mFont = new nsFont(aFont);
|
||||
} else {
|
||||
*mFont = aFont;
|
||||
}
|
||||
|
||||
// Bail out if there is no context
|
||||
if (nsnull == mContext) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsIFontMetrics* metrics;
|
||||
mContext->GetMetricsFor(aFont, metrics);
|
||||
nsFontHandle fontHandle;
|
||||
metrics->GetFontHandle(fontHandle);
|
||||
HFONT hfont = (HFONT)fontHandle;
|
||||
nsIFontMetrics* metrics;
|
||||
mContext->GetMetricsFor(aFont, metrics);
|
||||
nsFontHandle fontHandle;
|
||||
metrics->GetFontHandle(fontHandle);
|
||||
HFONT hfont = (HFONT)fontHandle;
|
||||
|
||||
// Draw in the new font
|
||||
::SendMessage(mWnd, WM_SETFONT, (WPARAM)hfont, (LPARAM)0);
|
||||
NS_RELEASE(metrics);
|
||||
// Draw in the new font
|
||||
::SendMessage(mWnd, WM_SETFONT, (WPARAM)hfont, (LPARAM)0);
|
||||
NS_RELEASE(metrics);
|
||||
|
||||
// XXX Temporary, should not be caching the font
|
||||
if (mFont == nsnull) {
|
||||
mFont = new nsFont(aFont);
|
||||
} else {
|
||||
*mFont = aFont;
|
||||
}
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1454,15 +1469,15 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
|||
newWidth = PRInt32(r.right - r.left);
|
||||
newHeight = PRInt32(r.bottom - r.top);
|
||||
nsRect rect(wp->x, wp->y, newWidth, newHeight);
|
||||
//if (newWidth != mWidth)
|
||||
//if (newWidth != mBounds.width)
|
||||
{
|
||||
RECT drect;
|
||||
|
||||
//getting wider
|
||||
|
||||
drect.left = wp->x + mWidth;
|
||||
drect.left = wp->x + mBounds.width;
|
||||
drect.top = wp->y;
|
||||
drect.right = drect.left + (newWidth - mWidth);
|
||||
drect.right = drect.left + (newWidth - mBounds.width);
|
||||
drect.bottom = drect.top + newHeight;
|
||||
|
||||
// ::InvalidateRect(mWnd, NULL, FALSE);
|
||||
|
@ -1470,24 +1485,24 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
|
|||
::RedrawWindow(mWnd, &drect, NULL,
|
||||
RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ERASENOW | RDW_ALLCHILDREN);
|
||||
}
|
||||
//if (newHeight != mHeight)
|
||||
//if (newHeight != mBounds.height)
|
||||
{
|
||||
RECT drect;
|
||||
|
||||
//getting taller
|
||||
|
||||
drect.left = wp->x;
|
||||
drect.top = wp->y + mHeight;
|
||||
drect.top = wp->y + mBounds.height;
|
||||
drect.right = drect.left + newWidth;
|
||||
drect.bottom = drect.top + (newHeight - mHeight);
|
||||
drect.bottom = drect.top + (newHeight - mBounds.height);
|
||||
|
||||
// ::InvalidateRect(mWnd, NULL, FALSE);
|
||||
// ::InvalidateRect(mWnd, &drect, FALSE);
|
||||
::RedrawWindow(mWnd, &drect, NULL,
|
||||
RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ERASENOW | RDW_ALLCHILDREN);
|
||||
}
|
||||
mWidth = newWidth;
|
||||
mHeight = newHeight;
|
||||
mBounds.width = newWidth;
|
||||
mBounds.height = newHeight;
|
||||
///nsRect rect(wp->x, wp->y, wp->cx, wp->cy);
|
||||
|
||||
// recalculate the width and height
|
||||
|
|
|
@ -67,7 +67,8 @@ NS_METHOD nsBaseWidget::RemoveTooltips()
|
|||
// nsBaseWidget constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsBaseWidget::nsBaseWidget()
|
||||
nsBaseWidget::nsBaseWidget() :
|
||||
mBounds(0,0,0,0)
|
||||
{
|
||||
mChildren = nsnull;
|
||||
mEventCallback = nsnull;
|
||||
|
@ -77,7 +78,6 @@ nsBaseWidget::nsBaseWidget()
|
|||
mEventListener = nsnull;
|
||||
mClientData = nsnull;
|
||||
mContext = nsnull;
|
||||
mWidth = mHeight = 0;
|
||||
mCursor = eCursor_standard;
|
||||
mBorderStyle = eBorderStyle_none;
|
||||
}
|
||||
|
@ -563,6 +563,43 @@ NS_METHOD nsBaseWidget::GetClientBounds(nsRect &aRect)
|
|||
return GetBounds(aRect);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the implementation of nsWindow supports borders this method MUST be overridden
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsBaseWidget::GetBounds(nsRect &aRect)
|
||||
{
|
||||
aRect = mBounds;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the implementation of nsWindow supports borders this method MUST be overridden
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsBaseWidget::GetBoundsAppUnits(nsRect &aRect, float aAppUnits)
|
||||
{
|
||||
aRect = mBounds;
|
||||
// Convert to twips
|
||||
aRect.x = nscoord((PRFloat64)aRect.x * aAppUnits);
|
||||
aRect.y = nscoord((PRFloat64)aRect.y * aAppUnits);
|
||||
aRect.width = nscoord((PRFloat64)aRect.width * aAppUnits);
|
||||
aRect.height = nscoord((PRFloat64)aRect.height * aAppUnits);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsBaseWidget::SetBounds(const nsRect &aRect)
|
||||
{
|
||||
mBounds = aRect;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the border width and height
|
||||
|
@ -571,16 +608,103 @@ NS_METHOD nsBaseWidget::GetClientBounds(nsRect &aRect)
|
|||
NS_METHOD nsBaseWidget::GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
nsRect rectWin;
|
||||
nsRect rectClient;
|
||||
nsRect rect;
|
||||
GetBounds(rectWin);
|
||||
GetClientBounds(rectClient);
|
||||
GetClientBounds(rect);
|
||||
|
||||
aWidth = (rectWin.width - rectClient.width) / 2;
|
||||
aHeight = (rectWin.height - rectClient.height) / 2;
|
||||
aWidth = (rectWin.width - rect.width) / 2;
|
||||
aHeight = (rectWin.height - rect.height) / 2;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the border width and height
|
||||
*
|
||||
**/
|
||||
void nsBaseWidget::DrawScaledRect(nsIRenderingContext& aRenderingContext, const nsRect & aRect, float aScale, float aAppUnits)
|
||||
{
|
||||
nsRect rect = aRect;
|
||||
|
||||
float x = (float)rect.x;
|
||||
float y = (float)rect.y;
|
||||
float w = (float)rect.width;
|
||||
float h = (float)rect.height;
|
||||
float twoAppUnits = aAppUnits * 2.0f;
|
||||
|
||||
for (int i=0;i<int(aScale);i++) {
|
||||
rect.x = nscoord(x);
|
||||
rect.y = nscoord(y);
|
||||
rect.width = nscoord(w);
|
||||
rect.height = nscoord(h);
|
||||
aRenderingContext.DrawRect(rect);
|
||||
x += aAppUnits;
|
||||
y += aAppUnits;
|
||||
w -= twoAppUnits;
|
||||
h -= twoAppUnits;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the border width and height
|
||||
*
|
||||
**/
|
||||
void nsBaseWidget::DrawScaledLine(nsIRenderingContext& aRenderingContext,
|
||||
nscoord aSX,
|
||||
nscoord aSY,
|
||||
nscoord aEX,
|
||||
nscoord aEY,
|
||||
float aScale,
|
||||
float aAppUnits,
|
||||
PRBool aIsHorz)
|
||||
{
|
||||
float sx = (float)aSX;
|
||||
float sy = (float)aSY;
|
||||
float ex = (float)aEX;
|
||||
float ey = (float)aEY;
|
||||
float twoAppUnits = aAppUnits * 2.0f;
|
||||
|
||||
for (int i=0;i<int(aScale);i++) {
|
||||
aSX = nscoord(sx);
|
||||
aSY = nscoord(sy);
|
||||
aEX = nscoord(ex);
|
||||
aEY = nscoord(ey);
|
||||
aRenderingContext.DrawLine(aSX, aSY, aEX, aEY);
|
||||
if (aIsHorz) {
|
||||
sy += aAppUnits;
|
||||
ey += aAppUnits;
|
||||
} else {
|
||||
sx += aAppUnits;
|
||||
ex += aAppUnits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints default border (XXX - this should be done by CSS)
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsBaseWidget::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsRect rect;
|
||||
float appUnits;
|
||||
float scale;
|
||||
nsIDeviceContext * context;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
|
||||
context->GetCanonicalPixelScale(scale);
|
||||
context->GetDevUnitsToAppUnits(appUnits);
|
||||
|
||||
GetBoundsAppUnits(rect, appUnits);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
DrawScaledRect(aRenderingContext, rect, scale, appUnits);
|
||||
|
||||
NS_RELEASE(context);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#ifndef nsBaseWidget_h__
|
||||
#define nsBaseWidget_h__
|
||||
|
||||
#include "nsRect.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIMouseListener.h"
|
||||
|
@ -77,12 +78,19 @@ public:
|
|||
NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]);
|
||||
NS_IMETHOD AddMouseListener(nsIMouseListener * aListener);
|
||||
NS_IMETHOD AddEventListener(nsIEventListener * aListener);
|
||||
NS_IMETHOD GetBounds(nsRect &aRect) = 0;
|
||||
NS_IMETHOD SetBounds(const nsRect &aRect);
|
||||
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||
NS_IMETHOD GetBoundsAppUnits(nsRect &aRect, float aAppUnits);
|
||||
NS_IMETHOD GetClientBounds(nsRect &aRect);
|
||||
NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect);
|
||||
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
||||
protected:
|
||||
|
||||
virtual void DrawScaledRect(nsIRenderingContext& aRenderingContext, const nsRect & aRect, float aScale, float aAppUnits);
|
||||
virtual void DrawScaledLine(nsIRenderingContext& aRenderingContext,
|
||||
nscoord aSX, nscoord aSY, nscoord aEX, nscoord aEY,
|
||||
float aScale, float aAppUnits, PRBool aIsHorz);
|
||||
virtual void OnDestroy();
|
||||
virtual void BaseCreate(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
|
@ -109,8 +117,9 @@ protected:
|
|||
PRBool mIsAltDown;
|
||||
PRBool mIsDestroying;
|
||||
PRBool mOnDestroyCalled;
|
||||
PRInt32 mWidth;
|
||||
PRInt32 mHeight;
|
||||
//PRInt32 mWidth;
|
||||
//PRInt32 mHeight;
|
||||
nsRect mBounds;
|
||||
|
||||
// keep the list of children
|
||||
class Enumerator : public nsIEnumerator {
|
||||
|
|
Загрузка…
Ссылка в новой задаче