mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 94627 - removing unused native listbox widget (plus some cleanup from already-removed native widgets). r=shaver, sr=blizzard.
This commit is contained in:
parent
482db0c87a
commit
1d3e6ec608
@ -179,7 +179,6 @@ static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID);
|
||||
static NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID);
|
||||
static NS_DEFINE_CID(kDialogCID, NS_DIALOG_CID);
|
||||
static NS_DEFINE_CID(kCheckButtonCID, NS_CHECKBUTTON_CID);
|
||||
static NS_DEFINE_CID(kRadioButtonCID, NS_RADIOBUTTON_CID);
|
||||
static NS_DEFINE_CID(kLabelCID, NS_LABEL_CID);
|
||||
|
||||
static NS_DEFINE_IID(kIXPBaseWindowIID, NS_IXPBASE_WINDOW_IID);
|
||||
|
@ -50,27 +50,12 @@
|
||||
#if defined(XP_OS2)
|
||||
#define WIDGET_DLL "WDGTOS2"
|
||||
#define GFXWIN_DLL "GFX_OS2"
|
||||
#define VIEW_DLL "NGVIEW"
|
||||
#define WEB_DLL "WEBSHELL"
|
||||
#define DOM_DLL "JSDOM"
|
||||
#define CAPS_DLL "CAPS"
|
||||
#elif defined(XP_PC)
|
||||
#define WIDGET_DLL "gkwidget.dll"
|
||||
#define GFXWIN_DLL "gkgfxwin.dll"
|
||||
#define VIEW_DLL "gkview.dll"
|
||||
#define DOM_DLL "jsdom.dll"
|
||||
#define CAPS_DLL "caps.dll"
|
||||
#elif defined(XP_MAC)
|
||||
#define WIDGET_DLL "WIDGET_DLL"
|
||||
#define GFXWIN_DLL "GFXWIN_DLL"
|
||||
#define VIEW_DLL "VIEW_DLL"
|
||||
#define WEB_DLL "WEB_DLL"
|
||||
#define DOM_DLL "DOM_DLL"
|
||||
#define CAPS_DLL "CAPS_DLL"
|
||||
#else
|
||||
#define VIEW_DLL "libgkview"MOZ_DLL_SUFFIX
|
||||
#define DOM_DLL "libjsdom"MOZ_DLL_SUFFIX
|
||||
#define CAPS_DLL "libcaps"MOZ_DLL_SUFFIX
|
||||
#endif
|
||||
|
||||
// Class ID's
|
||||
@ -111,14 +96,6 @@ static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID);
|
||||
static NS_DEFINE_IID(kCCheckButtonCID, NS_CHECKBUTTON_CID);
|
||||
#endif
|
||||
|
||||
// unneeded widgets
|
||||
#if 0
|
||||
static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID);
|
||||
static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID);
|
||||
static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID);
|
||||
static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID);
|
||||
#endif
|
||||
|
||||
// GFXWIN
|
||||
#if !defined(XP_UNIX) && !defined(XP_OS2) && !defined(XP_WIN)
|
||||
static NS_DEFINE_CID(kCRenderingContextCID, NS_RENDERING_CONTEXT_CID);
|
||||
@ -137,16 +114,6 @@ static NS_DEFINE_CID(kScreenManagerCID, NS_SCREENMANAGER_CID);
|
||||
static NS_DEFINE_CID(kPrintOptionsCID,NS_PRINTOPTIONS_CID);
|
||||
#endif
|
||||
|
||||
// VIEW
|
||||
static NS_DEFINE_IID(kCViewManagerCID, NS_VIEW_MANAGER_CID);
|
||||
static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID);
|
||||
static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID);
|
||||
static NS_DEFINE_IID(kCScrollPortViewCID, NS_SCROLL_PORT_VIEW_CID);
|
||||
|
||||
// DOM
|
||||
static NS_DEFINE_IID(kCDOMScriptObjectFactory, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
|
||||
static NS_DEFINE_IID(kCScriptNameSetRegistry, NS_SCRIPT_NAMESET_REGISTRY_CID);
|
||||
|
||||
extern "C" void
|
||||
NS_SetupRegistry()
|
||||
{
|
||||
@ -211,15 +178,6 @@ NS_SetupRegistry()
|
||||
nsComponentManager::RegisterComponentLib(kCMenuItemCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
#endif
|
||||
|
||||
// UNNEEDED WIDGETS
|
||||
#if 0
|
||||
nsComponentManager::RegisterComponentLib(kCComboBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCContextMenuCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCListBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCRadioButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCTextAreaCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
#endif
|
||||
|
||||
// GFXWIN
|
||||
#if !defined(XP_UNIX) && !defined(XP_OS2) && !defined(XP_WIN)
|
||||
nsComponentManager::RegisterComponentLib(kCRenderingContextCID, "Rendering Context", "@mozilla.org/gfx/renderingcontext;1", GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
||||
@ -238,13 +196,4 @@ NS_SetupRegistry()
|
||||
nsComponentManager::RegisterComponentLib(kPrintOptionsCID, "PrintOptions", "@mozilla.org/gfx/printoptions;1", GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
||||
#endif
|
||||
|
||||
// VIEW
|
||||
nsComponentManager::RegisterComponentLib(kCViewManagerCID, NULL, NULL, VIEW_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCViewCID, NULL, NULL, VIEW_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCScrollingViewCID, NULL, NULL, VIEW_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCScrollPortViewCID, NULL, NULL, VIEW_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
// DOM
|
||||
nsComponentManager::RegisterComponentLib(kCDOMScriptObjectFactory, NULL, NULL, DOM_DLL, PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponentLib(kCScriptNameSetRegistry, NULL, NULL, DOM_DLL, PR_FALSE, PR_FALSE);
|
||||
}
|
||||
|
@ -7,10 +7,8 @@ nsIWidget.h
|
||||
nsIKBStateControl.h
|
||||
nsIButton.h
|
||||
nsICheckButton.h
|
||||
nsIListWidget.h
|
||||
nsITextWidget.h
|
||||
nsITextAreaWidget.h
|
||||
nsIListBox.h
|
||||
nsIScrollbar.h
|
||||
nsGUIEvent.h
|
||||
nsEvent.h
|
||||
|
@ -43,10 +43,8 @@ EXPORTS = \
|
||||
nsIKBStateControl.h \
|
||||
nsIButton.h \
|
||||
nsICheckButton.h \
|
||||
nsIListWidget.h \
|
||||
nsITextWidget.h \
|
||||
nsITextAreaWidget.h \
|
||||
nsIListBox.h \
|
||||
nsIScrollbar.h \
|
||||
nsGUIEvent.h \
|
||||
nsEvent.h \
|
||||
|
@ -1,183 +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 nsIListBox_h__
|
||||
#define nsIListBox_h__
|
||||
|
||||
#include "nsIListWidget.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// {F8030014-C342-11d1-97F0-00609703C14E}
|
||||
#define NS_ILISTBOX_IID \
|
||||
{ 0xf8030014, 0xc342, 0x11d1, { 0x97, 0xf0, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
|
||||
|
||||
|
||||
/**
|
||||
* Initialize list box data
|
||||
*/
|
||||
|
||||
struct nsListBoxInitData : public nsWidgetInitData {
|
||||
nsListBoxInitData()
|
||||
: mMultiSelect(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
PRBool mMultiSelect;
|
||||
};
|
||||
|
||||
/**
|
||||
* Single or multi selection list of items.
|
||||
* Unlike a nsIWidget, The the list widget must automatically clear
|
||||
* itself to the background color when paint messages are generated.
|
||||
* The listbox always has a vertical scrollbar. It never has a
|
||||
* horizontal scrollbar.
|
||||
*/
|
||||
|
||||
class nsIListBox : public nsISupports {
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILISTBOX_IID)
|
||||
|
||||
/**
|
||||
* Set an item at the specific position
|
||||
*
|
||||
* @param aItem the item name. The item has to be null terminated
|
||||
* @param aPosition the position the item should be inserted at
|
||||
* 0 is at the top of the list
|
||||
* -1 is at the end of the list
|
||||
*/
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Finds the first occurrence of the specified item
|
||||
*
|
||||
* @param aItem the string to be filled
|
||||
* @param aStartPos the starting position (index)
|
||||
* @return PR_TRUE if successful, PR_FALSE otherwise
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos) = 0;
|
||||
|
||||
/**
|
||||
* Returns the number of items in the list
|
||||
*
|
||||
* @return the number of items
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 GetItemCount() = 0;
|
||||
|
||||
/**
|
||||
* Remove the first occurrence of the specified item
|
||||
*
|
||||
* @param aPosition the item position
|
||||
* 0 is at the top of the list
|
||||
* -1 is at the end of the list
|
||||
*
|
||||
* @return PR_TRUE if successful, PR_FALSE otherwise
|
||||
*
|
||||
*/
|
||||
virtual PRBool RemoveItemAt(PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Gets an item at a specific location
|
||||
*
|
||||
* @param anItem on return contains the string of the item at that position
|
||||
* @param aPosition the Position of the item
|
||||
*
|
||||
*/
|
||||
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Gets the selected item for a single selection list
|
||||
*
|
||||
* @param aItem on return contains the string of the selected item
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD GetSelectedItem(nsString &aItem) = 0;
|
||||
|
||||
/**
|
||||
* Returns with the index of the selected item
|
||||
*
|
||||
* @return PRInt32, index of selected item
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 GetSelectedIndex() = 0;
|
||||
|
||||
/**
|
||||
* Select the item at the specified position
|
||||
*
|
||||
* @param PRInt32, the item position
|
||||
* 0 is at the top of the list
|
||||
* -1 is at the end of the list
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Deselects all the items in the list
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD Deselect() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Set the listbox to be multi-select.
|
||||
* @param aMultiple PR_TRUE can have multiple selections. PR_FALSE single
|
||||
* selections only.
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
|
||||
NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections) = 0;
|
||||
|
||||
/**
|
||||
* Return the number of selected items. For single selection list box this
|
||||
* @return the number of selected items
|
||||
* can be 1 or 0.
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 GetSelectedCount() = 0;
|
||||
|
||||
/**
|
||||
* Retrieves the indices of the selected items.
|
||||
* @param aIndices Array to hold the selected items. Use GetSelectedCount to
|
||||
* determine how large the array needs to be.
|
||||
* @param aSize Size of the aIndices array
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) = 0;
|
||||
|
||||
/**
|
||||
* Sets the indices of the selected items.
|
||||
* @param aIndices Array to hold the selected items. Use GetSelectedCount to
|
||||
* determine how large the array needs to be.
|
||||
* @param aSize Size of the aIndices array
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsIListBox_h__
|
||||
|
||||
|
||||
|
@ -1,130 +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 nsIListWidget_h__
|
||||
#define nsIListWidget_h__
|
||||
|
||||
#include "nsIWidget.h"
|
||||
#include "nsString.h"
|
||||
|
||||
// {F8030013-C342-11d1-97F0-00609703C14E}
|
||||
#define NS_ILISTWIDGET_IID \
|
||||
{ 0xf8030013, 0xc342, 0x11d1, { 0x97, 0xf0, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
|
||||
|
||||
/**
|
||||
*
|
||||
* Base class for nsIListBox and nsIComboBox
|
||||
*
|
||||
*/
|
||||
|
||||
class nsIListWidget : public nsISupports {
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ILISTWIDGET_IID)
|
||||
|
||||
/**
|
||||
* Set an item at the specific position
|
||||
*
|
||||
* @param aItem the item name. The item has to be null terminated
|
||||
* @param aPosition the position the item should be inserted at
|
||||
* 0 is at the top of the list
|
||||
* -1 is at the end of the list
|
||||
*/
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Finds the first occurrence of the specified item
|
||||
*
|
||||
* @param aItem the string to be filled
|
||||
* @param aStartPos the starting position (index)
|
||||
* @return PR_TRUE if successful, PR_FALSE otherwise
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos) = 0;
|
||||
|
||||
/**
|
||||
* Returns the number of items in the list
|
||||
*
|
||||
* @return the number of items
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 GetItemCount() = 0;
|
||||
|
||||
/**
|
||||
* Remove the first occurrence of the specified item
|
||||
*
|
||||
* @param aPosition the item position
|
||||
* 0 is at the top of the list
|
||||
* -1 is at the end of the list
|
||||
*
|
||||
* @return PR_TRUE if successful, PR_FALSE otherwise
|
||||
*
|
||||
*/
|
||||
virtual PRBool RemoveItemAt(PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Gets an item at a specific location
|
||||
*
|
||||
* @param anItem on return contains the string of the item at that position
|
||||
* @param aPosition the Position of the item
|
||||
*
|
||||
*/
|
||||
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Gets the selected item for a single selection list
|
||||
*
|
||||
* @param aItem on return contains the string of the selected item
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD GetSelectedItem(nsString &aItem) = 0;
|
||||
|
||||
/**
|
||||
* Returns with the index of the selected item
|
||||
*
|
||||
* @return PRInt32, index of selected item
|
||||
*
|
||||
*/
|
||||
virtual PRInt32 GetSelectedIndex() = 0;
|
||||
|
||||
/**
|
||||
* Select the item at the specified position
|
||||
*
|
||||
* @param PRInt32, the item position
|
||||
* 0 is at the top of the list
|
||||
* -1 is at the end of the list
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition) = 0;
|
||||
|
||||
/**
|
||||
* Deselects all the items in the list
|
||||
*
|
||||
*/
|
||||
NS_IMETHOD Deselect() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsIListWidget_h__
|
||||
|
||||
|
||||
|
@ -48,11 +48,6 @@
|
||||
{ 0x2d96b3d3, 0xc051, 0x11d1, \
|
||||
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
|
||||
|
||||
/* 2d96b3d4-c051-11d1-a827-0040959a28c9 */
|
||||
#define NS_COMBOBOX_CID \
|
||||
{ 0x2d96b3d4, 0xc051, 0x11d1, \
|
||||
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
|
||||
|
||||
/* 2d96b3d5-c051-11d1-a827-0040959a28c9 */
|
||||
#define NS_FILEWIDGET_CID \
|
||||
{ 0x2d96b3d5, 0xc051, 0x11d1, \
|
||||
@ -63,16 +58,6 @@
|
||||
{ 0xbd57cee8, 0x1dd1, 0x11b2, \
|
||||
{0x9f, 0xe7, 0x95, 0xcf, 0x47, 0x09, 0xae, 0xa3} }
|
||||
|
||||
/* 2d96b3d6-c051-11d1-a827-0040959a28c9 */
|
||||
#define NS_LISTBOX_CID \
|
||||
{ 0x2d96b3d6, 0xc051, 0x11d1, \
|
||||
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
|
||||
|
||||
/* 2d96b3d7-c051-11d1-a827-0040959a28c9 */
|
||||
#define NS_RADIOBUTTON_CID \
|
||||
{ 0x2d96b3d7, 0xc051, 0x11d1, \
|
||||
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
|
||||
|
||||
/* 2d96b3d9-c051-11d1-a827-0040959a28c9 */
|
||||
#define NS_HORZSCROLLBAR_CID \
|
||||
{ 0x2d96b3d9, 0xc051, 0x11d1, \
|
||||
@ -140,11 +125,6 @@
|
||||
{ 0x7f045771, 0x4beb, 0x11d2, \
|
||||
{ 0x8d, 0xbb, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } }
|
||||
|
||||
// {1677DAE1-04E2-11d3-B35C-00A0CC3C1CDE}
|
||||
#define NS_CONTEXTMENU_CID \
|
||||
{ 0x1677dae1, 0x4e2, 0x11d3, \
|
||||
{ 0xb3, 0x5c, 0x0, 0xa0, 0xcc, 0x3c, 0x1c, 0xde } }
|
||||
|
||||
//f58c2550-4a7c-11d2-bee2-00805f8a8dbd
|
||||
#define NS_IMAGEBUTTON_CID \
|
||||
{ 0xf58c2550, 0x4a7c, 0x11d2, \
|
||||
|
@ -43,7 +43,6 @@ CPPSRCS = \
|
||||
nsFontRetrieverService.cpp \
|
||||
nsFontSizeIterator.cpp \
|
||||
nsLabel.cpp \
|
||||
nsListBox.cpp \
|
||||
nsLookAndFeel.cpp \
|
||||
nsObject.cpp \
|
||||
nsPopUpMenu.cpp \
|
||||
|
@ -1,393 +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 "nsListBox.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsListBox)
|
||||
NS_IMPL_RELEASE(nsListBox)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
mMultiSelect = aMultipleSelections;
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
mListView->SetListType(aMultipleSelections ? B_MULTIPLE_SELECTION_LIST : B_SINGLE_SELECTION_LIST);
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
if (nsnull != aInitData) {
|
||||
nsListBoxInitData* data = (nsListBoxInitData *) aInitData;
|
||||
mMultiSelect = data->mMultiSelect;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
mListView->AddItem(new BStringItem(val), aPosition);
|
||||
NS_FREE_STR_BUF(val);
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
#if 0
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
int index = ::SendMessage(mWnd, LB_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 nsListBox::GetItemCount()
|
||||
{
|
||||
PRInt32 result = 0;
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
result = mListView->CountItems();
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
BListItem *it = mListView->RemoveItem(aPosition);
|
||||
delete it;
|
||||
mListView->UnlockLooper();
|
||||
return it ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
anItem.SetLength(0);
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
BListItem *it = mListView->ItemAt(aPosition);
|
||||
BStringItem *str;
|
||||
if((str = dynamic_cast<BStringItem *>(it)) != 0)
|
||||
{
|
||||
anItem.AppendWithConversion(str->Text());
|
||||
result = PR_TRUE;
|
||||
}
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
GetItemAt(aItem, GetSelectedIndex());
|
||||
} else {
|
||||
NS_ASSERTION(0, "Multi selection list box does not support GetSelectedItem()");
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
if (!mMultiSelect)
|
||||
{
|
||||
PRInt32 index = -1;
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
index = mListView->CurrentSelection();
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return index;
|
||||
} else {
|
||||
NS_ASSERTION(0, "Multi selection list box does not support GetSelectedIndex()");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
mListView->Select(aPosition);
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
PRInt32 inx = GetSelectedIndex();
|
||||
return (inx == -1? 0 : 1);
|
||||
} else {
|
||||
PRInt32 count = 0;
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
int index = 0;
|
||||
while((index = mListView->CurrentSelection(index)) != -1)
|
||||
count++;
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
int index = 0;
|
||||
for(int i = 0; i < aSize; i++)
|
||||
{
|
||||
if(index != -1)
|
||||
index = mListView->CurrentSelection(index);
|
||||
aIndices[i] = index;
|
||||
}
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
mListView->Select(aIndices[0], false);
|
||||
for(int i = 1; i < aSize; i++)
|
||||
mListView->Select(aIndices[i], true);
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
if(mListView && mListView->LockLooper())
|
||||
{
|
||||
mListView->DeselectAll();
|
||||
mListView->UnlockLooper();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// 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);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(kInsListWidgetIID)) {
|
||||
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::OnPaint(nsRect &r)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::OnResize(nsRect &aWindowRect)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Clear window before paint
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
PRBool nsListBox::AutoErase()
|
||||
{
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// get position/dimensions
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::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;
|
||||
}
|
||||
|
||||
BView *nsListBox::CreateBeOSView()
|
||||
{
|
||||
return mListView = new nsListViewBeOS((nsIWidget *)this, BRect(0, 0, 0, 0), "");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Sub-class of BeOS ListView
|
||||
//-------------------------------------------------------------------------
|
||||
nsListViewBeOS::nsListViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||
const char *aName, uint32 aResizingMode, uint32 aFlags )
|
||||
: BListView( aFrame, aName,
|
||||
((nsListBox *)aWidgetWindow)->mMultiSelect ? B_MULTIPLE_SELECTION_LIST : B_SINGLE_SELECTION_LIST,
|
||||
aResizingMode, aFlags ),
|
||||
nsIWidgetStore( aWidgetWindow )
|
||||
{
|
||||
}
|
@ -1,95 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsdefs.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsSwitchToUIThread.h"
|
||||
#include "nsIListBox.h"
|
||||
|
||||
#include <ListView.h>
|
||||
#include <ListItem.h>
|
||||
|
||||
/**
|
||||
* Native Win32 Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWindow,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint(nsRect &r);
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
||||
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||
|
||||
|
||||
// nsIListBox interface
|
||||
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);
|
||||
|
||||
// nsWindow interface
|
||||
virtual PRBool AutoErase();
|
||||
protected:
|
||||
PRBool mMultiSelect;
|
||||
virtual BView *CreateBeOSView();
|
||||
BListView *mListView;
|
||||
|
||||
friend class nsListViewBeOS;
|
||||
};
|
||||
|
||||
//
|
||||
// A BListView subclass
|
||||
//
|
||||
class nsListViewBeOS : public BListView, public nsIWidgetStore {
|
||||
public:
|
||||
nsListViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||
const char *name, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -37,7 +37,6 @@
|
||||
#include "nsTextAreaWidget.h"
|
||||
#include "nsFilePicker.h"
|
||||
#include "nsFileWidget.h"
|
||||
#include "nsListBox.h"
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsLabel.h"
|
||||
#include "nsFontRetrieverService.h"
|
||||
@ -60,7 +59,6 @@ static NS_DEFINE_IID(kCButton, NS_BUTTON_CID);
|
||||
static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_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);
|
||||
static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID);
|
||||
@ -180,9 +178,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
|
||||
else if (mClassID.Equals(kCFilePicker)) {
|
||||
inst = (nsISupports*)(nsBaseFilePicker*)new nsFilePicker();
|
||||
}
|
||||
else if (mClassID.Equals(kCListbox)) {
|
||||
inst = (nsISupports*)(nsWindow *)new nsListBox();
|
||||
}
|
||||
else if (mClassID.Equals(kCHorzScrollbar)) {
|
||||
inst = (nsISupports*)(nsWindow *)new nsScrollbar(PR_FALSE);
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "nsIButton.h"
|
||||
#include "nsIEventListener.h"
|
||||
#include "nsILabel.h"
|
||||
#include "nsIListBox.h"
|
||||
#include "nsIListWidget.h"
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsIMouseListener.h"
|
||||
@ -218,36 +217,6 @@ NS_CreateScrollBar(nsISupports* aParent,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_WIDGET nsresult
|
||||
NS_CreateListBox(nsISupports* aParent,
|
||||
nsIListBox* aWidget,
|
||||
const nsRect& aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
const nsFont* aFont)
|
||||
{
|
||||
nsIWidget* parent = nsnull;
|
||||
if (aParent != nsnull)
|
||||
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||
|
||||
nsIWidget* widget = nsnull;
|
||||
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||
widget->Show(PR_TRUE);
|
||||
if (aFont != nsnull)
|
||||
widget->SetFont(*aFont);
|
||||
NS_IF_RELEASE(widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||
}
|
||||
|
||||
if (aParent)
|
||||
NS_IF_RELEASE(parent);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
extern NS_WIDGET nsresult
|
||||
NS_ShowWidget(nsISupports* aWidget, PRBool aShow)
|
||||
{
|
||||
|
@ -1,394 +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 <gtk/gtk.h>
|
||||
|
||||
#include "nsListBox.h"
|
||||
#include "nsString.h"
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsListBox, nsWidget)
|
||||
NS_IMPL_RELEASE_INHERITED(nsListBox, nsWidget)
|
||||
NS_IMPL_QUERY_INTERFACE3(nsListBox, nsIListBox, nsIListWidget, nsIWidget)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMultiSelect = PR_FALSE;
|
||||
mCList = nsnull;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::~nsListBox()
|
||||
{
|
||||
}
|
||||
|
||||
void nsListBox::InitCallbacks(char * aName)
|
||||
{
|
||||
InstallButtonPressSignal(mCList);
|
||||
InstallButtonReleaseSignal(mCList);
|
||||
|
||||
InstallEnterNotifySignal(mCList);
|
||||
InstallLeaveNotifySignal(mCList);
|
||||
|
||||
// These are needed so that the events will go to us and not our parent.
|
||||
AddToEventMask(mCList,
|
||||
GDK_BUTTON_PRESS_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK |
|
||||
GDK_ENTER_NOTIFY_MASK |
|
||||
GDK_EXPOSURE_MASK |
|
||||
GDK_FOCUS_CHANGE_MASK |
|
||||
GDK_KEY_PRESS_MASK |
|
||||
GDK_KEY_RELEASE_MASK |
|
||||
GDK_LEAVE_NOTIFY_MASK |
|
||||
GDK_POINTER_MOTION_MASK);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
mMultiSelect = aMultipleSelections;
|
||||
if (mCList) {
|
||||
if (mMultiSelect)
|
||||
gtk_clist_set_selection_mode(GTK_CLIST(mCList), GTK_SELECTION_MULTIPLE);
|
||||
else
|
||||
gtk_clist_set_selection_mode(GTK_CLIST(mCList), GTK_SELECTION_BROWSE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
if (mCList) {
|
||||
gchar *text[2];
|
||||
const nsAutoCString tempStr(aItem);
|
||||
text[0] = (gchar*)(const char *)tempStr;
|
||||
text[1] = (gchar*)NULL;
|
||||
gtk_clist_insert(GTK_CLIST(mCList), (int)aPosition, text);
|
||||
|
||||
// XXX Im not sure using the string address is the right thing to
|
||||
// store in the row data.
|
||||
gtk_clist_set_row_data(GTK_CLIST(mCList), aPosition, (gpointer)&aItem);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
int i = -1;
|
||||
if (mCList) {
|
||||
i = gtk_clist_find_row_from_data(GTK_CLIST(mCList), (gpointer)&aItem);
|
||||
if (i < aStartPos) {
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
if (mCList) {
|
||||
return GTK_CLIST(mCList)->rows;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
if (mCList) {
|
||||
gtk_clist_remove(GTK_CLIST(mCList), aPosition);
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
anItem.Truncate();
|
||||
if (mCList) {
|
||||
char *text = nsnull;
|
||||
gtk_clist_get_text(GTK_CLIST(mCList),aPosition,0,&text);
|
||||
if (text) {
|
||||
anItem.AppendWithConversion(text);
|
||||
result = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
aItem.Truncate();
|
||||
if (mCList) {
|
||||
PRInt32 i=0, idx=-1;
|
||||
GtkCList *clist = GTK_CLIST(mCList);
|
||||
GList *list = clist->row_list;
|
||||
|
||||
for (i=0; i < clist->rows && idx == -1; i++, list = list->next) {
|
||||
if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) {
|
||||
char *text = nsnull;
|
||||
gtk_clist_get_text(GTK_CLIST(mCList),i,0,&text);
|
||||
if (text) {
|
||||
aItem.AppendWithConversion(text);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
PRInt32 i=0, idx=-1;
|
||||
if (mCList) {
|
||||
if (!mMultiSelect) {
|
||||
GtkCList *clist = GTK_CLIST(mCList);
|
||||
GList *list = clist->row_list;
|
||||
|
||||
for (i=0; i < clist->rows && idx == -1; i++, list = list->next) {
|
||||
if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) {
|
||||
idx = i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "Multi selection list box does not support GetSelectedIndex()");
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
if (mCList) {
|
||||
gtk_clist_select_row(GTK_CLIST(mCList), aPosition, 0);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
if (mCList) {
|
||||
if (!GTK_CLIST(mCList)->selection)
|
||||
return 0;
|
||||
else
|
||||
return (PRInt32)g_list_length(GTK_CLIST(mCList)->selection);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
if (mCList) {
|
||||
PRInt32 i=0, num = 0;
|
||||
GtkCList *clist = GTK_CLIST(mCList);
|
||||
GList *list = clist->row_list;
|
||||
|
||||
for (i=0; i < clist->rows && num < aSize; i++, list = list->next) {
|
||||
if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) {
|
||||
aIndices[num] = i;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRInt32 i = 0;
|
||||
for (i = 0; i < aSize; i++) aIndices[i] = 0;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
if (mCList) {
|
||||
gtk_clist_unselect_all(GTK_CLIST(mCList));
|
||||
int i;
|
||||
for (i=0;i<aSize;i++) {
|
||||
SelectItem(aIndices[i]);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::Deselect()
|
||||
{
|
||||
if (mCList) {
|
||||
gtk_clist_unselect_all(GTK_CLIST(mCList));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set initial parameters
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
if (nsnull != aInitData) {
|
||||
nsListBoxInitData* data = (nsListBoxInitData *) aInitData;
|
||||
mMultiSelect = data->mMultiSelect;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Create the native widget
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::CreateNative(GtkObject *parentWindow)
|
||||
{
|
||||
// to handle scrolling
|
||||
mWidget = gtk_scrolled_window_new (nsnull, nsnull);
|
||||
gtk_widget_set_name(mWidget, "nsListBox");
|
||||
gtk_container_set_border_width(GTK_CONTAINER(mWidget), 0);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mWidget),
|
||||
GTK_POLICY_NEVER,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
|
||||
mCList = ::gtk_clist_new(1);
|
||||
gtk_clist_column_titles_hide(GTK_CLIST(mCList));
|
||||
// Default (it may be changed)
|
||||
gtk_clist_set_selection_mode(GTK_CLIST(mCList), GTK_SELECTION_BROWSE);
|
||||
SetMultipleSelection(mMultiSelect);
|
||||
gtk_widget_show(mCList);
|
||||
gtk_signal_connect(GTK_OBJECT(mCList),
|
||||
"destroy",
|
||||
GTK_SIGNAL_FUNC(DestroySignal),
|
||||
this);
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (mWidget), mCList);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsListBox::OnDestroySignal(GtkWidget* aGtkWidget)
|
||||
{
|
||||
if (aGtkWidget == mCList) {
|
||||
mCList = nsnull;
|
||||
}
|
||||
else {
|
||||
nsWidget::OnDestroySignal(aGtkWidget);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// set font for listbox
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
/*virtual*/
|
||||
void nsListBox::SetFontNative(GdkFont *aFont)
|
||||
{
|
||||
GtkStyle *style = gtk_style_copy(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0))->style);
|
||||
// gtk_style_copy ups the ref count of the font
|
||||
gdk_font_unref (style->font);
|
||||
|
||||
style->font = aFont;
|
||||
gdk_font_ref(style->font);
|
||||
|
||||
gtk_widget_set_style(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0)), style);
|
||||
|
||||
gtk_style_unref(style);
|
||||
}
|
@ -1,70 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIListBox.h"
|
||||
|
||||
/**
|
||||
* Native GTK+ Listbox wrapper
|
||||
*/
|
||||
class nsListBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIListBox interface
|
||||
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||
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() ;
|
||||
|
||||
virtual void SetFontNative(GdkFont *aFont);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD CreateNative(GtkObject *parentWindow);
|
||||
virtual void InitCallbacks(char * aName = nsnull);
|
||||
virtual void OnDestroySignal(GtkWidget* aGtkWidget);
|
||||
|
||||
GtkWidget *mCList;
|
||||
PRBool mMultiSelect;
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -1,561 +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 "nsListBox.h"
|
||||
#include "nsMacResources.h"
|
||||
#include <StringCompare.h>
|
||||
#include <Resources.h>
|
||||
#include <Folders.h>
|
||||
#include <Appearance.h>
|
||||
#if TARGET_CARBON
|
||||
#include <ControlDefinitions.h>
|
||||
#endif
|
||||
|
||||
NS_IMPL_ADDREF(nsListBox);
|
||||
NS_IMPL_RELEASE(nsListBox);
|
||||
|
||||
typedef struct ldesRsrc
|
||||
{
|
||||
short version;
|
||||
short rows;
|
||||
short cols;
|
||||
short cellHeight;
|
||||
short cellWidth;
|
||||
Boolean vertScroll;
|
||||
Boolean __pad1;
|
||||
Boolean horizScroll;
|
||||
Boolean __pad2;
|
||||
short ldefID;
|
||||
Boolean hasGrow;
|
||||
Boolean __pad3;
|
||||
} ldesRsrc;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::nsListBox() : nsMacControl(), nsIListWidget(), nsIListBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
gInstanceClassName = "nsListBox";
|
||||
SetControlType(kControlListBoxProc);
|
||||
|
||||
mListHandle = nsnull;
|
||||
mMultiSelect = PR_FALSE;
|
||||
|
||||
AcceptFocusOnClick(PR_TRUE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::~nsListBox()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsListBox::GetRectForMacControl(nsRect &outRect)
|
||||
{
|
||||
outRect = mBounds;
|
||||
outRect.x = outRect.y = 0;
|
||||
// inset to make space for border
|
||||
outRect.Deflate(2, 2);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
#define kLDESRsrcID 128 // The Appearance Manager needs a 'ldes' resource to create list controls
|
||||
|
||||
nsMacResources::OpenLocalResourceFile();
|
||||
|
||||
mValue = kLDESRsrcID;
|
||||
nsresult res = Inherited::Create(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData);
|
||||
mValue = 0;
|
||||
|
||||
nsMacResources::CloseLocalResourceFile();
|
||||
|
||||
if (res == NS_OK)
|
||||
{
|
||||
Size actualSize;
|
||||
::GetControlData(mControl, kControlNoPart, kControlListBoxListHandleTag, sizeof(ListHandle), (Ptr)&mListHandle, &actualSize);
|
||||
if (mListHandle)
|
||||
{
|
||||
SetMultipleSelection(mMultiSelect);
|
||||
StartDraw();
|
||||
::LSetDrawingMode(mVisible, mListHandle);
|
||||
::SetControlMinimum(mControl, 0);
|
||||
::SetControlMaximum(mControl, 0);
|
||||
::SetControlValue(mControl, 0);
|
||||
EndDraw();
|
||||
}
|
||||
else
|
||||
res = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_INTERFACE_MAP_BEGIN(nsListBox)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIListBox)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIListWidget)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsWindow)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsListBox::Show(PRBool bState)
|
||||
{
|
||||
if (! mListHandle)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (mVisible == bState)
|
||||
return NS_OK;
|
||||
|
||||
Inherited::Show(bState);
|
||||
StartDraw();
|
||||
::LSetDrawingMode(bState, mListHandle);
|
||||
EndDraw();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetMultipleSelection
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool 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;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsListBox::AddItemAt(nsString &aItem, PRInt32 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;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 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;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
if (! mListHandle)
|
||||
return 0;
|
||||
|
||||
return (*mListHandle)->dataBounds.bottom;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
if (! mListHandle)
|
||||
return PR_FALSE;
|
||||
|
||||
if (GetItemCount() < aPosition)
|
||||
return PR_FALSE;
|
||||
|
||||
StartDraw();
|
||||
::LDelRow(1, aPosition, mListHandle);
|
||||
::SetControlMaximum(mControl, GetItemCount());
|
||||
EndDraw();
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 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 content of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsListBox::GetSelectedItem(nsString& 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 items
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::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);
|
||||
}
|
||||
::LAutoScroll(mListHandle);
|
||||
::LSetDrawingMode(mVisible, mListHandle);
|
||||
EndDraw();
|
||||
|
||||
Invalidate(PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
if (! mListHandle)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (GetItemCount() < aPosition)
|
||||
return PR_FALSE;
|
||||
|
||||
if (! mMultiSelect)
|
||||
Deselect();
|
||||
|
||||
StartDraw();
|
||||
Cell theCell;
|
||||
::SetPt(&theCell, 0, aPosition);
|
||||
::LSetSelect(true, theCell, mListHandle);
|
||||
::LAutoScroll(mListHandle);
|
||||
EndDraw();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsListBox::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(mVisible, mListHandle);
|
||||
EndDraw();
|
||||
|
||||
Invalidate(PR_TRUE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// DispatchMouseEvent
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::DispatchMouseEvent(nsMouseEvent &aEvent)
|
||||
{
|
||||
PRBool eventHandled = PR_FALSE;
|
||||
switch (aEvent.message)
|
||||
{
|
||||
case NS_MOUSE_LEFT_DOUBLECLICK:
|
||||
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
||||
eventHandled = Inherited::DispatchMouseEvent(aEvent);
|
||||
if (!eventHandled && mListHandle != NULL) {
|
||||
EventRecord* macEvent = (EventRecord*)aEvent.nativeMsg;
|
||||
|
||||
StartDraw();
|
||||
Point where = macEvent->where;
|
||||
::GlobalToLocal(&where);
|
||||
::HandleControlClick(mControl, where, macEvent->modifiers, NULL);
|
||||
// ::LClick(where, macEvent->modifiers, mListHandle);
|
||||
EndDraw();
|
||||
|
||||
ControlChanged(GetSelectedIndex());
|
||||
|
||||
// since the mouseUp event will be consumed by TrackControl,
|
||||
// simulate the mouse up event immediately.
|
||||
nsMouseEvent mouseUpEvent = aEvent;
|
||||
mouseUpEvent.message = NS_MOUSE_LEFT_BUTTON_UP;
|
||||
Inherited::DispatchMouseEvent(mouseUpEvent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (Inherited::DispatchMouseEvent(aEvent));
|
||||
}
|
||||
|
||||
PRBool nsListBox::DispatchWindowEvent(nsGUIEvent& aEvent)
|
||||
{
|
||||
PRBool eventHandled = Inherited::DispatchWindowEvent(aEvent);
|
||||
if (!eventHandled && mListHandle != NULL) {
|
||||
if (aEvent.message == NS_KEY_DOWN) {
|
||||
EventRecord* macEvent = (EventRecord*)aEvent.nativeMsg;
|
||||
SInt16 keyCode = (macEvent->message & keyCodeMask) >> 8;
|
||||
SInt16 charCode = (macEvent->message & charCodeMask);
|
||||
StartDraw();
|
||||
::HandleControlKey(mControl, keyCode, charCode, macEvent->modifiers);
|
||||
nsKeyEvent* keyEvent = (nsKeyEvent*)&aEvent;
|
||||
switch (keyEvent->keyCode) {
|
||||
case NS_VK_UP:
|
||||
case NS_VK_DOWN:
|
||||
::LAutoScroll(mListHandle);
|
||||
break;
|
||||
}
|
||||
EndDraw();
|
||||
eventHandled = PR_TRUE;
|
||||
} else {
|
||||
switch (aEvent.message) {
|
||||
case NS_GOTFOCUS:
|
||||
case NS_LOSTFOCUS:
|
||||
StartDraw();
|
||||
::SetKeyboardFocus(mWindowPtr, mControl, (aEvent.message == NS_GOTFOCUS ? kControlFocusNextPart : kControlFocusNoPart));
|
||||
EndDraw();
|
||||
eventHandled = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return eventHandled;
|
||||
}
|
@ -1,88 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsMacControl.h"
|
||||
#include "nsIListBox.h"
|
||||
#include <Lists.h>
|
||||
|
||||
|
||||
class nsListBox : public nsMacControl,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
private:
|
||||
typedef nsMacControl Inherited;
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
// nsIWidget
|
||||
NS_IMETHODIMP Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
NS_IMETHOD Show(PRBool aState);
|
||||
|
||||
// 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);
|
||||
|
||||
// nsWindow
|
||||
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
|
||||
virtual PRBool DispatchWindowEvent(nsGUIEvent& aEvent);
|
||||
|
||||
protected:
|
||||
// nsMacControl
|
||||
virtual void GetRectForMacControl(nsRect &outRect);
|
||||
|
||||
protected:
|
||||
ListHandle mListHandle;
|
||||
PRBool mMultiSelect;
|
||||
};
|
||||
|
||||
|
||||
#endif // nsListBox_h__
|
@ -63,7 +63,6 @@
|
||||
|
||||
#if USE_NATIVE_VERSION
|
||||
# include "nsTextAreaWidget.h"
|
||||
# include "nsListBox.h"
|
||||
# include "nsCheckButton.h"
|
||||
#endif
|
||||
|
||||
@ -89,7 +88,6 @@ static NS_DEFINE_CID(kCButton, NS_BUTTON_CID);
|
||||
static NS_DEFINE_CID(kCCheckButton, NS_CHECKBUTTON_CID);
|
||||
static NS_DEFINE_CID(kCFilePicker, NS_FILEPICKER_CID);
|
||||
static NS_DEFINE_CID(kCFileOpen, NS_FILEWIDGET_CID);
|
||||
static NS_DEFINE_CID(kCListbox, NS_LISTBOX_CID);
|
||||
static NS_DEFINE_CID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
|
||||
static NS_DEFINE_CID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
|
||||
static NS_DEFINE_CID(kCTextArea, NS_TEXTAREA_CID);
|
||||
@ -210,9 +208,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
|
||||
else if (mClassID.Equals(kCCheckButton)) {
|
||||
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsCheckButton();
|
||||
}
|
||||
else if (mClassID.Equals(kCListbox)) {
|
||||
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsListBox();
|
||||
}
|
||||
else if (mClassID.Equals(kCTextArea)) {
|
||||
inst = (nsISupports*)(nsBaseWidget*)(nsWindow*)new nsTextAreaWidget();
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ CPPSRCS = \
|
||||
nsCheckButton.cpp \
|
||||
nsFileWidget.cpp \
|
||||
nsLabel.cpp \
|
||||
nsListBox.cpp \
|
||||
nsLookAndFeel.cpp \
|
||||
nsMenu.cpp \
|
||||
nsMenuBar.cpp \
|
||||
|
@ -1,420 +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 "nsListBox.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include <Xm/List.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
mMultiSelect = aMultipleSelections;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD 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);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// 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 inx = XmListItemPos(mWidget, str)-1;
|
||||
if (inx < aStartPos) {
|
||||
inx = -1;
|
||||
}
|
||||
NS_FREE_STR_BUF(val);
|
||||
XmStringFree(str);
|
||||
|
||||
return inx;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
int * list;
|
||||
int count;
|
||||
|
||||
if (XmListGetSelectedPos(mWidget, &list, &count)) {
|
||||
GetItemAt(aItem, list[0]-1);
|
||||
XtFree((char *)list);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
int * list;
|
||||
int count;
|
||||
|
||||
if (XmListGetSelectedPos(mWidget, &list, &count)) {
|
||||
int inx = -1;
|
||||
if (count > 0) {
|
||||
inx = list[0]-1;
|
||||
}
|
||||
XtFree((char *)list);
|
||||
return inx;
|
||||
}
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "Multi selection list box does not support GetSelectedIndex()");
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
|
||||
if (aPosition >= 0 && aPosition < count) {
|
||||
XmListSelectPos(mWidget, aPosition+1, FALSE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
int count = 0;
|
||||
XtVaGetValues(mWidget, XmNselectedItemCount, &count, nsnull);
|
||||
return (PRInt32)count;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD 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);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD 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]);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
XtVaSetValues(mWidget, XmNselectedItemCount, 0, NULL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD 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 (aParent) {
|
||||
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
} else {
|
||||
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
|
||||
}
|
||||
|
||||
InitToolkit(aToolkit, aParent);
|
||||
InitDeviceContext(aContext, 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);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
//InitCallbacks();
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::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 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;
|
||||
}
|
||||
|
||||
|
@ -1,90 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsIListBox.h"
|
||||
|
||||
/**
|
||||
* Native Motif Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWindow,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
|
||||
NS_IMETHOD Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIAppShell *aAppShell = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
NS_IMETHOD 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
|
||||
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() ;
|
||||
|
||||
protected:
|
||||
PRBool mMultiSelect;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -36,7 +36,6 @@
|
||||
#include "nsTextWidget.h"
|
||||
#include "nsTextAreaWidget.h"
|
||||
#include "nsFileWidget.h"
|
||||
#include "nsListBox.h"
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsLabel.h"
|
||||
// #include "nsFontRetrieverService.h"
|
||||
@ -61,7 +60,6 @@ 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(kCFileOpen, NS_FILEWIDGET_CID);
|
||||
static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID);
|
||||
static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID);
|
||||
@ -179,9 +177,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
|
||||
else if (mClassID.Equals(kCFileOpen)) {
|
||||
inst = (nsISupports*)(nsIWidget *)new nsFileWidget();
|
||||
}
|
||||
else if (mClassID.Equals(kCListbox)) {
|
||||
inst = (nsISupports*)(nsIWidget *)new nsListBox();
|
||||
}
|
||||
else if (mClassID.Equals(kCHorzScrollbar)) {
|
||||
inst = (nsISupports*)(nsIWidget *)new nsScrollbar(PR_FALSE);
|
||||
}
|
||||
|
@ -1,521 +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 "nsListBox.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include <Pt.h>
|
||||
#include "nsPhWidgetLog.h"
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsListBox)
|
||||
NS_IMPL_RELEASE(nsListBox)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMultiSelect = PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::~nsListBox()
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::~nsListBox - Destructor Called\n"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult result = nsWidget::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;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::SetMultipleSelection aMultipleSelections=<%d>\n", aMultipleSelections));
|
||||
|
||||
PtArg_t arg;
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
mMultiSelect = aMultipleSelections;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
if (mMultiSelect)
|
||||
PtSetArg( &arg, Pt_ARG_SELECTION_MODE, (Pt_EXTENDED_MODE), 0);
|
||||
else
|
||||
PtSetArg( &arg, Pt_ARG_SELECTION_MODE, (Pt_SINGLE_MODE), 0);
|
||||
|
||||
if ( PtSetResources(mWidget, 1, &arg ) == 0)
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
char *str = aItem.ToNewCString();
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::AddItemAt aItem=<%s> aPosition=<%d>\n", str, aPosition));
|
||||
|
||||
PtArg_t arg;
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
int err;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
err = PtListAddItems(mWidget, (const char **) &str, 1, (unsigned int) (aPosition+1));
|
||||
if (err == 0)
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
delete [] str;
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
char *str = aItem.ToNewCString();
|
||||
int index = -1;
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::AddItemAt aItem=<%s> aStartPos=<%d>\n", str, aStartPos));
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
index = PtListItemPos(mWidget, str);
|
||||
if (index == 0)
|
||||
index = -1; /* item wasn't found */
|
||||
}
|
||||
|
||||
|
||||
delete [] str;
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
PtArg_t arg;
|
||||
short *theCount;
|
||||
PRInt32 total = 0;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PtSetArg( &arg, Pt_ARG_LIST_ITEM_COUNT, &theCount, 0);
|
||||
PtGetResources(mWidget, 1, &arg );
|
||||
|
||||
total = *theCount;
|
||||
}
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetItemCount is <%d>\n", total));
|
||||
return total;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::RemoveItemAt %d\n", aPosition));
|
||||
|
||||
int err;
|
||||
PRBool res = PR_FALSE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
if (PtListDeleteItemPos(mWidget, 1, (aPosition+1)) == 0)
|
||||
res = PR_TRUE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
short *num;
|
||||
char **items;
|
||||
PtArg_t arg;
|
||||
|
||||
/* Clear the nsString */
|
||||
anItem.SetLength(0);
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PtSetArg( &arg, Pt_ARG_ITEMS, &items, &num);
|
||||
PtGetResources(mWidget, 1, &arg );
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetItemAt aPosition=<%d> aItem=<%s>\n", aPosition, items[aPosition]));
|
||||
|
||||
anItem.Append(items[aPosition]);
|
||||
result = PR_TRUE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the text from the first selected Item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
int theFirstSelectedItem = GetSelectedIndex();
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedItem theFirstSelectedItem is <%d>\n", theFirstSelectedItem));
|
||||
|
||||
GetItemAt(aItem, theFirstSelectedItem);
|
||||
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected items
|
||||
// Gets the Position of the first selected Item or -1 if no items.
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndex - Not Implemented\n"));
|
||||
|
||||
PRInt32 index=-1;
|
||||
int theFirstSelectedItem[1];
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
GetSelectedIndices(theFirstSelectedItem, 1);
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndex theFirstSelectedItem is <%d>\n", theFirstSelectedItem[0]));
|
||||
|
||||
index = theFirstSelectedItem[0];
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::SelectItem %d\n", aPosition));
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PtListSelectPos(mWidget, (aPosition+1)); /* Photon is 1 based */
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
PtArg_t arg;
|
||||
short *theCount;
|
||||
PRInt32 total = 0;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PtSetArg( &arg, Pt_ARG_LIST_SEL_COUNT, &theCount, 0);
|
||||
PtGetResources(mWidget, 1, &arg );
|
||||
|
||||
total = *theCount;
|
||||
}
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedCount theCount=<%d>\n", total));
|
||||
return total;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices aSize=<%d>\n", aSize));
|
||||
|
||||
PRInt32 i=0, num = 0;
|
||||
short *theSelectedIndices, *theSelectedCount;
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
PtArg_t arg;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PtSetArg( &arg, Pt_ARG_SELECTION_INDEXES, &theSelectedIndices, &theSelectedCount);
|
||||
PtGetResources(mWidget, 1, &arg );
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices Found %d Selected Items\n", *theSelectedCount));
|
||||
|
||||
for (i=0; i < *theSelectedCount && i < aSize; i++)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices %d is Selected.\n", theSelectedIndices[i]));
|
||||
|
||||
aIndices[i] = (theSelectedIndices[i]-1) ; /* photon is 1 based, mozilla appears to be 0 based */
|
||||
}
|
||||
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::SetSelectedIndices\n"));
|
||||
|
||||
/* De-Select Everything ... */
|
||||
Deselect();
|
||||
|
||||
int i;
|
||||
for (i=0;i<aSize;i++)
|
||||
{
|
||||
SelectItem(aIndices[i]);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::Deselect\n"));
|
||||
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
const int theSelectedCount = GetSelectedCount();
|
||||
int theList[theSelectedCount];
|
||||
int i;
|
||||
|
||||
GetSelectedIndices(theList, theSelectedCount);
|
||||
for(i=0;i<theSelectedCount;i++)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::Deselect Unselecting <%d>\n", theList[i]));
|
||||
PtListUnselectPos(mWidget, theList[i]);
|
||||
}
|
||||
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set initial parameters
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::PreCreateWidget - Not Implemented\n"));
|
||||
|
||||
if (nsnull != aInitData) {
|
||||
nsListBoxInitData* data = (nsListBoxInitData *) aInitData;
|
||||
mMultiSelect = data->mMultiSelect;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Create the native widget
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::CreateNative(PtWidget_t *parentWindow)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::CreateNative\n"));
|
||||
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
PtArg_t arg[5];
|
||||
PhPoint_t pos;
|
||||
PhDim_t dim;
|
||||
|
||||
pos.x = mBounds.x;
|
||||
pos.y = mBounds.y;
|
||||
dim.w = mBounds.width - 4; // Correct for border width
|
||||
dim.h = mBounds.height - 4;
|
||||
|
||||
PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 );
|
||||
PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 );
|
||||
PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 2, 0 );
|
||||
|
||||
mWidget = PtCreateWidget( PtList, parentWindow, 3, arg );
|
||||
if( mWidget )
|
||||
{
|
||||
res = NS_OK;
|
||||
|
||||
/* Mozilla calls this first before we have a widget so re-call this */
|
||||
SetMultipleSelection(mMultiSelect);
|
||||
|
||||
/* Add a Callback so I can keep track of whats selected or not */
|
||||
// PtAddCallback(mWidget, Pt_CB_SELECTION, handle_selection_event, this);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::OnMove - Not Implemented\n"));
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint message. Don't send the paint out
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::OnPaint(nsPaintEvent &aEvent)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::OnPaint - Not Implemented\n"));
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::OnResize - Not Implemented\n"));
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Callback when user selects or deselects an item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
int nsListBox::handle_selection_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo )
|
||||
{
|
||||
nsListBox *me = (nsListBox *) aData;
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsListBox::handle_select_event widget=<%p>\n",me));
|
||||
|
||||
if ((me) && (aCbinfo->reason == Pt_CB_SELECTION) &&
|
||||
(aCbinfo->reason_subtype == Pt_LIST_SELECTION_FINAL))
|
||||
{
|
||||
PtListCallback_t *ListCallback = (PtListCallback_t *) aCbinfo->cbdata;
|
||||
|
||||
// PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsListBox::handle_select_event mode=<%d>\n",ListCal));
|
||||
|
||||
}
|
||||
|
||||
return (Pt_CONTINUE);
|
||||
}
|
@ -1,76 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIListBox.h"
|
||||
|
||||
/**
|
||||
* Native Photon Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
|
||||
// nsIListBox interface
|
||||
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||
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() ;
|
||||
|
||||
protected:
|
||||
NS_IMETHOD CreateNative(PtWidget_t *parentWindow);
|
||||
static int handle_selection_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo );
|
||||
|
||||
PRBool mMultiSelect;
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -3,7 +3,6 @@ moc_nsQApplication.cpp
|
||||
moc_nsLabel.cpp
|
||||
moc_nsScrollbar.cpp
|
||||
moc_nsButton.cpp
|
||||
moc_nsListBox.cpp
|
||||
moc_nsTextAreaWidget.cpp
|
||||
moc_nsCheckButton.cpp
|
||||
moc_nsTextWidget.cpp
|
||||
|
@ -1,384 +0,0 @@
|
||||
/* -*- 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.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 "nsListBox.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// nsQListBox class
|
||||
//
|
||||
//=============================================================================
|
||||
nsQListBox::nsQListBox(nsWidget * widget,
|
||||
QWidget * parent,
|
||||
const char * name,
|
||||
WFlags f)
|
||||
: QListBox(parent, name, f), nsQBaseWidget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsQListBox::~nsQListBox()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsListBox, nsWidget)
|
||||
NS_IMPL_RELEASE_INHERITED(nsListBox, nsWidget)
|
||||
NS_IMPL_QUERY_INTERFACE3(nsListBox, nsIListBox, nsIListWidget, nsIWidget)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::nsListBox()\n"));
|
||||
NS_INIT_REFCNT();
|
||||
mMultiSelect = PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsListBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsListBox::~nsListBox()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::~nsListBox()\n"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::SetMultipleSelection()\n"));
|
||||
mMultiSelect = aMultipleSelections;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
((QListBox *)mWidget)->setMultiSelection(mMultiSelect);
|
||||
QListBox::SelectionMode mode = (mMultiSelect ? QListBox::Multi : QListBox::Single);
|
||||
((QListBox *)mWidget)->setSelectionMode(mode);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
char *buf = aItem.ToNewCString();
|
||||
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::AddItemAt: %s at %d\n",
|
||||
buf,
|
||||
aPosition));
|
||||
|
||||
((QListBox *)mWidget)->insertItem(buf, aPosition);
|
||||
|
||||
delete[] buf;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
int i;
|
||||
PRInt32 index = -1;
|
||||
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::FindItem: find %s at %d\n",
|
||||
val,
|
||||
aStartPos));
|
||||
|
||||
int count = ((QListBox *)mWidget)->count();
|
||||
|
||||
for (i = aStartPos; i < count; i++)
|
||||
{
|
||||
QString string = ((QListBox*)mWidget)->text(i);
|
||||
|
||||
if (string == val)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NS_FREE_STR_BUF(val);
|
||||
|
||||
if (index < aStartPos)
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::FindItem: returning %d \n",
|
||||
index));
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
PRInt32 count = ((QListBox *)mWidget)->count();
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::GetItemCount: count=%d\n",
|
||||
count));
|
||||
return count;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::RemoveItemAt: remove at %d\n",
|
||||
aPosition));
|
||||
((QListBox *)mWidget)->removeItem(aPosition);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::GetItemAt: get at %d\n",
|
||||
aPosition));
|
||||
PRBool result = PR_FALSE;
|
||||
|
||||
QString text = ((QListBox *)mWidget)->text(aPosition);
|
||||
|
||||
anItem.SetLength(0);
|
||||
anItem.AppendWithConversion((const char *) text);
|
||||
result = PR_TRUE;
|
||||
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::GetItemAt: returning %s\n",
|
||||
(const char *) text));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the text of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::GetSelectedItem()\n"));
|
||||
int item = ((QListBox *) mWidget)->currentItem();
|
||||
|
||||
QString text = ((QListBox *) mWidget)->text(item);
|
||||
|
||||
aItem.SetLength(0);
|
||||
aItem.AppendWithConversion((const char *) text);
|
||||
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsListBox::GetSelectedItem: returning %s\n",
|
||||
(const char *)text));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
PRInt32 index=-1;
|
||||
if (!mMultiSelect)
|
||||
{
|
||||
index = ((QListBox *)mWidget)->currentItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "Multi selection list box doesn't support GetSelectedIndex()");
|
||||
}
|
||||
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsListBox::GetSelectedIndex: returning %d\n",
|
||||
index));
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::SelectItem at %d\n",
|
||||
aPosition));
|
||||
//((QListBox *)mWidget)->setCurrentItem(aPosition);
|
||||
if (!mMultiSelect)
|
||||
{
|
||||
((QListBox *)mWidget)->setCurrentItem(aPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
((QListBox *)mWidget)->setSelected(aPosition, true);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
PRInt32 i = 0;
|
||||
PRInt32 selectedCount = 0;
|
||||
PRInt32 count = GetItemCount();
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (((QListBox *)mWidget)->isSelected(i))
|
||||
{
|
||||
selectedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsListBox::GetSelectedCount returning %d\n", selectedCount));
|
||||
|
||||
return selectedCount;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices()\n"));
|
||||
PRInt32 i = 0;
|
||||
PRInt32 num = 0;
|
||||
PRInt32 count = GetItemCount();
|
||||
|
||||
for (i = 0; i < count && num < aSize; i++)
|
||||
{
|
||||
if (((QListBox *)mWidget)->isSelected(i))
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsListBox::GetSelectedIndices: %d is selected\n",
|
||||
i));
|
||||
aIndices[num] = i;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::SetSelectedIndices()\n"));
|
||||
PRInt32 i = 0;
|
||||
|
||||
Deselect();
|
||||
|
||||
GetSelectedCount();
|
||||
|
||||
for (i = 0; i < aSize; i++)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsListBox::SetSelectedIndices: setting %d\n",
|
||||
aIndices[i]));
|
||||
SelectItem(aIndices[i]);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::Deselect()\n"));
|
||||
((QListBox *)mWidget)->clearSelection();
|
||||
SelectItem(-1);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set initial parameters
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM, PR_LOG_DEBUG, ("nsListBox::PreCreateWidget()\n"));
|
||||
if (nsnull != aInitData)
|
||||
{
|
||||
nsListBoxInitData* data = (nsListBoxInitData *) aInitData;
|
||||
mMultiSelect = data->mMultiSelect;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/* -*- 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.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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIListBox.h"
|
||||
#include <qlistbox.h>
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// nsQListBox class
|
||||
//
|
||||
//=============================================================================
|
||||
class nsQListBox : public QListBox, public nsQBaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
nsQListBox(nsWidget * widget,
|
||||
QWidget * parent = 0,
|
||||
const char * name = 0,
|
||||
WFlags f = 0);
|
||||
~nsQListBox();
|
||||
};
|
||||
|
||||
/**
|
||||
* Native QT Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent) { return PR_FALSE; }
|
||||
virtual PRBool OnResize(nsRect &aRect) { return PR_FALSE; }
|
||||
|
||||
|
||||
// nsIListBox
|
||||
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||
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() ;
|
||||
|
||||
protected:
|
||||
|
||||
PRBool mMultiSelect;
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -1,354 +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):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#include "nsListBox.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsListBox)
|
||||
NS_IMPL_RELEASE(nsListBox)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
mMultiSelect = aMultipleSelections;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
if (nsnull != aInitData) {
|
||||
nsListBoxInitData* data = (nsListBoxInitData *) aInitData;
|
||||
mMultiSelect = data->mMultiSelect;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
SendMessage(mWnd, LB_INSERTSTRING, (int)aPosition, (LPARAM)(LPCTSTR)val);
|
||||
NS_FREE_STR_BUF(val);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
int index = ::SendMessage(mWnd, LB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val);
|
||||
NS_FREE_STR_BUF(val);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
return (PRInt32)::SendMessage(mWnd, LB_GETCOUNT, (int)0, (LPARAM)0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
int status = ::SendMessage(mWnd, LB_DELETESTRING, (int)aPosition, (LPARAM)(LPCTSTR)0);
|
||||
return (status != LB_ERR?PR_TRUE:PR_FALSE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
int len = ::SendMessage(mWnd, LB_GETTEXTLEN, (int)aPosition, (LPARAM)0);
|
||||
if (len != LB_ERR) {
|
||||
char * str = new char[len+1];
|
||||
anItem.SetLength(0);
|
||||
int status = ::SendMessage(mWnd, LB_GETTEXT, (int)aPosition, (LPARAM)(LPCTSTR)str);
|
||||
if (status != LB_ERR) {
|
||||
anItem.Append(str);
|
||||
result = PR_TRUE;
|
||||
}
|
||||
delete str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
int index = ::SendMessage(mWnd, LB_GETCURSEL, (int)0, (LPARAM)0);
|
||||
GetItemAt(aItem, index);
|
||||
} else {
|
||||
NS_ASSERTION(0, "Multi selection list box does not support GetSelectedItem()");
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
return ::SendMessage(mWnd, LB_GETCURSEL, (int)0, (LPARAM)0);
|
||||
} else {
|
||||
NS_ASSERTION(0, "Multi selection list box does not support GetSelectedIndex()");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
::SendMessage(mWnd, LB_SETCURSEL, (int)aPosition, (LPARAM)0);
|
||||
} else {
|
||||
::SendMessage(mWnd, LB_SETSEL, (WPARAM) (BOOL)PR_TRUE, (LPARAM)(UINT)aPosition);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
PRInt32 inx = GetSelectedIndex();
|
||||
return (inx == -1? 0 : 1);
|
||||
} else {
|
||||
return ::SendMessage(mWnd, LB_GETSELCOUNT, (int)0, (LPARAM)0);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
::SendMessage(mWnd, LB_GETSELITEMS, (int)aSize, (LPARAM)aIndices);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
for (int i=0;i<aSize;i++) {
|
||||
SelectItem(aIndices[i]);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
::SendMessage(mWnd, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0);
|
||||
} else {
|
||||
::SendMessage(mWnd, LB_SETSEL, (WPARAM) (BOOL)PR_FALSE, (LPARAM)(UINT)-1);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// 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);
|
||||
|
||||
if (result == NS_NOINTERFACE) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIListBox))) {
|
||||
*aInstancePtr = (void*) ((nsIListBox*)this);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(NS_GET_IID(nsIListWidget))) {
|
||||
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsListBox::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::OnPaint()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::OnResize(nsRect &aWindowRect)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// return the window class name and initialize the class if needed
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
LPCTSTR nsListBox::WindowClass()
|
||||
{
|
||||
return("LISTBOX");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// return window styles
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
DWORD nsListBox::WindowStyle()
|
||||
{
|
||||
DWORD style = (LBS_NOINTEGRALHEIGHT | WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL);
|
||||
if (mMultiSelect)
|
||||
style = LBS_MULTIPLESEL | LBS_EXTENDEDSEL | style;
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// return window extended styles
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
DWORD nsListBox::WindowExStyle()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Clear window before paint
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
PRBool nsListBox::AutoErase()
|
||||
{
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// get position/dimensions
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsListBox::GetBounds(nsRect &aRect)
|
||||
{
|
||||
nsWindow::GetNonClientBounds(aRect);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1,82 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsdefs.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsSwitchToUIThread.h"
|
||||
#include "nsIListBox.h"
|
||||
|
||||
/**
|
||||
* Native Win32 Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWindow,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint();
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
||||
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||
|
||||
|
||||
// nsIListBox interface
|
||||
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);
|
||||
|
||||
// nsWindow interface
|
||||
virtual PRBool AutoErase();
|
||||
protected:
|
||||
PRBool mMultiSelect;
|
||||
virtual LPCTSTR WindowClass();
|
||||
virtual DWORD WindowStyle();
|
||||
virtual DWORD WindowExStyle();
|
||||
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -45,7 +45,6 @@ CPPSRCS = \
|
||||
nsFileWidget.cpp \
|
||||
nsKeyCode.cpp \
|
||||
nsLabel.cpp \
|
||||
nsListBox.cpp \
|
||||
nsLookAndFeel.cpp \
|
||||
nsMenu.cpp \
|
||||
nsMenuBar.cpp \
|
||||
|
@ -1,134 +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 "nsListBox.h"
|
||||
|
||||
NS_IMPL_ADDREF(nsListBox)
|
||||
NS_IMPL_RELEASE(nsListBox)
|
||||
|
||||
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsListBox::GetItemCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 nsListBox::GetSelectedIndex()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 nsListBox::GetSelectedCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsListBox::~nsListBox()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
nsresult result = nsWidget::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);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(kInsListWidgetIID)) {
|
||||
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||
NS_ADDREF_THIS();
|
||||
result = NS_OK;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool nsListBox::AutoErase()
|
||||
{
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
|
@ -1,72 +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 nsListBox_h__
|
||||
#define nsListBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIListBox.h"
|
||||
#include "nsIListWidget.h"
|
||||
|
||||
/**
|
||||
* Native Win32 Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsListBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIListBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsListBox();
|
||||
virtual ~nsListBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
|
||||
// nsIListBox interface
|
||||
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);
|
||||
|
||||
// nsWindow interface
|
||||
virtual PRBool AutoErase();
|
||||
protected:
|
||||
PRBool mMultiSelect;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsListBox_h__
|
@ -137,7 +137,6 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
||||
static NS_DEFINE_CID(kMenuBarCID, NS_MENUBAR_CID);
|
||||
static NS_DEFINE_CID(kMenuCID, NS_MENU_CID);
|
||||
static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID);
|
||||
static NS_DEFINE_CID(kContextMenuCID, NS_CONTEXTMENU_CID);
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
Loading…
Reference in New Issue
Block a user