OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/table/table_view_win.h" | 5 #include "ui/views/controls/table/table_view_win.h" |
6 | 6 |
7 #include <commctrl.h> | 7 #include <commctrl.h> |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 LPARAM l_param) { | 510 LPARAM l_param) { |
511 TableView* table_view = reinterpret_cast<TableViewWrapper*>( | 511 TableView* table_view = reinterpret_cast<TableViewWrapper*>( |
512 GetWindowLongPtr(window, GWLP_USERDATA))->table_view; | 512 GetWindowLongPtr(window, GWLP_USERDATA))->table_view; |
513 | 513 |
514 // Is the mouse down on the table? | 514 // Is the mouse down on the table? |
515 static bool in_mouse_down = false; | 515 static bool in_mouse_down = false; |
516 // Should we select on mouse up? | 516 // Should we select on mouse up? |
517 static bool select_on_mouse_up = false; | 517 static bool select_on_mouse_up = false; |
518 | 518 |
519 // If the mouse is down, this is the location of the mouse down message. | 519 // If the mouse is down, this is the location of the mouse down message. |
520 static int mouse_down_x, mouse_down_y; | 520 CR_DEFINE_STATIC_LOCAL(gfx::Point, mouse_down_pos, ()); |
521 | 521 |
522 switch (message) { | 522 switch (message) { |
523 case WM_CONTEXTMENU: { | 523 case WM_CONTEXTMENU: { |
524 // This addresses two problems seen with context menus in right to left | 524 // This addresses two problems seen with context menus in right to left |
525 // locales: | 525 // locales: |
526 // 1. The mouse coordinates in the l_param were occasionally wrong in | 526 // 1. The mouse coordinates in the l_param were occasionally wrong in |
527 // weird ways. This is most often seen when right clicking on the | 527 // weird ways. This is most often seen when right clicking on the |
528 // list-view twice in a row. | 528 // list-view twice in a row. |
529 // 2. Right clicking on the icon would show the scrollbar menu. | 529 // 2. Right clicking on the icon would show the scrollbar menu. |
530 // | 530 // |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 if ((w_param | (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) == | 640 if ((w_param | (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) == |
641 (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) { | 641 (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) { |
642 if (in_mouse_down) | 642 if (in_mouse_down) |
643 return 0; | 643 return 0; |
644 | 644 |
645 int view_index = GetViewIndexFromPoint(window, gfx::Point(l_param)); | 645 int view_index = GetViewIndexFromPoint(window, gfx::Point(l_param)); |
646 if (view_index != -1) { | 646 if (view_index != -1) { |
647 table_view->ignore_listview_change_ = true; | 647 table_view->ignore_listview_change_ = true; |
648 in_mouse_down = true; | 648 in_mouse_down = true; |
649 select_on_mouse_up = false; | 649 select_on_mouse_up = false; |
650 mouse_down_x = GET_X_LPARAM(l_param); | 650 mouse_down_pos.set_x(GET_X_LPARAM(l_param)); |
651 mouse_down_y = GET_Y_LPARAM(l_param); | 651 mouse_down_pos.set_y(GET_Y_LPARAM(l_param)); |
652 int model_index = table_view->ViewToModel(view_index); | 652 int model_index = table_view->ViewToModel(view_index); |
653 bool select = true; | 653 bool select = true; |
654 if (w_param & MK_CONTROL) { | 654 if (w_param & MK_CONTROL) { |
655 select = false; | 655 select = false; |
656 if (!table_view->IsItemSelected(model_index)) { | 656 if (!table_view->IsItemSelected(model_index)) { |
657 if (table_view->single_selection_) { | 657 if (table_view->single_selection_) { |
658 // Single selection mode and the row isn't selected, select | 658 // Single selection mode and the row isn't selected, select |
659 // only it. | 659 // only it. |
660 table_view->Select(model_index); | 660 table_view->Select(model_index); |
661 } else { | 661 } else { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 SetCapture(window); | 702 SetCapture(window); |
703 return 0; | 703 return 0; |
704 } | 704 } |
705 // else case, continue on to default handler | 705 // else case, continue on to default handler |
706 } | 706 } |
707 break; | 707 break; |
708 } | 708 } |
709 | 709 |
710 case WM_MOUSEMOVE: { | 710 case WM_MOUSEMOVE: { |
711 if (in_mouse_down) { | 711 if (in_mouse_down) { |
712 int x = GET_X_LPARAM(l_param); | 712 gfx::Point mouse_pos(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param)); |
713 int y = GET_Y_LPARAM(l_param); | 713 if (View::ExceededDragThreshold(mouse_pos - mouse_down_pos)) { |
714 if (View::ExceededDragThreshold(x - mouse_down_x, y - mouse_down_y)) { | |
715 // We're about to start drag and drop, which results in no mouse up. | 714 // We're about to start drag and drop, which results in no mouse up. |
716 // Release capture and reset state. | 715 // Release capture and reset state. |
717 ReleaseCapture(); | 716 ReleaseCapture(); |
718 in_mouse_down = false; | 717 in_mouse_down = false; |
719 | 718 |
720 NMLISTVIEW details; | 719 NMLISTVIEW details; |
721 memset(&details, 0, sizeof(details)); | 720 memset(&details, 0, sizeof(details)); |
722 details.hdr.code = LVN_BEGINDRAG; | 721 details.hdr.code = LVN_BEGINDRAG; |
723 SendMessage(::GetParent(window), WM_NOTIFY, 0, | 722 SendMessage(::GetParent(window), WM_NOTIFY, 0, |
724 reinterpret_cast<LPARAM>(&details)); | 723 reinterpret_cast<LPARAM>(&details)); |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 } | 1640 } |
1642 | 1641 |
1643 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { | 1642 void TableSelectionIterator::UpdateModelIndexFromViewIndex() { |
1644 if (view_index_ == -1) | 1643 if (view_index_ == -1) |
1645 model_index_ = -1; | 1644 model_index_ = -1; |
1646 else | 1645 else |
1647 model_index_ = table_view_->ViewToModel(view_index_); | 1646 model_index_ = table_view_->ViewToModel(view_index_); |
1648 } | 1647 } |
1649 | 1648 |
1650 } // namespace views | 1649 } // namespace views |
OLD | NEW |