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

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

Issue 2557103002: Cleanup FWL default values part II. (Closed)
Patch Set: Rebase to master 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/core/cfwl_listbox.h ('k') | xfa/fwl/core/cfwl_message.h » ('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/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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 CFWL_ListItem* pItem) { 1096 CFWL_ListItem* pItem) {
1087 return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState; 1097 return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState;
1088 } 1098 }
1089 1099
1090 void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget, 1100 void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget,
1091 CFWL_ListItem* pItem, 1101 CFWL_ListItem* pItem,
1092 uint32_t dwCheckState) { 1102 uint32_t dwCheckState) {
1093 static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState; 1103 static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState;
1094 } 1104 }
1095 1105
1096 CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, 1106 CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd) {
1097 bool bSelect) {
1098 auto pItem = pdfium::MakeUnique<CFWL_ListItem>(); 1107 auto pItem = pdfium::MakeUnique<CFWL_ListItem>();
1099 pItem->m_dwStates = 0; 1108 pItem->m_dwStates = 0;
1100 pItem->m_wsText = wsAdd; 1109 pItem->m_wsText = wsAdd;
1101 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; 1110 pItem->m_dwStates = 0;
1102 m_ItemArray.push_back(std::move(pItem)); 1111 m_ItemArray.push_back(std::move(pItem));
1103 return m_ItemArray.back().get(); 1112 return m_ItemArray.back().get();
1104 } 1113 }
1105 1114
1106 bool CFWL_ListBox::RemoveAt(int32_t iIndex) { 1115 bool CFWL_ListBox::RemoveAt(int32_t iIndex) {
1107 if (iIndex < 0 || static_cast<size_t>(iIndex) >= m_ItemArray.size()) 1116 if (iIndex < 0 || static_cast<size_t>(iIndex) >= m_ItemArray.size())
1108 return false; 1117 return false;
1109 1118
1110 m_ItemArray.erase(m_ItemArray.begin() + iIndex); 1119 m_ItemArray.erase(m_ItemArray.begin() + iIndex);
1111 return true; 1120 return true;
(...skipping 18 matching lines...) Expand all
1130 void CFWL_ListBox::DeleteAll() { 1139 void CFWL_ListBox::DeleteAll() {
1131 m_ItemArray.clear(); 1140 m_ItemArray.clear();
1132 } 1141 }
1133 1142
1134 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { 1143 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) {
1135 if (!pItem) 1144 if (!pItem)
1136 return 0; 1145 return 0;
1137 return pItem->m_dwStates | pItem->m_dwCheckState; 1146 return pItem->m_dwStates | pItem->m_dwCheckState;
1138 } 1147 }
1139 1148
OLDNEW
« no previous file with comments | « xfa/fwl/core/cfwl_listbox.h ('k') | xfa/fwl/core/cfwl_message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698