Bug 95556 - removing obsolete native textarea widget. r=jag, sr=blizzard, a=blizzard.

This commit is contained in:
bryner%netscape.com 2001-08-31 23:10:11 +00:00
Родитель f1dd09ede3
Коммит dad448eb7f
43 изменённых файлов: 14 добавлений и 2670 удалений

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

@ -27,7 +27,7 @@
#include "nsWindow.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWindow,

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

@ -8,7 +8,6 @@ nsIKBStateControl.h
nsIButton.h
nsICheckButton.h
nsITextWidget.h
nsITextAreaWidget.h
nsIScrollbar.h
nsGUIEvent.h
nsEvent.h

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

@ -44,7 +44,6 @@ EXPORTS = \
nsIButton.h \
nsICheckButton.h \
nsITextWidget.h \
nsITextAreaWidget.h \
nsIScrollbar.h \
nsGUIEvent.h \
nsEvent.h \

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

@ -1,158 +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):
*/
#ifndef nsITextAreaWidget_h__
#define nsITextAreaWidget_h__
#include "nsIWidget.h"
#include "nsITextWidget.h"
#include "nsString.h"
// {F8030012-C342-11d1-97F0-00609703C14E}
#define NS_ITEXTAREAWIDGET_IID \
{ 0xf8030012, 0xc342, 0x11d1, { 0x97, 0xf0, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
/**
* Multi-line text editor.
* See nsITextWidget for capabilities.
* Displays a scrollbar when the text content exceeds the number of lines
* displayed.
* Unlike a nsIWidget, The textarea must automatically clear
* itself to the background color when paint messages are generated.
*/
class nsITextAreaWidget : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITEXTAREAWIDGET_IID)
/**
* Get the text of this component.
*
* @param aTextBuffer on return contains the text of this component
* @param aBufferSize the size of the buffer passed in
* @param aActualSize the number of char copied
* @result NS_Ok if no errors
*
*/
NS_IMETHOD GetText(nsString &aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize) = 0;
/**
* Set the text of this component.
*
* @param aText -- an object containing a copy of the text
* @return the number of chars in the text string
* @result NS_Ok if no errors
*
*/
NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize) = 0;
/**
* Insert text into this component.
* When aStartPos and aEndPos are a valid range this function performs a replace.
* When aStartPos and aEndPos are equal this function performs an insert.
* When aStartPos and aEndPos are both -1 (0xFFFFFFFF) this function performs an append.
* If aStartPos and aEndPos are out of range they are rounded to the closest end.
*
* @param aText the text to set
* @param aStartPos starting position for inserting text
* @param aEndPos ending position for inserting text
* @result NS_Ok if no errors
*/
NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize) = 0;
/**
* Remove any content from this text widget
* @result NS_Ok if no errors
*/
NS_IMETHOD RemoveText(void) = 0;
/**
* Sets the maximum number of characters the widget can hold
*
* @param aChars maximum number of characters for this widget. if 0 then there isn't any limit
* @result NS_Ok if no errors
*/
NS_IMETHOD SetMaxTextLength(PRUint32 aChars) = 0;
/**
* Set the text widget to be read-only
*
* @param aReadOnlyFlag PR_TRUE the widget is read-only,
* PR_FALSE indicates the widget is writable.
* @param PR_TRUE if it was read only. PR_FALSE if it was writable
* @result NS_Ok if no errors
*/
NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag) = 0;
/**
* Select all of the contents
* @result NS_Ok if no errors
*/
NS_IMETHOD SelectAll() = 0;
/**
* Set the selection in this text component
* @param aStartSel starting selection position in characters
* @param aEndSel ending selection position in characters
* @result NS_Ok if no errors
*/
NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel) = 0;
/**
* Get the selection in this text component
* @param aStartSel starting selection position in characters
* @param aEndSel ending selection position in characters
* @result NS_Ok if no errors
*/
NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel) = 0;
/**
* Set the caret position
* @param aPosition caret position in characters
* @result NS_Ok if no errors
*/
NS_IMETHOD SetCaretPosition(PRUint32 aPosition) = 0;
/**
* Get the caret position
* @return caret position in characters
* @result NS_Ok if no errors
*/
NS_IMETHOD GetCaretPosition(PRUint32& aPosition) = 0;
};
#endif // nsITextAreaWidget_h__

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

@ -68,11 +68,6 @@
{ 0x2d96b3da, 0xc051, 0x11d1, \
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
/* 2d96b3db-c051-11d1-a827-0040959a28c9 */
#define NS_TEXTAREA_CID \
{ 0x2d96b3db, 0xc051, 0x11d1, \
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
/* 2d96b3dc-c051-11d1-a827-0040959a28c9 */
#define NS_TEXTFIELD_CID \
{ 0x2d96b3dc, 0xc051, 0x11d1, \

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

@ -48,7 +48,6 @@ CPPSRCS = \
nsPopUpMenu.cpp \
nsScrollbar.cpp \
nsSound.cpp \
nsTextAreaWidget.cpp \
nsTextHelper.cpp \
nsTextWidget.cpp \
nsToolkit.cpp \

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

@ -1,248 +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 "nsTextAreaWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.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);
/*NS_IMPL_ADDREF(nsTextAreaWidget)
//NS_IMPL_RELEASE(nsTextAreaWidget)
nsrefcnt nsTextAreaWidget::Release(void)
{
// NS_PRECONDITION(0 != cnt, "dup release");
if (--mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}*/
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::nsTextAreaWidget()
{
NS_INIT_REFCNT();
nsTextHelper::mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextAreaWidget destructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
if (aIID.Equals(kITextAreaWidgetIID)) {
nsITextAreaWidget* textArea = this;
*aInstancePtr = (void*) (textArea);
NS_ADDREF_THIS();
return NS_OK;
}
else if (aIID.Equals(kIWidgetIID))
{
nsIWidget* widget = this;
*aInstancePtr = (void*) (widget);
NS_ADDREF_THIS();
return NS_OK;
}
return nsWindow::QueryInterface(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsTextAreaWidget::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsTextAreaWidget::OnPaint(nsRect &r)
{
return PR_FALSE;
}
PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// get position/dimensions
//
//-------------------------------------------------------------------------
NS_METHOD nsTextAreaWidget::GetBounds(nsRect &aRect)
{
#if 0
nsWindow::GetNonClientBounds(aRect);
#endif
printf("nsTextAreaWidget::GetBounds not wrong\n"); // the following is just a placeholder
nsWindow::GetClientBounds(aRect);
return NS_OK;
}
/**
* Renders the TextWidget for Printing
*
**/
NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
nsRect rect;
float appUnits;
float scale;
nsIDeviceContext * context;
aRenderingContext.GetDeviceContext(context);
context->GetCanonicalPixelScale(scale);
context->GetDevUnitsToAppUnits(appUnits);
GetBoundsAppUnits(rect, appUnits);
aRenderingContext.SetColor(NS_RGB(0,0,0));
nscolor bgColor = NS_RGB(255,255,255);
nscolor fgColor = NS_RGB(0,0,0);
nscolor hltColor = NS_RGB(240,240,240);
nscolor sdwColor = NS_RGB(128,128,128);
nscolor txtBGColor = NS_RGB(255,255,255);
nscolor txtFGColor = NS_RGB(0,0,0);
nsILookAndFeel * lookAndFeel;
if (NS_OK == 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);
aRenderingContext.DrawString(mText, x, y);
NS_RELEASE(context);
return NS_OK;
}
BView *nsTextAreaWidget::CreateBeOSView()
{
mTextView = new nsTextAreaBeOS(this, BRect(0, 0, 0, 0), B_EMPTY_STRING, BRect(0, 0, 0, 0), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
return new TextFrameBeOS(mTextView, BRect(0, 0, 0, 0), B_EMPTY_STRING, 0, 0);
}
//----------------------------------------------------
// BeOS Sub-Class TextView
//----------------------------------------------------
nsTextAreaBeOS::nsTextAreaBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
const char *aName, BRect aTextRect, uint32 aResizingMode,
uint32 aFlags )
: BTextView( aFrame, aName, aTextRect, aResizingMode, aFlags ),
nsIWidgetStore( aWidgetWindow )
{
}

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

@ -1,71 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
#include <TextView.h>
/**
* Native WIN32 multi-line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIWidget Overrides
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsRect &r);
virtual PRBool OnResize(nsRect &aWindowRect);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
protected:
BView *CreateBeOSView();
};
//
// A BTextView subclass
//
class nsTextAreaBeOS : public BTextView, public nsIWidgetStore {
public:
nsTextAreaBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
BRect aTextRect, uint32 aResizingMode, uint32 aFlags );
};
#endif // nsTextAreaWidget_h__

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

@ -185,7 +185,7 @@ NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos)
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget()
nsTextHelper::nsTextHelper() : nsWindow(), nsITextWidget()
{
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;

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

@ -24,17 +24,15 @@
#include "nsdefs.h"
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWindow.h"
class BTextView;
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWindow,
public nsITextAreaWidget,
public nsITextWidget
{

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

@ -34,7 +34,6 @@
#include "nsScrollbar.h"
#include "nsCheckButton.h"
#include "nsTextWidget.h"
#include "nsTextAreaWidget.h"
#include "nsFilePicker.h"
#include "nsFileWidget.h"
#include "nsLookAndFeel.h"
@ -61,7 +60,6 @@ static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kCFilePicker, NS_FILEPICKER_CID);
static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kCTextField, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kCAppShell, NS_APPSHELL_CID);
static NS_DEFINE_IID(kCToolkit, NS_TOOLKIT_CID);
@ -184,9 +182,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCVertScrollbar)) {
inst = (nsISupports*)(nsWindow *)new nsScrollbar(PR_TRUE);
}
else if (mClassID.Equals(kCTextArea)) {
inst = (nsISupports*)(nsWindow *)new nsTextAreaWidget();
}
else if (mClassID.Equals(kCTextField)) {
inst = (nsISupports*)(nsWindow *)new nsTextWidget();
}

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

@ -23,7 +23,6 @@
#include "nsWidgetSupport.h"
#include "nsRect.h"
#include "nsITextAreaWidget.h"
#include "nsIFileWidget.h"
#include "nsIAppShell.h"
#include "nsIButton.h"
@ -127,36 +126,6 @@ NS_CreateLabel( nsISupports* aParent,
NS_WIDGET nsresult
NS_CreateTextAreaWidget(nsISupports* aParent,
nsITextAreaWidget* aWidget,
const nsRect& aRect,
EVENT_CALLBACK aHandleEventFunction,
const nsFont* aFont)
{
nsIWidget* parent = nsnull;
if (aParent != nsnull)
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
nsIWidget* widget = nsnull;
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
widget->Create(parent, aRect, aHandleEventFunction, NULL);
widget->Show(PR_TRUE);
if (aFont != nsnull)
widget->SetFont(*aFont);
NS_IF_RELEASE(widget);
}
else
{
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
}
if (aParent)
NS_IF_RELEASE(parent);
return NS_OK;
}
NS_WIDGET nsresult
NS_CreateTextWidget(nsISupports* aParent,
nsITextWidget* aWidget,

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

@ -1,97 +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 <gtk/gtk.h>
#include "nsTextAreaWidget.h"
#include "nsString.h"
NS_IMPL_ADDREF_INHERITED(nsTextAreaWidget, nsWidget)
NS_IMPL_RELEASE_INHERITED(nsTextAreaWidget, nsWidget)
NS_IMPL_QUERY_INTERFACE2(nsTextAreaWidget, nsITextAreaWidget, nsIWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::nsTextAreaWidget()
{
mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextAreaWidget destructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
gtk_widget_destroy(mTextWidget);
mTextWidget = nsnull;
}
//-------------------------------------------------------------------------
//
// Create the native Text widget
//
//-------------------------------------------------------------------------
NS_METHOD nsTextAreaWidget::CreateNative(GtkObject *parentWindow)
{
PRBool oldIsReadOnly;
mWidget = gtk_scrolled_window_new(nsnull, nsnull);
gtk_container_set_border_width(GTK_CONTAINER(mWidget), 0);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(mWidget),
GTK_POLICY_NEVER,
GTK_POLICY_ALWAYS);
mTextWidget = gtk_text_new(nsnull, nsnull);
gtk_text_set_word_wrap(GTK_TEXT(mTextWidget), PR_TRUE);
gtk_widget_set_name(mTextWidget, "nsTextAreaWidget");
gtk_widget_show(mTextWidget);
SetPassword(mIsPassword);
SetReadOnly(mIsReadOnly, oldIsReadOnly);
gtk_container_add(GTK_CONTAINER(mWidget), mTextWidget);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// set font for textarea
//
//-------------------------------------------------------------------------
/* virtual */
void nsTextAreaWidget::SetFontNative(GdkFont *aFont)
{
GtkStyle *style = gtk_style_copy(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0))->style);
// gtk_style_copy ups the ref count of the font
gdk_font_unref (style->font);
style->font = aFont;
gdk_font_ref(style->font);
gtk_widget_set_style(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0)), style);
gtk_style_unref(style);
}

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

@ -1,49 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
/**
* Native GTK+ multi-line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
NS_DECL_ISUPPORTS_INHERITED
virtual void SetFontNative(GdkFont *aFont);
protected:
NS_METHOD CreateNative(GtkObject *parentWindow);
};
#endif // nsTextAreaWidget_h__

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

@ -35,7 +35,7 @@ NS_IMPL_RELEASE_INHERITED(nsTextHelper, nsWidget)
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper() : nsWidget(), nsITextAreaWidget(), nsITextWidget()
nsTextHelper::nsTextHelper() : nsWidget(), nsITextWidget()
{
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;

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

@ -23,14 +23,12 @@
#define nsTextHelper_h__
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWidget.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWidget,
public nsITextAreaWidget,
public nsITextWidget
{

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

@ -1,787 +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 "nsTextAreaWidget.h"
#include "nsMacWindow.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include <memory>
#include <ToolUtils.h>
NS_IMPL_ADDREF(nsTextAreaWidget);
NS_IMPL_RELEASE(nsTextAreaWidget);
#define MARGIN 4
//-------------------------------------------------------------------------
// ¥ NOTE ABOUT MENU HANDLING ¥
//
// The definitions below, as well as the NS_MENU_SELECTED code in
// DispatchEvent() are temporary hacks only. They require the menu
// resources to be created under Contructor with the standard
// PowerPlant menu IDs. All that will go away because:
// - nsTextWidget will be rewritten as an XP widget by the Editor team.
// - menu handling will be rewritten by the XPApp team.
//-------------------------------------------------------------------------
#include <Scrap.h>
typedef SInt32 MessageT;
typedef PRUint32 Uint32;
const MessageT cmd_Cut = 12; // nil
const MessageT cmd_Copy = 13; // nil
const MessageT cmd_Paste = 14; // nil
const MessageT cmd_Clear = 15; // nil
const MessageT cmd_SelectAll = 16; // nil
enum
{
menu_Apple = 128,
menu_File,
menu_Edit
};
/**-------------------------------------------------------------------------------
* nsTextAreaWidget Constructor
* @update dc 09/10/98
*/
nsTextAreaWidget::nsTextAreaWidget(): nsWindow()
{
NS_INIT_REFCNT();
mIsPasswordCallBacksInstalled = PR_FALSE;
mMakeReadOnly = PR_FALSE;
mMakePassword = PR_FALSE;
mTE_Data = nsnull;
WIDGET_SET_CLASSNAME("nsTextAreaWidget");
//mBackground = NS_RGB(124, 124, 124);
AcceptFocusOnClick(PR_TRUE);
}
/**-------------------------------------------------------------------------------
* The create method for a nsTextAreaWidget, using a nsIWidget as the parent
* @update dc 09/10/98
* @param aParent -- the widget which will be this widgets parent in the tree
* @param aRect -- The bounds in parental coordinates of this widget
* @param aHandleEventFunction -- Procedures to be executed for this widget
* @param aContext -- device context to be used by this widget
* @param aAppShell --
* @param aToolkit -- toolkit to be used by this widget
* @param aInitData -- Initialization data used by frames
* @return -- NS_OK if everything was created correctly
*/
NS_IMETHODIMP nsTextAreaWidget::Create(nsIWidget *aParent,const nsRect &aRect,EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,nsIAppShell *aAppShell,nsIToolkit *aToolkit, nsWidgetInitData *aInitData)
{
nsWindow::Create(aParent, aRect, aHandleEventFunction,
aContext, aAppShell, aToolkit, aInitData);
mWindowPtr = nsnull;
if (aParent)
mWindowPtr = (WindowPtr)aParent->GetNativeData(NS_NATIVE_DISPLAY);
/* this always returned NULL, so it was removed
else if (aAppShell)
mWindowPtr = (WindowPtr)aAppShell->GetNativeData(NS_NATIVE_SHELL);
*/
// Initialize the TE record
LongRect destRect, viewRect;
viewRect.top = MARGIN;
viewRect.left = MARGIN;
viewRect.bottom = aRect.height - MARGIN;
viewRect.right = aRect.width - MARGIN;
destRect = viewRect;
StartDraw();
PRUint32 teFlags = weDoAutoScroll | weDoOutlineHilite | weDoMonoStyled;
if (!mVisible)
teFlags |= weDoInhibitRedraw;
WENew(&destRect, &viewRect, teFlags, &mTE_Data);
EndDraw();
return (mTE_Data ? NS_OK : NS_ERROR_FAILURE);
}
//-------------------------------------------------------------------------
// Destroy
//
//-------------------------------------------------------------------------
// The repeater in this widget needs to use out of band notification
// to sever its ties with the nsTimer. If we just rely on the
// dtor to do it, it will never get called because the nsTimer holds a ref to
// this object.
//
NS_IMETHODIMP
nsTextAreaWidget::Destroy()
{
Inherited::Destroy();
if (mRepeating) RemoveFromRepeatList();
if (mIdling) RemoveFromIdleList();
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Destuctor for the nsTextAreaWidget
* @update dc 08/31/98
*/
nsTextAreaWidget::~nsTextAreaWidget()
{
if (mTE_Data)
WEDispose(mTE_Data);
}
NS_INTERFACE_MAP_BEGIN(nsTextAreaWidget)
NS_INTERFACE_MAP_ENTRY(nsITextAreaWidget)
NS_INTERFACE_MAP_END_INHERITING(nsWindow)
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
NS_IMETHODIMP nsTextAreaWidget::Show(PRBool bState)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
if (mVisible == bState)
return NS_OK;
Inherited::Show(bState);
WEFeatureFlag(weFInhibitRedraw, (bState ? weBitClear : weBitSet), mTE_Data);
return NS_OK;
}
//-------------------------------------------------------------------------
/**
* The onPaint handler for a nsTextAreaWidget -- this may change, inherited from windows
* @param aEvent -- The paint event to respond to
* @return -- PR_TRUE if painted, false otherwise
*/
PRBool nsTextAreaWidget::OnPaint(nsPaintEvent & aEvent)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
if (! mVisible)
return PR_FALSE;
StartDraw();
{
// erase all
nsRect rect;
Rect macRect;
GetBounds(rect);
rect.x = rect.y = 0;
nsRectToMacRect(rect, macRect);
::EraseRect(&macRect);
// update text
WEUpdate(nsnull, mTE_Data);
// draw frame
::FrameRect(&macRect);
}
EndDraw();
return PR_FALSE;
}
//-------------------------------------------------------------------------
/**
* The Keydown handler for a nsTextAreaWidget
* @param aKey -- the key pressed
* @param aModifiers -- the modifiers of the key pressed, like command, shift, etc.
* @return -- PR_TRUE if painted, false otherwise
*/
void nsTextAreaWidget::PrimitiveKeyDown(PRInt16 aKey, PRInt16 aModifiers)
{
if (! mTE_Data)
return;
StartDraw();
WEKey(aKey, aModifiers, mTE_Data);
EndDraw();
}
/**-------------------------------------------------------------------------------
* DispatchMouseEvent handle an event for this nsTextAreaWidget
* @update dc 10/10/98
* @Param aEvent -- The mouse event to respond to for this button
* @return -- True if the event was handled, PR_FALSE if we did not handle it.
*/
PRBool nsTextAreaWidget::DispatchMouseEvent(nsMouseEvent &aEvent)
{
if (! mTE_Data)
return PR_FALSE;
PRBool result = PR_FALSE;
switch (aEvent.message)
{
case NS_MOUSE_LEFT_DOUBLECLICK:
case NS_MOUSE_LEFT_BUTTON_DOWN:
Point mouseLoc;
mouseLoc.h = aEvent.point.x;
mouseLoc.v = aEvent.point.y;
EventModifiers modifiers = 0;
if (aEvent.nativeMsg != nsnull)
{
EventRecord* osEvent = (EventRecord*)aEvent.nativeMsg;
modifiers = osEvent->modifiers;
}
StartDraw();
WEClick(mouseLoc, modifiers, aEvent.time, mTE_Data);
EndDraw();
result = PR_TRUE;
break;
case NS_MOUSE_LEFT_BUTTON_UP:
break;
case NS_MOUSE_EXIT:
SetCursor(eCursor_standard);
break;
case NS_MOUSE_ENTER:
SetCursor(eCursor_select);
break;
}
return result;
}
//-------------------------------------------------------------------------
PRBool nsTextAreaWidget::DispatchWindowEvent(nsGUIEvent &aEvent)
{
// filter cursor keys
PRBool passKeyEvent = PR_TRUE;
switch (aEvent.message)
{
case NS_KEY_DOWN:
case NS_KEY_UP:
{
nsKeyEvent* keyEvent = (nsKeyEvent*)&aEvent;
#if 0
// this hack is no longer needed, since Enter is being mapped to
// VK_RETURN in the event handler
if (keyEvent->keyCode == kEnterCharCode)
keyEvent->keyCode = NS_VK_RETURN;
#endif
// is this hack really needed?
EventRecord* theOSEvent = (EventRecord*)aEvent.nativeMsg;
if (theOSEvent && ((theOSEvent->message & charCodeMask) == kEnterCharCode))
theOSEvent->message = (theOSEvent->message & ~charCodeMask) + kReturnCharCode;
switch (keyEvent->keyCode)
{
case NS_VK_PAGE_UP:
case NS_VK_PAGE_DOWN:
case NS_VK_END:
case NS_VK_HOME:
case NS_VK_LEFT:
case NS_VK_UP:
case NS_VK_RIGHT:
case NS_VK_DOWN:
passKeyEvent = PR_FALSE;
break;
}
break;
}
}
// dispatch the message
PRBool eventHandled = PR_FALSE;
if (passKeyEvent)
eventHandled = Inherited::DispatchWindowEvent(aEvent);
if (! eventHandled)
{
switch ( aEvent.message )
{
case NS_GOTFOCUS:
{
if (mTE_Data)
{
StartIdling();
StartDraw();
WEActivate(mTE_Data);
EndDraw();
}
break;
}
case NS_LOSTFOCUS:
{
if (mTE_Data)
{
StopIdling();
StartDraw();
WEDeactivate(mTE_Data);
EndDraw();
}
break;
}
case NS_KEY_DOWN:
{
char theChar;
EventModifiers theModifiers;
EventRecord* theOSEvent = (EventRecord*)aEvent.nativeMsg;
if (theOSEvent)
{
theChar = (theOSEvent->message & charCodeMask);
theModifiers = theOSEvent->modifiers;
}
else
{
nsKeyEvent* keyEvent = (nsKeyEvent*)&aEvent;
theChar = keyEvent->charCode;
if (keyEvent->isShift)
theModifiers = shiftKey;
if (keyEvent->isControl)
theModifiers |= controlKey;
if (keyEvent->isAlt)
theModifiers |= optionKey;
if (keyEvent->isMeta)
theModifiers |= cmdKey;
}
PrimitiveKeyDown(theChar, theModifiers);
eventHandled = PR_TRUE;
break;
}
case NS_MENU_SELECTED:
{
nsMenuEvent* menuEvent = (nsMenuEvent*)&aEvent;
long menuID = HiWord(menuEvent->mCommand);
long menuItem = LoWord(menuEvent->mCommand);
switch (menuID)
{
case menu_Edit:
{
switch (menuItem)
{
// case cmd_Undo:
case cmd_Cut:
case cmd_Copy:
{
PRUint32 startSel = 0, endSel = 0;
GetSelection ( &startSel, &endSel );
if ( startSel != endSel ) {
const Uint32 selectionLen = endSel - startSel;
// extract out the selection into a different nsString so
// we can keep it unicode as long as possible
PRUint32 unused = 0;
nsString str, selection;
GetText(str, 0, unused );
str.Mid(selection, startSel, selectionLen);
// now |selection| holds the current selection in unicode.
// We need to convert it to a c-string for MacOS.
auto_ptr<char> cRepOfSelection(new char[selectionLen + 1]);
selection.ToCString(cRepOfSelection.get(), selectionLen + 1);
// copy it to the scrapMgr
::ZeroScrap();
::PutScrap ( selectionLen, 'TEXT', cRepOfSelection.get() );
// if we're cutting, remove the text from the widget
if ( menuItem == cmd_Cut ) {
unused = 0;
str.Cut ( startSel, selectionLen );
SetText ( str, unused );
}
} // if there is a selection
eventHandled = PR_TRUE;
break;
}
case cmd_Paste:
{
long scrapOffset;
Handle scrapH = ::NewHandle(0);
long scrapLen = ::GetScrap(scrapH, 'TEXT', &scrapOffset);
if (scrapLen > 0)
{
::HLock(scrapH);
// truncate to the first line
//char* cr = strchr((char*)*scrapH, '\r');
//if (cr != nil)
// scrapLen = cr - *scrapH;
// paste text
nsString str;
str.SetString((char*)*scrapH, scrapLen);
PRUint32 startSel, endSel;
GetSelection(&startSel, &endSel);
PRUint32 outSize;
InsertText(str, startSel, endSel, outSize);
startSel += str.Length();
SetSelection(startSel, startSel);
::HUnlock(scrapH);
}
::DisposeHandle(scrapH);
eventHandled = PR_TRUE;
break;
}
case cmd_Clear:
{
nsString str;
PRUint32 outSize;
SetText(str, outSize);
eventHandled = PR_TRUE;
break;
}
case cmd_SelectAll:
{
SelectAll();
eventHandled = PR_TRUE;
break;
}
}
break;
}
}
break;
} // case NS_MENU_SELECTED
} // switch on which event message
} // if key event not handled
return (eventHandled);
}
/**-------------------------------------------------------------------------------
* Sets the password flag. If true, asteriks are the onlything displayed
* @update dc 10/10/98
* @Param aIsPassword -- if true, password attribute is used.
* @return -- if everything is ok
*/
NS_METHOD nsTextAreaWidget::SetPassword(PRBool aIsPassword)
{
//¥TODO?: can we really have textAreas displayed as passwords?
if (aIsPassword)
mMakePassword = PR_TRUE;
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Sets the readonly flag. If true, you can only read the text
* @update dc 10/10/98
* @Param aReadOnlyFlag -- if true, readoly attribute is used.
* @Param aOldFlag -- the old setting
* @return -- if everything is ok
*/
NS_METHOD nsTextAreaWidget::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldFlag)
{
//¥TODO: toggle between read-only and editable modes
aOldFlag = mMakeReadOnly;
mMakeReadOnly = aReadOnlyFlag;
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Sets the maximum number of characters allowed.
* @update dc 10/10/98
* @Param aChars -- number of characters allowed
* @return -- if everything is ok
*/
NS_METHOD nsTextAreaWidget::SetMaxTextLength(PRUint32 aChars)
{
//¥TODO: implement this
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Gets the text from this widget
* @update dc 10/10/98
* @Param aTextBuffer -- string to fill in
* @Param aBufferSize -- size of the buffer passed in
* @Param aSize -- size of the string passed out
* @return -- if everything is ok
*/
NS_METHOD nsTextAreaWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aSize)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
Handle text = WEGetText(mTE_Data);
PRInt32 len = WEGetTextLength(mTE_Data);
char* str = new char[len+1];
for (PRInt32 i = 0; i < len; i++)
str[i] = (*text)[i];
str[len] = 0;
aTextBuffer.SetLength(0);
aTextBuffer.Append(str);
aSize = aTextBuffer.Length();
delete [] str;
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Resize this widget
* @update dc 10/01/98
* @param aWidth -- x offset in widget local coordinates
* @param aHeight -- y offset in widget local coordinates
* @param aRepaint -- indicates if a repaint is needed.
* @return PR_TRUE if the pt is contained in the widget
*/
NS_IMETHODIMP nsTextAreaWidget::Resize(PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
{
return Resize(0, 0, aWidth, aHeight, aRepaint);
}
/**-------------------------------------------------------------------------------
* Resize this widget
* @update dc 10/01/98
* @param aX -- left part of rectangle
* @param aY -- top of rectangle
* @param aWidth -- x offset in widget local coordinates
* @param aHeight -- y offset in widget local coordinates
* @param aW
* @return PR_TRUE
*/
NS_IMETHODIMP nsTextAreaWidget::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, PRBool aRepaint)
{
Inherited::Resize(aX, aY, aWidth, aHeight, aRepaint);
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
LongRect macRect;
macRect.top = mBounds.y + MARGIN;
macRect.left = mBounds.x + MARGIN;
macRect.bottom = mBounds.YMost() - MARGIN;
macRect.right = mBounds.XMost() - MARGIN;
StartDraw();
WESetDestRect(&macRect, mTE_Data);
WESetViewRect(&macRect, mTE_Data);
EndDraw();
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Set the text for this widget
* @update dc 10/01/98
* @param aText -- Text to use in this widget
* @param outSize -- (out only) Length of text displayed in the text area
* @return PR_TRUE
*/
PRUint32 nsTextAreaWidget::SetText(const nsString& aText, PRUint32& outSize)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
outSize = aText.Length();
const unsigned int bufferSize = outSize + 1; // add 1 for null
this->RemoveText();
auto_ptr<char> buffer(new char[bufferSize]);
if (buffer.get())
{
aText.ToCString(buffer.get(), bufferSize);
char* occur = buffer.get(); // replace LineFeed with Return
while ((occur = strchr(occur, '\n')) != nil) {
*occur = '\r';
}
StartDraw();
WEInsert(buffer.get(), outSize, 0, 0, mTE_Data);
EndDraw();
}
else
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
/**-------------------------------------------------------------------------------
* insert text into this widget
* @update dc 10/01/98
* @param aText -- Text to use in this widget
* @param aStartPos - Starting position
* @param aEndtPos - Ending position
* @param aSize -- size of the text to use here
* @return PR_TRUE
*/
PRUint32 nsTextAreaWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aSize)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
const unsigned int bufferSize = aText.Length();
auto_ptr<char> buffer(new char[bufferSize + 1]); // add 1 for null
if (buffer.get())
{
aText.ToCString(buffer.get(), bufferSize + 1);
char* occur = buffer.get(); // replace LineFeed with Return
while ((occur = strchr(occur, '\n')) != nil) {
*occur = '\r';
}
StartDraw();
if (aStartPos == (PRUint32)-1L)
aStartPos = WEGetTextLength(mTE_Data);
if (aEndPos == (PRUint32)-1L)
aEndPos = WEGetTextLength(mTE_Data);
WESetSelection(aStartPos, aEndPos, mTE_Data);
WEInsert(buffer.get(), bufferSize, 0, 0, mTE_Data);
EndDraw();
}
else
return NS_ERROR_OUT_OF_MEMORY;
aSize = WEGetTextLength(mTE_Data);
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Remove all the text for this widget
* @update dc 10/01/98
* @return PR_TRUE
*/
NS_METHOD nsTextAreaWidget::RemoveText()
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
StartDraw();
WESetSelection(0, WEGetTextLength(mTE_Data), mTE_Data);
WEDelete(mTE_Data);
EndDraw();
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Select all the text for this widget
* @update dc 10/01/98
* @return PR_TRUE
*/
NS_METHOD nsTextAreaWidget::SelectAll()
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
StartDraw();
WESetSelection(0, WEGetTextLength(mTE_Data), mTE_Data);
EndDraw();
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Set the text for this widget
* @update dc 10/01/98
* @param aStartSel -- start index of the text
* @param aEndSel -- end index of the text
* @return PR_TRUE
*/
NS_METHOD nsTextAreaWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
StartDraw();
WESetSelection(aStartSel, aEndSel, mTE_Data);
EndDraw();
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Get the text for this widget
* @update dc 10/01/98
* @param aStartSel -- start index of the text
* @param aEndSel -- end index of the text
* @return PR_TRUE
*/
NS_METHOD nsTextAreaWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
{
if (! mTE_Data)
return NS_ERROR_NOT_INITIALIZED;
StartDraw();
WEGetSelection((SInt32*)aStartSel, (SInt32*)aEndSel, mTE_Data);
EndDraw();
return NS_OK;
}
/**-------------------------------------------------------------------------------
* Set the caret position for this widget
* @update dc 10/01/98
* @param aPosition -- postition of text
* @return PR_TRUE
*/
NS_METHOD nsTextAreaWidget::SetCaretPosition(PRUint32 aPosition)
{
return SetSelection(aPosition, aPosition);
}
/**-------------------------------------------------------------------------------
* Get the caret position for this widget
* @update dc 10/01/98
* @param aPosition -- postition of text
* @return PR_TRUE if the pt is contained in the widget
*/
NS_METHOD nsTextAreaWidget::GetCaretPosition(PRUint32& aPos)
{
PRUint32 startSel, endSel;
nsresult res = GetSelection(&startSel, &endSel);
aPos = (res == NS_OK ? startSel : 0);
return res;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
void nsTextAreaWidget::RepeatAction(const EventRecord& inMacEvent)
{
if (mTE_Data)
{
UInt32 maxSleep = 0;
StartDraw();
WEIdle(&maxSleep, mTE_Data);
EndDraw();
}
}

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

@ -1,100 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsWindow.h"
#include "nsITextAreaWidget.h"
#ifndef RHAPSODY
#include "WASTE.h"
#endif
#include "nsRepeater.h"
/**
* Native Mac single line edit control wrapper.
*/
class nsTextAreaWidget : public nsWindow, public nsITextAreaWidget, public Repeater
{
private:
typedef nsWindow Inherited;
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Destroy();
NS_IMETHOD Show(PRBool aState);
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
// nsITextAreaWidget interface
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 Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
// nsWindow Interface
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
virtual PRBool DispatchWindowEvent(nsGUIEvent& event);
// Repeater interface
virtual void RepeatAction(const EventRecord& inMacEvent);
void PrimitiveKeyDown(PRInt16 aKey,PRInt16 aModifiers);
protected:
PRBool mIsPasswordCallBacksInstalled;
private:
PRBool mMakeReadOnly;
PRBool mMakePassword;
WEReference mTE_Data;
};
#endif // nsTextAreaWidget_h__

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

@ -62,7 +62,6 @@
#include "nsDragService.h"
#if USE_NATIVE_VERSION
# include "nsTextAreaWidget.h"
# include "nsCheckButton.h"
#endif
@ -90,7 +89,6 @@ static NS_DEFINE_CID(kCFilePicker, NS_FILEPICKER_CID);
static NS_DEFINE_CID(kCFileOpen, NS_FILEWIDGET_CID);
static NS_DEFINE_CID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
static NS_DEFINE_CID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
static NS_DEFINE_CID(kCTextArea, NS_TEXTAREA_CID);
static NS_DEFINE_CID(kCTextField, NS_TEXTFIELD_CID);
static NS_DEFINE_CID(kCAppShell, NS_APPSHELL_CID);
static NS_DEFINE_CID(kCToolkit, NS_TOOLKIT_CID);
@ -208,9 +206,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCCheckButton)) {
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsCheckButton();
}
else if (mClassID.Equals(kCTextArea)) {
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsTextAreaWidget();
}
#endif
else if (mClassID.Equals(kCHorzScrollbar)) {
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsScrollbar(PR_FALSE);

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

@ -23,7 +23,6 @@
#include "nsWidgetSupport.h"
#include "nsRect.h"
#include "nsITextAreaWidget.h"
#include "nsIFileWidget.h"
#include "nsIAppShell.h"
#include "nsIButton.h"
@ -117,36 +116,6 @@ NS_CreateLabel( nsISupports* aParent,
NS_WIDGET nsresult
NS_CreateTextAreaWidget(nsISupports* aParent,
nsITextAreaWidget* aWidget,
const nsRect& aRect,
EVENT_CALLBACK aHandleEventFunction,
const nsFont* aFont)
{
nsIWidget* parent = nsnull;
if (aParent != nsnull)
aParent->QueryInterface(NS_GET_IID(nsIWidget),(void**)&parent);
nsIWidget* widget = nsnull;
if (NS_OK == aWidget->QueryInterface(NS_GET_IID(nsIWidget),(void**)&widget)) {
widget->Create(parent, aRect, aHandleEventFunction, NULL);
widget->Show(PR_TRUE);
if (aFont != nsnull)
widget->SetFont(*aFont);
NS_IF_RELEASE(widget);
}
else
{
NS_ERROR("Called QueryInterface on a non nsIWidget supported object");
}
if (aParent)
NS_IF_RELEASE(parent);
return NS_OK;
}
NS_WIDGET nsresult
NS_CreateTextWidget(nsISupports* aParent,
nsITextWidget* aWidget,

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

@ -45,7 +45,6 @@ CPPSRCS = \
nsMenuItem.cpp \
nsPopUpMenu.cpp \
nsScrollbar.cpp \
nsTextAreaWidget.cpp \
nsTextHelper.cpp \
nsTextWidget.cpp \
nsToolkit.cpp \

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

@ -1,139 +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 <Xm/Text.h>
#include "nsTextAreaWidget.h"
#include "nsString.h"
#define DBG 0
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::nsTextAreaWidget()
{
mMakeReadOnly = PR_FALSE;
mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextAreaWidget destructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
}
//-------------------------------------------------------------------------
NS_METHOD nsTextAreaWidget::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", (unsigned int)aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", (unsigned int)parentWidget);
mWidget = ::XtVaCreateManagedWidget("button",
xmTextWidgetClass,
parentWidget,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNeditMode, XmMULTI_LINE_EDIT,
XmNeditable, mMakeReadOnly?False:True,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
// save the event callback function
mEventCallback = aHandleEventFunction;
InitCallbacks("nsTextAreaWidget");
if (mMakeReadOnly) {
PRBool oldReadOnly;
SetReadOnly(PR_TRUE, oldReadOnly);
}
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsTextAreaWidget::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
return NS_OK;
}
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
if (aIID.Equals(kITextAreaWidgetIID)) {
nsITextAreaWidget* textArea = this;
*aInstancePtr = (void*) (textArea);
AddRef();
return NS_OK;
}
else if (aIID.Equals(kIWidgetIID))
{
nsIWidget* widget = this;
*aInstancePtr = (void*) (widget);
AddRef();
return NS_OK;
}
return nsWindow::QueryInterface(aIID, aInstancePtr);
}

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

@ -1,65 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
/**
* Native Motif multi-line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
private:
PRBool mMakeReadOnly;
};
#endif // nsTextAreaWidget_h__

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

@ -38,7 +38,7 @@
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget()
nsTextHelper::nsTextHelper() : nsWindow(), nsITextWidget()
{
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;

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

@ -23,16 +23,14 @@
#define nsTextHelper_h__
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWindow.h"
#include <Xm/Xm.h>
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWindow,
public nsITextAreaWidget,
public nsITextWidget
{

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

@ -34,7 +34,6 @@
#include "nsScrollbar.h"
#include "nsCheckButton.h"
#include "nsTextWidget.h"
#include "nsTextAreaWidget.h"
#include "nsFileWidget.h"
#include "nsLookAndFeel.h"
#include "nsLabel.h"
@ -62,7 +61,6 @@ static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID);
static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kCTextField, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kCAppShell, NS_APPSHELL_CID);
static NS_DEFINE_IID(kCToolkit, NS_TOOLKIT_CID);
@ -183,9 +181,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCVertScrollbar)) {
inst = (nsISupports*)(nsIWidget *)new nsScrollbar(PR_TRUE);
}
else if (mClassID.Equals(kCTextArea)) {
inst = (nsISupports*)(nsIWidget *)new nsTextAreaWidget();
}
else if (mClassID.Equals(kCTextField)) {
inst = (nsISupports*)(nsIWidget *)new nsTextWidget();
}

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

@ -1,150 +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 "nsTextAreaWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
#include <Pt.h>
#include "nsPhWidgetLog.h"
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::nsTextAreaWidget() : nsTextHelper()
{
NS_INIT_REFCNT();
mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextAreaWidget destructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
nsresult result = nsWidget::QueryInterface(aIID, aInstancePtr);
static NS_DEFINE_IID(kInsTextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
if (result == NS_NOINTERFACE && aIID.Equals(kInsTextAreaWidgetIID)) {
*aInstancePtr = (void*) ((nsITextAreaWidget*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
//-------------------------------------------------------------------------
//
//
//-------------------------------------------------------------------------
PRBool nsTextAreaWidget::OnPaint()
{
return PR_FALSE;
}
// Not Implemented
PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
NS_METHOD nsTextAreaWidget::CreateNative( PtWidget_t* aParent )
{
nsresult res = NS_ERROR_FAILURE;
PtArg_t arg[5];
PhPoint_t pos;
PhDim_t dim;
pos.x = mBounds.x;
pos.y = mBounds.y;
dim.w = mBounds.width - 4; // Correct for border width
dim.h = mBounds.height - 4;
PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 );
PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 );
PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 2, 0 );
mWidget = PtCreateWidget( PtMultiText, aParent, 3, arg );
if( mWidget )
{
res = NS_OK;
PtAddEventHandler(mWidget, Ph_EV_KEY, RawEventHandler, this);
/* Add an Activate Callback */
// PtAddCallback(mWidget, Pt_CB_ACTIVATE, handle_activate_event, this);
}
return res;
}
int nsTextAreaWidget::RawEventHandler(PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbInfo )
{
nsTextAreaWidget *me = (nsTextAreaWidget *) aData; /* Mozilla object that created the event */
if( aCbInfo->reason == Pt_CB_RAW )
{
PhEvent_t* event = aCbInfo->event;
switch( event->type )
{
case Ph_EV_KEY:
{
PhKeyEvent_t* keyev = (PhKeyEvent_t*) PhGetData( event );
me->DispatchKeyEvent(keyev);
break;
}
default:
break;
}
}
return (Pt_CONTINUE);
}

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

@ -1,54 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
/**
* Native Photon single line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
virtual PRBool OnPaint();
virtual PRBool OnResize(nsRect &aWindowRect);
protected:
NS_IMETHOD CreateNative(PtWidget_t *aParentWindow);
static int RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo );
// static int handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo );
};
#endif // nsTextAreaWidget_h__

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

@ -245,7 +245,7 @@ NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos)
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper() : nsWidget(), nsITextAreaWidget(), nsITextWidget()
nsTextHelper::nsTextHelper() : nsWidget(), nsITextWidget()
{
mIsReadOnly = PR_FALSE;
mIsPassword = PR_FALSE;

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

@ -23,15 +23,13 @@
#define nsTextHelper_h__
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWidget.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWidget,
public nsITextAreaWidget,
public nsITextWidget
{

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

@ -3,7 +3,6 @@ moc_nsQApplication.cpp
moc_nsLabel.cpp
moc_nsScrollbar.cpp
moc_nsButton.cpp
moc_nsTextAreaWidget.cpp
moc_nsCheckButton.cpp
moc_nsTextWidget.cpp
moc_nsTabWidget.cpp

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

@ -1,113 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 "nsTextAreaWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#define DBG 0
//=============================================================================
//
// nsQMultiLineEdit class
//
//=============================================================================
nsQMultiLineEdit::nsQMultiLineEdit(nsWidget * widget,
QWidget * parent,
const char * name)
: QMultiLineEdit(parent, name), nsQBaseWidget(widget)
{
}
nsQMultiLineEdit::~nsQMultiLineEdit()
{
}
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::nsTextAreaWidget()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextAreaWidget::nsTextAreaWidget()\n"));
mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextAreaWidget destructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextAreaWidget::~nsTextAreaWidget()\n"));
}
nsresult
nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextAreaWidget::QueryInterface()\n"));
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
if (aIID.Equals(kITextAreaWidgetIID))
{
nsITextAreaWidget* textArea = this;
*aInstancePtr = (void*) (textArea);
AddRef();
return NS_OK;
}
else if (aIID.Equals(kIWidgetIID))
{
nsIWidget* widget = this;
*aInstancePtr = (void*) (widget);
AddRef();
return NS_OK;
}
return nsWidget::QueryInterface(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsTextAreaWidget::OnPaint(nsPaintEvent & aEvent)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextAreaWidget::OnPaint()\n"));
return PR_FALSE;
}
//--------------------------------------------------------------
PRBool nsTextAreaWidget::OnResize(nsRect &aRect)
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextAreaWidget::OnResize()\n"));
return PR_FALSE;
}

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

@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsWidget.h"
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
#include <qmultilineedit.h>
//=============================================================================
//
// nsQMultiLineEdit class
//
//=============================================================================
class nsQMultiLineEdit : public QMultiLineEdit, public nsQBaseWidget
{
Q_OBJECT
public:
nsQMultiLineEdit(nsWidget * widget,
QWidget * parent = 0,
const char * name = 0);
~nsQMultiLineEdit();
};
/**
* Native QT multi-line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
NS_DECL_ISUPPORTS
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsRect &aRect);
};
#endif // nsTextAreaWidget_h__

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

@ -22,7 +22,6 @@
#include "nsTextHelper.h"
#include "nsTextWidget.h"
#include "nsTextAreaWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
@ -42,7 +41,7 @@
//
//-------------------------------------------------------------------------
nsTextHelper::nsTextHelper() : nsWidget(), nsITextAreaWidget(), nsITextWidget()
nsTextHelper::nsTextHelper() : nsWidget(), nsITextWidget()
{
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsTextHelper::nsTextHelper()\n"));
mIsReadOnly = PR_FALSE;

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

@ -23,15 +23,13 @@
#define nsTextHelper_h__
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWidget.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWidget,
public nsITextAreaWidget,
public nsITextWidget
{

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

@ -1,272 +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 <pp@ludusdesign.com>
*/
#include "nsTextAreaWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include <windows.h>
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
/*NS_IMPL_ADDREF(nsTextAreaWidget)
//NS_IMPL_RELEASE(nsTextAreaWidget)
nsrefcnt nsTextAreaWidget::Release(void)
{
// NS_PRECONDITION(0 != cnt, "dup release");
if (--mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}*/
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
//-------------------------------------------------------------------------
//
// nsTextAreaWidget constructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::nsTextAreaWidget()
{
NS_INIT_REFCNT();
nsTextHelper::mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsTextAreaWidget destructor
//
//-------------------------------------------------------------------------
nsTextAreaWidget::~nsTextAreaWidget()
{
}
//-------------------------------------------------------------------------
void nsTextAreaWidget::SetUpForPaint(HDC aHDC)
{
::SetBkColor (aHDC, NSRGB_2_COLOREF(mBackground));
::SetTextColor(aHDC, NSRGB_2_COLOREF(mForeground));
//::SetBkMode (aHDC, TRANSPARENT); // don't do this
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (aIID.Equals(NS_GET_IID(nsITextAreaWidget))) {
nsITextAreaWidget* textArea = this;
*aInstancePtr = (void*) (textArea);
NS_ADDREF_THIS();
return NS_OK;
}
else if (aIID.Equals(NS_GET_IID(nsIWidget)))
{
nsIWidget* widget = this;
*aInstancePtr = (void*) (widget);
NS_ADDREF_THIS();
return NS_OK;
}
return nsWindow::QueryInterface(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsTextAreaWidget::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsTextAreaWidget::OnPaint()
{
return PR_FALSE;
}
PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// return the window class name and initialize the class if needed
//
//-------------------------------------------------------------------------
LPCTSTR nsTextAreaWidget::WindowClass()
{
return(nsTextHelper::WindowClass());
}
//-------------------------------------------------------------------------
//
// return window styles
//
//-------------------------------------------------------------------------
DWORD nsTextAreaWidget::WindowStyle()
{
DWORD style = WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | ES_NOHIDESEL | ES_MULTILINE | WS_VSCROLL;
if (mIsReadOnly)
style = style | ES_READONLY;
return style;
}
//-------------------------------------------------------------------------
//
// return window extended styles
//
//-------------------------------------------------------------------------
DWORD nsTextAreaWidget::WindowExStyle()
{
return WS_EX_CLIENTEDGE;
}
//-------------------------------------------------------------------------
//
// get position/dimensions
//
//-------------------------------------------------------------------------
NS_METHOD nsTextAreaWidget::GetBounds(nsRect &aRect)
{
nsWindow::GetNonClientBounds(aRect);
return NS_OK;
}
/**
* Renders the TextWidget for Printing
*
**/
NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
nsRect rect;
float appUnits;
float scale;
nsIDeviceContext * context;
aRenderingContext.GetDeviceContext(context);
context->GetCanonicalPixelScale(scale);
context->GetDevUnitsToAppUnits(appUnits);
GetBoundsAppUnits(rect, appUnits);
aRenderingContext.SetColor(NS_RGB(0,0,0));
nscolor bgColor = NS_RGB(255,255,255);
nscolor fgColor = NS_RGB(0,0,0);
nscolor hltColor = NS_RGB(240,240,240);
nscolor sdwColor = NS_RGB(128,128,128);
nscolor txtBGColor = NS_RGB(255,255,255);
nscolor txtFGColor = NS_RGB(0,0,0);
nsILookAndFeel * lookAndFeel;
if (NS_OK == 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);
aRenderingContext.DrawString(mText, x, y);
NS_RELEASE(context);
return NS_OK;
}

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

@ -1,68 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
/**
* Native WIN32 multi-line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIWidget Overrides
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint();
virtual PRBool OnResize(nsRect &aWindowRect);
NS_IMETHOD GetBounds(nsRect &aRect);
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
virtual void SetUpForPaint(HDC aHDC);
protected:
virtual LPCTSTR WindowClass();
virtual DWORD WindowStyle();
virtual DWORD WindowExStyle();
};
#endif // nsTextAreaWidget_h__

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

@ -24,15 +24,13 @@
#include "nsdefs.h"
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWindow.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWindow,
public nsITextAreaWidget,
public nsITextWidget
{

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

@ -52,7 +52,6 @@ CPPSRCS = \
nsPopUpMenu.cpp \
nsScrollBar.cpp \
nsSound.cpp \
nsTextAreaWidget.cpp \
nsTextHelper.cpp \
nsTextWidget.cpp \
nsToolkit.cpp \

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

@ -1,62 +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 "nsTextAreaWidget.h"
NS_IMPL_ADDREF(nsTextAreaWidget)
NS_IMPL_RELEASE(nsTextAreaWidget)
nsTextAreaWidget::nsTextAreaWidget()
{
NS_INIT_REFCNT();
}
nsTextAreaWidget::~nsTextAreaWidget()
{
}
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
if (aIID.Equals(kITextAreaWidgetIID)) {
nsITextAreaWidget* textArea = this;
*aInstancePtr = (void*) (textArea);
NS_ADDREF_THIS();
return NS_OK;
}
else if (aIID.Equals(kIWidgetIID)) {
nsIWidget* widget = this;
*aInstancePtr = (void*) (widget);
NS_ADDREF_THIS();
return NS_OK;
}
return nsWidget::QueryInterface(aIID, aInstancePtr);
}
NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
return NS_OK;
}

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

@ -1,56 +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):
*/
#ifndef nsTextAreaWidget_h__
#define nsTextAreaWidget_h__
#include "nsWidget.h"
#include "nsTextHelper.h"
#include "nsITextAreaWidget.h"
/**
* Native WIN32 multi-line edit control wrapper.
*/
class nsTextAreaWidget : public nsTextHelper
{
public:
nsTextAreaWidget();
virtual ~nsTextAreaWidget();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIWidget Overrides
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
protected:
};
#endif // nsTextAreaWidget_h__

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

@ -92,7 +92,7 @@ NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos)
return NS_OK;
}
nsTextHelper::nsTextHelper() : nsWidget(), nsITextAreaWidget(), nsITextWidget()
nsTextHelper::nsTextHelper() : nsWidget(), nsITextWidget()
{
}

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

@ -23,15 +23,13 @@
#define nsTextHelper_h__
#include "nsITextWidget.h"
#include "nsITextAreaWidget.h"
#include "nsWidget.h"
/**
* Base class for nsTextAreaWidget and nsTextWidget
* Base class for nsTextAreaWidget (obsolete) and nsTextWidget
*/
class nsTextHelper : public nsWidget,
public nsITextAreaWidget,
public nsITextWidget
{