1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/listbox.cpp
4 // Author: Robert Roebling
5 // Modified By: Ryan Norton (GtkTreeView implementation)
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
15 #include "wx/listbox.h"
18 #include "wx/dynarray.h"
22 #include "wx/settings.h"
23 #include "wx/checklst.h"
24 #include "wx/arrstr.h"
28 #include "wx/tooltip.h"
32 #include "wx/gtk/private.h"
33 #include "wx/gtk/private/gtk2-compat.h"
34 #include "wx/gtk/private/object.h"
35 #include "wx/gtk/private/treeentry_gtk.h"
37 #include <gdk/gdkkeysyms.h>
39 #include <gdk/gdkkeysyms-compat.h>
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 extern bool g_blockEventsOnDrag
;
47 extern bool g_blockEventsOnScroll
;
51 //-----------------------------------------------------------------------------
52 // Macro to tell which row the strings are in (1 if native checklist, 0 if not)
53 //-----------------------------------------------------------------------------
55 #if wxUSE_CHECKLISTBOX
56 # define WXLISTBOX_DATACOLUMN_ARG(x) (x->m_hasCheckBoxes ? 1 : 0)
58 # define WXLISTBOX_DATACOLUMN_ARG(x) (0)
59 #endif // wxUSE_CHECKLISTBOX
61 #define WXLISTBOX_DATACOLUMN WXLISTBOX_DATACOLUMN_ARG(this)
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
70 // Return the entry for the given listbox item.
72 GetEntry(GtkListStore
*store
, GtkTreeIter
*iter
, const wxListBox
*listbox
)
75 gtk_tree_model_get(GTK_TREE_MODEL(store
),
77 WXLISTBOX_DATACOLUMN_ARG(listbox
),
80 g_object_unref(entry
);
84 } // anonymous namespace
86 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
92 gtk_listbox_row_activated_callback(GtkTreeView
* WXUNUSED(treeview
),
94 GtkTreeViewColumn
* WXUNUSED(col
),
97 if (g_blockEventsOnDrag
) return;
98 if (g_blockEventsOnScroll
) return;
100 // This is triggered by either a double-click or a space press
102 int sel
= gtk_tree_path_get_indices(path
)[0];
104 listbox
->GTKOnActivated(sel
);
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
114 gtk_listitem_changed_callback(GtkTreeSelection
* WXUNUSED(selection
),
117 if (g_blockEventsOnDrag
) return;
119 listbox
->GTKOnSelectionChanged();
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
130 gtk_listbox_key_press_callback( GtkWidget
*WXUNUSED(widget
),
131 GdkEventKey
*gdk_event
,
134 if ((gdk_event
->keyval
== GDK_Return
) ||
135 (gdk_event
->keyval
== GDK_ISO_Enter
) ||
136 (gdk_event
->keyval
== GDK_KP_Enter
))
139 if (!listbox
->HasMultipleSelection())
140 index
= listbox
->GetSelection();
144 if (listbox
->GetSelections( sels
) < 1)
149 if (index
!= wxNOT_FOUND
)
151 listbox
->GTKOnActivated(index
);
153 // wxMac and wxMSW always invoke default action
156 // DClick not handled -> invoke default action
157 wxWindow
*tlw
= wxGetTopLevelParent( listbox
);
160 GtkWindow
*gtk_window
= GTK_WINDOW( tlw
->GetHandle() );
162 gtk_window_activate_default( gtk_window
);
166 // Always intercept, otherwise we'd get another dclick
167 // event from row_activated
176 //-----------------------------------------------------------------------------
177 // GtkTreeEntry destruction (to destroy client data)
178 //-----------------------------------------------------------------------------
181 static void tree_entry_destroy_cb(wxTreeEntry
* entry
,
184 if (listbox
->HasClientObjectData())
186 void* userdata
= wx_tree_entry_get_userdata(entry
);
188 delete (wxClientData
*)userdata
;
193 //-----------------------------------------------------------------------------
194 // Sorting callback (standard CmpNoCase return value)
195 //-----------------------------------------------------------------------------
198 static gint
gtk_listbox_sort_callback(GtkTreeModel
* WXUNUSED(model
),
203 wxTreeEntry
* entry1
= GetEntry(listbox
->m_liststore
, a
, listbox
);
204 wxCHECK_MSG(entry1
, 0, wxT("Could not get first entry"));
206 wxTreeEntry
* entry2
= GetEntry(listbox
->m_liststore
, b
, listbox
);
207 wxCHECK_MSG(entry2
, 0, wxT("Could not get second entry"));
209 //We compare collate keys here instead of calling g_utf8_collate
210 //as it is rather slow (and even the docs recommend this)
211 return strcmp(wx_tree_entry_get_collate_key(entry1
),
212 wx_tree_entry_get_collate_key(entry2
)) >= 0;
216 //-----------------------------------------------------------------------------
217 // Searching callback (TRUE == not equal, FALSE == equal)
218 //-----------------------------------------------------------------------------
221 static gboolean
gtk_listbox_searchequal_callback(GtkTreeModel
* WXUNUSED(model
),
222 gint
WXUNUSED(column
),
227 wxTreeEntry
* entry
= GetEntry(listbox
->m_liststore
, iter
, listbox
);
228 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
230 wxGtkString
keycollatekey(g_utf8_collate_key(key
, -1));
232 return strcmp(keycollatekey
, wx_tree_entry_get_collate_key(entry
)) != 0;
236 //-----------------------------------------------------------------------------
238 //-----------------------------------------------------------------------------
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
244 void wxListBox::Init()
247 #if wxUSE_CHECKLISTBOX
248 m_hasCheckBoxes
= false;
249 #endif // wxUSE_CHECKLISTBOX
252 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
253 const wxPoint
&pos
, const wxSize
&size
,
254 const wxArrayString
& choices
,
255 long style
, const wxValidator
& validator
,
256 const wxString
&name
)
258 wxCArrayString
chs(choices
);
260 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
261 style
, validator
, name
);
264 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
265 const wxPoint
&pos
, const wxSize
&size
,
266 int n
, const wxString choices
[],
267 long style
, const wxValidator
& validator
,
268 const wxString
&name
)
270 if (!PreCreation( parent
, pos
, size
) ||
271 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
273 wxFAIL_MSG( wxT("wxListBox creation failed") );
277 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
278 g_object_ref(m_widget
);
279 if (style
& wxLB_ALWAYS_SB
)
281 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
282 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
286 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
287 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
291 GTKScrolledWindowSetBorder(m_widget
, style
);
293 m_treeview
= GTK_TREE_VIEW( gtk_tree_view_new( ) );
295 //wxListBox doesn't have a header :)
296 //NB: If enabled SetFirstItem doesn't work correctly
297 gtk_tree_view_set_headers_visible(m_treeview
, FALSE
);
299 #if wxUSE_CHECKLISTBOX
301 ((wxCheckListBox
*)this)->DoCreateCheckList();
302 #endif // wxUSE_CHECKLISTBOX
304 // Create the data column
305 gtk_tree_view_insert_column_with_attributes(m_treeview
, -1, "",
306 gtk_cell_renderer_text_new(),
308 WXLISTBOX_DATACOLUMN
, NULL
);
310 // Now create+set the model (GtkListStore) - first argument # of columns
311 #if wxUSE_CHECKLISTBOX
313 m_liststore
= gtk_list_store_new(2, G_TYPE_BOOLEAN
,
317 m_liststore
= gtk_list_store_new(1, WX_TYPE_TREE_ENTRY
);
319 gtk_tree_view_set_model(m_treeview
, GTK_TREE_MODEL(m_liststore
));
321 g_object_unref (m_liststore
); //free on treeview destruction
323 // Disable the pop-up textctrl that enables searching - note that
324 // the docs specify that even if this disabled (which we are doing)
325 // the user can still have it through the start-interactive-search
326 // key binding...either way we want to provide a searchequal callback
327 // NB: If this is enabled a doubleclick event (activate) gets sent
328 // on a successful search
329 gtk_tree_view_set_search_column(m_treeview
, WXLISTBOX_DATACOLUMN
);
330 gtk_tree_view_set_search_equal_func(m_treeview
,
331 (GtkTreeViewSearchEqualFunc
) gtk_listbox_searchequal_callback
,
335 gtk_tree_view_set_enable_search(m_treeview
, FALSE
);
337 GtkSelectionMode mode
;
338 // GTK_SELECTION_EXTENDED is a deprecated synonym for GTK_SELECTION_MULTIPLE
339 if ( style
& (wxLB_MULTIPLE
| wxLB_EXTENDED
) )
341 mode
= GTK_SELECTION_MULTIPLE
;
343 else // no multi-selection flags specified
345 m_windowStyle
|= wxLB_SINGLE
;
347 // Notice that we must use BROWSE and not GTK_SELECTION_SINGLE because
348 // the latter allows to not select any items at all while a single
349 // selection listbox is supposed to always have a selection (at least
350 // once the user selected something, it might not have any initially).
351 mode
= GTK_SELECTION_BROWSE
;
354 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
355 gtk_tree_selection_set_mode( selection
, mode
);
357 // Handle sortable stuff
358 if(HasFlag(wxLB_SORT
))
360 // Setup sorting in ascending (wx) order
361 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m_liststore
),
362 WXLISTBOX_DATACOLUMN
,
365 // Set the sort callback
366 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(m_liststore
),
367 WXLISTBOX_DATACOLUMN
,
368 (GtkTreeIterCompareFunc
) gtk_listbox_sort_callback
,
370 NULL
//"destroy notifier"
375 gtk_container_add (GTK_CONTAINER (m_widget
), GTK_WIDGET(m_treeview
) );
377 gtk_widget_show( GTK_WIDGET(m_treeview
) );
378 m_focusWidget
= GTK_WIDGET(m_treeview
);
380 Append(n
, choices
); // insert initial items
382 // generate dclick events
383 g_signal_connect_after(m_treeview
, "row-activated",
384 G_CALLBACK(gtk_listbox_row_activated_callback
), this);
386 // for intercepting dclick generation by <ENTER>
387 g_signal_connect (m_treeview
, "key_press_event",
388 G_CALLBACK (gtk_listbox_key_press_callback
),
390 m_parent
->DoAddChild( this );
393 SetInitialSize(size
); // need this too because this is a wxControlWithItems
395 g_signal_connect_after (selection
, "changed",
396 G_CALLBACK (gtk_listitem_changed_callback
), this);
401 wxListBox::~wxListBox()
405 GTKDisconnect(m_treeview
);
406 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
408 GTKDisconnect(selection
);
414 void wxListBox::GTKDisableEvents()
416 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
418 g_signal_handlers_block_by_func(selection
,
419 (gpointer
) gtk_listitem_changed_callback
, this);
422 void wxListBox::GTKEnableEvents()
424 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
426 g_signal_handlers_unblock_by_func(selection
,
427 (gpointer
) gtk_listitem_changed_callback
, this);
429 UpdateOldSelections();
433 void wxListBox::Update()
438 gdk_window_process_updates(gtk_widget_get_window(GTK_WIDGET(m_treeview
)), true);
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
445 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
448 wxClientDataType type
)
450 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
452 InvalidateBestSize();
453 int n
= DoInsertItemsInLoop(items
, pos
, clientData
, type
);
454 UpdateOldSelections();
458 int wxListBox::DoInsertOneItem(const wxString
& item
, unsigned int pos
)
460 wxTreeEntry
* entry
= wx_tree_entry_new();
461 wx_tree_entry_set_label(entry
, wxGTK_CONV(item
));
462 wx_tree_entry_set_destroy_func(entry
, (wxTreeEntryDestroy
)tree_entry_destroy_cb
, this);
464 #if wxUSE_CHECKLISTBOX
465 int entryCol
= int(m_hasCheckBoxes
);
469 gtk_list_store_insert_with_values(m_liststore
, NULL
, pos
, entryCol
, entry
, -1);
470 g_object_unref(entry
);
475 // ----------------------------------------------------------------------------
477 // ----------------------------------------------------------------------------
479 void wxListBox::DoClear()
481 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
483 GTKDisableEvents(); // just in case
485 InvalidateBestSize();
487 gtk_list_store_clear( m_liststore
); /* well, THAT was easy :) */
491 UpdateOldSelections();
494 void wxListBox::DoDeleteOneItem(unsigned int n
)
496 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
498 InvalidateBestSize();
500 GTKDisableEvents(); // just in case
503 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("wrong listbox index") );
505 // this returns false if iter is invalid (e.g. deleting item at end) but
506 // since we don't use iter, we ignore the return value
507 gtk_list_store_remove(m_liststore
, &iter
);
512 // ----------------------------------------------------------------------------
513 // helper functions for working with iterators
514 // ----------------------------------------------------------------------------
516 bool wxListBox::GTKGetIteratorFor(unsigned pos
, GtkTreeIter
*iter
) const
518 if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore
),
521 wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos
);
528 int wxListBox::GTKGetIndexFor(GtkTreeIter
& iter
) const
531 gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore
), &iter
);
533 gint
* pIntPath
= gtk_tree_path_get_indices(path
);
535 wxCHECK_MSG( pIntPath
, wxNOT_FOUND
, wxT("failed to get iterator path") );
537 int idx
= pIntPath
[0];
539 gtk_tree_path_free( path
);
544 // get GtkTreeEntry from position (note: you need to g_unref it if valid)
545 wxTreeEntry
* wxListBox::GTKGetEntry(unsigned n
) const
548 if ( !GTKGetIteratorFor(n
, &iter
) )
551 return GetEntry(m_liststore
, &iter
, this);
554 // ----------------------------------------------------------------------------
556 // ----------------------------------------------------------------------------
558 void* wxListBox::DoGetItemClientData(unsigned int n
) const
560 wxTreeEntry
* entry
= GTKGetEntry(n
);
561 wxCHECK_MSG(entry
, NULL
, wxT("could not get entry"));
563 return wx_tree_entry_get_userdata(entry
);
566 void wxListBox::DoSetItemClientData(unsigned int n
, void* clientData
)
568 wxTreeEntry
* entry
= GTKGetEntry(n
);
569 wxCHECK_RET(entry
, wxT("could not get entry"));
571 wx_tree_entry_set_userdata(entry
, clientData
);
574 // ----------------------------------------------------------------------------
575 // string list access
576 // ----------------------------------------------------------------------------
578 void wxListBox::SetString(unsigned int n
, const wxString
& label
)
580 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
583 wxCHECK_RET(GTKGetIteratorFor(n
, &iter
), "invalid index");
584 wxTreeEntry
* entry
= GetEntry(m_liststore
, &iter
, this);
586 // update the item itself
587 wx_tree_entry_set_label(entry
, wxGTK_CONV(label
));
589 // signal row changed
590 GtkTreeModel
* tree_model
= GTK_TREE_MODEL(m_liststore
);
591 GtkTreePath
* path
= gtk_tree_model_get_path(tree_model
, &iter
);
592 gtk_tree_model_row_changed(tree_model
, path
, &iter
);
593 gtk_tree_path_free(path
);
596 wxString
wxListBox::GetString(unsigned int n
) const
598 wxCHECK_MSG( m_treeview
!= NULL
, wxEmptyString
, wxT("invalid listbox") );
600 wxTreeEntry
* entry
= GTKGetEntry(n
);
601 wxCHECK_MSG( entry
, wxEmptyString
, wxT("wrong listbox index") );
603 return wxGTK_CONV_BACK(wx_tree_entry_get_label(entry
));
606 unsigned int wxListBox::GetCount() const
608 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox") );
610 return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore
), NULL
);
613 int wxListBox::FindString( const wxString
&item
, bool bCase
) const
615 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
617 //Sort of hackish - maybe there is a faster way
618 unsigned int nCount
= wxListBox::GetCount();
620 for(unsigned int i
= 0; i
< nCount
; ++i
)
622 if( item
.IsSameAs( wxListBox::GetString(i
), bCase
) )
627 // it's not an error if the string is not found -> no wxCHECK
631 // ----------------------------------------------------------------------------
633 // ----------------------------------------------------------------------------
635 void wxListBox::GTKOnActivated(int item
)
637 SendEvent(wxEVT_LISTBOX_DCLICK
, item
, IsSelected(item
));
640 void wxListBox::GTKOnSelectionChanged()
642 if ( HasFlag(wxLB_MULTIPLE
| wxLB_EXTENDED
) )
646 else // single selection
648 const int item
= GetSelection();
649 if ( DoChangeSingleSelection(item
) )
650 SendEvent(wxEVT_LISTBOX
, item
, true);
654 int wxListBox::GetSelection() const
656 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox"));
657 wxCHECK_MSG( HasFlag(wxLB_SINGLE
), wxNOT_FOUND
,
658 wxT("must be single selection listbox"));
661 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
663 // only works on single-sel
664 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
667 return GTKGetIndexFor(iter
);
670 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
672 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
678 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
680 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore
), &iter
))
681 { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead
684 if (gtk_tree_selection_iter_is_selected(selection
, &iter
))
688 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore
), &iter
));
691 return aSelections
.GetCount();
694 bool wxListBox::IsSelected( int n
) const
696 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid listbox") );
698 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
701 wxCHECK_MSG( GTKGetIteratorFor(n
, &iter
), false, wxT("Invalid index") );
703 return gtk_tree_selection_iter_is_selected(selection
, &iter
) != 0;
706 void wxListBox::DoSetSelection( int n
, bool select
)
708 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
712 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
714 // passing -1 to SetSelection() is documented to deselect all items
715 if ( n
== wxNOT_FOUND
)
717 gtk_tree_selection_unselect_all(selection
);
722 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetSelection") );
726 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("Invalid index") );
729 gtk_tree_selection_select_iter(selection
, &iter
);
731 gtk_tree_selection_unselect_iter(selection
, &iter
);
733 GtkTreePath
* path
= gtk_tree_model_get_path(
734 GTK_TREE_MODEL(m_liststore
), &iter
);
736 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
, FALSE
, 0.0f
, 0.0f
);
738 gtk_tree_path_free(path
);
743 void wxListBox::DoScrollToCell(int n
, float alignY
, float alignX
)
745 wxCHECK_RET( m_treeview
, wxT("invalid listbox") );
746 wxCHECK_RET( IsValid(n
), wxT("invalid index"));
748 //RN: I have no idea why this line is needed...
749 if (gtk_widget_has_grab(GTK_WIDGET(m_treeview
)))
753 if ( !GTKGetIteratorFor(n
, &iter
) )
756 GtkTreePath
* path
= gtk_tree_model_get_path(
757 GTK_TREE_MODEL(m_liststore
), &iter
);
759 // Scroll to the desired cell (0.0 == topleft alignment)
760 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
,
761 TRUE
, alignY
, alignX
);
763 gtk_tree_path_free(path
);
766 void wxListBox::DoSetFirstItem(int n
)
768 DoScrollToCell(n
, 0, 0);
771 void wxListBox::EnsureVisible(int n
)
773 DoScrollToCell(n
, 0.5, 0);
776 // ----------------------------------------------------------------------------
778 // ----------------------------------------------------------------------------
780 int wxListBox::DoListHitTest(const wxPoint
& point
) const
782 // gtk_tree_view_get_path_at_pos() also gets items that are not visible and
783 // we only want visible items we need to check for it manually here
784 if ( !GetClientRect().Contains(point
) )
787 // need to translate from master window since it is in client coords
789 gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview
),
790 &binx
, &biny
, NULL
, NULL
);
793 if ( !gtk_tree_view_get_path_at_pos
799 NULL
, // [out] column (always 0 here)
800 NULL
, // [out] x-coord relative to the cell (not interested)
801 NULL
// [out] y-coord relative to the cell
807 int index
= gtk_tree_path_get_indices(path
)[0];
808 gtk_tree_path_free(path
);
813 // ----------------------------------------------------------------------------
815 // ----------------------------------------------------------------------------
817 GtkWidget
*wxListBox::GetConnectWidget()
819 // the correct widget for listbox events (such as mouse clicks for example)
820 // is m_treeview, not the parent scrolled window
821 return GTK_WIDGET(m_treeview
);
824 GdkWindow
*wxListBox::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
826 return gtk_tree_view_get_bin_window(m_treeview
);
829 void wxListBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
832 // don't know if this is even necessary, or how to do it
834 if (m_hasBgCol
&& m_backgroundColour
.IsOk())
836 GdkWindow
*window
= gtk_tree_view_get_bin_window(m_treeview
);
839 m_backgroundColour
.CalcPixel( gdk_drawable_get_colormap( window
) );
840 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
841 gdk_window_clear( window
);
846 GTKApplyStyle(GTK_WIDGET(m_treeview
), style
);
849 wxSize
wxListBox::DoGetBestSize() const
851 wxCHECK_MSG(m_treeview
, wxDefaultSize
, wxT("invalid tree view"));
853 // Start with a minimum size that's not too small
855 GetTextExtent( wxT("X"), &cx
, &cy
);
859 // Find the widest string.
860 const unsigned int count
= GetCount();
864 for ( unsigned int i
= 0; i
< count
; i
++ )
866 GetTextExtent(GetString(i
), &wLine
, NULL
);
867 if ( wLine
> lbWidth
)
874 // And just a bit more for the checkbox if present and then some
875 // (these are rough guesses)
876 #if wxUSE_CHECKLISTBOX
877 if ( m_hasCheckBoxes
)
880 cy
= cy
> 25 ? cy
: 25; // rough height of checkbox
884 // Add room for the scrollbar
885 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
887 // Don't make the listbox too tall but don't make it too small neither
888 lbHeight
= (cy
+4) * wxMin(wxMax(count
, 3), 10);
890 wxSize
best(lbWidth
, lbHeight
);
897 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
899 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new(), true);
902 #endif // wxUSE_LISTBOX