1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/listbox.cpp
4 // Author: Robert Roebling
5 // Modified By: Ryan Norton (GtkTreeView implementation)
7 // Copyright: (c) 1998 Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/listbox.h"
19 #include "wx/dynarray.h"
23 #include "wx/settings.h"
24 #include "wx/checklst.h"
25 #include "wx/arrstr.h"
28 #include "wx/gtk/private.h"
29 #include "wx/gtk/treeentry_gtk.h"
32 #include "wx/tooltip.h"
36 #include <gdk/gdkkeysyms.h>
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
42 extern bool g_blockEventsOnDrag
;
43 extern bool g_blockEventsOnScroll
;
47 //-----------------------------------------------------------------------------
48 // Macro to tell which row the strings are in (1 if native checklist, 0 if not)
49 //-----------------------------------------------------------------------------
51 #if wxUSE_CHECKLISTBOX
52 # define WXLISTBOX_DATACOLUMN_ARG(x) (x->m_hasCheckBoxes ? 1 : 0)
54 # define WXLISTBOX_DATACOLUMN_ARG(x) (0)
55 #endif // wxUSE_CHECKLISTBOX
57 #define WXLISTBOX_DATACOLUMN WXLISTBOX_DATACOLUMN_ARG(this)
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
65 gtk_listbox_row_activated_callback(GtkTreeView
* WXUNUSED(treeview
),
67 GtkTreeViewColumn
* WXUNUSED(col
),
70 if (g_blockEventsOnDrag
) return;
71 if (g_blockEventsOnScroll
) return;
73 // This is triggered by either a double-click or a space press
75 int sel
= gtk_tree_path_get_indices(path
)[0];
77 listbox
->GTKOnActivated(sel
);
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
87 gtk_listitem_changed_callback(GtkTreeSelection
* WXUNUSED(selection
),
90 if (g_blockEventsOnDrag
) return;
92 listbox
->GTKOnSelectionChanged();
97 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
103 gtk_listbox_key_press_callback( GtkWidget
*WXUNUSED(widget
),
104 GdkEventKey
*gdk_event
,
107 if ((gdk_event
->keyval
== GDK_Return
) ||
108 (gdk_event
->keyval
== GDK_ISO_Enter
) ||
109 (gdk_event
->keyval
== GDK_KP_Enter
))
112 if (!listbox
->HasMultipleSelection())
113 index
= listbox
->GetSelection();
117 if (listbox
->GetSelections( sels
) < 1)
122 if (index
!= wxNOT_FOUND
)
124 listbox
->GTKOnActivated(index
);
126 // wxMac and wxMSW always invoke default action
129 // DClick not handled -> invoke default action
130 wxWindow
*tlw
= wxGetTopLevelParent( listbox
);
133 GtkWindow
*gtk_window
= GTK_WINDOW( tlw
->GetHandle() );
135 gtk_window_activate_default( gtk_window
);
139 // Always intercept, otherwise we'd get another dclick
140 // event from row_activated
149 //-----------------------------------------------------------------------------
150 // GtkTreeEntry destruction (to destroy client data)
151 //-----------------------------------------------------------------------------
154 static void gtk_tree_entry_destroy_cb(GtkTreeEntry
* entry
,
157 if (listbox
->HasClientObjectData())
159 gpointer userdata
= gtk_tree_entry_get_userdata(entry
);
161 delete (wxClientData
*)userdata
;
166 //-----------------------------------------------------------------------------
167 // Sorting callback (standard CmpNoCase return value)
168 //-----------------------------------------------------------------------------
171 static gint
gtk_listbox_sort_callback(GtkTreeModel
* WXUNUSED(model
),
177 GtkTreeEntry
* entry2
;
179 gtk_tree_model_get(GTK_TREE_MODEL(listbox
->m_liststore
),
181 WXLISTBOX_DATACOLUMN_ARG(listbox
),
183 gtk_tree_model_get(GTK_TREE_MODEL(listbox
->m_liststore
),
185 WXLISTBOX_DATACOLUMN_ARG(listbox
),
187 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
188 wxCHECK_MSG(entry2
, 0, wxT("Could not get entry2"));
190 //We compare collate keys here instead of calling g_utf8_collate
191 //as it is rather slow (and even the docs reccommend this)
192 int ret
= strcmp(gtk_tree_entry_get_collate_key(entry
),
193 gtk_tree_entry_get_collate_key(entry2
)) >= 0;
195 g_object_unref (entry
);
196 g_object_unref (entry2
);
202 //-----------------------------------------------------------------------------
203 // Searching callback (TRUE == not equal, FALSE == equal)
204 //-----------------------------------------------------------------------------
207 static gboolean
gtk_listbox_searchequal_callback(GtkTreeModel
* WXUNUSED(model
),
208 gint
WXUNUSED(column
),
215 gtk_tree_model_get(GTK_TREE_MODEL(listbox
->m_liststore
),
217 WXLISTBOX_DATACOLUMN_ARG(listbox
),
219 wxCHECK_MSG(entry
, 0, wxT("Could not get entry"));
220 wxGtkString
keycollatekey(g_utf8_collate_key(key
, -1));
222 int ret
= strcmp(keycollatekey
,
223 gtk_tree_entry_get_collate_key(entry
));
225 g_object_unref (entry
);
231 //-----------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------
235 IMPLEMENT_DYNAMIC_CLASS(wxListBox
, wxControlWithItems
)
237 // ----------------------------------------------------------------------------
239 // ----------------------------------------------------------------------------
241 void wxListBox::Init()
244 #if wxUSE_CHECKLISTBOX
245 m_hasCheckBoxes
= false;
246 #endif // wxUSE_CHECKLISTBOX
249 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
250 const wxPoint
&pos
, const wxSize
&size
,
251 const wxArrayString
& choices
,
252 long style
, const wxValidator
& validator
,
253 const wxString
&name
)
255 wxCArrayString
chs(choices
);
257 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(),
258 style
, validator
, name
);
261 bool wxListBox::Create( wxWindow
*parent
, wxWindowID id
,
262 const wxPoint
&pos
, const wxSize
&size
,
263 int n
, const wxString choices
[],
264 long style
, const wxValidator
& validator
,
265 const wxString
&name
)
267 if (!PreCreation( parent
, pos
, size
) ||
268 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
270 wxFAIL_MSG( wxT("wxListBox creation failed") );
274 m_widget
= gtk_scrolled_window_new( NULL
, NULL
);
275 g_object_ref(m_widget
);
276 if (style
& wxLB_ALWAYS_SB
)
278 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
279 GTK_POLICY_AUTOMATIC
, GTK_POLICY_ALWAYS
);
283 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget
),
284 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
288 GTKScrolledWindowSetBorder(m_widget
, style
);
290 m_treeview
= GTK_TREE_VIEW( gtk_tree_view_new( ) );
292 //wxListBox doesn't have a header :)
293 //NB: If enabled SetFirstItem doesn't work correctly
294 gtk_tree_view_set_headers_visible(m_treeview
, FALSE
);
296 #if wxUSE_CHECKLISTBOX
298 ((wxCheckListBox
*)this)->DoCreateCheckList();
299 #endif // wxUSE_CHECKLISTBOX
301 // Create the data column
302 gtk_tree_view_insert_column_with_attributes(m_treeview
, -1, "",
303 gtk_cell_renderer_text_new(),
305 WXLISTBOX_DATACOLUMN
, NULL
);
307 // Now create+set the model (GtkListStore) - first argument # of columns
308 #if wxUSE_CHECKLISTBOX
310 m_liststore
= gtk_list_store_new(2, G_TYPE_BOOLEAN
,
311 GTK_TYPE_TREE_ENTRY
);
314 m_liststore
= gtk_list_store_new(1, GTK_TYPE_TREE_ENTRY
);
316 gtk_tree_view_set_model(m_treeview
, GTK_TREE_MODEL(m_liststore
));
318 g_object_unref (m_liststore
); //free on treeview destruction
320 // Disable the pop-up textctrl that enables searching - note that
321 // the docs specify that even if this disabled (which we are doing)
322 // the user can still have it through the start-interactive-search
323 // key binding...either way we want to provide a searchequal callback
324 // NB: If this is enabled a doubleclick event (activate) gets sent
325 // on a successful search
326 gtk_tree_view_set_search_column(m_treeview
, WXLISTBOX_DATACOLUMN
);
327 gtk_tree_view_set_search_equal_func(m_treeview
,
328 (GtkTreeViewSearchEqualFunc
) gtk_listbox_searchequal_callback
,
332 gtk_tree_view_set_enable_search(m_treeview
, FALSE
);
334 GtkSelectionMode mode
;
335 // GTK_SELECTION_EXTENDED is a deprecated synonym for GTK_SELECTION_MULTIPLE
336 if ( style
& (wxLB_MULTIPLE
| wxLB_EXTENDED
) )
338 mode
= GTK_SELECTION_MULTIPLE
;
340 else // no multi-selection flags specified
342 m_windowStyle
|= wxLB_SINGLE
;
344 // Notice that we must use BROWSE and not GTK_SELECTION_SINGLE because
345 // the latter allows to not select any items at all while a single
346 // selection listbox is supposed to always have a selection (at least
347 // once the user selected something, it might not have any initially).
348 mode
= GTK_SELECTION_BROWSE
;
351 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
352 gtk_tree_selection_set_mode( selection
, mode
);
354 // Handle sortable stuff
355 if(HasFlag(wxLB_SORT
))
357 // Setup sorting in ascending (wx) order
358 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m_liststore
),
359 WXLISTBOX_DATACOLUMN
,
362 // Set the sort callback
363 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(m_liststore
),
364 WXLISTBOX_DATACOLUMN
,
365 (GtkTreeIterCompareFunc
) gtk_listbox_sort_callback
,
367 NULL
//"destroy notifier"
372 gtk_container_add (GTK_CONTAINER (m_widget
), GTK_WIDGET(m_treeview
) );
374 gtk_widget_show( GTK_WIDGET(m_treeview
) );
375 m_focusWidget
= GTK_WIDGET(m_treeview
);
377 Append(n
, choices
); // insert initial items
379 // generate dclick events
380 g_signal_connect_after(m_treeview
, "row-activated",
381 G_CALLBACK(gtk_listbox_row_activated_callback
), this);
383 // for intercepting dclick generation by <ENTER>
384 g_signal_connect (m_treeview
, "key_press_event",
385 G_CALLBACK (gtk_listbox_key_press_callback
),
387 m_parent
->DoAddChild( this );
390 SetInitialSize(size
); // need this too because this is a wxControlWithItems
392 g_signal_connect_after (selection
, "changed",
393 G_CALLBACK (gtk_listitem_changed_callback
), this);
398 wxListBox::~wxListBox()
405 void wxListBox::GTKDisableEvents()
407 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
409 g_signal_handlers_block_by_func(selection
,
410 (gpointer
) gtk_listitem_changed_callback
, this);
413 void wxListBox::GTKEnableEvents()
415 GtkTreeSelection
* selection
= gtk_tree_view_get_selection( m_treeview
);
417 g_signal_handlers_unblock_by_func(selection
,
418 (gpointer
) gtk_listitem_changed_callback
, this);
420 UpdateOldSelections();
424 void wxListBox::Update()
429 gdk_window_process_updates(GTK_WIDGET(m_treeview
)->window
, TRUE
);
432 // ----------------------------------------------------------------------------
434 // ----------------------------------------------------------------------------
436 int wxListBox::DoInsertItems(const wxArrayStringsAdapter
& items
,
439 wxClientDataType type
)
441 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
443 InvalidateBestSize();
445 GtkTreeIter
* pIter
= NULL
; // append by default
447 if ( pos
!= GetCount() )
449 wxCHECK_MSG( GTKGetIteratorFor(pos
, &iter
), wxNOT_FOUND
,
450 wxT("internal wxListBox error in insertion") );
455 const unsigned int numItems
= items
.GetCount();
456 for ( unsigned int i
= 0; i
< numItems
; ++i
)
458 GtkTreeEntry
* entry
= gtk_tree_entry_new();
459 gtk_tree_entry_set_label(entry
, wxGTK_CONV(items
[i
]));
460 gtk_tree_entry_set_destroy_func(entry
,
461 (GtkTreeEntryDestroy
)gtk_tree_entry_destroy_cb
,
465 gtk_list_store_insert_before(m_liststore
, &itercur
, pIter
);
467 GTKSetItem(itercur
, entry
);
469 g_object_unref (entry
);
472 AssignNewItemClientData(GTKGetIndexFor(itercur
), clientData
, i
, type
);
475 UpdateOldSelections();
477 return pos
+ numItems
- 1;
480 // ----------------------------------------------------------------------------
482 // ----------------------------------------------------------------------------
484 void wxListBox::DoClear()
486 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
488 GTKDisableEvents(); // just in case
490 InvalidateBestSize();
492 gtk_list_store_clear( m_liststore
); /* well, THAT was easy :) */
497 void wxListBox::DoDeleteOneItem(unsigned int n
)
499 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
501 InvalidateBestSize();
503 GTKDisableEvents(); // just in case
506 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("wrong listbox index") );
508 // this returns false if iter is invalid (e.g. deleting item at end) but
509 // since we don't use iter, we ignore the return value
510 gtk_list_store_remove(m_liststore
, &iter
);
515 // ----------------------------------------------------------------------------
516 // helper functions for working with iterators
517 // ----------------------------------------------------------------------------
519 bool wxListBox::GTKGetIteratorFor(unsigned pos
, GtkTreeIter
*iter
) const
521 if ( !gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_liststore
),
524 wxLogDebug(wxT("gtk_tree_model_iter_nth_child(%u) failed"), pos
);
531 int wxListBox::GTKGetIndexFor(GtkTreeIter
& iter
) const
534 gtk_tree_model_get_path(GTK_TREE_MODEL(m_liststore
), &iter
);
536 gint
* pIntPath
= gtk_tree_path_get_indices(path
);
538 wxCHECK_MSG( pIntPath
, wxNOT_FOUND
, wxT("failed to get iterator path") );
540 int idx
= pIntPath
[0];
542 gtk_tree_path_free( path
);
547 // get GtkTreeEntry from position (note: you need to g_unref it if valid)
548 GtkTreeEntry
*wxListBox::GTKGetEntry(unsigned n
) const
551 if ( !GTKGetIteratorFor(n
, &iter
) )
555 GtkTreeEntry
* entry
= NULL
;
556 gtk_tree_model_get(GTK_TREE_MODEL(m_liststore
), &iter
,
557 WXLISTBOX_DATACOLUMN
, &entry
, -1);
562 void wxListBox::GTKSetItem(GtkTreeIter
& iter
, const GtkTreeEntry
*entry
)
564 #if wxUSE_CHECKLISTBOX
565 if ( m_hasCheckBoxes
)
567 gtk_list_store_set(m_liststore
, &iter
,
568 0, FALSE
, // FALSE == not toggled
573 #endif // wxUSE_CHECKLISTBOX
575 gtk_list_store_set(m_liststore
, &iter
, 0, entry
, -1);
579 // ----------------------------------------------------------------------------
581 // ----------------------------------------------------------------------------
583 void* wxListBox::DoGetItemClientData(unsigned int n
) const
585 wxCHECK_MSG( IsValid(n
), NULL
,
586 wxT("Invalid index passed to GetItemClientData") );
588 GtkTreeEntry
* entry
= GTKGetEntry(n
);
589 wxCHECK_MSG(entry
, NULL
, wxT("could not get entry"));
591 void* userdata
= gtk_tree_entry_get_userdata( entry
);
592 g_object_unref (entry
);
596 void wxListBox::DoSetItemClientData(unsigned int n
, void* clientData
)
598 wxCHECK_RET( IsValid(n
),
599 wxT("Invalid index passed to SetItemClientData") );
601 GtkTreeEntry
* entry
= GTKGetEntry(n
);
602 wxCHECK_RET(entry
, wxT("could not get entry"));
604 gtk_tree_entry_set_userdata( entry
, clientData
);
605 g_object_unref (entry
);
608 // ----------------------------------------------------------------------------
609 // string list access
610 // ----------------------------------------------------------------------------
612 void wxListBox::SetString(unsigned int n
, const wxString
& label
)
614 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetString") );
615 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
617 GtkTreeEntry
* entry
= GTKGetEntry(n
);
618 wxCHECK_RET( entry
, wxT("wrong listbox index") );
620 // update the item itself
621 gtk_tree_entry_set_label(entry
, wxGTK_CONV(label
));
623 // and update the model which will refresh the tree too
625 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("failed to get iterator") );
627 // FIXME: this resets the checked status of a wxCheckListBox item
629 GTKSetItem(iter
, entry
);
632 wxString
wxListBox::GetString(unsigned int n
) const
634 wxCHECK_MSG( m_treeview
!= NULL
, wxEmptyString
, wxT("invalid listbox") );
636 GtkTreeEntry
* entry
= GTKGetEntry(n
);
637 wxCHECK_MSG( entry
, wxEmptyString
, wxT("wrong listbox index") );
639 wxString label
= wxGTK_CONV_BACK( gtk_tree_entry_get_label(entry
) );
641 g_object_unref (entry
);
645 unsigned int wxListBox::GetCount() const
647 wxCHECK_MSG( m_treeview
!= NULL
, 0, wxT("invalid listbox") );
649 return (unsigned int)gtk_tree_model_iter_n_children(GTK_TREE_MODEL(m_liststore
), NULL
);
652 int wxListBox::FindString( const wxString
&item
, bool bCase
) const
654 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
656 //Sort of hackish - maybe there is a faster way
657 unsigned int nCount
= wxListBox::GetCount();
659 for(unsigned int i
= 0; i
< nCount
; ++i
)
661 if( item
.IsSameAs( wxListBox::GetString(i
), bCase
) )
666 // it's not an error if the string is not found -> no wxCHECK
670 // ----------------------------------------------------------------------------
672 // ----------------------------------------------------------------------------
674 void wxListBox::GTKOnActivated(int item
)
676 SendEvent(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, item
, IsSelected(item
));
679 void wxListBox::GTKOnSelectionChanged()
681 if ( HasFlag(wxLB_MULTIPLE
| wxLB_EXTENDED
) )
685 else // single selection
687 const int item
= GetSelection();
688 if ( DoChangeSingleSelection(item
) )
689 SendEvent(wxEVT_COMMAND_LISTBOX_SELECTED
, item
, true);
693 int wxListBox::GetSelection() const
695 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox"));
696 wxCHECK_MSG( HasFlag(wxLB_SINGLE
), wxNOT_FOUND
,
697 wxT("must be single selection listbox"));
700 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
702 // only works on single-sel
703 if (!gtk_tree_selection_get_selected(selection
, NULL
, &iter
))
706 return GTKGetIndexFor(iter
);
709 int wxListBox::GetSelections( wxArrayInt
& aSelections
) const
711 wxCHECK_MSG( m_treeview
!= NULL
, wxNOT_FOUND
, wxT("invalid listbox") );
717 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
719 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_liststore
), &iter
))
720 { //gtk_tree_selection_get_selected_rows is GTK 2.2+ so iter instead
723 if (gtk_tree_selection_iter_is_selected(selection
, &iter
))
727 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(m_liststore
), &iter
));
730 return aSelections
.GetCount();
733 bool wxListBox::IsSelected( int n
) const
735 wxCHECK_MSG( m_treeview
!= NULL
, false, wxT("invalid listbox") );
737 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
740 wxCHECK_MSG( GTKGetIteratorFor(n
, &iter
), false, wxT("Invalid index") );
742 return gtk_tree_selection_iter_is_selected(selection
, &iter
);
745 void wxListBox::DoSetSelection( int n
, bool select
)
747 wxCHECK_RET( m_treeview
!= NULL
, wxT("invalid listbox") );
751 GtkTreeSelection
* selection
= gtk_tree_view_get_selection(m_treeview
);
753 // passing -1 to SetSelection() is documented to deselect all items
754 if ( n
== wxNOT_FOUND
)
756 gtk_tree_selection_unselect_all(selection
);
761 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxListBox::SetSelection") );
765 wxCHECK_RET( GTKGetIteratorFor(n
, &iter
), wxT("Invalid index") );
768 gtk_tree_selection_select_iter(selection
, &iter
);
770 gtk_tree_selection_unselect_iter(selection
, &iter
);
772 GtkTreePath
* path
= gtk_tree_model_get_path(
773 GTK_TREE_MODEL(m_liststore
), &iter
);
775 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
, FALSE
, 0.0f
, 0.0f
);
777 gtk_tree_path_free(path
);
782 void wxListBox::DoScrollToCell(int n
, float alignY
, float alignX
)
784 wxCHECK_RET( m_treeview
, wxT("invalid listbox") );
785 wxCHECK_RET( IsValid(n
), wxT("invalid index"));
787 //RN: I have no idea why this line is needed...
788 if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_treeview
))
792 if ( !GTKGetIteratorFor(n
, &iter
) )
795 GtkTreePath
* path
= gtk_tree_model_get_path(
796 GTK_TREE_MODEL(m_liststore
), &iter
);
798 // Scroll to the desired cell (0.0 == topleft alignment)
799 gtk_tree_view_scroll_to_cell(m_treeview
, path
, NULL
,
800 TRUE
, alignY
, alignX
);
802 gtk_tree_path_free(path
);
805 void wxListBox::DoSetFirstItem(int n
)
807 DoScrollToCell(n
, 0, 0);
810 void wxListBox::EnsureVisible(int n
)
812 DoScrollToCell(n
, 0.5, 0);
815 // ----------------------------------------------------------------------------
817 // ----------------------------------------------------------------------------
819 int wxListBox::DoListHitTest(const wxPoint
& point
) const
821 // gtk_tree_view_get_path_at_pos() also gets items that are not visible and
822 // we only want visible items we need to check for it manually here
823 if ( !GetClientRect().Contains(point
) )
826 // need to translate from master window since it is in client coords
828 gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview
),
829 &binx
, &biny
, NULL
, NULL
, NULL
);
832 if ( !gtk_tree_view_get_path_at_pos
838 NULL
, // [out] column (always 0 here)
839 NULL
, // [out] x-coord relative to the cell (not interested)
840 NULL
// [out] y-coord relative to the cell
846 int index
= gtk_tree_path_get_indices(path
)[0];
847 gtk_tree_path_free(path
);
852 // ----------------------------------------------------------------------------
854 // ----------------------------------------------------------------------------
857 void wxListBox::GTKApplyToolTip( GtkTooltips
*tips
, const gchar
*tip
)
859 // RN: Is this needed anymore?
860 gtk_tooltips_set_tip( tips
, GTK_WIDGET( m_treeview
), tip
, NULL
);
862 #endif // wxUSE_TOOLTIPS
864 GtkWidget
*wxListBox::GetConnectWidget()
866 // the correct widget for listbox events (such as mouse clicks for example)
867 // is m_treeview, not the parent scrolled window
868 return GTK_WIDGET(m_treeview
);
871 GdkWindow
*wxListBox::GTKGetWindow(wxArrayGdkWindows
& WXUNUSED(windows
)) const
873 return gtk_tree_view_get_bin_window(m_treeview
);
876 void wxListBox::DoApplyWidgetStyle(GtkRcStyle
*style
)
878 if (m_hasBgCol
&& m_backgroundColour
.Ok())
880 GdkWindow
*window
= gtk_tree_view_get_bin_window(m_treeview
);
883 m_backgroundColour
.CalcPixel( gdk_drawable_get_colormap( window
) );
884 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
885 gdk_window_clear( window
);
889 gtk_widget_modify_style( GTK_WIDGET(m_treeview
), style
);
892 wxSize
wxListBox::DoGetBestSize() const
894 wxCHECK_MSG(m_treeview
, wxDefaultSize
, wxT("invalid tree view"));
896 // Start with a minimum size that's not too small
898 GetTextExtent( wxT("X"), &cx
, &cy
);
902 // Find the widest string.
903 const unsigned int count
= GetCount();
907 for ( unsigned int i
= 0; i
< count
; i
++ )
909 GetTextExtent(GetString(i
), &wLine
, NULL
);
910 if ( wLine
> lbWidth
)
917 // And just a bit more for the checkbox if present and then some
918 // (these are rough guesses)
919 #if wxUSE_CHECKLISTBOX
920 if ( m_hasCheckBoxes
)
923 cy
= cy
> 25 ? cy
: 25; // rough height of checkbox
927 // Add room for the scrollbar
928 lbWidth
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
930 // Don't make the listbox too tall but don't make it too small neither
931 lbHeight
= (cy
+4) * wxMin(wxMax(count
, 3), 10);
933 wxSize
best(lbWidth
, lbHeight
);
940 wxListBox::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
942 return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new
, true);
945 #endif // wxUSE_LISTBOX