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"
29 #include "wx/tooltip.h"
33 #include "wx/gtk/private.h"
34 #include "wx/gtk/private/gtk2-compat.h"
35 #include "wx/gtk/private/object.h"
36 #include "wx/gtk/private/treeentry_gtk.h"
38 #include <gdk/gdkkeysyms.h>
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 GetEntry(GtkListStore
*store
, GtkTreeIter
*iter
, const wxListBox
*listbox
)
76 gtk_tree_model_get(GTK_TREE_MODEL(store
),
78 WXLISTBOX_DATACOLUMN_ARG(listbox
),
81 g_object_unref(entry
);
85 } // anonymous namespace
87 //-----------------------------------------------------------------------------
89 //-----------------------------------------------------------------------------
93 gtk_listbox_row_activated_callback(GtkTreeView
* WXUNUSED(treeview
),
95 GtkTreeViewColumn
* WXUNUSED(col
),
98 if (g_blockEventsOnDrag
) return;
99 if (g_blockEventsOnScroll
) return;
101 // This is triggered by either a double-click or a space press
103 int sel
= gtk_tree_path_get_indices(path
)[0];
105 listbox
->GTKOnActivated(sel
);
109 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
115 gtk_listitem_changed_callback(GtkTreeSelection
* WXUNUSED(selection
),
118 if (g_blockEventsOnDrag
) return;
120 listbox
->GTKOnSelectionChanged();
125 //-----------------------------------------------------------------------------
127 //-----------------------------------------------------------------------------
131 gtk_listbox_key_press_callback( GtkWidget
*WXUNUSED(widget
),
132 GdkEventKey
*gdk_event
,
135 if ((gdk_event
->keyval
== GDK_Return
) ||
136 (gdk_event
->keyval
== GDK_ISO_Enter
) ||
137 (gdk_event
->keyval
== GDK_KP_Enter
))
140 if (!listbox
->HasMultipleSelection())
141 index
= listbox
->GetSelection();
145 if (listbox
->GetSelections( sels
) < 1)
150 if (index
!= wxNOT_FOUND
)
152 listbox
->GTKOnActivated(index
);
154 // wxMac and wxMSW always invoke default action
157 // DClick not handled -> invoke default action
158 wxWindow
*tlw
= wxGetTopLevelParent( listbox
);
161 GtkWindow
*gtk_window
= GTK_WINDOW( tlw
->GetHandle() );
163 gtk_window_activate_default( gtk_window
);
167 // Always intercept, otherwise we'd get another dclick
168 // event from row_activated
177 //-----------------------------------------------------------------------------
178 // GtkTreeEntry destruction (to destroy client data)
179 //-----------------------------------------------------------------------------
182 static void tree_entry_destroy_cb(wxTreeEntry
* entry
,
185 if (listbox
->HasClientObjectData())
187 void* userdata
= wx_tree_entry_get_userdata(entry
);
189 delete (wxClientData
*)userdata
;
194 //-----------------------------------------------------------------------------
195 // Sorting callback (standard CmpNoCase return value)
196 //-----------------------------------------------------------------------------
199 static gint
gtk_listbox_sort_callback(GtkTreeModel
* WXUNUSED(model
),
204 wxTreeEntry
* entry1
= GetEntry(listbox
->m_liststore
, a
, listbox
);
205 wxCHECK_MSG(entry1
, 0, wxT("Could not get first entry"));
207 wxTreeEntry
* entry2
= GetEntry(listbox
->m_liststore
, b
, listbox
);
208 wxCHECK_MSG(entry2
, 0, wxT("Could not get second entry"));
210 //We compare collate keys here instead of calling g_utf8_collate
211 //as it is rather slow (and even the docs recommend this)
212 return strcmp(wx_tree_entry_get_collate_key(entry1
),
213 wx_tree_entry_get_collate_key(entry2
)) >= 0;
217 //-----------------------------------------------------------------------------
218 // Searching callback (TRUE == not equal, FALSE == equal)
219 //-----------------------------------------------------------------------------
222 static gboolean
gtk_listbox_searchequal_callback(GtkTreeModel
* WXUNUSED(model
),
223 gint
WXUNUSED(column
),
228 wxTreeEntry
* entry
= GetEntry(listbox
->m_liststore
, iter
, listbox
);
229 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
231 wxGtkString
keycollatekey(g_utf8_collate_key(key
, -1));
233 return strcmp(keycollatekey
, wx_tree_entry_get_collate_key(entry
)) != 0;
237 //-----------------------------------------------------------------------------
239 //-----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
245 void wxListBox::Init()
248 #if wxUSE_CHECKLISTBOX
249 m_hasCheckBoxes
= false;
250 #endif // wxUSE_CHECKLISTBOX
253 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
254 const wxPoint
&pos
, const wxSize
&size
,
255 const wxArrayString
& choices
,
256 long style
, const wxValidator
& validator
,
257 const wxString
&name
)
259 wxCArrayString
chs(choices
);
261 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
262 style
, validator
, name
);
265 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
266 const wxPoint
&pos
, const wxSize
&size
,
267 int n
, const wxString choices
[],
268 long style
, const wxValidator
& validator
,
269 const wxString
&name
)
271 if (!PreCreation( parent
, pos
, size
) ||
272 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
274 wxFAIL_MSG( wxT("wxListBox creation failed") );
278 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
279 g_object_ref(m_widget
);
280 if (style
& wxLB_ALWAYS_SB
)
282 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
283 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
287 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
288 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
292 GTKScrolledWindowSetBorder(m_widget
, style
);
294 m_treeview
= GTK_TREE_VIEW( gtk_tree_view_new( ) );
296 //wxListBox doesn't have a header :)
297 //NB: If enabled SetFirstItem doesn't work correctly
298 gtk_tree_view_set_headers_visible(m_treeview
, FALSE
);
300 #if wxUSE_CHECKLISTBOX
302 ((wxCheckListBox
*)this)->DoCreateCheckList();
303 #endif // wxUSE_CHECKLISTBOX
305 // Create the data column
306 gtk_tree_view_insert_column_with_attributes(m_treeview
, -1, "",
307 gtk_cell_renderer_text_new(),
309 WXLISTBOX_DATACOLUMN
, NULL
);
311 // Now create+set the model (GtkListStore) - first argument # of columns
312 #if wxUSE_CHECKLISTBOX
314 m_liststore
= gtk_list_store_new(2, G_TYPE_BOOLEAN
,
318 m_liststore
= gtk_list_store_new(1, WX_TYPE_TREE_ENTRY
);
320 gtk_tree_view_set_model(m_treeview
, GTK_TREE_MODEL(m_liststore
));
322 g_object_unref (m_liststore
); //free on treeview destruction
324 // Disable the pop-up textctrl that enables searching - note that
325 // the docs specify that even if this disabled (which we are doing)
326 // the user can still have it through the start-interactive-search
327 // key binding...either way we want to provide a searchequal callback
328 // NB: If this is enabled a doubleclick event (activate) gets sent
329 // on a successful search
330 gtk_tree_view_set_search_column(m_treeview
, WXLISTBOX_DATACOLUMN
);
331 gtk_tree_view_set_search_equal_func(m_treeview
,
332 (GtkTreeViewSearchEqualFunc
) gtk_listbox_searchequal_callback
,
336 gtk_tree_view_set_enable_search(m_treeview
, FALSE
);
338 GtkSelectionMode mode
;
339 // GTK_SELECTION_EXTENDED is a deprecated synonym for GTK_SELECTION_MULTIPLE
340 if ( style
& (wxLB_MULTIPLE
| wxLB_EXTENDED
) )
342 mode
= GTK_SELECTION_MULTIPLE
;
344 else // no multi-selection flags specified
346 m_windowStyle
|= wxLB_SINGLE
;
348 // Notice that we must use BROWSE and not GTK_SELECTION_SINGLE because
349 // the latter allows to not select any items at all while a single
350 // selection listbox is supposed to always have a selection (at least
351 // once the user selected something, it might not have any initially).
352 mode
= GTK_SELECTION_BROWSE
;
355 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
356 gtk_tree_selection_set_mode( selection
, mode
);
358 // Handle sortable stuff
359 if(HasFlag(wxLB_SORT
))
361 // Setup sorting in ascending (wx) order
362 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m_liststore
),
363 WXLISTBOX_DATACOLUMN
,
366 // Set the sort callback
367 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(m_liststore
),
368 WXLISTBOX_DATACOLUMN
,
369 (GtkTreeIterCompareFunc
) gtk_listbox_sort_callback
,
371 NULL
//"destroy notifier"
376 gtk_container_add (GTK_CONTAINER (m_widget
), GTK_WIDGET(m_treeview
) );
378 gtk_widget_show( GTK_WIDGET(m_treeview
) );
379 m_focusWidget
= GTK_WIDGET(m_treeview
);
381 Append(n
, choices
); // insert initial items
383 // generate dclick events
384 g_signal_connect_after(m_treeview
, "row-activated",
385 G_CALLBACK(gtk_listbox_row_activated_callback
), this);
387 // for intercepting dclick generation by <ENTER>
388 g_signal_connect (m_treeview
, "key_press_event",
389 G_CALLBACK (gtk_listbox_key_press_callback
),
391 m_parent
->DoAddChild( this );
394 SetInitialSize(size
); // need this too because this is a wxControlWithItems
396 g_signal_connect_after (selection
, "changed",
397 G_CALLBACK (gtk_listitem_changed_callback
), this);
402 wxListBox::~wxListBox()
406 GTKDisconnect(m_treeview
);
407 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
409 GTKDisconnect(selection
);
415 void wxListBox::GTKDisableEvents()
417 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
419 g_signal_handlers_block_by_func(selection
,
420 (gpointer
) gtk_listitem_changed_callback
, this);
423 void wxListBox::GTKEnableEvents()
425 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
427 g_signal_handlers_unblock_by_func(selection
,
428 (gpointer
) gtk_listitem_changed_callback
, this);
430 UpdateOldSelections();
434 void wxListBox::Update()
439 gdk_window_process_updates(gtk_widget_get_window(GTK_WIDGET(m_treeview
)), true);
442 // ----------------------------------------------------------------------------
444 // ----------------------------------------------------------------------------
446 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
449 wxClientDataType type
)
451 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
453 InvalidateBestSize();
454 int n
= DoInsertItemsInLoop(items
, pos
, clientData
, type
);
455 UpdateOldSelections();
459 int wxListBox::DoInsertOneItem(const wxString
& item
, unsigned int pos
)
461 wxTreeEntry
* entry
= wx_tree_entry_new();
462 wx_tree_entry_set_label(entry
, wxGTK_CONV(item
));
463 wx_tree_entry_set_destroy_func(entry
, (wxTreeEntryDestroy
)tree_entry_destroy_cb
, this);
465 #if wxUSE_CHECKLISTBOX
466 int entryCol
= int(m_hasCheckBoxes
);
470 gtk_list_store_insert_with_values(m_liststore
, NULL
, pos
, entryCol
, entry
, -1);
471 g_object_unref(entry
);
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
480 void wxListBox::DoClear()
482 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
484 GTKDisableEvents(); // just in case
486 InvalidateBestSize();
488 gtk_list_store_clear( m_liststore
); /* well, THAT was easy :) */
492 UpdateOldSelections();
495 void wxListBox::DoDeleteOneItem(unsigned int n
)
497 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
499 InvalidateBestSize();
501 GTKDisableEvents(); // just in case
504 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("wrong listbox index") );
506 // this returns false if iter is invalid (e.g. deleting item at end) but
507 // since we don't use iter, we ignore the return value
508 gtk_list_store_remove(m_liststore
, &iter
);
513 // ----------------------------------------------------------------------------
514 // helper functions for working with iterators
515 // ----------------------------------------------------------------------------
517 bool wxListBox::GTKGetIteratorFor(unsigned pos
, GtkTreeIter
*iter
) const
519 if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore
),
522 wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos
);
529 int wxListBox::GTKGetIndexFor(GtkTreeIter
& iter
) const
532 gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore
), &iter
);
534 gint
* pIntPath
= gtk_tree_path_get_indices(path
);
536 wxCHECK_MSG( pIntPath
, wxNOT_FOUND
, wxT("failed to get iterator path") );
538 int idx
= pIntPath
[0];
540 gtk_tree_path_free( path
);
545 // get GtkTreeEntry from position (note: you need to g_unref it if valid)
546 wxTreeEntry
* wxListBox::GTKGetEntry(unsigned n
) const
549 if ( !GTKGetIteratorFor(n
, &iter
) )
552 return GetEntry(m_liststore
, &iter
, this);
555 // ----------------------------------------------------------------------------
557 // ----------------------------------------------------------------------------
559 void* wxListBox::DoGetItemClientData(unsigned int n
) const
561 wxTreeEntry
* entry
= GTKGetEntry(n
);
562 wxCHECK_MSG(entry
, NULL
, wxT("could not get entry"));
564 return wx_tree_entry_get_userdata(entry
);
567 void wxListBox::DoSetItemClientData(unsigned int n
, void* clientData
)
569 wxTreeEntry
* entry
= GTKGetEntry(n
);
570 wxCHECK_RET(entry
, wxT("could not get entry"));
572 wx_tree_entry_set_userdata(entry
, clientData
);
575 // ----------------------------------------------------------------------------
576 // string list access
577 // ----------------------------------------------------------------------------
579 void wxListBox::SetString(unsigned int n
, const wxString
& label
)
581 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
584 wxCHECK_RET(GTKGetIteratorFor(n
, &iter
), "invalid index");
585 wxTreeEntry
* entry
= GetEntry(m_liststore
, &iter
, this);
587 // update the item itself
588 wx_tree_entry_set_label(entry
, wxGTK_CONV(label
));
590 // signal row changed
591 GtkTreeModel
* tree_model
= GTK_TREE_MODEL(m_liststore
);
592 GtkTreePath
* path
= gtk_tree_model_get_path(tree_model
, &iter
);
593 gtk_tree_model_row_changed(tree_model
, path
, &iter
);
594 gtk_tree_path_free(path
);
597 wxString
wxListBox::GetString(unsigned int n
) const
599 wxCHECK_MSG( m_treeview
!= NULL
, wxEmptyString
, wxT("invalid listbox") );
601 wxTreeEntry
* entry
= GTKGetEntry(n
);
602 wxCHECK_MSG( entry
, wxEmptyString
, wxT("wrong listbox index") );
604 return wxGTK_CONV_BACK(wx_tree_entry_get_label(entry
));
607 unsigned int wxListBox::GetCount() const
609 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox") );
611 return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore
), NULL
);
614 int wxListBox::FindString( const wxString
&item
, bool bCase
) const
616 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
618 //Sort of hackish - maybe there is a faster way
619 unsigned int nCount
= wxListBox::GetCount();
621 for(unsigned int i
= 0; i
< nCount
; ++i
)
623 if( item
.IsSameAs( wxListBox::GetString(i
), bCase
) )
628 // it's not an error if the string is not found -> no wxCHECK
632 // ----------------------------------------------------------------------------
634 // ----------------------------------------------------------------------------
636 void wxListBox::GTKOnActivated(int item
)
638 SendEvent(wxEVT_LISTBOX_DCLICK
, item
, IsSelected(item
));
641 void wxListBox::GTKOnSelectionChanged()
643 if ( HasFlag(wxLB_MULTIPLE
| wxLB_EXTENDED
) )
647 else // single selection
649 const int item
= GetSelection();
650 if ( DoChangeSingleSelection(item
) )
651 SendEvent(wxEVT_LISTBOX
, item
, true);
655 int wxListBox::GetSelection() const
657 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox"));
658 wxCHECK_MSG( HasFlag(wxLB_SINGLE
), wxNOT_FOUND
,
659 wxT("must be single selection listbox"));
662 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
664 // only works on single-sel
665 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
668 return GTKGetIndexFor(iter
);
671 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
673 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
679 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
681 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore
), &iter
))
682 { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead
685 if (gtk_tree_selection_iter_is_selected(selection
, &iter
))
689 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore
), &iter
));
692 return aSelections
.GetCount();
695 bool wxListBox::IsSelected( int n
) const
697 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid listbox") );
699 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
702 wxCHECK_MSG( GTKGetIteratorFor(n
, &iter
), false, wxT("Invalid index") );
704 return gtk_tree_selection_iter_is_selected(selection
, &iter
) != 0;
707 void wxListBox::DoSetSelection( int n
, bool select
)
709 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
713 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
715 // passing -1 to SetSelection() is documented to deselect all items
716 if ( n
== wxNOT_FOUND
)
718 gtk_tree_selection_unselect_all(selection
);
723 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetSelection") );
727 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("Invalid index") );
730 gtk_tree_selection_select_iter(selection
, &iter
);
732 gtk_tree_selection_unselect_iter(selection
, &iter
);
734 GtkTreePath
* path
= gtk_tree_model_get_path(
735 GTK_TREE_MODEL(m_liststore
), &iter
);
737 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
, FALSE
, 0.0f
, 0.0f
);
739 gtk_tree_path_free(path
);
744 void wxListBox::DoScrollToCell(int n
, float alignY
, float alignX
)
746 wxCHECK_RET( m_treeview
, wxT("invalid listbox") );
747 wxCHECK_RET( IsValid(n
), wxT("invalid index"));
749 //RN: I have no idea why this line is needed...
750 if (gtk_widget_has_grab(GTK_WIDGET(m_treeview
)))
754 if ( !GTKGetIteratorFor(n
, &iter
) )
757 GtkTreePath
* path
= gtk_tree_model_get_path(
758 GTK_TREE_MODEL(m_liststore
), &iter
);
760 // Scroll to the desired cell (0.0 == topleft alignment)
761 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
,
762 TRUE
, alignY
, alignX
);
764 gtk_tree_path_free(path
);
767 void wxListBox::DoSetFirstItem(int n
)
769 DoScrollToCell(n
, 0, 0);
772 void wxListBox::EnsureVisible(int n
)
774 DoScrollToCell(n
, 0.5, 0);
777 // ----------------------------------------------------------------------------
779 // ----------------------------------------------------------------------------
781 int wxListBox::DoListHitTest(const wxPoint
& point
) const
783 // gtk_tree_view_get_path_at_pos() also gets items that are not visible and
784 // we only want visible items we need to check for it manually here
785 if ( !GetClientRect().Contains(point
) )
788 // need to translate from master window since it is in client coords
790 gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview
),
791 &binx
, &biny
, NULL
, NULL
);
794 if ( !gtk_tree_view_get_path_at_pos
800 NULL
, // [out] column (always 0 here)
801 NULL
, // [out] x-coord relative to the cell (not interested)
802 NULL
// [out] y-coord relative to the cell
808 int index
= gtk_tree_path_get_indices(path
)[0];
809 gtk_tree_path_free(path
);
814 // ----------------------------------------------------------------------------
816 // ----------------------------------------------------------------------------
818 GtkWidget
*wxListBox::GetConnectWidget()
820 // the correct widget for listbox events (such as mouse clicks for example)
821 // is m_treeview, not the parent scrolled window
822 return GTK_WIDGET(m_treeview
);
825 GdkWindow
*wxListBox::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
827 return gtk_tree_view_get_bin_window(m_treeview
);
830 void wxListBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
833 // don't know if this is even necessary, or how to do it
835 if (m_hasBgCol
&& m_backgroundColour
.IsOk())
837 GdkWindow
*window
= gtk_tree_view_get_bin_window(m_treeview
);
840 m_backgroundColour
.CalcPixel( gdk_drawable_get_colormap( window
) );
841 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
842 gdk_window_clear( window
);
847 GTKApplyStyle(GTK_WIDGET(m_treeview
), style
);
850 wxSize
wxListBox::DoGetBestSize() const
852 wxCHECK_MSG(m_treeview
, wxDefaultSize
, wxT("invalid tree view"));
854 // Start with a minimum size that's not too small
856 GetTextExtent( wxT("X"), &cx
, &cy
);
860 // Find the widest string.
861 const unsigned int count
= GetCount();
865 for ( unsigned int i
= 0; i
< count
; i
++ )
867 GetTextExtent(GetString(i
), &wLine
, NULL
);
868 if ( wLine
> lbWidth
)
875 // And just a bit more for the checkbox if present and then some
876 // (these are rough guesses)
877 #if wxUSE_CHECKLISTBOX
878 if ( m_hasCheckBoxes
)
881 cy
= cy
> 25 ? cy
: 25; // rough height of checkbox
885 // Add room for the scrollbar
886 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
888 // Don't make the listbox too tall but don't make it too small neither
889 lbHeight
= (cy
+4) * wxMin(wxMax(count
, 3), 10);
891 wxSize
best(lbWidth
, lbHeight
);
898 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
900 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new(), true);
903 #endif // wxUSE_LISTBOX