mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 04:45:45 +00:00
Removing unused native combobox implementation. Not part of the build. r=cls.
This commit is contained in:
parent
0c2bfb80b7
commit
c9336f384f
@ -1,357 +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 "nsComboBox.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#define DBG 0
|
||||
|
||||
#define INITIAL_MAX_ITEMS 128
|
||||
#define ITEMS_GROWSIZE 128
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsComboBox, nsWidget)
|
||||
NS_IMPL_RELEASE_INHERITED(nsComboBox, nsWidget)
|
||||
NS_IMPL_QUERY_INTERFACE3(nsComboBox, nsIComboBox, nsIListWidget, nsIWidget)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::nsComboBox() : nsWidget(), nsIListWidget(), nsIComboBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMultiSelect = PR_FALSE;
|
||||
mItems = nsnull;
|
||||
mNumItems = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::~nsComboBox()
|
||||
{
|
||||
if (mItems) {
|
||||
for (GList *items = mItems; items; items = (GList*) g_list_next(items)){
|
||||
g_free(items->data);
|
||||
}
|
||||
g_list_free(mItems);
|
||||
}
|
||||
gtk_widget_destroy(mCombo);
|
||||
}
|
||||
|
||||
void nsComboBox::InitCallbacks(char * aName)
|
||||
{
|
||||
InstallButtonPressSignal(mWidget);
|
||||
InstallButtonReleaseSignal(mWidget);
|
||||
|
||||
InstallEnterNotifySignal(mWidget);
|
||||
InstallLeaveNotifySignal(mWidget);
|
||||
|
||||
// These are needed so that the events will go to us and not our parent.
|
||||
AddToEventMask(mWidget,
|
||||
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_METHOD nsComboBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
mMultiSelect = aMultipleSelections;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
mItems = g_list_insert( mItems, g_strdup(val), aPosition );
|
||||
mNumItems++;
|
||||
if (mCombo) {
|
||||
gtk_combo_set_popdown_strings( GTK_COMBO( mCombo ), mItems );
|
||||
}
|
||||
NS_FREE_STR_BUF(val);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
int i;
|
||||
PRInt32 inx = -1;
|
||||
GList *items = g_list_nth(mItems, aStartPos);
|
||||
for(i=0; items != NULL; items = (GList *) g_list_next(items), i++ )
|
||||
{
|
||||
if(!strcmp(val, (gchar *) items->data))
|
||||
{
|
||||
inx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
NS_FREE_STR_BUF(val);
|
||||
return inx;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetItemCount()
|
||||
{
|
||||
return (PRInt32)mNumItems;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
if (aPosition >= 0 && aPosition < mNumItems) {
|
||||
|
||||
g_free(g_list_nth(mItems, aPosition)->data);
|
||||
mItems = g_list_remove_link(mItems, g_list_nth(mItems, aPosition));
|
||||
mNumItems--;
|
||||
if (mCombo) {
|
||||
gtk_combo_set_popdown_strings(GTK_COMBO( mCombo ), mItems);
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
else
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
if (aPosition >= 0 && aPosition < mNumItems) {
|
||||
anItem.AssignWithConversion((gchar *) g_list_nth(mItems, aPosition)->data);
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
aItem.Truncate();
|
||||
if (mCombo) {
|
||||
aItem.AssignWithConversion(gtk_entry_get_text (GTK_ENTRY (GTK_COMBO(mCombo)->entry)));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedIndex()
|
||||
{
|
||||
nsString nsstring;
|
||||
GetSelectedItem(nsstring);
|
||||
return FindItem(nsstring, 0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
GList *pos;
|
||||
if (!mItems)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
pos = g_list_nth(mItems, aPosition);
|
||||
if (!pos)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (mCombo) {
|
||||
gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(mCombo)->entry),
|
||||
(gchar *) pos->data);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedCount()
|
||||
{
|
||||
if (!mMultiSelect) {
|
||||
PRInt32 inx = GetSelectedIndex();
|
||||
return (inx == -1? 0 : 1);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
// this is an error
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::Deselect()
|
||||
{
|
||||
if (mMultiSelect) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Create the native GtkCombo widget
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::CreateNative(GtkObject *parentWindow)
|
||||
{
|
||||
mWidget = ::gtk_event_box_new();
|
||||
|
||||
::gtk_widget_set_name(mWidget, "nsComboBox");
|
||||
mCombo = ::gtk_combo_new();
|
||||
gtk_widget_show(mCombo);
|
||||
|
||||
/* make the stuff uneditable */
|
||||
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(mCombo)->entry), PR_FALSE);
|
||||
|
||||
gtk_signal_connect(GTK_OBJECT(mCombo),
|
||||
"destroy",
|
||||
GTK_SIGNAL_FUNC(DestroySignal),
|
||||
this);
|
||||
gtk_signal_connect(GTK_OBJECT(GTK_COMBO(mCombo)->popwin),
|
||||
"unmap",
|
||||
GTK_SIGNAL_FUNC(UnmapSignal),
|
||||
this);
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(mWidget), mCombo);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsComboBox::OnDestroySignal(GtkWidget* aGtkWidget)
|
||||
{
|
||||
if (aGtkWidget == mCombo) {
|
||||
mCombo = nsnull;
|
||||
}
|
||||
else {
|
||||
nsWidget::OnDestroySignal(aGtkWidget);
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
nsComboBox::UnmapSignal(GtkWidget* aGtkWidget, nsComboBox* aCombo)
|
||||
{
|
||||
if (!aCombo) return PR_FALSE;
|
||||
aCombo->OnUnmapSignal(aGtkWidget);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nsComboBox::OnUnmapSignal(GtkWidget * aWidget)
|
||||
{
|
||||
if (!aWidget) return;
|
||||
|
||||
// Generate a NS_CONTROL_CHANGE event and send it to the frame
|
||||
nsGUIEvent event;
|
||||
event.eventStructType = NS_GUI_EVENT;
|
||||
nsPoint point(0,0);
|
||||
InitEvent(event, NS_CONTROL_CHANGE, &point);
|
||||
DispatchWindowEvent(&event);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get handle for style
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
/*virtual*/
|
||||
void nsComboBox::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_BIN (mWidget)->child, style);
|
||||
|
||||
gtk_style_unref(style);
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsComboBox_h__
|
||||
#define nsComboBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIComboBox.h"
|
||||
|
||||
/**
|
||||
* Native GTK+ Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsComboBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIComboBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsComboBox();
|
||||
virtual ~nsComboBox();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||
virtual PRInt32 GetItemCount();
|
||||
virtual PRBool RemoveItemAt(PRInt32 aPosition);
|
||||
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||
NS_IMETHOD GetSelectedItem(nsString& aItem);
|
||||
virtual PRInt32 GetSelectedIndex();
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||
NS_IMETHOD Deselect() ;
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections);
|
||||
PRInt32 GetSelectedCount();
|
||||
NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
|
||||
virtual void SetFontNative(GdkFont *aFont);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD CreateNative(GtkObject *parentWindow);
|
||||
virtual void InitCallbacks(char * aName = nsnull);
|
||||
virtual void OnDestroySignal(GtkWidget* aGtkWidget);
|
||||
virtual void OnUnmapSignal(GtkWidget* aWidget);
|
||||
static gint UnmapSignal(GtkWidget* aGtkWidget, nsComboBox* aCombo);
|
||||
|
||||
GtkWidget *mCombo; /* workaround for gtkcombo bug */
|
||||
GList *mItems;
|
||||
PRBool mMultiSelect;
|
||||
int mNumItems;
|
||||
};
|
||||
|
||||
#endif // nsComboBox_h__
|
@ -1,338 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsComboBox.h"
|
||||
#include "nsMenu.h"
|
||||
#include <StringCompare.h>
|
||||
#include "nsCarbonHelpers.h"
|
||||
|
||||
#if TARGET_CARBON
|
||||
#include <ControlDefinitions.h>
|
||||
#endif
|
||||
|
||||
NS_IMPL_ADDREF(nsComboBox);
|
||||
NS_IMPL_RELEASE(nsComboBox);
|
||||
|
||||
#define DASH '-'
|
||||
#define OPTION_DASH 'Ð'
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::nsComboBox() : nsMacControl(), nsIListWidget(), nsIComboBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
gInstanceClassName = "nsComboBox";
|
||||
SetControlType(kControlPopupButtonProc + kControlPopupFixedWidthVariant);
|
||||
|
||||
mMenuHandle = nsnull;
|
||||
mMenuID = -12345; // so that the control doesn't look for a menu in resource
|
||||
mMin = mMenuID; // when creating a popup, 'min' must contain the menuID
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::~nsComboBox()
|
||||
{
|
||||
if (mMenuHandle)
|
||||
{
|
||||
// ::DeleteMenu(mMenuID);
|
||||
// ::DisposeMenu(mMenuHandle);
|
||||
mMenuHandle = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsComboBox::Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
nsresult res = Inherited::Create(aParent, aRect, aHandleEventFunction,
|
||||
aContext, aAppShell, aToolkit, aInitData);
|
||||
|
||||
if (res == NS_OK)
|
||||
{
|
||||
mMenuID = nsMenu::GetUniqueMenuID();
|
||||
mMenuHandle = ::NewMenu(mMenuID, "\p");
|
||||
if (mMenuHandle)
|
||||
{
|
||||
StartDraw();
|
||||
::InsertMenu(mMenuHandle, hierMenu);
|
||||
SetControlPopupMenuStuff ( mControl, mMenuHandle, mMenuID );
|
||||
::SetControlMinimum(mControl, 0);
|
||||
::SetControlMaximum(mControl, 0);
|
||||
::SetControlValue(mControl, 0);
|
||||
EndDraw();
|
||||
}
|
||||
else
|
||||
res = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_INTERFACE_MAP_BEGIN(nsComboBox)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIComboBox)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIListWidget)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsWindow)
|
||||
|
||||
#pragma mark -
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
nsresult nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
if (! mMenuHandle)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
Str255 pString;
|
||||
StringToStr255(aItem, pString);
|
||||
|
||||
// Mac hacks: a menu item should not be an empty string
|
||||
// (otherwise a new item is not appended to the menu)
|
||||
// and it should not contain a dash '-' as first character
|
||||
// (otherwise it is considered as a menu separator even though
|
||||
// we are doing a 2-step initialization with MacInsertMenuItem()
|
||||
// and SetMenuItemText()).
|
||||
if (pString[0] == 0)
|
||||
{
|
||||
pString[0] = 1;
|
||||
pString[1] = ' ';
|
||||
}
|
||||
else if (pString[1] == DASH) {
|
||||
pString[1] = OPTION_DASH;
|
||||
}
|
||||
|
||||
StartDraw();
|
||||
|
||||
short menuItems = GetItemCount();
|
||||
if (aPosition == -1 || aPosition > menuItems) {
|
||||
aPosition = menuItems;
|
||||
}
|
||||
::MacInsertMenuItem(mMenuHandle, "\p ", aPosition);
|
||||
::SetMenuItemText(mMenuHandle, aPosition + 1, pString);
|
||||
|
||||
menuItems = GetItemCount();
|
||||
::SetControlMinimum(mControl, (menuItems ? 1 : 0));
|
||||
::SetControlMaximum(mControl, (menuItems ? menuItems : 0));
|
||||
EndDraw();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
if (! mMenuHandle)
|
||||
return -1;
|
||||
|
||||
PRInt32 index = -1;
|
||||
short itemCount = GetItemCount();
|
||||
for (short i = aStartPos; i < itemCount; i ++)
|
||||
{
|
||||
nsString temp;
|
||||
GetItemAt(temp, i);
|
||||
if (aItem == temp)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetItemCount()
|
||||
{
|
||||
if (! mMenuHandle)
|
||||
return 0;
|
||||
|
||||
return ::CountMenuItems(mMenuHandle);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
if (! mMenuHandle)
|
||||
return PR_FALSE;
|
||||
|
||||
if (GetItemCount() < aPosition)
|
||||
return PR_FALSE;
|
||||
|
||||
StartDraw();
|
||||
if (aPosition == -1)
|
||||
::DeleteMenuItem(mMenuHandle, GetItemCount());
|
||||
else
|
||||
::DeleteMenuItem(mMenuHandle, aPosition + 1);
|
||||
|
||||
short menuItems = GetItemCount();
|
||||
::SetControlMinimum(mControl, (menuItems ? 1 : 0));
|
||||
::SetControlMaximum(mControl, (menuItems ? menuItems : 0));
|
||||
EndDraw();
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Returns an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
anItem = "";
|
||||
|
||||
if (! mMenuHandle)
|
||||
return PR_FALSE;
|
||||
|
||||
if (aPosition >= GetItemCount())
|
||||
return PR_FALSE;
|
||||
|
||||
Str255 itemStr;
|
||||
::GetMenuItemText(mMenuHandle, aPosition + 1, itemStr);
|
||||
if (itemStr[1] == OPTION_DASH) // see AddItemAt() for more info
|
||||
itemStr[1] = DASH;
|
||||
Str255ToString(itemStr, anItem);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsComboBox::GetSelectedItem(nsString& anItem)
|
||||
{
|
||||
return GetItemAt(anItem, GetSelectedIndex());
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedIndex()
|
||||
{
|
||||
if (! mMenuHandle)
|
||||
return -1;
|
||||
|
||||
return ::GetControlValue(mControl) - 1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsComboBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
if (! mMenuHandle)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
StartDraw();
|
||||
if (aPosition == -1)
|
||||
::SetControlValue(mControl, GetItemCount());
|
||||
else
|
||||
::SetControlValue(mControl, aPosition + 1);
|
||||
EndDraw();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsComboBox::Deselect()
|
||||
{
|
||||
return SelectItem(0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// DispatchMouseEvent
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::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) {
|
||||
StartDraw();
|
||||
Point thePoint;
|
||||
thePoint.h = aEvent.point.x;
|
||||
thePoint.v = aEvent.point.y;
|
||||
::TrackControl(mControl, thePoint, nil);
|
||||
ControlChanged(::GetControlValue(mControl));
|
||||
EndDraw();
|
||||
|
||||
// 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;
|
||||
default:
|
||||
eventHandled = Inherited::DispatchMouseEvent(aEvent);
|
||||
break;
|
||||
}
|
||||
return eventHandled;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsComboBox_h__
|
||||
#define nsComboBox_h__
|
||||
|
||||
#include "nsMacControl.h"
|
||||
#include "nsIComboBox.h"
|
||||
|
||||
|
||||
class nsComboBox : public nsMacControl,
|
||||
public nsIListWidget,
|
||||
public nsIComboBox
|
||||
{
|
||||
private:
|
||||
typedef nsMacControl Inherited;
|
||||
|
||||
public:
|
||||
nsComboBox();
|
||||
virtual ~nsComboBox();
|
||||
|
||||
// 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);
|
||||
|
||||
// nsIComboBox part
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
NS_IMETHOD_(PRInt32) FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||
NS_IMETHOD_(PRInt32) GetItemCount();
|
||||
NS_IMETHOD_(PRBool) RemoveItemAt(PRInt32 aPosition);
|
||||
NS_IMETHOD_(PRBool) GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||
NS_IMETHOD GetSelectedItem(nsString &aItem);
|
||||
NS_IMETHOD_(PRInt32) GetSelectedIndex();
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||
NS_IMETHOD Deselect();
|
||||
|
||||
// nsWindow
|
||||
virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent);
|
||||
|
||||
protected:
|
||||
PRInt16 mMenuID;
|
||||
MenuHandle mMenuHandle;
|
||||
};
|
||||
|
||||
|
||||
#endif // nsComboBox_h__
|
@ -1,422 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsComboBox.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
||||
#include <Pt.h>
|
||||
#include "nsPhWidgetLog.h"
|
||||
|
||||
#define DBG 0
|
||||
|
||||
#define INITIAL_MAX_ITEMS 128
|
||||
#define ITEMS_GROWSIZE 128
|
||||
|
||||
NS_IMPL_ADDREF(nsComboBox)
|
||||
NS_IMPL_RELEASE(nsComboBox)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::nsComboBox() : nsWidget(), nsIListWidget(), nsIComboBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMultiSelect = PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::~nsComboBox()
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::~nsComboBox - Destructor called\n"));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::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 res;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
char *str = aItem.ToNewCString();
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::AddItemAt - aItem=<%s> aPos=<%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 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
char *str = aItem.ToNewCString();
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::FindItem - aItem=<%s> aStartPos=<%d>\n",str, aStartPos));
|
||||
|
||||
PRInt32 index = -1;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
index = PtListItemPos(mWidget, str);
|
||||
if (index == 0)
|
||||
index = -1; /* item wasn't found */
|
||||
}
|
||||
|
||||
delete [] str;
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetItemCount()
|
||||
{
|
||||
PtArg_t arg;
|
||||
short *theCount = nsnull;
|
||||
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, ("nsComboBox::GetItemCount - mNumItems=<%d>\n", total));
|
||||
return (PRInt32) total;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::RemoveItemAt - aPos=<%d>\n", aPosition));
|
||||
|
||||
int err;
|
||||
PRBool res = PR_FALSE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
if (PtListDeleteItemPos(mWidget, 1, aPosition) == 0)
|
||||
res = PR_TRUE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::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, ("nsComboBox::GetItemAt aPosition=<%d> aItem=<%s>\n", aPosition, items[aPosition+1]));
|
||||
|
||||
anItem.Append(items[aPosition+1]);
|
||||
result = PR_TRUE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
int theFirstSelectedItem = GetSelectedIndex();
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedItem theFirstSelectedItem is <%d>\n", theFirstSelectedItem));
|
||||
GetItemAt(aItem, theFirstSelectedItem);
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected items
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedIndex()
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedIndex\n"));
|
||||
|
||||
PRInt32 index=-1;
|
||||
int theFirstSelectedItem[1];
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
GetSelectedIndices(theFirstSelectedItem, 1);
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedIndex theFirstSelectedItem is <%d>\n", theFirstSelectedItem[0]));
|
||||
|
||||
index = theFirstSelectedItem[0];
|
||||
res = NS_OK;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::SelectItem at %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 nsComboBox::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, ("nsComboBox::GetSelectedCount theCount=<%d>\n", total));
|
||||
return total;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedIndices - Not Implemented\n"));
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::Deselect()
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::DeSelect - Not Implemented\n"));
|
||||
|
||||
if (mMultiSelect) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kInsComboBoxIID, NS_ICOMBOBOX_IID);
|
||||
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
|
||||
|
||||
if (aIID.Equals(kInsComboBoxIID)) {
|
||||
*aInstancePtr = (void*) ((nsIComboBox*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(kInsListWidgetIID)) {
|
||||
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsWidget::QueryInterface(aIID,aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Create the native GtkCombo widget
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::CreateNative(PtWidget_t *parentWindow)
|
||||
{
|
||||
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;
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::CreateNative pos=(%d,%d) dim=(%d,%d)\n",
|
||||
pos.x, pos.y, dim.w, dim.h));
|
||||
|
||||
|
||||
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( PtComboBox, parentWindow, 3, arg );
|
||||
if( mWidget )
|
||||
{
|
||||
res = NS_OK;
|
||||
|
||||
/* Mozilla calls this first before we have a widget so re-call this */
|
||||
SetMultipleSelection(mMultiSelect);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::OnMove - Not Implemented\n"));
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint message. Don't send the paint out
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::OnPaint(nsPaintEvent &aEvent)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::OnPaint - Not Implemented\n"));
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsComboBox::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::OnResize - Not Implemented\n"));
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
@ -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 nsComboBox_h__
|
||||
#define nsComboBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIComboBox.h"
|
||||
|
||||
/**
|
||||
* Native Photon Listbox wrapper
|
||||
*/
|
||||
|
||||
class nsComboBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIComboBox
|
||||
{
|
||||
public:
|
||||
nsComboBox();
|
||||
~nsComboBox();
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
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();
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||
NS_IMETHOD Deselect() ;
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections);
|
||||
PRInt32 GetSelectedCount();
|
||||
NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD CreateNative(PtWidget_t *parentWindow);
|
||||
PRBool mMultiSelect;
|
||||
};
|
||||
|
||||
#endif // nsComboBox_h__
|
@ -1,6 +1,5 @@
|
||||
Makefile
|
||||
moc_nsQApplication.cpp
|
||||
moc_nsComboBox.cpp
|
||||
moc_nsLabel.cpp
|
||||
moc_nsScrollbar.cpp
|
||||
moc_nsButton.cpp
|
||||
|
@ -1,333 +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 "nsComboBox.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
||||
#define DBG 0
|
||||
|
||||
#define INITIAL_MAX_ITEMS 128
|
||||
#define ITEMS_GROWSIZE 128
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// nsQComboBox class
|
||||
//
|
||||
//=============================================================================
|
||||
nsQComboBox::nsQComboBox(nsWidget * widget,
|
||||
QWidget * parent,
|
||||
const char * name)
|
||||
: QComboBox(TRUE, parent, name), nsQBaseWidget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
nsQComboBox::~nsQComboBox()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsComboBox, nsWidget)
|
||||
NS_IMPL_RELEASE_INHERITED(nsComboBox, nsWidget)
|
||||
NS_IMPL_QUERY_INTERFACE3(nsComboBox, nsIComboBox, nsIListWidget, nsIWidget)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::nsComboBox() : nsWidget(), nsIListWidget(), nsIComboBox()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::nsComboBox()\n"));
|
||||
NS_INIT_REFCNT();
|
||||
mMultiSelect = PR_FALSE;
|
||||
|
||||
mNumItems = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox:: destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::~nsComboBox()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::~nsComboBox()\n"));
|
||||
if (mWidget)
|
||||
{
|
||||
delete ((QComboBox *)mWidget);
|
||||
mWidget = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// initializer
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::SetMultipleSelection()\n"));
|
||||
mMultiSelect = aMultipleSelections;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// AddItemAt
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::AddItemAt: add %s at %d\n",
|
||||
val,
|
||||
aPosition));
|
||||
|
||||
((QComboBox *)mWidget)->insertItem(val, aPosition);
|
||||
mNumItems++;
|
||||
NS_FREE_STR_BUF(val);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
int i;
|
||||
PRInt32 index = -1;
|
||||
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::FindItem: find %s starting at %d\n",
|
||||
val,
|
||||
aStartPos));
|
||||
|
||||
int count = ((QComboBox *)mWidget)->count();
|
||||
|
||||
for (i = aStartPos; i < count; i++)
|
||||
{
|
||||
QString string = ((QComboBox*)mWidget)->text(i);
|
||||
|
||||
if (string == val)
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NS_FREE_STR_BUF(val);
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetItemCount()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetItemCount: returning %d\n",
|
||||
mNumItems));
|
||||
return (PRInt32)mNumItems;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::RemoveItemAt: remove at %d\n",
|
||||
aPosition));
|
||||
if (aPosition >= 0 && aPosition < mNumItems)
|
||||
{
|
||||
((QComboBox *)mWidget)->removeItem(aPosition);
|
||||
mNumItems--;
|
||||
return PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetItemAt: get at %d\n",
|
||||
aPosition));
|
||||
PRBool result = PR_FALSE;
|
||||
if (aPosition >= 0 && aPosition < mNumItems)
|
||||
{
|
||||
QString string = ((QComboBox *)mWidget)->text(aPosition);
|
||||
anItem = NS_ConvertASCIItoUCS2(string).get();
|
||||
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetItemAt: found %s at %d\n",
|
||||
(const char *) string,
|
||||
aPosition));
|
||||
|
||||
result = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = PR_FALSE;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the text of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
QString string = ((QComboBox *)mWidget)->currentText();
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetSelectedItem: %s is selected\n",
|
||||
(const char *) string));
|
||||
|
||||
aItem = NS_ConvertASCIItoUCS2(string).get();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the index of the selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedIndex()
|
||||
{
|
||||
PRInt32 item = ((QComboBox *)mWidget)->currentItem();
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetSelectedIndex: %d is selected\n",
|
||||
item));
|
||||
return item;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::SelectItem: select at %d\n",
|
||||
aPosition));
|
||||
((QComboBox *) mWidget)->setCurrentItem(aPosition);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedCount
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedCount()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetSelectedCount()\n"));
|
||||
if (!mMultiSelect)
|
||||
{
|
||||
PRInt32 inx = GetSelectedIndex();
|
||||
return (inx == -1? 0 : 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// GetSelectedIndices
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::GetSelectedIndices()\n"));
|
||||
// this is an error
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::Deselect()
|
||||
{
|
||||
PR_LOG(QtWidgetsLM,
|
||||
PR_LOG_DEBUG,
|
||||
("nsComboBox::Deselect()\n"));
|
||||
if (mMultiSelect)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectItem(-1);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
@ -1,94 +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 nsComboBox_h__
|
||||
#define nsComboBox_h__
|
||||
|
||||
#include "nsWidget.h"
|
||||
#include "nsIComboBox.h"
|
||||
|
||||
#include <qcombobox.h>
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
// nsQComboBox class
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
class nsQComboBox : public QComboBox, public nsQBaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
nsQComboBox(nsWidget * widget,
|
||||
QWidget * parent = 0,
|
||||
const char * name = 0);
|
||||
~nsQComboBox();
|
||||
};
|
||||
|
||||
/**
|
||||
* Native QT ComboBox wrapper
|
||||
*/
|
||||
|
||||
class nsComboBox : public nsWidget,
|
||||
public nsIListWidget,
|
||||
public nsIComboBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsComboBox();
|
||||
virtual ~nsComboBox();
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||
virtual PRInt32 GetItemCount();
|
||||
virtual PRBool RemoveItemAt(PRInt32 aPosition);
|
||||
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||
NS_IMETHOD GetSelectedItem(nsString& aItem);
|
||||
virtual PRInt32 GetSelectedIndex();
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||
NS_IMETHOD Deselect() ;
|
||||
|
||||
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; }
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections);
|
||||
PRInt32 GetSelectedCount();
|
||||
NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||
|
||||
protected:
|
||||
|
||||
/*
|
||||
QWidget * mCombo;
|
||||
QWidget * mPullDownMenu;
|
||||
QWidget * mOptionMenu;
|
||||
GList * mItems;
|
||||
*/
|
||||
PRBool mMultiSelect;
|
||||
int mNumItems;
|
||||
};
|
||||
|
||||
#endif // nsComboBox_h__
|
@ -1,362 +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 "nsComboBox.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsILookAndFeel.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
|
||||
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
NS_IMPL_ADDREF(nsComboBox)
|
||||
NS_IMPL_RELEASE(nsComboBox)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsComboBox constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::nsComboBox() : nsWindow(), nsIListWidget(), nsIComboBox()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mBackground = NS_RGB(124, 124, 124);
|
||||
mDropDownHeight = 60; // Default to 60 pixels for drop-down list height
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
::SendMessage(mWnd, CB_INSERTSTRING, (int)aPosition, (LPARAM)(LPCTSTR)val);
|
||||
NS_FREE_STR_BUF(val);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Finds an item at a postion
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||
int index = ::SendMessage(mWnd, CB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val);
|
||||
NS_FREE_STR_BUF(val);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// CountItems - Get Item Count
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetItemCount()
|
||||
{
|
||||
return (PRInt32)::SendMessage(mWnd, CB_GETCOUNT, (int)0, (LPARAM)0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
|
||||
{
|
||||
int status = ::SendMessage(mWnd, CB_DELETESTRING, (int)aPosition, (LPARAM)(LPCTSTR)0);
|
||||
return (status != CB_ERR?PR_TRUE:PR_FALSE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Removes an Item at a specified location
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
int len = ::SendMessage(mWnd, CB_GETLBTEXTLEN, (int)aPosition, (LPARAM)0);
|
||||
if (len != CB_ERR) {
|
||||
char * str = new char[len+1];
|
||||
anItem.SetLength(0);
|
||||
int status = ::SendMessage(mWnd, CB_GETLBTEXT, (int)aPosition, (LPARAM)(LPCTSTR)str);
|
||||
if (status != CB_ERR) {
|
||||
anItem.Append(str);
|
||||
result = PR_TRUE;
|
||||
}
|
||||
delete str;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the selected of selected item
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
|
||||
{
|
||||
|
||||
int index = ::SendMessage(mWnd, CB_GETCURSEL, (int)0, (LPARAM)0);
|
||||
GetItemAt(aItem, index);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Gets the list of selected otems
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRInt32 nsComboBox::GetSelectedIndex()
|
||||
{
|
||||
return ::SendMessage(mWnd, CB_GETCURSEL, (int)0, (LPARAM)0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// SelectItem
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
|
||||
{
|
||||
::SendMessage(mWnd, CB_SETCURSEL, (int)aPosition, (LPARAM)0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsComboBox::Deselect()
|
||||
{
|
||||
::SendMessage(mWnd, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsComboBox::~nsComboBox()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIComboBox))) {
|
||||
*aInstancePtr = (void*) ((nsIComboBox*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(NS_GET_IID(nsIListWidget))) {
|
||||
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsWindow::QueryInterface(aIID,aInstancePtr);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsComboBox::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsComboBox::OnPaint()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsComboBox::OnResize(nsRect &aWindowRect)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// return the window class name and initialize the class if needed
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
LPCTSTR nsComboBox::WindowClass()
|
||||
{
|
||||
return("COMBOBOX");
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// return window styles
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
DWORD nsComboBox::WindowStyle()
|
||||
{
|
||||
return (CBS_DROPDOWNLIST | WS_BORDER | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// return window extended styles
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
DWORD nsComboBox::WindowExStyle()
|
||||
{
|
||||
return WS_EX_CLIENTEDGE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Cache the drop down list height in mDropDownHeight
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||
{
|
||||
nsComboBoxInitData* comboData = (nsComboBoxInitData*)aInitData;
|
||||
mDropDownHeight = comboData->mDropDownHeight;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Modify the height passed to create and resize to be
|
||||
// the combo box drop down list height. (Note: Windows uses
|
||||
// the height of the window to specify the drop-down list size,
|
||||
// not the height of combobox text area.
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
PRInt32 nsComboBox::GetHeight(PRInt32 aProposedHeight)
|
||||
{
|
||||
return(mDropDownHeight);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// get position/dimensions
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
NS_METHOD nsComboBox::GetBounds(nsRect &aRect)
|
||||
{
|
||||
nsWindow::GetNonClientBounds(aRect);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the TextWidget for Printing
|
||||
*
|
||||
**/
|
||||
NS_METHOD nsComboBox::Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect)
|
||||
{
|
||||
nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||
/*nsRect rect;
|
||||
GetBoundsAppUnits(rect, aTwipsConversion);
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
|
||||
nscolor bgColor = NS_RGB(255,255,255);
|
||||
nscolor fgColor = NS_RGB(0,0,0);
|
||||
nscolor hltColor = NS_RGB(240,240,240);
|
||||
nscolor sdwColor = NS_RGB(128,128,128);
|
||||
nsILookAndFeel * lookAndFeel;
|
||||
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||
}
|
||||
|
||||
nsIDeviceContext * context;
|
||||
//nsDrawingSurface surface;
|
||||
aRenderingContext.GetDeviceContext(context);
|
||||
//context->GetDrawingSurface(aRenderingContext, surface);
|
||||
|
||||
//HDC the_hdc = ((nsDrawingSurfaceWin *)&surface)->mDC;
|
||||
|
||||
//::SendMessage(mWnd, WM_PAINT, (WPARAM)the_hdc, NULL);
|
||||
|
||||
|
||||
// shrink by one pixel
|
||||
|
||||
nscoord onePixel = nscoord((aTwipsConversion+0.6F));
|
||||
nscoord twoPixels = onePixel*2;
|
||||
|
||||
nsString text("(ComboBox)");
|
||||
//GetSelectedItem(text);
|
||||
|
||||
|
||||
aRenderingContext.SetColor(bgColor);
|
||||
aRenderingContext.FillRect(rect);
|
||||
|
||||
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||
aRenderingContext.DrawRect(rect);
|
||||
|
||||
|
||||
aRenderingContext.SetFont(*mFont);
|
||||
|
||||
nscoord textWidth;
|
||||
nscoord textHeight;
|
||||
aRenderingContext.GetWidth(text, textWidth);
|
||||
|
||||
nsIFontMetrics* metrics;
|
||||
context->GetMetricsFor(*mFont, metrics);
|
||||
metrics->GetMaxAscent(textHeight);
|
||||
|
||||
nscoord x = (twoPixels * 2) + rect.x;
|
||||
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||
//aRenderingContext.DrawString(text, x, y);
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,85 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsComboBox_h__
|
||||
#define nsComboBox_h__
|
||||
|
||||
#include "nsdefs.h"
|
||||
#include "nsWindow.h"
|
||||
#include "nsSwitchToUIThread.h"
|
||||
#include "nsIComboBox.h"
|
||||
|
||||
/**
|
||||
* Native Win32 Combobox wrapper
|
||||
*/
|
||||
|
||||
class nsComboBox : public nsWindow,
|
||||
public nsIListWidget,
|
||||
public nsIComboBox
|
||||
{
|
||||
|
||||
public:
|
||||
nsComboBox();
|
||||
~nsComboBox();
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
// nsIWidget overrides
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint();
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
||||
// nsIWidget
|
||||
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||
|
||||
// nsIComboBox interface
|
||||
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||
virtual PRInt32 GetItemCount();
|
||||
virtual PRBool RemoveItemAt(PRInt32 aPosition);
|
||||
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||
NS_IMETHOD GetSelectedItem(nsString& aItem);
|
||||
virtual PRInt32 GetSelectedIndex();
|
||||
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||
NS_IMETHOD Deselect() ;
|
||||
|
||||
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||
const nsRect& aDirtyRect);
|
||||
|
||||
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||
|
||||
protected:
|
||||
|
||||
// Modify the height passed to create and resize to be
|
||||
// the combo box drop down list height.
|
||||
PRInt32 GetHeight(PRInt32 aProposedHeight);
|
||||
LPCTSTR WindowClass();
|
||||
DWORD WindowStyle();
|
||||
DWORD WindowExStyle();
|
||||
PRInt32 mDropDownHeight;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsComboBox_h__
|
Loading…
Reference in New Issue
Block a user