Removing unused native combobox implementation. r=cls.

This commit is contained in:
bryner%netscape.com 2001-08-03 00:26:19 +00:00
Родитель e85024b972
Коммит 1900fc8c9d
8 изменённых файлов: 0 добавлений и 1040 удалений

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

@ -37,7 +37,6 @@ CPPSRCS = \
nsButton.cpp \
nsCheckButton.cpp \
nsClipboard.cpp \
nsComboBox.cpp \
nsDragService.cpp \
nsFileWidget.cpp \
nsFilePicker.cpp \

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

@ -1,384 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsComboBox.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include "nsILookAndFeel.h"
#include "nsWidgetsCID.h"
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#include "nsIFontMetrics.h"
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
NS_IMPL_ADDREF(nsComboBox)
NS_IMPL_RELEASE(nsComboBox)
//-------------------------------------------------------------------------
//
// nsComboBox constructor
//
//-------------------------------------------------------------------------
nsComboBox::nsComboBox() : nsWindow(), nsIListWidget(), nsIComboBox()
{
NS_INIT_REFCNT();
mBackground = NS_RGB(124, 124, 124);
mDropDownHeight = 60; // Default to 60 pixels for drop-down list height
}
//-------------------------------------------------------------------------
//
// destructor
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
{
if(mMenuField && mMenuField->LockLooper())
{
NS_ALLOC_STR_BUF(val, aItem, 256);
mMenuField->Menu()->AddItem(new BMenuItem(val, 0), aPosition);
NS_FREE_STR_BUF(val);
mMenuField->UnlockLooper();
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Finds an item at a postion
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
{
#if 0
NS_ALLOC_STR_BUF(val, aItem, 256);
int index = ::SendMessage(mWnd, CB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val);
NS_FREE_STR_BUF(val);
return index;
#endif
printf("nsListBox::FindItem not implemented\n");
return -1;
}
//-------------------------------------------------------------------------
//
// CountItems - Get Item Count
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetItemCount()
{
PRInt32 result = 0;
if(mMenuField && mMenuField->LockLooper())
{
result = mMenuField->Menu()->CountItems();
mMenuField->UnlockLooper();
}
return result;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
{
if(mMenuField && mMenuField->LockLooper())
{
BMenuItem *it = mMenuField->Menu()->RemoveItem(aPosition);
delete it;
mMenuField->UnlockLooper();
return it ? PR_TRUE : PR_FALSE;
}
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
{
PRBool result = PR_FALSE;
anItem.SetLength(0);
if(mMenuField && mMenuField->LockLooper())
{
BMenuItem *it = mMenuField->Menu()->ItemAt(aPosition);
anItem.AppendWithConversion(it->Label());
mMenuField->UnlockLooper();
result = PR_TRUE;
}
return result;
}
//-------------------------------------------------------------------------
//
// Gets the selected of selected item
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
{
GetItemAt(aItem, GetSelectedIndex());
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Gets the list of selected otems
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetSelectedIndex()
{
PRInt32 index = -1;
if(mMenuField && mMenuField->LockLooper())
{
BMenuItem *it = mMenuField->Menu()->FindMarked();
index = it ? mMenuField->Menu()->IndexOf(it) : -1;
mMenuField->UnlockLooper();
}
return index;
}
//-------------------------------------------------------------------------
//
// SelectItem
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
{
if(mMenuField && mMenuField->LockLooper())
{
BMenuItem *it = mMenuField->Menu()->ItemAt(aPosition);
if(it)
it->SetMarked(true);
mMenuField->UnlockLooper();
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Deselect
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::Deselect()
{
if(mMenuField && mMenuField->LockLooper())
{
BMenuItem *it = mMenuField->Menu()->FindMarked();
if(it)
it->SetMarked(false);
mMenuField->UnlockLooper();
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// destructor
//
//-------------------------------------------------------------------------
nsComboBox::~nsComboBox()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kInsComboBoxIID, NS_ICOMBOBOX_IID);
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
if (aIID.Equals(kInsComboBoxIID)) {
*aInstancePtr = (void*) ((nsIComboBox*)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);
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsComboBox::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
PRBool nsComboBox::OnPaint(nsRect &r)
{
return PR_FALSE;
}
PRBool nsComboBox::OnResize(nsRect &aWindowRect)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Cache the drop down list height in mDropDownHeight
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::PreCreateWidget(nsWidgetInitData *aInitData)
{
nsComboBoxInitData* comboData = (nsComboBoxInitData*)aInitData;
mDropDownHeight = comboData->mDropDownHeight;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Modify the height passed to create and resize to be
// the combo box drop down list height. (Note: Windows uses
// the height of the window to specify the drop-down list size,
// not the height of combobox text area.
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetHeight(PRInt32 aProposedHeight)
{
return(mDropDownHeight);
}
//-------------------------------------------------------------------------
//
// get position/dimensions
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::GetBounds(nsRect &aRect)
{
#if 0
nsWindow::GetNonClientBounds(aRect);
#endif
printf("nsListBox::GetBounds not wrong\n"); // the following is just a placeholder
nsWindow::GetClientBounds(aRect);
return NS_OK;
}
/**
* Renders the TextWidget for Printing
*
**/
NS_METHOD nsComboBox::Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
/*nsRect rect;
GetBoundsAppUnits(rect, aTwipsConversion);
aRenderingContext.SetColor(NS_RGB(0,0,0));
nscolor bgColor = NS_RGB(255,255,255);
nscolor fgColor = NS_RGB(0,0,0);
nscolor hltColor = NS_RGB(240,240,240);
nscolor sdwColor = NS_RGB(128,128,128);
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
}
nsIDeviceContext * context;
//nsDrawingSurface surface;
aRenderingContext.GetDeviceContext(context);
//context->GetDrawingSurface(aRenderingContext, surface);
//HDC the_hdc = ((nsDrawingSurfaceWin *)&surface)->mDC;
//::SendMessage(mWnd, WM_PAINT, (WPARAM)the_hdc, NULL);
// shrink by one pixel
nscoord onePixel = nscoord((aTwipsConversion+0.6F));
nscoord twoPixels = onePixel*2;
nsString text("(ComboBox)");
//GetSelectedItem(text);
aRenderingContext.SetColor(bgColor);
aRenderingContext.FillRect(rect);
aRenderingContext.SetColor(NS_RGB(0,0,0));
aRenderingContext.DrawRect(rect);
aRenderingContext.SetFont(*mFont);
nscoord textWidth;
nscoord textHeight;
aRenderingContext.GetWidth(text, textWidth);
nsIFontMetrics* metrics;
context->GetMetricsFor(*mFont, metrics);
metrics->GetMaxAscent(textHeight);
nscoord x = (twoPixels * 2) + rect.x;
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
//aRenderingContext.DrawString(text, x, y);
*/
return NS_OK;
}
BView *nsComboBox::CreateBeOSView()
{
return mMenuField = new nsMenuFieldBeOS((nsIWidget *)this, BRect(0, 0, 0, 0), "");
}
//-------------------------------------------------------------------------
// Sub-class of BeOS MenuField
//-------------------------------------------------------------------------
nsMenuFieldBeOS::nsMenuFieldBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
const char *aName, uint32 aResizingMode, uint32 aFlags )
: BMenuField( aFrame, aName, "", new BPopUpMenu(""), aResizingMode, aFlags ),
nsIWidgetStore( aWidgetWindow )
{
SetDivider(0);
}

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

@ -1,97 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsComboBox_h__
#define nsComboBox_h__
#include "nsdefs.h"
#include "nsWindow.h"
#include "nsSwitchToUIThread.h"
#include "nsIComboBox.h"
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <MenuField.h>
/**
* Native Win32 Combobox wrapper
*/
class nsComboBox : public nsWindow,
public nsIListWidget,
public nsIComboBox
{
public:
nsComboBox();
~nsComboBox();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIWidget overrides
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsRect &r);
virtual PRBool OnResize(nsRect &aWindowRect);
// nsIWidget
NS_IMETHOD GetBounds(nsRect &aRect);
// nsIComboBox interface
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
virtual PRInt32 GetItemCount();
virtual PRBool RemoveItemAt(PRInt32 aPosition);
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
NS_IMETHOD GetSelectedItem(nsString& aItem);
virtual PRInt32 GetSelectedIndex();
NS_IMETHOD SelectItem(PRInt32 aPosition);
NS_IMETHOD Deselect() ;
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
protected:
// Modify the height passed to create and resize to be
// the combo box drop down list height.
PRInt32 GetHeight(PRInt32 aProposedHeight);
PRInt32 mDropDownHeight;
BView *CreateBeOSView();
BMenuField *mMenuField;
};
//
// A BMenuField subclass
//
class nsMenuFieldBeOS : public BMenuField, public nsIWidgetStore {
public:
nsMenuFieldBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
const char *name, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
};
#endif // nsComboBox_h__

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

@ -39,7 +39,6 @@
#include "nsFilePicker.h"
#include "nsFileWidget.h"
#include "nsListBox.h"
#include "nsComboBox.h"
#include "nsLookAndFeel.h"
#include "nsLabel.h"
#include "nsFontRetrieverService.h"
@ -60,7 +59,6 @@ static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
static NS_DEFINE_IID(kCButton, NS_BUTTON_CID);
static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID);
static NS_DEFINE_IID(kCCombobox, NS_COMBOBOX_CID);
static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kCFilePicker, NS_FILEPICKER_CID);
static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID);
@ -178,9 +176,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCCheckButton)) {
inst = (nsISupports*)(nsWindow *)new nsCheckButton();
}
else if (mClassID.Equals(kCCombobox)) {
inst = (nsISupports*)(nsWindow *)new nsComboBox();
}
else if (mClassID.Equals(kCRadioButton)) {
inst = (nsISupports*)(nsWindow *)new nsRadioButton();
}

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

@ -37,7 +37,6 @@ CPPSRCS = \
nsBidiKeyboard.cpp \
nsButton.cpp \
nsCheckButton.cpp \
nsComboBox.cpp \
nsFileWidget.cpp \
nsLabel.cpp \
nsListBox.cpp \

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

@ -1,453 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsComboBox.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include "nsIDeviceContext.h"
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#define DBG 0
#define INITIAL_MAX_ITEMS 128
#define ITEMS_GROWSIZE 128
NS_IMPL_ADDREF(nsComboBox)
NS_IMPL_RELEASE(nsComboBox)
//-------------------------------------------------------------------------
//
// nsComboBox constructor
//
//-------------------------------------------------------------------------
nsComboBox::nsComboBox() : nsWindow(), nsIListWidget(), nsIComboBox()
{
NS_INIT_REFCNT();
mMultiSelect = PR_FALSE;
mBackground = NS_RGB(124, 124, 124);
mMaxNumItems = INITIAL_MAX_ITEMS;
mItems = (Widget *)new long[INITIAL_MAX_ITEMS];
mNumItems = 0;
}
//-------------------------------------------------------------------------
//
// nsComboBox:: destructor
//
//-------------------------------------------------------------------------
nsComboBox::~nsComboBox()
{
if (mItems != nsnull) {
delete[] mItems;
}
}
//-------------------------------------------------------------------------
//
// Set the foreground color
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::SetForegroundColor(const nscolor &aColor)
{
nsWindow::SetForegroundColor(aColor);
PRUint32 pixel;
mContext->ConvertPixel(aColor, pixel);
XtVaSetValues(mOptionMenu, XtNforeground, pixel, nsnull);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Set the background color
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::SetBackgroundColor(const nscolor &aColor)
{
nsWindow::SetForegroundColor(aColor);
PRUint32 pixel;
mContext->ConvertPixel(aColor, pixel);
XtVaSetValues(mOptionMenu, XtNbackground, pixel, nsnull);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// initializer
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::SetMultipleSelection(PRBool aMultipleSelections)
{
mMultiSelect = aMultipleSelections;
return NS_OK;
}
//-------------------------------------------------------------------------
//
// AddItemAt
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
{
NS_ALLOC_STR_BUF(val, aItem, 256);
XmString str;
Arg args[30];
int argc = 0;
str = XmStringCreateLocalized(val);
XtSetArg(args[argc], XmNlabelString, str); argc++;
Widget btn = XmCreatePushButton(mPullDownMenu, val, args, argc);
XtManageChild(btn);
if (mNumItems == mMaxNumItems) {
// [TODO] Grow array here by ITEMS_GROWSIZE
}
mItems[mNumItems++] = btn;
NS_FREE_STR_BUF(val);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Finds an item at a postion
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
{
NS_ALLOC_STR_BUF(val, aItem, 256);
int i;
PRInt32 inx = -1;
for (i=0;i<mNumItems && inx == -1;i++) {
XmString str;
XtVaGetValues(mItems[i], XmNlabelString, &str, nsnull);
char * text;
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
if (!strcmp(text, val)) {
inx = i;
}
XtFree(text);
}
}
NS_FREE_STR_BUF(val);
return inx;
}
//-------------------------------------------------------------------------
//
// CountItems - Get Item Count
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetItemCount()
{
return (PRInt32)mNumItems;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
{
if (aPosition >= 0 && aPosition < mNumItems) {
XtUnmanageChild(mItems[aPosition]);
XtDestroyWidget(mItems[aPosition]);
int i;
for (i=aPosition ; i < mNumItems-1; i++) {
mItems[i] = mItems[i+1];
}
mItems[mNumItems-1] = NULL;
mNumItems--;
return PR_TRUE;
}
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
{
PRBool result = PR_FALSE;
if (aPosition < 0 || aPosition >= mNumItems) {
return result;
}
XmString str;
XtVaGetValues(mItems[aPosition], XmNlabelString, &str, nsnull);
char * text;
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
anItem = text;
XtFree(text);
}
return result;
}
//-------------------------------------------------------------------------
//
// Gets the selected of selected item
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
{
Widget w;
XtVaGetValues(mWidget, XmNmenuHistory, &w, NULL);
int i;
for (i=0;i<mNumItems;i++) {
if (mItems[i] == w) {
GetItemAt(aItem, i);
}
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Gets the list of selected otems
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetSelectedIndex()
{
if (!mMultiSelect) {
Widget w;
XtVaGetValues(mWidget, XmNmenuHistory, &w, NULL);
int i;
for (i=0;i<mNumItems;i++) {
if (mItems[i] == w) {
return (PRInt32)i;
}
}
} else {
NS_ASSERTION(PR_FALSE, "Multi selection list box does not support GetSlectedIndex()");
}
return -1;
}
//-------------------------------------------------------------------------
//
// SelectItem
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
{
if (!mMultiSelect) {
if (aPosition >= 0 && aPosition < mNumItems) {
XtVaSetValues(mWidget,
XmNmenuHistory, mItems[aPosition],
NULL);
}
} else {
// this is an error
return NS_ERROR_FAILURE;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// GetSelectedCount
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetSelectedCount()
{
if (!mMultiSelect) {
PRInt32 inx = GetSelectedIndex();
return (inx == -1? 0 : 1);
} else {
return 0;
}
}
//-------------------------------------------------------------------------
//
// GetSelectedIndices
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
{
// this is an error
return NS_ERROR_FAILURE;
}
//-------------------------------------------------------------------------
//
// Deselect
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::Deselect()
{
if (mMultiSelect) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kInsComboBoxIID, NS_ICOMBOBOX_IID);
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
if (aIID.Equals(kInsComboBoxIID)) {
*aInstancePtr = (void*) ((nsIComboBox*)this);
AddRef();
return NS_OK;
}
else if (aIID.Equals(kInsListWidgetIID)) {
*aInstancePtr = (void*) ((nsIListWidget*)this);
AddRef();
return NS_OK;
}
return nsWindow::QueryInterface(aIID,aInstancePtr);
}
//-------------------------------------------------------------------------
//
// nsComboBox Creator
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else if (aAppShell) {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
Arg args[30];
int argc;
argc = 0;
XtSetArg(args[argc], XmNx, 0); argc++;
XtSetArg(args[argc], XmNy, 0); argc++;
mPullDownMenu = XmCreatePulldownMenu(parentWidget, "pulldown", args, argc);
argc = 0;
XtSetArg(args[argc], XmNmarginHeight, 0); argc++;
XtSetArg(args[argc], XmNmarginWidth, 0); argc++;
XtSetArg(args[argc], XmNrecomputeSize, False); argc++;
XtSetArg(args[argc], XmNresizeHeight, False); argc++;
XtSetArg(args[argc], XmNresizeWidth, False); argc++;
XtSetArg(args[argc], XmNspacing, False); argc++;
XtSetArg(args[argc], XmNborderWidth, 0); argc++;
XtSetArg(args[argc], XmNnavigationType, XmTAB_GROUP); argc++;
XtSetArg(args[argc], XmNtraversalOn, True); argc++;
XtSetArg(args[argc], XmNorientation, XmVERTICAL); argc++;
XtSetArg(args[argc], XmNadjustMargin, False); argc++;
XtSetArg(args[argc], XmNsubMenuId, mPullDownMenu); argc++;
XtSetArg(args[argc], XmNuserData, (XtPointer)this); argc++;
XtSetArg(args[argc], XmNx, aRect.x); argc++;
XtSetArg(args[argc], XmNy, aRect.y); argc++;
XtSetArg(args[argc], XmNwidth, aRect.width); argc++;
XtSetArg(args[argc], XmNheight, aRect.height); argc++;
mWidget = XmCreateOptionMenu(parentWidget, "", args, argc);
mOptionMenu = XmOptionLabelGadget(mWidget);
XtUnmanageChild(mOptionMenu);
// save the event callback function
mEventCallback = aHandleEventFunction;
//InitCallbacks();
return NS_OK;
}
//-------------------------------------------------------------------------
//
// nsComboBox Creator
//
//-------------------------------------------------------------------------
NS_METHOD nsComboBox::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
return NS_ERROR_FAILURE;
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsComboBox::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// paint message. Don't send the paint out
//
//-------------------------------------------------------------------------
PRBool nsComboBox::OnPaint(nsPaintEvent &aEvent)
{
return PR_FALSE;
}
PRBool nsComboBox::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}

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

@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsComboBox_h__
#define nsComboBox_h__
#include "nsWindow.h"
#include "nsIComboBox.h"
/**
* Native Motif Listbox wrapper
*/
class nsComboBox : public nsWindow,
public nsIListWidget,
public nsIComboBox
{
public:
nsComboBox();
~nsComboBox();
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
// nsIComboBox interface
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
virtual PRInt32 GetItemCount();
virtual PRBool RemoveItemAt(PRInt32 aPosition);
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
NS_IMETHOD GetSelectedItem(nsString& aItem);
virtual PRInt32 GetSelectedIndex();
NS_IMETHOD SelectItem(PRInt32 aPosition);
NS_IMETHOD Deselect() ;
NS_IMETHOD Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
NS_IMETHOD SetForegroundColor(const nscolor &aColor);
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
// nsIComboBox interface
NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections);
PRInt32 GetSelectedCount();
NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
protected:
Widget mPullDownMenu;
Widget mOptionMenu;
PRBool mMultiSelect;
Widget *mItems;
int mMaxNumItems;
int mNumItems;
};
#endif // nsComboBox_h__

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

@ -38,7 +38,6 @@
#include "nsTextAreaWidget.h"
#include "nsFileWidget.h"
#include "nsListBox.h"
#include "nsComboBox.h"
#include "nsLookAndFeel.h"
#include "nsLabel.h"
// #include "nsFontRetrieverService.h"
@ -62,7 +61,6 @@ static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
static NS_DEFINE_IID(kCButton, NS_BUTTON_CID);
static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID);
static NS_DEFINE_IID(kCCombobox, NS_COMBOBOX_CID);
static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID);
static NS_DEFINE_IID(kCRadioButton, NS_RADIOBUTTON_CID);
@ -180,9 +178,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCCheckButton)) {
inst = (nsISupports*)(nsIWidget *)new nsCheckButton();
}
else if (mClassID.Equals(kCCombobox)) {
inst = (nsISupports*)(nsIWidget *)new nsComboBox();
}
else if (mClassID.Equals(kCRadioButton)) {
inst = (nsISupports*)(nsIWidget *)new nsRadioButton();
}