diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 09:48:42 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 09:48:42 +0000 |
commit | 4441bbed72c07151797f4f69c978b8374fb0bac0 (patch) | |
tree | c221372e8a7867ff71b6307f7dc1377192921106 /views | |
parent | da86a4cd91b795f2bcfa1c1508ec89bb9a908c37 (diff) | |
download | chromium_src-4441bbed72c07151797f4f69c978b8374fb0bac0.zip chromium_src-4441bbed72c07151797f4f69c978b8374fb0bac0.tar.gz chromium_src-4441bbed72c07151797f4f69c978b8374fb0bac0.tar.bz2 |
Implement selection of rows on mouse clicks in TableView2 for GTK.
Before this change, clicking rows in TableView2 for GTK did not
select the clicked rows.
TEST=manually with view_examples.
BUG=none
Review URL: http://codereview.chromium.org/1015005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/table/native_table_gtk.cc | 22 | ||||
-rw-r--r-- | views/controls/table/native_table_gtk.h | 6 | ||||
-rw-r--r-- | views/examples/table2_example.h | 3 |
3 files changed, 29 insertions, 2 deletions
diff --git a/views/controls/table/native_table_gtk.cc b/views/controls/table/native_table_gtk.cc index b2dce54..779308d 100644 --- a/views/controls/table/native_table_gtk.cc +++ b/views/controls/table/native_table_gtk.cc @@ -203,6 +203,9 @@ void NativeTableGtk::CreateNativeControl() { } tree_view_ = GTK_TREE_VIEW(gtk_tree_view_new()); + g_signal_connect(tree_view_, "cursor-changed", + G_CALLBACK(OnCursorChangedThunk), this); + // The tree view must be wrapped in a scroll-view to be scrollable. GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), @@ -307,6 +310,25 @@ void NativeTableGtk::SetRowData(int row_index, GtkTreeIter* iter) { } } +void NativeTableGtk::OnCursorChanged(GtkWidget* widget) { + // Ignore the signal if no row is selected. This can occur when GTK + // first opens a window (i.e. no row is selected but the cursor is set + // to the first row). When a user clicks on a row, the row is selected, + // and then "cursor-changed" signal is emitted, hence the selection + // count will be 1 here. + if (gtk_tree_selection_count_selected_rows(tree_selection_) == 0) { + return; + } + GtkTreePath *tree_path = NULL; + gtk_tree_view_get_cursor(tree_view_, &tree_path, NULL); + if (tree_path) { + const gint* indices = gtk_tree_path_get_indices(tree_path); + CHECK(indices); + table_->SelectRow(indices[0]); + gtk_tree_path_free(tree_path); + } +} + GdkPixbuf* NativeTableGtk::GetModelIcon(int row) { SkBitmap icon = table_->model()->GetIcon(row); return gfx::GdkPixbufFromSkBitmap(&icon); diff --git a/views/controls/table/native_table_gtk.h b/views/controls/table/native_table_gtk.h index aa18f50..5078dee 100644 --- a/views/controls/table/native_table_gtk.h +++ b/views/controls/table/native_table_gtk.h @@ -1,10 +1,11 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this +// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this // source code is governed by a BSD-style license that can be found in the // LICENSE file. #ifndef VIEWS_CONTROLS_TABLE_NATIVE_TABLE_GTK_H_ #define VIEWS_CONTROLS_TABLE_NATIVE_TABLE_GTK_H_ +#include "app/gtk_signal.h" #include "app/table_model.h" #include "views/controls/native_control_gtk.h" #include "views/controls/table/native_table_wrapper.h" @@ -58,6 +59,9 @@ class NativeTableGtk : public NativeControlGtk, public NativeTableWrapper { // the data in the model at row |index|. void SetRowData(int index, GtkTreeIter* iter); + // Handles the "cursor-changed" event. + CHROMEGTK_CALLBACK_0(NativeTableGtk, void, OnCursorChanged); + // Returns the icon that should be displayed for the row at |row|. GdkPixbuf* GetModelIcon(int row); diff --git a/views/examples/table2_example.h b/views/examples/table2_example.h index 475faf6..5fa783a 100644 --- a/views/examples/table2_example.h +++ b/views/examples/table2_example.h @@ -116,7 +116,8 @@ class Table2Example // TableViewObserver implementation: virtual void OnSelectionChanged() { - PrintStatus(L"Selection changed"); + PrintStatus(L"Selection changed: %d", + table_->GetFirstSelectedRow()); } virtual void OnDoubleClick() {} |