initial add copied from widget\src\windows and all NS_NewXXX method

for bug 17027 r=kmcclusk
This commit is contained in:
rods%netscape.com 2000-02-04 15:54:24 +00:00
Родитель 325c55e57c
Коммит 2568ce1230
11 изменённых файлов: 1759 добавлений и 0 удалений

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

@ -0,0 +1,288 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsButton.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <windows.h>
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
//-------------------------------------------------------------------------
nsresult
NS_NewButton(nsIButton** aControl)
{
NS_PRECONDITION(aControl, "null OUT ptr");
if (nsnull == aControl) {
return NS_ERROR_NULL_POINTER;
}
nsButton* it = new nsButton;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(it);
// set the state flags (if any are provided)
*aControl = (nsIButton*)it;
return NS_OK;
}
NS_IMPL_ADDREF(nsButton)
NS_IMPL_RELEASE(nsButton)
//-------------------------------------------------------------------------
//
// nsButton constructor
//
//-------------------------------------------------------------------------
nsButton::nsButton() : nsWindow() , nsIButton()
{
NS_INIT_REFCNT();
}
//-------------------------------------------------------------------------
//
// nsButton destructor
//
//-------------------------------------------------------------------------
nsButton::~nsButton()
{
}
/**
* Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
* @modify gpk 8/4/98
* @param aIID The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*
*/
nsresult nsButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kIButton, NS_IBUTTON_IID);
if (aIID.Equals(kIButton)) {
*aInstancePtr = (void*) ((nsIButton*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return nsWindow::QueryInterface(aIID,aInstancePtr);
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsButton::SetLabel(const nsString& aText)
{
mLabel = aText;
if (NULL == mWnd) {
return NS_ERROR_FAILURE;
}
NS_ALLOC_STR_BUF(label, aText, 256);
VERIFY(::SetWindowText(mWnd, label));
NS_FREE_STR_BUF(label);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsButton::GetLabel(nsString& aBuffer)
{
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;
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsButton::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsButton::OnPaint()
{
//printf("** nsButton::OnPaint **\n");
return PR_FALSE;
}
PRBool nsButton::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsButton::WindowClass()
{
return "BUTTON";
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
DWORD nsButton::WindowStyle()
{
return WS_CHILD | WS_CLIPSIBLINGS;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
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 == nsComponentManager::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);
NS_RELEASE(context);
return NS_OK;
}

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

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsButton_h__
#define nsButton_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsIButton.h"
/**
* Native Win32 button wrapper
*/
class nsButton : public nsWindow,
public nsIButton
{
public:
friend nsresult NS_NewButton(nsIButton** aControl);
nsButton();
virtual ~nsButton();
//nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIButton part
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();
};
#endif // nsButton_h__

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

@ -0,0 +1,275 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsCheckButton.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <windows.h>
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
//-------------------------------------------------------------------------
nsresult
NS_NewCheckButton(nsICheckButton** aControl)
{
NS_PRECONDITION(aControl, "null OUT ptr");
if (nsnull == aControl) {
return NS_ERROR_NULL_POINTER;
}
nsCheckButton* it = new nsCheckButton;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(it);
*aControl = (nsICheckButton*)it;
return NS_OK;
}
NS_IMPL_ADDREF(nsCheckButton)
NS_IMPL_RELEASE(nsCheckButton)
//-------------------------------------------------------------------------
//
// nsCheckButton constructor
//
//-------------------------------------------------------------------------
nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton(),
mState(PR_FALSE)
{
NS_INIT_REFCNT();
}
//-------------------------------------------------------------------------
//
// nsCheckButton destructor
//
//-------------------------------------------------------------------------
nsCheckButton::~nsCheckButton()
{
}
/**
* Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
* @modify gpk 8/4/98
* @param aIID The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*
*/
nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
if (aIID.Equals(kICheckButtonIID)) {
*aInstancePtr = (void*) ((nsICheckButton*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return nsWindow::QueryInterface(aIID,aInstancePtr);
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::SetState(const PRBool aState)
{
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;
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetState(PRBool& aState)
{
if (::SendMessage(mWnd, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
aState = PR_TRUE;
else
aState = PR_FALSE;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::SetLabel(const nsString& aText)
{
char label[256];
aText.ToCString(label, 256);
label[255] = '\0';
VERIFY(::SetWindowText(mWnd, label));
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
{
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;
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsCheckButton::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsCheckButton::OnPaint()
{
return PR_FALSE;
}
PRBool nsCheckButton::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsCheckButton::WindowClass()
{
return "BUTTON";
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
DWORD nsCheckButton::WindowStyle()
{
return BS_CHECKBOX | WS_CHILD | WS_CLIPSIBLINGS;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
DWORD nsCheckButton::WindowExStyle()
{
return 0;
}
/**
* 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;
}

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

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsCheckButton_h__
#define nsCheckButton_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsICheckButton.h"
/**
* Native Win32 Checkbox wrapper
*/
class nsCheckButton : public nsWindow,
public nsICheckButton
{
public:
friend nsresult NS_NewCheckButton(nsICheckButton** aControl);
nsCheckButton();
virtual ~nsCheckButton();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsICheckButton part
NS_IMETHOD SetLabel(const nsString &aText);
NS_IMETHOD GetLabel(nsString &aBuffer);
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();
virtual DWORD WindowExStyle();
};
#endif // nsCheckButton_h__

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

@ -0,0 +1,263 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsLabel.h"
#include "nsILabel.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include "nsIFontMetrics.h"
#include "nsIDeviceContext.h"
#include <windows.h>
//-------------------------------------------------------------------------
nsresult
NS_NewLabel(nsILabel** aControl)
{
NS_PRECONDITION(aControl, "null OUT ptr");
if (nsnull == aControl) {
return NS_ERROR_NULL_POINTER;
}
nsLabel* it = new nsLabel;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(it);
*aControl = (nsILabel*)it;
return NS_OK;
}
NS_IMPL_ADDREF(nsLabel)
NS_IMPL_RELEASE(nsLabel)
//-------------------------------------------------------------------------
//
// nsLabel constructor
//
//-------------------------------------------------------------------------
nsLabel::nsLabel() : nsWindow(), nsILabel()
{
NS_INIT_REFCNT();
mAlignment = eAlign_Left;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::PreCreateWidget(nsWidgetInitData *aInitData)
{
if (nsnull != aInitData) {
nsLabelInitData* data = (nsLabelInitData *) aInitData;
mAlignment = data->mAlignment;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// nsLabel destructor
//
//-------------------------------------------------------------------------
nsLabel::~nsLabel()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsLabel::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
if (result == NS_NOINTERFACE && aIID.Equals(kILabelIID)) {
*aInstancePtr = (void*) ((nsILabel*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment)
{
mAlignment = aAlignment;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::SetLabel(const nsString& aText)
{
NS_ALLOC_STR_BUF(label, aText, 256);
VERIFY(::SetWindowText(mWnd, label));
NS_FREE_STR_BUF(label);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::GetLabel(nsString& aBuffer)
{
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;
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsLabel::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsLabel::OnPaint()
{
//printf("** nsLabel::OnPaint **\n");
return PR_FALSE;
}
PRBool nsLabel::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsLabel::WindowClass()
{
return "STATIC";
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
DWORD nsLabel::WindowStyle()
{
DWORD style = WS_CHILD | WS_CLIPSIBLINGS;
switch (mAlignment) {
case eAlign_Right : style |= SS_RIGHT; break;
case eAlign_Left : style |= SS_LEFT; break;
case eAlign_Center: style |= SS_CENTER;break;
default :
style |= SS_LEFT;
}
return style;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
DWORD nsLabel::WindowExStyle()
{
return 0;
}
//-------------------------------------------------------------------------
//
// get position/dimensions
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::GetBounds(nsRect &aRect)
{
return nsWindow::GetBounds(aRect);
}
//-------------------------------------------------------------------------
NS_METHOD nsLabel::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
{
if (nsnull == mContext) {
return NS_ERROR_FAILURE;
}
//nsIFontMetrics * fm = GetFont();;
// mDeviceContext->GetMetricsFor(mFont, &fm);
nsIFontMetrics* metrics;
mContext->GetMetricsFor(*mFont, metrics);
nsString text;
GetLabel(text);
nsIRenderingContext *cx;
mContext->CreateRenderingContext(this, cx);
cx->SetFont(metrics);
nscoord string_height, string_width;
metrics->GetHeight(string_height);
cx->GetWidth(text, string_width);
NS_RELEASE(cx);
NS_RELEASE(metrics);
if (mPreferredWidth != 0) {
aWidth = mPreferredWidth;
} else {
aWidth = string_width+8;
}
if (mPreferredHeight != 0) {
aHeight = mPreferredHeight;
} else {
aHeight = string_height+8;
}
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsLabel::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight)
{
mPreferredWidth = aWidth;
mPreferredHeight = aHeight;
return NS_OK;
}

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

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsLabel_h__
#define nsLabel_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsILabel.h"
/**
* Native Win32 Label wrapper
*/
class nsLabel : public nsWindow,
public nsILabel
{
public:
friend nsresult NS_NewLabel(nsILabel** aControl);
nsLabel();
virtual ~nsLabel();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsILabel part
NS_IMETHOD SetLabel(const nsString &aText);
NS_IMETHOD GetLabel(nsString &aBuffer);
NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment);
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint();
virtual PRBool OnResize(nsRect &aWindowRect);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
protected:
nsLabelAlignment mAlignment;
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle();
};
#endif // nsLabel_h__

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

@ -0,0 +1,215 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsTextHelper.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <windows.h>
NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData)
{
if (nsnull != aInitData) {
nsTextWidgetInitData* data = (nsTextWidgetInitData *) aInitData;
mIsPassword = data->mIsPassword;
mIsReadOnly = data->mIsReadOnly;
}
return NS_OK;
}
NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars)
{
::SendMessage(mWnd, EM_SETLIMITTEXT, (WPARAM) (INT)aChars, 0);
return NS_OK;
}
NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize) {
int length = GetWindowTextLength(mWnd);
int bufLength = length + 1;
NS_ALLOC_CHAR_BUF(buf, 512, bufLength);
int charsCopied = GetWindowText(mWnd, buf, bufLength);
aTextBuffer.SetLength(0);
aTextBuffer.Append(buf);
NS_FREE_CHAR_BUF(buf);
aActualSize = charsCopied;
return NS_OK;
}
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);
aActualSize = aText.Length();
return NS_OK;
}
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()
{
SetWindowText(mWnd, "");
return NS_OK;
}
NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
{
mIsPassword = aIsPassword;
return NS_OK;
}
NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldFlag)
{
aOldFlag = mIsReadOnly;
mIsReadOnly = aReadOnlyFlag;
// Update the widget
::SendMessage(mWnd, EM_SETREADONLY, (WPARAM) (BOOL)aReadOnlyFlag, (LPARAM)0);
return NS_OK;
}
NS_METHOD nsTextHelper::SelectAll()
{
::SendMessage(mWnd, EM_SETSEL, (WPARAM) 0, (LPARAM)-1);
return NS_OK;
}
NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
::SendMessage(mWnd, EM_SETSEL, (WPARAM) (INT)aStartSel, (INT) (LPDWORD)aEndSel);
return NS_OK;
}
NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
{
::SendMessage(mWnd, EM_GETSEL, (WPARAM) (LPDWORD)aStartSel, (LPARAM) (LPDWORD)aEndSel);
return NS_OK;
}
NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition)
{
SetSelection(aPosition, aPosition);
return NS_OK;
}
NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos)
{
PRUint32 start;
PRUint32 end;
GetSelection(&start, &end);
if (start == end) {
aPos = start;
}
else {
aPos = PRUint32(-1);/* XXX is this right??? scary cast! */
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// nsTextHelper constructor
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget()
{
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// nsTextHelper destructor
//
//-------------------------------------------------------------------------
nsTextHelper::~nsTextHelper()
{
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsTextHelper::WindowClass()
{
return("EDIT");
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
DWORD nsTextHelper::WindowStyle()
{
DWORD style = ES_AUTOHSCROLL | WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | ES_NOHIDESEL;
if (mIsPassword)
style = style | ES_PASSWORD;
if (mIsReadOnly)
style = style | ES_READONLY;
return style;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
DWORD nsTextHelper::WindowExStyle()
{
return 0;
}
//-------------------------------------------------------------------------
//
// Clear window before paint
//
//-------------------------------------------------------------------------
PRBool nsTextHelper::AutoErase()
{
return(PR_TRUE);
}

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

@ -0,0 +1,71 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsTextHelper_h__
#define nsTextHelper_h__
#include "nsdefs.h"
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWindow.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
*/
class nsTextHelper : public nsWindow,
public nsITextAreaWidget,
public nsITextWidget
{
public:
nsTextHelper();
virtual ~nsTextHelper();
NS_IMETHOD SelectAll();
NS_IMETHOD SetMaxTextLength(PRUint32 aChars);
NS_IMETHOD GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize);
NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize);
NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize);
NS_IMETHOD RemoveText();
NS_IMETHOD SetPassword(PRBool aIsPassword);
NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag);
NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
NS_IMETHOD SetCaretPosition(PRUint32 aPosition);
NS_IMETHOD GetCaretPosition(PRUint32& aPosition);
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual PRBool AutoErase();
protected:
nsString mText;
PRBool mIsPassword;
PRBool mIsReadOnly;
virtual DWORD WindowExStyle();
};
#endif // nsTextHelper_h__

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

@ -0,0 +1,311 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsTextWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include <windows.h>
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
//-------------------------------------------------------------------------
nsresult
NS_NewTextWidget(nsITextWidget** aControl)
{
NS_PRECONDITION(aControl, "null OUT ptr");
if (nsnull == aControl) {
return NS_ERROR_NULL_POINTER;
}
nsTextWidget* it = new nsTextWidget;
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(it);
*aControl = (nsITextWidget*)it;
return NS_OK;
}
NS_IMPL_ADDREF(nsTextWidget)
NS_IMPL_RELEASE(nsTextWidget)
//-------------------------------------------------------------------------
//
// nsTextWidget constructor
//
//-------------------------------------------------------------------------
nsTextWidget::nsTextWidget() : nsTextHelper()
{
NS_INIT_REFCNT();
mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextWidget destructor
//
//-------------------------------------------------------------------------
nsTextWidget::~nsTextWidget()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsTextWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
if (result == NS_NOINTERFACE && aIID.Equals(NS_GET_IID(nsITextWidget))) {
*aInstancePtr = (void*) ((nsITextWidget*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// -----------------------------------------------------------------------
//
// Subclass (or remove the subclass from) this component's nsWindow
// this is need for filtering out the "ding" when the return key is pressed
//
// -----------------------------------------------------------------------
void nsTextWidget::SubclassWindow(BOOL bState)
{
NS_PRECONDITION(::IsWindow(mWnd), "Invalid window handle");
if (bState) {
// change the nsWindow proc
mPrevWndProc = (WNDPROC)::SetWindowLong(mWnd, GWL_WNDPROC,
(LONG)nsTextWidget::TextWindowProc);
NS_ASSERTION(mPrevWndProc, "Null standard window procedure");
// connect the this pointer to the nsWindow handle
::SetWindowLong(mWnd, GWL_USERDATA, (LONG)this);
}
else {
(void) ::SetWindowLong(mWnd, GWL_WNDPROC, (LONG)mPrevWndProc);
mPrevWndProc = NULL;
}
}
//-------------------------------------------------------------------------
//
// the nsTextWidget procedure for all nsTextWidget in this toolkit
// this is need for filtering out the "ding" when the return key is pressed
//
//-------------------------------------------------------------------------
LRESULT CALLBACK nsTextWidget::TextWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Filters the "ding" when hitting the return key
if (msg == WM_CHAR) {
long chCharCode = (TCHAR) wParam; // character code
if (chCharCode == 13 || chCharCode == 9) {
return 0L;
}
}
return nsWindow::WindowProc(hWnd, msg, wParam, lParam);
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsTextWidget::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsTextWidget::OnPaint()
{
return PR_FALSE;
}
PRBool nsTextWidget::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsTextWidget::WindowClass()
{
return(nsTextHelper::WindowClass());
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
DWORD nsTextWidget::WindowStyle()
{
return(nsTextHelper::WindowStyle());
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
DWORD nsTextWidget::WindowExStyle()
{
return WS_EX_CLIENTEDGE;
}
//-------------------------------------------------------------------------
//
// get position/dimensions
//
//-------------------------------------------------------------------------
NS_METHOD nsTextWidget::GetBounds(nsRect &aRect)
{
nsWindow::GetNonClientBounds(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 == nsComponentManager::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);
} else {
nsString astricks;
PRInt32 i;
for (i=0;i<mText.Length();i++) {
astricks.Append("*");
}
aRenderingContext.DrawString(astricks, x, y);
}
NS_RELEASE(context);
return NS_OK;
}

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

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsTextWidget_h__
#define nsTextWidget_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsTextHelper.h"
#include "nsITextWidget.h"
/**
* Native WIN32 single line edit control wrapper.
*/
class nsTextWidget : public nsTextHelper
{
public:
friend nsresult NS_NewTextWidget(nsITextWidget** aControl);
nsTextWidget();
virtual ~nsTextWidget();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
virtual PRBool OnPaint();
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnResize(nsRect &aWindowRect);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
virtual void SubclassWindow(BOOL bState);
protected:
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle();
static LRESULT CALLBACK TextWindowProc(HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam);
};
#endif // nsTextWidget_h__

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

@ -0,0 +1,42 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef NSDEFS_H
#define NSDEFS_H
#include <windows.h>
#ifdef _DEBUG
#define BREAK_TO_DEBUGGER DebugBreak()
#else
#define BREAK_TO_DEBUGGER
#endif
#ifdef _DEBUG
#define VERIFY(exp) ((exp) ? 0: (GetLastError(), BREAK_TO_DEBUGGER))
#else // !_DEBUG
#define VERIFY(exp) (exp)
#endif // !_DEBUG
#endif // NSDEFS_H