From 76ed158d4c3a0f032a1fe4c590fbb5e8a6bcb26b Mon Sep 17 00:00:00 2001 From: "blakeross%telocity.com" Date: Mon, 8 Jan 2001 23:26:42 +0000 Subject: [PATCH] Fix 63938: removing unused widget files. more to come. sr=cls git-svn-id: svn://10.0.0.236/trunk@84614 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/windows/makefile.win | 10 - mozilla/widget/src/windows/nsButton.cpp | 270 ----------------- mozilla/widget/src/windows/nsCheckButton.cpp | 257 ---------------- mozilla/widget/src/windows/nsLabel.cpp | 246 --------------- mozilla/widget/src/windows/nsTextHelper.cpp | 215 ------------- mozilla/widget/src/windows/nsTextWidget.cpp | 298 ------------------- 6 files changed, 1296 deletions(-) delete mode 100644 mozilla/widget/src/windows/nsButton.cpp delete mode 100644 mozilla/widget/src/windows/nsCheckButton.cpp delete mode 100644 mozilla/widget/src/windows/nsLabel.cpp delete mode 100644 mozilla/widget/src/windows/nsTextHelper.cpp delete mode 100644 mozilla/widget/src/windows/nsTextWidget.cpp diff --git a/mozilla/widget/src/windows/makefile.win b/mozilla/widget/src/windows/makefile.win index ec2cce21f74..48117aff3bb 100644 --- a/mozilla/widget/src/windows/makefile.win +++ b/mozilla/widget/src/windows/makefile.win @@ -43,11 +43,6 @@ CPPSRCS = \ nsLookAndFeel.cpp \ nsToolkit.cpp \ nsSound.cpp \ -# nsButton.cpp \ -# nsTextWidget.cpp \ -# nsTextHelper.cpp \ -# nsLabel.cpp \ -# nsCheckButton.cpp \ $(NULL) MODULE=raptor @@ -70,11 +65,6 @@ OBJS = \ .\$(OBJDIR)\nsLookAndFeel.obj \ .\$(OBJDIR)\nsToolkit.obj \ .\$(OBJDIR)\nsSound.obj \ -# .\$(OBJDIR)\nsButton.obj \ -# .\$(OBJDIR)\nsTextWidget.obj \ -# .\$(OBJDIR)\nsTextHelper.obj \ -# .\$(OBJDIR)\nsLabel.obj \ -# .\$(OBJDIR)\nsCheckButton.obj \ $(NULL) LINCS= \ diff --git a/mozilla/widget/src/windows/nsButton.cpp b/mozilla/widget/src/windows/nsButton.cpp deleted file mode 100644 index 804106821eb..00000000000 --- a/mozilla/widget/src/windows/nsButton.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* -*- 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 - -#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); - - -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;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); - - - NS_RELEASE(context); - return NS_OK; -} - - diff --git a/mozilla/widget/src/windows/nsCheckButton.cpp b/mozilla/widget/src/windows/nsCheckButton.cpp deleted file mode 100644 index 19f7d6ea184..00000000000 --- a/mozilla/widget/src/windows/nsCheckButton.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* -*- 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 - -#include "nsILookAndFeel.h" -#include "nsWidgetsCID.h" -#include "nsIComponentManager.h" - -#include "nsIDeviceContext.h" - -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; -} - diff --git a/mozilla/widget/src/windows/nsLabel.cpp b/mozilla/widget/src/windows/nsLabel.cpp deleted file mode 100644 index 6130b157610..00000000000 --- a/mozilla/widget/src/windows/nsLabel.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- 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 - -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; -} - diff --git a/mozilla/widget/src/windows/nsTextHelper.cpp b/mozilla/widget/src/windows/nsTextHelper.cpp deleted file mode 100644 index cd47780d468..00000000000 --- a/mozilla/widget/src/windows/nsTextHelper.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* -*- 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 - - -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); -} - - diff --git a/mozilla/widget/src/windows/nsTextWidget.cpp b/mozilla/widget/src/windows/nsTextWidget.cpp deleted file mode 100644 index 740e4b4cd85..00000000000 --- a/mozilla/widget/src/windows/nsTextWidget.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/* -*- 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 - */ - -#include "nsTextWidget.h" -#include "nsToolkit.h" -#include "nsColor.h" -#include "nsGUIEvent.h" -#include "nsString.h" -#include - -#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); - - -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) -{ - if (NULL != mWnd) { - 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 - SetNSWindowPtr(mWnd, this); - } - else { - (void) ::SetWindowLong(mWnd, GWL_WNDPROC, (LONG)mPrevWndProc); - SetNSWindowPtr(mWnd, NULL); - 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