From 66877044f1cc7466924d8bef6459183d1d1f233f Mon Sep 17 00:00:00 2001 From: rods Date: Fri, 19 Jun 1998 21:38:32 +0000 Subject: [PATCH] Added ListBox and fixed RadioButton to be managed --- widget/src/motif/Makefile | 2 + widget/src/motif/nsListBox.cpp | 67 +++++++++++++++++++++++++++- widget/src/motif/nsListBox.h | 17 ++++++- widget/src/motif/nsRadioButton.cpp | 3 +- widget/src/motif/nsWidgetFactory.cpp | 7 ++- 5 files changed, 91 insertions(+), 5 deletions(-) diff --git a/widget/src/motif/Makefile b/widget/src/motif/Makefile index 26da89f27d0c..74c2977ca2b1 100644 --- a/widget/src/motif/Makefile +++ b/widget/src/motif/Makefile @@ -44,6 +44,7 @@ EXTRA_DSO_LDOPTS+= -lXm -lXt -lX11 -lm endif CPPSRCS= \ + nsListBox.cpp \ nsRadioButton.cpp \ nsFileWidget.cpp \ nsTextHelper.cpp \ @@ -58,6 +59,7 @@ CPPSRCS= \ nsToolkit.cpp CPP_OBJS= \ + ./$(OBJDIR)/nsListBox.o \ ./$(OBJDIR)/nsRadioButton.o \ ./$(OBJDIR)/nsFileWidget.o \ ./$(OBJDIR)/nsTextHelper.o \ diff --git a/widget/src/motif/nsListBox.cpp b/widget/src/motif/nsListBox.cpp index 8ea80769f7d4..6c87dd799e94 100644 --- a/widget/src/motif/nsListBox.cpp +++ b/widget/src/motif/nsListBox.cpp @@ -24,6 +24,8 @@ #include +#define DBG 0 + //------------------------------------------------------------------------- // // initializer @@ -45,7 +47,13 @@ void nsListBox::SetMultipleSelection(PRBool aMultipleSelections) void nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition) { NS_ALLOC_STR_BUF(val, aItem, 256); - //SendMessage(mWnd, LB_INSERTSTRING, (int)aPosition, (LPARAM)(LPCTSTR)val); + + XmString str; + + str = XmStringCreateLocalized(val); + + printf("String being added [%s] %d\n", val, aPosition); + XmListAddItem(mWidget, str, (int)aPosition); NS_FREE_STR_BUF(val); } @@ -234,6 +242,63 @@ nsresult nsListBox::QueryObject(const nsIID& aIID, void** aInstancePtr) return result; } +//------------------------------------------------------------------------- +// +// nsListBox Creator +// +//------------------------------------------------------------------------- +void nsListBox::Create(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + Widget parentWidget = nsnull; + + if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent); + + if (aParent) { + parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET); + } else { + parentWidget = (Widget) aInitData ; + } + + if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget); + + mWidget = ::XtVaCreateManagedWidget("", + xmListWidgetClass, + parentWidget, + XmNitemCount, 0, + XmNwidth, aRect.width, + XmNheight, aRect.height, + XmNx, aRect.x, + XmNy, aRect.y, + 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(nsNativeWindow aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ +} + //------------------------------------------------------------------------- // // move, paint, resizes message - ignore diff --git a/widget/src/motif/nsListBox.h b/widget/src/motif/nsListBox.h index a9ee2d15a3a2..a5d6758cc629 100644 --- a/widget/src/motif/nsListBox.h +++ b/widget/src/motif/nsListBox.h @@ -36,12 +36,25 @@ public: // 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, + nsIToolkit *aToolkit = nsnull, + nsWidgetInitData *aInitData = nsnull); + + void Create(nsNativeWindow aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext = nsnull, + nsIToolkit *aToolkit = nsnull, + nsWidgetInitData *aInitData = nsnull); + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); virtual PRBool OnPaint(nsPaintEvent & aEvent); virtual PRBool OnResize(nsSizeEvent &aEvent); - // nsIWidget interface // nsIListBox interface void SetMultipleSelection(PRBool aMultipleSelections); @@ -71,7 +84,7 @@ private: // Aggregator class and instance variable used to aggregate in the // nsIListBox interface to nsListBox w/o using multiple // inheritance. - class AggListBox : public nsIListBox { + class AggListBox : public nsIListWidget { public: AggListBox(); virtual ~AggListBox(); diff --git a/widget/src/motif/nsRadioButton.cpp b/widget/src/motif/nsRadioButton.cpp index 3e348aa61ab3..c2a0771cf4a1 100644 --- a/widget/src/motif/nsRadioButton.cpp +++ b/widget/src/motif/nsRadioButton.cpp @@ -78,7 +78,8 @@ void nsRadioButton::Create(nsIWidget *aParent, XmNy, aRect.y, nsnull); - mRadioBtn = ::XmCreateToggleButton(mWidget, "radio", nsnull, 0); + mRadioBtn = ::XmCreateToggleButton(mWidget, "", nsnull, 0); + XtManageChild(mRadioBtn); if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this); diff --git a/widget/src/motif/nsWidgetFactory.cpp b/widget/src/motif/nsWidgetFactory.cpp index 9c5a3a4da02b..11dde526dce8 100644 --- a/widget/src/motif/nsWidgetFactory.cpp +++ b/widget/src/motif/nsWidgetFactory.cpp @@ -28,6 +28,7 @@ #include "nsButton.h" #include "nsScrollbar.h" #include "nsCheckButton.h" +#include "nsRadioButton.h" #include "nsTextWidget.h" #include "nsFileWidget.h" #include "nsListBox.h" @@ -38,6 +39,7 @@ static NS_DEFINE_IID(kCAppShell, 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(kCFileWidgetCID, NS_FILEWIDGET_CID); static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID); @@ -150,8 +152,11 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter, else if (mClassID.Equals(kCTextWidgetCID)) { inst = new nsTextWidget(aOuter); } + else if ( mClassID.Equals(kCRadioButtonCID)) { + inst = new nsRadioButton(aOuter); + } else if (mClassID.Equals(kCListBoxCID)) { - //inst = new nsListBox(aOuter); + inst = new nsListBox(aOuter); } else if (mClassID.Equals(kCFileWidgetCID)) { inst = new nsFileWidget(aOuter);