diff --git a/mozilla/widget/public/nsIWidget.h b/mozilla/widget/public/nsIWidget.h index f8ad0474a19..3c4abc03957 100644 --- a/mozilla/widget/public/nsIWidget.h +++ b/mozilla/widget/public/nsIWidget.h @@ -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; }; diff --git a/mozilla/widget/src/motif/nsWindow.cpp b/mozilla/widget/src/motif/nsWindow.cpp index 29748cf3d4e..a3fd643971a 100644 --- a/mozilla/widget/src/motif/nsWindow.cpp +++ b/mozilla/widget/src/motif/nsWindow.cpp @@ -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; +} diff --git a/mozilla/widget/src/motif/nsWindow.h b/mozilla/widget/src/motif/nsWindow.h index 0eb65572885..3700af0e0db 100644 --- a/mozilla/widget/src/motif/nsWindow.h +++ b/mozilla/widget/src/motif/nsWindow.h @@ -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); }; diff --git a/mozilla/widget/src/windows/nsButton.cpp b/mozilla/widget/src/windows/nsButton.cpp index 04f0825d0c7..3b458900851 100644 --- a/mozilla/widget/src/windows/nsButton.cpp +++ b/mozilla/widget/src/windows/nsButton.cpp @@ -24,6 +24,16 @@ #include "nsStringUtil.h" #include +#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;iGetMetricsFor(*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; +} + diff --git a/mozilla/widget/src/windows/nsButton.h b/mozilla/widget/src/windows/nsButton.h index a38ba288a53..59f711c9478 100644 --- a/mozilla/widget/src/windows/nsButton.h +++ b/mozilla/widget/src/windows/nsButton.h @@ -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(); diff --git a/mozilla/widget/src/windows/nsCheckButton.cpp b/mozilla/widget/src/windows/nsCheckButton.cpp index ff08ea31de1..a36c4bc28f8 100644 --- a/mozilla/widget/src/windows/nsCheckButton.cpp +++ b/mozilla/widget/src/windows/nsCheckButton.cpp @@ -24,6 +24,11 @@ #include "nsStringUtil.h" #include +#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; +} diff --git a/mozilla/widget/src/windows/nsCheckButton.h b/mozilla/widget/src/windows/nsCheckButton.h index 00d6e763437..813c8549f01 100644 --- a/mozilla/widget/src/windows/nsCheckButton.h +++ b/mozilla/widget/src/windows/nsCheckButton.h @@ -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(); diff --git a/mozilla/widget/src/windows/nsComboBox.cpp b/mozilla/widget/src/windows/nsComboBox.cpp index 6da711105c0..70c79a3bd6c 100644 --- a/mozilla/widget/src/windows/nsComboBox.cpp +++ b/mozilla/widget/src/windows/nsComboBox.cpp @@ -24,6 +24,15 @@ #include "nsStringUtil.h" #include +#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; +} + + diff --git a/mozilla/widget/src/windows/nsComboBox.h b/mozilla/widget/src/windows/nsComboBox.h index 044bcf3cd18..809d7c2d39b 100644 --- a/mozilla/widget/src/windows/nsComboBox.h +++ b/mozilla/widget/src/windows/nsComboBox.h @@ -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: diff --git a/mozilla/widget/src/windows/nsRadioButton.cpp b/mozilla/widget/src/windows/nsRadioButton.cpp index 889012e78d0..87c0a9e442c 100644 --- a/mozilla/widget/src/windows/nsRadioButton.cpp +++ b/mozilla/widget/src/windows/nsRadioButton.cpp @@ -21,8 +21,14 @@ #include "nsColor.h" #include "nsGUIEvent.h" #include "nsStringUtil.h" - #include + +#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 +#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; +} diff --git a/mozilla/widget/src/windows/nsTextAreaWidget.h b/mozilla/widget/src/windows/nsTextAreaWidget.h index d67b775954d..5a1ee99927b 100644 --- a/mozilla/widget/src/windows/nsTextAreaWidget.h +++ b/mozilla/widget/src/windows/nsTextAreaWidget.h @@ -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); diff --git a/mozilla/widget/src/windows/nsTextHelper.cpp b/mozilla/widget/src/windows/nsTextHelper.cpp index f77a76caee1..69d33977a87 100644 --- a/mozilla/widget/src/windows/nsTextHelper.cpp +++ b/mozilla/widget/src/windows/nsTextHelper.cpp @@ -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() diff --git a/mozilla/widget/src/windows/nsTextHelper.h b/mozilla/widget/src/windows/nsTextHelper.h index a0ec60f8eac..d7adcc49bff 100644 --- a/mozilla/widget/src/windows/nsTextHelper.h +++ b/mozilla/widget/src/windows/nsTextHelper.h @@ -56,9 +56,9 @@ public: virtual PRBool AutoErase(); protected: - - PRBool mIsPassword; - PRBool mIsReadOnly; + nsString mText; + PRBool mIsPassword; + PRBool mIsReadOnly; virtual DWORD WindowExStyle(); diff --git a/mozilla/widget/src/windows/nsTextWidget.cpp b/mozilla/widget/src/windows/nsTextWidget.cpp index 0cdb185090f..64f314e5b64 100644 --- a/mozilla/widget/src/windows/nsTextWidget.cpp +++ b/mozilla/widget/src/windows/nsTextWidget.cpp @@ -23,6 +23,17 @@ #include "nsString.h" #include +#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;iGetMetricsFor(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 diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp index 3236d803318..ddb3f7a95d9 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.cpp @@ -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;iGetCanonicalPixelScale(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; +} + diff --git a/mozilla/widget/src/xpwidgets/nsBaseWidget.h b/mozilla/widget/src/xpwidgets/nsBaseWidget.h index 10c82eba225..d5cfb2cd222 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseWidget.h +++ b/mozilla/widget/src/xpwidgets/nsBaseWidget.h @@ -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 {