Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: xfa/fwl/cfwl_combobox.cpp

Issue 2560873005: Cleanup CFWL_Widget code to return CFX_RectFs where appropriate (Closed)
Patch Set: Review feedback Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/cfwl_checkbox.cpp ('k') | xfa/fwl/cfwl_comboedit.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/cfwl_combobox.h" 7 #include "xfa/fwl/cfwl_combobox.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); 401 CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem);
402 m_pEdit->SetText(wsText); 402 m_pEdit->SetText(wsText);
403 m_pEdit->Update(); 403 m_pEdit->Update();
404 m_pEdit->SetSelected(); 404 m_pEdit->SetSelected();
405 } 405 }
406 406
407 void CFWL_ComboBox::Layout() { 407 void CFWL_ComboBox::Layout() {
408 if (m_pWidgetMgr->IsFormDisabled()) 408 if (m_pWidgetMgr->IsFormDisabled())
409 return DisForm_Layout(); 409 return DisForm_Layout();
410 410
411 GetClientRect(m_rtClient); 411 m_rtClient = GetClientRect();
412 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( 412 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>(
413 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 413 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
414 if (!pFWidth) 414 if (!pFWidth)
415 return; 415 return;
416 416
417 FX_FLOAT fBtn = *pFWidth; 417 FX_FLOAT fBtn = *pFWidth;
418 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, 418 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn,
419 m_rtClient.height); 419 m_rtClient.height);
420 if (!IsDropDownStyle() || !m_pEdit) 420 if (!IsDropDownStyle() || !m_pEdit)
421 return; 421 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; 505 dwAdd |= FWL_STYLEEXT_LTB_LeftAlign;
506 break; 506 break;
507 } 507 }
508 } 508 }
509 m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); 509 m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask);
510 } 510 }
511 511
512 void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { 512 void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) {
513 m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0)); 513 m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0));
514 if (!IsDropDownStyle()) { 514 if (!IsDropDownStyle()) {
515 Repaint(&m_rtClient); 515 RepaintRect(m_rtClient);
516 return; 516 return;
517 } 517 }
518 518
519 CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); 519 CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
520 if (!hItem) 520 if (!hItem)
521 return; 521 return;
522 522
523 CFX_WideString wsText = m_pListBox->GetItemText(this, hItem); 523 CFX_WideString wsText = m_pListBox->GetItemText(this, hItem);
524 if (m_pEdit) { 524 if (m_pEdit) {
525 m_pEdit->SetText(wsText); 525 m_pEdit->SetText(wsText);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 if (bActivate) { 615 if (bActivate) {
616 m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); 616 m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible);
617 CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); 617 CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this);
618 DispatchEvent(&postEvent); 618 DispatchEvent(&postEvent);
619 } else { 619 } else {
620 m_pListBox->SetStates(FWL_WGTSTATE_Invisible); 620 m_pListBox->SetStates(FWL_WGTSTATE_Invisible);
621 } 621 }
622 622
623 CFX_RectF rect = m_pListBox->GetWidgetRect(); 623 CFX_RectF rect = m_pListBox->GetWidgetRect();
624 rect.Inflate(2, 2); 624 rect.Inflate(2, 2);
625 Repaint(&rect); 625 RepaintRect(rect);
626 } 626 }
627 627
628 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, 628 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded,
629 uint32_t dwStylesExRemoved) { 629 uint32_t dwStylesExRemoved) {
630 if (!m_pEdit) 630 if (!m_pEdit)
631 DisForm_InitComboEdit(); 631 DisForm_InitComboEdit();
632 632
633 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); 633 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown);
634 bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); 634 bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown);
635 635
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (!m_pListBox || !DisForm_IsDropListVisible()) 710 if (!m_pListBox || !DisForm_IsDropListVisible())
711 return rect; 711 return rect;
712 712
713 CFX_RectF rtList = m_pListBox->GetWidgetRect(); 713 CFX_RectF rtList = m_pListBox->GetWidgetRect();
714 rtList.Offset(rect.left, rect.top); 714 rtList.Offset(rect.left, rect.top);
715 rect.Union(rtList); 715 rect.Union(rtList);
716 return rect; 716 return rect;
717 } 717 }
718 718
719 void CFWL_ComboBox::DisForm_Layout() { 719 void CFWL_ComboBox::DisForm_Layout() {
720 GetClientRect(m_rtClient); 720 m_rtClient = GetClientRect();
721 m_rtContent = m_rtClient; 721 m_rtContent = m_rtClient;
722 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( 722 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>(
723 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 723 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
724 if (!pFWidth) 724 if (!pFWidth)
725 return; 725 return;
726 726
727 FX_FLOAT borderWidth = 1; 727 FX_FLOAT borderWidth = 1;
728 FX_FLOAT fBtn = *pFWidth; 728 FX_FLOAT fBtn = *pFWidth;
729 if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { 729 if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) {
730 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, 730 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { 823 void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
824 if (bSet) { 824 if (bSet) {
825 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; 825 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
826 if (IsDropDownStyle() && pMsg->m_pSrcTarget != m_pListBox.get()) { 826 if (IsDropDownStyle() && pMsg->m_pSrcTarget != m_pListBox.get()) {
827 if (!m_pEdit) 827 if (!m_pEdit)
828 return; 828 return;
829 m_pEdit->SetSelected(); 829 m_pEdit->SetSelected();
830 return; 830 return;
831 } 831 }
832 832
833 Repaint(&m_rtClient); 833 RepaintRect(m_rtClient);
834 return; 834 return;
835 } 835 }
836 836
837 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; 837 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
838 if (!IsDropDownStyle() || pMsg->m_pDstTarget == m_pListBox.get()) { 838 if (!IsDropDownStyle() || pMsg->m_pDstTarget == m_pListBox.get()) {
839 Repaint(&m_rtClient); 839 RepaintRect(m_rtClient);
840 return; 840 return;
841 } 841 }
842 if (!m_pEdit) 842 if (!m_pEdit)
843 return; 843 return;
844 844
845 m_pEdit->FlagFocus(false); 845 m_pEdit->FlagFocus(false);
846 m_pEdit->ClearSelected(); 846 m_pEdit->ClearSelected();
847 } 847 }
848 848
849 void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) { 849 void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
850 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) 850 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
851 return; 851 return;
852 852
853 CFX_RectF& rtBtn = IsDropDownStyle() ? m_rtBtn : m_rtClient; 853 CFX_RectF& rtBtn = IsDropDownStyle() ? m_rtBtn : m_rtClient;
854 if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) 854 if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
855 return; 855 return;
856 856
857 if (IsDropDownStyle() && m_pEdit) 857 if (IsDropDownStyle() && m_pEdit)
858 MatchEditText(); 858 MatchEditText();
859 859
860 m_bLButtonDown = true; 860 m_bLButtonDown = true;
861 m_iBtnState = CFWL_PartState_Pressed; 861 m_iBtnState = CFWL_PartState_Pressed;
862 Repaint(&m_rtClient); 862 RepaintRect(m_rtClient);
863 863
864 ShowDropList(true); 864 ShowDropList(true);
865 m_iBtnState = CFWL_PartState_Normal; 865 m_iBtnState = CFWL_PartState_Normal;
866 Repaint(&m_rtClient); 866 RepaintRect(m_rtClient);
867 } 867 }
868 868
869 void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { 869 void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
870 m_bLButtonDown = false; 870 m_bLButtonDown = false;
871 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) 871 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
872 m_iBtnState = CFWL_PartState_Hovered; 872 m_iBtnState = CFWL_PartState_Hovered;
873 else 873 else
874 m_iBtnState = CFWL_PartState_Normal; 874 m_iBtnState = CFWL_PartState_Normal;
875 875
876 Repaint(&m_rtBtn); 876 RepaintRect(m_rtBtn);
877 } 877 }
878 878
879 void CFWL_ComboBox::OnMouseMove(CFWL_MessageMouse* pMsg) { 879 void CFWL_ComboBox::OnMouseMove(CFWL_MessageMouse* pMsg) {
880 int32_t iOldState = m_iBtnState; 880 int32_t iOldState = m_iBtnState;
881 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { 881 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) {
882 m_iBtnState = 882 m_iBtnState =
883 m_bLButtonDown ? CFWL_PartState_Pressed : CFWL_PartState_Hovered; 883 m_bLButtonDown ? CFWL_PartState_Pressed : CFWL_PartState_Hovered;
884 } else { 884 } else {
885 m_iBtnState = CFWL_PartState_Normal; 885 m_iBtnState = CFWL_PartState_Normal;
886 } 886 }
887 if ((iOldState != m_iBtnState) && 887 if ((iOldState != m_iBtnState) &&
888 !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 888 !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) ==
889 FWL_WGTSTATE_Disabled)) { 889 FWL_WGTSTATE_Disabled)) {
890 Repaint(&m_rtBtn); 890 RepaintRect(m_rtBtn);
891 } 891 }
892 } 892 }
893 893
894 void CFWL_ComboBox::OnMouseLeave(CFWL_MessageMouse* pMsg) { 894 void CFWL_ComboBox::OnMouseLeave(CFWL_MessageMouse* pMsg) {
895 if (!IsDropListVisible() && 895 if (!IsDropListVisible() &&
896 !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 896 !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) ==
897 FWL_WGTSTATE_Disabled)) { 897 FWL_WGTSTATE_Disabled)) {
898 m_iBtnState = CFWL_PartState_Normal; 898 m_iBtnState = CFWL_PartState_Normal;
899 Repaint(&m_rtBtn); 899 RepaintRect(m_rtBtn);
900 } 900 }
901 } 901 }
902 902
903 void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) { 903 void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) {
904 uint32_t dwKeyCode = pMsg->m_dwKeyCode; 904 uint32_t dwKeyCode = pMsg->m_dwKeyCode;
905 if (dwKeyCode == FWL_VKEY_Tab) 905 if (dwKeyCode == FWL_VKEY_Tab)
906 return; 906 return;
907 if (pMsg->m_pDstTarget == this) 907 if (pMsg->m_pDstTarget == this)
908 DoSubCtrlKey(pMsg); 908 DoSubCtrlKey(pMsg);
909 } 909 }
(...skipping 26 matching lines...) Expand all
936 return; 936 return;
937 if (bUp) 937 if (bUp)
938 iCurSel--; 938 iCurSel--;
939 else 939 else
940 iCurSel++; 940 iCurSel++;
941 } 941 }
942 m_iCurSel = iCurSel; 942 m_iCurSel = iCurSel;
943 if (bDropDown && m_pEdit) 943 if (bDropDown && m_pEdit)
944 SyncEditText(m_iCurSel); 944 SyncEditText(m_iCurSel);
945 else 945 else
946 Repaint(&m_rtClient); 946 RepaintRect(m_rtClient);
947 return; 947 return;
948 } 948 }
949 949
950 if (IsDropDownStyle()) 950 if (IsDropDownStyle())
951 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); 951 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
952 } 952 }
953 953
954 void CFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { 954 void CFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) {
955 if (!pMessage) 955 if (!pMessage)
956 return; 956 return;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 else 1069 else
1070 iCurSel++; 1070 iCurSel++;
1071 } 1071 }
1072 m_iCurSel = iCurSel; 1072 m_iCurSel = iCurSel;
1073 SyncEditText(m_iCurSel); 1073 SyncEditText(m_iCurSel);
1074 return; 1074 return;
1075 } 1075 }
1076 if (m_pEdit) 1076 if (m_pEdit)
1077 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); 1077 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
1078 } 1078 }
OLDNEW
« no previous file with comments | « xfa/fwl/cfwl_checkbox.cpp ('k') | xfa/fwl/cfwl_comboedit.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698