extern void wxapp_install_idle_handler();
extern bool g_isIdle;
-//-----------------------------------------------------------------------------
-// private functions
-//-----------------------------------------------------------------------------
-
-#if wxUSE_CHECKLISTBOX
-
-// checklistboxes have "[±] " 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
//-----------------------------------------------------------------------------
if (!listbox->m_hasVMT) return;
if (g_blockEventsOnDrag) return;
-
+
if (listbox->m_blockEvent) return;
wxCommandEvent event(wxEVT_COMMAND_LISTBOX_SELECTED, listbox->GetId() );
event.SetEventObject( listbox );
-
+
// MSW doesn't do that either
// event.SetExtraLong( (long) is_selection );
delete m_strings;
}
+// ----------------------------------------------------------------------------
+// adding items
+// ----------------------------------------------------------------------------
+
void wxListBox::DoInsertItems(const wxArrayString& items, int pos)
{
wxCHECK_RET( m_list != NULL, wxT("invalid listbox") );
}
// ----------------------------------------------------------------------------
-// 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") );
-
- wxClientData *cd = (wxClientData*) node->Data();
- delete cd;
-
- 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") );
gtk_list_clear_items( m_list, 0, GetCount() );
-
+
if ( GTK_LIST(m_list)->last_focus_child != NULL )
{
// This should be NULL, I think.
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 "[±] " 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") );
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 = wxGTK_CONV_BACK( GET_REAL_LABEL(label->label) );
-
- return str;
+ return GetRealLabel(child);
}
wxFAIL_MSG(wxT("wrong listbox index"));
int count = 0;
while (child)
{
- GtkBin *bin = GTK_BIN( child->data );
- GtkLabel *label = GTK_LABEL( bin->child );
-
- wxString str = wxGTK_CONV_BACK( GET_REAL_LABEL(label->label) );
-
- if (str == item)
+ if ( GetRealLabel(child) == item )
return count;
count++;
else
gtk_list_unselect_item( m_list, n );
- m_blockEvent = FALSE;
+ m_blockEvent = FALSE;
}
void wxListBox::DoSetFirstItem( int n )
float y = item->allocation.y;
if (y > adjustment->upper - adjustment->page_size)
y = adjustment->upper - adjustment->page_size;
- gtk_adjustment_set_value( adjustment, y );
+ gtk_adjustment_set_value( adjustment, y );
}
// ----------------------------------------------------------------------------