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

Side by Side Diff: xfa/fwl/core/cfwl_listbox.cpp

Issue 2557103002: Cleanup FWL default values part II. (Closed)
Patch Set: Unused 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
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/core/cfwl_listbox.h" 7 #include "xfa/fwl/core/cfwl_listbox.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 default: { 83 default: {
84 m_iTTOAligns = FDE_TTOALIGNMENT_Center; 84 m_iTTOAligns = FDE_TTOALIGNMENT_Center;
85 break; 85 break;
86 } 86 }
87 } 87 }
88 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) 88 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading)
89 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; 89 m_dwTTOStyles |= FDE_TTOSTYLE_RTL;
90 90
91 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; 91 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine;
92 m_fScorllBarWidth = GetScrollWidth(); 92 m_fScorllBarWidth = GetScrollWidth();
93 CalcSize(); 93 CalcSize(false);
94 } 94 }
95 95
96 FWL_WidgetHit CFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { 96 FWL_WidgetHit CFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) {
97 if (IsShowScrollBar(false)) { 97 if (IsShowScrollBar(false)) {
98 CFX_RectF rect; 98 CFX_RectF rect;
99 m_pHorzScrollBar->GetWidgetRect(rect, false); 99 m_pHorzScrollBar->GetWidgetRect(rect, false);
100 if (rect.Contains(fx, fy)) 100 if (rect.Contains(fx, fy))
101 return FWL_WidgetHit::HScrollBar; 101 return FWL_WidgetHit::HScrollBar;
102 } 102 }
103 if (IsShowScrollBar(true)) { 103 if (IsShowScrollBar(true)) {
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && 615 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll &&
616 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { 616 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) {
617 bShowVertScr = (fs.y > iHeight); 617 bShowVertScr = (fs.y > iHeight);
618 } 618 }
619 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) 619 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll)
620 bShowHorzScr = (fs.x > iWidth); 620 bShowHorzScr = (fs.x > iWidth);
621 621
622 CFX_SizeF szRange; 622 CFX_SizeF szRange;
623 if (bShowVertScr) { 623 if (bShowVertScr) {
624 if (!m_pVertScrollBar) 624 if (!m_pVertScrollBar)
625 InitScrollBar(); 625 InitVerticalScrollBar();
626 626
627 CFX_RectF rtScrollBar; 627 CFX_RectF rtScrollBar;
628 rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, 628 rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top,
629 m_fScorllBarWidth, m_rtClient.height - 1); 629 m_fScorllBarWidth, m_rtClient.height - 1);
630 if (bShowHorzScr) 630 if (bShowHorzScr)
631 rtScrollBar.height -= m_fScorllBarWidth; 631 rtScrollBar.height -= m_fScorllBarWidth;
632 632
633 m_pVertScrollBar->SetWidgetRect(rtScrollBar); 633 m_pVertScrollBar->SetWidgetRect(rtScrollBar);
634 szRange.x = 0, szRange.y = fs.y - m_rtConent.height; 634 szRange.x = 0, szRange.y = fs.y - m_rtConent.height;
635 szRange.y = std::max(szRange.y, m_fItemHeight); 635 szRange.y = std::max(szRange.y, m_fItemHeight);
(...skipping 12 matching lines...) Expand all
648 m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible); 648 m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
649 } 649 }
650 m_pVertScrollBar->Update(); 650 m_pVertScrollBar->Update();
651 } else if (m_pVertScrollBar) { 651 } else if (m_pVertScrollBar) {
652 m_pVertScrollBar->SetPos(0); 652 m_pVertScrollBar->SetPos(0);
653 m_pVertScrollBar->SetTrackPos(0); 653 m_pVertScrollBar->SetTrackPos(0);
654 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible); 654 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible);
655 } 655 }
656 if (bShowHorzScr) { 656 if (bShowHorzScr) {
657 if (!m_pHorzScrollBar) 657 if (!m_pHorzScrollBar)
658 InitScrollBar(false); 658 InitHorizontalScrollBar();
659 659
660 CFX_RectF rtScrollBar; 660 CFX_RectF rtScrollBar;
661 rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, 661 rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth,
662 m_rtClient.width, m_fScorllBarWidth); 662 m_rtClient.width, m_fScorllBarWidth);
663 if (bShowVertScr) 663 if (bShowVertScr)
664 rtScrollBar.width -= m_fScorllBarWidth; 664 rtScrollBar.width -= m_fScorllBarWidth;
665 665
666 m_pHorzScrollBar->SetWidgetRect(rtScrollBar); 666 m_pHorzScrollBar->SetWidgetRect(rtScrollBar);
667 szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; 667 szRange.x = 0, szRange.y = fs.x - rtScrollBar.width;
668 m_pHorzScrollBar->SetRange(szRange.x, szRange.y); 668 m_pHorzScrollBar->SetRange(szRange.x, szRange.y);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 711
712 FX_FLOAT CFWL_ListBox::GetMaxTextWidth() { 712 FX_FLOAT CFWL_ListBox::GetMaxTextWidth() {
713 FX_FLOAT fRet = 0.0f; 713 FX_FLOAT fRet = 0.0f;
714 int32_t iCount = CountItems(this); 714 int32_t iCount = CountItems(this);
715 for (int32_t i = 0; i < iCount; i++) { 715 for (int32_t i = 0; i < iCount; i++) {
716 CFWL_ListItem* pItem = GetItem(this, i); 716 CFWL_ListItem* pItem = GetItem(this, i);
717 if (!pItem) 717 if (!pItem)
718 continue; 718 continue;
719 719
720 CFX_WideString wsText = GetItemText(this, pItem); 720 CFX_WideString wsText = GetItemText(this, pItem);
721 CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider); 721 CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider, false);
722 fRet = std::max(fRet, sz.x); 722 fRet = std::max(fRet, sz.x);
723 } 723 }
724 return fRet; 724 return fRet;
725 } 725 }
726 726
727 FX_FLOAT CFWL_ListBox::GetScrollWidth() { 727 FX_FLOAT CFWL_ListBox::GetScrollWidth() {
728 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( 728 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>(
729 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 729 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
730 if (!pfWidth) 730 if (!pfWidth)
731 return 0; 731 return 0;
732 return *pfWidth; 732 return *pfWidth;
733 } 733 }
734 734
735 FX_FLOAT CFWL_ListBox::CalcItemHeight() { 735 FX_FLOAT CFWL_ListBox::CalcItemHeight() {
736 FX_FLOAT* pfFont = 736 FX_FLOAT* pfFont =
737 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); 737 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize));
738 if (!pfFont) 738 if (!pfFont)
739 return 20; 739 return 20;
740 return *pfFont + 2 * kItemTextMargin; 740 return *pfFont + 2 * kItemTextMargin;
741 } 741 }
742 742
743 void CFWL_ListBox::InitScrollBar(bool bVert) { 743 void CFWL_ListBox::InitVerticalScrollBar() {
744 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) 744 if (m_pVertScrollBar)
745 return; 745 return;
746 746
747 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); 747 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
748 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; 748 prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
749 prop->m_dwStates = FWL_WGTSTATE_Invisible; 749 prop->m_dwStates = FWL_WGTSTATE_Invisible;
750 prop->m_pParent = this; 750 prop->m_pParent = this;
751 prop->m_pThemeProvider = m_pScrollBarTP; 751 prop->m_pThemeProvider = m_pScrollBarTP;
752 CFWL_ScrollBar* sb = new CFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); 752 m_pVertScrollBar =
753 if (bVert) 753 pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp, std::move(prop), this);
754 m_pVertScrollBar.reset(sb); 754 }
755 else 755
756 m_pHorzScrollBar.reset(sb); 756 void CFWL_ListBox::InitHorizontalScrollBar() {
757 if (m_pHorzScrollBar)
758 return;
759
760 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
761 prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
762 prop->m_dwStates = FWL_WGTSTATE_Invisible;
763 prop->m_pParent = this;
764 prop->m_pThemeProvider = m_pScrollBarTP;
765 m_pHorzScrollBar =
766 pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp, std::move(prop), this);
757 } 767 }
758 768
759 bool CFWL_ListBox::IsShowScrollBar(bool bVert) { 769 bool CFWL_ListBox::IsShowScrollBar(bool bVert) {
760 CFWL_ScrollBar* pScrollbar = 770 CFWL_ScrollBar* pScrollbar =
761 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); 771 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get();
762 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) 772 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible))
763 return false; 773 return false;
764 return !(m_pProperties->m_dwStyleExes & 774 return !(m_pProperties->m_dwStyleExes &
765 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || 775 FWL_STYLEEXT_LTB_ShowScrollBarFocus) ||
766 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); 776 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 CFWL_ListItem* pItem) { 1097 CFWL_ListItem* pItem) {
1088 return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState; 1098 return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState;
1089 } 1099 }
1090 1100
1091 void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget, 1101 void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget,
1092 CFWL_ListItem* pItem, 1102 CFWL_ListItem* pItem,
1093 uint32_t dwCheckState) { 1103 uint32_t dwCheckState) {
1094 static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState; 1104 static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState;
1095 } 1105 }
1096 1106
1097 CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, 1107 CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd) {
1098 bool bSelect) {
1099 auto pItem = pdfium::MakeUnique<CFWL_ListItem>(); 1108 auto pItem = pdfium::MakeUnique<CFWL_ListItem>();
1100 pItem->m_dwStates = 0; 1109 pItem->m_dwStates = 0;
1101 pItem->m_wsText = wsAdd; 1110 pItem->m_wsText = wsAdd;
1102 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; 1111 pItem->m_dwStates = 0;
1103 m_ItemArray.push_back(std::move(pItem)); 1112 m_ItemArray.push_back(std::move(pItem));
1104 return m_ItemArray.back().get(); 1113 return m_ItemArray.back().get();
1105 } 1114 }
1106 1115
1107 bool CFWL_ListBox::RemoveAt(int32_t iIndex) { 1116 bool CFWL_ListBox::RemoveAt(int32_t iIndex) {
1108 if (iIndex < 0 || static_cast<size_t>(iIndex) >= m_ItemArray.size()) 1117 if (iIndex < 0 || static_cast<size_t>(iIndex) >= m_ItemArray.size())
1109 return false; 1118 return false;
1110 1119
1111 m_ItemArray.erase(m_ItemArray.begin() + iIndex); 1120 m_ItemArray.erase(m_ItemArray.begin() + iIndex);
1112 return true; 1121 return true;
(...skipping 18 matching lines...) Expand all
1131 void CFWL_ListBox::DeleteAll() { 1140 void CFWL_ListBox::DeleteAll() {
1132 m_ItemArray.clear(); 1141 m_ItemArray.clear();
1133 } 1142 }
1134 1143
1135 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { 1144 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) {
1136 if (!pItem) 1145 if (!pItem)
1137 return 0; 1146 return 0;
1138 return pItem->m_dwStates | pItem->m_dwCheckState; 1147 return pItem->m_dwStates | pItem->m_dwCheckState;
1139 } 1148 }
1140 1149
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698