OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/table_view.h" | 5 #include "views/controls/table/table_view.h" |
6 | 6 |
| 7 #include <windowsx.h> |
| 8 #include <atlbase.h> |
| 9 #include <atlapp.h> |
| 10 #include <atlmisc.h> |
| 11 |
7 #include <algorithm> | 12 #include <algorithm> |
8 #include <windowsx.h> | |
9 | 13 |
10 #include "app/gfx/chrome_canvas.h" | 14 #include "app/gfx/chrome_canvas.h" |
11 #include "app/gfx/favicon_size.h" | 15 #include "app/gfx/favicon_size.h" |
12 #include "app/gfx/icon_util.h" | 16 #include "app/gfx/icon_util.h" |
13 #include "app/l10n_util_win.h" | 17 #include "app/l10n_util_win.h" |
14 #include "app/resource_bundle.h" | 18 #include "app/resource_bundle.h" |
15 #include "base/string_util.h" | 19 #include "base/string_util.h" |
16 #include "base/win_util.h" | 20 #include "base/win_util.h" |
17 #include "skia/ext/skia_utils_win.h" | 21 #include "skia/ext/skia_utils_win.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 table_type_(table_type), | 92 table_type_(table_type), |
89 single_selection_(single_selection), | 93 single_selection_(single_selection), |
90 ignore_listview_change_(false), | 94 ignore_listview_change_(false), |
91 custom_colors_enabled_(false), | 95 custom_colors_enabled_(false), |
92 sized_columns_(false), | 96 sized_columns_(false), |
93 autosize_columns_(autosize_columns), | 97 autosize_columns_(autosize_columns), |
94 resizable_columns_(resizable_columns), | 98 resizable_columns_(resizable_columns), |
95 list_view_(NULL), | 99 list_view_(NULL), |
96 header_original_handler_(NULL), | 100 header_original_handler_(NULL), |
97 original_handler_(NULL), | 101 original_handler_(NULL), |
98 table_view_wrapper_(this), | 102 ALLOW_THIS_IN_INITIALIZER_LIST(table_view_wrapper_(this)), |
99 custom_cell_font_(NULL), | 103 custom_cell_font_(NULL), |
100 content_offset_(0) { | 104 content_offset_(0) { |
101 for (std::vector<TableColumn>::const_iterator i = columns.begin(); | 105 for (std::vector<TableColumn>::const_iterator i = columns.begin(); |
102 i != columns.end(); ++i) { | 106 i != columns.end(); ++i) { |
103 AddColumn(*i); | 107 AddColumn(*i); |
104 visible_columns_.push_back(i->id); | 108 visible_columns_.push_back(i->id); |
105 } | 109 } |
106 } | 110 } |
107 | 111 |
108 TableView::~TableView() { | 112 TableView::~TableView() { |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 // locales: | 571 // locales: |
568 // 1. The mouse coordinates in the l_param were occasionally wrong in | 572 // 1. The mouse coordinates in the l_param were occasionally wrong in |
569 // weird ways. This is most often seen when right clicking on the | 573 // weird ways. This is most often seen when right clicking on the |
570 // list-view twice in a row. | 574 // list-view twice in a row. |
571 // 2. Right clicking on the icon would show the scrollbar menu. | 575 // 2. Right clicking on the icon would show the scrollbar menu. |
572 // | 576 // |
573 // As a work around this uses the position of the cursor and ignores | 577 // As a work around this uses the position of the cursor and ignores |
574 // the position supplied in the l_param. | 578 // the position supplied in the l_param. |
575 if (table_view->UILayoutIsRightToLeft() && | 579 if (table_view->UILayoutIsRightToLeft() && |
576 (GET_X_LPARAM(l_param) != -1 || GET_Y_LPARAM(l_param) != -1)) { | 580 (GET_X_LPARAM(l_param) != -1 || GET_Y_LPARAM(l_param) != -1)) { |
577 CPoint screen_point; | 581 WTL::CPoint screen_point; |
578 GetCursorPos(&screen_point); | 582 GetCursorPos(&screen_point); |
579 CPoint table_point = screen_point; | 583 WTL::CPoint table_point = screen_point; |
580 CRect client_rect; | 584 WTL::CRect client_rect; |
581 if (ScreenToClient(window, &table_point) && | 585 if (ScreenToClient(window, &table_point) && |
582 GetClientRect(window, &client_rect) && | 586 GetClientRect(window, &client_rect) && |
583 client_rect.PtInRect(table_point)) { | 587 client_rect.PtInRect(table_point)) { |
584 // The point is over the client area of the table, handle it ourself. | 588 // The point is over the client area of the table, handle it ourself. |
585 // But first select the row if it isn't already selected. | 589 // But first select the row if it isn't already selected. |
586 LVHITTESTINFO hit_info = {0}; | 590 LVHITTESTINFO hit_info = {0}; |
587 hit_info.pt.x = table_point.x; | 591 hit_info.pt.x = table_point.x; |
588 hit_info.pt.y = table_point.y; | 592 hit_info.pt.y = table_point.y; |
589 int view_index = ListView_HitTest(window, &hit_info); | 593 int view_index = ListView_HitTest(window, &hit_info); |
590 if (view_index != -1) { | 594 if (view_index != -1) { |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 // We get notifications for empty items, just ignore them. | 1228 // We get notifications for empty items, just ignore them. |
1225 if (view_index >= model_->RowCount()) | 1229 if (view_index >= model_->RowCount()) |
1226 return CDRF_DODEFAULT; | 1230 return CDRF_DODEFAULT; |
1227 int model_index = view_to_model(view_index); | 1231 int model_index = view_to_model(view_index); |
1228 LRESULT r = CDRF_DODEFAULT; | 1232 LRESULT r = CDRF_DODEFAULT; |
1229 // First let's take care of painting the right icon. | 1233 // First let's take care of painting the right icon. |
1230 if (table_type_ == ICON_AND_TEXT) { | 1234 if (table_type_ == ICON_AND_TEXT) { |
1231 SkBitmap image = model_->GetIcon(model_index); | 1235 SkBitmap image = model_->GetIcon(model_index); |
1232 if (!image.isNull()) { | 1236 if (!image.isNull()) { |
1233 // Get the rect that holds the icon. | 1237 // Get the rect that holds the icon. |
1234 CRect icon_rect, client_rect; | 1238 WTL::CRect icon_rect, client_rect; |
1235 if (ListView_GetItemRect(list_view_, view_index, &icon_rect, | 1239 if (ListView_GetItemRect(list_view_, view_index, &icon_rect, |
1236 LVIR_ICON) && | 1240 LVIR_ICON) && |
1237 GetClientRect(list_view_, &client_rect)) { | 1241 GetClientRect(list_view_, &client_rect)) { |
1238 CRect intersection; | 1242 WTL::CRect intersection; |
1239 // Client rect includes the header but we need to make sure we don't | 1243 // Client rect includes the header but we need to make sure we don't |
1240 // paint into it. | 1244 // paint into it. |
1241 client_rect.top += content_offset_; | 1245 client_rect.top += content_offset_; |
1242 // Make sure the region need to paint is visible. | 1246 // Make sure the region need to paint is visible. |
1243 if (intersection.IntersectRect(&icon_rect, &client_rect)) { | 1247 if (intersection.IntersectRect(&icon_rect, &client_rect)) { |
1244 ChromeCanvas canvas(icon_rect.Width(), icon_rect.Height(), false); | 1248 ChromeCanvas canvas(icon_rect.Width(), icon_rect.Height(), false); |
1245 | 1249 |
1246 // It seems the state in nmcd.uItemState is not correct. | 1250 // It seems the state in nmcd.uItemState is not correct. |
1247 // We'll retrieve it explicitly. | 1251 // We'll retrieve it explicitly. |
1248 int selected = ListView_GetItemState( | 1252 int selected = ListView_GetItemState( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 canvas.getTopPlatformDevice().drawToHDC(draw_info->nmcd.hdc, | 1284 canvas.getTopPlatformDevice().drawToHDC(draw_info->nmcd.hdc, |
1281 intersection.left, | 1285 intersection.left, |
1282 intersection.top, | 1286 intersection.top, |
1283 &to_draw); | 1287 &to_draw); |
1284 r = CDRF_SKIPDEFAULT; | 1288 r = CDRF_SKIPDEFAULT; |
1285 } | 1289 } |
1286 } | 1290 } |
1287 } | 1291 } |
1288 } | 1292 } |
1289 if (ImplementPostPaint()) { | 1293 if (ImplementPostPaint()) { |
1290 CRect cell_rect; | 1294 WTL::CRect cell_rect; |
1291 if (ListView_GetItemRect(list_view_, view_index, &cell_rect, | 1295 if (ListView_GetItemRect(list_view_, view_index, &cell_rect, |
1292 LVIR_BOUNDS)) { | 1296 LVIR_BOUNDS)) { |
1293 PostPaint(model_index, 0, false, cell_rect, draw_info->nmcd.hdc); | 1297 PostPaint(model_index, 0, false, gfx::Rect(cell_rect), |
| 1298 draw_info->nmcd.hdc); |
1294 r = CDRF_SKIPDEFAULT; | 1299 r = CDRF_SKIPDEFAULT; |
1295 } | 1300 } |
1296 } | 1301 } |
1297 return r; | 1302 return r; |
1298 } | 1303 } |
1299 default: | 1304 default: |
1300 return CDRF_DODEFAULT; | 1305 return CDRF_DODEFAULT; |
1301 } | 1306 } |
1302 } | 1307 } |
1303 | 1308 |
1304 void TableView::UpdateListViewCache(int start, int length, bool add) { | 1309 void TableView::UpdateListViewCache(int start, int length, bool add) { |
1305 ignore_listview_change_ = true; | 1310 ignore_listview_change_ = true; |
1306 UpdateListViewCache0(start, length, add); | 1311 UpdateListViewCache0(start, length, add); |
1307 ignore_listview_change_ = false; | 1312 ignore_listview_change_ = false; |
1308 } | 1313 } |
1309 | 1314 |
1310 void TableView::ResetColumnSizes() { | 1315 void TableView::ResetColumnSizes() { |
1311 if (!list_view_) | 1316 if (!list_view_) |
1312 return; | 1317 return; |
1313 | 1318 |
1314 // See comment in TableColumn for what this does. | 1319 // See comment in TableColumn for what this does. |
1315 int width = this->width(); | 1320 int width = this->width(); |
1316 CRect native_bounds; | 1321 WTL::CRect native_bounds; |
1317 if (GetClientRect(GetNativeControlHWND(), &native_bounds) && | 1322 if (GetClientRect(GetNativeControlHWND(), &native_bounds) && |
1318 native_bounds.Width() > 0) { | 1323 native_bounds.Width() > 0) { |
1319 // Prefer the bounds of the window over our bounds, which may be different. | 1324 // Prefer the bounds of the window over our bounds, which may be different. |
1320 width = native_bounds.Width(); | 1325 width = native_bounds.Width(); |
1321 } | 1326 } |
1322 | 1327 |
1323 float percent = 0; | 1328 float percent = 0; |
1324 int fixed_width = 0; | 1329 int fixed_width = 0; |
1325 int autosize_width = 0; | 1330 int autosize_width = 0; |
1326 | 1331 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 if (!list_view_) | 1522 if (!list_view_) |
1518 return; | 1523 return; |
1519 | 1524 |
1520 HWND header = ListView_GetHeader(list_view_); | 1525 HWND header = ListView_GetHeader(list_view_); |
1521 if (!header) | 1526 if (!header) |
1522 return; | 1527 return; |
1523 | 1528 |
1524 POINT origin = {0, 0}; | 1529 POINT origin = {0, 0}; |
1525 MapWindowPoints(header, list_view_, &origin, 1); | 1530 MapWindowPoints(header, list_view_, &origin, 1); |
1526 | 1531 |
1527 CRect header_bounds; | 1532 WTL::CRect header_bounds; |
1528 GetWindowRect(header, &header_bounds); | 1533 GetWindowRect(header, &header_bounds); |
1529 | 1534 |
1530 content_offset_ = origin.y + header_bounds.Height(); | 1535 content_offset_ = origin.y + header_bounds.Height(); |
1531 } | 1536 } |
1532 | 1537 |
1533 // | 1538 // |
1534 // TableSelectionIterator | 1539 // TableSelectionIterator |
1535 // | 1540 // |
1536 TableSelectionIterator::TableSelectionIterator(TableView* view, | 1541 TableSelectionIterator::TableSelectionIterator(TableView* view, |
1537 int view_index) | 1542 int view_index) |
(...skipping 28 matching lines...) Expand all Loading... |
1566 } | 1571 } |
1567 | 1572 |
1568 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { | 1573 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { |
1569 if (view_index_ == -1) | 1574 if (view_index_ == -1) |
1570 model_index_ = -1; | 1575 model_index_ = -1; |
1571 else | 1576 else |
1572 model_index_ = table_view_->view_to_model(view_index_); | 1577 model_index_ = table_view_->view_to_model(view_index_); |
1573 } | 1578 } |
1574 | 1579 |
1575 } // namespace views | 1580 } // namespace views |
OLD | NEW |