fix wxCheckListBox which was completely broken by the Unicode changes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16968 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -102,6 +102,9 @@ public:
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
// return the string label for the given item
|
||||
wxString GetRealLabel(struct _GList *item) const;
|
||||
|
||||
private:
|
||||
// this array is only used for controls with wxCB_SORT style, so only
|
||||
// allocate it if it's needed (hence using pointer)
|
||||
|
@@ -102,6 +102,9 @@ public:
|
||||
protected:
|
||||
virtual wxSize DoGetBestSize() const;
|
||||
|
||||
// return the string label for the given item
|
||||
wxString GetRealLabel(struct _GList *item) const;
|
||||
|
||||
private:
|
||||
// this array is only used for controls with wxCB_SORT style, so only
|
||||
// allocate it if it's needed (hence using pointer)
|
||||
|
@@ -38,24 +38,6 @@
|
||||
extern void wxapp_install_idle_handler();
|
||||
extern bool g_isIdle;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// private functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_CHECKLISTBOX
|
||||
|
||||
// checklistboxes have "[<5B>] " prepended to their lables, this macro removes it
|
||||
// (NB: 4 below is the length of wxCHECKLBOX_STRING above)
|
||||
//
|
||||
// the argument to it is a "const char *" pointer
|
||||
#define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
|
||||
|
||||
#else // !wxUSE_CHECKLISTBOX
|
||||
|
||||
#define GET_REAL_LABEL(label) (label)
|
||||
|
||||
#endif // wxUSE_CHECKLISTBOX
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// data
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -431,6 +413,10 @@ wxListBox::~wxListBox()
|
||||
delete m_strings;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// adding items
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
{
|
||||
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
|
||||
@@ -612,52 +598,9 @@ void wxListBox::DoSetItems( const wxArrayString& items,
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// deleting items
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxListBox::DoSetItemClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientData") );
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
void* wxListBox::DoGetItemClientData( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetItemClientData") );
|
||||
|
||||
return node->Data();
|
||||
}
|
||||
|
||||
void wxListBox::DoSetItemClientObject( int n, wxClientData* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientObject") );
|
||||
|
||||
// wxItemContainer already deletes data for us
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
wxClientData* wxListBox::DoGetItemClientObject( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, (wxClientData *)NULL,
|
||||
wxT("invalid index in wxListBox::DoGetItemClientObject") );
|
||||
|
||||
return (wxClientData*) node->Data();
|
||||
}
|
||||
|
||||
void wxListBox::Clear()
|
||||
{
|
||||
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
|
||||
@@ -716,10 +659,81 @@ void wxListBox::Delete( int n )
|
||||
m_strings->Remove(n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxListBox::DoSetItemClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientData") );
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
void* wxListBox::DoGetItemClientData( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetItemClientData") );
|
||||
|
||||
return node->Data();
|
||||
}
|
||||
|
||||
void wxListBox::DoSetItemClientObject( int n, wxClientData* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientObject") );
|
||||
|
||||
// wxItemContainer already deletes data for us
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
wxClientData* wxListBox::DoGetItemClientObject( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, (wxClientData *)NULL,
|
||||
wxT("invalid index in wxListBox::DoGetItemClientObject") );
|
||||
|
||||
return (wxClientData*) node->Data();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// string list access
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxListBox::GetRealLabel(GList *item) const
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( item->data );
|
||||
GtkLabel *label = GTK_LABEL( bin->child );
|
||||
|
||||
wxString str;
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
str = wxGTK_CONV_BACK( gtk_label_get_text( label ) );
|
||||
#else
|
||||
str = wxString( label->label );
|
||||
#endif
|
||||
|
||||
#if wxUSE_CHECKLISTBOX
|
||||
// checklistboxes have "[<5B>] " prepended to their lables, remove it
|
||||
//
|
||||
// NB: 4 below is the length of wxCHECKLBOX_STRING from wx/gtk/checklst.h
|
||||
if ( m_hasCheckBoxes )
|
||||
str.erase(0, 4);
|
||||
#endif // wxUSE_CHECKLISTBOX
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void wxListBox::SetString( int n, const wxString &string )
|
||||
{
|
||||
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
|
||||
@@ -752,16 +766,7 @@ wxString wxListBox::GetString( int n ) const
|
||||
GList *child = g_list_nth( m_list->children, n );
|
||||
if (child)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkLabel *label = GTK_LABEL( bin->child );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString str = wxGTK_CONV_BACK( gtk_label_get_text( label ) );
|
||||
#else
|
||||
wxString str = wxString( label->label );
|
||||
#endif
|
||||
|
||||
return str;
|
||||
return GetRealLabel(child);
|
||||
}
|
||||
|
||||
wxFAIL_MSG(wxT("wrong listbox index"));
|
||||
@@ -785,16 +790,7 @@ int wxListBox::FindString( const wxString &item ) const
|
||||
int count = 0;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkLabel *label = GTK_LABEL( bin->child );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString str = wxGTK_CONV_BACK( gtk_label_get_text( label ) );
|
||||
#else
|
||||
wxString str = wxString( label->label );
|
||||
#endif
|
||||
|
||||
if (str == item)
|
||||
if ( GetRealLabel(child) == item )
|
||||
return count;
|
||||
|
||||
count++;
|
||||
|
@@ -38,24 +38,6 @@
|
||||
extern void wxapp_install_idle_handler();
|
||||
extern bool g_isIdle;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// private functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if wxUSE_CHECKLISTBOX
|
||||
|
||||
// checklistboxes have "[<5B>] " prepended to their lables, this macro removes it
|
||||
// (NB: 4 below is the length of wxCHECKLBOX_STRING above)
|
||||
//
|
||||
// the argument to it is a "const char *" pointer
|
||||
#define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
|
||||
|
||||
#else // !wxUSE_CHECKLISTBOX
|
||||
|
||||
#define GET_REAL_LABEL(label) (label)
|
||||
|
||||
#endif // wxUSE_CHECKLISTBOX
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// data
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -431,6 +413,10 @@ wxListBox::~wxListBox()
|
||||
delete m_strings;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// adding items
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
|
||||
{
|
||||
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
|
||||
@@ -612,52 +598,9 @@ void wxListBox::DoSetItems( const wxArrayString& items,
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// deleting items
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxListBox::DoSetItemClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientData") );
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
void* wxListBox::DoGetItemClientData( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetItemClientData") );
|
||||
|
||||
return node->Data();
|
||||
}
|
||||
|
||||
void wxListBox::DoSetItemClientObject( int n, wxClientData* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientObject") );
|
||||
|
||||
// wxItemContainer already deletes data for us
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
wxClientData* wxListBox::DoGetItemClientObject( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, (wxClientData *)NULL,
|
||||
wxT("invalid index in wxListBox::DoGetItemClientObject") );
|
||||
|
||||
return (wxClientData*) node->Data();
|
||||
}
|
||||
|
||||
void wxListBox::Clear()
|
||||
{
|
||||
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
|
||||
@@ -716,10 +659,81 @@ void wxListBox::Delete( int n )
|
||||
m_strings->Remove(n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// client data
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxListBox::DoSetItemClientData( int n, void* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientData") );
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
void* wxListBox::DoGetItemClientData( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, NULL, wxT("invalid index in wxListBox::DoGetItemClientData") );
|
||||
|
||||
return node->Data();
|
||||
}
|
||||
|
||||
void wxListBox::DoSetItemClientObject( int n, wxClientData* clientData )
|
||||
{
|
||||
wxCHECK_RET( m_widget != NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_RET( node, wxT("invalid index in wxListBox::DoSetItemClientObject") );
|
||||
|
||||
// wxItemContainer already deletes data for us
|
||||
|
||||
node->SetData( (wxObject*) clientData );
|
||||
}
|
||||
|
||||
wxClientData* wxListBox::DoGetItemClientObject( int n ) const
|
||||
{
|
||||
wxCHECK_MSG( m_widget != NULL, (wxClientData*) NULL, wxT("invalid listbox control") );
|
||||
|
||||
wxNode *node = m_clientList.Nth( n );
|
||||
wxCHECK_MSG( node, (wxClientData *)NULL,
|
||||
wxT("invalid index in wxListBox::DoGetItemClientObject") );
|
||||
|
||||
return (wxClientData*) node->Data();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// string list access
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxListBox::GetRealLabel(GList *item) const
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( item->data );
|
||||
GtkLabel *label = GTK_LABEL( bin->child );
|
||||
|
||||
wxString str;
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
str = wxGTK_CONV_BACK( gtk_label_get_text( label ) );
|
||||
#else
|
||||
str = wxString( label->label );
|
||||
#endif
|
||||
|
||||
#if wxUSE_CHECKLISTBOX
|
||||
// checklistboxes have "[<5B>] " prepended to their lables, remove it
|
||||
//
|
||||
// NB: 4 below is the length of wxCHECKLBOX_STRING from wx/gtk/checklst.h
|
||||
if ( m_hasCheckBoxes )
|
||||
str.erase(0, 4);
|
||||
#endif // wxUSE_CHECKLISTBOX
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
void wxListBox::SetString( int n, const wxString &string )
|
||||
{
|
||||
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
|
||||
@@ -752,16 +766,7 @@ wxString wxListBox::GetString( int n ) const
|
||||
GList *child = g_list_nth( m_list->children, n );
|
||||
if (child)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkLabel *label = GTK_LABEL( bin->child );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString str = wxGTK_CONV_BACK( gtk_label_get_text( label ) );
|
||||
#else
|
||||
wxString str = wxString( label->label );
|
||||
#endif
|
||||
|
||||
return str;
|
||||
return GetRealLabel(child);
|
||||
}
|
||||
|
||||
wxFAIL_MSG(wxT("wrong listbox index"));
|
||||
@@ -785,16 +790,7 @@ int wxListBox::FindString( const wxString &item ) const
|
||||
int count = 0;
|
||||
while (child)
|
||||
{
|
||||
GtkBin *bin = GTK_BIN( child->data );
|
||||
GtkLabel *label = GTK_LABEL( bin->child );
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
wxString str = wxGTK_CONV_BACK( gtk_label_get_text( label ) );
|
||||
#else
|
||||
wxString str = wxString( label->label );
|
||||
#endif
|
||||
|
||||
if (str == item)
|
||||
if ( GetRealLabel(child) == item )
|
||||
return count;
|
||||
|
||||
count++;
|
||||
|
Reference in New Issue
Block a user