From 8e6ff55a0e05211f4efcbb6eef4ede28ef145db0 Mon Sep 17 00:00:00 2001 From: "pierre%netscape.com" Date: Mon, 8 Mar 1999 04:50:20 +0000 Subject: [PATCH] implemented nsListbox --- widget/macbuild/widget.mcp | Bin 83132 -> 83132 bytes widget/src/mac/nsListBox.cpp | 799 ++++++++++++++--------------- widget/src/mac/nsListBox.h | 125 ++--- widget/src/mac/nsWidgetFactory.cpp | 5 +- 4 files changed, 424 insertions(+), 505 deletions(-) diff --git a/widget/macbuild/widget.mcp b/widget/macbuild/widget.mcp index 216faab8fc94f912d872173acb6877e9ad86b7ff..cee2f47da6458eaea7fb4df318a66cf65ab43839 100644 GIT binary patch delta 378 zcmdnf$-1YLb;D{FK}`k*1_wqU0mSh@96LFIU4HUymRcK-08o4p5FcP*;HzR_5CAfP z{DQ>HA{*xb3-_YLw1E7g5}g1;pg7ndRv-h26DCh!UBCijY_?$2V4U77&d5GFZ=u8F zV+(CJKVe_b$+&Ry1i{6OlM6nxOtu#0Q@*Wm>Q5B$&DiEsy zu{scI0kQVvCoI;Y&Onwc5W54hClGr9vCrlw?CUu90}Oma@4(CbU|)OPCn50KnKGBYsB^kHjHwN qYzxzYLUXpW*fD-)lx+aA1#(LYKw$<7E+}A~0AwuKF5 +#include -#include +NS_IMPL_ADDREF(nsListBox); +NS_IMPL_RELEASE(nsListBox); -#define DBG 0 - -//------------------------------------------------------------------------- -// -// initializer -// -//------------------------------------------------------------------------- - -void nsListBox::SetMultipleSelection(PRBool aMultipleSelections) +typedef struct ldesRsrc { - 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 0) { - XtVaSetValues(mWidget, XmNselectedItemCount, 0, NULL); - } - int i; - for (i=0;icols = 1; + (*ldesH)->vertScroll = 1; + short resID = mValue = 2222; + ::AddResource(resH, 'ldes', resID, "\p"); + } + + nsresult res = Inherited::Create(aParent, aRect, aHandleEventFunction, + aContext, aAppShell, aToolkit, aInitData); + if (resH) + { + ::RemoveResource(resH); + ::DisposeHandle(resH); + } + + if (res == NS_OK) + { + Size actualSize; + ::GetControlData(mControl, kControlNoPart, kControlListBoxListHandleTag, sizeof(ListHandle), (Ptr)&mListHandle, &actualSize); + if (mListHandle) + { + SetMultipleSelection(mMultiSelect); + ::SetControlMinimum(mControl, 0); + ::SetControlMaximum(mControl, 0); + ::LSetDrawingMode(true, mListHandle); + } + else + res = NS_ERROR_FAILURE; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// +//------------------------------------------------------------------------- +nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; } - return result; + static NS_DEFINE_IID(kInsListBoxIID, NS_ILISTBOX_IID); + static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID); + + if (aIID.Equals(kInsListBoxIID)) { + *aInstancePtr = (void*) ((nsIListBox*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + else if (aIID.Equals(kInsListWidgetIID)) { + *aInstancePtr = (void*) ((nsIListWidget*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsWindow::QueryInterface(aIID,aInstancePtr); } -//------------------------------------------------------------------------- -// -// 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())) - - +#pragma mark - //------------------------------------------------------------------------- // // SetMultipleSelection // //------------------------------------------------------------------------- - -void nsListBox::AggListBox::SetMultipleSelection(PRBool aMultipleSelections) +NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections) { - GET_OUTER()->SetMultipleSelection(aMultipleSelections); + mMultiSelect = aMultipleSelections; + + if (mListHandle) + (*mListHandle)->selFlags = (mMultiSelect ? (lUseSense | lNoRect | lNoExtend) : lOnlyOne); + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// PreCreateWidget +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData) +{ + if (nsnull != aInitData) { + nsListBoxInitData* data = (nsListBoxInitData *) aInitData; + mMultiSelect = data->mMultiSelect; + } + return NS_OK; } @@ -432,10 +191,27 @@ void nsListBox::AggListBox::SetMultipleSelection(PRBool aMultipleSelections) // AddItemAt // //------------------------------------------------------------------------- - -void nsListBox::AggListBox::AddItemAt(nsString &aItem, PRInt32 aPosition) +nsresult nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition) { - GET_OUTER()->AddItemAt(aItem, aPosition); + if (! mListHandle) + return NS_ERROR_NOT_INITIALIZED; + + Str255 pString; + StringToStr255(aItem, pString); + + StartDraw(); + if (aPosition == -1) + aPosition = GetItemCount() + 1; + short rowNum = ::LAddRow(1, aPosition, mListHandle); + + Cell newCell; + ::SetPt(&newCell, 0, rowNum); + ::LSetCell(pString+1, *pString, newCell, mListHandle); + + ::SetControlMaximum(mControl, GetItemCount()); + EndDraw(); + + return NS_OK; } //------------------------------------------------------------------------- @@ -443,9 +219,40 @@ void nsListBox::AggListBox::AddItemAt(nsString &aItem, PRInt32 aPosition) // Finds an item at a postion // //------------------------------------------------------------------------- -PRInt32 nsListBox::AggListBox::FindItem(nsString &aItem, PRInt32 aStartPos) +PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos) { - return GET_OUTER()->FindItem(aItem, aStartPos); + if (! mListHandle) + return -1; + + PRInt32 index = -1; + short itemCount = GetItemCount(); + + if (aStartPos < itemCount) + { + Str255 searchStr; + StringToStr255(aItem, searchStr); + + for (short i = aStartPos; i < itemCount; i ++) + { + Str255 itemStr; + short strSize = sizeof(itemStr) - 1; + + Cell theCell; + ::SetPt(&theCell, 0, i); + + ::LGetCell(itemStr+1, &strSize, theCell, mListHandle); + if (strSize > sizeof(itemStr) - 1) + strSize = sizeof(itemStr) - 1; + itemStr[0] = strSize; + + if (::EqualString(itemStr, searchStr, FALSE, FALSE)) + { + index = i; + break; + } + } + } + return index; } //------------------------------------------------------------------------- @@ -453,9 +260,12 @@ PRInt32 nsListBox::AggListBox::FindItem(nsString &aItem, PRInt32 aStartPos) // CountItems - Get Item Count // //------------------------------------------------------------------------- -PRInt32 nsListBox::AggListBox::GetItemCount() +PRInt32 nsListBox::GetItemCount() { - return GET_OUTER()->GetItemCount(); + if (! mListHandle) + return 0; + + return (*mListHandle)->dataBounds.bottom; } //------------------------------------------------------------------------- @@ -463,9 +273,20 @@ PRInt32 nsListBox::AggListBox::GetItemCount() // Removes an Item at a specified location // //------------------------------------------------------------------------- -PRBool nsListBox::AggListBox::RemoveItemAt(PRInt32 aPosition) +PRBool nsListBox::RemoveItemAt(PRInt32 aPosition) { - return GET_OUTER()->RemoveItemAt(aPosition); + if (! mListHandle) + return PR_FALSE; + + if (GetItemCount() < aPosition) + return PR_FALSE; + + StartDraw(); + ::LDelRow(1, aPosition, mListHandle); + ::SetControlMaximum(mControl, GetItemCount()); + EndDraw(); + + return PR_TRUE; } //------------------------------------------------------------------------- @@ -473,29 +294,136 @@ PRBool nsListBox::AggListBox::RemoveItemAt(PRInt32 aPosition) // Removes an Item at a specified location // //------------------------------------------------------------------------- -PRBool nsListBox::AggListBox::GetItemAt(nsString& anItem, PRInt32 aPosition) +PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition) { - return GET_OUTER()->GetItemAt(anItem, aPosition); + anItem = ""; + + if (! mListHandle) + return PR_FALSE; + + if (GetItemCount() < aPosition) + return PR_FALSE; + + Str255 itemStr; + short strSize = sizeof(itemStr) - 1; + + Cell theCell; + ::SetPt(&theCell, 0, aPosition); + + ::LGetCell(itemStr+1, &strSize, theCell, mListHandle); + if (strSize > sizeof(itemStr) - 1) + strSize = sizeof(itemStr) - 1; + itemStr[0] = strSize; + Str255ToString(itemStr, anItem); + + return PR_TRUE; } //------------------------------------------------------------------------- // -// Gets the selected of selected item +// Gets the content of selected item // //------------------------------------------------------------------------- -void nsListBox::AggListBox::GetSelectedItem(nsString& aItem) +nsresult nsListBox::GetSelectedItem(nsString& aItem) { - GET_OUTER()->GetSelectedItem(aItem); + aItem = ""; + + if (! mListHandle) + return PR_FALSE; + + PRInt32 selectedIndex = GetSelectedIndex(); + if (selectedIndex < 0) + return PR_FALSE; + + GetItemAt(aItem, selectedIndex); + return PR_TRUE; } //------------------------------------------------------------------------- // -// Gets the list of selected otems +// Gets the list of selected items // //------------------------------------------------------------------------- -PRInt32 nsListBox::AggListBox::GetSelectedIndex() +PRInt32 nsListBox::GetSelectedIndex() { - return GET_OUTER()->GetSelectedIndex(); + if (! mListHandle) + return -1; + + Cell theCell; + ::SetPt(&theCell, 0, 0); + + if (::LGetSelect(true, &theCell, mListHandle)) + return theCell.v; + else + return -1; +} + +//------------------------------------------------------------------------- +// +// Gets the count of selected items +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetSelectedCount() +{ + if (! mListHandle) + return 0; + + PRInt32 itemCount = 0; + Cell theCell; + ::SetPt(&theCell, 0, 0); + while (::LGetSelect(true, &theCell, mListHandle)) + { + itemCount ++; + ::LNextCell(true, true, &theCell, mListHandle); + } + return itemCount; +} + +//------------------------------------------------------------------------- +// +// Gets the indices of selected items +// +//------------------------------------------------------------------------- +nsresult nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + if (! mListHandle) + return NS_ERROR_NOT_INITIALIZED; + + PRInt32 itemCount = 0; + Cell theCell; + ::SetPt(&theCell, 0, 0); + while (::LGetSelect(true, &theCell, mListHandle) && (itemCount < aSize)) + { + aIndices[itemCount] = theCell.v; + itemCount ++; + ::LNextCell(true, true, &theCell, mListHandle); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Sets selected items +// +//------------------------------------------------------------------------- +nsresult nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + if (! mListHandle) + return NS_ERROR_NOT_INITIALIZED; + + StartDraw(); + ::LSetDrawingMode(false, mListHandle); + for (PRInt32 i = 0; i < aSize; i ++) + { + Cell theCell; + ::SetPt(&theCell, 0, 1); + ::LSetSelect(true, theCell, mListHandle); + } + ::LSetDrawingMode(true, mListHandle); + ::LAutoScroll(mListHandle); + EndDraw(); + + return NS_OK; } //------------------------------------------------------------------------- @@ -503,39 +431,25 @@ PRInt32 nsListBox::AggListBox::GetSelectedIndex() // SelectItem // //------------------------------------------------------------------------- -void nsListBox::AggListBox::SelectItem(PRInt32 aPosition) +nsresult nsListBox::SelectItem(PRInt32 aPosition) { - GET_OUTER()->SelectItem(aPosition); -} + if (! mListHandle) + return NS_ERROR_NOT_INITIALIZED; -//------------------------------------------------------------------------- -// -// GetSelectedCount -// -//------------------------------------------------------------------------- -PRInt32 nsListBox::AggListBox::GetSelectedCount() -{ - return GET_OUTER()->GetSelectedCount(); -} + if (GetItemCount() < aPosition) + return PR_FALSE; -//------------------------------------------------------------------------- -// -// GetSelectedIndices -// -//------------------------------------------------------------------------- -void nsListBox::AggListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) -{ - GET_OUTER()->GetSelectedIndices(aIndices, aSize); -} + if (! mMultiSelect) + Deselect(); -//------------------------------------------------------------------------- -// -// GetSelectedIndices -// -//------------------------------------------------------------------------- -void nsListBox::AggListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) -{ - GET_OUTER()->SetSelectedIndices(aIndices, aSize); + StartDraw(); + Cell theCell; + ::SetPt(&theCell, 0, aPosition); + ::LSetSelect(true, theCell, mListHandle); + ::LAutoScroll(mListHandle); + EndDraw(); + + return NS_OK; } //------------------------------------------------------------------------- @@ -543,14 +457,57 @@ void nsListBox::AggListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize // Deselect // //------------------------------------------------------------------------- -void nsListBox::AggListBox::Deselect() +nsresult nsListBox::Deselect() { - GET_OUTER()->Deselect(); + if (! mListHandle) + return NS_ERROR_NOT_INITIALIZED; + + if (GetItemCount() == 0) + return PR_FALSE; + + StartDraw(); + ::LSetDrawingMode(false, mListHandle); + Cell theCell; + ::SetPt(&theCell, 0, 0); + while (::LGetSelect(true, &theCell, mListHandle)) + { + ::LSetSelect(false, theCell, mListHandle); + ::LNextCell(true, true, &theCell, mListHandle); + } + ::LSetDrawingMode(true, mListHandle); + EndDraw(); + + return NS_OK; } +//------------------------------------------------------------------------- +// +// DispatchMouseEvent +// +//------------------------------------------------------------------------- +PRBool nsListBox::DispatchMouseEvent(nsMouseEvent &aEvent) +{ + PRBool eatEvent = PR_FALSE; + switch (aEvent.message) + { + case NS_MOUSE_LEFT_DOUBLECLICK: + case NS_MOUSE_LEFT_BUTTON_DOWN: + StartDraw(); + { + Point thePoint; + thePoint.h = aEvent.point.x; + thePoint.v = aEvent.point.y; + ::TrackControl(mControl, thePoint, nil); + //¥TODO: the mouseUp event is eaten by TrackControl. + //¥ We must create it and dispatch it after the mouseDown; + eatEvent = PR_TRUE; + } + EndDraw(); + break; + } -//---------------------------------------------------------------------- - -BASE_IWIDGET_IMPL(nsListBox, AggListBox); - + if (eatEvent) + return PR_TRUE; + return (Inherited::DispatchMouseEvent(aEvent)); +} diff --git a/widget/src/mac/nsListBox.h b/widget/src/mac/nsListBox.h index 24ee5a234e06..01ad8766b798 100644 --- a/widget/src/mac/nsListBox.h +++ b/widget/src/mac/nsListBox.h @@ -19,100 +19,63 @@ #ifndef nsListBox_h__ #define nsListBox_h__ -#include "nsWindow.h" +#include "nsMacControl.h" #include "nsIListBox.h" +#include -/** - * Native Motif Listbox wrapper - */ -class nsListBox : public nsWindow +class nsListBox : public nsMacControl, + public nsIListWidget, + public nsIListBox { +private: + typedef nsMacControl Inherited; public: - nsListBox(nsISupports *aOuter); - virtual ~nsListBox(); + nsListBox(); + virtual ~nsListBox(); - // nsISupports. Forward to the nsObject base class - NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr); + // nsISupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(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); + // nsIWidget + NS_IMETHODIMP 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); + // nsIListBox part + NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections); + NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition); + PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos); + PRInt32 GetItemCount(); + PRBool RemoveItemAt(PRInt32 aPosition); + PRBool GetItemAt(nsString& anItem, PRInt32 aPosition); + NS_IMETHOD GetSelectedItem(nsString& aItem); + PRInt32 GetSelectedIndex(); + PRInt32 GetSelectedCount(); + NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize); + NS_IMETHOD SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize); + NS_IMETHOD SelectItem(PRInt32 aPosition); + NS_IMETHOD Deselect() ; + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); - - 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() ; + // nsWindow + virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent); 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; + // nsMacControl + virtual void GetRectForMacControl(nsRect &outRect); +protected: + ListHandle mListHandle; + PRBool mMultiSelect; }; + #endif // nsListBox_h__ diff --git a/widget/src/mac/nsWidgetFactory.cpp b/widget/src/mac/nsWidgetFactory.cpp index 4218a8a87194..6c0c9983a5fd 100644 --- a/widget/src/mac/nsWidgetFactory.cpp +++ b/widget/src/mac/nsWidgetFactory.cpp @@ -42,7 +42,7 @@ #include "nsTextAreaWidget.h" -//#include "nsListBox.h" +#include "nsListBox.h" #include "nsComboBox.h" #include "nsLookAndFeel.h" @@ -189,8 +189,7 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter, inst = (nsISupports*)(nsWindow*)new nsFileWidget(); } else if (mClassID.Equals(kCListbox)) { -// inst = (nsISupports*)(nsWindow*)new nsListBox(); - NS_NOTYETIMPLEMENTED("nsListBox"); + inst = (nsISupports*)(nsWindow*)new nsListBox(); } else if (mClassID.Equals(kCHorzScrollbar)) { inst = (nsISupports*)(nsWindow*)new nsScrollbar(PR_FALSE);