1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "listbox.h"
15 #include "wx/listbox.h"
19 #include "wx/dynarray.h"
22 #include "wx/checklst.h"
23 #include "wx/settings.h"
26 #include "wx/tooltip.h"
29 #if wxUSE_DRAG_AND_DROP
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 extern void wxapp_install_idle_handler();
43 //-------------------------------------------------------------------------
44 // conditional compilation
45 //-------------------------------------------------------------------------
47 #if (GTK_MINOR_VERSION > 0)
48 #define NEW_GTK_SCROLL_CODE
51 //-----------------------------------------------------------------------------
53 //-----------------------------------------------------------------------------
55 #if wxUSE_CHECKLISTBOX
57 #define CHECKBOX_STRING "[-] "
59 // checklistboxes have "[±] " prepended to their lables, this macro removes it
60 // (NB: 4 below is the length of CHECKBOX_STRING above)
62 // the argument to it is a "const char *" pointer
63 #define GET_REAL_LABEL(label) ((m_hasCheckBoxes)?(label)+4 : (label))
65 #else // !wxUSE_CHECKLISTBOX
67 #define GET_REAL_LABEL(label) (label)
69 #endif // wxUSE_CHECKLISTBOX
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 extern bool g_blockEventsOnDrag
;
76 extern bool g_blockEventsOnScroll
;
78 static bool g_hasDoubleClicked
= FALSE
;
80 //-----------------------------------------------------------------------------
81 // "button_release_event"
82 //-----------------------------------------------------------------------------
84 /* we would normally emit a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event once
85 a GDK_2BUTTON_PRESS occurs, but this has the particular problem of the
86 listbox keeping the focus until it receives a GDK_BUTTON_RELEASE event.
87 this can lead to race conditions so that we emit the dclick event
88 after the GDK_BUTTON_RELEASE event after the GDK_2BUTTON_PRESS event */
91 gtk_listbox_button_release_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxListBox
*listbox
)
93 if (g_isIdle
) wxapp_install_idle_handler();
95 if (g_blockEventsOnDrag
) return FALSE
;
96 if (g_blockEventsOnScroll
) return FALSE
;
98 if (!listbox
->m_hasVMT
) return FALSE
;
100 if (!g_hasDoubleClicked
) return FALSE
;
102 wxCommandEvent
event( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
103 event
.SetEventObject( listbox
);
105 wxArrayInt aSelections
;
106 int count
= listbox
->GetSelections(aSelections
);
109 event
.m_commandInt
= aSelections
[0] ;
110 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
111 wxString
str(listbox
->GetString(event
.m_commandInt
));
112 if (!str
.IsEmpty()) event
.m_commandString
= str
;
116 event
.m_commandInt
= -1 ;
117 event
.m_commandString
.Empty();
120 listbox
->GetEventHandler()->ProcessEvent( event
);
125 //-----------------------------------------------------------------------------
126 // "button_press_event"
127 //-----------------------------------------------------------------------------
130 gtk_listbox_button_press_callback( GtkWidget
*widget
, GdkEventButton
*gdk_event
, wxListBox
*listbox
)
132 if (g_isIdle
) wxapp_install_idle_handler();
134 if (g_blockEventsOnDrag
) return FALSE
;
135 if (g_blockEventsOnScroll
) return FALSE
;
137 if (!listbox
->m_hasVMT
) return FALSE
;
139 int sel
= listbox
->GetIndex( widget
);
141 #if wxUSE_CHECKLISTBOX
142 if ((listbox
->m_hasCheckBoxes
) && (gdk_event
->x
< 15) && (gdk_event
->type
!= GDK_2BUTTON_PRESS
))
144 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
146 clb
->Check( sel
, !clb
->IsChecked(sel
) );
148 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
149 event
.SetEventObject( listbox
);
151 listbox
->GetEventHandler()->ProcessEvent( event
);
153 #endif // wxUSE_CHECKLISTBOX
155 /* emit wxEVT_COMMAND_LISTBOX_DOUBLECLICKED later */
156 g_hasDoubleClicked
= (gdk_event
->type
== GDK_2BUTTON_PRESS
);
161 //-----------------------------------------------------------------------------
163 //-----------------------------------------------------------------------------
165 #if wxUSE_CHECKLISTBOX
167 gtk_listbox_key_press_callback( GtkWidget
*widget
, GdkEventKey
*gdk_event
, wxListBox
*listbox
)
169 if (g_isIdle
) wxapp_install_idle_handler();
171 if (g_blockEventsOnDrag
) return FALSE
;
173 if (!listbox
->m_hasVMT
) return FALSE
;
175 if (gdk_event
->keyval
!= ' ') return FALSE
;
177 int sel
= listbox
->GetIndex( widget
);
179 wxCheckListBox
*clb
= (wxCheckListBox
*)listbox
;
181 clb
->Check( sel
, !clb
->IsChecked(sel
) );
183 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, listbox
->GetId() );
184 event
.SetEventObject( listbox
);
186 listbox
->GetEventHandler()->ProcessEvent( event
);
190 #endif // wxUSE_CHECKLISTBOX
192 //-----------------------------------------------------------------------------
193 // "select" and "deselect"
194 //-----------------------------------------------------------------------------
196 static void gtk_listitem_select_callback( GtkWidget
*WXUNUSED(widget
), wxListBox
*listbox
)
198 if (g_isIdle
) wxapp_install_idle_handler();
200 if (!listbox
->m_hasVMT
) return;
201 if (g_blockEventsOnDrag
) return;
203 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
205 wxArrayInt aSelections
;
206 int count
= listbox
->GetSelections(aSelections
);
209 event
.m_commandInt
= aSelections
[0] ;
210 event
.m_clientData
= listbox
->GetClientData( event
.m_commandInt
);
211 wxString
str(listbox
->GetString(event
.m_commandInt
));
212 if (!str
.IsEmpty()) event
.m_commandString
= str
;
216 event
.m_commandInt
= -1 ;
217 event
.m_commandString
.Empty();
220 event
.SetEventObject( listbox
);
222 listbox
->GetEventHandler()->ProcessEvent( event
);
225 //-----------------------------------------------------------------------------
227 //-----------------------------------------------------------------------------
229 IMPLEMENT_DYNAMIC_CLASS(wxListBox
,wxControl
)
231 wxListBox::wxListBox()
233 m_list
= (GtkList
*) NULL
;
234 #if wxUSE_CHECKLISTBOX
235 m_hasCheckBoxes
= FALSE
;
236 #endif // wxUSE_CHECKLISTBOX
239 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
240 const wxPoint
&pos
, const wxSize
&size
,
241 int n
, const wxString choices
[],
242 long style
, const wxValidator
& validator
, const wxString
&name
)
245 m_acceptsFocus
= TRUE
;
247 if (!PreCreation( parent
, pos
, size
) ||
248 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
250 wxFAIL_MSG( _T("wxListBox creation failed") );
254 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
255 if (style
& wxLB_ALWAYS_SB
)
257 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
258 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
262 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
263 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
266 m_list
= GTK_LIST( gtk_list_new() );
268 GtkSelectionMode mode
= GTK_SELECTION_BROWSE
;
269 if (style
& wxLB_MULTIPLE
)
270 mode
= GTK_SELECTION_MULTIPLE
;
271 else if (style
& wxLB_EXTENDED
)
272 mode
= GTK_SELECTION_EXTENDED
;
274 gtk_list_set_selection_mode( GTK_LIST(m_list
), mode
);
276 #ifdef NEW_GTK_SCROLL_CODE
277 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget
), GTK_WIDGET(m_list
) );
279 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_list
) );
282 gtk_widget_show( GTK_WIDGET(m_list
) );
284 wxSize newSize
= size
;
285 if (newSize
.x
== -1) newSize
.x
= 100;
286 if (newSize
.y
== -1) newSize
.y
= 110;
287 SetSize( newSize
.x
, newSize
.y
);
289 for (int i
= 0; i
< n
; i
++)
291 m_clientDataList
.Append( (wxObject
*) NULL
);
292 m_clientObjectList
.Append( (wxObject
*) NULL
);
294 GtkWidget
*list_item
;
296 wxString
str(choices
[i
]);
297 #if wxUSE_CHECKLISTBOX
300 str
.Prepend(CHECKBOX_STRING
);
302 #endif // wxUSE_CHECKLISTBOX
304 list_item
= gtk_list_item_new_with_label( str
.mbc_str() );
306 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
308 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
309 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
311 if (style
& wxLB_MULTIPLE
)
312 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
313 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
315 gtk_signal_connect( GTK_OBJECT(list_item
),
316 "button_press_event",
317 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
320 gtk_signal_connect_after( GTK_OBJECT(list_item
),
321 "button_release_event",
322 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
325 #if wxUSE_CHECKLISTBOX
328 gtk_signal_connect( GTK_OBJECT(list_item
),
330 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
333 #endif // wxUSE_CHECKLISTBOX
335 ConnectWidget( list_item
);
337 gtk_widget_show( list_item
);
340 m_parent
->DoAddChild( this );
344 SetBackgroundColour( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOW
) );
345 SetForegroundColour( parent
->GetForegroundColour() );
346 SetFont( parent
->GetFont() );
353 wxListBox::~wxListBox()
358 void wxListBox::InsertItems(int nItems
, const wxString items
[], int pos
)
360 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
362 GList
*children
= m_list
->children
;
363 int length
= g_list_length(children
);
364 wxCHECK_RET( pos
<= length
, _T("invalid index in wxListBox::InsertItems") );
366 // VZ: it seems that GTK 1.0.6 doesn't has a function to insert an item
367 // into a listbox at the given position, this is why we first delete
368 // all items after this position, then append these items and then
369 // reappend back the old ones.
371 // first detach the old items
376 // no need to do anything complicated
377 for ( n
= 0; n
< nItems
; n
++ )
385 wxArrayString deletedLabels
;
386 wxArrayPtrVoid deletedData
;
387 wxArrayInt deletedChecks
; // only for check list boxes
389 GList
*child
= g_list_nth( children
, pos
);
390 for ( n
= 0; child
!= NULL
; n
++, child
= child
->next
)
393 GtkBin
*bin
= GTK_BIN( child
->data
);
394 GtkLabel
*label
= GTK_LABEL( bin
->child
);
396 wxString
str(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
397 deletedLabels
.Add(str
);
400 void *clientData
= NULL
;
403 if ( n
< (int)m_clientObjectList
.GetCount() )
404 node
= m_clientObjectList
.Nth( n
);
408 clientData
= node
->GetData();
409 m_clientObjectList
.DeleteNode( node
);
414 if ( n
< (int)m_clientDataList
.GetCount() )
415 node
= m_clientDataList
.Nth( n
);
419 clientData
= node
->GetData();
420 node
= m_clientDataList
.Nth( n
);
424 deletedData
.Add(clientData
);
426 #if wxUSE_CHECKLISTBOX
428 if ( m_hasCheckBoxes
)
430 deletedChecks
.Add(((wxCheckListBox
*)this)->IsChecked(pos
+ n
));
432 #endif // wxUSE_CHECKLISTBOX
435 int nDeletedCount
= n
;
437 gtk_list_clear_items( m_list
, pos
, length
);
439 // now append the new items
440 for ( n
= 0; n
< nItems
; n
++ )
445 // and append the old items too
446 pos
+= nItems
; // now the indices are shifter
447 for ( n
= 0; n
< nDeletedCount
; n
++ )
449 Append(deletedLabels
[n
], deletedData
[n
]);
451 #if wxUSE_CHECKLISTBOX
452 if ( m_hasCheckBoxes
)
454 ((wxCheckListBox
*)this)->Check(pos
+ n
, (bool)deletedChecks
[n
]);
456 #endif // wxUSE_CHECKLISTBOX
460 void wxListBox::AppendCommon( const wxString
&item
)
462 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
464 GtkWidget
*list_item
;
466 wxString
label(item
);
467 #if wxUSE_CHECKLISTBOX
470 label
.Prepend(CHECKBOX_STRING
);
472 #endif // wxUSE_CHECKLISTBOX
474 list_item
= gtk_list_item_new_with_label( label
.mbc_str() );
476 gtk_container_add( GTK_CONTAINER(m_list
), list_item
);
478 gtk_signal_connect( GTK_OBJECT(list_item
), "select",
479 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
481 if (HasFlag(wxLB_MULTIPLE
))
482 gtk_signal_connect( GTK_OBJECT(list_item
), "deselect",
483 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
485 gtk_signal_connect( GTK_OBJECT(list_item
),
486 "button_press_event",
487 (GtkSignalFunc
)gtk_listbox_button_press_callback
,
490 gtk_signal_connect_after( GTK_OBJECT(list_item
),
491 "button_release_event",
492 (GtkSignalFunc
)gtk_listbox_button_release_callback
,
495 #if wxUSE_CHECKLISTBOX
498 gtk_signal_connect( GTK_OBJECT(list_item
),
500 (GtkSignalFunc
)gtk_listbox_key_press_callback
,
503 #endif // wxUSE_CHECKLISTBOX
505 gtk_widget_show( list_item
);
507 ConnectWidget( list_item
);
509 if (GTK_WIDGET_REALIZED(m_widget
))
511 gtk_widget_realize( list_item
);
512 gtk_widget_realize( GTK_BIN(list_item
)->child
);
514 if (m_widgetStyle
) ApplyWidgetStyle();
516 #if wxUSE_DRAG_AND_DROP
517 #ifndef NEW_GTK_DND_CODE
518 if (m_dropTarget
) m_dropTarget
->RegisterWidget( list_item
);
523 if (m_tooltip
) m_tooltip
->Apply( this );
528 void wxListBox::Append( const wxString
&item
)
530 m_clientDataList
.Append( (wxObject
*) NULL
);
531 m_clientObjectList
.Append( (wxObject
*) NULL
);
533 AppendCommon( item
);
536 void wxListBox::Append( const wxString
&item
, void *clientData
)
538 m_clientDataList
.Append( (wxObject
*) clientData
);
539 m_clientObjectList
.Append( (wxObject
*) NULL
);
541 AppendCommon( item
);
544 void wxListBox::Append( const wxString
&item
, wxClientData
*clientData
)
546 m_clientObjectList
.Append( (wxObject
*) clientData
);
547 m_clientDataList
.Append( (wxObject
*) NULL
);
549 AppendCommon( item
);
552 void wxListBox::SetClientData( int n
, void* clientData
)
554 wxCHECK_RET( m_widget
!= NULL
, _T("invalid combobox") );
556 wxNode
*node
= m_clientDataList
.Nth( n
);
559 node
->SetData( (wxObject
*) clientData
);
562 void* wxListBox::GetClientData( int n
)
564 wxCHECK_MSG( m_widget
!= NULL
, NULL
, _T("invalid combobox") );
566 wxNode
*node
= m_clientDataList
.Nth( n
);
567 if (!node
) return NULL
;
572 void wxListBox::SetClientObject( int n
, wxClientData
* clientData
)
574 wxCHECK_RET( m_widget
!= NULL
, _T("invalid combobox") );
576 wxNode
*node
= m_clientObjectList
.Nth( n
);
579 wxClientData
*cd
= (wxClientData
*) node
->Data();
582 node
->SetData( (wxObject
*) clientData
);
585 wxClientData
* wxListBox::GetClientObject( int n
)
587 wxCHECK_MSG( m_widget
!= NULL
, (wxClientData
*)NULL
, _T("invalid combobox") );
589 wxNode
*node
= m_clientObjectList
.Nth( n
);
590 if (!node
) return (wxClientData
*) NULL
;
592 return (wxClientData
*) node
->Data();
595 void wxListBox::Clear()
597 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
599 gtk_list_clear_items( m_list
, 0, Number() );
601 wxNode
*node
= m_clientObjectList
.First();
604 wxClientData
*cd
= (wxClientData
*)node
->Data();
608 m_clientObjectList
.Clear();
610 m_clientDataList
.Clear();
613 void wxListBox::Delete( int n
)
615 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
617 GList
*child
= g_list_nth( m_list
->children
, n
);
619 wxCHECK_RET( child
, _T("wrong listbox index") );
621 GList
*list
= g_list_append( (GList
*) NULL
, child
->data
);
622 gtk_list_remove_items( m_list
, list
);
625 wxNode
*node
= m_clientObjectList
.Nth( n
);
628 wxClientData
*cd
= (wxClientData
*)node
->Data();
630 m_clientObjectList
.DeleteNode( node
);
633 node
= m_clientDataList
.Nth( n
);
636 m_clientDataList
.DeleteNode( node
);
640 void wxListBox::Deselect( int n
)
642 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
646 gtk_list_unselect_item( m_list
, n
);
651 int wxListBox::FindString( const wxString
&item
) const
653 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
655 GList
*child
= m_list
->children
;
659 GtkBin
*bin
= GTK_BIN( child
->data
);
660 GtkLabel
*label
= GTK_LABEL( bin
->child
);
662 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
671 // it's not an error if the string is not found -> no wxCHECK
676 int wxListBox::GetSelection() const
678 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
680 GList
*child
= m_list
->children
;
684 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
) return count
;
691 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
693 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
695 // get the number of selected items first
696 GList
*child
= m_list
->children
;
698 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
)
700 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
709 aSelections
.Alloc(count
); // optimization attempt
711 for (child
= m_list
->children
; child
!= NULL
; child
= child
->next
, i
++)
713 if (GTK_WIDGET(child
->data
)->state
== GTK_STATE_SELECTED
)
721 wxString
wxListBox::GetString( int n
) const
723 wxCHECK_MSG( m_list
!= NULL
, _T(""), _T("invalid listbox") );
725 GList
*child
= g_list_nth( m_list
->children
, n
);
728 GtkBin
*bin
= GTK_BIN( child
->data
);
729 GtkLabel
*label
= GTK_LABEL( bin
->child
);
731 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
736 wxFAIL_MSG(_T("wrong listbox index"));
741 wxString
wxListBox::GetStringSelection() const
743 wxCHECK_MSG( m_list
!= NULL
, _T(""), _T("invalid listbox") );
745 GList
*selection
= m_list
->selection
;
748 GtkBin
*bin
= GTK_BIN( selection
->data
);
749 GtkLabel
*label
= GTK_LABEL( bin
->child
);
751 wxString str
= wxString(GET_REAL_LABEL(label
->label
),*wxConvCurrent
);
756 wxFAIL_MSG(_T("no listbox selection available"));
760 int wxListBox::Number()
762 wxCHECK_MSG( m_list
!= NULL
, -1, _T("invalid listbox") );
764 GList
*child
= m_list
->children
;
766 while (child
) { count
++; child
= child
->next
; }
770 bool wxListBox::Selected( int n
)
772 wxCHECK_MSG( m_list
!= NULL
, FALSE
, _T("invalid listbox") );
774 GList
*target
= g_list_nth( m_list
->children
, n
);
777 GList
*child
= m_list
->selection
;
780 if (child
->data
== target
->data
) return TRUE
;
784 wxFAIL_MSG(_T("wrong listbox index"));
788 void wxListBox::Set( int WXUNUSED(n
), const wxString
*WXUNUSED(choices
) )
790 wxFAIL_MSG(_T("wxListBox::Set not implemented"));
793 void wxListBox::SetFirstItem( int WXUNUSED(n
) )
795 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
798 void wxListBox::SetFirstItem( const wxString
&WXUNUSED(item
) )
800 wxFAIL_MSG(_T("wxListBox::SetFirstItem not implemented"));
803 void wxListBox::SetSelection( int n
, bool select
)
805 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
810 gtk_list_select_item( m_list
, n
);
812 gtk_list_unselect_item( m_list
, n
);
817 void wxListBox::SetString( int n
, const wxString
&string
)
819 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
821 GList
*child
= g_list_nth( m_list
->children
, n
);
824 GtkBin
*bin
= GTK_BIN( child
->data
);
825 GtkLabel
*label
= GTK_LABEL( bin
->child
);
828 #if wxUSE_CHECKLISTBOX
830 str
+= CHECKBOX_STRING
;
831 #endif // wxUSE_CHECKLISTBOX
834 gtk_label_set( label
, str
.mbc_str() );
838 wxFAIL_MSG(_T("wrong listbox index"));
842 void wxListBox::SetStringSelection( const wxString
&string
, bool select
)
844 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
846 SetSelection( FindString(string
), select
);
849 int wxListBox::GetIndex( GtkWidget
*item
) const
853 GList
*child
= m_list
->children
;
857 if (GTK_WIDGET(child
->data
) == item
) return count
;
866 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const wxChar
*tip
)
868 GList
*child
= m_list
->children
;
871 gtk_tooltips_set_tip( tips
, GTK_WIDGET( child
->data
), wxConvCurrent
->cWX2MB(tip
), (gchar
*) NULL
);
875 #endif // wxUSE_TOOLTIPS
877 #if wxUSE_DRAG_AND_DROP
878 void wxListBox::SetDropTarget( wxDropTarget
*dropTarget
)
880 wxCHECK_RET( m_list
!= NULL
, _T("invalid listbox") );
882 #ifndef NEW_GTK_DND_CODE
885 GList
*child
= m_list
->children
;
888 m_dropTarget
->UnregisterWidget( GTK_WIDGET( child
->data
) );
894 wxWindow::SetDropTarget( dropTarget
);
896 #ifndef NEW_GTK_DND_CODE
899 GList
*child
= m_list
->children
;
902 m_dropTarget
->RegisterWidget( GTK_WIDGET( child
->data
) );
910 void wxListBox::DisableEvents()
912 GList
*child
= m_list
->children
;
915 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
916 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
918 if (HasFlag(wxLB_MULTIPLE
))
919 gtk_signal_disconnect_by_func( GTK_OBJECT(child
->data
),
920 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
926 void wxListBox::EnableEvents()
928 GList
*child
= m_list
->children
;
931 gtk_signal_connect( GTK_OBJECT(child
->data
), "select",
932 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
934 if (HasFlag(wxLB_MULTIPLE
))
935 gtk_signal_connect( GTK_OBJECT(child
->data
), "deselect",
936 GTK_SIGNAL_FUNC(gtk_listitem_select_callback
), (gpointer
)this );
942 GtkWidget
*wxListBox::GetConnectWidget()
944 return GTK_WIDGET(m_list
);
947 bool wxListBox::IsOwnGtkWindow( GdkWindow
*window
)
949 if (wxWindow::IsOwnGtkWindow( window
)) return TRUE
;
951 GList
*child
= m_list
->children
;
954 GtkWidget
*bin
= GTK_WIDGET( child
->data
);
955 if (bin
->window
== window
) return TRUE
;
962 void wxListBox::ApplyWidgetStyle()
966 if (m_backgroundColour
.Ok())
968 GdkWindow
*window
= GTK_WIDGET(m_list
)->window
;
971 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
972 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
973 gdk_window_clear( window
);
977 GList
*child
= m_list
->children
;
980 gtk_widget_set_style( GTK_WIDGET(child
->data
), m_widgetStyle
);
982 GtkBin
*bin
= GTK_BIN( child
->data
);
983 GtkWidget
*label
= GTK_WIDGET( bin
->child
);
984 gtk_widget_set_style( label
, m_widgetStyle
);