1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/listbox.cpp
4 // Author: Robert Roebling
5 // Modified By: Ryan Norton (GtkTreeView implementation)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/listbox.h"
19 #include "wx/dynarray.h"
23 #include "wx/settings.h"
24 #include "wx/checklst.h"
25 #include "wx/arrstr.h"
28 #include "wx/gtk/private.h"
29 #include "wx/gtk/treeentry_gtk.h"
32 #include "wx/tooltip.h"
36 #include <gdk/gdkkeysyms.h>
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern bool g_blockEventsOnDrag
;
43 extern bool g_blockEventsOnScroll
;
47 //-----------------------------------------------------------------------------
48 // Macro to tell which row the strings are in (1 if native checklist, 0 if not)
49 //-----------------------------------------------------------------------------
51 #if wxUSE_CHECKLISTBOX
52 # define WXLISTBOX_DATACOLUMN_ARG(x) (x->m_hasCheckBoxes ? 1 : 0)
54 # define WXLISTBOX_DATACOLUMN_ARG(x) (0)
55 #endif // wxUSE_CHECKLISTBOX
57 #define WXLISTBOX_DATACOLUMN WXLISTBOX_DATACOLUMN_ARG(this)
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
65 gtk_listbox_row_activated_callback(GtkTreeView
*treeview
,
67 GtkTreeViewColumn
*col
,
70 if (g_blockEventsOnDrag
) return;
71 if (g_blockEventsOnScroll
) return;
73 // This is triggered by either a double-click or a space press
75 int sel
= gtk_tree_path_get_indices(path
)[0];
77 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, listbox
->GetId() );
78 event
.SetEventObject( listbox
);
80 if (listbox
->IsSelected(sel
))
82 GtkTreeEntry
* entry
= listbox
->GtkGetEntry(sel
);
87 event
.SetString(wxConvUTF8
.cMB2WX(gtk_tree_entry_get_label(entry
)));
89 if ( listbox
->HasClientObjectData() )
90 event
.SetClientObject( (wxClientData
*) gtk_tree_entry_get_userdata(entry
) );
91 else if ( listbox
->HasClientUntypedData() )
92 event
.SetClientData( gtk_tree_entry_get_userdata(entry
) );
94 g_object_unref (entry
);
98 wxLogSysError(wxT("Internal error - could not get entry for double-click"));
107 listbox
->GetEventHandler()->ProcessEvent( event
);
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
117 gtk_listitem_changed_callback( GtkTreeSelection
* selection
, wxListBox
*listbox
)
119 if (g_blockEventsOnDrag
) return;
121 if (listbox
->m_blockEvent
) return;
123 wxCommandEvent
event(wxEVT_COMMAND_LISTBOX_SELECTED
, listbox
->GetId() );
124 event
.SetEventObject( listbox
);
126 if (listbox
->HasFlag(wxLB_MULTIPLE
) || listbox
->HasFlag(wxLB_EXTENDED
))
128 wxArrayInt selections
;
129 listbox
->GetSelections( selections
);
131 if (selections
.GetCount() == 0)
133 // indicate that this is a deselection
134 event
.SetExtraLong( 0 );
137 listbox
->GetEventHandler()->ProcessEvent( event
);
143 // indicate that this is a selection
144 event
.SetExtraLong( 1 );
145 event
.SetInt( selections
[0] );
147 listbox
->GetEventHandler()->ProcessEvent( event
);
152 int index
= listbox
->GetSelection();
153 if (index
== wxNOT_FOUND
)
155 // indicate that this is a deselection
156 event
.SetExtraLong( 0 );
159 listbox
->GetEventHandler()->ProcessEvent( event
);
165 GtkTreeEntry
* entry
= listbox
->GtkGetEntry( index
);
167 // indicate that this is a selection
168 event
.SetExtraLong( 1 );
170 event
.SetInt( index
);
171 event
.SetString(wxConvUTF8
.cMB2WX(gtk_tree_entry_get_label(entry
)));
173 if ( listbox
->HasClientObjectData() )
174 event
.SetClientObject(
175 (wxClientData
*) gtk_tree_entry_get_userdata(entry
)
177 else if ( listbox
->HasClientUntypedData() )
178 event
.SetClientData( gtk_tree_entry_get_userdata(entry
) );
180 listbox
->GetEventHandler()->ProcessEvent( event
);
182 g_object_unref (entry
);
188 //-----------------------------------------------------------------------------
189 // GtkTreeEntry destruction (to destroy client data)
190 //-----------------------------------------------------------------------------
193 static void gtk_tree_entry_destroy_cb(GtkTreeEntry
* entry
,
196 if (listbox
->HasClientObjectData())
198 gpointer userdata
= gtk_tree_entry_get_userdata(entry
);
200 delete (wxClientData
*)userdata
;
205 //-----------------------------------------------------------------------------
206 // Sorting callback (standard CmpNoCase return value)
207 //-----------------------------------------------------------------------------
211 static gint
gtk_listbox_sort_callback(GtkTreeModel
*model
,
217 GtkTreeEntry
* entry2
;
219 gtk_tree_model_get(GTK_TREE_MODEL(listbox
->m_liststore
),
221 WXLISTBOX_DATACOLUMN_ARG(listbox
),
223 gtk_tree_model_get(GTK_TREE_MODEL(listbox
->m_liststore
),
225 WXLISTBOX_DATACOLUMN_ARG(listbox
),
227 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
228 wxCHECK_MSG(entry2
, 0, wxT("Could not get entry2"));
230 //We compare collate keys here instead of calling g_utf8_collate
231 //as it is rather slow (and even the docs reccommend this)
232 int ret
= strcmp(gtk_tree_entry_get_collate_key(entry
),
233 gtk_tree_entry_get_collate_key(entry2
));
235 g_object_unref (entry
);
236 g_object_unref (entry2
);
242 //-----------------------------------------------------------------------------
243 // Searching callback (TRUE == not equal, FALSE == equal)
244 //-----------------------------------------------------------------------------
247 static gboolean
gtk_listbox_searchequal_callback(GtkTreeModel
* model
,
255 gtk_tree_model_get(GTK_TREE_MODEL(listbox
->m_liststore
),
257 WXLISTBOX_DATACOLUMN_ARG(listbox
),
259 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
260 wxGtkString
keycollatekey(g_utf8_collate_key(key
, -1));
262 int ret
= strcmp(keycollatekey
,
263 gtk_tree_entry_get_collate_key(entry
));
265 g_object_unref (entry
);
271 //-----------------------------------------------------------------------------
273 //-----------------------------------------------------------------------------
275 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControl
)
277 // ----------------------------------------------------------------------------
279 // ----------------------------------------------------------------------------
281 void wxListBox::Init()
283 m_treeview
= (GtkTreeView
*) NULL
;
284 #if wxUSE_CHECKLISTBOX
285 m_hasCheckBoxes
= false;
286 #endif // wxUSE_CHECKLISTBOX
289 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
290 const wxPoint
&pos
, const wxSize
&size
,
291 const wxArrayString
& choices
,
292 long style
, const wxValidator
& validator
,
293 const wxString
&name
)
295 wxCArrayString
chs(choices
);
297 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
298 style
, validator
, name
);
301 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
302 const wxPoint
&pos
, const wxSize
&size
,
303 int n
, const wxString choices
[],
304 long style
, const wxValidator
& validator
,
305 const wxString
&name
)
307 m_blockEvent
= false;
309 if (!PreCreation( parent
, pos
, size
) ||
310 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
312 wxFAIL_MSG( wxT("wxListBox creation failed") );
316 m_widget
= gtk_scrolled_window_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
317 if (style
& wxLB_ALWAYS_SB
)
319 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
320 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
324 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
325 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
329 GtkScrolledWindowSetBorder(m_widget
, style
);
331 m_treeview
= GTK_TREE_VIEW( gtk_tree_view_new( ) );
333 //wxListBox doesn't have a header :)
334 //NB: If enabled SetFirstItem doesn't work correctly
335 gtk_tree_view_set_headers_visible(m_treeview
, FALSE
);
337 #if wxUSE_CHECKLISTBOX
339 ((wxCheckListBox
*)this)->DoCreateCheckList();
340 #endif // wxUSE_CHECKLISTBOX
342 // Create the data column
343 gtk_tree_view_insert_column_with_attributes(m_treeview
, -1, "",
344 gtk_cell_renderer_text_new(),
346 WXLISTBOX_DATACOLUMN
, NULL
);
348 // Now create+set the model (GtkListStore) - first argument # of columns
349 #if wxUSE_CHECKLISTBOX
351 m_liststore
= gtk_list_store_new(2, G_TYPE_BOOLEAN
,
352 GTK_TYPE_TREE_ENTRY
);
355 m_liststore
= gtk_list_store_new(1, GTK_TYPE_TREE_ENTRY
);
357 gtk_tree_view_set_model(m_treeview
, GTK_TREE_MODEL(m_liststore
));
359 g_object_unref (m_liststore
); //free on treeview destruction
361 // Disable the pop-up textctrl that enables searching - note that
362 // the docs specify that even if this disabled (which we are doing)
363 // the user can still have it through the start-interactive-search
364 // key binding...either way we want to provide a searchequal callback
365 // NB: If this is enabled a doubleclick event (activate) gets sent
366 // on a successful search
367 gtk_tree_view_set_search_column(m_treeview
, WXLISTBOX_DATACOLUMN
);
368 gtk_tree_view_set_search_equal_func(m_treeview
,
369 (GtkTreeViewSearchEqualFunc
) gtk_listbox_searchequal_callback
,
373 gtk_tree_view_set_enable_search(m_treeview
, FALSE
);
376 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
378 g_signal_connect_after (selection
, "changed",
379 G_CALLBACK (gtk_listitem_changed_callback
), this);
381 GtkSelectionMode mode
;
382 if (style
& wxLB_MULTIPLE
)
384 mode
= GTK_SELECTION_MULTIPLE
;
386 else if (style
& wxLB_EXTENDED
)
388 mode
= GTK_SELECTION_EXTENDED
;
392 // if style was 0 set single mode
393 m_windowStyle
|= wxLB_SINGLE
;
394 mode
= GTK_SELECTION_SINGLE
;
397 gtk_tree_selection_set_mode( selection
, mode
);
399 // Handle sortable stuff
400 if(HasFlag(wxLB_SORT
))
402 // Setup sorting in ascending (wx) order
403 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m_liststore
),
404 WXLISTBOX_DATACOLUMN
,
407 // Set the sort callback
408 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(m_liststore
),
409 WXLISTBOX_DATACOLUMN
,
410 (GtkTreeIterCompareFunc
) gtk_listbox_sort_callback
,
412 NULL
//"destroy notifier"
417 gtk_container_add (GTK_CONTAINER (m_widget
), GTK_WIDGET(m_treeview
) );
419 gtk_widget_show( GTK_WIDGET(m_treeview
) );
420 m_focusWidget
= GTK_WIDGET(m_treeview
);
422 Append(n
, choices
); // insert initial items
424 // generate dclick events
425 g_signal_connect_after(m_treeview
, "row-activated",
426 G_CALLBACK(gtk_listbox_row_activated_callback
), this);
428 m_parent
->DoAddChild( this );
431 SetInitialSize(size
); // need this too because this is a wxControlWithItems
436 wxListBox::~wxListBox()
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
447 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
450 wxClientDataType type
)
452 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
454 InvalidateBestSize();
456 GtkTreeIter
* pIter
= NULL
; // append by default
458 if ( pos
!= GetCount() )
460 wxCHECK_MSG( GtkGetIteratorFor(pos
, &iter
), wxNOT_FOUND
,
461 wxT("internal wxListBox error in insertion") );
466 const unsigned int numItems
= items
.GetCount();
467 for ( unsigned int i
= 0; i
< numItems
; ++i
)
469 GtkTreeEntry
* entry
= gtk_tree_entry_new();
470 gtk_tree_entry_set_label(entry
, wxGTK_CONV(items
[i
]));
471 gtk_tree_entry_set_destroy_func(entry
,
472 (GtkTreeEntryDestroy
)gtk_tree_entry_destroy_cb
,
476 gtk_tree_entry_set_userdata(entry
, clientData
[i
]);
479 gtk_list_store_insert_before(m_liststore
, &itercur
, pIter
);
481 GtkSetItem(itercur
, entry
);
483 g_object_unref (entry
);
486 if ( !HasClientData() )
487 m_clientDataItemsType
= type
;
489 return pos
+ numItems
- 1;
492 // ----------------------------------------------------------------------------
494 // ----------------------------------------------------------------------------
496 void wxListBox::DoClear()
498 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
500 InvalidateBestSize();
502 gtk_list_store_clear( m_liststore
); /* well, THAT was easy :) */
505 void wxListBox::DoDeleteOneItem(unsigned int n
)
507 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
509 InvalidateBestSize();
512 wxCHECK_RET( GtkGetIteratorFor(n
, &iter
), wxT("wrong listbox index") );
514 // this returns false if iter is invalid (e.g. deleting item at end) but
515 // since we don't use iter, we ignore the return value
516 gtk_list_store_remove(m_liststore
, &iter
);
519 // ----------------------------------------------------------------------------
520 // helper functions for working with iterators
521 // ----------------------------------------------------------------------------
523 bool wxListBox::GtkGetIteratorFor(unsigned pos
, GtkTreeIter
*iter
) const
525 if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore
),
528 wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos
);
535 int wxListBox::GtkGetIndexFor(GtkTreeIter
& iter
) const
538 gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore
), &iter
);
540 gint
* pIntPath
= gtk_tree_path_get_indices(path
);
542 wxCHECK_MSG( pIntPath
, wxNOT_FOUND
, _T("failed to get iterator path") );
544 int idx
= pIntPath
[0];
546 gtk_tree_path_free( path
);
551 // get GtkTreeEntry from position (note: you need to g_unref it if valid)
552 GtkTreeEntry
*wxListBox::GtkGetEntry(unsigned n
) const
555 if ( !GtkGetIteratorFor(n
, &iter
) )
559 GtkTreeEntry
* entry
= NULL
;
560 gtk_tree_model_get(GTK_TREE_MODEL(m_liststore
), &iter
,
561 WXLISTBOX_DATACOLUMN
, &entry
, -1);
566 void wxListBox::GtkSetItem(GtkTreeIter
& iter
, const GtkTreeEntry
*entry
)
568 #if wxUSE_CHECKLISTBOX
569 if ( m_hasCheckBoxes
)
571 gtk_list_store_set(m_liststore
, &iter
,
572 0, FALSE
, // FALSE == not toggled
577 #endif // wxUSE_CHECKLISTBOX
579 gtk_list_store_set(m_liststore
, &iter
, 0, entry
, -1);
583 // ----------------------------------------------------------------------------
585 // ----------------------------------------------------------------------------
587 void* wxListBox::DoGetItemClientData(unsigned int n
) const
589 wxCHECK_MSG( IsValid(n
), NULL
,
590 wxT("Invalid index passed to GetItemClientData") );
592 GtkTreeEntry
* entry
= GtkGetEntry(n
);
593 wxCHECK_MSG(entry
, NULL
, wxT("could not get entry"));
595 void* userdata
= gtk_tree_entry_get_userdata( entry
);
596 g_object_unref (entry
);
600 void wxListBox::DoSetItemClientData(unsigned int n
, void* clientData
)
602 wxCHECK_RET( IsValid(n
),
603 wxT("Invalid index passed to SetItemClientData") );
605 GtkTreeEntry
* entry
= GtkGetEntry(n
);
606 wxCHECK_RET(entry
, wxT("could not get entry"));
608 gtk_tree_entry_set_userdata( entry
, clientData
);
609 g_object_unref (entry
);
612 // ----------------------------------------------------------------------------
613 // string list access
614 // ----------------------------------------------------------------------------
616 void wxListBox::SetString(unsigned int n
, const wxString
& label
)
618 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetString") );
619 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
621 GtkTreeEntry
* entry
= GtkGetEntry(n
);
622 wxCHECK_RET( entry
, wxT("wrong listbox index") );
624 // update the item itself
625 gtk_tree_entry_set_label(entry
, wxGTK_CONV(label
));
627 // and update the model which will refresh the tree too
629 wxCHECK_RET( GtkGetIteratorFor(n
, &iter
), _T("failed to get iterator") );
631 // FIXME: this resets the checked status of a wxCheckListBox item
633 GtkSetItem(iter
, entry
);
636 wxString
wxListBox::GetString(unsigned int n
) const
638 wxCHECK_MSG( m_treeview
!= NULL
, wxEmptyString
, wxT("invalid listbox") );
640 GtkTreeEntry
* entry
= GtkGetEntry(n
);
641 wxCHECK_MSG( entry
, wxEmptyString
, wxT("wrong listbox index") );
643 wxString label
= wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry
) );
645 g_object_unref (entry
);
649 unsigned int wxListBox::GetCount() const
651 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox") );
653 return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore
), NULL
);
656 int wxListBox::FindString( const wxString
&item
, bool bCase
) const
658 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
660 //Sort of hackish - maybe there is a faster way
661 unsigned int nCount
= wxListBox::GetCount();
663 for(unsigned int i
= 0; i
< nCount
; ++i
)
665 if( item
.IsSameAs( wxListBox::GetString(i
), bCase
) )
670 // it's not an error if the string is not found -> no wxCHECK
674 // ----------------------------------------------------------------------------
676 // ----------------------------------------------------------------------------
678 int wxListBox::GetSelection() const
680 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox"));
681 wxCHECK_MSG( HasFlag(wxLB_SINGLE
), wxNOT_FOUND
,
682 wxT("must be single selection listbox"));
685 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
687 // only works on single-sel
688 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
691 return GtkGetIndexFor(iter
);
694 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
696 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
702 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
704 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore
), &iter
))
705 { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead
708 if (gtk_tree_selection_iter_is_selected(selection
, &iter
))
712 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore
), &iter
));
715 return aSelections
.GetCount();
718 bool wxListBox::IsSelected( int n
) const
720 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid listbox") );
722 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
725 wxCHECK_MSG( GtkGetIteratorFor(n
, &iter
), false, wxT("Invalid index") );
727 return gtk_tree_selection_iter_is_selected(selection
, &iter
);
730 void wxListBox::DoSetSelection( int n
, bool select
)
732 // passing -1 to SetSelection() is documented to deselect all items
733 if ( n
== wxNOT_FOUND
)
735 // ... and not generate any events in the process
740 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetSelection") );
742 // don't generate the selection event
743 GtkSetSelection(n
, select
, true);
746 void wxListBox::GtkDeselectAll()
748 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
750 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
754 gtk_tree_selection_unselect_all(selection
);
756 m_blockEvent
= false;
759 void wxListBox::GtkSetSelection(int n
, const bool select
, const bool blockEvent
)
761 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
763 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
766 wxCHECK_RET( GtkGetIteratorFor(n
, &iter
), wxT("Invalid index") );
768 m_blockEvent
= blockEvent
;
771 gtk_tree_selection_select_iter(selection
, &iter
);
773 gtk_tree_selection_unselect_iter(selection
, &iter
);
775 m_blockEvent
= false;
778 void wxListBox::DoSetFirstItem( int n
)
780 wxCHECK_RET( m_treeview
, wxT("invalid listbox") );
781 wxCHECK_RET( IsValid(n
), wxT("invalid index"));
783 //RN: I have no idea why this line is needed...
784 if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_treeview
))
788 if ( !GtkGetIteratorFor(n
, &iter
) )
791 GtkTreePath
* path
= gtk_tree_model_get_path(
792 GTK_TREE_MODEL(m_liststore
), &iter
);
794 // Scroll to the desired cell (0.0 == topleft alignment)
795 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
,
798 gtk_tree_path_free(path
);
801 // ----------------------------------------------------------------------------
803 // ----------------------------------------------------------------------------
805 int wxListBox::DoListHitTest(const wxPoint
& point
) const
807 // gtk_tree_view_get_path_at_pos() also gets items that are not visible and
808 // we only want visible items we need to check for it manually here
809 if ( !GetClientRect().Contains(point
) )
812 // need to translate from master window since it is in client coords
814 gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview
),
815 &binx
, &biny
, NULL
, NULL
, NULL
);
818 if ( !gtk_tree_view_get_path_at_pos
824 NULL
, // [out] column (always 0 here)
825 NULL
, // [out] x-coord relative to the cell (not interested)
826 NULL
// [out] y-coord relative to the cell
832 int index
= gtk_tree_path_get_indices(path
)[0];
833 gtk_tree_path_free(path
);
838 // ----------------------------------------------------------------------------
840 // ----------------------------------------------------------------------------
843 void wxListBox::ApplyToolTip( GtkTooltips
*tips
, const gchar
*tip
)
845 // RN: Is this needed anymore?
846 gtk_tooltips_set_tip( tips
, GTK_WIDGET( m_treeview
), tip
, (gchar
*) NULL
);
848 #endif // wxUSE_TOOLTIPS
850 GtkWidget
*wxListBox::GetConnectWidget()
852 // the correct widget for listbox events (such as mouse clicks for example)
853 // is m_treeview, not the parent scrolled window
854 return GTK_WIDGET(m_treeview
);
857 GdkWindow
*wxListBox::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
859 return gtk_tree_view_get_bin_window(m_treeview
);
862 void wxListBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
864 if (m_hasBgCol
&& m_backgroundColour
.Ok())
866 GdkWindow
*window
= gtk_tree_view_get_bin_window(m_treeview
);
869 m_backgroundColour
.CalcPixel( gdk_drawable_get_colormap( window
) );
870 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
871 gdk_window_clear( window
);
875 gtk_widget_modify_style( GTK_WIDGET(m_treeview
), style
);
878 wxSize
wxListBox::DoGetBestSize() const
880 wxCHECK_MSG(m_treeview
, wxDefaultSize
, wxT("invalid tree view"));
882 // Start with a minimum size that's not too small
884 GetTextExtent( wxT("X"), &cx
, &cy
);
885 int lbWidth
= 3 * cx
;
888 // Get the visible area of the tree view (limit to the 10th item
889 // so that it isn't too big)
890 unsigned int count
= GetCount();
895 // Find the widest line
896 for(unsigned int i
= 0; i
< count
; i
++) {
897 wxString
str(GetString(i
));
898 GetTextExtent(str
, &wLine
, NULL
);
899 lbWidth
= wxMax(lbWidth
, wLine
);
904 // And just a bit more for the checkbox if present and then some
905 // (these are rough guesses)
906 #if wxUSE_CHECKLISTBOX
907 if ( m_hasCheckBoxes
)
910 cy
= cy
> 25 ? cy
: 25; // rough height of checkbox
914 // don't make the listbox too tall (limit height to around 10 items) but don't
915 // make it too small neither
916 lbHeight
= (cy
+4) * wxMin(wxMax(count
, 3), 10);
919 // Add room for the scrollbar
920 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
922 wxSize
best(lbWidth
, lbHeight
);
929 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
931 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
, true);
934 #endif // wxUSE_LISTBOX