Changed to new interfaces

This commit is contained in:
rods%netscape.com 1998-09-16 17:31:02 +00:00
parent ebde4b917b
commit 92166df694
2 changed files with 62 additions and 243 deletions

View File

@ -24,7 +24,57 @@
#include <Xm/List.h>
#define DBG 0
NS_IMPL_ADDREF(nsListBox)
NS_IMPL_RELEASE(nsListBox)
//-------------------------------------------------------------------------
//
// nsListBox constructor
//
//-------------------------------------------------------------------------
nsListBox::nsListBox() : nsWindow(), nsIListWidget(), nsIListBox()
{
NS_INIT_REFCNT();
mMultiSelect = PR_FALSE;
mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
//
// nsListBox:: destructor
//
//-------------------------------------------------------------------------
nsListBox::~nsListBox()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
nsresult result = nsWindow::QueryInterface(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*)this);
AddRef();
result = NS_OK;
}
else if (aIID.Equals(kInsListWidgetIID)) {
*aInstancePtr = (void*) ((nsIListWidget*)this);
AddRef();
result = NS_OK;
}
}
return result;
}
//-------------------------------------------------------------------------
//
@ -245,54 +295,6 @@ 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
@ -309,8 +311,6 @@ void nsListBox::Create(nsIWidget *aParent,
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 {
@ -320,8 +320,6 @@ void nsListBox::Create(nsIWidget *aParent,
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
unsigned char selectionPolicy;
Boolean autoSelection;
@ -358,7 +356,6 @@ void nsListBox::Create(nsIWidget *aParent,
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;
@ -408,149 +405,3 @@ PRBool nsListBox::OnResize(nsSizeEvent &aEvent)
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
#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);

View File

@ -26,15 +26,20 @@
* Native Motif Listbox wrapper
*/
class nsListBox : public nsWindow
class nsListBox : public nsWindow,
public nsIListWidget,
public nsIListBox
{
public:
nsListBox(nsISupports *aOuter);
virtual ~nsListBox();
nsListBox();
virtual ~nsListBox();
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
// nsISupports. Forward to the nsObject base class
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
void Create(nsIWidget *aParent,
const nsRect &aRect,
@ -53,7 +58,7 @@ public:
nsWidgetInitData *aInitData = nsnull);
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
@ -76,43 +81,6 @@ public:
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__