r=mkaply, sr=blizzard
not part of build - OS/2 only - add OS/2 specific underpinnings for webshell/tests/viewer
This commit is contained in:
mkaply%us.ibm.com 2002-08-22 22:03:52 +00:00
Родитель b5d3198589
Коммит ccdc0434ea
13 изменённых файлов: 2005 добавлений и 0 удалений

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

@ -0,0 +1 @@
Makefile

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

@ -0,0 +1,57 @@
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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) 2001 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = webshell_tests
LIBRARY_NAME = viewer_os2_s
REQUIRES = xpcom \
string \
dom \
accessibility \
widget \
gfx \
$(NULL)
CPPSRCS = \
nsButton.cpp \
nsCheckButton.cpp \
nsTextWidget.cpp \
nsTextHelper.cpp \
nsLabel.cpp \
$(NULL)
#DEFINES += -DWIN32_LEAN_AND_MEAN
LOCAL_INCLUDES = \
-I$(topsrcdir)/widget/src/os2 \
-I$(topsrcdir)/widget/src/xpwidgets \
$(NULL)
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,302 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsButton.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <os2.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;
}
::WinSetWindowText(mWnd, NS_LossyConvertUCS2toASCII(aText).get());
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
//
//-------------------------------------------------------------------------
PCSZ nsButton::WindowClass()
{
return WC_BUTTON_STRING;
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
ULONG nsButton::WindowStyle()
{
return WS_CLIPSIBLINGS | BS_PUSHBUTTON;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
ULONG 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
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
aRenderingContext.SetFont(metrics);
nscoord textWidth;
nscoord textHeight;
aRenderingContext.GetWidth(mLabel, textWidth);
metrics->GetMaxAscent(textHeight);
nscoord x = ((rect.width - textWidth) / 2) + rect.x;
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
aRenderingContext.DrawString(mLabel, x, y + textHeight);
NS_RELEASE(context);
return NS_OK;
}

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

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsButton_h__
#define nsButton_h__
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsIButton.h"
#define WC_BUTTON_STRING "#3" //string equivalent to WC_BUTTON
/**
* 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 PCSZ WindowClass();
virtual ULONG WindowStyle();
virtual ULONG WindowExStyle();
};
#endif // nsButton_h__

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

@ -0,0 +1,293 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsCheckButton.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <os2.h>
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#define IDM_BUTTON 701
//-------------------------------------------------------------------------
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) {
USHORT chkState;
if (aState)
chkState = 1;
else
chkState = 0;
WinCheckButton(mWnd, IDM_BUTTON, chkState);
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetState(PRBool& aState)
{
USHORT chkState = WinQueryButtonCheckstate(mWnd, IDM_BUTTON);
if (chkState == 1)
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';
::WinSetWindowText(mWnd, label);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
{
int actualSize = ::WinQueryWindowTextLength(mWnd)+1;
NS_ALLOC_CHAR_BUF(label, 256, actualSize);
::WinQueryWindowText(mWnd, actualSize, label);
aBuffer.SetLength(0);
aBuffer.AppendWithConversion(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
//
//-------------------------------------------------------------------------
PCSZ nsCheckButton::WindowClass()
{
return WC_BUTTON_STRING;
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
ULONG nsCheckButton::WindowStyle()
{
return BS_CHECKBOX | WS_CLIPSIBLINGS;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
ULONG 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,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsCheckButton_h__
#define nsCheckButton_h__
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsICheckButton.h"
#define WC_BUTTON_STRING "#6" //string equivalent to WC_BUTTON
/**
* 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 PCSZ WindowClass();
virtual ULONG WindowStyle();
virtual ULONG WindowExStyle();
};
#endif // nsCheckButton_h__

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

@ -0,0 +1,276 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#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 <os2.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)
{
WinSetWindowText(mWnd, NS_LossyConvertUCS2toASCII(aText).get());
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this button label
//
//-------------------------------------------------------------------------
NS_METHOD nsLabel::GetLabel(nsString& aBuffer)
{
int actualSize = ::WinQueryWindowTextLength(mWnd)+1;
NS_ALLOC_CHAR_BUF(label, 256, actualSize);
::WinQueryWindowText(mWnd, actualSize, label);
aBuffer.SetLength(0);
aBuffer.AppendWithConversion(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
//
//-------------------------------------------------------------------------
PCSZ nsLabel::WindowClass()
{
return WC_STATIC_STRING;
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
ULONG nsLabel::WindowStyle()
{
ULONG style = WS_CLIPSIBLINGS;
switch (mAlignment) {
case eAlign_Right : style |= DT_RIGHT; break;
case eAlign_Left : style |= DT_LEFT; break;
case eAlign_Center: style |= DT_CENTER;break;
default :
style |= DT_LEFT;
}
return style;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
ULONG 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,91 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLabel_h__
#define nsLabel_h__
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsILabel.h"
#define WC_STATIC_STRING "#5" //string equivalent to WC_STATIC
/**
* 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 PCSZ WindowClass();
virtual ULONG WindowStyle();
virtual ULONG WindowExStyle();
};
#endif // nsLabel_h__

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

@ -0,0 +1,228 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsTextHelper.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <os2.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)
{
::WinSendMsg(mWnd, EM_SETTEXTLIMIT, (MPARAM)(INT)aChars, 0);
return NS_OK;
}
NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize) {
int length = WinQueryWindowTextLength(mWnd);
int bufLength = length + 1;
NS_ALLOC_CHAR_BUF(buf, 512, bufLength);
int charsCopied = WinQueryWindowText(mWnd, bufLength, buf);
aTextBuffer.SetLength(0);
aTextBuffer.AppendWithConversion(buf);
NS_FREE_CHAR_BUF(buf);
aActualSize = charsCopied;
return NS_OK;
}
NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize)
{
mText = aText;
WinSetWindowText(mWnd, NS_LossyConvertUCS2toASCII(aText).get());
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.get(), aStartPos, aText.Length());
SetText(currentText,actualSize);
aActualSize = aText.Length();
mText = currentText;
return NS_OK;
}
NS_METHOD nsTextHelper::RemoveText()
{
WinSetWindowText(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
::WinSendMsg(mWnd, EM_SETREADONLY, (MPARAM) (BOOL)aReadOnlyFlag, (MPARAM)0);
return NS_OK;
}
NS_METHOD nsTextHelper::SelectAll()
{
::WinSendMsg(mWnd, EM_SETSEL, (MPARAM) 0, (MPARAM)-1);
return NS_OK;
}
NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
::WinSendMsg(mWnd, EM_SETSEL, (MPARAM) (INT)aStartSel, (MPARAM)(INT) (ULONG*)aEndSel);
return NS_OK;
}
NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
{
::WinSendMsg(mWnd, EM_QUERYSEL, (MPARAM) (ULONG*)aStartSel, (MPARAM) (ULONG*)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(), nsITextWidget()
{
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// nsTextHelper destructor
//
//-------------------------------------------------------------------------
nsTextHelper::~nsTextHelper()
{
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
PCSZ nsTextHelper::WindowClass()
{
return WC_ENTRYFIELD_STRING;
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
ULONG nsTextHelper::WindowStyle()
{
ULONG style = WS_CLIPSIBLINGS | ES_MARGIN | ES_AUTOSCROLL;
if (mIsPassword)
style = style | ES_UNREADABLE;
if (mIsReadOnly)
style = style | ES_READONLY;
return style;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
ULONG nsTextHelper::WindowExStyle()
{
return 0;
}
//-------------------------------------------------------------------------
//
// Clear window before paint
//
//-------------------------------------------------------------------------
PRBool nsTextHelper::AutoErase()
{
return(PR_TRUE);
}

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

@ -0,0 +1,85 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsTextHelper_h__
#define nsTextHelper_h__
#include "nsITextWidget.h"
#include "nsWindow.h"
#define WC_ENTRYFIELD_STRING "#6" //string equivalent to WC_ENTRYFIELD
/**
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWindow,
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 PCSZ WindowClass();
virtual ULONG WindowStyle();
virtual PRBool AutoErase();
protected:
nsString mText;
PRBool mIsPassword;
PRBool mIsReadOnly;
virtual ULONG WindowExStyle();
};
#endif // nsTextHelper_h__

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

@ -0,0 +1,328 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsTextWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include <os2.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)
{
if (NULL != mWnd) {
NS_PRECONDITION(::WinIsWindow(0, mWnd), "Invalid window handle");
if (bState) {
// change the nsWindow proc
mPrevWndProc = WinSubclassWindow(mWnd, TextWindowProc);
NS_ASSERTION(mPrevWndProc, "Null standard window procedure");
// connect the this pointer to the nsWindow handle
SetNSWindowPtr(mWnd, this);
}
else {
WinSubclassWindow(mWnd, 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
//
//-------------------------------------------------------------------------
MRESULT EXPENTRY nsTextWidget::TextWindowProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
// Filters the "ding" when hitting the return key
if (msg == WM_CHAR) {
long chCharCode = LONGFROMMP(mp1); // character code
if (chCharCode == 13 || chCharCode == 9) {
return 0L;
}
}
return fnwpNSWindow(hWnd, msg, mp1, mp2);
}
//-------------------------------------------------------------------------
//
// 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
//
//-------------------------------------------------------------------------
PCSZ nsTextWidget::WindowClass()
{
return(nsTextHelper::WindowClass());
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
ULONG nsTextWidget::WindowStyle()
{
return(nsTextHelper::WindowStyle());
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
ULONG nsTextWidget::WindowExStyle()
{
return;
}
//-------------------------------------------------------------------------
//
// 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
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
aRenderingContext.SetFont(metrics);
nscoord textWidth;
nscoord textHeight;
aRenderingContext.GetWidth(mText, textWidth);
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 + textHeight);
} else {
nsString astricks;
PRUint32 i;
for (i=0;i<mText.Length();i++) {
astricks.Append(NS_LITERAL_STRING("*"));
}
aRenderingContext.DrawString(astricks, x, y + textHeight);
}
NS_RELEASE(context);
return NS_OK;
}

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

@ -0,0 +1,90 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsTextWidget_h__
#define nsTextWidget_h__
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsTextHelper.h"
#include "nsITextWidget.h"
#define WC_ENTRYFIELD_STRING "#6" //string equivalent to WC_ENTRYFIELD
/**
* 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 PCSZ WindowClass();
virtual ULONG WindowStyle();
virtual ULONG WindowExStyle();
static MRESULT EXPENTRY TextWindowProc(HWND hWnd,
ULONG msg,
MPARAM mp1,
MPARAM mp2);
};
#endif // nsTextWidget_h__

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

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef NSDEFS_H
#define NSDEFS_H
#ifdef _DEBUG
#define INCL_WINERRORS
#endif
#include <os2.h>
#ifdef XP_OS2_VACPP
#include <builtin.h>
#endif
#ifdef _DEBUG
#define BREAK_TO_DEBUGGER _interrupt(3)
#else
#define BREAK_TO_DEBUGGER
#endif
#ifdef _DEBUG
#define VERIFY(exp) ((exp) ? (void)0: (WinGetLastError((HAB)0), BREAK_TO_DEBUGGER))
#else // !_DEBUG
#define VERIFY(exp) (exp)
#endif // !_DEBUG
#define WC_BUTTON_STRING "#3" //string equivalent to WC_BUTTON
#define WC_STATIC_STRING "#5" //string equivalent to WC_STATIC
#define WC_ENTRYFIELD_STRING "#6" //string equivalent to WC_ENTRYFIELD
extern "C" {
PVOID APIENTRY WinQueryProperty(HWND hwnd, PCSZ pszNameOrAtom);
PVOID APIENTRY WinRemoveProperty(HWND hwnd, PCSZ pszNameOrAtom);
BOOL APIENTRY WinSetProperty(HWND hwnd, PCSZ pszNameOrAtom,
PVOID pvData, ULONG ulFlags);
}
#endif // NSDEFS_H