| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_win.h" | 5 #include "views/controls/table/native_table_win.h" |
| 6 | 6 |
| 7 #include <commctrl.h> | 7 #include <commctrl.h> |
| 8 #include <windowsx.h> | 8 #include <windowsx.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "skia/ext/skia_utils_win.h" | 11 #include "skia/ext/skia_utils_win.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/l10n/l10n_util_win.h" | 13 #include "ui/base/l10n/l10n_util_win.h" |
| 14 #include "ui/base/models/table_model.h" | 14 #include "ui/base/models/table_model.h" |
| 15 #include "ui/base/win/hwnd_util.h" | 15 #include "ui/base/win/hwnd_util.h" |
| 16 #include "ui/gfx/canvas_skia.h" | 16 #include "ui/gfx/canvas_skia.h" |
| 17 #include "ui/gfx/favicon_size.h" | 17 #include "ui/gfx/favicon_size.h" |
| 18 #include "ui/gfx/icon_util.h" | 18 #include "ui/gfx/icon_util.h" |
| 19 #include "views/controls/table/table_view2.h" | 19 #include "views/controls/table/table_view2.h" |
| 20 #include "views/controls/table/table_view_observer.h" | 20 #include "views/controls/table/table_view_observer.h" |
| 21 #include "views/widget/widget.h" | 21 #include "views/widget/widget.h" |
| 22 | 22 |
| 23 using ui::TableColumn; | |
| 24 | |
| 25 namespace views { | 23 namespace views { |
| 26 | 24 |
| 27 // Added to column width to prevent truncation. | 25 // Added to column width to prevent truncation. |
| 28 const int kListViewTextPadding = 15; | 26 const int kListViewTextPadding = 15; |
| 29 // Additional column width necessary if column has icons. | 27 // Additional column width necessary if column has icons. |
| 30 const int kListViewIconWidthAndPadding = 18; | 28 const int kListViewIconWidthAndPadding = 18; |
| 31 | 29 |
| 32 // static | 30 // static |
| 33 const int NativeTableWin::kImageSize = 18; | 31 const int NativeTableWin::kImageSize = 18; |
| 34 | 32 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 | 50 |
| 53 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
| 54 // NativeTableWin, NativeTableWrapper implementation: | 52 // NativeTableWin, NativeTableWrapper implementation: |
| 55 | 53 |
| 56 int NativeTableWin::GetRowCount() const { | 54 int NativeTableWin::GetRowCount() const { |
| 57 if (!native_view()) | 55 if (!native_view()) |
| 58 return 0; | 56 return 0; |
| 59 return ListView_GetItemCount(native_view()); | 57 return ListView_GetItemCount(native_view()); |
| 60 } | 58 } |
| 61 | 59 |
| 62 void NativeTableWin::InsertColumn(const TableColumn& tc, int index) { | 60 void NativeTableWin::InsertColumn(const ui::TableColumn& tc, int index) { |
| 63 if (!native_view()) | 61 if (!native_view()) |
| 64 return; | 62 return; |
| 65 | 63 |
| 66 LVCOLUMN column = { 0 }; | 64 LVCOLUMN column = { 0 }; |
| 67 column.mask = LVCF_TEXT|LVCF_FMT; | 65 column.mask = LVCF_TEXT|LVCF_FMT; |
| 68 column.pszText = const_cast<LPWSTR>(tc.title.c_str()); | 66 column.pszText = const_cast<LPWSTR>(tc.title.c_str()); |
| 69 switch (tc.alignment) { | 67 switch (tc.alignment) { |
| 70 case TableColumn::LEFT: | 68 case ui::TableColumn::LEFT: |
| 71 column.fmt = LVCFMT_LEFT; | 69 column.fmt = LVCFMT_LEFT; |
| 72 break; | 70 break; |
| 73 case TableColumn::RIGHT: | 71 case ui::TableColumn::RIGHT: |
| 74 column.fmt = LVCFMT_RIGHT; | 72 column.fmt = LVCFMT_RIGHT; |
| 75 break; | 73 break; |
| 76 case TableColumn::CENTER: | 74 case ui::TableColumn::CENTER: |
| 77 column.fmt = LVCFMT_CENTER; | 75 column.fmt = LVCFMT_CENTER; |
| 78 break; | 76 break; |
| 79 default: | 77 default: |
| 80 NOTREACHED(); | 78 NOTREACHED(); |
| 81 } | 79 } |
| 82 if (tc.width != -1) { | 80 if (tc.width != -1) { |
| 83 column.mask |= LVCF_WIDTH; | 81 column.mask |= LVCF_WIDTH; |
| 84 column.cx = tc.width; | 82 column.cx = tc.width; |
| 85 } | 83 } |
| 86 column.mask |= LVCF_SUBITEM; | 84 column.mask |= LVCF_SUBITEM; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // Prevent clicks so columns cannot be resized. | 283 // Prevent clicks so columns cannot be resized. |
| 286 if (!table_->resizable_columns()) | 284 if (!table_->resizable_columns()) |
| 287 return true; | 285 return true; |
| 288 break; | 286 break; |
| 289 | 287 |
| 290 case NM_DBLCLK: | 288 case NM_DBLCLK: |
| 291 OnDoubleClick(); | 289 OnDoubleClick(); |
| 292 break; | 290 break; |
| 293 | 291 |
| 294 case LVN_COLUMNCLICK: { | 292 case LVN_COLUMNCLICK: { |
| 295 const TableColumn& column = table_->GetVisibleColumnAt( | 293 const ui::TableColumn& column = table_->GetVisibleColumnAt( |
| 296 reinterpret_cast<NMLISTVIEW*>(hdr)->iSubItem); | 294 reinterpret_cast<NMLISTVIEW*>(hdr)->iSubItem); |
| 297 break; | 295 break; |
| 298 } | 296 } |
| 299 | 297 |
| 300 case LVN_MARQUEEBEGIN: // We don't want the marquee selection. | 298 case LVN_MARQUEEBEGIN: // We don't want the marquee selection. |
| 301 return true; | 299 return true; |
| 302 | 300 |
| 303 case LVN_GETINFOTIP: { | 301 case LVN_GETINFOTIP: { |
| 304 // This is called when the user hovers items in column zero. | 302 // This is called when the user hovers items in column zero. |
| 305 // * If the text in this column is not fully visible, the dwFlags | 303 // * If the text in this column is not fully visible, the dwFlags |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 } | 576 } |
| 579 } | 577 } |
| 580 | 578 |
| 581 memset(&item, 0, sizeof(LVITEM)); | 579 memset(&item, 0, sizeof(LVITEM)); |
| 582 item.stateMask = 0; | 580 item.stateMask = 0; |
| 583 item.mask = LVIF_TEXT; | 581 item.mask = LVIF_TEXT; |
| 584 if (table_->type() == ICON_AND_TEXT) | 582 if (table_->type() == ICON_AND_TEXT) |
| 585 item.mask |= LVIF_IMAGE; | 583 item.mask |= LVIF_IMAGE; |
| 586 | 584 |
| 587 for (size_t j = start_column; j < table_->GetVisibleColumnCount(); ++j) { | 585 for (size_t j = start_column; j < table_->GetVisibleColumnCount(); ++j) { |
| 588 TableColumn col = table_->GetVisibleColumnAt(j); | 586 ui::TableColumn col = table_->GetVisibleColumnAt(j); |
| 589 int max_text_width = ListView_GetStringWidth(native_view(), | 587 int max_text_width = ListView_GetStringWidth(native_view(), |
| 590 col.title.c_str()); | 588 col.title.c_str()); |
| 591 for (int i = start; i < max_row; ++i) { | 589 for (int i = start; i < max_row; ++i) { |
| 592 item.iItem = i; | 590 item.iItem = i; |
| 593 item.iSubItem = j; | 591 item.iSubItem = j; |
| 594 std::wstring text = table_->model()->GetText(i, col.id); | 592 std::wstring text = table_->model()->GetText(i, col.id); |
| 595 item.pszText = const_cast<LPWSTR>(text.c_str()); | 593 item.pszText = const_cast<LPWSTR>(text.c_str()); |
| 596 item.iImage = 0; | 594 item.iImage = 0; |
| 597 ListView_SetItem(native_view(), &item); | 595 ListView_SetItem(native_view(), &item); |
| 598 | 596 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 900 |
| 903 //////////////////////////////////////////////////////////////////////////////// | 901 //////////////////////////////////////////////////////////////////////////////// |
| 904 // NativeTableWrapper, public: | 902 // NativeTableWrapper, public: |
| 905 | 903 |
| 906 // static | 904 // static |
| 907 NativeTableWrapper* NativeTableWrapper::CreateNativeWrapper(TableView2* table) { | 905 NativeTableWrapper* NativeTableWrapper::CreateNativeWrapper(TableView2* table) { |
| 908 return new NativeTableWin(table); | 906 return new NativeTableWin(table); |
| 909 } | 907 } |
| 910 | 908 |
| 911 } // namespace views | 909 } // namespace views |
| OLD | NEW |