OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "views/controls/table/native_table_gtk.h" | 5 #include "views/controls/table/native_table_gtk.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 // Updates the gtk model with the actual model. | 271 // Updates the gtk model with the actual model. |
272 if (table_->model()) | 272 if (table_->model()) |
273 OnRowsAdded(0, table_->model()->RowCount()); | 273 OnRowsAdded(0, table_->model()->RowCount()); |
274 | 274 |
275 gtk_widget_show_all(native_view()); | 275 gtk_widget_show_all(native_view()); |
276 } | 276 } |
277 | 277 |
278 void NativeTableGtk::InsertTextColumn(const TableColumn& column, int index) { | 278 void NativeTableGtk::InsertTextColumn(const TableColumn& column, int index) { |
279 GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); | 279 GtkCellRenderer* renderer = gtk_cell_renderer_text_new(); |
280 gtk_tree_view_insert_column_with_attributes(tree_view_, -1, | 280 gtk_tree_view_insert_column_with_attributes(tree_view_, -1, |
281 WideToUTF8(column.title).c_str(), | 281 UTF16ToUTF8(column.title).c_str(), |
282 renderer, "text", index, NULL); | 282 renderer, "text", index, NULL); |
283 } | 283 } |
284 | 284 |
285 void NativeTableGtk::InsertIconAndTextColumn(const TableColumn& column, | 285 void NativeTableGtk::InsertIconAndTextColumn(const TableColumn& column, |
286 int index) { | 286 int index) { |
287 // If necessary we could support more than 1 icon and text column and we could | 287 // If necessary we could support more than 1 icon and text column and we could |
288 // make it so it does not have to be the 1st column. | 288 // make it so it does not have to be the 1st column. |
289 DCHECK_EQ(0, index) << "The icon and text column can only be the first column" | 289 DCHECK_EQ(0, index) << "The icon and text column can only be the first column" |
290 " at this point."; | 290 " at this point."; |
291 | 291 |
292 GtkTreeViewColumn* gtk_column = gtk_tree_view_column_new(); | 292 GtkTreeViewColumn* gtk_column = gtk_tree_view_column_new(); |
293 gtk_tree_view_column_set_title(gtk_column, WideToUTF8(column.title).c_str()); | 293 gtk_tree_view_column_set_title(gtk_column, UTF16ToUTF8(column.title).c_str()); |
294 GtkCellRenderer* renderer = gtk_cell_renderer_pixbuf_new(); | 294 GtkCellRenderer* renderer = gtk_cell_renderer_pixbuf_new(); |
295 gtk_tree_view_column_pack_start(gtk_column, renderer, FALSE); | 295 gtk_tree_view_column_pack_start(gtk_column, renderer, FALSE); |
296 // First we set the icon renderer at index 0. | 296 // First we set the icon renderer at index 0. |
297 gtk_tree_view_column_set_attributes(gtk_column, renderer, "pixbuf", 0, NULL); | 297 gtk_tree_view_column_set_attributes(gtk_column, renderer, "pixbuf", 0, NULL); |
298 | 298 |
299 renderer = gtk_cell_renderer_text_new(); | 299 renderer = gtk_cell_renderer_text_new(); |
300 gtk_tree_view_column_pack_start(gtk_column, renderer, TRUE); | 300 gtk_tree_view_column_pack_start(gtk_column, renderer, TRUE); |
301 // Then we set the text renderer at index 1. | 301 // Then we set the text renderer at index 1. |
302 gtk_tree_view_column_set_attributes(gtk_column, renderer, "text", 1, NULL); | 302 gtk_tree_view_column_set_attributes(gtk_column, renderer, "text", 1, NULL); |
303 | 303 |
304 gtk_tree_view_append_column(tree_view_, gtk_column); | 304 gtk_tree_view_append_column(tree_view_, gtk_column); |
305 } | 305 } |
306 | 306 |
307 void NativeTableGtk::SetRowData(int row_index, GtkTreeIter* iter) { | 307 void NativeTableGtk::SetRowData(int row_index, GtkTreeIter* iter) { |
308 int gtk_column_index = 0; | 308 int gtk_column_index = 0; |
309 if (table_->type() == ICON_AND_TEXT) { | 309 if (table_->type() == ICON_AND_TEXT) { |
310 GdkPixbuf* icon = GetModelIcon(row_index); | 310 GdkPixbuf* icon = GetModelIcon(row_index); |
311 gtk_list_store_set(gtk_model_, iter, 0, icon, -1); | 311 gtk_list_store_set(gtk_model_, iter, 0, icon, -1); |
312 g_object_unref(icon); | 312 g_object_unref(icon); |
313 gtk_column_index++; | 313 gtk_column_index++; |
314 } | 314 } |
315 for (size_t i = 0; i < table_->GetVisibleColumnCount(); | 315 for (size_t i = 0; i < table_->GetVisibleColumnCount(); |
316 ++i, ++gtk_column_index) { | 316 ++i, ++gtk_column_index) { |
317 std::string text = | 317 std::string text = |
318 WideToUTF8(table_->model()->GetText(row_index, | 318 UTF16ToUTF8(table_->model()->GetText(row_index, |
319 table_->GetVisibleColumnAt(i).id)); | 319 table_->GetVisibleColumnAt(i).id)); |
320 gtk_list_store_set(gtk_model_, iter, gtk_column_index, text.c_str(), -1); | 320 gtk_list_store_set(gtk_model_, iter, gtk_column_index, text.c_str(), -1); |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 void NativeTableGtk::OnCursorChanged(GtkWidget* widget) { | 324 void NativeTableGtk::OnCursorChanged(GtkWidget* widget) { |
325 // Ignore the signal if no row is selected. This can occur when GTK | 325 // Ignore the signal if no row is selected. This can occur when GTK |
326 // first opens a window (i.e. no row is selected but the cursor is set | 326 // first opens a window (i.e. no row is selected but the cursor is set |
327 // to the first row). When a user clicks on a row, the row is selected, | 327 // to the first row). When a user clicks on a row, the row is selected, |
328 // and then "cursor-changed" signal is emitted, hence the selection | 328 // and then "cursor-changed" signal is emitted, hence the selection |
329 // count will be 1 here. | 329 // count will be 1 here. |
(...skipping 14 matching lines...) Expand all Loading... |
344 SkBitmap icon = table_->model()->GetIcon(row); | 344 SkBitmap icon = table_->model()->GetIcon(row); |
345 return gfx::GdkPixbufFromSkBitmap(&icon); | 345 return gfx::GdkPixbufFromSkBitmap(&icon); |
346 } | 346 } |
347 | 347 |
348 // static | 348 // static |
349 NativeTableWrapper* NativeTableWrapper::CreateNativeWrapper(TableView2* table) { | 349 NativeTableWrapper* NativeTableWrapper::CreateNativeWrapper(TableView2* table) { |
350 return new NativeTableGtk(table); | 350 return new NativeTableGtk(table); |
351 } | 351 } |
352 | 352 |
353 } // namespace views | 353 } // namespace views |
OLD | NEW |