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/private/object.h"
30 #include "wx/gtk/treeentry_gtk.h"
33 #include "wx/tooltip.h"
38 #include <gdk/gdkkeysyms.h>
39 #if GTK_CHECK_VERSION(3,0,0)
40 #include <gdk/gdkkeysyms-compat.h>
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
47 extern bool g_blockEventsOnDrag
;
48 extern bool g_blockEventsOnScroll
;
52 //-----------------------------------------------------------------------------
53 // Macro to tell which row the strings are in (1 if native checklist, 0 if not)
54 //-----------------------------------------------------------------------------
56 #if wxUSE_CHECKLISTBOX
57 # define WXLISTBOX_DATACOLUMN_ARG(x) (x->m_hasCheckBoxes ? 1 : 0)
59 # define WXLISTBOX_DATACOLUMN_ARG(x) (0)
60 #endif // wxUSE_CHECKLISTBOX
62 #define WXLISTBOX_DATACOLUMN WXLISTBOX_DATACOLUMN_ARG(this)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
71 // Return the entry for the given listbox item.
73 // Return value must be released by caller if non-NULL.
75 GetEntry(GtkListStore
*store
, GtkTreeIter
*iter
, const wxListBox
*listbox
)
78 gtk_tree_model_get(GTK_TREE_MODEL(store
),
80 WXLISTBOX_DATACOLUMN_ARG(listbox
),
87 } // anonymous namespace
89 //-----------------------------------------------------------------------------
91 //-----------------------------------------------------------------------------
95 gtk_listbox_row_activated_callback(GtkTreeView
* WXUNUSED(treeview
),
97 GtkTreeViewColumn
* WXUNUSED(col
),
100 if (g_blockEventsOnDrag
) return;
101 if (g_blockEventsOnScroll
) return;
103 // This is triggered by either a double-click or a space press
105 int sel
= gtk_tree_path_get_indices(path
)[0];
107 listbox
->GTKOnActivated(sel
);
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
117 gtk_listitem_changed_callback(GtkTreeSelection
* WXUNUSED(selection
),
120 if (g_blockEventsOnDrag
) return;
122 listbox
->GTKOnSelectionChanged();
127 //-----------------------------------------------------------------------------
129 //-----------------------------------------------------------------------------
133 gtk_listbox_key_press_callback( GtkWidget
*WXUNUSED(widget
),
134 GdkEventKey
*gdk_event
,
137 if ((gdk_event
->keyval
== GDK_Return
) ||
138 (gdk_event
->keyval
== GDK_ISO_Enter
) ||
139 (gdk_event
->keyval
== GDK_KP_Enter
))
142 if (!listbox
->HasMultipleSelection())
143 index
= listbox
->GetSelection();
147 if (listbox
->GetSelections( sels
) < 1)
152 if (index
!= wxNOT_FOUND
)
154 listbox
->GTKOnActivated(index
);
156 // wxMac and wxMSW always invoke default action
159 // DClick not handled -> invoke default action
160 wxWindow
*tlw
= wxGetTopLevelParent( listbox
);
163 GtkWindow
*gtk_window
= GTK_WINDOW( tlw
->GetHandle() );
165 gtk_window_activate_default( gtk_window
);
169 // Always intercept, otherwise we'd get another dclick
170 // event from row_activated
179 //-----------------------------------------------------------------------------
180 // GtkTreeEntry destruction (to destroy client data)
181 //-----------------------------------------------------------------------------
184 static void gtk_tree_entry_destroy_cb(GtkTreeEntry
* entry
,
187 if (listbox
->HasClientObjectData())
189 gpointer userdata
= gtk_tree_entry_get_userdata(entry
);
191 delete (wxClientData
*)userdata
;
196 //-----------------------------------------------------------------------------
197 // Sorting callback (standard CmpNoCase return value)
198 //-----------------------------------------------------------------------------
201 static gint
gtk_listbox_sort_callback(GtkTreeModel
* WXUNUSED(model
),
206 wxGtkObject
<GtkTreeEntry
> entry1(GetEntry(listbox
->m_liststore
, a
, listbox
));
207 wxCHECK_MSG(entry1
, 0, wxT("Could not get first entry"));
209 wxGtkObject
<GtkTreeEntry
> entry2(GetEntry(listbox
->m_liststore
, b
, listbox
));
210 wxCHECK_MSG(entry2
, 0, wxT("Could not get second entry"));
212 //We compare collate keys here instead of calling g_utf8_collate
213 //as it is rather slow (and even the docs recommend this)
214 return strcmp(gtk_tree_entry_get_collate_key(entry1
),
215 gtk_tree_entry_get_collate_key(entry2
)) >= 0;
219 //-----------------------------------------------------------------------------
220 // Searching callback (TRUE == not equal, FALSE == equal)
221 //-----------------------------------------------------------------------------
224 static gboolean
gtk_listbox_searchequal_callback(GtkTreeModel
* WXUNUSED(model
),
225 gint
WXUNUSED(column
),
230 wxGtkObject
<GtkTreeEntry
>
231 entry(GetEntry(listbox
->m_liststore
, iter
, listbox
));
232 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
234 wxGtkString
keycollatekey(g_utf8_collate_key(key
, -1));
236 return strcmp(keycollatekey
, gtk_tree_entry_get_collate_key(entry
)) != 0;
240 //-----------------------------------------------------------------------------
242 //-----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 void wxListBox::Init()
251 #if wxUSE_CHECKLISTBOX
252 m_hasCheckBoxes
= false;
253 #endif // wxUSE_CHECKLISTBOX
256 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
257 const wxPoint
&pos
, const wxSize
&size
,
258 const wxArrayString
& choices
,
259 long style
, const wxValidator
& validator
,
260 const wxString
&name
)
262 wxCArrayString
chs(choices
);
264 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
265 style
, validator
, name
);
268 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
269 const wxPoint
&pos
, const wxSize
&size
,
270 int n
, const wxString choices
[],
271 long style
, const wxValidator
& validator
,
272 const wxString
&name
)
274 if (!PreCreation( parent
, pos
, size
) ||
275 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
277 wxFAIL_MSG( wxT("wxListBox creation failed") );
281 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
282 g_object_ref(m_widget
);
283 if (style
& wxLB_ALWAYS_SB
)
285 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
286 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
290 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
291 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
295 GTKScrolledWindowSetBorder(m_widget
, style
);
297 m_treeview
= GTK_TREE_VIEW( gtk_tree_view_new( ) );
299 //wxListBox doesn't have a header :)
300 //NB: If enabled SetFirstItem doesn't work correctly
301 gtk_tree_view_set_headers_visible(m_treeview
, FALSE
);
303 #if wxUSE_CHECKLISTBOX
305 ((wxCheckListBox
*)this)->DoCreateCheckList();
306 #endif // wxUSE_CHECKLISTBOX
308 // Create the data column
309 gtk_tree_view_insert_column_with_attributes(m_treeview
, -1, "",
310 gtk_cell_renderer_text_new(),
312 WXLISTBOX_DATACOLUMN
, NULL
);
314 // Now create+set the model (GtkListStore) - first argument # of columns
315 #if wxUSE_CHECKLISTBOX
317 m_liststore
= gtk_list_store_new(2, G_TYPE_BOOLEAN
,
318 GTK_TYPE_TREE_ENTRY
);
321 m_liststore
= gtk_list_store_new(1, GTK_TYPE_TREE_ENTRY
);
323 gtk_tree_view_set_model(m_treeview
, GTK_TREE_MODEL(m_liststore
));
325 g_object_unref (m_liststore
); //free on treeview destruction
327 // Disable the pop-up textctrl that enables searching - note that
328 // the docs specify that even if this disabled (which we are doing)
329 // the user can still have it through the start-interactive-search
330 // key binding...either way we want to provide a searchequal callback
331 // NB: If this is enabled a doubleclick event (activate) gets sent
332 // on a successful search
333 gtk_tree_view_set_search_column(m_treeview
, WXLISTBOX_DATACOLUMN
);
334 gtk_tree_view_set_search_equal_func(m_treeview
,
335 (GtkTreeViewSearchEqualFunc
) gtk_listbox_searchequal_callback
,
339 gtk_tree_view_set_enable_search(m_treeview
, FALSE
);
341 GtkSelectionMode mode
;
342 // GTK_SELECTION_EXTENDED is a deprecated synonym for GTK_SELECTION_MULTIPLE
343 if ( style
& (wxLB_MULTIPLE
| wxLB_EXTENDED
) )
345 mode
= GTK_SELECTION_MULTIPLE
;
347 else // no multi-selection flags specified
349 m_windowStyle
|= wxLB_SINGLE
;
351 // Notice that we must use BROWSE and not GTK_SELECTION_SINGLE because
352 // the latter allows to not select any items at all while a single
353 // selection listbox is supposed to always have a selection (at least
354 // once the user selected something, it might not have any initially).
355 mode
= GTK_SELECTION_BROWSE
;
358 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
359 gtk_tree_selection_set_mode( selection
, mode
);
361 // Handle sortable stuff
362 if(HasFlag(wxLB_SORT
))
364 // Setup sorting in ascending (wx) order
365 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m_liststore
),
366 WXLISTBOX_DATACOLUMN
,
369 // Set the sort callback
370 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(m_liststore
),
371 WXLISTBOX_DATACOLUMN
,
372 (GtkTreeIterCompareFunc
) gtk_listbox_sort_callback
,
374 NULL
//"destroy notifier"
379 gtk_container_add (GTK_CONTAINER (m_widget
), GTK_WIDGET(m_treeview
) );
381 gtk_widget_show( GTK_WIDGET(m_treeview
) );
382 m_focusWidget
= GTK_WIDGET(m_treeview
);
384 Append(n
, choices
); // insert initial items
386 // generate dclick events
387 g_signal_connect_after(m_treeview
, "row-activated",
388 G_CALLBACK(gtk_listbox_row_activated_callback
), this);
390 // for intercepting dclick generation by <ENTER>
391 g_signal_connect (m_treeview
, "key_press_event",
392 G_CALLBACK (gtk_listbox_key_press_callback
),
394 m_parent
->DoAddChild( this );
397 SetInitialSize(size
); // need this too because this is a wxControlWithItems
399 g_signal_connect_after (selection
, "changed",
400 G_CALLBACK (gtk_listitem_changed_callback
), this);
405 wxListBox::~wxListBox()
412 void wxListBox::GTKDisableEvents()
414 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
416 g_signal_handlers_block_by_func(selection
,
417 (gpointer
) gtk_listitem_changed_callback
, this);
420 void wxListBox::GTKEnableEvents()
422 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
424 g_signal_handlers_unblock_by_func(selection
,
425 (gpointer
) gtk_listitem_changed_callback
, this);
427 UpdateOldSelections();
431 void wxListBox::Update()
436 gdk_window_process_updates(gtk_widget_get_window(GTK_WIDGET(m_treeview
)), true);
439 // ----------------------------------------------------------------------------
441 // ----------------------------------------------------------------------------
443 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
446 wxClientDataType type
)
448 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
450 InvalidateBestSize();
452 GtkTreeIter
* pIter
= NULL
; // append by default
454 if ( pos
!= GetCount() )
456 wxCHECK_MSG( GTKGetIteratorFor(pos
, &iter
), wxNOT_FOUND
,
457 wxT("internal wxListBox error in insertion") );
462 const unsigned int numItems
= items
.GetCount();
463 for ( unsigned int i
= 0; i
< numItems
; ++i
)
465 wxGtkObject
<GtkTreeEntry
> entry(gtk_tree_entry_new());
466 gtk_tree_entry_set_label(entry
, wxGTK_CONV(items
[i
]));
467 gtk_tree_entry_set_destroy_func(entry
,
468 (GtkTreeEntryDestroy
)gtk_tree_entry_destroy_cb
,
472 gtk_list_store_insert_before(m_liststore
, &itercur
, pIter
);
474 GTKSetItem(itercur
, entry
);
477 AssignNewItemClientData(GTKGetIndexFor(itercur
), clientData
, i
, type
);
480 UpdateOldSelections();
482 return pos
+ numItems
- 1;
485 // ----------------------------------------------------------------------------
487 // ----------------------------------------------------------------------------
489 void wxListBox::DoClear()
491 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
493 GTKDisableEvents(); // just in case
495 InvalidateBestSize();
497 gtk_list_store_clear( m_liststore
); /* well, THAT was easy :) */
501 UpdateOldSelections();
504 void wxListBox::DoDeleteOneItem(unsigned int n
)
506 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
508 InvalidateBestSize();
510 GTKDisableEvents(); // just in case
513 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("wrong listbox index") );
515 // this returns false if iter is invalid (e.g. deleting item at end) but
516 // since we don't use iter, we ignore the return value
517 gtk_list_store_remove(m_liststore
, &iter
);
522 // ----------------------------------------------------------------------------
523 // helper functions for working with iterators
524 // ----------------------------------------------------------------------------
526 bool wxListBox::GTKGetIteratorFor(unsigned pos
, GtkTreeIter
*iter
) const
528 if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore
),
531 wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos
);
538 int wxListBox::GTKGetIndexFor(GtkTreeIter
& iter
) const
541 gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore
), &iter
);
543 gint
* pIntPath
= gtk_tree_path_get_indices(path
);
545 wxCHECK_MSG( pIntPath
, wxNOT_FOUND
, wxT("failed to get iterator path") );
547 int idx
= pIntPath
[0];
549 gtk_tree_path_free( path
);
554 // get GtkTreeEntry from position (note: you need to g_unref it if valid)
555 GtkTreeEntry
*wxListBox::GTKGetEntry(unsigned n
) const
558 if ( !GTKGetIteratorFor(n
, &iter
) )
561 return GetEntry(m_liststore
, &iter
, this);
564 void wxListBox::GTKSetItem(GtkTreeIter
& iter
, const GtkTreeEntry
*entry
)
566 #if wxUSE_CHECKLISTBOX
567 if ( m_hasCheckBoxes
)
569 gtk_list_store_set(m_liststore
, &iter
,
570 0, FALSE
, // FALSE == not toggled
575 #endif // wxUSE_CHECKLISTBOX
577 gtk_list_store_set(m_liststore
, &iter
, 0, entry
, -1);
581 // ----------------------------------------------------------------------------
583 // ----------------------------------------------------------------------------
585 void* wxListBox::DoGetItemClientData(unsigned int n
) const
587 wxGtkObject
<GtkTreeEntry
> entry(GTKGetEntry(n
));
588 wxCHECK_MSG(entry
, NULL
, wxT("could not get entry"));
590 return gtk_tree_entry_get_userdata( entry
);
593 void wxListBox::DoSetItemClientData(unsigned int n
, void* clientData
)
595 wxGtkObject
<GtkTreeEntry
> entry(GTKGetEntry(n
));
596 wxCHECK_RET(entry
, wxT("could not get entry"));
598 gtk_tree_entry_set_userdata( entry
, clientData
);
601 // ----------------------------------------------------------------------------
602 // string list access
603 // ----------------------------------------------------------------------------
605 void wxListBox::SetString(unsigned int n
, const wxString
& label
)
607 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetString") );
608 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
610 GtkTreeEntry
* entry
= GTKGetEntry(n
);
611 wxCHECK_RET( entry
, wxT("wrong listbox index") );
613 // update the item itself
614 gtk_tree_entry_set_label(entry
, wxGTK_CONV(label
));
616 // and update the model which will refresh the tree too
618 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("failed to get iterator") );
620 // FIXME: this resets the checked status of a wxCheckListBox item
622 GTKSetItem(iter
, entry
);
625 wxString
wxListBox::GetString(unsigned int n
) const
627 wxCHECK_MSG( m_treeview
!= NULL
, wxEmptyString
, wxT("invalid listbox") );
629 wxGtkObject
<GtkTreeEntry
> entry(GTKGetEntry(n
));
630 wxCHECK_MSG( entry
, wxEmptyString
, wxT("wrong listbox index") );
632 return wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry
) );
635 unsigned int wxListBox::GetCount() const
637 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox") );
639 return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore
), NULL
);
642 int wxListBox::FindString( const wxString
&item
, bool bCase
) const
644 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
646 //Sort of hackish - maybe there is a faster way
647 unsigned int nCount
= wxListBox::GetCount();
649 for(unsigned int i
= 0; i
< nCount
; ++i
)
651 if( item
.IsSameAs( wxListBox::GetString(i
), bCase
) )
656 // it's not an error if the string is not found -> no wxCHECK
660 // ----------------------------------------------------------------------------
662 // ----------------------------------------------------------------------------
664 void wxListBox::GTKOnActivated(int item
)
666 SendEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, item
, IsSelected(item
));
669 void wxListBox::GTKOnSelectionChanged()
671 if ( HasFlag(wxLB_MULTIPLE
| wxLB_EXTENDED
) )
675 else // single selection
677 const int item
= GetSelection();
678 if ( DoChangeSingleSelection(item
) )
679 SendEvent(wxEVT_COMMAND_LISTBOX_SELECTED
, item
, true);
683 int wxListBox::GetSelection() const
685 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox"));
686 wxCHECK_MSG( HasFlag(wxLB_SINGLE
), wxNOT_FOUND
,
687 wxT("must be single selection listbox"));
690 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
692 // only works on single-sel
693 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
696 return GTKGetIndexFor(iter
);
699 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
701 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
707 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
709 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore
), &iter
))
710 { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead
713 if (gtk_tree_selection_iter_is_selected(selection
, &iter
))
717 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore
), &iter
));
720 return aSelections
.GetCount();
723 bool wxListBox::IsSelected( int n
) const
725 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid listbox") );
727 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
730 wxCHECK_MSG( GTKGetIteratorFor(n
, &iter
), false, wxT("Invalid index") );
732 return gtk_tree_selection_iter_is_selected(selection
, &iter
) != 0;
735 void wxListBox::DoSetSelection( int n
, bool select
)
737 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
741 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
743 // passing -1 to SetSelection() is documented to deselect all items
744 if ( n
== wxNOT_FOUND
)
746 gtk_tree_selection_unselect_all(selection
);
751 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetSelection") );
755 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("Invalid index") );
758 gtk_tree_selection_select_iter(selection
, &iter
);
760 gtk_tree_selection_unselect_iter(selection
, &iter
);
762 GtkTreePath
* path
= gtk_tree_model_get_path(
763 GTK_TREE_MODEL(m_liststore
), &iter
);
765 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
, FALSE
, 0.0f
, 0.0f
);
767 gtk_tree_path_free(path
);
772 void wxListBox::DoScrollToCell(int n
, float alignY
, float alignX
)
774 wxCHECK_RET( m_treeview
, wxT("invalid listbox") );
775 wxCHECK_RET( IsValid(n
), wxT("invalid index"));
777 //RN: I have no idea why this line is needed...
778 if (gdk_pointer_is_grabbed () && gtk_widget_has_grab(GTK_WIDGET(m_treeview
)))
782 if ( !GTKGetIteratorFor(n
, &iter
) )
785 GtkTreePath
* path
= gtk_tree_model_get_path(
786 GTK_TREE_MODEL(m_liststore
), &iter
);
788 // Scroll to the desired cell (0.0 == topleft alignment)
789 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
,
790 TRUE
, alignY
, alignX
);
792 gtk_tree_path_free(path
);
795 void wxListBox::DoSetFirstItem(int n
)
797 DoScrollToCell(n
, 0, 0);
800 void wxListBox::EnsureVisible(int n
)
802 DoScrollToCell(n
, 0.5, 0);
805 // ----------------------------------------------------------------------------
807 // ----------------------------------------------------------------------------
809 int wxListBox::DoListHitTest(const wxPoint
& point
) const
811 // gtk_tree_view_get_path_at_pos() also gets items that are not visible and
812 // we only want visible items we need to check for it manually here
813 if ( !GetClientRect().Contains(point
) )
816 // need to translate from master window since it is in client coords
818 gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview
),
819 &binx
, &biny
, NULL
, NULL
, NULL
);
822 if ( !gtk_tree_view_get_path_at_pos
828 NULL
, // [out] column (always 0 here)
829 NULL
, // [out] x-coord relative to the cell (not interested)
830 NULL
// [out] y-coord relative to the cell
836 int index
= gtk_tree_path_get_indices(path
)[0];
837 gtk_tree_path_free(path
);
842 // ----------------------------------------------------------------------------
844 // ----------------------------------------------------------------------------
846 GtkWidget
*wxListBox::GetConnectWidget()
848 // the correct widget for listbox events (such as mouse clicks for example)
849 // is m_treeview, not the parent scrolled window
850 return GTK_WIDGET(m_treeview
);
853 GdkWindow
*wxListBox::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
855 return gtk_tree_view_get_bin_window(m_treeview
);
858 void wxListBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
860 if (m_hasBgCol
&& m_backgroundColour
.IsOk())
862 GdkWindow
*window
= gtk_tree_view_get_bin_window(m_treeview
);
865 m_backgroundColour
.CalcPixel( gdk_drawable_get_colormap( window
) );
866 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
867 gdk_window_clear( window
);
871 gtk_widget_modify_style( GTK_WIDGET(m_treeview
), style
);
874 wxSize
wxListBox::DoGetBestSize() const
876 wxCHECK_MSG(m_treeview
, wxDefaultSize
, wxT("invalid tree view"));
878 // Start with a minimum size that's not too small
880 GetTextExtent( wxT("X"), &cx
, &cy
);
884 // Find the widest string.
885 const unsigned int count
= GetCount();
889 for ( unsigned int i
= 0; i
< count
; i
++ )
891 GetTextExtent(GetString(i
), &wLine
, NULL
);
892 if ( wLine
> lbWidth
)
899 // And just a bit more for the checkbox if present and then some
900 // (these are rough guesses)
901 #if wxUSE_CHECKLISTBOX
902 if ( m_hasCheckBoxes
)
905 cy
= cy
> 25 ? cy
: 25; // rough height of checkbox
909 // Add room for the scrollbar
910 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
912 // Don't make the listbox too tall but don't make it too small neither
913 lbHeight
= (cy
+4) * wxMin(wxMax(count
, 3), 10);
915 wxSize
best(lbWidth
, lbHeight
);
922 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
924 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
, true);
927 #endif // wxUSE_LISTBOX