X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd0eed647daeb257f28699de879d2f4f5aeb7fb6..ef44a62179cde47dffb369b9731b2f74d54de52f:/src/gtk1/listbox.cpp?ds=sidebyside diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 2896e62535..2793afeb92 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -17,6 +17,16 @@ #include "wx/utils.h" #include +//------------------------------------------------------------------------- +// conditional compilation +//------------------------------------------------------------------------- + +#if (GTK_MINOR_VERSION == 1) +#if (GTK_MICRO_VERSION >= 5) +#define NEW_GTK_SCROLL_CODE +#endif +#endif + //----------------------------------------------------------------------------- // data //----------------------------------------------------------------------------- @@ -91,7 +101,12 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, gtk_list_set_selection_mode( GTK_LIST(m_list), mode ); +#ifdef NEW_GTK_SCROLL_CODE + gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), GTK_WIDGET(m_list) ); +#else gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) ); +#endif + gtk_widget_show( GTK_WIDGET(m_list) ); wxSize newSize = size; @@ -101,6 +116,9 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, for (int i = 0; i < n; i++) { + m_clientDataList.Append( (wxObject*) NULL ); + m_clientObjectList.Append( (wxObject*) NULL ); + GtkWidget *list_item; list_item = gtk_list_item_new_with_label( choices[i] ); @@ -115,8 +133,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, ConnectWidget( list_item ); - m_clientDataList.Append( (wxObject*)NULL ); - gtk_widget_show( list_item ); } @@ -138,14 +154,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, wxListBox::~wxListBox() { - wxNode *node = m_clientDataList.First(); - while (node) - { - wxClientData *cd = (wxClientData*)node->Data(); - if (cd) delete cd; - node = node->Next(); - } - m_clientDataList.Clear(); + Clear(); } void wxListBox::AppendCommon( const wxString &item ) @@ -169,29 +178,31 @@ void wxListBox::AppendCommon( const wxString &item ) ConnectWidget( list_item ); - ConnectDnDWidget( list_item ); +#ifndef NEW_GTK_DND_CODE + if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); +#endif } void wxListBox::Append( const wxString &item ) { - m_clientDataList.Append( (wxObject*)NULL ); + m_clientDataList.Append( (wxObject*) NULL ); + m_clientObjectList.Append( (wxObject*) NULL ); AppendCommon( item ); } void wxListBox::Append( const wxString &item, void *clientData ) { - if (clientData) - m_clientDataList.Append( (wxObject*) new wxVoidClientData( clientData ) ); - else - m_clientDataList.Append( (wxObject*)NULL ); + m_clientDataList.Append( (wxObject*) clientData ); + m_clientObjectList.Append( (wxObject*) NULL ); AppendCommon( item ); } void wxListBox::Append( const wxString &item, wxClientData *clientData ) { - m_clientDataList.Append( (wxObject*) clientData ); + m_clientObjectList.Append( (wxObject*) clientData ); + m_clientDataList.Append( (wxObject*) NULL ); AppendCommon( item ); } @@ -203,13 +214,7 @@ void wxListBox::SetClientData( int n, void* clientData ) wxNode *node = m_clientDataList.Nth( n ); if (!node) return; - wxClientData *cd = (wxClientData*) node->Data(); - if (cd) delete cd; - - if (clientData) - node->SetData( (wxObject*) new wxVoidClientData(clientData) ); - else - node->SetData( (wxObject*) NULL ); + node->SetData( (wxObject*) clientData ); } void* wxListBox::GetClientData( int n ) @@ -219,18 +224,14 @@ void* wxListBox::GetClientData( int n ) wxNode *node = m_clientDataList.Nth( n ); if (!node) return NULL; - wxVoidClientData *cd = (wxVoidClientData*) node->Data(); - if (cd) - return cd->GetData(); - else - return (void*) NULL; + return node->Data(); } void wxListBox::SetClientObject( int n, wxClientData* clientData ) { wxCHECK_RET( m_widget != NULL, "invalid combobox" ); - wxNode *node = m_clientDataList.Nth( n ); + wxNode *node = m_clientObjectList.Nth( n ); if (!node) return; wxClientData *cd = (wxClientData*) node->Data(); @@ -243,7 +244,7 @@ wxClientData* wxListBox::GetClientObject( int n ) { wxCHECK_MSG( m_widget != NULL, (wxClientData*)NULL, "invalid combobox" ); - wxNode *node = m_clientDataList.Nth( n ); + wxNode *node = m_clientObjectList.Nth( n ); if (!node) return (wxClientData*) NULL; return (wxClientData*) node->Data(); @@ -255,13 +256,15 @@ void wxListBox::Clear() gtk_list_clear_items( m_list, 0, Number() ); - wxNode *node = m_clientDataList.First(); + wxNode *node = m_clientObjectList.First(); while (node) { wxClientData *cd = (wxClientData*)node->Data(); if (cd) delete cd; node = node->Next(); } + m_clientObjectList.Clear(); + m_clientDataList.Clear(); } @@ -281,15 +284,17 @@ void wxListBox::Delete( int n ) gtk_list_remove_items( m_list, list ); g_list_free( list ); - wxNode *node = m_clientDataList.Nth( n ); - if (!node) - { - wxFAIL_MSG( "wrong index" ); - } - else + wxNode *node = m_clientObjectList.Nth( n ); + if (node) { wxClientData *cd = (wxClientData*)node->Data(); if (cd) delete cd; + m_clientObjectList.DeleteNode( node ); + } + + node = m_clientDataList.Nth( n ); + if (node) + { m_clientDataList.DeleteNode( node ); } } @@ -493,21 +498,31 @@ void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { wxCHECK_RET( m_list != NULL, "invalid listbox" ); - GList *child = m_list->children; - while (child) +#ifndef NEW_GTK_DND_CODE + if (m_dropTarget) { - DisconnectDnDWidget( GTK_WIDGET( child->data ) ); - child = child->next; + GList *child = m_list->children; + while (child) + { + m_dropTarget->UnregisterWidget( GTK_WIDGET( child->data ) ); + child = child->next; + } } +#endif + + wxWindow::SetDropTarget( dropTarget ); - wxWindow::SetDropTarget( dropTarget ); - - child = m_list->children; - while (child) +#ifndef NEW_GTK_DND_CODE + if (m_dropTarget) { - ConnectDnDWidget( GTK_WIDGET( child->data ) ); - child = child->next; + GList *child = m_list->children; + while (child) + { + m_dropTarget->RegisterWidget( GTK_WIDGET( child->data ) ); + child = child->next; + } } +#endif } GtkWidget *wxListBox::GetConnectWidget() @@ -534,10 +549,13 @@ void wxListBox::ApplyWidgetStyle() { SetWidgetStyle(); - GdkWindow *window = GTK_WIDGET(m_list)->window; - m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); - gdk_window_set_background( window, m_backgroundColour.GetColor() ); - gdk_window_clear( window ); + if (m_backgroundColour.Ok()) + { + GdkWindow *window = GTK_WIDGET(m_list)->window; + m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) ); + gdk_window_set_background( window, m_backgroundColour.GetColor() ); + gdk_window_clear( window ); + } GList *child = m_list->children; while (child)