зеркало из https://github.com/mozilla/gecko-dev.git
First Checked In.
This commit is contained in:
Родитель
dc085ac192
Коммит
6789c4d741
|
@ -0,0 +1,131 @@
|
|||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsFileWidget_h__
|
||||
#define nsFileWidget_h__
|
||||
|
||||
#include "nsToolkit.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIFileWidget.h"
|
||||
#include "nsWindow.h"
|
||||
|
||||
/**
|
||||
* Native Motif FileSelector wrapper
|
||||
*/
|
||||
|
||||
class nsFileWidget : public nsWindow
|
||||
{
|
||||
public:
|
||||
nsFileWidget(nsISupports *aOuter);
|
||||
virtual ~nsFileWidget();
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
// nsIWidget interface
|
||||
|
||||
virtual void Create( nsIWidget *aParent,
|
||||
nsString& aTitle,
|
||||
nsMode aMode,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
void *aInitData = nsnull);
|
||||
|
||||
// nsIFileWidget part
|
||||
virtual void Show(PRBool bState);
|
||||
virtual void GetFile(nsString& aFile);
|
||||
virtual void SetDefaultString(nsString& aString);
|
||||
virtual void SetFilterList(PRUint32 aNumberOfFilters,
|
||||
const nsString aTitles[],
|
||||
const nsString aFilters[]);
|
||||
virtual void OnOk();
|
||||
virtual void OnCancel();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
PRBool mIOwnEventLoop;
|
||||
PRBool mWasCancelled;
|
||||
nsString mTitle;
|
||||
nsMode mMode;
|
||||
nsString mFile;
|
||||
PRUint32 mNumberOfFilters;
|
||||
const nsString* mTitles;
|
||||
const nsString* mFilters;
|
||||
nsString mDefault;
|
||||
|
||||
void GetFilterListArray(nsString& aFilterList);
|
||||
|
||||
private:
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsFileWidget,mAggWidget);
|
||||
}
|
||||
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIFileWidget interface to nsFileWidget w/o using multiple
|
||||
// inheritance.
|
||||
class AggFileWidget : public nsIFileWidget {
|
||||
public:
|
||||
AggFileWidget();
|
||||
virtual ~AggFileWidget();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
// nsIFileWidget
|
||||
virtual void Create( nsIWidget *aParent,
|
||||
nsString& aTitle,
|
||||
nsMode aMode,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
void *aInitData = nsnull);
|
||||
|
||||
virtual void GetFile(nsString& aFile);
|
||||
virtual void SetDefaultString(nsString& aString);
|
||||
virtual void SetFilterList(PRUint32 aNumberOfFilters,
|
||||
const nsString aTitles[],
|
||||
const nsString aFilters[]);
|
||||
|
||||
virtual PRBool Show();
|
||||
virtual void OnOk();
|
||||
virtual void OnCancel();
|
||||
};
|
||||
AggFileWidget mAggWidget;
|
||||
friend class AggFileWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsFileWidget_h__
|
|
@ -0,0 +1,556 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsListBox.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include <Xm/List.h>
|
||||
|
||||
#define DBG 0
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
mMultiSelect = aMultipleSelections;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
|
||||
XmString str;
|
||||
|
||||
str = XmStringCreateLocalized(val);
|
||||
|
||||
XmListAddItem(mWidget, str, (int)aPosition+1);
|
||||
NS_FREE_STR_BUF(val);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
|
||||
XmString str = XmStringCreate(val, XmFONTLIST_DEFAULT_TAG);
|
||||
|
||||
int index = XmListItemPos(mWidget, str)-1;
|
||||
if (index < aStartPos) {
|
||||
index = -1;
|
||||
}
|
||||
NS_FREE_STR_BUF(val);
|
||||
XmStringFree(str);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
|
||||
|
||||
return (PRInt32)count;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
|
||||
if (aPosition >= 0 && aPosition < count) {
|
||||
XmListDeletePos(mWidget, aPosition+1);
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
XmStringTable list;
|
||||
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNitems, &list, XmNitemCount, &count, nsnull);
|
||||
|
||||
if (aPosition >= 0 && aPosition < count) {
|
||||
char * text;
|
||||
if (XmStringGetLtoR(list[aPosition], XmFONTLIST_DEFAULT_TAG, &text)) {
|
||||
anItem.SetLength(0);
|
||||
anItem.Append(text);
|
||||
XtFree(text);
|
||||
result = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
int * list;
|
||||
int count;
|
||||
|
||||
if (XmListGetSelectedPos(mWidget, &list, &count)) {
|
||||
GetItemAt(aItem, list[0]-1);
|
||||
XtFree((char *)list);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
int * list;
|
||||
int count;
|
||||
|
||||
if (XmListGetSelectedPos(mWidget, &list, &count)) {
|
||||
int index = -1;
|
||||
if (count > 0) {
|
||||
index = list[0]-1;
|
||||
}
|
||||
XtFree((char *)list);
|
||||
return index;
|
||||
}
|
||||
} else {
|
||||
NS_ASSERTION(0, "Multi selection list box does not support GetSlectedIndex()");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
|
||||
if (aPosition >= 0 && aPosition < count) {
|
||||
XmListSelectPos(mWidget, aPosition+1, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNselectedItemCount, &count, nsnull);
|
||||
return (PRInt32)count;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
int * list;
|
||||
int count;
|
||||
|
||||
if (XmListGetSelectedPos(mWidget, &list, &count)) {
|
||||
int num = aSize > count?count:aSize;
|
||||
int i;
|
||||
for (i=0;i<num;i++) {
|
||||
aIndices[i] = (PRInt32)list[i]-1;
|
||||
}
|
||||
XtFree((char *)list);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
if (GetSelectedCount() > 0) {
|
||||
XtVaSetValues(mWidget, XmNselectedItemCount, 0, NULL);
|
||||
}
|
||||
int i;
|
||||
for (i=0;i<aSize;i++) {
|
||||
SelectItem(aIndices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::Deselect()
|
||||
{
|
||||
XtVaSetValues(mWidget, XmNselectedItemCount, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::nsListBox(nsISupports *aOuter) : nsWindow(aOuter)
|
||||
{
|
||||
mMultiSelect = PR_FALSE;
|
||||
mBackground = NS_RGB(124, 124, 124);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::~nsListBox()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsListBox::QueryObject(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult result = nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
|
||||
static NS_DEFINE_IID(kInsListBoxIID, NS_ILISTBOX_IID);
|
||||
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
|
||||
if (result == NS_NOINTERFACE) {
|
||||
if (aIID.Equals(kInsListBoxIID)) {
|
||||
*aInstancePtr = (void*) ((nsIListBox*)&mAggWidget);
|
||||
AddRef();
|
||||
result = NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(kInsListWidgetIID)) {
|
||||
*aInstancePtr = (void*) ((nsIListWidget*)&mAggWidget);
|
||||
AddRef();
|
||||
result = NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::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", 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", parentWidget);
|
||||
|
||||
unsigned char selectionPolicy;
|
||||
|
||||
Boolean autoSelection;
|
||||
if (mMultiSelect) {
|
||||
//selectionPolicy = XmEXTENDED_SELECT;
|
||||
selectionPolicy = XmMULTIPLE_SELECT;
|
||||
autoSelection = TRUE;
|
||||
} else {
|
||||
selectionPolicy = XmBROWSE_SELECT;
|
||||
autoSelection = FALSE;
|
||||
}
|
||||
|
||||
mWidget = ::XtVaCreateManagedWidget("",
|
||||
xmListWidgetClass,
|
||||
parentWidget,
|
||||
XmNitemCount, 0,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
XmNwidth, aRect.width,
|
||||
XmNheight, aRect.height,
|
||||
XmNrecomputeSize, False,
|
||||
XmNselectionPolicy, selectionPolicy,
|
||||
XmNautomaticSelection, autoSelection,
|
||||
XmNscrollBarDisplayPolicy, XmAS_NEEDED,
|
||||
XmNlistSizePolicy, XmCONSTANT,
|
||||
XmNmarginTop, 0,
|
||||
XmNmarginBottom, 0,
|
||||
XmNmarginLeft, 0,
|
||||
XmNmarginRight, 0,
|
||||
XmNmarginHeight, 0,
|
||||
XmNmarginWidth, 0,
|
||||
XmNlistMarginHeight, 0,
|
||||
XmNlistMarginWidth, 0,
|
||||
XmNscrolledWindowMarginWidth, 0,
|
||||
XmNscrolledWindowMarginHeight, 0,
|
||||
nsnull);
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
//InitCallbacks();
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint message. Don't send the paint out
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::OnPaint(nsPaintEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
#define GET_OUTER() ((nsListBox*) ((char*)this - nsListBox::GetOuterOffset()))
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetMultipleSelection
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void nsListBox::AggListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
GET_OUTER()->SetMultipleSelection(aMultipleSelections);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
void nsListBox::AggListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
GET_OUTER()->AddItemAt(aItem, aPosition);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::AggListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
return GET_OUTER()->FindItem(aItem, aStartPos);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::AggListBox::GetItemCount()
|
||||
{
|
||||
return GET_OUTER()->GetItemCount();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::AggListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
return GET_OUTER()->RemoveItemAt(aPosition);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::AggListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
return GET_OUTER()->GetItemAt(anItem, aPosition);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::AggListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
GET_OUTER()->GetSelectedItem(aItem);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::AggListBox::GetSelectedIndex()
|
||||
{
|
||||
return GET_OUTER()->GetSelectedIndex();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::AggListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
GET_OUTER()->SelectItem(aPosition);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::AggListBox::GetSelectedCount()
|
||||
{
|
||||
return GET_OUTER()->GetSelectedCount();
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::AggListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
GET_OUTER()->GetSelectedIndices(aIndices, aSize);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::AggListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
GET_OUTER()->SetSelectedIndices(aIndices, aSize);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::AggListBox::Deselect()
|
||||
{
|
||||
GET_OUTER()->Deselect();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsListBox, AggListBox);
|
||||
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsIListBox.h"
|
||||
|
||||
/**
|
||||
* Native Motif Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWindow
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox(nsISupports *aOuter);
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports. Forward to the nsObject base class
|
||||
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
|
||||
// nsIListBox interface
|
||||
void SetMultipleSelection(PRBool aMultipleSelections);
|
||||
void AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||
PRInt32 GetItemCount();
|
||||
PRBool RemoveItemAt(PRInt32 aPosition);
|
||||
PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||
void GetSelectedItem(nsString& aItem);
|
||||
PRInt32 GetSelectedIndex();
|
||||
PRInt32 GetSelectedCount();
|
||||
void GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
void SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
void SelectItem(PRInt32 aPosition);
|
||||
void Deselect() ;
|
||||
|
||||
protected:
|
||||
PRBool mMultiSelect;
|
||||
|
||||
private:
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsListBox,mAggWidget);
|
||||
}
|
||||
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIListBox interface to nsListBox w/o using multiple
|
||||
// inheritance.
|
||||
class AggListBox : public nsIListBox {
|
||||
public:
|
||||
AggListBox();
|
||||
virtual ~AggListBox();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
// nsIListBox
|
||||
void SetMultipleSelection(PRBool aMultipleSelections);
|
||||
void AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||
PRInt32 GetItemCount();
|
||||
PRBool RemoveItemAt(PRInt32 aPosition);
|
||||
PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||
void GetSelectedItem(nsString& aItem);
|
||||
PRInt32 GetSelectedIndex();
|
||||
PRInt32 GetSelectedCount();
|
||||
void GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
void SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
void SelectItem(PRInt32 aPosition);
|
||||
void Deselect() ;
|
||||
|
||||
};
|
||||
AggListBox mAggWidget;
|
||||
friend class AggListBox;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
|
@ -0,0 +1,109 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsLookAndFeel.h"
|
||||
|
||||
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsLookAndFeel, kILookAndFeelIID);
|
||||
|
||||
nsLookAndFeel::nsLookAndFeel(nsISupports *aOuter)
|
||||
{
|
||||
mRefCnt = 0;
|
||||
}
|
||||
|
||||
nsLookAndFeel::~nsLookAndFeel()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nscolor) nsLookAndFeel::GetColor(nsColorID aID)
|
||||
{
|
||||
nscolor res = NS_RGB(0xff,0xff,0xff);
|
||||
switch (aID) {
|
||||
case WindowBackground:
|
||||
res = NS_RGB(0xff,0xff,0xff);
|
||||
break;
|
||||
case WindowForeground:
|
||||
res = NS_RGB(0x00,0x00,0x00);
|
||||
break;
|
||||
case WidgetBackground:
|
||||
res = NS_RGB(0x80,0x80,0x80);
|
||||
break;
|
||||
case WidgetForeground:
|
||||
res = NS_RGB(0x00,0x00,0x00);
|
||||
break;
|
||||
case WidgetSelectBackground:
|
||||
res = NS_RGB(0x80,0x80,0x80);
|
||||
break;
|
||||
case WidgetSelectForeground:
|
||||
res = NS_RGB(0x00,0x00,0x80);
|
||||
break;
|
||||
case Widget3DHighlight:
|
||||
res = NS_RGB(0xa0,0xa0,0xa0);
|
||||
break;
|
||||
case Widget3DShadow:
|
||||
res = NS_RGB(0x40,0x40,0x40);
|
||||
break;
|
||||
case TextBackground:
|
||||
res = NS_RGB(0xff,0xff,0xff);
|
||||
break;
|
||||
case TextForeground:
|
||||
res = NS_RGB(0x00,0x00,0x00);
|
||||
break;
|
||||
case TextSelectBackground:
|
||||
res = NS_RGB(0x00,0x00,0x80);
|
||||
break;
|
||||
case TextSelectForeground:
|
||||
res = NS_RGB(0xff,0xff,0xff);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32) nsLookAndFeel::GetMetric(nsMetricID aID)
|
||||
{
|
||||
PRInt32 res;
|
||||
switch (aID) {
|
||||
case WindowTitleHeight:
|
||||
res = 0;
|
||||
break;
|
||||
case WindowBorderWidth:
|
||||
res = 4;
|
||||
break;
|
||||
case WindowBorderHeight:
|
||||
res = 4;
|
||||
break;
|
||||
case Widget3DBorder:
|
||||
res = 4;
|
||||
break;
|
||||
default:
|
||||
res = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef __nsLookAndFeel
|
||||
#define __nsLookAndFeel
|
||||
#include "nsILookAndFeel.h"
|
||||
|
||||
class nsLookAndFeel: public nsILookAndFeel {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
nsLookAndFeel(nsISupports *aOuter);
|
||||
virtual ~nsLookAndFeel();
|
||||
|
||||
NS_IMETHOD_(nscolor) GetColor(nsColorID aID);
|
||||
NS_IMETHOD_(PRInt32) GetMetric(nsMetricID aID);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,332 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsRadioButton.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include "nsXtEventHandler.h"
|
||||
#include <Xm/ToggleB.h>
|
||||
#include <Xm/RowColumn.h>
|
||||
|
||||
#define DBG 0
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsRadioButton constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsRadioButton::nsRadioButton(nsISupports *aOuter) :
|
||||
nsWindow(aOuter),
|
||||
mIsArmed(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsRadioButton destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsRadioButton::~nsRadioButton()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsRadioButton Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::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", 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", parentWidget);
|
||||
|
||||
mWidget = ::XmCreateRadioBox(parentWidget, "radio", nsnull, 0);
|
||||
XtVaSetValues(mWidget, XmNwidth, aRect.width,
|
||||
XmNheight, aRect.height,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
XmNrecomputeSize, False,
|
||||
XmNresizeHeight, False,
|
||||
XmNresizeWidth, False,
|
||||
XmNradioAlwaysOne, False,
|
||||
XmNmarginHeight, 0,
|
||||
XmNmarginWidth, 0,
|
||||
XmNadjustMargin, False,
|
||||
XmNspacing, 0,
|
||||
// XmNentryAlignment, XmALIGNMENT_CENTER,
|
||||
// XmNentryVerticalAlignment, XmALIGNMENT_CENTER,
|
||||
XmNisAligned, False,
|
||||
XmNentryBorder, 0,
|
||||
XmNorientation, XmVERTICAL,
|
||||
XmNborderWidth, 0,
|
||||
0);
|
||||
|
||||
mRadioBtn = ::XmCreateToggleButton(mWidget, "", nsnull, 0);
|
||||
|
||||
XtVaSetValues(mRadioBtn,
|
||||
XmNwidth, aRect.width,
|
||||
XmNheight, aRect.height,
|
||||
XmNx, 0,
|
||||
XmNy, 0,
|
||||
XmNrecomputeSize, False,
|
||||
XmNresizeHeight, False,
|
||||
XmNresizeWidth, False,
|
||||
XmNmarginHeight, 0,
|
||||
XmNmarginWidth, 0,
|
||||
XmNadjustMargin, False,
|
||||
XmNspacing, 0,
|
||||
XmNisAligned, False,
|
||||
XmNentryBorder, 0,
|
||||
XmNborderWidth, 0,
|
||||
0);
|
||||
|
||||
XtManageChild(mRadioBtn);
|
||||
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
InitCallbacks();
|
||||
|
||||
XtAddCallback(mRadioBtn,
|
||||
XmNarmCallback,
|
||||
nsXtWidget_RadioButton_ArmCallback,
|
||||
this);
|
||||
|
||||
XtAddCallback(mRadioBtn,
|
||||
XmNdisarmCallback,
|
||||
nsXtWidget_RadioButton_DisArmCallback,
|
||||
this);
|
||||
|
||||
/*XtAddCallback(mRadioBtn,
|
||||
XmNvalueChangedCallback,
|
||||
nsXtWidget_Toggle_ValueChangedCallback,
|
||||
this);*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsRadioButton Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsRadioButton::QueryObject(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
|
||||
|
||||
if (aIID.Equals(kIRadioButtonIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Armed
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::Armed()
|
||||
{
|
||||
mIsArmed = PR_TRUE;
|
||||
mValueWasSet = PR_FALSE;
|
||||
mInitialState = XmToggleButtonGetState(mRadioBtn);
|
||||
if (DBG) printf("Arm: InitialValue: %d\n", mInitialState);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// DisArmed
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::DisArmed()
|
||||
{
|
||||
if (DBG) printf("DisArm: InitialValue: %d\n", mInitialState);
|
||||
if (DBG) printf("DisArm: ActualValue: %d\n", XmToggleButtonGetState(mRadioBtn));
|
||||
if (DBG) printf("DisArm: mValueWasSet %d\n", mValueWasSet);
|
||||
if (DBG) printf("DisArm: mNewValue %d\n", mNewValue);
|
||||
|
||||
if (mValueWasSet) {
|
||||
XmToggleButtonSetState(mRadioBtn, mNewValue, TRUE);
|
||||
} else {
|
||||
XmToggleButtonSetState(mRadioBtn, mInitialState, TRUE);
|
||||
}
|
||||
mIsArmed = PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::SetState(PRBool aState)
|
||||
{
|
||||
int state = aState;
|
||||
if (mIsArmed) {
|
||||
mNewValue = aState;
|
||||
mValueWasSet = PR_TRUE;
|
||||
}
|
||||
XmToggleButtonSetState(mRadioBtn, aState, TRUE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsRadioButton::GetState()
|
||||
{
|
||||
int state = XmToggleButtonGetState(mRadioBtn);
|
||||
if (mIsArmed) {
|
||||
if (mValueWasSet) {
|
||||
return mNewValue;
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::SetLabel(const nsString& aText)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(label, aText, 256);
|
||||
XmString str;
|
||||
str = XmStringCreate(label, XmFONTLIST_DEFAULT_TAG);
|
||||
XtVaSetValues(mRadioBtn, XmNlabelString, str, nsnull);
|
||||
NS_FREE_STR_BUF(label);
|
||||
XmStringFree(str);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsRadioButton::GetLabel(nsString& aBuffer)
|
||||
{
|
||||
XmString str;
|
||||
XtVaGetValues(mRadioBtn, XmNlabelString, &str, nsnull);
|
||||
char * text;
|
||||
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
|
||||
aBuffer.SetLength(0);
|
||||
aBuffer.Append(text);
|
||||
XtFree(text);
|
||||
}
|
||||
XmStringFree(str);
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsRadioButton::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsRadioButton::OnPaint(nsPaintEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsRadioButton::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define GET_OUTER() \
|
||||
((nsRadioButton*) ((char*)this - nsRadioButton::GetOuterOffset()))
|
||||
|
||||
PRBool nsRadioButton::AggRadioButton::GetState()
|
||||
{
|
||||
return GET_OUTER()->GetState();
|
||||
}
|
||||
|
||||
void nsRadioButton::AggRadioButton::SetState(PRBool aState)
|
||||
{
|
||||
GET_OUTER()->SetState(aState);
|
||||
}
|
||||
|
||||
void nsRadioButton::AggRadioButton::SetLabel(const nsString& aText)
|
||||
{
|
||||
GET_OUTER()->SetLabel(aText);
|
||||
}
|
||||
|
||||
void nsRadioButton::AggRadioButton::GetLabel(nsString& aText)
|
||||
{
|
||||
GET_OUTER()->GetLabel(aText);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsRadioButton, AggRadioButton);
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRadioButton_h__
|
||||
#define nsRadioButton_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsIRadioButton.h"
|
||||
|
||||
/**
|
||||
* Native Motif Radiobutton wrapper
|
||||
*/
|
||||
|
||||
class nsRadioButton : public nsWindow
|
||||
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
nsRadioButton(nsISupports *aOuter);
|
||||
virtual ~nsRadioButton();
|
||||
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
// nsIRadioButton part
|
||||
virtual void SetLabel(const nsString& aText);
|
||||
virtual void GetLabel(nsString& aBuffer);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint(nsPaintEvent &aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
virtual void SetState(PRBool aState);
|
||||
virtual PRBool GetState();
|
||||
|
||||
// These are needed to Override the auto check behavior
|
||||
void Armed();
|
||||
void DisArmed();
|
||||
|
||||
private:
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsRadioButton,mAggWidget);
|
||||
}
|
||||
|
||||
Widget mRadioBtn;
|
||||
Boolean mInitialState;
|
||||
Boolean mNewValue;
|
||||
Boolean mValueWasSet;
|
||||
Boolean mIsArmed;
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIButton interface to nsRadioButton w/o using multiple
|
||||
// inheritance.
|
||||
class AggRadioButton : public nsIRadioButton {
|
||||
public:
|
||||
AggRadioButton();
|
||||
virtual ~AggRadioButton();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
// nsIRadioButton
|
||||
virtual void SetLabel(const nsString &aText);
|
||||
virtual void GetLabel(nsString &aBuffer);
|
||||
virtual void SetState(PRBool aState);
|
||||
virtual PRBool GetState();
|
||||
|
||||
};
|
||||
AggRadioButton mAggWidget;
|
||||
friend class AggRadioButton;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsRadioButton_h__
|
|
@ -0,0 +1,508 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsScrollbar.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include <Xm/ScrollBar.h>
|
||||
|
||||
#include "nsXtEventHandler.h"
|
||||
|
||||
#define DBG 0
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsScrollbar constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsScrollbar::nsScrollbar(nsISupports *aOuter, PRBool aIsVertical) : nsWindow(aOuter)
|
||||
{
|
||||
strcpy(gInstanceClassName, "nsScrollbar");
|
||||
mOrientation = (aIsVertical) ? XmVERTICAL : XmHORIZONTAL;
|
||||
mLineIncrement = 0;
|
||||
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Create
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsScrollbar::Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
Widget parentWidget = (Widget)aParent;
|
||||
strcpy(gInstanceClassName, "nsScrollbar");
|
||||
|
||||
int procDir = mOrientation == XmVERTICAL? XmMAX_ON_BOTTOM:XmMAX_ON_RIGHT;
|
||||
|
||||
mWidget = ::XtVaCreateManagedWidget("scrollbar",
|
||||
xmScrollBarWidgetClass,
|
||||
parentWidget,
|
||||
XmNorientation, mOrientation,
|
||||
XmNprocessingDirection, procDir,
|
||||
XmNwidth, aRect.width,
|
||||
XmNheight, aRect.height,
|
||||
XmNrecomputeSize, False,
|
||||
XmNhighlightOnEnter, False,
|
||||
XmNminimum, 0,
|
||||
XmNmaximum, 100,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
nsnull);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
//InitCallbacks();
|
||||
XtAddCallback(mWidget,
|
||||
XmNdragCallback,
|
||||
nsXtWidget_Scrollbar_Callback,
|
||||
this);
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNdecrementCallback,
|
||||
nsXtWidget_Scrollbar_Callback,
|
||||
this);
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNincrementCallback,
|
||||
nsXtWidget_Scrollbar_Callback,
|
||||
this);
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNvalueChangedCallback,
|
||||
nsXtWidget_Scrollbar_Callback,
|
||||
this);
|
||||
|
||||
/*XtAddCallback(mWidget,
|
||||
XmNresizeCallback,
|
||||
nsXtWidget_Resize_Callback,
|
||||
this);*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
void nsScrollbar::Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
Widget parentWidget;
|
||||
|
||||
if (aParent) {
|
||||
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
} else {
|
||||
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
|
||||
}
|
||||
|
||||
Create((nsNativeWidget)parentWidget, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData);
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsScrollbar destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsScrollbar::~nsScrollbar()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsScrollbar::QueryObject(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kInsScrollbarIID, NS_ISCROLLBAR_IID);
|
||||
|
||||
if (aIID.Equals(kInsScrollbarIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Define the range settings
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsScrollbar::SetMaxRange(PRUint32 aEndRange)
|
||||
{
|
||||
int max = aEndRange;
|
||||
XtVaGetValues(mWidget, XmNmaximum, &max, nsnull);
|
||||
if (DBG) printf("SetMaxRange %d\n", max);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Return the range settings
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsScrollbar::GetMaxRange()
|
||||
{
|
||||
int maxRange = 0;
|
||||
XtVaGetValues(mWidget, XmNmaximum, &maxRange, nsnull);
|
||||
return (PRUint32)maxRange;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set the thumb position
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsScrollbar::SetPosition(PRUint32 aPos)
|
||||
{
|
||||
int pos = (int)aPos;
|
||||
if (DBG) printf("SetPosition %d\n", pos);
|
||||
XtVaSetValues(mWidget, XmNvalue, pos, nsnull);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get the current thumb position.
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsScrollbar::GetPosition()
|
||||
{
|
||||
int pagePos = 0;
|
||||
XtVaGetValues(mWidget, XmNvalue, &pagePos, nsnull);
|
||||
|
||||
return (PRUint32)pagePos;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set the thumb size
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsScrollbar::SetThumbSize(PRUint32 aSize)
|
||||
{
|
||||
if (aSize > 0) {
|
||||
XtVaSetValues(mWidget, XmNpageIncrement, (int)aSize, nsnull);
|
||||
XtVaSetValues(mWidget, XmNsliderSize, (int)aSize, nsnull);
|
||||
}
|
||||
if (DBG) printf("SetThumbSize %d\n", aSize);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get the thumb size
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsScrollbar::GetThumbSize()
|
||||
{
|
||||
int pageSize = 0;
|
||||
XtVaGetValues(mWidget, XmNpageIncrement, &pageSize, nsnull);
|
||||
|
||||
return (PRUint32)pageSize;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set the line increment for this scrollbar
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsScrollbar::SetLineIncrement(PRUint32 aLineIncrement)
|
||||
{
|
||||
if (aLineIncrement > 0) {
|
||||
mLineIncrement = aLineIncrement;
|
||||
XtVaSetValues(mWidget, XmNincrement, aLineIncrement, nsnull);
|
||||
}
|
||||
|
||||
if (DBG) printf("SetLineIncrement %d\n", aLineIncrement);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get the line increment for this scrollbar
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsScrollbar::GetLineIncrement()
|
||||
{
|
||||
return mLineIncrement;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set all scrolling parameters
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
|
||||
PRUint32 aPosition, PRUint32 aLineIncrement)
|
||||
{
|
||||
|
||||
int thumbSize = (((int)aThumbSize) > 0?aThumbSize:1);
|
||||
int maxRange = (((int)aMaxRange) > 0?aMaxRange:10);
|
||||
mLineIncrement = (((int)aLineIncrement) > 0?aLineIncrement:1);
|
||||
|
||||
int maxPos = maxRange - thumbSize;
|
||||
int pos = ((int)aPosition) > maxPos ? maxPos-1 : ((int)aPosition);
|
||||
|
||||
if (DBG) printf("SetParameters Max: %6d Thumb: %4d Pos: %4d Line: %4d \n",
|
||||
maxRange, thumbSize,
|
||||
pos, mLineIncrement);
|
||||
|
||||
XtVaSetValues(mWidget,
|
||||
XmNincrement, mLineIncrement,
|
||||
XmNminimum, 0,
|
||||
XmNmaximum, maxRange,
|
||||
XmNsliderSize, thumbSize,
|
||||
XmNpageIncrement, thumbSize,
|
||||
XmNvalue, pos,
|
||||
nsnull);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint message. Don't send the paint out
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsScrollbar::OnPaint(nsPaintEvent & aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
PRBool nsScrollbar::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
|
||||
if (DBG) printf("*&*&*&*&*&*&*()()()()(((( nsScrollbar::OnResize\n");
|
||||
return nsWindow::OnResize(aEvent);
|
||||
//return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
int nsScrollbar::AdjustScrollBarPosition(int aPosition)
|
||||
{
|
||||
int maxRange;
|
||||
int sliderSize;
|
||||
|
||||
XtVaGetValues(mWidget, XmNmaximum, &maxRange,
|
||||
XmNsliderSize, &sliderSize,
|
||||
nsnull);
|
||||
int cap = maxRange - sliderSize;
|
||||
return aPosition > cap ? cap : aPosition;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deal with scrollbar messages (actually implemented only in nsScrollbar)
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
|
||||
{
|
||||
PRBool result = PR_TRUE;
|
||||
int newPosition;
|
||||
|
||||
switch (aEvent.message) {
|
||||
|
||||
// scroll one line right or down
|
||||
case NS_SCROLLBAR_LINE_NEXT:
|
||||
{
|
||||
XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull);
|
||||
newPosition += mLineIncrement;
|
||||
PRUint32 max = GetMaxRange() - GetThumbSize();
|
||||
if (newPosition > (int)max)
|
||||
newPosition = (int)max;
|
||||
|
||||
// if an event callback is registered, give it the chance
|
||||
// to change the increment
|
||||
if (mEventCallback) {
|
||||
aEvent.position = newPosition;
|
||||
result = ConvertStatus((*mEventCallback)(&aEvent));
|
||||
newPosition = aEvent.position;
|
||||
}
|
||||
|
||||
XtVaSetValues(mWidget, XmNvalue,
|
||||
AdjustScrollBarPosition(newPosition), nsnull);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// scroll one line left or up
|
||||
case NS_SCROLLBAR_LINE_PREV:
|
||||
{
|
||||
XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull);
|
||||
|
||||
newPosition -= mLineIncrement;
|
||||
if (newPosition < 0)
|
||||
newPosition = 0;
|
||||
|
||||
// if an event callback is registered, give it the chance
|
||||
// to change the decrement
|
||||
if (mEventCallback) {
|
||||
aEvent.position = newPosition;
|
||||
|
||||
result = ConvertStatus((*mEventCallback)(&aEvent));
|
||||
newPosition = aEvent.position;
|
||||
}
|
||||
|
||||
XtVaSetValues(mWidget, XmNvalue, newPosition, nsnull);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Scrolls one page right or down
|
||||
case NS_SCROLLBAR_PAGE_NEXT:
|
||||
{
|
||||
XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull);
|
||||
PRUint32 max = GetMaxRange() - GetThumbSize();
|
||||
if (newPosition > (int)max)
|
||||
newPosition = (int)max;
|
||||
|
||||
// if an event callback is registered, give it the chance
|
||||
// to change the increment
|
||||
if (mEventCallback) {
|
||||
aEvent.position = newPosition;
|
||||
result = ConvertStatus((*mEventCallback)(&aEvent));
|
||||
newPosition = aEvent.position;
|
||||
}
|
||||
XtVaSetValues(mWidget, XmNvalue,
|
||||
AdjustScrollBarPosition(newPosition+10), nsnull);
|
||||
break;
|
||||
}
|
||||
|
||||
// Scrolls one page left or up.
|
||||
case NS_SCROLLBAR_PAGE_PREV:
|
||||
{
|
||||
XtVaGetValues(mWidget, XmNvalue, &newPosition, nsnull);
|
||||
if (newPosition < 0)
|
||||
newPosition = 0;
|
||||
|
||||
// if an event callback is registered, give it the chance
|
||||
// to change the increment
|
||||
if (mEventCallback) {
|
||||
aEvent.position = newPosition;
|
||||
result = ConvertStatus((*mEventCallback)(&aEvent));
|
||||
newPosition = aEvent.position;
|
||||
}
|
||||
|
||||
XtVaSetValues(mWidget, XmNvalue, newPosition-10, nsnull);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Scrolls to the absolute position. The current position is specified by
|
||||
// the cPos parameter.
|
||||
case NS_SCROLLBAR_POS:
|
||||
{
|
||||
newPosition = cPos;
|
||||
|
||||
// if an event callback is registered, give it the chance
|
||||
// to change the increment
|
||||
if (mEventCallback) {
|
||||
aEvent.position = newPosition;
|
||||
result = ConvertStatus((*mEventCallback)(&aEvent));
|
||||
newPosition = aEvent.position;
|
||||
}
|
||||
|
||||
XtVaSetValues(mWidget, XmNvalue,
|
||||
AdjustScrollBarPosition(newPosition), nsnull);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
#define GET_OUTER() ((nsScrollbar*) ((char*)this - nsScrollbar::GetOuterOffset()))
|
||||
|
||||
// nsIScrollbar part
|
||||
void nsScrollbar::AggScrollbar::SetMaxRange(PRUint32 aEndRange)
|
||||
{
|
||||
GET_OUTER()->SetMaxRange(aEndRange);
|
||||
}
|
||||
|
||||
PRUint32 nsScrollbar::AggScrollbar::GetMaxRange()
|
||||
{
|
||||
return GET_OUTER()->GetMaxRange();
|
||||
}
|
||||
|
||||
void nsScrollbar::AggScrollbar::SetPosition(PRUint32 aPos)
|
||||
{
|
||||
GET_OUTER()->SetPosition(aPos);
|
||||
}
|
||||
|
||||
PRUint32 nsScrollbar::AggScrollbar::GetPosition()
|
||||
{
|
||||
return GET_OUTER()->GetPosition();
|
||||
}
|
||||
|
||||
void nsScrollbar::AggScrollbar::SetThumbSize(PRUint32 aSize)
|
||||
{
|
||||
GET_OUTER()->SetThumbSize(aSize);
|
||||
}
|
||||
|
||||
PRUint32 nsScrollbar::AggScrollbar::GetThumbSize()
|
||||
{
|
||||
return GET_OUTER()->GetThumbSize();
|
||||
}
|
||||
|
||||
void nsScrollbar::AggScrollbar::SetLineIncrement(PRUint32 aSize)
|
||||
{
|
||||
GET_OUTER()->SetLineIncrement(aSize);
|
||||
}
|
||||
|
||||
PRUint32 nsScrollbar::AggScrollbar::GetLineIncrement()
|
||||
{
|
||||
return GET_OUTER()->GetLineIncrement();
|
||||
}
|
||||
|
||||
void nsScrollbar::AggScrollbar::SetParameters(PRUint32 aMaxRange,
|
||||
PRUint32 aThumbSize,
|
||||
PRUint32 aPosition,
|
||||
PRUint32 aLineIncrement)
|
||||
{
|
||||
GET_OUTER()->SetParameters(aMaxRange, aThumbSize, aPosition, aLineIncrement);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsScrollbar, AggScrollbar);
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsScrollbar_h__
|
||||
#define nsScrollbar_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
|
||||
#include "nsIScrollbar.h"
|
||||
|
||||
/**
|
||||
* Native Motif scrollbar wrapper.
|
||||
*/
|
||||
|
||||
class nsScrollbar : public nsWindow
|
||||
{
|
||||
|
||||
public:
|
||||
nsScrollbar(nsISupports *aOuter, PRBool aIsVertical);
|
||||
virtual ~nsScrollbar();
|
||||
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
|
||||
// nsIScrollbar part
|
||||
virtual void SetMaxRange(PRUint32 aEndRange);
|
||||
virtual PRUint32 GetMaxRange();
|
||||
virtual void SetPosition(PRUint32 aPos);
|
||||
virtual PRUint32 GetPosition();
|
||||
virtual void SetThumbSize(PRUint32 aSize);
|
||||
virtual PRUint32 GetThumbSize();
|
||||
virtual void SetLineIncrement(PRUint32 aSize);
|
||||
virtual PRUint32 GetLineIncrement();
|
||||
virtual void SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
|
||||
PRUint32 aPosition, PRUint32 aLineIncrement);
|
||||
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
private:
|
||||
|
||||
PRUint32 mLineIncrement;
|
||||
int mOrientation;
|
||||
|
||||
int AdjustScrollBarPosition(int aPosition);
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsScrollbar,mAggWidget);
|
||||
}
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIButton interface to nsButton w/o using multiple
|
||||
// inheritance.
|
||||
class AggScrollbar : public nsIScrollbar {
|
||||
public:
|
||||
AggScrollbar();
|
||||
virtual ~AggScrollbar();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
// nsIScrollbar part
|
||||
virtual void SetMaxRange(PRUint32 aEndRange);
|
||||
virtual PRUint32 GetMaxRange();
|
||||
virtual void SetPosition(PRUint32 aPos);
|
||||
virtual PRUint32 GetPosition();
|
||||
virtual void SetThumbSize(PRUint32 aSize);
|
||||
virtual PRUint32 GetThumbSize();
|
||||
virtual void SetLineIncrement(PRUint32 aSize);
|
||||
virtual PRUint32 GetLineIncrement();
|
||||
virtual void SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
|
||||
PRUint32 aPosition, PRUint32 aLineIncrement);
|
||||
};
|
||||
AggScrollbar mAggWidget;
|
||||
friend class AggScrollbar;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // nsScrollbar_
|
|
@ -0,0 +1,324 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsTextAreaWidget.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXtEventHandler.h"
|
||||
|
||||
#include <Xm/Text.h>
|
||||
|
||||
#define DBG 0
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsTextAreaWidget constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextAreaWidget::nsTextAreaWidget(nsISupports *aOuter) : nsWindow(aOuter),
|
||||
mMakeReadOnly(PR_FALSE)
|
||||
{
|
||||
//mBackground = NS_RGB(124, 124, 124);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsTextAreaWidget destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextAreaWidget::~nsTextAreaWidget()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void 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", 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", 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);
|
||||
mHelper = new nsTextHelper(mWidget);
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
InitCallbacks("nsTextAreaWidget");
|
||||
|
||||
if (mMakeReadOnly) {
|
||||
SetReadOnly(PR_TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextAreaWidget::Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsTextAreaWidget::QueryObject(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
|
||||
|
||||
if (aIID.Equals(kITextWidgetIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITextAreaWidgetIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::OnPaint(nsPaintEvent & aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
if (mWidget == nsnull && aReadOnlyFlag) {
|
||||
mMakeReadOnly = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return mHelper->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
mHelper->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return mHelper->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return mHelper->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return mHelper->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::RemoveText()
|
||||
{
|
||||
mHelper->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SelectAll()
|
||||
{
|
||||
mHelper->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
mHelper->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
mHelper->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
mHelper->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::GetCaretPosition()
|
||||
{
|
||||
return mHelper->GetCaretPosition();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::AutoErase()
|
||||
{
|
||||
return mHelper->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
#define GET_OUTER() ((nsTextAreaWidget*) ((char*)this - nsTextAreaWidget::GetOuterOffset()))
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
GET_OUTER()->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return GET_OUTER()->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return GET_OUTER()->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return GET_OUTER()->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::RemoveText()
|
||||
{
|
||||
GET_OUTER()->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
GET_OUTER()->SetPassword(aIsPassword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::AggTextAreaWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
return GET_OUTER()->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SelectAll()
|
||||
{
|
||||
GET_OUTER()->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
GET_OUTER()->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
GET_OUTER()->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
GET_OUTER()->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::GetCaretPosition()
|
||||
{
|
||||
return GET_OUTER()->GetCaretPosition();
|
||||
}
|
||||
|
||||
PRBool nsTextAreaWidget::AggTextAreaWidget::AutoErase()
|
||||
{
|
||||
return GET_OUTER()->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsTextAreaWidget, AggTextAreaWidget);
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsTextAreaWidget_h__
|
||||
#define nsTextAreaWidget_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsTextHelper.h"
|
||||
|
||||
#include "nsITextAreaWidget.h"
|
||||
|
||||
/**
|
||||
* Native Motif single line edit control wrapper.
|
||||
*/
|
||||
|
||||
class nsTextAreaWidget : public nsWindow
|
||||
{
|
||||
|
||||
public:
|
||||
nsTextAreaWidget(nsISupports *aOuter);
|
||||
virtual ~nsTextAreaWidget();
|
||||
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
// nsTextHelper Interface
|
||||
virtual void SelectAll();
|
||||
virtual void SetMaxTextLength(PRUint32 aChars);
|
||||
virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize);
|
||||
virtual PRUint32 SetText(const nsString& aText);
|
||||
virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos);
|
||||
virtual void RemoveText();
|
||||
virtual void SetPassword(PRBool aIsPassword);
|
||||
virtual PRBool SetReadOnly(PRBool aReadOnlyFlag);
|
||||
virtual void SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||
virtual void GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||
virtual void SetCaretPosition(PRUint32 aPosition);
|
||||
virtual PRUint32 GetCaretPosition();
|
||||
virtual PRBool AutoErase();
|
||||
|
||||
protected:
|
||||
nsTextHelper *mHelper;
|
||||
|
||||
private:
|
||||
PRBool mMakeReadOnly;
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsTextAreaWidget,mAggWidget);
|
||||
}
|
||||
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIText interface to nsText w/o using multiple
|
||||
// inheritance.
|
||||
class AggTextAreaWidget : public nsITextAreaWidget {
|
||||
public:
|
||||
AggTextAreaWidget();
|
||||
virtual ~AggTextAreaWidget();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
virtual void SelectAll();
|
||||
virtual void SetMaxTextLength(PRUint32 aChars);
|
||||
virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize);
|
||||
virtual PRUint32 SetText(const nsString& aText);
|
||||
virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos);
|
||||
virtual void RemoveText();
|
||||
virtual void SetPassword(PRBool aIsPassword);
|
||||
virtual PRBool SetReadOnly(PRBool aReadOnlyFlag);
|
||||
virtual void SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||
virtual void GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||
virtual void SetCaretPosition(PRUint32 aPosition);
|
||||
virtual PRUint32 GetCaretPosition();
|
||||
virtual PRBool AutoErase();
|
||||
|
||||
};
|
||||
AggTextAreaWidget mAggWidget;
|
||||
friend class AggTextAreaWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsTextAreaWidget_h__
|
|
@ -0,0 +1,208 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsTextHelper.h"
|
||||
#include "nsTextWidget.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include <Xm/Text.h>
|
||||
|
||||
#define DBG 0
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsTextHelper constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
nsTextHelper::nsTextHelper(Widget aWidget)
|
||||
{
|
||||
mWidget = aWidget;
|
||||
mIsReadOnly = PR_FALSE;
|
||||
mIsPassword = PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsTextHelper destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextHelper::~nsTextHelper()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
XmTextSetMaxLength(mWidget, (int)aChars);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize)
|
||||
{
|
||||
if (!mIsPassword) {
|
||||
char * str = XmTextGetString(mWidget);
|
||||
aTextBuffer.SetLength(0);
|
||||
aTextBuffer.Append(str);
|
||||
PRUint32 len = (PRUint32)strlen(str);
|
||||
XtFree(str);
|
||||
return len;
|
||||
} else {
|
||||
PasswordData * data;
|
||||
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
|
||||
aTextBuffer = data->mPassword;
|
||||
return aTextBuffer.Length();
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::SetText(const nsString& aText)
|
||||
{
|
||||
//printf("SetText Password %d\n", mIsPassword);
|
||||
if (!mIsPassword) {
|
||||
NS_ALLOC_STR_BUF(buf, aText, 512);
|
||||
XmTextSetString(mWidget, buf);
|
||||
NS_FREE_STR_BUF(buf);
|
||||
} else {
|
||||
PasswordData * data;
|
||||
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
|
||||
data->mPassword = aText;
|
||||
data->mIgnore = True;
|
||||
char * buf = new char[aText.Length()+1];
|
||||
memset(buf, '*', aText.Length());
|
||||
buf[aText.Length()] = 0;
|
||||
//printf("SetText [%s] [%s]\n", data->mPassword.ToNewCString(), buf);
|
||||
XmTextSetString(mWidget, buf);
|
||||
data->mIgnore = False;
|
||||
}
|
||||
return(aText.Length());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
|
||||
if (!mIsPassword) {
|
||||
NS_ALLOC_STR_BUF(buf, aText, 512);
|
||||
XmTextInsert(mWidget, aStartPos, buf);
|
||||
NS_FREE_STR_BUF(buf);
|
||||
} else {
|
||||
PasswordData * data;
|
||||
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
|
||||
data->mIgnore = True;
|
||||
nsString newText(aText);
|
||||
data->mPassword.Insert(newText, aStartPos, aText.Length());
|
||||
char * buf = new char[data->mPassword.Length()+1];
|
||||
memset(buf, '*', data->mPassword.Length());
|
||||
buf[data->mPassword.Length()] = 0;
|
||||
//printf("SetText [%s] [%s]\n", data->mPassword.ToNewCString(), buf);
|
||||
XmTextInsert(mWidget, aStartPos, buf);
|
||||
data->mIgnore = False;
|
||||
}
|
||||
return(aText.Length());
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::RemoveText()
|
||||
{
|
||||
char blank[2];
|
||||
blank[0] = 0;
|
||||
|
||||
XmTextSetString(mWidget, blank);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
mIsPassword = aIsPassword;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
NS_ASSERTION(mWidget != nsnull,
|
||||
"SetReadOnly - Widget is NULL, Create may not have been called!");
|
||||
PRBool oldSetting = mIsReadOnly;
|
||||
mIsReadOnly = aReadOnlyFlag;
|
||||
XmTextSetEditable(mWidget, aReadOnlyFlag?False:True);
|
||||
|
||||
return(oldSetting);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SelectAll()
|
||||
{
|
||||
nsString text;
|
||||
PRUint32 numChars = GetText(text, 0);
|
||||
SetSelection(0, numChars);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
XmTextPosition left = (XmTextPosition)aStartSel;
|
||||
XmTextPosition right = (XmTextPosition)aEndSel;
|
||||
|
||||
Time time;
|
||||
printf("SetSel %d %d\n", left, right);
|
||||
XmTextSetSelection(mWidget, left, right, 0);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
XmTextPosition left;
|
||||
XmTextPosition right;
|
||||
|
||||
if (XmTextGetSelectionPosition(mWidget, &left, &right)) {
|
||||
printf("left %d right %d\n", left, right);
|
||||
*aStartSel = (PRUint32)left;
|
||||
*aEndSel = (PRUint32)right;
|
||||
} else {
|
||||
printf("nsTextHelper::GetSelection Error getting positions\n");
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
XmTextSetInsertionPosition(mWidget, (XmTextPosition)aPosition);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::GetCaretPosition()
|
||||
{
|
||||
return (PRUint32)XmTextGetInsertionPosition(mWidget);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsTextHelper::AutoErase()
|
||||
{
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsTextHelper_h__
|
||||
#define nsTextHelper_h__
|
||||
|
||||
#include "nsITextWidget.h"
|
||||
#include "nsWindow.h"
|
||||
#include <Xm/Xm.h>
|
||||
|
||||
/**
|
||||
* Base class for nsTextAreaWidget and nsTextWidget
|
||||
*/
|
||||
|
||||
class nsTextHelper
|
||||
{
|
||||
|
||||
public:
|
||||
nsTextHelper(Widget aWidget);
|
||||
virtual ~nsTextHelper();
|
||||
|
||||
virtual void SelectAll();
|
||||
virtual void SetMaxTextLength(PRUint32 aChars);
|
||||
virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize);
|
||||
virtual PRUint32 SetText(const nsString& aText);
|
||||
virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos);
|
||||
virtual void RemoveText();
|
||||
virtual void SetPassword(PRBool aIsPassword);
|
||||
virtual PRBool SetReadOnly(PRBool aReadOnlyFlag);
|
||||
virtual void SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||
virtual void GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||
virtual void SetCaretPosition(PRUint32 aPosition);
|
||||
virtual PRUint32 GetCaretPosition();
|
||||
//virtual void PreCreateWidget(nsWidgetInitData *aInitData);
|
||||
virtual PRBool AutoErase();
|
||||
|
||||
protected:
|
||||
Widget mWidget;
|
||||
PRBool mIsPassword;
|
||||
PRBool mIsReadOnly;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsTextHelper_h__
|
|
@ -0,0 +1,360 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsTextWidget.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXtEventHandler.h"
|
||||
|
||||
#include <Xm/Text.h>
|
||||
|
||||
#define DBG 0
|
||||
|
||||
extern int mIsPasswordCallBacksInstalled;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsTextWidget constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextWidget::nsTextWidget(nsISupports *aOuter) : nsWindow(aOuter),
|
||||
mIsPasswordCallBacksInstalled(PR_FALSE),
|
||||
mMakeReadOnly(PR_FALSE),
|
||||
mMakePassword(PR_FALSE)
|
||||
{
|
||||
//mBackground = NS_RGB(124, 124, 124);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsTextWidget destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextWidget::~nsTextWidget()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextWidget::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", 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", parentWidget);
|
||||
|
||||
mWidget = ::XtVaCreateManagedWidget("button",
|
||||
xmTextWidgetClass,
|
||||
parentWidget,
|
||||
XmNwidth, aRect.width,
|
||||
XmNheight, aRect.height,
|
||||
XmNrecomputeSize, False,
|
||||
XmNhighlightOnEnter, False,
|
||||
XmNeditable, mMakeReadOnly?False:True,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
nsnull);
|
||||
mHelper = new nsTextHelper(mWidget);
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
InitCallbacks("nsTextWidget");
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNfocusCallback,
|
||||
nsXtWidget_Focus_Callback,
|
||||
this);
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNlosingFocusCallback,
|
||||
nsXtWidget_Focus_Callback,
|
||||
this);
|
||||
|
||||
if (mMakeReadOnly) {
|
||||
SetReadOnly(PR_TRUE);
|
||||
}
|
||||
if (mMakePassword) {
|
||||
SetPassword(PR_TRUE);
|
||||
PasswordData * data = new PasswordData();
|
||||
data->mPassword = "";
|
||||
XtVaSetValues(mWidget, XmNuserData, data, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextWidget::Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsTextWidget::QueryObject(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||
|
||||
if (aIID.Equals(kITextWidgetIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsTextWidget::OnPaint(nsPaintEvent & aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
if (mWidget == nsnull && aIsPassword) {
|
||||
mMakePassword = PR_TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (aIsPassword) {
|
||||
if (!mIsPasswordCallBacksInstalled) {
|
||||
XtAddCallback(mWidget, XmNmodifyVerifyCallback, nsXtWidget_Text_Callback, NULL);
|
||||
XtAddCallback(mWidget, XmNactivateCallback, nsXtWidget_Text_Callback, NULL);
|
||||
mIsPasswordCallBacksInstalled = PR_TRUE;
|
||||
}
|
||||
} else {
|
||||
if (mIsPasswordCallBacksInstalled) {
|
||||
XtRemoveCallback(mWidget, XmNmodifyVerifyCallback, nsXtWidget_Text_Callback, NULL);
|
||||
XtRemoveCallback(mWidget, XmNactivateCallback, nsXtWidget_Text_Callback, NULL);
|
||||
mIsPasswordCallBacksInstalled = PR_FALSE;
|
||||
}
|
||||
}
|
||||
mHelper->SetPassword(aIsPassword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
if (mWidget == nsnull && aReadOnlyFlag) {
|
||||
mMakeReadOnly = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return mHelper->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
mHelper->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return mHelper->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return mHelper->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return mHelper->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::RemoveText()
|
||||
{
|
||||
mHelper->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SelectAll()
|
||||
{
|
||||
mHelper->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
mHelper->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
mHelper->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
mHelper->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::GetCaretPosition()
|
||||
{
|
||||
return mHelper->GetCaretPosition();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::AutoErase()
|
||||
{
|
||||
return mHelper->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
#define GET_OUTER() ((nsTextWidget*) ((char*)this - nsTextWidget::GetOuterOffset()))
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
GET_OUTER()->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return GET_OUTER()->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return GET_OUTER()->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return GET_OUTER()->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::RemoveText()
|
||||
{
|
||||
GET_OUTER()->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
GET_OUTER()->SetPassword(aIsPassword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::AggTextWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
return GET_OUTER()->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SelectAll()
|
||||
{
|
||||
GET_OUTER()->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
GET_OUTER()->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
GET_OUTER()->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
GET_OUTER()->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::GetCaretPosition()
|
||||
{
|
||||
return GET_OUTER()->GetCaretPosition();
|
||||
}
|
||||
|
||||
PRBool nsTextWidget::AggTextWidget::AutoErase()
|
||||
{
|
||||
return GET_OUTER()->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsTextWidget, AggTextWidget);
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsTextWidget_h__
|
||||
#define nsTextWidget_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsTextHelper.h"
|
||||
|
||||
#include "nsITextWidget.h"
|
||||
|
||||
typedef struct _PasswordData {
|
||||
nsString mPassword;
|
||||
Boolean mIgnore;
|
||||
} PasswordData;
|
||||
|
||||
/**
|
||||
* Native Motif single line edit control wrapper.
|
||||
*/
|
||||
|
||||
class nsTextWidget : public nsWindow
|
||||
{
|
||||
|
||||
public:
|
||||
nsTextWidget(nsISupports *aOuter);
|
||||
virtual ~nsTextWidget();
|
||||
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
// nsTextHelper Interface
|
||||
virtual void SelectAll();
|
||||
virtual void SetMaxTextLength(PRUint32 aChars);
|
||||
virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize);
|
||||
virtual PRUint32 SetText(const nsString& aText);
|
||||
virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos);
|
||||
virtual void RemoveText();
|
||||
virtual void SetPassword(PRBool aIsPassword);
|
||||
virtual PRBool SetReadOnly(PRBool aReadOnlyFlag);
|
||||
virtual void SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||
virtual void GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||
virtual void SetCaretPosition(PRUint32 aPosition);
|
||||
virtual PRUint32 GetCaretPosition();
|
||||
virtual PRBool AutoErase();
|
||||
|
||||
protected:
|
||||
PRBool mIsPasswordCallBacksInstalled;
|
||||
nsTextHelper *mHelper;
|
||||
|
||||
private:
|
||||
PRBool mMakeReadOnly;
|
||||
PRBool mMakePassword;
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsTextWidget,mAggWidget);
|
||||
}
|
||||
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIText interface to nsText w/o using multiple
|
||||
// inheritance.
|
||||
class AggTextWidget : public nsITextWidget {
|
||||
public:
|
||||
AggTextWidget();
|
||||
virtual ~AggTextWidget();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
virtual void SelectAll();
|
||||
virtual void SetMaxTextLength(PRUint32 aChars);
|
||||
virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize);
|
||||
virtual PRUint32 SetText(const nsString& aText);
|
||||
virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos);
|
||||
virtual void RemoveText();
|
||||
virtual void SetPassword(PRBool aIsPassword);
|
||||
virtual PRBool SetReadOnly(PRBool aReadOnlyFlag);
|
||||
virtual void SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||
virtual void GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||
virtual void SetCaretPosition(PRUint32 aPosition);
|
||||
virtual PRUint32 GetCaretPosition();
|
||||
virtual PRBool AutoErase();
|
||||
|
||||
};
|
||||
AggTextWidget mAggWidget;
|
||||
friend class AggTextWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsTextWidget_h__
|
|
@ -0,0 +1,82 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsToolkit.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include <Fonts.h>
|
||||
#include <TextEdit.h>
|
||||
#include <Dialogs.h>
|
||||
#include <Traps.h>
|
||||
#include <Events.h>
|
||||
#include <Menus.h>
|
||||
|
||||
|
||||
PRBool nsToolkit::mInit = PR_FALSE;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsToolkit::nsToolkit()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
// once only, macintosh specific initialization
|
||||
if( mInit == PR_TRUE)
|
||||
{
|
||||
mInit = PR_TRUE;
|
||||
InitGraf;
|
||||
InitWindows();
|
||||
InitMenus();
|
||||
TEInit();
|
||||
InitDialogs(0);
|
||||
InitCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsToolkit::~nsToolkit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsISupports implementation macro
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_DEFINE_IID(kIToolkitIID, NS_ITOOLKIT_IID);
|
||||
NS_IMPL_ISUPPORTS(nsToolkit,kIToolkitIID);
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsToolkit::Init(PRThread *aThread)
|
||||
{
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef TOOLKIT_H
|
||||
#define TOOLKIT_H
|
||||
|
||||
#include "nsIToolkit.h"
|
||||
|
||||
struct MethodInfo;
|
||||
|
||||
/**
|
||||
* Wrapper around the thread running the message pump.
|
||||
* The toolkit abstraction is necessary because the message pump must
|
||||
* execute within the same thread that created the widget under Win32.
|
||||
*/
|
||||
|
||||
class nsToolkit : public nsIToolkit
|
||||
{
|
||||
|
||||
public:
|
||||
nsToolkit();
|
||||
virtual ~nsToolkit();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void Init(PRThread *aThread);
|
||||
|
||||
public:
|
||||
|
||||
private:
|
||||
static PRBool mInit;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // TOOLKIT_H
|
|
@ -0,0 +1,243 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIButton.h"
|
||||
#include "nsITextWidget.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
|
||||
#include "nsToolkit.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsAppShell.h"
|
||||
#include "nsButton.h"
|
||||
#include "nsScrollbar.h"
|
||||
#include "nsCheckButton.h"
|
||||
#include "nsRadioButton.h"
|
||||
#include "nsTextWidget.h"
|
||||
#include "nsTextAreaWidget.h"
|
||||
#include "nsFileWidget.h"
|
||||
#include "nsListBox.h"
|
||||
#include "nsComboBox.h"
|
||||
#include "nsLookAndFeel.h"
|
||||
|
||||
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
|
||||
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
|
||||
static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID);
|
||||
static NS_DEFINE_IID(kCHorzScrollbarCID, NS_HORZSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCVertScrollbarCID, NS_VERTSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCCheckButtonCID, NS_CHECKBUTTON_CID);
|
||||
static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID);
|
||||
static NS_DEFINE_IID(kCTextWidgetCID, NS_TEXTFIELD_CID);
|
||||
static NS_DEFINE_IID(kCTextAreaWidgetCID, NS_TEXTAREA_CID);
|
||||
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
|
||||
static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID);
|
||||
static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID);
|
||||
static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID);
|
||||
static NS_DEFINE_IID(kCLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIWidget, NS_IWIDGET_IID);
|
||||
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
||||
static NS_DEFINE_IID(kIButton, NS_IBUTTON_IID);
|
||||
static NS_DEFINE_IID(kICheckButton, NS_ICHECKBUTTON_IID);
|
||||
static NS_DEFINE_IID(kIScrollbar, NS_ISCROLLBAR_IID);
|
||||
static NS_DEFINE_IID(kIFileWidget, NS_IFILEWIDGET_IID);
|
||||
static NS_DEFINE_IID(kIListBox, NS_ILISTBOX_IID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
|
||||
class nsWidgetFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
nsWidgetFactory(const nsCID &aClass);
|
||||
~nsWidgetFactory();
|
||||
private:
|
||||
nsCID mClassID;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
nsWidgetFactory::nsWidgetFactory(const nsCID &aClass)
|
||||
{
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
nsWidgetFactory::~nsWidgetFactory()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsWidgetFactory::QueryInterface(const nsIID &aIID,
|
||||
void **aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kIFactoryIID)) {
|
||||
*aInstancePtr = (void*)(nsWidgetFactory*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsWidgetFactory*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsWidgetFactory)
|
||||
NS_IMPL_RELEASE(nsWidgetFactory)
|
||||
|
||||
nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
if (nsnull != aOuter && !aIID.Equals(kISupportsIID)) {
|
||||
// aggregation with IID != nsISupports
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
nsWindow *inst = nsnull;
|
||||
if (aIID.Equals(kCWindow)) {
|
||||
inst = new nsWindow(aOuter);
|
||||
}
|
||||
else if ( mClassID.Equals(kCCheckButtonCID)) {
|
||||
inst = new nsCheckButton(aOuter);
|
||||
}
|
||||
else if ( mClassID.Equals(kCButtonCID)) {
|
||||
inst = new nsButton(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCVertScrollbarCID)) {
|
||||
inst = new nsScrollbar(aOuter, PR_TRUE);
|
||||
}
|
||||
else if (mClassID.Equals(kCHorzScrollbarCID)) {
|
||||
inst = new nsScrollbar(aOuter, PR_FALSE);
|
||||
}
|
||||
else if (aIID.Equals(kIScrollbar)) {
|
||||
inst = nsnull;
|
||||
fprintf(stderr, "------ NOT CreatingkIScrollbar Scrollbar\n");
|
||||
}
|
||||
else if (mClassID.Equals(kCTextWidgetCID)) {
|
||||
inst = new nsTextWidget(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCTextAreaWidgetCID)) {
|
||||
inst = new nsTextAreaWidget(aOuter);
|
||||
}
|
||||
else if ( mClassID.Equals(kCRadioButtonCID)) {
|
||||
inst = new nsRadioButton(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCListBoxCID)) {
|
||||
inst = new nsListBox(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCComboBoxCID)) {
|
||||
inst = new nsComboBox(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCFileWidgetCID)) {
|
||||
inst = new nsFileWidget(aOuter);
|
||||
}
|
||||
else if (aIID.Equals(kIWidget)) {
|
||||
inst = new nsWindow(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCChild)) {
|
||||
inst = new ChildWindow(aOuter);
|
||||
}
|
||||
else if (mClassID.Equals(kCLookAndFeelCID)) {
|
||||
nsLookAndFeel *laf = new nsLookAndFeel(aOuter);
|
||||
if (laf == NULL) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult res = laf->QueryInterface(aIID, aResult);
|
||||
if (res != NS_OK) {
|
||||
delete laf;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
else if (mClassID.Equals(kCAppShellCID)) {
|
||||
nsAppShell *appInst = new nsAppShell();
|
||||
if (appInst == NULL) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult res = appInst->QueryInterface(aIID, aResult);
|
||||
if (res != NS_OK) {
|
||||
delete appInst;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
if (inst == NULL) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult res = inst->QueryObject(aIID, aResult);
|
||||
|
||||
if (res != NS_OK) {
|
||||
delete inst;
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(inst);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsWidgetFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" NS_WIDGET nsresult NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
|
||||
{
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aFactory = new nsWidgetFactory(aClass);
|
||||
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,554 @@
|
|||
/* -*- 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.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef Window_h__
|
||||
#define Window_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "nsToolkit.h"
|
||||
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIAppShell.h"
|
||||
|
||||
#include "nsIMouseListener.h"
|
||||
#include "nsIEventListener.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
||||
#define NSRGB_2_COLOREF(color) \
|
||||
RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
|
||||
|
||||
|
||||
/**
|
||||
* Native Motif window wrapper.
|
||||
*/
|
||||
|
||||
class nsWindow : public nsIWidget
|
||||
{
|
||||
|
||||
public:
|
||||
nsWindow(nsISupports *aOuter);
|
||||
virtual ~nsWindow();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
|
||||
nsrefcnt AddRefObject(void);
|
||||
nsrefcnt ReleaseObject(void);
|
||||
|
||||
// nsIWidget interface
|
||||
virtual void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
virtual void Create(nsNativeWidget aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
virtual void Destroy();
|
||||
virtual nsIWidget* GetParent(void);
|
||||
virtual nsIEnumerator* GetChildren();
|
||||
virtual void AddChild(nsIWidget* aChild);
|
||||
virtual void RemoveChild(nsIWidget* aChild);
|
||||
virtual void Show(PRBool bState);
|
||||
virtual void Move(PRUint32 aX, PRUint32 aY);
|
||||
virtual void Resize(PRUint32 aWidth,
|
||||
PRUint32 aHeight, PRBool aRepaint);
|
||||
virtual void Resize(PRUint32 aX,
|
||||
PRUint32 aY,
|
||||
PRUint32 aWidth,
|
||||
PRUint32 aHeight, PRBool aRepaint);
|
||||
virtual void Enable(PRBool bState);
|
||||
virtual void SetFocus(void);
|
||||
virtual void GetBounds(nsRect &aRect);
|
||||
virtual void SetBounds(const nsRect &aRect);
|
||||
virtual nscolor GetForegroundColor(void);
|
||||
virtual void SetForegroundColor(const nscolor &aColor);
|
||||
virtual nscolor GetBackgroundColor(void);
|
||||
virtual void SetBackgroundColor(const nscolor &aColor);
|
||||
virtual nsIFontMetrics* GetFont(void);
|
||||
virtual void SetFont(const nsFont &aFont);
|
||||
virtual nsCursor GetCursor();
|
||||
virtual void SetCursor(nsCursor aCursor);
|
||||
virtual void Invalidate(PRBool aIsSynchronous);
|
||||
virtual void* GetNativeData(PRUint32 aDataType);
|
||||
virtual nsIRenderingContext* GetRenderingContext();
|
||||
virtual void SetColorMap(nsColorMap *aColorMap);
|
||||
virtual nsIDeviceContext* GetDeviceContext();
|
||||
virtual nsIAppShell* GetAppShell();
|
||||
virtual void Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
|
||||
virtual nsIToolkit* GetToolkit();
|
||||
virtual void SetBorderStyle(nsBorderStyle aBorderStyle);
|
||||
virtual void SetTitle(const nsString& aTitle);
|
||||
virtual void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
|
||||
|
||||
virtual void RemoveTooltips();
|
||||
virtual void UpdateTooltips(nsRect* aNewTips[]);
|
||||
virtual void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
|
||||
virtual void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
|
||||
virtual void AddMouseListener(nsIMouseListener * aListener);
|
||||
virtual void AddEventListener(nsIEventListener * aListener);
|
||||
virtual void BeginResizingChildren(void);
|
||||
virtual void EndResizingChildren(void);
|
||||
|
||||
static PRBool ConvertStatus(nsEventStatus aStatus);
|
||||
virtual PRBool DispatchEvent(nsGUIEvent* event);
|
||||
virtual PRBool DispatchMouseEvent(nsMouseEvent aEvent);
|
||||
|
||||
virtual void OnDestroy();
|
||||
virtual PRBool OnPaint(nsPaintEvent &event);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
virtual PRBool OnKey(PRUint32 aEventType, PRUint32 aKeyCode, nsKeyEvent* aEvent);
|
||||
|
||||
virtual PRBool DispatchFocus(nsGUIEvent &aEvent);
|
||||
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
|
||||
|
||||
virtual void SetIgnoreResize(PRBool aIgnore);
|
||||
virtual PRBool IgnoreResize();
|
||||
|
||||
virtual PRUint32 GetYCoord(PRUint32 aNewY);
|
||||
|
||||
// Resize event management
|
||||
void SetResizeRect(nsRect& aRect);
|
||||
void SetResized(PRBool aResized);
|
||||
void GetResizeRect(nsRect* aRect);
|
||||
PRBool GetResized();
|
||||
|
||||
char gInstanceClassName[256];
|
||||
protected:
|
||||
|
||||
void CreateGC();
|
||||
void CreateWindow(nsNativeWidget aNativeParent, nsIWidget *aWidgetParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData);
|
||||
|
||||
void CreateMainWindow(nsNativeWidget aNativeParent, nsIWidget *aWidgetParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData);
|
||||
|
||||
void CreateChildWindow(nsNativeWidget aNativeParent, nsIWidget *aWidgetParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData);
|
||||
|
||||
|
||||
void InitToolkit(nsIToolkit *aToolkit, nsIWidget * aWidgetParent);
|
||||
|
||||
|
||||
virtual void UpdateVisibilityFlag();
|
||||
virtual void UpdateDisplay();
|
||||
|
||||
//Widget mWidget;
|
||||
EVENT_CALLBACK mEventCallback;
|
||||
nsIDeviceContext *mContext;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
nsToolkit *mToolkit;
|
||||
nsIAppShell *mAppShell;
|
||||
|
||||
nsIMouseListener * mMouseListener;
|
||||
nsIEventListener * mEventListener;
|
||||
|
||||
nscolor mBackground;
|
||||
nscolor mForeground;
|
||||
nsCursor mCursor;
|
||||
nsBorderStyle mBorderStyle;
|
||||
nsRect mBounds;
|
||||
|
||||
PRBool mIgnoreResize;
|
||||
PRBool mShown;
|
||||
PRBool mVisible;
|
||||
PRBool mDisplayed;
|
||||
|
||||
// Resize event management
|
||||
nsRect mResizeRect;
|
||||
int mResized;
|
||||
PRBool mLowerLeft;
|
||||
|
||||
nsISupports* mOuter;
|
||||
|
||||
class InnerSupport : public nsISupports {
|
||||
public:
|
||||
InnerSupport() {}
|
||||
|
||||
#define INNER_OUTER \
|
||||
((nsWindow*)((char*)this - offsetof(nsWindow, mInner)))
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{ return INNER_OUTER->QueryObject(aIID, aInstancePtr); }
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void)
|
||||
{ return INNER_OUTER->AddRefObject(); }
|
||||
NS_IMETHOD_(nsrefcnt) Release(void)
|
||||
{ return INNER_OUTER->ReleaseObject(); }
|
||||
} mInner;
|
||||
friend InnerSupport;
|
||||
|
||||
private:
|
||||
//GC mGC;
|
||||
};
|
||||
|
||||
//
|
||||
// A child window is a window with different style
|
||||
//
|
||||
class ChildWindow : public nsWindow {
|
||||
|
||||
public:
|
||||
ChildWindow(nsISupports *aOuter) : nsWindow(aOuter) {}
|
||||
|
||||
};
|
||||
|
||||
#define AGGREGATE_METHOD_DEF \
|
||||
public: \
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
protected: \
|
||||
nsrefcnt mRefCnt; \
|
||||
public: \
|
||||
virtual void Create(nsIWidget *aParent, \
|
||||
const nsRect &aRect, \
|
||||
EVENT_CALLBACK aHandleEventFunction, \
|
||||
nsIDeviceContext *aContext, \
|
||||
nsIAppShell *aAppShell, \
|
||||
nsIToolkit *aToolkit = nsnull, \
|
||||
nsWidgetInitData *aInitData = nsnull); \
|
||||
virtual void Create(nsNativeWidget aParent, \
|
||||
const nsRect &aRect, \
|
||||
EVENT_CALLBACK aHandleEventFunction, \
|
||||
nsIDeviceContext *aContext, \
|
||||
nsIAppShell *aAppShell, \
|
||||
nsIToolkit *aToolkit = nsnull, \
|
||||
nsWidgetInitData *aInitData = nsnull); \
|
||||
virtual void Destroy(); \
|
||||
virtual nsIWidget* GetParent(void); \
|
||||
virtual nsIEnumerator* GetChildren(); \
|
||||
virtual void AddChild(nsIWidget* aChild); \
|
||||
virtual void RemoveChild(nsIWidget* aChild); \
|
||||
virtual void Show(PRBool bState); \
|
||||
virtual void Move(PRUint32 aX, PRUint32 aY); \
|
||||
virtual void Resize(PRUint32 aWidth, \
|
||||
PRUint32 aHeight, PRBool aRepaint); \
|
||||
virtual void Resize(PRUint32 aX, \
|
||||
PRUint32 aY, \
|
||||
PRUint32 aWidth, \
|
||||
PRUint32 aHeight, PRBool aRepaint); \
|
||||
virtual void Enable(PRBool bState); \
|
||||
virtual void SetFocus(void); \
|
||||
virtual void GetBounds(nsRect &aRect); \
|
||||
virtual void SetBounds(const nsRect &aRect); \
|
||||
virtual nscolor GetForegroundColor(void); \
|
||||
virtual void SetForegroundColor(const nscolor &aColor); \
|
||||
virtual nscolor GetBackgroundColor(void); \
|
||||
virtual void SetBackgroundColor(const nscolor &aColor); \
|
||||
virtual nsIFontMetrics* GetFont(void); \
|
||||
virtual void SetFont(const nsFont &aFont); \
|
||||
virtual nsCursor GetCursor(); \
|
||||
virtual void SetCursor(nsCursor aCursor); \
|
||||
virtual void Invalidate(PRBool aIsSynchronous); \
|
||||
virtual void* GetNativeData(PRUint32 aDataType); \
|
||||
virtual nsIRenderingContext* GetRenderingContext(); \
|
||||
virtual void SetColorMap(nsColorMap *aColorMap); \
|
||||
virtual nsIDeviceContext* GetDeviceContext(); \
|
||||
virtual nsIAppShell* GetAppShell(); \
|
||||
virtual void Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); \
|
||||
virtual nsIToolkit* GetToolkit(); \
|
||||
virtual void SetBorderStyle(nsBorderStyle aBorderStyle); \
|
||||
virtual void SetTitle(const nsString& aTitle); \
|
||||
virtual void SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); \
|
||||
virtual void RemoveTooltips(); \
|
||||
virtual void UpdateTooltips(nsRect* aNewTips[]); \
|
||||
virtual void WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect); \
|
||||
virtual void ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect); \
|
||||
virtual void AddMouseListener(nsIMouseListener * aListener); \
|
||||
virtual void AddEventListener(nsIEventListener * aListener); \
|
||||
virtual void BeginResizingChildren(void); \
|
||||
virtual void EndResizingChildren(void); \
|
||||
virtual PRBool DispatchEvent(nsGUIEvent* event); \
|
||||
virtual PRBool DispatchMouseEvent(nsMouseEvent aEvent); \
|
||||
virtual void OnDestroy(); \
|
||||
virtual PRBool OnPaint(nsPaintEvent & event); \
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent); \
|
||||
virtual PRBool OnKey(PRUint32 aEventType, PRUint32 aKeyCode, nsKeyEvent* aEvent); \
|
||||
virtual PRBool DispatchFocus(nsGUIEvent &aEvent); \
|
||||
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
|
||||
|
||||
|
||||
#define BASE_IWIDGET_IMPL_NO_SHOW(_classname, _aggname) \
|
||||
_classname::_aggname::_aggname() \
|
||||
{ \
|
||||
} \
|
||||
_classname::_aggname::~_aggname() \
|
||||
{ \
|
||||
} \
|
||||
nsrefcnt _classname::_aggname::AddRef() \
|
||||
{ \
|
||||
return GET_OUTER()->AddRef(); \
|
||||
} \
|
||||
nsrefcnt _classname::_aggname::Release() \
|
||||
{ \
|
||||
return GET_OUTER()->Release(); \
|
||||
} \
|
||||
nsresult _classname::_aggname::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
return GET_OUTER()->QueryInterface(aIID, aInstancePtr); \
|
||||
} \
|
||||
void _classname::_aggname::Create(nsIWidget *aParent, \
|
||||
const nsRect &aRect, \
|
||||
EVENT_CALLBACK aHandleEventFunction, \
|
||||
nsIDeviceContext *aContext, \
|
||||
nsIAppShell *aAppShell, \
|
||||
nsIToolkit *aToolkit, \
|
||||
nsWidgetInitData *aInitData) \
|
||||
{ \
|
||||
GET_OUTER()->Create(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); \
|
||||
} \
|
||||
void _classname::_aggname::Create(nsNativeWidget aParent, \
|
||||
const nsRect &aRect, \
|
||||
EVENT_CALLBACK aHandleEventFunction, \
|
||||
nsIDeviceContext *aContext, \
|
||||
nsIAppShell *aAppShell, \
|
||||
nsIToolkit *aToolkit, \
|
||||
nsWidgetInitData *aInitData) \
|
||||
{ \
|
||||
GET_OUTER()->Create(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); \
|
||||
} \
|
||||
void _classname::_aggname::Destroy() \
|
||||
{ \
|
||||
GET_OUTER()->Destroy(); \
|
||||
} \
|
||||
nsIWidget* _classname::_aggname::GetParent(void) \
|
||||
{ \
|
||||
return GET_OUTER()->GetParent(); \
|
||||
} \
|
||||
nsIEnumerator* _classname::_aggname::GetChildren() \
|
||||
{ \
|
||||
return GET_OUTER()->GetChildren(); \
|
||||
} \
|
||||
void _classname::_aggname::AddChild(nsIWidget* aChild) \
|
||||
{ \
|
||||
GET_OUTER()->AddChild(aChild); \
|
||||
} \
|
||||
void _classname::_aggname::RemoveChild(nsIWidget* aChild) \
|
||||
{ \
|
||||
GET_OUTER()->RemoveChild(aChild); \
|
||||
} \
|
||||
void _classname::_aggname::Move(PRUint32 aX, PRUint32 aY) \
|
||||
{ \
|
||||
GET_OUTER()->Move(aX, aY); \
|
||||
} \
|
||||
void _classname::_aggname::Resize(PRUint32 aWidth, \
|
||||
PRUint32 aHeight, PRBool aRepaint) \
|
||||
{ \
|
||||
GET_OUTER()->Resize(aWidth, aHeight, aRepaint); \
|
||||
} \
|
||||
void _classname::_aggname::Resize(PRUint32 aX, \
|
||||
PRUint32 aY, \
|
||||
PRUint32 aWidth, \
|
||||
PRUint32 aHeight, PRBool aRepaint) \
|
||||
{ \
|
||||
GET_OUTER()->Resize(aX, aY, aWidth, aHeight, aRepaint); \
|
||||
} \
|
||||
void _classname::_aggname::Enable(PRBool bState) \
|
||||
{ \
|
||||
GET_OUTER()->Enable(bState); \
|
||||
} \
|
||||
void _classname::_aggname::SetFocus(void) \
|
||||
{ \
|
||||
GET_OUTER()->SetFocus(); \
|
||||
} \
|
||||
void _classname::_aggname::GetBounds(nsRect &aRect) \
|
||||
{ \
|
||||
GET_OUTER()->GetBounds(aRect); \
|
||||
} \
|
||||
void _classname::_aggname::SetBounds(const nsRect &aRect) \
|
||||
{ \
|
||||
GET_OUTER()->SetBounds(aRect); \
|
||||
} \
|
||||
nscolor _classname::_aggname::GetForegroundColor(void) \
|
||||
{ \
|
||||
return GET_OUTER()->GetForegroundColor(); \
|
||||
} \
|
||||
void _classname::_aggname::SetForegroundColor(const nscolor &aColor) \
|
||||
{ \
|
||||
GET_OUTER()->SetForegroundColor(aColor); \
|
||||
} \
|
||||
nscolor _classname::_aggname::GetBackgroundColor(void) \
|
||||
{ \
|
||||
return GET_OUTER()->GetBackgroundColor(); \
|
||||
} \
|
||||
void _classname::_aggname::SetBackgroundColor(const nscolor &aColor) \
|
||||
{ \
|
||||
GET_OUTER()->SetBackgroundColor(aColor); \
|
||||
} \
|
||||
nsIFontMetrics* _classname::_aggname::GetFont(void) \
|
||||
{ \
|
||||
return GET_OUTER()->GetFont(); \
|
||||
} \
|
||||
void _classname::_aggname::SetFont(const nsFont &aFont) \
|
||||
{ \
|
||||
GET_OUTER()->SetFont(aFont); \
|
||||
} \
|
||||
nsCursor _classname::_aggname::GetCursor() \
|
||||
{ \
|
||||
return GET_OUTER()->GetCursor(); \
|
||||
} \
|
||||
void _classname::_aggname::SetCursor(nsCursor aCursor) \
|
||||
{ \
|
||||
GET_OUTER()->SetCursor(aCursor); \
|
||||
} \
|
||||
void _classname::_aggname::Invalidate(PRBool aIsSynchronous) \
|
||||
{ \
|
||||
GET_OUTER()->Invalidate(aIsSynchronous); \
|
||||
} \
|
||||
void* _classname::_aggname::GetNativeData(PRUint32 aDataType) \
|
||||
{ \
|
||||
return GET_OUTER()->GetNativeData(aDataType); \
|
||||
} \
|
||||
nsIRenderingContext* _classname::_aggname::GetRenderingContext() \
|
||||
{ \
|
||||
return GET_OUTER()->GetRenderingContext(); \
|
||||
} \
|
||||
nsIDeviceContext* _classname::_aggname::GetDeviceContext() \
|
||||
{ \
|
||||
return GET_OUTER()->GetDeviceContext(); \
|
||||
} \
|
||||
nsIAppShell* _classname::_aggname::GetAppShell() \
|
||||
{ \
|
||||
return GET_OUTER()->GetAppShell(); \
|
||||
} \
|
||||
void _classname::_aggname::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) \
|
||||
{ \
|
||||
GET_OUTER()->Scroll(aDx, aDy, aClipRect); \
|
||||
} \
|
||||
nsIToolkit* _classname::_aggname::GetToolkit() \
|
||||
{ \
|
||||
return GET_OUTER()->GetToolkit(); \
|
||||
} \
|
||||
void _classname::_aggname::SetColorMap(nsColorMap *aColorMap) \
|
||||
{ \
|
||||
GET_OUTER()->SetColorMap(aColorMap); \
|
||||
} \
|
||||
void _classname::_aggname::AddMouseListener(nsIMouseListener * aListener) \
|
||||
{ \
|
||||
GET_OUTER()->AddMouseListener(aListener); \
|
||||
} \
|
||||
void _classname::_aggname::AddEventListener(nsIEventListener * aListener) \
|
||||
{ \
|
||||
GET_OUTER()->AddEventListener(aListener); \
|
||||
} \
|
||||
void _classname::_aggname::SetBorderStyle(nsBorderStyle aBorderStyle) \
|
||||
{ \
|
||||
GET_OUTER()->SetBorderStyle(aBorderStyle); \
|
||||
} \
|
||||
void _classname::_aggname::SetTitle(const nsString& aTitle) \
|
||||
{ \
|
||||
GET_OUTER()->SetTitle(aTitle); \
|
||||
} \
|
||||
void _classname::_aggname::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]) \
|
||||
{ \
|
||||
GET_OUTER()->SetTooltips(aNumberOfTips, aTooltipAreas); \
|
||||
} \
|
||||
void _classname::_aggname::UpdateTooltips(nsRect* aNewTips[]) \
|
||||
{ \
|
||||
GET_OUTER()->UpdateTooltips(aNewTips); \
|
||||
} \
|
||||
void _classname::_aggname::RemoveTooltips() \
|
||||
{ \
|
||||
GET_OUTER()->RemoveTooltips(); \
|
||||
} \
|
||||
void _classname::_aggname::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) \
|
||||
{ \
|
||||
GET_OUTER()->WidgetToScreen(aOldRect, aNewRect); \
|
||||
} \
|
||||
void _classname::_aggname::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) \
|
||||
{ \
|
||||
GET_OUTER()->ScreenToWidget(aOldRect, aNewRect); \
|
||||
} \
|
||||
PRBool _classname::_aggname::DispatchEvent(nsGUIEvent* event) \
|
||||
{ \
|
||||
return GET_OUTER()->DispatchEvent(event); \
|
||||
} \
|
||||
PRBool _classname::_aggname::DispatchMouseEvent(nsMouseEvent event) \
|
||||
{ \
|
||||
return GET_OUTER()->DispatchMouseEvent(event); \
|
||||
} \
|
||||
PRBool _classname::_aggname::OnPaint(nsPaintEvent &event) \
|
||||
{ \
|
||||
return GET_OUTER()->OnPaint(event); \
|
||||
} \
|
||||
void _classname::_aggname::BeginResizingChildren() \
|
||||
{ \
|
||||
GET_OUTER()->BeginResizingChildren(); \
|
||||
} \
|
||||
void _classname::_aggname::EndResizingChildren() \
|
||||
{ \
|
||||
GET_OUTER()->EndResizingChildren(); \
|
||||
} \
|
||||
void _classname::_aggname::OnDestroy() \
|
||||
{ \
|
||||
GET_OUTER()->OnDestroy(); \
|
||||
} \
|
||||
PRBool _classname::_aggname::OnResize(nsSizeEvent &aEvent) \
|
||||
{ \
|
||||
return GET_OUTER()->OnResize(aEvent); \
|
||||
} \
|
||||
PRBool _classname::_aggname::OnKey(PRUint32 aEventType, PRUint32 aKeyCode, nsKeyEvent* aEvent) \
|
||||
{ \
|
||||
return GET_OUTER()->OnKey(aEventType, aKeyCode, aEvent); \
|
||||
} \
|
||||
PRBool _classname::_aggname::DispatchFocus(nsGUIEvent &aEvent) \
|
||||
{ \
|
||||
return GET_OUTER()->DispatchFocus(aEvent); \
|
||||
} \
|
||||
PRBool _classname::_aggname::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos) \
|
||||
{ \
|
||||
return GET_OUTER()->OnScroll(aEvent, cPos); \
|
||||
}
|
||||
|
||||
#define BASE_IWIDGET_IMPL_SHOW(_classname, _aggname) \
|
||||
void _classname::_aggname::Show(PRBool bState) \
|
||||
{ \
|
||||
GET_OUTER()->Show(bState); \
|
||||
}
|
||||
|
||||
#define BASE_IWIDGET_IMPL(_classname, _aggname) \
|
||||
BASE_IWIDGET_IMPL_NO_SHOW(_classname, _aggname) \
|
||||
BASE_IWIDGET_IMPL_SHOW(_classname, _aggname)
|
||||
|
||||
|
||||
|
||||
#endif // Window_h__
|
Загрузка…
Ссылка в новой задаче