intl.cpp C B
ipcbase.cpp C
layout.cpp C
+lboxcmn.cpp C
list.cpp C B
log.cpp C B
memory.cpp C
#! Created: 14.07.99
#! Version: $Id$
#!#############################################################################
-
#${
#! include the code which parses filelist.txt file and initializes
#! %wxCommon, %wxGeneric and %wxMSW hashes.
#pragma interface
#endif
-#include "wx/defs.h"
-
-#if wxUSE_LISTBOX
-
-#include "wx/object.h"
#include "wx/list.h"
-#include "wx/control.h"
-
-//-----------------------------------------------------------------------------
-// classes
-//-----------------------------------------------------------------------------
-
-class wxListBox;
-class wxArrayInt;
-
-//-----------------------------------------------------------------------------
-// global data
-//-----------------------------------------------------------------------------
-
-extern const char *wxListBoxNameStr;
//-----------------------------------------------------------------------------
// wxListBox
//-----------------------------------------------------------------------------
-class wxListBox : public wxControl
+class wxListBox : public wxListBoxBase
{
-DECLARE_DYNAMIC_CLASS(wxListBox)
-
public:
+ // ctors and such
wxListBox();
wxListBox( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxListBoxNameStr);
- void Append( const wxString &item );
- void Append( const wxString &item, void* clientData );
- void Append( const wxString &item, wxClientData* clientData );
-
- void InsertItems(int nItems, const wxString items[], int pos);
-
- void SetClientData( int n, void* clientData );
- void* GetClientData( int n );
- void SetClientObject( int n, wxClientData* clientData );
- wxClientData* GetClientObject( int n );
-
- void SetClientObject( wxClientData *data ) { wxControl::SetClientObject( data ); }
- wxClientData *GetClientObject() const { return wxControl::GetClientObject(); }
- void SetClientData( void *data ) { wxControl::SetClientData( data ); }
- void *GetClientData() const { return wxControl::GetClientData(); }
-
- void Clear();
- void Delete( int n );
-
- void Deselect( int n );
- int FindString( const wxString &item ) const;
- int GetSelection() const;
- int GetSelections( class wxArrayInt &) const;
- wxString GetString( int n ) const;
- wxString GetStringSelection() const;
- int Number();
- bool Selected( int n );
- void Set( int n, const wxString *choices );
- void SetFirstItem( int n );
- void SetFirstItem( const wxString &item );
- void SetSelection( int n, bool select = TRUE );
- void SetString( int n, const wxString &string );
- void SetStringSelection( const wxString &string, bool select = TRUE );
+ // implement base class pure virtuals
+ virtual void Clear();
+ virtual void Delete(int n);
+
+ virtual int GetCount() const;
+ virtual wxString GetString(int n) const;
+ virtual void SetString(int n, const wxString& s);
+ virtual int FindString(const wxString& s) const;
+
+ virtual bool IsSelected(int n) const;
+ virtual void SetSelection(int n, bool select = TRUE);
+ virtual int GetSelection() const;
+ virtual int GetSelections(wxArrayInt& aSelections) const;
+
+ virtual int DoAppend(const wxString& item);
+ virtual void DoInsertItems(const wxArrayString& items, int pos);
+ virtual void DoSetItems(const wxArrayString& items, void **clientData);
+
+ virtual void DoSetFirstItem(int n);
+
+ virtual void DoSetClientData(int n, void* clientData);
+ virtual void* DoGetClientData(int n) const;
+ virtual void DoSetClientObject(int n, wxClientData* clientData);
+ virtual wxClientData* DoGetClientObject(int n) const;
+
+ // implementation from now on
#if wxUSE_DRAG_AND_DROP
void SetDropTarget( wxDropTarget *dropTarget );
#endif
- // implementation
-
void DisableEvents();
void EnableEvents();
- void AppendCommon( const wxString &item );
+ void AppendWithoutSorting( const wxString &item );
int GetIndex( GtkWidget *item ) const;
GtkWidget *GetConnectWidget();
bool IsOwnGtkWindow( GdkWindow *window );
#endif // wxUSE_TOOLTIPS
GtkList *m_list;
- wxList m_clientDataList;
- wxList m_clientObjectList;
+ wxList m_clientData;
#if wxUSE_CHECKLISTBOX
bool m_hasCheckBoxes;
#endif // wxUSE_CHECKLISTBOX
-};
-#endif
+private:
+ // this array is only used for controls with wxCB_SORT style, so only
+ // allocate it if it's needed (hence using pointer)
+ wxSortedArrayString *m_strings;
+
+ DECLARE_DYNAMIC_CLASS(wxListBox)
+};
#endif // __GTKLISTBOXH__
#pragma interface
#endif
-#include "wx/defs.h"
-
-#if wxUSE_LISTBOX
-
-#include "wx/object.h"
#include "wx/list.h"
-#include "wx/control.h"
-
-//-----------------------------------------------------------------------------
-// classes
-//-----------------------------------------------------------------------------
-
-class wxListBox;
-class wxArrayInt;
-
-//-----------------------------------------------------------------------------
-// global data
-//-----------------------------------------------------------------------------
-
-extern const char *wxListBoxNameStr;
//-----------------------------------------------------------------------------
// wxListBox
//-----------------------------------------------------------------------------
-class wxListBox : public wxControl
+class wxListBox : public wxListBoxBase
{
-DECLARE_DYNAMIC_CLASS(wxListBox)
-
public:
+ // ctors and such
wxListBox();
wxListBox( wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxListBoxNameStr);
- void Append( const wxString &item );
- void Append( const wxString &item, void* clientData );
- void Append( const wxString &item, wxClientData* clientData );
-
- void InsertItems(int nItems, const wxString items[], int pos);
-
- void SetClientData( int n, void* clientData );
- void* GetClientData( int n );
- void SetClientObject( int n, wxClientData* clientData );
- wxClientData* GetClientObject( int n );
-
- void SetClientObject( wxClientData *data ) { wxControl::SetClientObject( data ); }
- wxClientData *GetClientObject() const { return wxControl::GetClientObject(); }
- void SetClientData( void *data ) { wxControl::SetClientData( data ); }
- void *GetClientData() const { return wxControl::GetClientData(); }
-
- void Clear();
- void Delete( int n );
-
- void Deselect( int n );
- int FindString( const wxString &item ) const;
- int GetSelection() const;
- int GetSelections( class wxArrayInt &) const;
- wxString GetString( int n ) const;
- wxString GetStringSelection() const;
- int Number();
- bool Selected( int n );
- void Set( int n, const wxString *choices );
- void SetFirstItem( int n );
- void SetFirstItem( const wxString &item );
- void SetSelection( int n, bool select = TRUE );
- void SetString( int n, const wxString &string );
- void SetStringSelection( const wxString &string, bool select = TRUE );
+ // implement base class pure virtuals
+ virtual void Clear();
+ virtual void Delete(int n);
+
+ virtual int GetCount() const;
+ virtual wxString GetString(int n) const;
+ virtual void SetString(int n, const wxString& s);
+ virtual int FindString(const wxString& s) const;
+
+ virtual bool IsSelected(int n) const;
+ virtual void SetSelection(int n, bool select = TRUE);
+ virtual int GetSelection() const;
+ virtual int GetSelections(wxArrayInt& aSelections) const;
+
+ virtual int DoAppend(const wxString& item);
+ virtual void DoInsertItems(const wxArrayString& items, int pos);
+ virtual void DoSetItems(const wxArrayString& items, void **clientData);
+
+ virtual void DoSetFirstItem(int n);
+
+ virtual void DoSetClientData(int n, void* clientData);
+ virtual void* DoGetClientData(int n) const;
+ virtual void DoSetClientObject(int n, wxClientData* clientData);
+ virtual wxClientData* DoGetClientObject(int n) const;
+
+ // implementation from now on
#if wxUSE_DRAG_AND_DROP
void SetDropTarget( wxDropTarget *dropTarget );
#endif
- // implementation
-
void DisableEvents();
void EnableEvents();
- void AppendCommon( const wxString &item );
+ void AppendWithoutSorting( const wxString &item );
int GetIndex( GtkWidget *item ) const;
GtkWidget *GetConnectWidget();
bool IsOwnGtkWindow( GdkWindow *window );
#endif // wxUSE_TOOLTIPS
GtkList *m_list;
- wxList m_clientDataList;
- wxList m_clientObjectList;
+ wxList m_clientData;
#if wxUSE_CHECKLISTBOX
bool m_hasCheckBoxes;
#endif // wxUSE_CHECKLISTBOX
-};
-#endif
+private:
+ // this array is only used for controls with wxCB_SORT style, so only
+ // allocate it if it's needed (hence using pointer)
+ wxSortedArrayString *m_strings;
+
+ DECLARE_DYNAMIC_CLASS(wxListBox)
+};
#endif // __GTKLISTBOXH__
+///////////////////////////////////////////////////////////////////////////////
+// Name: wx/listbox.h
+// Purpose: wxListBox class interface
+// Author: Vadim Zeitlin
+// Modified by:
+// Created: 22.10.99
+// RCS-ID: $Id$
+// Copyright: (c) wxWindows team
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
#ifndef _WX_LISTBOX_H_BASE_
#define _WX_LISTBOX_H_BASE_
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#ifdef __GNUG__
+ #pragma interface "listboxbase.h"
+#endif
+
+#include "wx/defs.h"
+
+#if wxUSE_LISTBOX
+
+#include "wx/control.h" // base class
+
+// forward declarations are enough here
+class WXDLLEXPORT wxArrayInt;
+class WXDLLEXPORT wxArrayString;
+
+// ----------------------------------------------------------------------------
+// global data
+// ----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(extern const wxChar*) wxListBoxNameStr;
+
+// ----------------------------------------------------------------------------
+// wxListBox interface is defined by the class wxListBoxBase
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxListBoxBase : public wxControl
+{
+public:
+ // ctor
+ wxListBoxBase() { m_clientDataItemsType = ClientData_None; }
+
+ // adding items
+ // ------------
+
+ void Append(const wxString& item)
+ { DoAppend(item); }
+ void Append(const wxString& item, void *clientData)
+ { int n = DoAppend(item); SetClientData(n, clientData); }
+ void Append(const wxString& item, wxClientData *clientData)
+ { int n = DoAppend(item); SetClientObject(n, clientData); }
+
+ void Insert(const wxString& item, int pos)
+ { DoInsert(item, pos); }
+ void Insert(const wxString& item, int pos, void *clientData)
+ { DoInsert(item, pos); SetClientData(pos, clientData); }
+ void Insert(const wxString& item, int pos, wxClientData *clientData)
+ { DoInsert(item, pos); SetClientObject(pos, clientData); }
+
+ void InsertItems(int nItems, const wxString *items, int pos);
+ void InsertItems(const wxArrayString& items, int pos)
+ { DoInsertItems(items, pos); }
+
+ void Set(int n, const wxString* items, void **clientData = NULL);
+ void Set(const wxArrayString& items, void **clientData = NULL)
+ { DoSetItems(items, clientData); }
+
+ // deleting items
+ // --------------
+
+ virtual void Clear() = 0;
+ virtual void Delete(int n) = 0;
+
+ // accessing strings
+ // -----------------
+
+ virtual int GetCount() const = 0;
+ virtual wxString GetString(int n) const = 0;
+ virtual void SetString(int n, const wxString& s) = 0;
+ virtual int FindString(const wxString& s) const = 0;
+
+ // selection
+ // ---------
+
+ virtual bool IsSelected(int n) const = 0;
+ virtual void SetSelection(int n, bool select = TRUE) = 0;
+ void Select(int n) { SetSelection(n, TRUE); }
+ void Deselect(int n) { SetSelection(n, FALSE); }
+
+ virtual int GetSelection() const = 0;
+ virtual int GetSelections(wxArrayInt& aSelections) const = 0;
+
+ bool SetStringSelection(const wxString& s, bool select = TRUE);
+ wxString GetStringSelection() const;
+
+ // misc
+ // ----
+
+ // client data stuff
+ void SetClientData( int n, void* clientData );
+ void* GetClientData( int n ) const;
+
+ void SetClientObject( int n, wxClientData* clientData );
+ wxClientData* GetClientObject( int n ) const;
+
+ // Set the specified item at the first visible item or scroll to max
+ // range.
+ void SetFirstItem(int n) { DoSetFirstItem(n); }
+ void SetFirstItem(const wxString& s);
+
+ // emulate selecting or deselecting (depending on event.GetExtraLong())
+ // the item event.GetInt() from the control
+ virtual void Command(wxCommandEvent &event);
+
+ // compatibility - these functions are deprecated, use the new ones
+ // instead
+ bool Selected(int n) const { return IsSelected(n); }
+ int Number() const { return GetCount(); }
+
+protected:
+ // NB: due to wxGTK implementation details, DoInsert() is implemented
+ // using DoInsertItems() and not the other way round
+ void DoInsert(const wxString& item, int pos)
+ { InsertItems(1, &item, pos); }
+
+ // to be implemented in derived classes
+ virtual int DoAppend(const wxString& item) = 0;
+ virtual void DoInsertItems(const wxArrayString& items, int pos) = 0;
+ virtual void DoSetItems(const wxArrayString& items, void **clientData) = 0;
+
+ virtual void DoSetFirstItem(int n) = 0;
+
+ virtual void DoSetClientData(int n, void* clientData) = 0;
+ virtual void* DoGetClientData(int n) const = 0;
+ virtual void DoSetClientObject(int n, wxClientData* clientData) = 0;
+ virtual wxClientData* DoGetClientObject(int n) const = 0;
+
+ // the above pure virtuals hide these virtuals in wxWindowBase
+ virtual void DoSetClientData(void* clientData )
+ { wxWindowBase::DoSetClientData(clientData); };
+ virtual void* DoGetClientData() const
+ { return(wxWindowBase::DoGetClientData()); };
+ virtual void DoSetClientObject( wxClientData* clientData )
+ { wxWindowBase::DoSetClientObject(clientData); };
+ virtual wxClientData* DoGetClientObject() const
+ { return(wxWindowBase::DoGetClientObject()); };
+
+ // the type of the client data for the items
+ wxClientDataType m_clientDataItemsType;
+};
+
+// ----------------------------------------------------------------------------
+// include the platform-specific class declaration
+// ----------------------------------------------------------------------------
+
#if defined(__WXMSW__)
-#include "wx/msw/listbox.h"
+ #include "wx/msw/listbox.h"
#elif defined(__WXMOTIF__)
-#include "wx/motif/listbox.h"
+ #include "wx/motif/listbox.h"
#elif defined(__WXGTK__)
-#include "wx/gtk/listbox.h"
+ #include "wx/gtk/listbox.h"
#elif defined(__WXQT__)
-#include "wx/qt/listbox.h"
+ #include "wx/qt/listbox.h"
#elif defined(__WXMAC__)
-#include "wx/mac/listbox.h"
+ #include "wx/mac/listbox.h"
#elif defined(__WXPM__)
-#include "wx/os2/listbox.h"
+ #include "wx/os2/listbox.h"
#elif defined(__WXSTUBS__)
-#include "wx/stubs/listbox.h"
+ #include "wx/stubs/listbox.h"
#endif
+#endif // wxUSE_LISTBOX
+
#endif
// _WX_LISTBOX_H_BASE_
/////////////////////////////////////////////////////////////////////////////
-// Name: listbox.h
+// Name: wx/msw/listbox.h
// Purpose: wxListBox class
// Author: Julian Smart
// Modified by:
#pragma interface "listbox.h"
#endif
-#include "wx/control.h"
-
-WXDLLEXPORT_DATA(extern const wxChar*) wxListBoxNameStr;
+// ----------------------------------------------------------------------------
+// simple types
+// ----------------------------------------------------------------------------
#if wxUSE_OWNER_DRAWN
class WXDLLEXPORT wxOwnerDrawn;
#include <wx/dynarray.h>
WX_DEFINE_EXPORTED_ARRAY(wxOwnerDrawn *, wxListBoxItemsArray);
-
-#endif
+#endif // wxUSE_OWNER_DRAWN
// forward decl for GetSelections()
class wxArrayInt;
-WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
+// ----------------------------------------------------------------------------
+// List box control
+// ----------------------------------------------------------------------------
-// List box item
-class WXDLLEXPORT wxListBox : public wxControl
+class WXDLLEXPORT wxListBox : public wxListBoxBase
{
- DECLARE_DYNAMIC_CLASS(wxListBox)
-
public:
+ // ctors and such
wxListBox();
wxListBox(wxWindow *parent, wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
}
bool Create(wxWindow *parent, wxWindowID id,
- const wxPoint& pos = wxDefaultPosition,
- const wxSize& size = wxDefaultSize,
- int n = 0, const wxString choices[] = NULL,
- long style = 0,
- const wxValidator& validator = wxDefaultValidator,
- const wxString& name = wxListBoxNameStr);
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ int n = 0, const wxString choices[] = NULL,
+ long style = 0,
+ const wxValidator& validator = wxDefaultValidator,
+ const wxString& name = wxListBoxNameStr);
- ~wxListBox();
+ virtual ~wxListBox();
- bool MSWCommand(WXUINT param, WXWORD id);
+ // implement base class pure virtuals
+ virtual void Clear();
+ virtual void Delete(int n);
+
+ virtual int GetCount() const;
+ virtual wxString GetString(int n) const;
+ virtual void SetString(int n, const wxString& s);
+ virtual int FindString(const wxString& s) const;
+
+ virtual bool IsSelected(int n) const;
+ virtual void SetSelection(int n, bool select = TRUE);
+ virtual int GetSelection() const;
+ virtual int GetSelections(wxArrayInt& aSelections) const;
+
+ virtual int DoAppend(const wxString& item);
+ virtual void DoInsertItems(const wxArrayString& items, int pos);
+ virtual void DoSetItems(const wxArrayString& items, void **clientData);
+ virtual void DoSetFirstItem(int n);
+
+ virtual void DoSetClientData(int n, void* clientData);
+ virtual void* DoGetClientData(int n) const;
+ virtual void DoSetClientObject(int n, wxClientData* clientData);
+ virtual wxClientData* DoGetClientObject(int n) const;
+
+ // wxCheckListBox support
#if wxUSE_OWNER_DRAWN
bool MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
bool MSWOnDraw(WXDRAWITEMSTRUCT *item);
int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); }
#endif // wxUSE_OWNER_DRAWN
- virtual void Append(const wxString& item);
- virtual void Append(const wxString& item, void *clientData);
- virtual void Set(int n, const wxString* choices, void **clientData = NULL);
- virtual int FindString(const wxString& s) const ;
- virtual void Clear();
- virtual void SetSelection(int n, bool select = TRUE);
-
- virtual void Deselect(int n);
-
- // For single choice list item only
- virtual int GetSelection() const ;
- virtual void Delete(int n);
- virtual void *GetClientData(int n) const ;
- virtual void SetClientData(int n, void *clientData);
- virtual void SetString(int n, const wxString& s);
-
- // For single or multiple choice list item
- virtual int GetSelections(wxArrayInt& aSelections) const;
- virtual bool Selected(int n) const ;
- virtual wxString GetString(int n) const ;
-
- // Set the specified item at the first visible item
- // or scroll to max range.
- virtual void SetFirstItem(int n) ;
- virtual void SetFirstItem(const wxString& s) ;
-
- virtual void InsertItems(int nItems, const wxString items[], int pos);
-
- virtual wxString GetStringSelection() const ;
- virtual bool SetStringSelection(const wxString& s, bool flag = TRUE);
- virtual int Number() const ;
-
- void Command(wxCommandEvent& event);
-
- // Windows-specific code to set the horizontal extent of
- // the listbox, if necessary. If s is non-NULL, it's
- // used to calculate the horizontal extent.
- // Otherwise, all strings are used.
+ // Windows-specific code to set the horizontal extent of the listbox, if
+ // necessary. If s is non-NULL, it's used to calculate the horizontal
+ // extent. Otherwise, all strings are used.
virtual void SetHorizontalExtent(const wxString& s = wxEmptyString);
+ // Windows callbacks
virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
- WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
+ WXUINT message,
+ WXWPARAM wParam, WXLPARAM lParam);
+
+ bool MSWCommand(WXUINT param, WXWORD id);
- virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
virtual void SetupColours();
protected:
+ // do we have multiple selections?
+ bool HasMultipleSelection() const;
+
int m_noItems;
int m_selected;
// control items
wxListBoxItemsArray m_aItems;
#endif
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxListBox)
};
#endif
{
wxSimpleDataObjectList::Node *node = m_dataObjects.Item( m_preferred );
-#ifdef __WXGTK__
- wxCHECK_MSG( node, wxDataFormat(wxDF_INVALID), wxT("no preferred format") );
-#else
- wxCHECK_MSG( node, wxDataFormat((unsigned short) wxDF_INVALID), wxT("no preferred format") );
-#endif
+ wxCHECK_MSG( node, wxFormatInvalid, wxT("no preferred format") );
wxDataObjectSimple* dataObj = node->GetData();
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: common/lboxcmn.cpp
+// Purpose: wxListBox class methods common to all platforms
+// Author: Vadim Zeitlin
+// Modified by:
+// Created: 22.10.99
+// RCS-ID: $Id$
+// Copyright: (c) wxWindows team
+// Licence: wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#ifdef __GNUG__
+ #pragma implementation "listboxbase.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/listbox.h"
+#endif
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// adding items
+// ----------------------------------------------------------------------------
+
+void wxListBoxBase::InsertItems(int nItems, const wxString *items, int pos)
+{
+ wxArrayString aItems;
+ for ( int n = 0; n < nItems; n++ )
+ {
+ aItems.Add(items[n]);
+ }
+
+ DoInsertItems(aItems, pos);
+}
+
+
+void wxListBoxBase::Set(int nItems, const wxString* items, void **clientData)
+{
+ wxArrayString aItems;
+ for ( int n = 0; n < nItems; n++ )
+ {
+ aItems.Add(items[n]);
+ }
+
+ DoSetItems(aItems, clientData);
+}
+
+// ----------------------------------------------------------------------------
+// selection
+// ----------------------------------------------------------------------------
+
+wxString wxListBoxBase::GetStringSelection () const
+{
+ wxString s;
+ int sel = GetSelection();
+ if ( sel != -1 )
+ s = GetString(sel);
+
+ return s;
+}
+
+bool wxListBoxBase::SetStringSelection(const wxString& s, bool select)
+{
+ int sel = FindString(s);
+ wxCHECK_MSG( sel != -1, FALSE,
+ wxT("invalid string in wxListBox::SetStringSelection") );
+
+ SetSelection(sel, select);
+
+ return TRUE;
+}
+
+// ----------------------------------------------------------------------------
+// client data
+// ----------------------------------------------------------------------------
+
+void wxListBoxBase::SetClientObject(int n, wxClientData *data)
+{
+ wxASSERT_MSG( m_clientDataItemsType != ClientData_Void,
+ wxT("can't have both object and void client data") );
+
+ wxClientData *clientDataOld = DoGetClientObject(n);
+ if ( clientDataOld )
+ delete clientDataOld;
+
+ DoSetClientObject(n, data);
+ m_clientDataItemsType = ClientData_Object;
+}
+
+wxClientData *wxListBoxBase::GetClientObject(int n) const
+{
+ wxASSERT_MSG( m_clientDataItemsType == ClientData_Object,
+ wxT("this window doesn't have object client data") );
+
+ return DoGetClientObject(n);
+}
+
+void wxListBoxBase::SetClientData(int n, void *data)
+{
+ wxASSERT_MSG( m_clientDataItemsType != ClientData_Object,
+ wxT("can't have both object and void client data") );
+
+ DoSetClientData(n, data);
+ m_clientDataItemsType = ClientData_Void;
+}
+
+void *wxListBoxBase::GetClientData(int n) const
+{
+ wxASSERT_MSG( m_clientDataItemsType == ClientData_Void,
+ wxT("this window doesn't have void client data") );
+
+ return DoGetClientData(n);
+}
+
+// ----------------------------------------------------------------------------
+// misc
+// ----------------------------------------------------------------------------
+
+void wxListBoxBase::SetFirstItem(const wxString& s)
+{
+ int n = FindString(s);
+
+ wxCHECK_RET( n != -1, wxT("invalid string in wxListBox::SetFirstItem") );
+
+ DoSetFirstItem(n);
+}
+
+void wxListBoxBase::Command(wxCommandEvent & event)
+{
+ SetSelection(event.m_commandInt, event.m_extraLong);
+ (void)ProcessEvent(event);
+}
+
int wxChoice::DoAppend( const wxString &item )
{
- wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") );
+ wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice control") );
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
void wxChoice::DoSetClientData( int n, void* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetClientData") );
void* wxChoice::DoGetClientData( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetClientData") );
void wxChoice::DoSetClientObject( int n, wxClientData* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetClientObject") );
wxClientData* wxChoice::DoGetClientObject( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_MSG( node, (wxClientData *)NULL,
GtkWidget *menu = gtk_menu_new();
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
- if (m_clientDataItemsType == ClientData_Object)
- {
- wxNode *node = m_clientList.First();
- while (node)
- {
- wxClientData *cd = (wxClientData*)node->Data();
- if (cd) delete cd;
- node = node->Next();
- }
- }
+ if ( m_clientDataItemsType == ClientData_Object )
+ m_clientList.DeleteContents(TRUE);
m_clientList.Clear();
+
+ if ( m_strings )
+ m_strings->Clear();
}
void wxChoice::Delete( int WXUNUSED(n) )
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
wxArrayInt aSelections;
- int count = listbox->GetSelections(aSelections);
+ int n, count = listbox->GetSelections(aSelections);
if ( count > 0 )
{
- event.m_commandInt = aSelections[0] ;
- event.m_clientData = listbox->GetClientData( event.m_commandInt );
- wxString str(listbox->GetString(event.m_commandInt));
- if (!str.IsEmpty()) event.m_commandString = str;
+ n = aSelections[0];
+ event.m_clientData = listbox->m_clientData.Item(n);
+ event.m_commandString = listbox->GetString(n);
}
else
{
- event.m_commandInt = -1 ;
- event.m_commandString.Empty();
+ n = -1;
}
+ event.m_commandInt = n;
+
event.SetEventObject( listbox );
listbox->GetEventHandler()->ProcessEvent( event );
IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl)
+// ----------------------------------------------------------------------------
+// construction
+// ----------------------------------------------------------------------------
+
wxListBox::wxListBox()
{
m_list = (GtkList *) NULL;
bool wxListBox::Create( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
int n, const wxString choices[],
- long style, const wxValidator& validator, const wxString &name )
+ long style, const wxValidator& validator,
+ const wxString &name )
{
m_needParent = TRUE;
m_acceptsFocus = TRUE;
!CreateBase( parent, id, pos, size, style, validator, name ))
{
wxFAIL_MSG( wxT("wxListBox creation failed") );
- return FALSE;
+ return FALSE;
}
m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
gtk_container_set_focus_vadjustment(
GTK_CONTAINER(m_list),
gtk_scrolled_window_get_vadjustment(
- GTK_SCROLLED_WINDOW(m_widget)));
+ GTK_SCROLLED_WINDOW(m_widget)));
gtk_widget_show( GTK_WIDGET(m_list) );
if (newSize.y == -1) newSize.y = 110;
SetSize( newSize.x, newSize.y );
+ if ( style & wxLB_SORT )
+ {
+ // this will change DoAppend() behaviour
+ m_strings = new wxSortedArrayString;
+ }
+
for (int i = 0; i < n; i++)
{
- m_clientDataList.Append( (wxObject*) NULL );
- m_clientObjectList.Append( (wxObject*) NULL );
+ m_clientData.Append((wxObject *)NULL);
- GtkWidget *list_item;
+ DoAppend(choices[i]);
+#if 0
wxString str(choices[i]);
+
#if wxUSE_CHECKLISTBOX
if (m_hasCheckBoxes)
{
}
#endif // wxUSE_CHECKLISTBOX
- list_item = gtk_list_item_new_with_label( str.mbc_str() );
+ GtkWidget *list_item = gtk_list_item_new_with_label( str.mbc_str() );
gtk_container_add( GTK_CONTAINER(m_list), list_item );
ConnectWidget( list_item );
gtk_widget_show( list_item );
+#endif // 0
}
m_parent->DoAddChild( this );
Clear();
}
-void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
+void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
{
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
+ // code elsewhere supposes we have as many items in m_clientData as items
+ // in the listbox
+ wxASSERT_MSG( m_clientData.GetCount() == (size_t)GetCount(),
+ wxT("bug in client data management") );
+
GList *children = m_list->children;
int length = g_list_length(children);
wxCHECK_RET( pos <= length, wxT("invalid index in wxListBox::InsertItems") );
// all items after this position, then append these items and then
// reappend back the old ones.
- // first detach the old items
- int n; // loop var
+ // VZ: notice that InsertItems knows nothing about sorting, so calling it
+ // from outside (and not from our own Append) is likely to break
+ // everything
+ size_t nItems = items.GetCount();
+
+ size_t n; // loop var
+
+ // optimise for this trivial case
if ( pos == length )
{
// no need to do anything complicated
for ( n = 0; n < nItems; n++ )
{
- Append(items[n]);
+ AppendWithoutSorting(items[n]);
+
+ m_clientData.Append((wxObject *)NULL);
}
+ wxASSERT_MSG( m_clientData.GetCount() == (size_t)GetCount(),
+ wxT("bug in client data management") );
+
return;
}
+ // remove the old items
wxArrayString deletedLabels;
wxArrayPtrVoid deletedData;
- wxArrayInt deletedChecks; // only for check list boxes
+#if wxUSE_CHECKLISTBOX
+ wxArrayInt deletedChecks;
+#endif
GList *child = g_list_nth( children, pos );
for ( n = 0; child != NULL; n++, child = child->next )
deletedLabels.Add(str);
// save data
- void *clientData = NULL;
- wxNode *node = NULL;
-
- if ( n < (int)m_clientObjectList.GetCount() )
- node = m_clientObjectList.Nth( n );
-
- if ( node )
- {
- clientData = node->GetData();
- m_clientObjectList.DeleteNode( node );
- }
-
- if ( !clientData )
- {
- if ( n < (int)m_clientDataList.GetCount() )
- node = m_clientDataList.Nth( n );
-
- if ( node )
- {
- clientData = node->GetData();
- node = m_clientDataList.Nth( n );
- }
- }
-
- deletedData.Add(clientData);
+ deletedData.Add(m_clientData.Item(n));
#if wxUSE_CHECKLISTBOX
// save check state
#endif // wxUSE_CHECKLISTBOX
}
- int nDeletedCount = n;
+ // don't delete contents, the data will be reappended soon
+ m_clientData.Clear();
+
+ size_t nDeletedCount = n;
gtk_list_clear_items( m_list, pos, length );
// now append the new items
for ( n = 0; n < nItems; n++ )
{
- Append(items[n]);
+ AppendWithoutSorting(items[n]);
+
+ m_clientData.Append((wxObject *)NULL);
}
// and append the old items too
pos += nItems; // now the indices are shifter
for ( n = 0; n < nDeletedCount; n++ )
{
- Append(deletedLabels[n], deletedData[n]);
+ AppendWithoutSorting(deletedLabels[n]);
+
+ m_clientData.Append((wxObject *)NULL);
+
+ if ( m_clientDataItemsType == ClientData_Object )
+ SetClientObject(n, (wxClientData *)deletedData[n]);
+ else if ( m_clientDataItemsType == ClientData_Void )
+ SetClientData(n, deletedData[n]);
#if wxUSE_CHECKLISTBOX
if ( m_hasCheckBoxes )
}
#endif // wxUSE_CHECKLISTBOX
}
+
+ wxASSERT_MSG( m_clientData.GetCount() == (size_t)GetCount(),
+ wxT("bug in client data management") );
+}
+
+int wxListBox::DoAppend( const wxString& item )
+{
+ int index;
+ if ( m_strings )
+ {
+ // need to determine the index
+ index = m_strings->Add(item);
+
+ InsertItems(1, &item, index);
+ }
+ else
+ {
+ // not sorted, just append
+ AppendWithoutSorting(item);
+
+ m_clientData.Append((wxObject *)NULL);
+
+ index = GetCount() - 1;
+ }
+
+ return index;
}
-void wxListBox::AppendCommon( const wxString &item )
+void wxListBox::AppendWithoutSorting( const wxString &item )
{
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
}
#if wxUSE_DRAG_AND_DROP
-#ifndef NEW_GTK_DND_CODE
+ #ifndef NEW_GTK_DND_CODE
if (m_dropTarget) m_dropTarget->RegisterWidget( list_item );
-#endif
+ #endif
#endif
#if wxUSE_TOOLTIPS
}
}
-void wxListBox::Append( const wxString &item )
+void wxListBox::DoSetItems( const wxArrayString& items,
+ void **clientData)
{
- m_clientDataList.Append( (wxObject*) NULL );
- m_clientObjectList.Append( (wxObject*) NULL );
-
- AppendCommon( item );
-}
+ Clear();
-void wxListBox::Append( const wxString &item, void *clientData )
-{
- m_clientDataList.Append( (wxObject*) clientData );
- m_clientObjectList.Append( (wxObject*) NULL );
+ DoInsertItems(items, 0);
- AppendCommon( item );
+ if ( clientData )
+ {
+ size_t count = items.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ SetClientData(n, clientData[n]);
+ }
+ }
}
-void wxListBox::Append( const wxString &item, wxClientData *clientData )
-{
- m_clientObjectList.Append( (wxObject*) clientData );
- m_clientDataList.Append( (wxObject*) NULL );
+// ----------------------------------------------------------------------------
+// client data
+// ----------------------------------------------------------------------------
- AppendCommon( item );
-}
-
-void wxListBox::SetClientData( int n, void* clientData )
+void wxListBox::DoSetClientData( int n, void* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientDataList.Nth( n );
- if (!node) return;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetClientData") );
node->SetData( (wxObject*) clientData );
}
-void* wxListBox::GetClientData( int n )
+void* wxListBox::DoGetClientData( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientDataList.Nth( n );
- if (!node) return NULL;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetClientData") );
return node->Data();
}
-void wxListBox::SetClientObject( int n, wxClientData* clientData )
+void wxListBox::DoSetClientObject( int n, wxClientData* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientObjectList.Nth( n );
- if (!node) return;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetClientObject") );
wxClientData *cd = (wxClientData*) node->Data();
- if (cd) delete cd;
+ delete cd;
node->SetData( (wxObject*) clientData );
}
-wxClientData* wxListBox::GetClientObject( int n )
+wxClientData* wxListBox::DoGetClientObject( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientObjectList.Nth( n );
- if (!node) return (wxClientData*) NULL;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_MSG( node, (wxClientData *)NULL,
+ wxT("invalid index in wxListBox::DoGetClientObject") );
return (wxClientData*) node->Data();
}
gtk_list_clear_items( m_list, 0, Number() );
- wxNode *node = m_clientObjectList.First();
- while (node)
- {
- wxClientData *cd = (wxClientData*)node->Data();
- if (cd) delete cd;
- node = node->Next();
- }
- m_clientObjectList.Clear();
+ if ( m_clientDataItemsType == ClientData_Object )
+ m_clientData.DeleteContents(TRUE);
+ m_clientData.Clear();
- m_clientDataList.Clear();
+ if ( m_strings )
+ m_strings->Clear();
}
void wxListBox::Delete( int n )
gtk_list_remove_items( m_list, list );
g_list_free( list );
- wxNode *node = m_clientObjectList.Nth( n );
- if (node)
+ wxNode *node = m_clientData.Nth( n );
+ if ( node )
{
- wxClientData *cd = (wxClientData*)node->Data();
- if (cd) delete cd;
- m_clientObjectList.DeleteNode( node );
+ if ( m_clientDataItemsType == ClientData_Object )
+ {
+ wxClientData *cd = (wxClientData*)node->Data();
+ delete cd;
+ }
+
+ m_clientData.DeleteNode( node );
}
- node = m_clientDataList.Nth( n );
- if (node)
+ if ( m_strings )
+ m_strings->Remove(n);
+}
+
+// ----------------------------------------------------------------------------
+// string list access
+// ----------------------------------------------------------------------------
+
+void wxListBox::SetString( int n, const wxString &string )
+{
+ wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
+
+ GList *child = g_list_nth( m_list->children, n );
+ if (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
+
+ wxString str;
+#if wxUSE_CHECKLISTBOX
+ if (m_hasCheckBoxes)
+ str += CHECKBOX_STRING;
+#endif // wxUSE_CHECKLISTBOX
+ str += string;
+
+ gtk_label_set( label, str.mbc_str() );
+ }
+ else
{
- m_clientDataList.DeleteNode( node );
+ wxFAIL_MSG(wxT("wrong listbox index"));
}
}
-void wxListBox::Deselect( int n )
+wxString wxListBox::GetString( int n ) const
{
- wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
+ wxCHECK_MSG( m_list != NULL, wxT(""), wxT("invalid listbox") );
- DisableEvents();
+ GList *child = g_list_nth( m_list->children, n );
+ if (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
- gtk_list_unselect_item( m_list, n );
+ wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent);
- EnableEvents();
+ return str;
+ }
+
+ wxFAIL_MSG(wxT("wrong listbox index"));
+
+ return wxT("");
+}
+
+int wxListBox::GetCount() const
+{
+ wxCHECK_MSG( m_list != NULL, -1, wxT("invalid listbox") );
+
+ GList *child = m_list->children;
+ int count = 0;
+ while (child)
+ {
+ count++;
+ child = child->next;
+ }
+
+ return count;
}
int wxListBox::FindString( const wxString &item ) const
child = child->next;
}
- // it's not an error if the string is not found -> no wxCHECK
+ // it's not an error if the string is not found -> no wxCHECK
- return -1;
+ return wxNOT_FOUND;
}
+// ----------------------------------------------------------------------------
+// selection
+// ----------------------------------------------------------------------------
+
int wxListBox::GetSelection() const
{
wxCHECK_MSG( m_list != NULL, -1, wxT("invalid listbox") );
return count;
}
-wxString wxListBox::GetString( int n ) const
-{
- wxCHECK_MSG( m_list != NULL, wxT(""), wxT("invalid listbox") );
-
- GList *child = g_list_nth( m_list->children, n );
- if (child)
- {
- GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent);
-
- return str;
- }
-
- wxFAIL_MSG(wxT("wrong listbox index"));
-
- return wxT("");
-}
-
-wxString wxListBox::GetStringSelection() const
-{
- wxCHECK_MSG( m_list != NULL, wxT(""), wxT("invalid listbox") );
-
- GList *selection = m_list->selection;
- if (selection)
- {
- GtkBin *bin = GTK_BIN( selection->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent);
-
- return str;
- }
-
- wxFAIL_MSG(wxT("no listbox selection available"));
- return wxT("");
-}
-
-int wxListBox::Number()
-{
- wxCHECK_MSG( m_list != NULL, -1, wxT("invalid listbox") );
-
- GList *child = m_list->children;
- int count = 0;
- while (child) { count++; child = child->next; }
- return count;
-}
-
-bool wxListBox::Selected( int n )
+bool wxListBox::IsSelected( int n ) const
{
wxCHECK_MSG( m_list != NULL, FALSE, wxT("invalid listbox") );
child = child->next;
}
}
- wxFAIL_MSG(wxT("wrong listbox index"));
- return FALSE;
-}
-
-void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) )
-{
- wxFAIL_MSG(wxT("wxListBox::Set not implemented"));
-}
-void wxListBox::SetFirstItem( int WXUNUSED(n) )
-{
- wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
-}
+ wxFAIL_MSG(wxT("wrong listbox index"));
-void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) )
-{
- wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
+ return FALSE;
}
void wxListBox::SetSelection( int n, bool select )
EnableEvents();
}
-void wxListBox::SetString( int n, const wxString &string )
+void wxListBox::DoSetFirstItem( int WXUNUSED(n) )
{
- wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
-
- GList *child = g_list_nth( m_list->children, n );
- if (child)
- {
- GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str;
-#if wxUSE_CHECKLISTBOX
- if (m_hasCheckBoxes)
- str += CHECKBOX_STRING;
-#endif // wxUSE_CHECKLISTBOX
- str += string;
-
- gtk_label_set( label, str.mbc_str() );
- }
- else
- {
- wxFAIL_MSG(wxT("wrong listbox index"));
- }
+ wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
}
-void wxListBox::SetStringSelection( const wxString &string, bool select )
-{
- wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
-
- SetSelection( FindString(string), select );
-}
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
int wxListBox::GetIndex( GtkWidget *item ) const
{
if (GTK_WIDGET(m_list)->window && cursor.Ok())
{
/* I now set the cursor the anew in every OnInternalIdle call
- as setting the cursor in a parent window also effects the
- windows above so that checking for the current cursor is
- not possible. */
-
- gdk_window_set_cursor( GTK_WIDGET(m_list)->window, cursor.GetCursor() );
+ as setting the cursor in a parent window also effects the
+ windows above so that checking for the current cursor is
+ not possible. */
+
+ gdk_window_set_cursor( GTK_WIDGET(m_list)->window, cursor.GetCursor() );
GList *child = m_list->children;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkWidget *label = GTK_WIDGET( bin->child );
-
- if (!label->window)
- break;
- else
- gdk_window_set_cursor( label->window, cursor.GetCursor() );
+
+ if (!label->window)
+ break;
+ else
+ gdk_window_set_cursor( label->window, cursor.GetCursor() );
child = child->next;
}
int wxChoice::DoAppend( const wxString &item )
{
- wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") );
+ wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice control") );
GtkWidget *menu = gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) );
void wxChoice::DoSetClientData( int n, void* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetClientData") );
void* wxChoice::DoGetClientData( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetClientData") );
void wxChoice::DoSetClientObject( int n, wxClientData* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetClientObject") );
wxClientData* wxChoice::DoGetClientObject( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid choice control") );
wxNode *node = m_clientList.Nth( n );
wxCHECK_MSG( node, (wxClientData *)NULL,
GtkWidget *menu = gtk_menu_new();
gtk_option_menu_set_menu( GTK_OPTION_MENU(m_widget), menu );
- if (m_clientDataItemsType == ClientData_Object)
- {
- wxNode *node = m_clientList.First();
- while (node)
- {
- wxClientData *cd = (wxClientData*)node->Data();
- if (cd) delete cd;
- node = node->Next();
- }
- }
+ if ( m_clientDataItemsType == ClientData_Object )
+ m_clientList.DeleteContents(TRUE);
m_clientList.Clear();
+
+ if ( m_strings )
+ m_strings->Clear();
}
void wxChoice::Delete( int WXUNUSED(n) )
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
wxArrayInt aSelections;
- int count = listbox->GetSelections(aSelections);
+ int n, count = listbox->GetSelections(aSelections);
if ( count > 0 )
{
- event.m_commandInt = aSelections[0] ;
- event.m_clientData = listbox->GetClientData( event.m_commandInt );
- wxString str(listbox->GetString(event.m_commandInt));
- if (!str.IsEmpty()) event.m_commandString = str;
+ n = aSelections[0];
+ event.m_clientData = listbox->m_clientData.Item(n);
+ event.m_commandString = listbox->GetString(n);
}
else
{
- event.m_commandInt = -1 ;
- event.m_commandString.Empty();
+ n = -1;
}
+ event.m_commandInt = n;
+
event.SetEventObject( listbox );
listbox->GetEventHandler()->ProcessEvent( event );
IMPLEMENT_DYNAMIC_CLASS(wxListBox,wxControl)
+// ----------------------------------------------------------------------------
+// construction
+// ----------------------------------------------------------------------------
+
wxListBox::wxListBox()
{
m_list = (GtkList *) NULL;
bool wxListBox::Create( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
int n, const wxString choices[],
- long style, const wxValidator& validator, const wxString &name )
+ long style, const wxValidator& validator,
+ const wxString &name )
{
m_needParent = TRUE;
m_acceptsFocus = TRUE;
!CreateBase( parent, id, pos, size, style, validator, name ))
{
wxFAIL_MSG( wxT("wxListBox creation failed") );
- return FALSE;
+ return FALSE;
}
m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
gtk_container_set_focus_vadjustment(
GTK_CONTAINER(m_list),
gtk_scrolled_window_get_vadjustment(
- GTK_SCROLLED_WINDOW(m_widget)));
+ GTK_SCROLLED_WINDOW(m_widget)));
gtk_widget_show( GTK_WIDGET(m_list) );
if (newSize.y == -1) newSize.y = 110;
SetSize( newSize.x, newSize.y );
+ if ( style & wxLB_SORT )
+ {
+ // this will change DoAppend() behaviour
+ m_strings = new wxSortedArrayString;
+ }
+
for (int i = 0; i < n; i++)
{
- m_clientDataList.Append( (wxObject*) NULL );
- m_clientObjectList.Append( (wxObject*) NULL );
+ m_clientData.Append((wxObject *)NULL);
- GtkWidget *list_item;
+ DoAppend(choices[i]);
+#if 0
wxString str(choices[i]);
+
#if wxUSE_CHECKLISTBOX
if (m_hasCheckBoxes)
{
}
#endif // wxUSE_CHECKLISTBOX
- list_item = gtk_list_item_new_with_label( str.mbc_str() );
+ GtkWidget *list_item = gtk_list_item_new_with_label( str.mbc_str() );
gtk_container_add( GTK_CONTAINER(m_list), list_item );
ConnectWidget( list_item );
gtk_widget_show( list_item );
+#endif // 0
}
m_parent->DoAddChild( this );
Clear();
}
-void wxListBox::InsertItems(int nItems, const wxString items[], int pos)
+void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
{
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
+ // code elsewhere supposes we have as many items in m_clientData as items
+ // in the listbox
+ wxASSERT_MSG( m_clientData.GetCount() == (size_t)GetCount(),
+ wxT("bug in client data management") );
+
GList *children = m_list->children;
int length = g_list_length(children);
wxCHECK_RET( pos <= length, wxT("invalid index in wxListBox::InsertItems") );
// all items after this position, then append these items and then
// reappend back the old ones.
- // first detach the old items
- int n; // loop var
+ // VZ: notice that InsertItems knows nothing about sorting, so calling it
+ // from outside (and not from our own Append) is likely to break
+ // everything
+ size_t nItems = items.GetCount();
+
+ size_t n; // loop var
+
+ // optimise for this trivial case
if ( pos == length )
{
// no need to do anything complicated
for ( n = 0; n < nItems; n++ )
{
- Append(items[n]);
+ AppendWithoutSorting(items[n]);
+
+ m_clientData.Append((wxObject *)NULL);
}
+ wxASSERT_MSG( m_clientData.GetCount() == (size_t)GetCount(),
+ wxT("bug in client data management") );
+
return;
}
+ // remove the old items
wxArrayString deletedLabels;
wxArrayPtrVoid deletedData;
- wxArrayInt deletedChecks; // only for check list boxes
+#if wxUSE_CHECKLISTBOX
+ wxArrayInt deletedChecks;
+#endif
GList *child = g_list_nth( children, pos );
for ( n = 0; child != NULL; n++, child = child->next )
deletedLabels.Add(str);
// save data
- void *clientData = NULL;
- wxNode *node = NULL;
-
- if ( n < (int)m_clientObjectList.GetCount() )
- node = m_clientObjectList.Nth( n );
-
- if ( node )
- {
- clientData = node->GetData();
- m_clientObjectList.DeleteNode( node );
- }
-
- if ( !clientData )
- {
- if ( n < (int)m_clientDataList.GetCount() )
- node = m_clientDataList.Nth( n );
-
- if ( node )
- {
- clientData = node->GetData();
- node = m_clientDataList.Nth( n );
- }
- }
-
- deletedData.Add(clientData);
+ deletedData.Add(m_clientData.Item(n));
#if wxUSE_CHECKLISTBOX
// save check state
#endif // wxUSE_CHECKLISTBOX
}
- int nDeletedCount = n;
+ // don't delete contents, the data will be reappended soon
+ m_clientData.Clear();
+
+ size_t nDeletedCount = n;
gtk_list_clear_items( m_list, pos, length );
// now append the new items
for ( n = 0; n < nItems; n++ )
{
- Append(items[n]);
+ AppendWithoutSorting(items[n]);
+
+ m_clientData.Append((wxObject *)NULL);
}
// and append the old items too
pos += nItems; // now the indices are shifter
for ( n = 0; n < nDeletedCount; n++ )
{
- Append(deletedLabels[n], deletedData[n]);
+ AppendWithoutSorting(deletedLabels[n]);
+
+ m_clientData.Append((wxObject *)NULL);
+
+ if ( m_clientDataItemsType == ClientData_Object )
+ SetClientObject(n, (wxClientData *)deletedData[n]);
+ else if ( m_clientDataItemsType == ClientData_Void )
+ SetClientData(n, deletedData[n]);
#if wxUSE_CHECKLISTBOX
if ( m_hasCheckBoxes )
}
#endif // wxUSE_CHECKLISTBOX
}
+
+ wxASSERT_MSG( m_clientData.GetCount() == (size_t)GetCount(),
+ wxT("bug in client data management") );
+}
+
+int wxListBox::DoAppend( const wxString& item )
+{
+ int index;
+ if ( m_strings )
+ {
+ // need to determine the index
+ index = m_strings->Add(item);
+
+ InsertItems(1, &item, index);
+ }
+ else
+ {
+ // not sorted, just append
+ AppendWithoutSorting(item);
+
+ m_clientData.Append((wxObject *)NULL);
+
+ index = GetCount() - 1;
+ }
+
+ return index;
}
-void wxListBox::AppendCommon( const wxString &item )
+void wxListBox::AppendWithoutSorting( const wxString &item )
{
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
}
#if wxUSE_DRAG_AND_DROP
-#ifndef NEW_GTK_DND_CODE
+ #ifndef NEW_GTK_DND_CODE
if (m_dropTarget) m_dropTarget->RegisterWidget( list_item );
-#endif
+ #endif
#endif
#if wxUSE_TOOLTIPS
}
}
-void wxListBox::Append( const wxString &item )
+void wxListBox::DoSetItems( const wxArrayString& items,
+ void **clientData)
{
- m_clientDataList.Append( (wxObject*) NULL );
- m_clientObjectList.Append( (wxObject*) NULL );
-
- AppendCommon( item );
-}
+ Clear();
-void wxListBox::Append( const wxString &item, void *clientData )
-{
- m_clientDataList.Append( (wxObject*) clientData );
- m_clientObjectList.Append( (wxObject*) NULL );
+ DoInsertItems(items, 0);
- AppendCommon( item );
+ if ( clientData )
+ {
+ size_t count = items.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ SetClientData(n, clientData[n]);
+ }
+ }
}
-void wxListBox::Append( const wxString &item, wxClientData *clientData )
-{
- m_clientObjectList.Append( (wxObject*) clientData );
- m_clientDataList.Append( (wxObject*) NULL );
+// ----------------------------------------------------------------------------
+// client data
+// ----------------------------------------------------------------------------
- AppendCommon( item );
-}
-
-void wxListBox::SetClientData( int n, void* clientData )
+void wxListBox::DoSetClientData( int n, void* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientDataList.Nth( n );
- if (!node) return;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetClientData") );
node->SetData( (wxObject*) clientData );
}
-void* wxListBox::GetClientData( int n )
+void* wxListBox::DoGetClientData( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientDataList.Nth( n );
- if (!node) return NULL;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetClientData") );
return node->Data();
}
-void wxListBox::SetClientObject( int n, wxClientData* clientData )
+void wxListBox::DoSetClientObject( int n, wxClientData* clientData )
{
- wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") );
+ wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientObjectList.Nth( n );
- if (!node) return;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetClientObject") );
wxClientData *cd = (wxClientData*) node->Data();
- if (cd) delete cd;
+ delete cd;
node->SetData( (wxObject*) clientData );
}
-wxClientData* wxListBox::GetClientObject( int n )
+wxClientData* wxListBox::DoGetClientObject( int n ) const
{
- wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, wxT("invalid combobox") );
+ wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
- wxNode *node = m_clientObjectList.Nth( n );
- if (!node) return (wxClientData*) NULL;
+ wxNode *node = m_clientData.Nth( n );
+ wxCHECK_MSG( node, (wxClientData *)NULL,
+ wxT("invalid index in wxListBox::DoGetClientObject") );
return (wxClientData*) node->Data();
}
gtk_list_clear_items( m_list, 0, Number() );
- wxNode *node = m_clientObjectList.First();
- while (node)
- {
- wxClientData *cd = (wxClientData*)node->Data();
- if (cd) delete cd;
- node = node->Next();
- }
- m_clientObjectList.Clear();
+ if ( m_clientDataItemsType == ClientData_Object )
+ m_clientData.DeleteContents(TRUE);
+ m_clientData.Clear();
- m_clientDataList.Clear();
+ if ( m_strings )
+ m_strings->Clear();
}
void wxListBox::Delete( int n )
gtk_list_remove_items( m_list, list );
g_list_free( list );
- wxNode *node = m_clientObjectList.Nth( n );
- if (node)
+ wxNode *node = m_clientData.Nth( n );
+ if ( node )
{
- wxClientData *cd = (wxClientData*)node->Data();
- if (cd) delete cd;
- m_clientObjectList.DeleteNode( node );
+ if ( m_clientDataItemsType == ClientData_Object )
+ {
+ wxClientData *cd = (wxClientData*)node->Data();
+ delete cd;
+ }
+
+ m_clientData.DeleteNode( node );
}
- node = m_clientDataList.Nth( n );
- if (node)
+ if ( m_strings )
+ m_strings->Remove(n);
+}
+
+// ----------------------------------------------------------------------------
+// string list access
+// ----------------------------------------------------------------------------
+
+void wxListBox::SetString( int n, const wxString &string )
+{
+ wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
+
+ GList *child = g_list_nth( m_list->children, n );
+ if (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
+
+ wxString str;
+#if wxUSE_CHECKLISTBOX
+ if (m_hasCheckBoxes)
+ str += CHECKBOX_STRING;
+#endif // wxUSE_CHECKLISTBOX
+ str += string;
+
+ gtk_label_set( label, str.mbc_str() );
+ }
+ else
{
- m_clientDataList.DeleteNode( node );
+ wxFAIL_MSG(wxT("wrong listbox index"));
}
}
-void wxListBox::Deselect( int n )
+wxString wxListBox::GetString( int n ) const
{
- wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
+ wxCHECK_MSG( m_list != NULL, wxT(""), wxT("invalid listbox") );
- DisableEvents();
+ GList *child = g_list_nth( m_list->children, n );
+ if (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ GtkLabel *label = GTK_LABEL( bin->child );
- gtk_list_unselect_item( m_list, n );
+ wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent);
- EnableEvents();
+ return str;
+ }
+
+ wxFAIL_MSG(wxT("wrong listbox index"));
+
+ return wxT("");
+}
+
+int wxListBox::GetCount() const
+{
+ wxCHECK_MSG( m_list != NULL, -1, wxT("invalid listbox") );
+
+ GList *child = m_list->children;
+ int count = 0;
+ while (child)
+ {
+ count++;
+ child = child->next;
+ }
+
+ return count;
}
int wxListBox::FindString( const wxString &item ) const
child = child->next;
}
- // it's not an error if the string is not found -> no wxCHECK
+ // it's not an error if the string is not found -> no wxCHECK
- return -1;
+ return wxNOT_FOUND;
}
+// ----------------------------------------------------------------------------
+// selection
+// ----------------------------------------------------------------------------
+
int wxListBox::GetSelection() const
{
wxCHECK_MSG( m_list != NULL, -1, wxT("invalid listbox") );
return count;
}
-wxString wxListBox::GetString( int n ) const
-{
- wxCHECK_MSG( m_list != NULL, wxT(""), wxT("invalid listbox") );
-
- GList *child = g_list_nth( m_list->children, n );
- if (child)
- {
- GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent);
-
- return str;
- }
-
- wxFAIL_MSG(wxT("wrong listbox index"));
-
- return wxT("");
-}
-
-wxString wxListBox::GetStringSelection() const
-{
- wxCHECK_MSG( m_list != NULL, wxT(""), wxT("invalid listbox") );
-
- GList *selection = m_list->selection;
- if (selection)
- {
- GtkBin *bin = GTK_BIN( selection->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str = wxString(GET_REAL_LABEL(label->label),*wxConvCurrent);
-
- return str;
- }
-
- wxFAIL_MSG(wxT("no listbox selection available"));
- return wxT("");
-}
-
-int wxListBox::Number()
-{
- wxCHECK_MSG( m_list != NULL, -1, wxT("invalid listbox") );
-
- GList *child = m_list->children;
- int count = 0;
- while (child) { count++; child = child->next; }
- return count;
-}
-
-bool wxListBox::Selected( int n )
+bool wxListBox::IsSelected( int n ) const
{
wxCHECK_MSG( m_list != NULL, FALSE, wxT("invalid listbox") );
child = child->next;
}
}
- wxFAIL_MSG(wxT("wrong listbox index"));
- return FALSE;
-}
-
-void wxListBox::Set( int WXUNUSED(n), const wxString *WXUNUSED(choices) )
-{
- wxFAIL_MSG(wxT("wxListBox::Set not implemented"));
-}
-void wxListBox::SetFirstItem( int WXUNUSED(n) )
-{
- wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
-}
+ wxFAIL_MSG(wxT("wrong listbox index"));
-void wxListBox::SetFirstItem( const wxString &WXUNUSED(item) )
-{
- wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
+ return FALSE;
}
void wxListBox::SetSelection( int n, bool select )
EnableEvents();
}
-void wxListBox::SetString( int n, const wxString &string )
+void wxListBox::DoSetFirstItem( int WXUNUSED(n) )
{
- wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
-
- GList *child = g_list_nth( m_list->children, n );
- if (child)
- {
- GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str;
-#if wxUSE_CHECKLISTBOX
- if (m_hasCheckBoxes)
- str += CHECKBOX_STRING;
-#endif // wxUSE_CHECKLISTBOX
- str += string;
-
- gtk_label_set( label, str.mbc_str() );
- }
- else
- {
- wxFAIL_MSG(wxT("wrong listbox index"));
- }
+ wxFAIL_MSG(wxT("wxListBox::SetFirstItem not implemented"));
}
-void wxListBox::SetStringSelection( const wxString &string, bool select )
-{
- wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
-
- SetSelection( FindString(string), select );
-}
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
int wxListBox::GetIndex( GtkWidget *item ) const
{
if (GTK_WIDGET(m_list)->window && cursor.Ok())
{
/* I now set the cursor the anew in every OnInternalIdle call
- as setting the cursor in a parent window also effects the
- windows above so that checking for the current cursor is
- not possible. */
-
- gdk_window_set_cursor( GTK_WIDGET(m_list)->window, cursor.GetCursor() );
+ as setting the cursor in a parent window also effects the
+ windows above so that checking for the current cursor is
+ not possible. */
+
+ gdk_window_set_cursor( GTK_WIDGET(m_list)->window, cursor.GetCursor() );
GList *child = m_list->children;
while (child)
{
GtkBin *bin = GTK_BIN( child->data );
GtkWidget *label = GTK_WIDGET( bin->child );
-
- if (!label->window)
- break;
- else
- gdk_window_set_cursor( label->window, cursor.GetCursor() );
+
+ if (!label->window)
+ break;
+ else
+ gdk_window_set_cursor( label->window, cursor.GetCursor() );
child = child->next;
}
// list box control implementation
// ============================================================================
-bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
-{
- /*
- if (param == LBN_SELCANCEL)
- {
- event.extraLong = FALSE;
- }
- */
- if (param == LBN_SELCHANGE)
- {
- wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
- wxArrayInt aSelections;
- int count = GetSelections(aSelections);
- if ( count > 0 )
- {
- event.m_commandInt = aSelections[0] ;
- event.m_clientData = GetClientData(event.m_commandInt);
- wxString str(GetString(event.m_commandInt));
- if (str != wxT(""))
- {
- event.m_commandString = str;
- }
- }
- else
- {
- event.m_commandInt = -1 ;
- event.m_commandString.Empty();
- }
+// ----------------------------------------------------------------------------
+// creation
+// ----------------------------------------------------------------------------
- event.SetEventObject( this );
- ProcessCommand(event);
- return TRUE;
- }
- else if (param == LBN_DBLCLK)
- {
- wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
- event.SetEventObject( this );
- GetEventHandler()->ProcessEvent(event) ;
- return TRUE;
- }
-
- return FALSE;
-}
-
- // Listbox item
+// Listbox item
wxListBox::wxListBox()
{
m_noItems = 0;
wstyle |= LBS_EXTENDEDSEL;
if (m_windowStyle & wxLB_ALWAYS_SB)
- wstyle |= LBS_DISABLENOSCROLL ;
+ wstyle |= LBS_DISABLENOSCROLL;
if (m_windowStyle & wxLB_HSCROLL)
wstyle |= WS_HSCROLL;
if (m_windowStyle & wxLB_SORT)
wstyle |= LBS_NOINTEGRALHEIGHT;
bool want3D;
- WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
+ WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
- // Even with extended styles, need to combine with WS_BORDER
- // for them to look right.
+ // Even with extended styles, need to combine with WS_BORDER for them to
+ // look right.
if ( want3D || wxStyleHasBorder(m_windowStyle) )
{
wstyle |= WS_BORDER;
SetForegroundColour(GetParent()->GetForegroundColour());
}
-void wxListBox::SetFirstItem(int N)
+// ----------------------------------------------------------------------------
+// implementation of wxListBoxBase methods
+// ----------------------------------------------------------------------------
+
+void wxListBox::DoSetFirstItem(int N)
{
wxCHECK_RET( N >= 0 && N < m_noItems,
wxT("invalid index in wxListBox::SetFirstItem") );
- SendMessage(GetHwnd(),LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ;
-}
-
-void wxListBox::SetFirstItem(const wxString& s)
-{
- int N = FindString(s) ;
-
- if ( N >= 0 )
- SetFirstItem(N) ;
+ SendMessage(GetHwnd(), LB_SETTOPINDEX, (WPARAM)N, (LPARAM)0);
}
void wxListBox::Delete(int N)
SetHorizontalExtent("");
}
-void wxListBox::Append(const wxString& item)
+int wxListBox::DoAppend(const wxString& item)
{
int index = ListBox_AddString(GetHwnd(), item);
- m_noItems ++;
+ m_noItems++;
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW ) {
#endif
SetHorizontalExtent(item);
-}
-
-void wxListBox::Append(const wxString& item, void *Client_data)
-{
- int index = ListBox_AddString(GetHwnd(), item);
- m_noItems ++;
-
-#if wxUSE_OWNER_DRAWN
- if ( m_windowStyle & wxLB_OWNERDRAW ) {
- // client data must be pointer to wxOwnerDrawn, otherwise we would crash
- // in OnMeasure/OnDraw.
- wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
- }
- else
-#endif
-
- ListBox_SetItemData(GetHwnd(), index, Client_data);
- SetHorizontalExtent(item);
+ return index;
}
-void wxListBox::Set(int n, const wxString *choices, void** clientData)
+void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
{
ShowWindow(GetHwnd(), SW_HIDE);
+
ListBox_ResetContent(GetHwnd());
+
+ m_noItems = choices.GetCount();
int i;
- for (i = 0; i < n; i++)
+ for (i = 0; i < m_noItems; i++)
{
ListBox_AddString(GetHwnd(), choices[i]);
if ( clientData )
+ {
+#if wxUSE_OWNER_DRAWN
+ wxASSERT_MSG(clientData[ui] == NULL,
+ wxT("Can't use client data with owner-drawn listboxes"));
+#else // !wxUSE_OWNER_DRAWN
ListBox_SetItemData(GetHwnd(), i, clientData[i]);
+#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
+ }
}
- m_noItems = n;
#if wxUSE_OWNER_DRAWN
if ( m_windowStyle & wxLB_OWNERDRAW ) {
m_aItems.Empty();
// then create new ones
- for (ui = 0; ui < (size_t)n; ui++) {
+ for ( ui = 0; ui < (size_t)m_noItems; ui++ ) {
wxOwnerDrawn *pNewItem = CreateItem(ui);
pNewItem->SetName(choices[ui]);
m_aItems.Add(pNewItem);
ListBox_SetItemData(GetHwnd(), ui, pNewItem);
-
- wxASSERT_MSG(clientData[ui] == NULL,
- wxT("Can't use client data with owner-drawn listboxes"));
}
}
-#endif
+#endif // wxUSE_OWNER_DRAWN
+
+ SetHorizontalExtent();
- SetHorizontalExtent("");
ShowWindow(GetHwnd(), SW_SHOW);
}
{
int pos = ListBox_FindStringExact(GetHwnd(), (WPARAM)-1, s);
if (pos == LB_ERR)
- return -1;
+ return wxNOT_FOUND;
else
return pos;
}
#endif // wxUSE_OWNER_DRAWN
m_noItems = 0;
- ListBox_GetHorizontalExtent(GetHwnd());
+ SetHorizontalExtent();
}
void wxListBox::SetSelection(int N, bool select)
wxCHECK_RET( N >= 0 && N < m_noItems,
wxT("invalid index in wxListBox::SetSelection") );
- if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
+ if ( HasMultipleSelection() )
+ {
SendMessage(GetHwnd(), LB_SETSEL, select, N);
+ }
else
{
- int N1 = N;
- if (!select)
- N1 = -1;
- SendMessage(GetHwnd(), LB_SETCURSEL, N1, 0);
+ SendMessage(GetHwnd(), LB_SETCURSEL, select ? N : -1, 0);
}
}
-bool wxListBox::Selected(int N) const
+bool wxListBox::IsSelected(int N) const
{
wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE,
wxT("invalid index in wxListBox::Selected") );
return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? FALSE : TRUE;
}
-void wxListBox::Deselect(int N)
+wxClientData* wxListBox::DoGetClientObject(int n) const
{
- wxCHECK_RET( N >= 0 && N < m_noItems,
- wxT("invalid index in wxListBox::Deselect") );
-
- if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
- SendMessage(GetHwnd(), LB_SETSEL, FALSE, N);
+ return (wxClientData *)DoGetClientData(n);
}
-void *wxListBox::GetClientData(int N) const
+void *wxListBox::DoGetClientData(int n) const
{
- wxCHECK_MSG( N >= 0 && N < m_noItems, NULL,
+ wxCHECK_MSG( n >= 0 && n < m_noItems, NULL,
wxT("invalid index in wxListBox::GetClientData") );
- return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, N, 0);
+ return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
}
-void wxListBox::SetClientData(int N, void *Client_data)
+void wxListBox::DoSetClientObject(int n, wxClientData* clientData)
{
- wxCHECK_RET( N >= 0 && N < m_noItems,
+ DoSetClientData(n, clientData);
+}
+
+void wxListBox::DoSetClientData(int n, void *clientData)
+{
+ wxCHECK_RET( n >= 0 && n < m_noItems,
wxT("invalid index in wxListBox::SetClientData") );
- if ( ListBox_SetItemData(GetHwnd(), N, Client_data) == LB_ERR )
+#if wxUSE_OWNER_DRAWN
+ if ( m_windowStyle & wxLB_OWNERDRAW )
+ {
+ // client data must be pointer to wxOwnerDrawn, otherwise we would crash
+ // in OnMeasure/OnDraw.
+ wxFAIL_MSG(wxT("Can't use client data with owner-drawn listboxes"));
+ }
+#endif // wxUSE_OWNER_DRAWN
+
+ if ( ListBox_SetItemData(GetHwnd(), n, clientData) == LB_ERR )
wxLogDebug(wxT("LB_SETITEMDATA failed"));
}
+bool wxListBox::HasMultipleSelection() const
+{
+ return (m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED);
+}
+
// Return number of selections and an array of selected integers
int wxListBox::GetSelections(wxArrayInt& aSelections) const
{
aSelections.Empty();
- if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED))
+ if ( HasMultipleSelection() )
{
int no_sel = ListBox_GetSelCount(GetHwnd());
if (no_sel != 0) {
int *selections = new int[no_sel];
- if ( ListBox_GetSelItems(GetHwnd(), no_sel, selections) == LB_ERR ) {
- wxFAIL_MSG(wxT("This listbox can't have single-selection style!"));
- }
+ int rc = ListBox_GetSelItems(GetHwnd(), no_sel, selections);
+
+ wxCHECK_MSG(rc != LB_ERR, -1, wxT("ListBox_GetSelItems failed"));
aSelections.Alloc(no_sel);
for ( int n = 0; n < no_sel; n++ )
// Get single selection, for single choice list items
int wxListBox::GetSelection() const
{
- wxCHECK_MSG( !(m_windowStyle & wxLB_MULTIPLE) &&
- !(m_windowStyle & wxLB_EXTENDED),
+ wxCHECK_MSG( !HasMultipleSelection(),
-1,
wxT("GetSelection() can't be used with multiple-selection "
"listboxes, use GetSelections() instead.") );
return result;
}
+void
+wxListBox::DoInsertItems(const wxArrayString& items, int pos)
+{
+ wxCHECK_RET( pos >= 0 && pos <= m_noItems,
+ wxT("invalid index in wxListBox::InsertItems") );
+
+ int nItems = items.GetCount();
+ for ( int i = 0; i < nItems; i++ )
+ ListBox_InsertString(GetHwnd(), i + pos, items[i]);
+ m_noItems += nItems;
+
+ SetHorizontalExtent();
+}
+
+void wxListBox::SetString(int N, const wxString& s)
+{
+ wxCHECK_RET( N >= 0 && N < m_noItems,
+ wxT("invalid index in wxListBox::SetString") );
+
+ // remember the state of the item
+ bool wasSelected = IsSelected(N);
+
+ void *oldData = NULL;
+ wxClientData *oldObjData = NULL;
+ if ( m_clientDataItemsType == ClientData_Void )
+ oldData = GetClientData(N);
+ else if ( m_clientDataItemsType == ClientData_Object )
+ oldObjData = GetClientObject(N);
+
+ // delete and recreate it
+ SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
+
+ int newN = N;
+ if ( N == m_noItems - 1 )
+ newN = -1;
+
+ ListBox_InsertString(GetHwnd(), newN, s);
+
+ // restore the client data
+ if ( oldData )
+ SetClientData(N, oldData);
+ else if ( oldObjData )
+ SetClientObject(N, oldObjData);
+
+ // we may have lost the selection
+ if ( wasSelected )
+ Select(N);
+
+#if wxUSE_OWNER_DRAWN
+ if ( m_windowStyle & wxLB_OWNERDRAW )
+ // update item's text
+ m_aItems[N]->SetName(s);
+#endif //USE_OWNER_DRAWN
+}
+
+int wxListBox::GetCount() const
+{
+ return m_noItems;
+}
+
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
+
// Windows-specific code to set the horizontal extent of the listbox, if
// necessary. If s is non-NULL, it's used to calculate the horizontal extent.
// Otherwise, all strings are used.
return;
TEXTMETRIC lpTextMetric;
- if (s != wxT(""))
+ if ( !s.IsEmpty() )
{
int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L);
HDC dc = GetWindowDC(GetHwnd());
ReleaseDC(GetHwnd(), dc);
if (extentX > existingExtent)
SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L);
- return;
}
else
{
}
}
-void
-wxListBox::InsertItems(int nItems, const wxString items[], int pos)
-{
- wxCHECK_RET( pos >= 0 && pos <= m_noItems,
- wxT("invalid index in wxListBox::InsertItems") );
-
- int i;
- for (i = 0; i < nItems; i++)
- ListBox_InsertString(GetHwnd(), i + pos, items[i]);
- m_noItems += nItems;
-
- SetHorizontalExtent(wxT(""));
-}
-
-void wxListBox::SetString(int N, const wxString& s)
-{
- wxCHECK_RET( N >= 0 && N < m_noItems,
- wxT("invalid index in wxListBox::SetString") );
-
- int sel = -1;
- if (!(m_windowStyle & wxLB_MULTIPLE) && !(m_windowStyle & wxLB_EXTENDED))
- sel = GetSelection();
-
- void *oldData = wxListBox::GetClientData(N);
-
- SendMessage(GetHwnd(), LB_DELETESTRING, N, 0);
-
- int newN = N;
- if (N == (m_noItems - 1))
- newN = -1;
-
- SendMessage(GetHwnd(), LB_INSERTSTRING, newN, (LPARAM) (const wxChar *)s);
- if (oldData)
- wxListBox::SetClientData(N, oldData);
-
- // Selection may have changed
- if (sel >= 0)
- SetSelection(sel);
-
-#if wxUSE_OWNER_DRAWN
- if ( m_windowStyle & wxLB_OWNERDRAW )
- // update item's text
- m_aItems[N]->SetName(s);
-#endif //USE_OWNER_DRAWN
-}
-
-int wxListBox::Number () const
-{
- return m_noItems;
-}
-
-// For single selection items only
-wxString wxListBox::GetStringSelection () const
-{
- int sel = GetSelection ();
- if (sel > -1)
- return this->GetString (sel);
- else
- return wxString("");
-}
-
-bool wxListBox::SetStringSelection (const wxString& s, bool flag)
-{
- int sel = FindString (s);
- if (sel > -1)
- {
- SetSelection (sel, flag);
- return TRUE;
- }
- else
- return FALSE;
-}
-
wxSize wxListBox::DoGetBestSize()
{
// find the widest string
return wxSize(wListbox, hListbox);
}
-// Is this the right thing? Won't setselection generate a command
-// event too? No! It'll just generate a setselection event.
-// But we still can't have this being called whenever a real command
-// is generated, because it sets the selection, which will already
-// have been done! (Unless we have an optional argument for calling
-// by the actual window system, or a separate function, ProcessCommand)
-void wxListBox::Command (wxCommandEvent & event)
+// ----------------------------------------------------------------------------
+// callbacks
+// ----------------------------------------------------------------------------
+
+bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
- if (event.m_extraLong)
- SetSelection (event.m_commandInt);
- else
+ /*
+ if (param == LBN_SELCANCEL)
+ {
+ event.extraLong = FALSE;
+ }
+ */
+ if (param == LBN_SELCHANGE)
{
- Deselect (event.m_commandInt);
- return;
+ wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, m_windowId);
+ wxArrayInt aSelections;
+ int count = GetSelections(aSelections);
+ if ( count > 0 )
+ {
+ event.m_commandInt = aSelections[0];
+ event.m_clientData = GetClientData(event.m_commandInt);
+ wxString str(GetString(event.m_commandInt));
+ if (str != wxT(""))
+ {
+ event.m_commandString = str;
+ }
+ }
+ else
+ {
+ event.m_commandInt = -1;
+ event.m_commandString.Empty();
+ }
+
+ event.SetEventObject( this );
+ ProcessCommand(event);
+ return TRUE;
}
- ProcessCommand (event);
+ else if (param == LBN_DBLCLK)
+ {
+ wxCommandEvent event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, m_windowId);
+ event.SetEventObject( this );
+ GetEventHandler()->ProcessEvent(event);
+ return TRUE;
+ }
+
+ return FALSE;
}
WXHBRUSH wxListBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
- WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+ WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
#if wxUSE_CTL3D
if ( m_useCtl3D )
return (WXHBRUSH) backgroundBrush->GetResourceHandle();
}
-long wxListBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
-{
- return wxControl::MSWWindowProc(nMsg, wParam, lParam);
-}
+// ----------------------------------------------------------------------------
+// wxCheckListBox support
+// ----------------------------------------------------------------------------
#if wxUSE_OWNER_DRAWN
-# This file was automatically generated by tmake at 15:16, 1999/10/21
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE B32.T!
#
$(MSWDIR)\intl.obj \
$(MSWDIR)\ipcbase.obj \
$(MSWDIR)\layout.obj \
+ $(MSWDIR)\lboxcmn.obj \
$(MSWDIR)\list.obj \
$(MSWDIR)\log.obj \
$(MSWDIR)\memory.obj \
$(MSWDIR)\layout.obj: $(COMMDIR)\layout.$(SRCSUFF)
+$(MSWDIR)\lboxcmn.obj: $(COMMDIR)\lboxcmn.$(SRCSUFF)
+
$(MSWDIR)\list.obj: $(COMMDIR)\list.$(SRCSUFF)
$(MSWDIR)\log.obj: $(COMMDIR)\log.$(SRCSUFF)
-# This file was automatically generated by tmake at 15:16, 1999/10/21
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BCC.T!
#
$(MSWDIR)\intl.obj \
$(MSWDIR)\ipcbase.obj \
$(MSWDIR)\layout.obj \
+ $(MSWDIR)\lboxcmn.obj \
$(MSWDIR)\list.obj \
$(MSWDIR)\log.obj \
$(MSWDIR)\memory.obj \
$(MSWDIR)\layout.obj: $(COMMDIR)\layout.$(SRCSUFF)
+$(MSWDIR)\lboxcmn.obj: $(COMMDIR)\lboxcmn.$(SRCSUFF)
+
$(MSWDIR)\list.obj: $(COMMDIR)\list.$(SRCSUFF)
$(MSWDIR)\log.obj: $(COMMDIR)\log.$(SRCSUFF)
-# This file was automatically generated by tmake at 15:16, 1999/10/21
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE DOS.T!
#
$(COMMDIR)\intl.obj \
$(COMMDIR)\ipcbase.obj \
$(COMMDIR)\layout.obj \
+ $(COMMDIR)\lboxcmn.obj \
$(COMMDIR)\list.obj \
$(COMMDIR)\log.obj \
$(COMMDIR)\memory.obj \
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
+$(COMMDIR)/lboxcmn.obj: $*.$(SRCSUFF)
+ cl @<<
+$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
+<<
+
$(COMMDIR)/list.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
-
-# This file was automatically generated by tmake at 12:32, 1999/10/22
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE G95.T!
#
$(COMMDIR)/intl.$(OBJSUFF) \
$(COMMDIR)/ipcbase.$(OBJSUFF) \
$(COMMDIR)/layout.$(OBJSUFF) \
+ $(COMMDIR)/lboxcmn.$(OBJSUFF) \
$(COMMDIR)/list.$(OBJSUFF) \
$(COMMDIR)/log.$(OBJSUFF) \
$(COMMDIR)/memory.$(OBJSUFF) \
$(MSWDIR)/window.$(OBJSUFF) \
$(MSWDIR)/xpmhand.$(OBJSUFF)
-ADVANCEDOBJS = \
- $(COMMDIR)/odbc.$(OBJSUFF) \
- $(MSWDIR)/ole/automtn.$(OBJSUFF) \
- $(MSWDIR)/ole/dataobj.$(OBJSUFF) \
- $(MSWDIR)/ole/dropsrc.$(OBJSUFF) \
- $(MSWDIR)/ole/droptgt.$(OBJSUFF) \
- $(MSWDIR)/ole/oleutils.$(OBJSUFF) \
- $(MSWDIR)/ole/uuid.$(OBJSUFF)
-
ZLIBOBJS = \
$(ZLIBDIR)/adler32.$(OBJSUFF) \
$(ZLIBDIR)/compress.$(OBJSUFF) \
$(XPMDIR)/wrffrp.o $(XPMDIR)/wrffri.o
OBJECTS = $(MSWOBJS) $(COMMONOBJS) $(GENERICOBJS) $(HTMLOBJS) \
- $(JPEGOBJS) $(PNGOBJS) $(ZLIBOBJS) # $(ADVANCEDOBJS) # $(XPMOBJECTS)
-
-ifeq ($(MINGW32),1)
- ifeq ($(MINGW32VERSION),2.95)
- OBJECTS = $(MSWOBJS) $(COMMONOBJS) $(GENERICOBJS) $(HTMLOBJS) \
- $(JPEGOBJS) $(PNGOBJS) $(ZLIBOBJS) $(ADVANCEDOBJS) # $(XPMOBJECTS)
- else
- OBJECTS = $(MSWOBJS) $(COMMONOBJS) $(GENERICOBJS) $(HTMLOBJS) \
- $(JPEGOBJS) $(PNGOBJS) $(ZLIBOBJS) # $(XPMOBJECTS)
- endif
-else
- OBJECTS = $(MSWOBJS) $(COMMONOBJS) $(GENERICOBJS) $(HTMLOBJS) \
$(JPEGOBJS) $(PNGOBJS) $(ZLIBOBJS) # $(XPMOBJECTS)
-endif
all: $(OBJECTS) $(WXLIB)
# mv y.tab.c $(COMMDIR)/y_tab.c
clean:
- rm -f *.o
- rm -f *.bak
- rm -f core
- rm -f ..\common\y_tab.c
- rm -f ..\common\lex_yy.c
- rm -f ..\common\*.o
- rm -f ..\common\*.bak
- rm -f ..\generic\*.o
- rm -f ..\generic\*.bak
- rm -f ..\html\*.o
- rm -f ..\png\*.o
- rm -f ..\png\*.bak
- rm -f ..\zlib\*.o
- rm -f ..\zlib\*.bak
- rm -f ..\jpeg\*.o
- rm -f ..\..\lib\libwx.a
+ -erase *.o
+ -erase *.bak
+ -erase core
+ -erase ..\common\y_tab.c
+ -erase ..\common\lex_yy.c
+ -erase ..\common\*.o
+ -erase ..\common\*.bak
+ -erase ..\generic\*.o
+ -erase ..\generic\*.bak
+ -erase ..\html\*.o
+ -erase ..\png\*.o
+ -erase ..\png\*.bak
+ -erase ..\zlib\*.o
+ -erase ..\zlib\*.bak
+ -erase ..\jpeg\*.o
+ -erase ..\..\lib\libwx.a
cleanall: clean
-# This file was automatically generated by tmake at 15:16, 1999/10/21
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE SC.T!
# Symantec C++ makefile for the msw objects
$(COMMDIR)\intl.obj \
$(COMMDIR)\ipcbase.obj \
$(COMMDIR)\layout.obj \
+ $(COMMDIR)\lboxcmn.obj \
$(COMMDIR)\list.obj \
$(COMMDIR)\log.obj \
$(COMMDIR)\memory.obj \
-# This file was automatically generated by tmake at 15:16, 1999/10/21
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE VC.T!
# File: makefile.vc
..\common\$D\intl.obj \
..\common\$D\ipcbase.obj \
..\common\$D\layout.obj \
+ ..\common\$D\lboxcmn.obj \
..\common\$D\list.obj \
..\common\$D\log.obj \
..\common\$D\memory.obj \
-# This file was automatically generated by tmake at 15:16, 1999/10/21
+# This file was automatically generated by tmake at 16:37, 1999/10/22
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE WAT.T!
#!/binb/wmake.exe
intl.obj &
ipcbase.obj &
layout.obj &
+ lboxcmn.obj &
list.obj &
log.obj &
memory.obj &
layout.obj: $(COMMDIR)\layout.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+lboxcmn.obj: $(COMMDIR)\lboxcmn.cpp
+ *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+
list.obj: $(COMMDIR)\list.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<