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"
37 #include <gdk/gdkkeysyms.h>
39 //-----------------------------------------------------------------------------
41 //-----------------------------------------------------------------------------
43 extern bool g_blockEventsOnDrag
;
44 extern bool g_blockEventsOnScroll
;
48 //-----------------------------------------------------------------------------
49 // Macro to tell which row the strings are in (1 if native checklist, 0 if not)
50 //-----------------------------------------------------------------------------
52 #if wxUSE_CHECKLISTBOX
53 # define WXLISTBOX_DATACOLUMN_ARG(x) (x->m_hasCheckBoxes ? 1 : 0)
55 # define WXLISTBOX_DATACOLUMN_ARG(x) (0)
56 #endif // wxUSE_CHECKLISTBOX
58 #define WXLISTBOX_DATACOLUMN WXLISTBOX_DATACOLUMN_ARG(this)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
67 // Return the entry for the given listbox item.
69 // Return value must be released by caller if non-NULL.
71 GetEntry(GtkListStore
*store
, GtkTreeIter
*iter
, const wxListBox
*listbox
)
74 gtk_tree_model_get(GTK_TREE_MODEL(store
),
76 WXLISTBOX_DATACOLUMN_ARG(listbox
),
83 } // anonymous namespace
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
91 gtk_listbox_row_activated_callback(GtkTreeView
* WXUNUSED(treeview
),
93 GtkTreeViewColumn
* WXUNUSED(col
),
96 if (g_blockEventsOnDrag
) return;
97 if (g_blockEventsOnScroll
) return;
99 // This is triggered by either a double-click or a space press
101 int sel
= gtk_tree_path_get_indices(path
)[0];
103 listbox
->GTKOnActivated(sel
);
107 //-----------------------------------------------------------------------------
109 //-----------------------------------------------------------------------------
113 gtk_listitem_changed_callback(GtkTreeSelection
* WXUNUSED(selection
),
116 if (g_blockEventsOnDrag
) return;
118 listbox
->GTKOnSelectionChanged();
123 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
129 gtk_listbox_key_press_callback( GtkWidget
*WXUNUSED(widget
),
130 GdkEventKey
*gdk_event
,
133 if ((gdk_event
->keyval
== GDK_Return
) ||
134 (gdk_event
->keyval
== GDK_ISO_Enter
) ||
135 (gdk_event
->keyval
== GDK_KP_Enter
))
138 if (!listbox
->HasMultipleSelection())
139 index
= listbox
->GetSelection();
143 if (listbox
->GetSelections( sels
) < 1)
148 if (index
!= wxNOT_FOUND
)
150 listbox
->GTKOnActivated(index
);
152 // wxMac and wxMSW always invoke default action
155 // DClick not handled -> invoke default action
156 wxWindow
*tlw
= wxGetTopLevelParent( listbox
);
159 GtkWindow
*gtk_window
= GTK_WINDOW( tlw
->GetHandle() );
161 gtk_window_activate_default( gtk_window
);
165 // Always intercept, otherwise we'd get another dclick
166 // event from row_activated
175 //-----------------------------------------------------------------------------
176 // GtkTreeEntry destruction (to destroy client data)
177 //-----------------------------------------------------------------------------
180 static void gtk_tree_entry_destroy_cb(GtkTreeEntry
* entry
,
183 if (listbox
->HasClientObjectData())
185 gpointer userdata
= gtk_tree_entry_get_userdata(entry
);
187 delete (wxClientData
*)userdata
;
192 //-----------------------------------------------------------------------------
193 // Sorting callback (standard CmpNoCase return value)
194 //-----------------------------------------------------------------------------
197 static gint
gtk_listbox_sort_callback(GtkTreeModel
* WXUNUSED(model
),
202 wxGtkObject
<GtkTreeEntry
> entry1(GetEntry(listbox
->m_liststore
, a
, listbox
));
203 wxCHECK_MSG(entry1
, 0, wxT("Could not get first entry"));
205 wxGtkObject
<GtkTreeEntry
> entry2(GetEntry(listbox
->m_liststore
, b
, listbox
));
206 wxCHECK_MSG(entry2
, 0, wxT("Could not get second entry"));
208 //We compare collate keys here instead of calling g_utf8_collate
209 //as it is rather slow (and even the docs reccommend this)
210 return strcmp(gtk_tree_entry_get_collate_key(entry1
),
211 gtk_tree_entry_get_collate_key(entry2
)) >= 0;
215 //-----------------------------------------------------------------------------
216 // Searching callback (TRUE == not equal, FALSE == equal)
217 //-----------------------------------------------------------------------------
220 static gboolean
gtk_listbox_searchequal_callback(GtkTreeModel
* WXUNUSED(model
),
221 gint
WXUNUSED(column
),
226 wxGtkObject
<GtkTreeEntry
>
227 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
, gtk_tree_entry_get_collate_key(entry
)) != 0;
236 //-----------------------------------------------------------------------------
238 //-----------------------------------------------------------------------------
240 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControlWithItems
)
242 // ----------------------------------------------------------------------------
244 // ----------------------------------------------------------------------------
246 void wxListBox::Init()
249 #if wxUSE_CHECKLISTBOX
250 m_hasCheckBoxes
= false;
251 #endif // wxUSE_CHECKLISTBOX
254 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
255 const wxPoint
&pos
, const wxSize
&size
,
256 const wxArrayString
& choices
,
257 long style
, const wxValidator
& validator
,
258 const wxString
&name
)
260 wxCArrayString
chs(choices
);
262 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
263 style
, validator
, name
);
266 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
267 const wxPoint
&pos
, const wxSize
&size
,
268 int n
, const wxString choices
[],
269 long style
, const wxValidator
& validator
,
270 const wxString
&name
)
272 if (!PreCreation( parent
, pos
, size
) ||
273 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
275 wxFAIL_MSG( wxT("wxListBox creation failed") );
279 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
280 g_object_ref(m_widget
);
281 if (style
& wxLB_ALWAYS_SB
)
283 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
284 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
288 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
289 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
293 GTKScrolledWindowSetBorder(m_widget
, style
);
295 m_treeview
= GTK_TREE_VIEW( gtk_tree_view_new( ) );
297 //wxListBox doesn't have a header :)
298 //NB: If enabled SetFirstItem doesn't work correctly
299 gtk_tree_view_set_headers_visible(m_treeview
, FALSE
);
301 #if wxUSE_CHECKLISTBOX
303 ((wxCheckListBox
*)this)->DoCreateCheckList();
304 #endif // wxUSE_CHECKLISTBOX
306 // Create the data column
307 gtk_tree_view_insert_column_with_attributes(m_treeview
, -1, "",
308 gtk_cell_renderer_text_new(),
310 WXLISTBOX_DATACOLUMN
, NULL
);
312 // Now create+set the model (GtkListStore) - first argument # of columns
313 #if wxUSE_CHECKLISTBOX
315 m_liststore
= gtk_list_store_new(2, G_TYPE_BOOLEAN
,
316 GTK_TYPE_TREE_ENTRY
);
319 m_liststore
= gtk_list_store_new(1, GTK_TYPE_TREE_ENTRY
);
321 gtk_tree_view_set_model(m_treeview
, GTK_TREE_MODEL(m_liststore
));
323 g_object_unref (m_liststore
); //free on treeview destruction
325 // Disable the pop-up textctrl that enables searching - note that
326 // the docs specify that even if this disabled (which we are doing)
327 // the user can still have it through the start-interactive-search
328 // key binding...either way we want to provide a searchequal callback
329 // NB: If this is enabled a doubleclick event (activate) gets sent
330 // on a successful search
331 gtk_tree_view_set_search_column(m_treeview
, WXLISTBOX_DATACOLUMN
);
332 gtk_tree_view_set_search_equal_func(m_treeview
,
333 (GtkTreeViewSearchEqualFunc
) gtk_listbox_searchequal_callback
,
337 gtk_tree_view_set_enable_search(m_treeview
, FALSE
);
339 GtkSelectionMode mode
;
340 // GTK_SELECTION_EXTENDED is a deprecated synonym for GTK_SELECTION_MULTIPLE
341 if ( style
& (wxLB_MULTIPLE
| wxLB_EXTENDED
) )
343 mode
= GTK_SELECTION_MULTIPLE
;
345 else // no multi-selection flags specified
347 m_windowStyle
|= wxLB_SINGLE
;
349 // Notice that we must use BROWSE and not GTK_SELECTION_SINGLE because
350 // the latter allows to not select any items at all while a single
351 // selection listbox is supposed to always have a selection (at least
352 // once the user selected something, it might not have any initially).
353 mode
= GTK_SELECTION_BROWSE
;
356 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
357 gtk_tree_selection_set_mode( selection
, mode
);
359 // Handle sortable stuff
360 if(HasFlag(wxLB_SORT
))
362 // Setup sorting in ascending (wx) order
363 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m_liststore
),
364 WXLISTBOX_DATACOLUMN
,
367 // Set the sort callback
368 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(m_liststore
),
369 WXLISTBOX_DATACOLUMN
,
370 (GtkTreeIterCompareFunc
) gtk_listbox_sort_callback
,
372 NULL
//"destroy notifier"
377 gtk_container_add (GTK_CONTAINER (m_widget
), GTK_WIDGET(m_treeview
) );
379 gtk_widget_show( GTK_WIDGET(m_treeview
) );
380 m_focusWidget
= GTK_WIDGET(m_treeview
);
382 Append(n
, choices
); // insert initial items
384 // generate dclick events
385 g_signal_connect_after(m_treeview
, "row-activated",
386 G_CALLBACK(gtk_listbox_row_activated_callback
), this);
388 // for intercepting dclick generation by <ENTER>
389 g_signal_connect (m_treeview
, "key_press_event",
390 G_CALLBACK (gtk_listbox_key_press_callback
),
392 m_parent
->DoAddChild( this );
395 SetInitialSize(size
); // need this too because this is a wxControlWithItems
397 g_signal_connect_after (selection
, "changed",
398 G_CALLBACK (gtk_listitem_changed_callback
), this);
403 wxListBox::~wxListBox()
410 void wxListBox::GTKDisableEvents()
412 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
414 g_signal_handlers_block_by_func(selection
,
415 (gpointer
) gtk_listitem_changed_callback
, this);
418 void wxListBox::GTKEnableEvents()
420 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
422 g_signal_handlers_unblock_by_func(selection
,
423 (gpointer
) gtk_listitem_changed_callback
, this);
425 UpdateOldSelections();
429 void wxListBox::Update()
434 gdk_window_process_updates(GTK_WIDGET(m_treeview
)->window
, TRUE
);
437 // ----------------------------------------------------------------------------
439 // ----------------------------------------------------------------------------
441 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
444 wxClientDataType type
)
446 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
448 InvalidateBestSize();
450 GtkTreeIter
* pIter
= NULL
; // append by default
452 if ( pos
!= GetCount() )
454 wxCHECK_MSG( GTKGetIteratorFor(pos
, &iter
), wxNOT_FOUND
,
455 wxT("internal wxListBox error in insertion") );
460 const unsigned int numItems
= items
.GetCount();
461 for ( unsigned int i
= 0; i
< numItems
; ++i
)
463 wxGtkObject
<GtkTreeEntry
> entry(gtk_tree_entry_new());
464 gtk_tree_entry_set_label(entry
, wxGTK_CONV(items
[i
]));
465 gtk_tree_entry_set_destroy_func(entry
,
466 (GtkTreeEntryDestroy
)gtk_tree_entry_destroy_cb
,
470 gtk_list_store_insert_before(m_liststore
, &itercur
, pIter
);
472 GTKSetItem(itercur
, entry
);
475 AssignNewItemClientData(GTKGetIndexFor(itercur
), clientData
, i
, type
);
478 UpdateOldSelections();
480 return pos
+ numItems
- 1;
483 // ----------------------------------------------------------------------------
485 // ----------------------------------------------------------------------------
487 void wxListBox::DoClear()
489 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
491 GTKDisableEvents(); // just in case
493 InvalidateBestSize();
495 gtk_list_store_clear( m_liststore
); /* well, THAT was easy :) */
500 void wxListBox::DoDeleteOneItem(unsigned int n
)
502 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
504 InvalidateBestSize();
506 GTKDisableEvents(); // just in case
509 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("wrong listbox index") );
511 // this returns false if iter is invalid (e.g. deleting item at end) but
512 // since we don't use iter, we ignore the return value
513 gtk_list_store_remove(m_liststore
, &iter
);
518 // ----------------------------------------------------------------------------
519 // helper functions for working with iterators
520 // ----------------------------------------------------------------------------
522 bool wxListBox::GTKGetIteratorFor(unsigned pos
, GtkTreeIter
*iter
) const
524 if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore
),
527 wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos
);
534 int wxListBox::GTKGetIndexFor(GtkTreeIter
& iter
) const
537 gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore
), &iter
);
539 gint
* pIntPath
= gtk_tree_path_get_indices(path
);
541 wxCHECK_MSG( pIntPath
, wxNOT_FOUND
, wxT("failed to get iterator path") );
543 int idx
= pIntPath
[0];
545 gtk_tree_path_free( path
);
550 // get GtkTreeEntry from position (note: you need to g_unref it if valid)
551 GtkTreeEntry
*wxListBox::GTKGetEntry(unsigned n
) const
554 if ( !GTKGetIteratorFor(n
, &iter
) )
557 return GetEntry(m_liststore
, &iter
, this);
560 void wxListBox::GTKSetItem(GtkTreeIter
& iter
, const GtkTreeEntry
*entry
)
562 #if wxUSE_CHECKLISTBOX
563 if ( m_hasCheckBoxes
)
565 gtk_list_store_set(m_liststore
, &iter
,
566 0, FALSE
, // FALSE == not toggled
571 #endif // wxUSE_CHECKLISTBOX
573 gtk_list_store_set(m_liststore
, &iter
, 0, entry
, -1);
577 // ----------------------------------------------------------------------------
579 // ----------------------------------------------------------------------------
581 void* wxListBox::DoGetItemClientData(unsigned int n
) const
583 wxCHECK_MSG( IsValid(n
), NULL
,
584 wxT("Invalid index passed to GetItemClientData") );
586 wxGtkObject
<GtkTreeEntry
> entry(GTKGetEntry(n
));
587 wxCHECK_MSG(entry
, NULL
, wxT("could not get entry"));
589 return gtk_tree_entry_get_userdata( entry
);
592 void wxListBox::DoSetItemClientData(unsigned int n
, void* clientData
)
594 wxCHECK_RET( IsValid(n
),
595 wxT("Invalid index passed to SetItemClientData") );
597 wxGtkObject
<GtkTreeEntry
> entry(GTKGetEntry(n
));
598 wxCHECK_RET(entry
, wxT("could not get entry"));
600 gtk_tree_entry_set_userdata( entry
, clientData
);
603 // ----------------------------------------------------------------------------
604 // string list access
605 // ----------------------------------------------------------------------------
607 void wxListBox::SetString(unsigned int n
, const wxString
& label
)
609 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetString") );
610 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
612 GtkTreeEntry
* entry
= GTKGetEntry(n
);
613 wxCHECK_RET( entry
, wxT("wrong listbox index") );
615 // update the item itself
616 gtk_tree_entry_set_label(entry
, wxGTK_CONV(label
));
618 // and update the model which will refresh the tree too
620 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("failed to get iterator") );
622 // FIXME: this resets the checked status of a wxCheckListBox item
624 GTKSetItem(iter
, entry
);
627 wxString
wxListBox::GetString(unsigned int n
) const
629 wxCHECK_MSG( m_treeview
!= NULL
, wxEmptyString
, wxT("invalid listbox") );
631 wxGtkObject
<GtkTreeEntry
> entry(GTKGetEntry(n
));
632 wxCHECK_MSG( entry
, wxEmptyString
, wxT("wrong listbox index") );
634 return wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry
) );
637 unsigned int wxListBox::GetCount() const
639 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox") );
641 return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore
), NULL
);
644 int wxListBox::FindString( const wxString
&item
, bool bCase
) const
646 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
648 //Sort of hackish - maybe there is a faster way
649 unsigned int nCount
= wxListBox::GetCount();
651 for(unsigned int i
= 0; i
< nCount
; ++i
)
653 if( item
.IsSameAs( wxListBox::GetString(i
), bCase
) )
658 // it's not an error if the string is not found -> no wxCHECK
662 // ----------------------------------------------------------------------------
664 // ----------------------------------------------------------------------------
666 void wxListBox::GTKOnActivated(int item
)
668 SendEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, item
, IsSelected(item
));
671 void wxListBox::GTKOnSelectionChanged()
673 if ( HasFlag(wxLB_MULTIPLE
| wxLB_EXTENDED
) )
677 else // single selection
679 const int item
= GetSelection();
680 if ( DoChangeSingleSelection(item
) )
681 SendEvent(wxEVT_COMMAND_LISTBOX_SELECTED
, item
, true);
685 int wxListBox::GetSelection() const
687 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox"));
688 wxCHECK_MSG( HasFlag(wxLB_SINGLE
), wxNOT_FOUND
,
689 wxT("must be single selection listbox"));
692 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
694 // only works on single-sel
695 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
698 return GTKGetIndexFor(iter
);
701 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
703 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
709 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
711 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore
), &iter
))
712 { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead
715 if (gtk_tree_selection_iter_is_selected(selection
, &iter
))
719 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore
), &iter
));
722 return aSelections
.GetCount();
725 bool wxListBox::IsSelected( int n
) const
727 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid listbox") );
729 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
732 wxCHECK_MSG( GTKGetIteratorFor(n
, &iter
), false, wxT("Invalid index") );
734 return gtk_tree_selection_iter_is_selected(selection
, &iter
);
737 void wxListBox::DoSetSelection( int n
, bool select
)
739 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
743 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
745 // passing -1 to SetSelection() is documented to deselect all items
746 if ( n
== wxNOT_FOUND
)
748 gtk_tree_selection_unselect_all(selection
);
753 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetSelection") );
757 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("Invalid index") );
760 gtk_tree_selection_select_iter(selection
, &iter
);
762 gtk_tree_selection_unselect_iter(selection
, &iter
);
764 GtkTreePath
* path
= gtk_tree_model_get_path(
765 GTK_TREE_MODEL(m_liststore
), &iter
);
767 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
, FALSE
, 0.0f
, 0.0f
);
769 gtk_tree_path_free(path
);
774 void wxListBox::DoScrollToCell(int n
, float alignY
, float alignX
)
776 wxCHECK_RET( m_treeview
, wxT("invalid listbox") );
777 wxCHECK_RET( IsValid(n
), wxT("invalid index"));
779 //RN: I have no idea why this line is needed...
780 if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_treeview
))
784 if ( !GTKGetIteratorFor(n
, &iter
) )
787 GtkTreePath
* path
= gtk_tree_model_get_path(
788 GTK_TREE_MODEL(m_liststore
), &iter
);
790 // Scroll to the desired cell (0.0 == topleft alignment)
791 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
,
792 TRUE
, alignY
, alignX
);
794 gtk_tree_path_free(path
);
797 void wxListBox::DoSetFirstItem(int n
)
799 DoScrollToCell(n
, 0, 0);
802 void wxListBox::EnsureVisible(int n
)
804 DoScrollToCell(n
, 0.5, 0);
807 // ----------------------------------------------------------------------------
809 // ----------------------------------------------------------------------------
811 int wxListBox::DoListHitTest(const wxPoint
& point
) const
813 // gtk_tree_view_get_path_at_pos() also gets items that are not visible and
814 // we only want visible items we need to check for it manually here
815 if ( !GetClientRect().Contains(point
) )
818 // need to translate from master window since it is in client coords
820 gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview
),
821 &binx
, &biny
, NULL
, NULL
, NULL
);
824 if ( !gtk_tree_view_get_path_at_pos
830 NULL
, // [out] column (always 0 here)
831 NULL
, // [out] x-coord relative to the cell (not interested)
832 NULL
// [out] y-coord relative to the cell
838 int index
= gtk_tree_path_get_indices(path
)[0];
839 gtk_tree_path_free(path
);
844 // ----------------------------------------------------------------------------
846 // ----------------------------------------------------------------------------
849 void wxListBox::GTKApplyToolTip( GtkTooltips
*tips
, const gchar
*tip
)
851 // RN: Is this needed anymore?
852 gtk_tooltips_set_tip( tips
, GTK_WIDGET( m_treeview
), tip
, NULL
);
854 #endif // wxUSE_TOOLTIPS
856 GtkWidget
*wxListBox::GetConnectWidget()
858 // the correct widget for listbox events (such as mouse clicks for example)
859 // is m_treeview, not the parent scrolled window
860 return GTK_WIDGET(m_treeview
);
863 GdkWindow
*wxListBox::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
865 return gtk_tree_view_get_bin_window(m_treeview
);
868 void wxListBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
870 if (m_hasBgCol
&& m_backgroundColour
.Ok())
872 GdkWindow
*window
= gtk_tree_view_get_bin_window(m_treeview
);
875 m_backgroundColour
.CalcPixel( gdk_drawable_get_colormap( window
) );
876 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
877 gdk_window_clear( window
);
881 gtk_widget_modify_style( GTK_WIDGET(m_treeview
), style
);
884 wxSize
wxListBox::DoGetBestSize() const
886 wxCHECK_MSG(m_treeview
, wxDefaultSize
, wxT("invalid tree view"));
888 // Start with a minimum size that's not too small
890 GetTextExtent( wxT("X"), &cx
, &cy
);
894 // Find the widest string.
895 const unsigned int count
= GetCount();
899 for ( unsigned int i
= 0; i
< count
; i
++ )
901 GetTextExtent(GetString(i
), &wLine
, NULL
);
902 if ( wLine
> lbWidth
)
909 // And just a bit more for the checkbox if present and then some
910 // (these are rough guesses)
911 #if wxUSE_CHECKLISTBOX
912 if ( m_hasCheckBoxes
)
915 cy
= cy
> 25 ? cy
: 25; // rough height of checkbox
919 // Add room for the scrollbar
920 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
922 // Don't make the listbox too tall but don't make it too small neither
923 lbHeight
= (cy
+4) * wxMin(wxMax(count
, 3), 10);
925 wxSize
best(lbWidth
, lbHeight
);
932 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
934 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
, true);
937 #endif // wxUSE_LISTBOX