]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/listbox.cpp
fix for non precomp
[wxWidgets.git] / src / gtk / listbox.cpp
index f6dd76bf7dcd5493eb54dcf56b9313344fed13c1..d908514a19232f1722b643d38c525d1171ee2d1f 100644 (file)
@@ -43,12 +43,6 @@ extern bool           g_blockEventsOnScroll;
 extern wxCursor       g_globalCursor;
 
 
-//-----------------------------------------------------------------------------
-// idle system
-//-----------------------------------------------------------------------------
-
-extern void wxapp_install_idle_handler();
-extern bool g_isIdle;
 
 //-----------------------------------------------------------------------------
 // Macro to tell which row the strings are in (1 if native checklist, 0 if not)
@@ -978,44 +972,56 @@ void wxListBox::DoSetFirstItem( int n )
     if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_treeview))
         return;
 
-    // terribly efficient (RN:???)
-    // RN: Note that evidently the vadjustment property "vadjustment" from
-    // GtkTreeView is different from the "gtk-vadjustment"...
-    // (i.e. gtk_tree_view_get_vadjustment)
-    const gchar *vadjustment_key = "gtk-vadjustment";
-    guint vadjustment_key_id = g_quark_from_static_string (vadjustment_key);
+    GtkTreeIter iter;
+    gtk_tree_model_iter_nth_child(
+                                    GTK_TREE_MODEL(m_liststore),
+                                    &iter,
+                                    NULL, //NULL = parent = get first
+                                    n
+                                 );
 
-    GtkAdjustment *adjustment =
-       (GtkAdjustment*) g_object_get_qdata(G_OBJECT (m_treeview), vadjustment_key_id);
-    wxCHECK_RET( adjustment, wxT("invalid listbox code") );
+    GtkTreePath* path = gtk_tree_model_get_path(
+                            GTK_TREE_MODEL(m_liststore), &iter);
 
-    // Get the greater of the item heights from each column
-    gint cellheight = 0, cellheightcur;
-    GList* columnlist = gtk_tree_view_get_columns(m_treeview);
-    GList* curlist = columnlist;
+    // Scroll to the desired cell (0.0 == topleft alignment)
+    gtk_tree_view_scroll_to_cell(m_treeview, path, NULL,
+                                 TRUE, 0.0f, 0.0f);
 
-    while(curlist)
-    {
-        gtk_tree_view_column_cell_get_size(
-            GTK_TREE_VIEW_COLUMN(curlist->data),
-            NULL, NULL, NULL, NULL,
-            &cellheightcur);
+    gtk_tree_path_free(path);
+}
 
-        cellheight = cellheightcur > cellheight ? 
-                      cellheightcur : cellheight;
+// ----------------------------------------------------------------------------
+// hittest
+// ----------------------------------------------------------------------------
 
-        curlist = curlist->next;
+int wxListBox::DoListHitTest(const wxPoint& point) const
+{
+    // need to translate from master window since it is in client coords
+    gint binx, biny;
+    gdk_window_get_geometry(gtk_tree_view_get_bin_window(m_treeview), 
+                            &binx, &biny, NULL, NULL, NULL);
+
+    GtkTreePath* path;
+    if ( !gtk_tree_view_get_path_at_pos
+          (
+            m_treeview, 
+            point.x - binx,
+            point.y - biny,
+            &path,
+            NULL,   // [out] column (always 0 here)
+            NULL,   // [out] x-coord relative to the cell (not interested)
+            NULL    // [out] y-coord relative to the cell
+          ) )
+    {
+        return wxNOT_FOUND;
     }
 
-    g_list_free(columnlist);
+    int index = gtk_tree_path_get_indices(path)[0];
+    gtk_tree_path_free(path);
 
-    float y = (float) (cellheight * n);
-    if (y > adjustment->upper - adjustment->page_size)
-        y = adjustment->upper - adjustment->page_size;
-    gtk_adjustment_set_value( adjustment, y );
+    return index;
 }
 
-
 // ----------------------------------------------------------------------------
 // helpers
 // ----------------------------------------------------------------------------
@@ -1030,8 +1036,9 @@ void wxListBox::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
 
 GtkWidget *wxListBox::GetConnectWidget()
 {
-    // return GTK_WIDGET(m_treeview);
-    return m_widget;
+    // the correct widget for listbox events (such as mouse clicks for example)
+    // is m_treeview, not the parent scrolled window
+    return GTK_WIDGET(m_treeview);
 }
 
 bool wxListBox::IsOwnGtkWindow( GdkWindow *window )