OLD | NEW |
---|---|
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/ifwl_listbox.h" | 7 #include "xfa/fwl/core/ifwl_listbox.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fde/tto/fde_textout.h" | 10 #include "xfa/fde/tto/fde_textout.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 m_rtStatic.Reset(); | 36 m_rtStatic.Reset(); |
37 } | 37 } |
38 | 38 |
39 IFWL_ListBox::~IFWL_ListBox() {} | 39 IFWL_ListBox::~IFWL_ListBox() {} |
40 | 40 |
41 FWL_Type IFWL_ListBox::GetClassID() const { | 41 FWL_Type IFWL_ListBox::GetClassID() const { |
42 return FWL_Type::ListBox; | 42 return FWL_Type::ListBox; |
43 } | 43 } |
44 | 44 |
45 void IFWL_ListBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 45 void IFWL_ListBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
46 if (bAutoSize) { | 46 if (!bAutoSize) { |
47 rect.Set(0, 0, 0, 0); | |
48 if (!m_pProperties->m_pThemeProvider) { | |
49 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
50 } | |
51 CFX_SizeF fs = CalcSize(true); | |
52 rect.Set(0, 0, fs.x, fs.y); | |
53 IFWL_Widget::GetWidgetRect(rect, true); | |
54 } else { | |
55 rect = m_pProperties->m_rtWidget; | 47 rect = m_pProperties->m_rtWidget; |
48 return; | |
56 } | 49 } |
50 | |
51 rect.Set(0, 0, 0, 0); | |
52 if (!m_pProperties->m_pThemeProvider) | |
53 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
54 | |
55 CFX_SizeF fs = CalcSize(true); | |
56 rect.Set(0, 0, fs.x, fs.y); | |
57 IFWL_Widget::GetWidgetRect(rect, true); | |
57 } | 58 } |
58 | 59 |
59 void IFWL_ListBox::Update() { | 60 void IFWL_ListBox::Update() { |
60 if (IsLocked()) { | 61 if (IsLocked()) |
61 return; | 62 return; |
62 } | 63 if (!m_pProperties->m_pThemeProvider) |
63 if (!m_pProperties->m_pThemeProvider) { | |
64 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 64 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
65 } | 65 |
66 m_iTTOAligns = FDE_TTOALIGNMENT_Center; | |
67 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_AlignMask) { | 66 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_AlignMask) { |
68 case FWL_STYLEEXT_LTB_LeftAlign: { | 67 case FWL_STYLEEXT_LTB_LeftAlign: { |
69 m_iTTOAligns = FDE_TTOALIGNMENT_CenterLeft; | 68 m_iTTOAligns = FDE_TTOALIGNMENT_CenterLeft; |
70 break; | 69 break; |
71 } | 70 } |
72 case FWL_STYLEEXT_LTB_RightAlign: { | 71 case FWL_STYLEEXT_LTB_RightAlign: { |
73 m_iTTOAligns = FDE_TTOALIGNMENT_CenterRight; | 72 m_iTTOAligns = FDE_TTOALIGNMENT_CenterRight; |
74 break; | 73 break; |
75 } | 74 } |
76 case FWL_STYLEEXT_LTB_CenterAlign: | 75 case FWL_STYLEEXT_LTB_CenterAlign: |
77 default: { m_iTTOAligns = FDE_TTOALIGNMENT_Center; } | 76 default: { |
77 m_iTTOAligns = FDE_TTOALIGNMENT_Center; | |
78 break; | |
79 } | |
78 } | 80 } |
79 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { | 81 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) |
80 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | 82 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; |
81 } | 83 |
82 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; | 84 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; |
83 m_fScorllBarWidth = GetScrollWidth(); | 85 m_fScorllBarWidth = GetScrollWidth(); |
84 CalcSize(); | 86 CalcSize(); |
85 } | 87 } |
86 | 88 |
87 FWL_WidgetHit IFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 89 FWL_WidgetHit IFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
88 if (IsShowScrollBar(false)) { | 90 if (IsShowScrollBar(false)) { |
89 CFX_RectF rect; | 91 CFX_RectF rect; |
90 m_pHorzScrollBar->GetWidgetRect(rect); | 92 m_pHorzScrollBar->GetWidgetRect(rect); |
91 if (rect.Contains(fx, fy)) | 93 if (rect.Contains(fx, fy)) |
92 return FWL_WidgetHit::HScrollBar; | 94 return FWL_WidgetHit::HScrollBar; |
93 } | 95 } |
94 if (IsShowScrollBar(true)) { | 96 if (IsShowScrollBar(true)) { |
95 CFX_RectF rect; | 97 CFX_RectF rect; |
96 m_pVertScrollBar->GetWidgetRect(rect); | 98 m_pVertScrollBar->GetWidgetRect(rect); |
97 if (rect.Contains(fx, fy)) | 99 if (rect.Contains(fx, fy)) |
98 return FWL_WidgetHit::VScrollBar; | 100 return FWL_WidgetHit::VScrollBar; |
99 } | 101 } |
100 if (m_rtClient.Contains(fx, fy)) | 102 if (m_rtClient.Contains(fx, fy)) |
101 return FWL_WidgetHit::Client; | 103 return FWL_WidgetHit::Client; |
102 return FWL_WidgetHit::Unknown; | 104 return FWL_WidgetHit::Unknown; |
103 } | 105 } |
104 | 106 |
105 void IFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, | 107 void IFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, |
106 const CFX_Matrix* pMatrix) { | 108 const CFX_Matrix* pMatrix) { |
107 if (!pGraphics) | 109 if (!pGraphics) |
108 return; | 110 return; |
109 if (!m_pProperties->m_pThemeProvider) | 111 if (!m_pProperties->m_pThemeProvider) |
110 return; | 112 return; |
113 | |
111 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 114 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
112 pGraphics->SaveGraphState(); | 115 pGraphics->SaveGraphState(); |
113 if (HasBorder()) { | 116 if (HasBorder()) |
114 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 117 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
115 } | 118 if (HasEdge()) |
116 if (HasEdge()) { | |
117 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 119 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
118 } | 120 |
119 CFX_RectF rtClip(m_rtConent); | 121 CFX_RectF rtClip(m_rtConent); |
120 if (IsShowScrollBar(false)) { | 122 if (IsShowScrollBar(false)) |
121 rtClip.height -= m_fScorllBarWidth; | 123 rtClip.height -= m_fScorllBarWidth; |
122 } | 124 if (IsShowScrollBar(true)) |
123 if (IsShowScrollBar(true)) { | |
124 rtClip.width -= m_fScorllBarWidth; | 125 rtClip.width -= m_fScorllBarWidth; |
125 } | 126 if (pMatrix) |
126 if (pMatrix) { | |
127 pMatrix->TransformRect(rtClip); | 127 pMatrix->TransformRect(rtClip); |
128 } | 128 |
129 pGraphics->SetClipRect(rtClip); | 129 pGraphics->SetClipRect(rtClip); |
130 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0) { | 130 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0) |
131 DrawBkground(pGraphics, pTheme, pMatrix); | 131 DrawBkground(pGraphics, pTheme, pMatrix); |
132 } | 132 |
133 DrawItems(pGraphics, pTheme, pMatrix); | 133 DrawItems(pGraphics, pTheme, pMatrix); |
134 pGraphics->RestoreGraphState(); | 134 pGraphics->RestoreGraphState(); |
135 } | 135 } |
136 | 136 |
137 void IFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | 137 void IFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { |
138 if (pThemeProvider) | 138 if (pThemeProvider) |
139 m_pProperties->m_pThemeProvider = pThemeProvider; | 139 m_pProperties->m_pThemeProvider = pThemeProvider; |
140 } | 140 } |
141 | |
141 int32_t IFWL_ListBox::CountSelItems() { | 142 int32_t IFWL_ListBox::CountSelItems() { |
142 if (!m_pProperties->m_pDataProvider) | 143 if (!m_pProperties->m_pDataProvider) |
143 return 0; | 144 return 0; |
145 | |
144 int32_t iRet = 0; | 146 int32_t iRet = 0; |
145 IFWL_ListBoxDP* pData = | 147 IFWL_ListBoxDP* pData = |
146 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 148 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
147 int32_t iCount = pData->CountItems(this); | 149 int32_t iCount = pData->CountItems(this); |
148 for (int32_t i = 0; i < iCount; i++) { | 150 for (int32_t i = 0; i < iCount; i++) { |
149 CFWL_ListItem* pItem = pData->GetItem(this, i); | 151 CFWL_ListItem* pItem = pData->GetItem(this, i); |
150 if (!pItem) { | 152 if (!pItem) |
151 continue; | 153 continue; |
152 } | 154 |
153 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | 155 uint32_t dwStyle = pData->GetItemStyles(this, pItem); |
154 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { | 156 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) |
155 iRet++; | 157 iRet++; |
156 } | |
157 } | 158 } |
158 return iRet; | 159 return iRet; |
159 } | 160 } |
160 | 161 |
161 CFWL_ListItem* IFWL_ListBox::GetSelItem(int32_t nIndexSel) { | 162 CFWL_ListItem* IFWL_ListBox::GetSelItem(int32_t nIndexSel) { |
163 int32_t idx = GetSelIndex(nIndexSel); | |
164 if (idx < 0) | |
165 return nullptr; | |
166 IFWL_ListBoxDP* pData = | |
167 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | |
168 return pData->GetItem(this, idx); | |
169 } | |
170 | |
171 int32_t IFWL_ListBox::GetSelIndex(int32_t nIndex) { | |
162 if (!m_pProperties->m_pDataProvider) | 172 if (!m_pProperties->m_pDataProvider) |
163 return nullptr; | 173 return -1; |
174 | |
164 int32_t index = 0; | 175 int32_t index = 0; |
165 IFWL_ListBoxDP* pData = | 176 IFWL_ListBoxDP* pData = |
166 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 177 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
167 int32_t iCount = pData->CountItems(this); | 178 int32_t iCount = pData->CountItems(this); |
168 for (int32_t i = 0; i < iCount; i++) { | 179 for (int32_t i = 0; i < iCount; i++) { |
169 CFWL_ListItem* pItem = pData->GetItem(this, i); | 180 CFWL_ListItem* pItem = pData->GetItem(this, i); |
170 if (!pItem) { | 181 if (!pItem) |
171 return nullptr; | 182 return -1; |
172 } | 183 |
173 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | 184 uint32_t dwStyle = pData->GetItemStyles(this, pItem); |
174 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { | 185 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { |
175 if (index == nIndexSel) { | 186 if (index == nIndex) |
176 return pItem; | |
177 } else { | |
178 index++; | |
179 } | |
180 } | |
181 } | |
182 return nullptr; | |
183 } | |
184 | |
185 int32_t IFWL_ListBox::GetSelIndex(int32_t nIndex) { | |
186 if (!m_pProperties->m_pDataProvider) | |
187 return -1; | |
188 int32_t index = 0; | |
189 IFWL_ListBoxDP* pData = | |
190 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | |
191 int32_t iCount = pData->CountItems(this); | |
192 for (int32_t i = 0; i < iCount; i++) { | |
193 CFWL_ListItem* pItem = pData->GetItem(this, i); | |
194 if (!pItem) { | |
195 return -1; | |
196 } | |
197 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | |
198 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { | |
199 if (index == nIndex) { | |
200 return i; | 187 return i; |
201 } else { | 188 index++; |
202 index++; | |
203 } | |
204 } | 189 } |
205 } | 190 } |
206 return -1; | 191 return -1; |
207 } | 192 } |
208 | 193 |
209 void IFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { | 194 void IFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { |
210 if (!m_pProperties->m_pDataProvider) | 195 if (!m_pProperties->m_pDataProvider) |
211 return; | 196 return; |
212 if (!pItem) { | 197 if (!pItem) { |
213 if (bSelect) { | 198 if (bSelect) { |
214 SelectAll(); | 199 SelectAll(); |
215 } else { | 200 } else { |
216 ClearSelection(); | 201 ClearSelection(); |
217 SetFocusItem(nullptr); | 202 SetFocusItem(nullptr); |
218 } | 203 } |
219 return; | 204 return; |
220 } | 205 } |
221 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 206 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) |
222 SetSelectionDirect(pItem, bSelect); | 207 SetSelectionDirect(pItem, bSelect); |
223 } else { | 208 else |
224 SetSelection(pItem, pItem, bSelect); | 209 SetSelection(pItem, pItem, bSelect); |
225 } | |
226 } | 210 } |
227 | 211 |
228 void IFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) { | 212 void IFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) { |
229 if (!m_pProperties->m_pDataProvider) | 213 if (!m_pProperties->m_pDataProvider) |
230 return; | 214 return; |
215 | |
231 IFWL_ListBoxDP* pData = | 216 IFWL_ListBoxDP* pData = |
232 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 217 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
233 if (!pItem) | 218 if (!pItem) |
234 return; | 219 return; |
220 | |
235 pData->GetItemText(this, pItem, wsText); | 221 pData->GetItemText(this, pItem, wsText); |
236 } | 222 } |
237 | 223 |
238 CFWL_ListItem* IFWL_ListBox::GetItem(CFWL_ListItem* pItem, uint32_t dwKeyCode) { | 224 CFWL_ListItem* IFWL_ListBox::GetItem(CFWL_ListItem* pItem, uint32_t dwKeyCode) { |
239 CFWL_ListItem* hRet = nullptr; | 225 CFWL_ListItem* hRet = nullptr; |
240 switch (dwKeyCode) { | 226 switch (dwKeyCode) { |
241 case FWL_VKEY_Up: | 227 case FWL_VKEY_Up: |
242 case FWL_VKEY_Down: | 228 case FWL_VKEY_Down: |
243 case FWL_VKEY_Home: | 229 case FWL_VKEY_Home: |
244 case FWL_VKEY_End: { | 230 case FWL_VKEY_End: { |
245 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 231 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
246 const bool bDown = dwKeyCode == FWL_VKEY_Down; | 232 const bool bDown = dwKeyCode == FWL_VKEY_Down; |
247 const bool bHome = dwKeyCode == FWL_VKEY_Home; | 233 const bool bHome = dwKeyCode == FWL_VKEY_Home; |
248 IFWL_ListBoxDP* pData = | 234 IFWL_ListBoxDP* pData = |
249 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 235 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
250 int32_t iDstItem = -1; | 236 int32_t iDstItem = -1; |
251 if (bUp || bDown) { | 237 if (bUp || bDown) { |
252 int32_t index = pData->GetItemIndex(this, pItem); | 238 int32_t index = pData->GetItemIndex(this, pItem); |
253 iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; | 239 iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; |
254 } else if (bHome) { | 240 } else if (bHome) { |
255 iDstItem = 0; | 241 iDstItem = 0; |
256 } else { | 242 } else { |
257 int32_t iCount = pData->CountItems(this); | 243 int32_t iCount = pData->CountItems(this); |
258 iDstItem = iCount - 1; | 244 iDstItem = iCount - 1; |
259 } | 245 } |
260 hRet = pData->GetItem(this, iDstItem); | 246 hRet = pData->GetItem(this, iDstItem); |
261 break; | 247 break; |
262 } | 248 } |
263 default: {} | 249 default: |
250 break; | |
264 } | 251 } |
265 return hRet; | 252 return hRet; |
266 } | 253 } |
267 | 254 |
268 void IFWL_ListBox::SetSelection(CFWL_ListItem* hStart, | 255 void IFWL_ListBox::SetSelection(CFWL_ListItem* hStart, |
269 CFWL_ListItem* hEnd, | 256 CFWL_ListItem* hEnd, |
270 bool bSelected) { | 257 bool bSelected) { |
271 IFWL_ListBoxDP* pData = | 258 IFWL_ListBoxDP* pData = |
272 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 259 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
273 int32_t iStart = pData->GetItemIndex(this, hStart); | 260 int32_t iStart = pData->GetItemIndex(this, hStart); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 uint32_t dwState = pData->GetItemStyles(this, pItem); | 303 uint32_t dwState = pData->GetItemStyles(this, pItem); |
317 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) | 304 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) |
318 continue; | 305 continue; |
319 SetSelectionDirect(pItem, false); | 306 SetSelectionDirect(pItem, false); |
320 if (!bMulti) | 307 if (!bMulti) |
321 return; | 308 return; |
322 } | 309 } |
323 } | 310 } |
324 | 311 |
325 void IFWL_ListBox::SelectAll() { | 312 void IFWL_ListBox::SelectAll() { |
326 bool bMulti = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; | 313 if (!m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) |
Lei Zhang
2016/11/24 00:05:30
This is probably wrong because (whatever newer ver
Nico
2016/11/24 00:12:40
Nice! primiano requested this to be a warning in h
| |
327 if (!bMulti) { | |
328 return; | 314 return; |
329 } | 315 |
330 IFWL_ListBoxDP* pData = | 316 IFWL_ListBoxDP* pData = |
331 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 317 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
332 int32_t iCount = pData->CountItems(this); | 318 int32_t iCount = pData->CountItems(this); |
333 if (iCount > 0) { | 319 if (iCount <= 0) |
334 CFWL_ListItem* pItemStart = pData->GetItem(this, 0); | 320 return; |
335 CFWL_ListItem* pItemEnd = pData->GetItem(this, iCount - 1); | 321 |
336 SetSelection(pItemStart, pItemEnd, false); | 322 CFWL_ListItem* pItemStart = pData->GetItem(this, 0); |
337 } | 323 CFWL_ListItem* pItemEnd = pData->GetItem(this, iCount - 1); |
324 SetSelection(pItemStart, pItemEnd, false); | |
338 } | 325 } |
339 | 326 |
340 CFWL_ListItem* IFWL_ListBox::GetFocusedItem() { | 327 CFWL_ListItem* IFWL_ListBox::GetFocusedItem() { |
341 IFWL_ListBoxDP* pData = | 328 IFWL_ListBoxDP* pData = |
342 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 329 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
343 int32_t iCount = pData->CountItems(this); | 330 int32_t iCount = pData->CountItems(this); |
344 for (int32_t i = 0; i < iCount; i++) { | 331 for (int32_t i = 0; i < iCount; i++) { |
345 CFWL_ListItem* pItem = pData->GetItem(this, i); | 332 CFWL_ListItem* pItem = pData->GetItem(this, i); |
346 if (!pItem) | 333 if (!pItem) |
347 return nullptr; | 334 return nullptr; |
348 if (pData->GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) { | 335 if (pData->GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) |
349 return pItem; | 336 return pItem; |
350 } | |
351 } | 337 } |
352 return nullptr; | 338 return nullptr; |
353 } | 339 } |
354 | 340 |
355 void IFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { | 341 void IFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { |
356 IFWL_ListBoxDP* pData = | 342 IFWL_ListBoxDP* pData = |
357 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 343 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
358 CFWL_ListItem* hFocus = GetFocusedItem(); | 344 CFWL_ListItem* hFocus = GetFocusedItem(); |
359 if (pItem != hFocus) { | 345 if (pItem == hFocus) |
360 if (hFocus) { | 346 return; |
361 uint32_t dwStyle = pData->GetItemStyles(this, hFocus); | 347 |
362 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; | 348 if (hFocus) { |
363 pData->SetItemStyles(this, hFocus, dwStyle); | 349 uint32_t dwStyle = pData->GetItemStyles(this, hFocus); |
364 } | 350 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; |
365 if (pItem) { | 351 pData->SetItemStyles(this, hFocus, dwStyle); |
366 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | 352 } |
367 dwStyle |= FWL_ITEMSTATE_LTB_Focused; | 353 if (pItem) { |
368 pData->SetItemStyles(this, pItem, dwStyle); | 354 uint32_t dwStyle = pData->GetItemStyles(this, pItem); |
369 } | 355 dwStyle |= FWL_ITEMSTATE_LTB_Focused; |
356 pData->SetItemStyles(this, pItem, dwStyle); | |
370 } | 357 } |
371 } | 358 } |
372 | 359 |
373 CFWL_ListItem* IFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { | 360 CFWL_ListItem* IFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { |
374 fx -= m_rtConent.left, fy -= m_rtConent.top; | 361 fx -= m_rtConent.left, fy -= m_rtConent.top; |
375 FX_FLOAT fPosX = 0.0f; | 362 FX_FLOAT fPosX = 0.0f; |
376 if (m_pHorzScrollBar) { | 363 if (m_pHorzScrollBar) |
377 fPosX = m_pHorzScrollBar->GetPos(); | 364 fPosX = m_pHorzScrollBar->GetPos(); |
378 } | 365 |
379 FX_FLOAT fPosY = 0.0; | 366 FX_FLOAT fPosY = 0.0; |
380 if (m_pVertScrollBar) { | 367 if (m_pVertScrollBar) |
381 fPosY = m_pVertScrollBar->GetPos(); | 368 fPosY = m_pVertScrollBar->GetPos(); |
382 } | 369 |
383 IFWL_ListBoxDP* pData = | 370 IFWL_ListBoxDP* pData = |
384 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 371 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
385 int32_t nCount = pData->CountItems(this); | 372 int32_t nCount = pData->CountItems(this); |
386 for (int32_t i = 0; i < nCount; i++) { | 373 for (int32_t i = 0; i < nCount; i++) { |
387 CFWL_ListItem* pItem = pData->GetItem(this, i); | 374 CFWL_ListItem* pItem = pData->GetItem(this, i); |
388 if (!pItem) { | 375 if (!pItem) |
389 continue; | 376 continue; |
390 } | 377 |
391 CFX_RectF rtItem; | 378 CFX_RectF rtItem; |
392 pData->GetItemRect(this, pItem, rtItem); | 379 pData->GetItemRect(this, pItem, rtItem); |
393 rtItem.Offset(-fPosX, -fPosY); | 380 rtItem.Offset(-fPosX, -fPosY); |
394 if (rtItem.Contains(fx, fy)) { | 381 if (rtItem.Contains(fx, fy)) |
395 return pItem; | 382 return pItem; |
396 } | |
397 } | 383 } |
398 return nullptr; | 384 return nullptr; |
399 } | 385 } |
400 | 386 |
401 bool IFWL_ListBox::GetItemCheckRect(CFWL_ListItem* pItem, CFX_RectF& rtCheck) { | 387 bool IFWL_ListBox::GetItemCheckRect(CFWL_ListItem* pItem, CFX_RectF& rtCheck) { |
402 if (!m_pProperties->m_pDataProvider) | 388 if (!m_pProperties->m_pDataProvider) |
403 return false; | 389 return false; |
404 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 390 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) |
405 return false; | 391 return false; |
406 } | 392 |
407 IFWL_ListBoxDP* pData = | 393 IFWL_ListBoxDP* pData = |
408 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 394 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
409 pData->GetItemCheckRect(this, pItem, rtCheck); | 395 pData->GetItemCheckRect(this, pItem, rtCheck); |
410 return true; | 396 return true; |
411 } | 397 } |
412 | 398 |
413 bool IFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { | 399 bool IFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { |
414 if (!m_pProperties->m_pDataProvider) | 400 if (!m_pProperties->m_pDataProvider) |
415 return false; | 401 return false; |
416 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 402 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) |
417 return false; | 403 return false; |
418 } | 404 |
419 IFWL_ListBoxDP* pData = | 405 IFWL_ListBoxDP* pData = |
420 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 406 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
421 return !!(pData->GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); | 407 return !!(pData->GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); |
422 } | 408 } |
423 | 409 |
424 bool IFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { | 410 bool IFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { |
425 if (!m_pProperties->m_pDataProvider) | 411 if (!m_pProperties->m_pDataProvider) |
426 return false; | 412 return false; |
427 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 413 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) |
428 return false; | 414 return false; |
429 } | 415 |
430 IFWL_ListBoxDP* pData = | 416 IFWL_ListBoxDP* pData = |
431 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 417 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
432 pData->SetItemCheckState(this, pItem, | 418 pData->SetItemCheckState(this, pItem, |
433 bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); | 419 bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); |
434 return true; | 420 return true; |
435 } | 421 } |
436 | 422 |
437 bool IFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { | 423 bool IFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { |
438 if (!m_pVertScrollBar) | 424 if (!m_pVertScrollBar) |
439 return false; | 425 return false; |
426 | |
440 CFX_RectF rtItem; | 427 CFX_RectF rtItem; |
441 IFWL_ListBoxDP* pData = | 428 IFWL_ListBoxDP* pData = |
442 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 429 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
443 pData->GetItemRect(this, pItem, rtItem); | 430 pData->GetItemRect(this, pItem, rtItem); |
431 | |
444 bool bScroll = false; | 432 bool bScroll = false; |
445 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); | 433 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); |
446 rtItem.Offset(0, -fPosY + m_rtConent.top); | 434 rtItem.Offset(0, -fPosY + m_rtConent.top); |
447 if (rtItem.top < m_rtConent.top) { | 435 if (rtItem.top < m_rtConent.top) { |
448 fPosY += rtItem.top - m_rtConent.top; | 436 fPosY += rtItem.top - m_rtConent.top; |
449 bScroll = true; | 437 bScroll = true; |
450 } else if (rtItem.bottom() > m_rtConent.bottom()) { | 438 } else if (rtItem.bottom() > m_rtConent.bottom()) { |
451 fPosY += rtItem.bottom() - m_rtConent.bottom(); | 439 fPosY += rtItem.bottom() - m_rtConent.bottom(); |
452 bScroll = true; | 440 bScroll = true; |
453 } | 441 } |
454 if (!bScroll) { | 442 if (!bScroll) |
455 return false; | 443 return false; |
456 } | 444 |
457 m_pVertScrollBar->SetPos(fPosY); | 445 m_pVertScrollBar->SetPos(fPosY); |
458 m_pVertScrollBar->SetTrackPos(fPosY); | 446 m_pVertScrollBar->SetTrackPos(fPosY); |
459 Repaint(&m_rtClient); | 447 Repaint(&m_rtClient); |
460 return true; | 448 return true; |
461 } | 449 } |
462 | 450 |
463 void IFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, | 451 void IFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, |
464 IFWL_ThemeProvider* pTheme, | 452 IFWL_ThemeProvider* pTheme, |
465 const CFX_Matrix* pMatrix) { | 453 const CFX_Matrix* pMatrix) { |
466 if (!pGraphics) | 454 if (!pGraphics) |
467 return; | 455 return; |
468 if (!pTheme) | 456 if (!pTheme) |
469 return; | 457 return; |
458 | |
470 CFWL_ThemeBackground param; | 459 CFWL_ThemeBackground param; |
471 param.m_pWidget = this; | 460 param.m_pWidget = this; |
472 param.m_iPart = CFWL_Part::Background; | 461 param.m_iPart = CFWL_Part::Background; |
473 param.m_dwStates = 0; | 462 param.m_dwStates = 0; |
474 param.m_pGraphics = pGraphics; | 463 param.m_pGraphics = pGraphics; |
475 param.m_matrix.Concat(*pMatrix); | 464 param.m_matrix.Concat(*pMatrix); |
476 param.m_rtPart = m_rtClient; | 465 param.m_rtPart = m_rtClient; |
477 if (IsShowScrollBar(false) && IsShowScrollBar(true)) { | 466 if (IsShowScrollBar(false) && IsShowScrollBar(true)) |
478 param.m_pData = &m_rtStatic; | 467 param.m_pData = &m_rtStatic; |
479 } | 468 if (!IsEnabled()) |
480 if (!IsEnabled()) { | |
481 param.m_dwStates = CFWL_PartState_Disabled; | 469 param.m_dwStates = CFWL_PartState_Disabled; |
482 } | 470 |
483 pTheme->DrawBackground(¶m); | 471 pTheme->DrawBackground(¶m); |
484 } | 472 } |
485 | 473 |
486 void IFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, | 474 void IFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, |
487 IFWL_ThemeProvider* pTheme, | 475 IFWL_ThemeProvider* pTheme, |
488 const CFX_Matrix* pMatrix) { | 476 const CFX_Matrix* pMatrix) { |
489 FX_FLOAT fPosX = 0.0f; | 477 FX_FLOAT fPosX = 0.0f; |
490 if (m_pHorzScrollBar) { | 478 if (m_pHorzScrollBar) |
491 fPosX = m_pHorzScrollBar->GetPos(); | 479 fPosX = m_pHorzScrollBar->GetPos(); |
492 } | 480 |
493 FX_FLOAT fPosY = 0.0f; | 481 FX_FLOAT fPosY = 0.0f; |
494 if (m_pVertScrollBar) { | 482 if (m_pVertScrollBar) |
495 fPosY = m_pVertScrollBar->GetPos(); | 483 fPosY = m_pVertScrollBar->GetPos(); |
496 } | 484 |
497 CFX_RectF rtView(m_rtConent); | 485 CFX_RectF rtView(m_rtConent); |
498 if (m_pHorzScrollBar) { | 486 if (m_pHorzScrollBar) |
499 rtView.height -= m_fScorllBarWidth; | 487 rtView.height -= m_fScorllBarWidth; |
500 } | 488 if (m_pVertScrollBar) |
501 if (m_pVertScrollBar) { | |
502 rtView.width -= m_fScorllBarWidth; | 489 rtView.width -= m_fScorllBarWidth; |
503 } | 490 |
504 bool bMultiCol = | 491 bool bMultiCol = |
505 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); | 492 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); |
506 IFWL_ListBoxDP* pData = | 493 IFWL_ListBoxDP* pData = |
507 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 494 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
508 int32_t iCount = pData->CountItems(this); | 495 int32_t iCount = pData->CountItems(this); |
509 for (int32_t i = 0; i < iCount; i++) { | 496 for (int32_t i = 0; i < iCount; i++) { |
510 CFWL_ListItem* pItem = pData->GetItem(this, i); | 497 CFWL_ListItem* pItem = pData->GetItem(this, i); |
511 if (!pItem) { | 498 if (!pItem) |
512 continue; | 499 continue; |
513 } | 500 |
514 CFX_RectF rtItem; | 501 CFX_RectF rtItem; |
515 pData->GetItemRect(this, pItem, rtItem); | 502 pData->GetItemRect(this, pItem, rtItem); |
516 rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); | 503 rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); |
517 if (rtItem.bottom() < m_rtConent.top) { | 504 if (rtItem.bottom() < m_rtConent.top) |
518 continue; | 505 continue; |
519 } | 506 if (rtItem.top >= m_rtConent.bottom()) |
520 if (rtItem.top >= m_rtConent.bottom()) { | |
521 break; | 507 break; |
522 } | 508 if (bMultiCol && rtItem.left > m_rtConent.right()) |
523 if (bMultiCol && rtItem.left > m_rtConent.right()) { | |
524 break; | 509 break; |
525 } | 510 |
526 if (GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw) { | 511 if (GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw) { |
527 CFWL_EvtLtbDrawItem ev; | 512 CFWL_EvtLtbDrawItem ev; |
528 ev.m_pSrcTarget = this; | 513 ev.m_pSrcTarget = this; |
529 ev.m_pGraphics = pGraphics; | 514 ev.m_pGraphics = pGraphics; |
530 ev.m_matrix = *pMatrix; | 515 ev.m_matrix = *pMatrix; |
531 ev.m_index = i; | 516 ev.m_index = i; |
532 ev.m_rect = rtItem; | 517 ev.m_rect = rtItem; |
533 DispatchEvent(&ev); | 518 DispatchEvent(&ev); |
534 } else { | 519 } else { |
535 DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); | 520 DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); |
536 } | 521 } |
537 } | 522 } |
538 } | 523 } |
539 | 524 |
540 void IFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, | 525 void IFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, |
541 IFWL_ThemeProvider* pTheme, | 526 IFWL_ThemeProvider* pTheme, |
542 CFWL_ListItem* pItem, | 527 CFWL_ListItem* pItem, |
543 int32_t Index, | 528 int32_t Index, |
544 const CFX_RectF& rtItem, | 529 const CFX_RectF& rtItem, |
545 const CFX_Matrix* pMatrix) { | 530 const CFX_Matrix* pMatrix) { |
546 IFWL_ListBoxDP* pData = | 531 IFWL_ListBoxDP* pData = |
547 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 532 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
548 uint32_t dwItemStyles = pData->GetItemStyles(this, pItem); | 533 uint32_t dwItemStyles = pData->GetItemStyles(this, pItem); |
549 uint32_t dwPartStates = CFWL_PartState_Normal; | 534 uint32_t dwPartStates = CFWL_PartState_Normal; |
550 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | 535 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
551 dwPartStates = CFWL_PartState_Disabled; | 536 dwPartStates = CFWL_PartState_Disabled; |
552 } else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) { | 537 else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) |
553 dwPartStates = CFWL_PartState_Selected; | 538 dwPartStates = CFWL_PartState_Selected; |
554 } | 539 |
555 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && | 540 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && |
556 dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { | 541 dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { |
557 dwPartStates |= CFWL_PartState_Focused; | 542 dwPartStates |= CFWL_PartState_Focused; |
558 } | 543 } |
559 { | 544 |
545 CFWL_ThemeBackground bg_param; | |
546 bg_param.m_pWidget = this; | |
547 bg_param.m_iPart = CFWL_Part::ListItem; | |
548 bg_param.m_dwStates = dwPartStates; | |
549 bg_param.m_pGraphics = pGraphics; | |
550 bg_param.m_matrix.Concat(*pMatrix); | |
551 bg_param.m_rtPart = rtItem; | |
552 bg_param.m_bMaximize = true; | |
553 CFX_RectF rtFocus(rtItem); | |
554 bg_param.m_pData = &rtFocus; | |
555 if (m_pVertScrollBar && !m_pHorzScrollBar && | |
556 (dwPartStates & CFWL_PartState_Focused)) { | |
557 bg_param.m_rtPart.left += 1; | |
558 bg_param.m_rtPart.width -= (m_fScorllBarWidth + 1); | |
559 rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1); | |
560 } | |
561 pTheme->DrawBackground(&bg_param); | |
562 | |
563 bool bHasIcon = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Icon); | |
564 if (bHasIcon) { | |
565 CFX_RectF rtDIB; | |
566 CFX_DIBitmap* pDib = pData->GetItemIcon(this, pItem); | |
567 rtDIB.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); | |
568 if (pDib) { | |
569 CFWL_ThemeBackground param; | |
570 param.m_pWidget = this; | |
571 param.m_iPart = CFWL_Part::Icon; | |
572 param.m_pGraphics = pGraphics; | |
573 param.m_matrix.Concat(*pMatrix); | |
574 param.m_rtPart = rtDIB; | |
575 param.m_bMaximize = true; | |
576 param.m_pImage = pDib; | |
577 pTheme->DrawBackground(¶m); | |
578 } | |
579 } | |
580 | |
581 bool bHasCheck = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Check); | |
582 if (bHasCheck) { | |
583 CFX_RectF rtCheck; | |
584 rtCheck.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); | |
585 rtCheck.Deflate(2, 2, 2, 2); | |
586 pData->SetItemCheckRect(this, pItem, rtCheck); | |
560 CFWL_ThemeBackground param; | 587 CFWL_ThemeBackground param; |
561 param.m_pWidget = this; | 588 param.m_pWidget = this; |
562 param.m_iPart = CFWL_Part::ListItem; | 589 param.m_iPart = CFWL_Part::Check; |
563 param.m_dwStates = dwPartStates; | |
564 param.m_pGraphics = pGraphics; | 590 param.m_pGraphics = pGraphics; |
591 if (GetItemChecked(pItem)) | |
592 param.m_dwStates = CFWL_PartState_Checked; | |
593 else | |
594 param.m_dwStates = CFWL_PartState_Normal; | |
565 param.m_matrix.Concat(*pMatrix); | 595 param.m_matrix.Concat(*pMatrix); |
566 param.m_rtPart = rtItem; | 596 param.m_rtPart = rtCheck; |
567 param.m_bMaximize = true; | 597 param.m_bMaximize = true; |
568 CFX_RectF rtFocus(rtItem); | |
569 param.m_pData = &rtFocus; | |
570 if (m_pVertScrollBar && !m_pHorzScrollBar && | |
571 (dwPartStates & CFWL_PartState_Focused)) { | |
572 param.m_rtPart.left += 1; | |
573 param.m_rtPart.width -= (m_fScorllBarWidth + 1); | |
574 rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1); | |
575 } | |
576 pTheme->DrawBackground(¶m); | 598 pTheme->DrawBackground(¶m); |
577 } | 599 } |
578 { | 600 |
579 bool bHasIcon = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Icon); | 601 CFX_WideString wsText; |
580 if (bHasIcon) { | 602 pData->GetItemText(this, pItem, wsText); |
581 CFX_RectF rtDIB; | 603 if (wsText.GetLength() <= 0) |
582 CFX_DIBitmap* pDib = pData->GetItemIcon(this, pItem); | 604 return; |
583 rtDIB.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); | 605 |
584 if (pDib) { | 606 CFX_RectF rtText(rtItem); |
585 CFWL_ThemeBackground param; | 607 rtText.Deflate(kItemTextMargin, kItemTextMargin); |
586 param.m_pWidget = this; | 608 if (bHasIcon || bHasCheck) |
587 param.m_iPart = CFWL_Part::Icon; | 609 rtText.Deflate(rtItem.height, 0, 0, 0); |
588 param.m_pGraphics = pGraphics; | 610 |
589 param.m_matrix.Concat(*pMatrix); | 611 CFWL_ThemeText textParam; |
590 param.m_rtPart = rtDIB; | 612 textParam.m_pWidget = this; |
591 param.m_bMaximize = true; | 613 textParam.m_iPart = CFWL_Part::ListItem; |
592 param.m_pImage = pDib; | 614 textParam.m_dwStates = dwPartStates; |
593 pTheme->DrawBackground(¶m); | 615 textParam.m_pGraphics = pGraphics; |
594 } | 616 textParam.m_matrix.Concat(*pMatrix); |
595 } | 617 textParam.m_rtPart = rtText; |
596 bool bHasCheck = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Check); | 618 textParam.m_wsText = wsText; |
597 if (bHasCheck) { | 619 textParam.m_dwTTOStyles = m_dwTTOStyles; |
598 CFX_RectF rtCheck; | 620 textParam.m_iTTOAlign = m_iTTOAligns; |
599 rtCheck.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); | 621 textParam.m_bMaximize = true; |
600 rtCheck.Deflate(2, 2, 2, 2); | 622 pTheme->DrawText(&textParam); |
601 pData->SetItemCheckRect(this, pItem, rtCheck); | |
602 CFWL_ThemeBackground param; | |
603 param.m_pWidget = this; | |
604 param.m_iPart = CFWL_Part::Check; | |
605 param.m_pGraphics = pGraphics; | |
606 if (GetItemChecked(pItem)) { | |
607 param.m_dwStates = CFWL_PartState_Checked; | |
608 } else { | |
609 param.m_dwStates = CFWL_PartState_Normal; | |
610 } | |
611 param.m_matrix.Concat(*pMatrix); | |
612 param.m_rtPart = rtCheck; | |
613 param.m_bMaximize = true; | |
614 pTheme->DrawBackground(¶m); | |
615 } | |
616 CFX_WideString wsText; | |
617 pData->GetItemText(this, pItem, wsText); | |
618 if (wsText.GetLength() <= 0) { | |
619 return; | |
620 } | |
621 CFX_RectF rtText(rtItem); | |
622 rtText.Deflate(kItemTextMargin, kItemTextMargin); | |
623 if (bHasIcon || bHasCheck) { | |
624 rtText.Deflate(rtItem.height, 0, 0, 0); | |
625 } | |
626 CFWL_ThemeText textParam; | |
627 textParam.m_pWidget = this; | |
628 textParam.m_iPart = CFWL_Part::ListItem; | |
629 textParam.m_dwStates = dwPartStates; | |
630 textParam.m_pGraphics = pGraphics; | |
631 textParam.m_matrix.Concat(*pMatrix); | |
632 textParam.m_rtPart = rtText; | |
633 textParam.m_wsText = wsText; | |
634 textParam.m_dwTTOStyles = m_dwTTOStyles; | |
635 textParam.m_iTTOAlign = m_iTTOAligns; | |
636 textParam.m_bMaximize = true; | |
637 pTheme->DrawText(&textParam); | |
638 } | |
639 } | 623 } |
640 | 624 |
641 CFX_SizeF IFWL_ListBox::CalcSize(bool bAutoSize) { | 625 CFX_SizeF IFWL_ListBox::CalcSize(bool bAutoSize) { |
642 CFX_SizeF fs; | 626 CFX_SizeF fs; |
643 if (!m_pProperties->m_pThemeProvider) | 627 if (!m_pProperties->m_pThemeProvider) |
644 return fs; | 628 return fs; |
645 | 629 |
646 GetClientRect(m_rtClient); | 630 GetClientRect(m_rtClient); |
647 m_rtConent = m_rtClient; | 631 m_rtConent = m_rtClient; |
648 CFX_RectF rtUIMargin; | 632 CFX_RectF rtUIMargin; |
649 rtUIMargin.Set(0, 0, 0, 0); | 633 rtUIMargin.Set(0, 0, 0, 0); |
650 if (!m_pOuter) { | 634 if (!m_pOuter) { |
651 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( | 635 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( |
652 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); | 636 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); |
653 if (pUIMargin) { | 637 if (pUIMargin) { |
654 m_rtConent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | 638 m_rtConent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, |
655 pUIMargin->height); | 639 pUIMargin->height); |
656 } | 640 } |
657 } | 641 } |
642 | |
658 FX_FLOAT fWidth = 0; | 643 FX_FLOAT fWidth = 0; |
659 if (m_pProperties->m_pThemeProvider->IsCustomizedLayout(this)) { | 644 if (m_pProperties->m_pThemeProvider->IsCustomizedLayout(this)) { |
660 IFWL_ListBoxDP* pData = | 645 IFWL_ListBoxDP* pData = |
661 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 646 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
662 int32_t iCount = pData->CountItems(this); | 647 int32_t iCount = pData->CountItems(this); |
663 for (int32_t i = 0; i < iCount; i++) { | 648 for (int32_t i = 0; i < iCount; i++) { |
664 CFWL_ListItem* pItem = pData->GetItem(this, i); | 649 CFWL_ListItem* pItem = pData->GetItem(this, i); |
665 if (!bAutoSize) { | 650 if (!bAutoSize) { |
666 CFX_RectF rtItem; | 651 CFX_RectF rtItem; |
667 rtItem.Set(m_rtClient.left, m_rtClient.top + fs.y, 0, 0); | 652 rtItem.Set(m_rtClient.left, m_rtClient.top + fs.y, 0, 0); |
668 IFWL_ListBoxDP* pBox = | 653 IFWL_ListBoxDP* pBox = |
669 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 654 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
670 pBox->SetItemRect(this, pItem, rtItem); | 655 pBox->SetItemRect(this, pItem, rtItem); |
671 } | 656 } |
672 if (fs.x < 0) { | 657 if (fs.x < 0) { |
673 fs.x = 0; | 658 fs.x = 0; |
674 fWidth = 0; | 659 fWidth = 0; |
675 } | 660 } |
676 } | 661 } |
677 } else { | 662 } else { |
678 fWidth = GetMaxTextWidth(); | 663 fWidth = GetMaxTextWidth(); |
679 fWidth += 2 * kItemTextMargin; | 664 fWidth += 2 * kItemTextMargin; |
680 if (!bAutoSize) { | 665 if (!bAutoSize) { |
681 FX_FLOAT fActualWidth = | 666 FX_FLOAT fActualWidth = |
682 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 667 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
683 if (fWidth < fActualWidth) { | 668 fWidth = std::max(fWidth, fActualWidth); |
684 fWidth = fActualWidth; | |
685 } | |
686 } | 669 } |
670 | |
687 IFWL_ListBoxDP* pData = | 671 IFWL_ListBoxDP* pData = |
688 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 672 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
689 m_fItemHeight = CalcItemHeight(); | 673 m_fItemHeight = CalcItemHeight(); |
690 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) | 674 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) |
691 fWidth += m_fItemHeight; | 675 fWidth += m_fItemHeight; |
692 | 676 |
693 int32_t iCount = pData->CountItems(this); | 677 int32_t iCount = pData->CountItems(this); |
694 for (int32_t i = 0; i < iCount; i++) { | 678 for (int32_t i = 0; i < iCount; i++) { |
695 CFWL_ListItem* htem = pData->GetItem(this, i); | 679 CFWL_ListItem* htem = pData->GetItem(this, i); |
696 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); | 680 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); |
697 } | 681 } |
698 } | 682 } |
699 if (bAutoSize) { | 683 if (bAutoSize) |
700 return fs; | 684 return fs; |
701 } | 685 |
702 FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 686 FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
703 FX_FLOAT iHeight = m_rtClient.height; | 687 FX_FLOAT iHeight = m_rtClient.height; |
704 bool bShowVertScr = | 688 bool bShowVertScr = |
705 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && | 689 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && |
706 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); | 690 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); |
707 bool bShowHorzScr = | 691 bool bShowHorzScr = |
708 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && | 692 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && |
709 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); | 693 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); |
710 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && | 694 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && |
711 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { | 695 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { |
712 bShowVertScr = (fs.y > iHeight); | 696 bShowVertScr = (fs.y > iHeight); |
713 } | 697 } |
714 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) { | 698 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) |
715 bShowHorzScr = (fs.x > iWidth); | 699 bShowHorzScr = (fs.x > iWidth); |
716 } | 700 |
717 CFX_SizeF szRange; | 701 CFX_SizeF szRange; |
718 if (bShowVertScr) { | 702 if (bShowVertScr) { |
719 if (!m_pVertScrollBar) { | 703 if (!m_pVertScrollBar) |
720 InitScrollBar(); | 704 InitScrollBar(); |
721 } | 705 |
722 CFX_RectF rtScrollBar; | 706 CFX_RectF rtScrollBar; |
723 rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, | 707 rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, |
724 m_fScorllBarWidth, m_rtClient.height - 1); | 708 m_fScorllBarWidth, m_rtClient.height - 1); |
725 if (bShowHorzScr) { | 709 if (bShowHorzScr) |
726 rtScrollBar.height -= m_fScorllBarWidth; | 710 rtScrollBar.height -= m_fScorllBarWidth; |
727 } | 711 |
728 m_pVertScrollBar->SetWidgetRect(rtScrollBar); | 712 m_pVertScrollBar->SetWidgetRect(rtScrollBar); |
729 szRange.x = 0, szRange.y = fs.y - m_rtConent.height; | 713 szRange.x = 0, szRange.y = fs.y - m_rtConent.height; |
730 if (szRange.y < m_fItemHeight) { | 714 szRange.y = std::max(szRange.y, m_fItemHeight); |
731 szRange.y = m_fItemHeight; | 715 |
732 } | |
733 m_pVertScrollBar->SetRange(szRange.x, szRange.y); | 716 m_pVertScrollBar->SetRange(szRange.x, szRange.y); |
734 m_pVertScrollBar->SetPageSize(rtScrollBar.height * 9 / 10); | 717 m_pVertScrollBar->SetPageSize(rtScrollBar.height * 9 / 10); |
735 m_pVertScrollBar->SetStepSize(m_fItemHeight); | 718 m_pVertScrollBar->SetStepSize(m_fItemHeight); |
736 FX_FLOAT fPos = m_pVertScrollBar->GetPos(); | 719 |
737 if (fPos < 0) { | 720 FX_FLOAT fPos = |
738 fPos = 0; | 721 std::min(std::max(m_pVertScrollBar->GetPos(), 0.f), szRange.y); |
739 } | |
740 if (fPos > szRange.y) { | |
741 fPos = szRange.y; | |
742 } | |
743 m_pVertScrollBar->SetPos(fPos); | 722 m_pVertScrollBar->SetPos(fPos); |
744 m_pVertScrollBar->SetTrackPos(fPos); | 723 m_pVertScrollBar->SetTrackPos(fPos); |
745 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == | 724 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == |
746 0 || | 725 0 || |
747 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { | 726 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { |
748 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); | 727 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
749 } | 728 } |
750 m_pVertScrollBar->Update(); | 729 m_pVertScrollBar->Update(); |
751 } else if (m_pVertScrollBar) { | 730 } else if (m_pVertScrollBar) { |
752 m_pVertScrollBar->SetPos(0); | 731 m_pVertScrollBar->SetPos(0); |
753 m_pVertScrollBar->SetTrackPos(0); | 732 m_pVertScrollBar->SetTrackPos(0); |
754 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); | 733 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
755 } | 734 } |
756 if (bShowHorzScr) { | 735 if (bShowHorzScr) { |
757 if (!m_pHorzScrollBar) { | 736 if (!m_pHorzScrollBar) |
758 InitScrollBar(false); | 737 InitScrollBar(false); |
759 } | 738 |
760 CFX_RectF rtScrollBar; | 739 CFX_RectF rtScrollBar; |
761 rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, | 740 rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, |
762 m_rtClient.width, m_fScorllBarWidth); | 741 m_rtClient.width, m_fScorllBarWidth); |
763 if (bShowVertScr) { | 742 if (bShowVertScr) |
764 rtScrollBar.width -= m_fScorllBarWidth; | 743 rtScrollBar.width -= m_fScorllBarWidth; |
765 } | 744 |
766 m_pHorzScrollBar->SetWidgetRect(rtScrollBar); | 745 m_pHorzScrollBar->SetWidgetRect(rtScrollBar); |
767 szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; | 746 szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; |
768 m_pHorzScrollBar->SetRange(szRange.x, szRange.y); | 747 m_pHorzScrollBar->SetRange(szRange.x, szRange.y); |
769 m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10); | 748 m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10); |
770 m_pHorzScrollBar->SetStepSize(fWidth / 10); | 749 m_pHorzScrollBar->SetStepSize(fWidth / 10); |
771 FX_FLOAT fPos = m_pHorzScrollBar->GetPos(); | 750 |
772 if (fPos < 0) { | 751 FX_FLOAT fPos = |
773 fPos = 0; | 752 std::min(std::max(m_pHorzScrollBar->GetPos(), 0.f), szRange.y); |
774 } | |
775 if (fPos > szRange.y) { | |
776 fPos = szRange.y; | |
777 } | |
778 m_pHorzScrollBar->SetPos(fPos); | 753 m_pHorzScrollBar->SetPos(fPos); |
779 m_pHorzScrollBar->SetTrackPos(fPos); | 754 m_pHorzScrollBar->SetTrackPos(fPos); |
780 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == | 755 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == |
781 0 || | 756 0 || |
782 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { | 757 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { |
783 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); | 758 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
784 } | 759 } |
785 m_pHorzScrollBar->Update(); | 760 m_pHorzScrollBar->Update(); |
786 } else if (m_pHorzScrollBar) { | 761 } else if (m_pHorzScrollBar) { |
787 m_pHorzScrollBar->SetPos(0); | 762 m_pHorzScrollBar->SetPos(0); |
788 m_pHorzScrollBar->SetTrackPos(0); | 763 m_pHorzScrollBar->SetTrackPos(0); |
789 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); | 764 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
790 } | 765 } |
791 if (bShowVertScr && bShowHorzScr) { | 766 if (bShowVertScr && bShowHorzScr) { |
792 m_rtStatic.Set(m_rtClient.right() - m_fScorllBarWidth, | 767 m_rtStatic.Set(m_rtClient.right() - m_fScorllBarWidth, |
793 m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, | 768 m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, |
794 m_fScorllBarWidth); | 769 m_fScorllBarWidth); |
795 } | 770 } |
796 return fs; | 771 return fs; |
797 } | 772 } |
798 | 773 |
799 void IFWL_ListBox::GetItemSize(CFX_SizeF& size, | 774 void IFWL_ListBox::GetItemSize(CFX_SizeF& size, |
800 CFWL_ListItem* pItem, | 775 CFWL_ListItem* pItem, |
801 FX_FLOAT fWidth, | 776 FX_FLOAT fWidth, |
802 FX_FLOAT fItemHeight, | 777 FX_FLOAT fItemHeight, |
803 bool bAutoSize) { | 778 bool bAutoSize) { |
804 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) { | 779 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) |
805 } else { | 780 return; |
806 if (!bAutoSize) { | 781 |
807 CFX_RectF rtItem; | 782 if (!bAutoSize) { |
808 rtItem.Set(0, size.y, fWidth, fItemHeight); | 783 CFX_RectF rtItem; |
809 IFWL_ListBoxDP* pData = | 784 rtItem.Set(0, size.y, fWidth, fItemHeight); |
810 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 785 IFWL_ListBoxDP* pData = |
811 pData->SetItemRect(this, pItem, rtItem); | 786 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
812 } | 787 pData->SetItemRect(this, pItem, rtItem); |
813 size.x = fWidth; | |
814 size.y += fItemHeight; | |
815 } | 788 } |
789 size.x = fWidth; | |
790 size.y += fItemHeight; | |
816 } | 791 } |
817 | 792 |
818 FX_FLOAT IFWL_ListBox::GetMaxTextWidth() { | 793 FX_FLOAT IFWL_ListBox::GetMaxTextWidth() { |
819 FX_FLOAT fRet = 0.0f; | 794 FX_FLOAT fRet = 0.0f; |
820 IFWL_ListBoxDP* pData = | 795 IFWL_ListBoxDP* pData = |
821 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 796 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
822 int32_t iCount = pData->CountItems(this); | 797 int32_t iCount = pData->CountItems(this); |
823 for (int32_t i = 0; i < iCount; i++) { | 798 for (int32_t i = 0; i < iCount; i++) { |
824 CFWL_ListItem* pItem = pData->GetItem(this, i); | 799 CFWL_ListItem* pItem = pData->GetItem(this, i); |
825 if (!pItem) { | 800 if (!pItem) |
826 continue; | 801 continue; |
827 } | 802 |
828 CFX_WideString wsText; | 803 CFX_WideString wsText; |
829 pData->GetItemText(this, pItem, wsText); | 804 pData->GetItemText(this, pItem, wsText); |
830 CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider); | 805 CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider); |
831 if (sz.x > fRet) { | 806 fRet = std::max(fRet, sz.x); |
832 fRet = sz.x; | |
833 } | |
834 } | 807 } |
835 return fRet; | 808 return fRet; |
836 } | 809 } |
837 | 810 |
838 FX_FLOAT IFWL_ListBox::GetScrollWidth() { | 811 FX_FLOAT IFWL_ListBox::GetScrollWidth() { |
839 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 812 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
840 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 813 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
841 if (!pfWidth) | 814 if (!pfWidth) |
842 return 0; | 815 return 0; |
843 return *pfWidth; | 816 return *pfWidth; |
844 } | 817 } |
845 | 818 |
846 FX_FLOAT IFWL_ListBox::CalcItemHeight() { | 819 FX_FLOAT IFWL_ListBox::CalcItemHeight() { |
847 FX_FLOAT* pfFont = | 820 FX_FLOAT* pfFont = |
848 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); | 821 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); |
849 if (!pfFont) | 822 if (!pfFont) |
850 return 20; | 823 return 20; |
851 return *pfFont + 2 * kItemTextMargin; | 824 return *pfFont + 2 * kItemTextMargin; |
852 } | 825 } |
853 | 826 |
854 void IFWL_ListBox::InitScrollBar(bool bVert) { | 827 void IFWL_ListBox::InitScrollBar(bool bVert) { |
855 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) { | 828 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) |
856 return; | 829 return; |
857 } | 830 |
858 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 831 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
859 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; | 832 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; |
860 prop->m_dwStates = FWL_WGTSTATE_Invisible; | 833 prop->m_dwStates = FWL_WGTSTATE_Invisible; |
861 prop->m_pParent = this; | 834 prop->m_pParent = this; |
862 prop->m_pThemeProvider = m_pScrollBarTP; | 835 prop->m_pThemeProvider = m_pScrollBarTP; |
863 IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); | 836 IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); |
864 if (bVert) | 837 if (bVert) |
865 m_pVertScrollBar.reset(sb); | 838 m_pVertScrollBar.reset(sb); |
866 else | 839 else |
867 m_pHorzScrollBar.reset(sb); | 840 m_pHorzScrollBar.reset(sb); |
868 } | 841 } |
869 | 842 |
870 bool IFWL_ListBox::IsShowScrollBar(bool bVert) { | 843 bool IFWL_ListBox::IsShowScrollBar(bool bVert) { |
871 IFWL_ScrollBar* pScrollbar = | 844 IFWL_ScrollBar* pScrollbar = |
872 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); | 845 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); |
873 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) { | 846 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) |
874 return false; | 847 return false; |
875 } | |
876 return !(m_pProperties->m_dwStyleExes & | 848 return !(m_pProperties->m_dwStyleExes & |
877 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || | 849 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || |
878 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); | 850 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); |
879 } | 851 } |
880 | 852 |
881 void IFWL_ListBox::ProcessSelChanged() { | 853 void IFWL_ListBox::ProcessSelChanged() { |
882 CFWL_EvtLtbSelChanged selEvent; | 854 CFWL_EvtLtbSelChanged selEvent; |
883 selEvent.m_pSrcTarget = this; | 855 selEvent.m_pSrcTarget = this; |
884 CFX_Int32Array arrSels; | 856 CFX_Int32Array arrSels; |
885 int32_t iCount = CountSelItems(); | 857 int32_t iCount = CountSelItems(); |
886 for (int32_t i = 0; i < iCount; i++) { | 858 for (int32_t i = 0; i < iCount; i++) { |
887 CFWL_ListItem* item = GetSelItem(i); | 859 CFWL_ListItem* item = GetSelItem(i); |
888 if (!item) { | 860 if (!item) |
889 continue; | 861 continue; |
890 } | |
891 selEvent.iarraySels.Add(i); | 862 selEvent.iarraySels.Add(i); |
892 } | 863 } |
893 DispatchEvent(&selEvent); | 864 DispatchEvent(&selEvent); |
894 } | 865 } |
895 | 866 |
896 void IFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) { | 867 void IFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) { |
897 if (!pMessage) | 868 if (!pMessage) |
898 return; | 869 return; |
899 if (!IsEnabled()) | 870 if (!IsEnabled()) |
900 return; | 871 return; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1049 break; | 1020 break; |
1050 } | 1021 } |
1051 } | 1022 } |
1052 | 1023 |
1053 void IFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { | 1024 void IFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { |
1054 if (!pItem) | 1025 if (!pItem) |
1055 return; | 1026 return; |
1056 | 1027 |
1057 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 1028 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { |
1058 if (bCtrl) { | 1029 if (bCtrl) { |
1030 // Do nothing. | |
1059 } else if (bShift) { | 1031 } else if (bShift) { |
1060 if (m_hAnchor) | 1032 if (m_hAnchor) |
1061 SetSelection(m_hAnchor, pItem, true); | 1033 SetSelection(m_hAnchor, pItem, true); |
1062 else | 1034 else |
1063 SetSelectionDirect(pItem, true); | 1035 SetSelectionDirect(pItem, true); |
1064 } else { | 1036 } else { |
1065 SetSelection(pItem, pItem, true); | 1037 SetSelection(pItem, pItem, true); |
1066 m_hAnchor = pItem; | 1038 m_hAnchor = pItem; |
1067 } | 1039 } |
1068 } else { | 1040 } else { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1131 Repaint(&m_rtClient); | 1103 Repaint(&m_rtClient); |
1132 } | 1104 } |
1133 return true; | 1105 return true; |
1134 } | 1106 } |
1135 | 1107 |
1136 void IFWL_ListBox::DispatchSelChangedEv() { | 1108 void IFWL_ListBox::DispatchSelChangedEv() { |
1137 CFWL_EvtLtbSelChanged ev; | 1109 CFWL_EvtLtbSelChanged ev; |
1138 ev.m_pSrcTarget = this; | 1110 ev.m_pSrcTarget = this; |
1139 DispatchEvent(&ev); | 1111 DispatchEvent(&ev); |
1140 } | 1112 } |
OLD | NEW |