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/cfwl_listbox.h" | 7 #include "xfa/fwl/cfwl_listbox.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 m_pProperties->m_pThemeProvider = pThemeProvider; | 129 m_pProperties->m_pThemeProvider = pThemeProvider; |
130 } | 130 } |
131 | 131 |
132 int32_t CFWL_ListBox::CountSelItems() { | 132 int32_t CFWL_ListBox::CountSelItems() { |
133 int32_t iRet = 0; | 133 int32_t iRet = 0; |
134 int32_t iCount = CountItems(this); | 134 int32_t iCount = CountItems(this); |
135 for (int32_t i = 0; i < iCount; i++) { | 135 for (int32_t i = 0; i < iCount; i++) { |
136 CFWL_ListItem* pItem = GetItem(this, i); | 136 CFWL_ListItem* pItem = GetItem(this, i); |
137 if (!pItem) | 137 if (!pItem) |
138 continue; | 138 continue; |
139 if (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected) | 139 if (pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected) |
140 iRet++; | 140 iRet++; |
141 } | 141 } |
142 return iRet; | 142 return iRet; |
143 } | 143 } |
144 | 144 |
145 CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { | 145 CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { |
146 int32_t idx = GetSelIndex(nIndexSel); | 146 int32_t idx = GetSelIndex(nIndexSel); |
147 if (idx < 0) | 147 if (idx < 0) |
148 return nullptr; | 148 return nullptr; |
149 return GetItem(this, idx); | 149 return GetItem(this, idx); |
150 } | 150 } |
151 | 151 |
152 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { | 152 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { |
153 int32_t index = 0; | 153 int32_t index = 0; |
154 int32_t iCount = CountItems(this); | 154 int32_t iCount = CountItems(this); |
155 for (int32_t i = 0; i < iCount; i++) { | 155 for (int32_t i = 0; i < iCount; i++) { |
156 CFWL_ListItem* pItem = GetItem(this, i); | 156 CFWL_ListItem* pItem = GetItem(this, i); |
157 if (!pItem) | 157 if (!pItem) |
158 return -1; | 158 return -1; |
159 if (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected) { | 159 if (pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected) { |
160 if (index == nIndex) | 160 if (index == nIndex) |
161 return i; | 161 return i; |
162 index++; | 162 index++; |
163 } | 163 } |
164 } | 164 } |
165 return -1; | 165 return -1; |
166 } | 166 } |
167 | 167 |
168 void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { | 168 void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { |
169 if (!pItem) { | 169 if (!pItem) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 for (; iStart <= iEnd; iStart++) { | 235 for (; iStart <= iEnd; iStart++) { |
236 CFWL_ListItem* pItem = GetItem(this, iStart); | 236 CFWL_ListItem* pItem = GetItem(this, iStart); |
237 SetSelectionDirect(pItem, bSelected); | 237 SetSelectionDirect(pItem, bSelected); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { | 241 void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { |
242 if (!pItem) | 242 if (!pItem) |
243 return; | 243 return; |
244 | 244 |
245 uint32_t dwOldStyle = pItem->GetStyles(); | 245 uint32_t dwOldStyle = pItem->GetStates(); |
246 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected | 246 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected |
247 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; | 247 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; |
248 pItem->SetStyles(dwOldStyle); | 248 pItem->SetStates(dwOldStyle); |
249 } | 249 } |
250 | 250 |
251 bool CFWL_ListBox::IsMultiSelection() const { | 251 bool CFWL_ListBox::IsMultiSelection() const { |
252 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; | 252 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; |
253 } | 253 } |
254 | 254 |
255 bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { | 255 bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { |
256 if (!pItem) | 256 if (!pItem) |
257 return false; | 257 return false; |
258 return (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected) != 0; | 258 return (pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected) != 0; |
259 } | 259 } |
260 | 260 |
261 void CFWL_ListBox::ClearSelection() { | 261 void CFWL_ListBox::ClearSelection() { |
262 bool bMulti = IsMultiSelection(); | 262 bool bMulti = IsMultiSelection(); |
263 int32_t iCount = CountItems(this); | 263 int32_t iCount = CountItems(this); |
264 for (int32_t i = 0; i < iCount; i++) { | 264 for (int32_t i = 0; i < iCount; i++) { |
265 CFWL_ListItem* pItem = GetItem(this, i); | 265 CFWL_ListItem* pItem = GetItem(this, i); |
266 if (!pItem) | 266 if (!pItem) |
267 continue; | 267 continue; |
268 if (!(pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected)) | 268 if (!(pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)) |
269 continue; | 269 continue; |
270 SetSelectionDirect(pItem, false); | 270 SetSelectionDirect(pItem, false); |
271 if (!bMulti) | 271 if (!bMulti) |
272 return; | 272 return; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 void CFWL_ListBox::SelectAll() { | 276 void CFWL_ListBox::SelectAll() { |
277 if (!IsMultiSelection()) | 277 if (!IsMultiSelection()) |
278 return; | 278 return; |
279 | 279 |
280 int32_t iCount = CountItems(this); | 280 int32_t iCount = CountItems(this); |
281 if (iCount <= 0) | 281 if (iCount <= 0) |
282 return; | 282 return; |
283 | 283 |
284 CFWL_ListItem* pItemStart = GetItem(this, 0); | 284 CFWL_ListItem* pItemStart = GetItem(this, 0); |
285 CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1); | 285 CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1); |
286 SetSelection(pItemStart, pItemEnd, false); | 286 SetSelection(pItemStart, pItemEnd, false); |
287 } | 287 } |
288 | 288 |
289 CFWL_ListItem* CFWL_ListBox::GetFocusedItem() { | 289 CFWL_ListItem* CFWL_ListBox::GetFocusedItem() { |
290 int32_t iCount = CountItems(this); | 290 int32_t iCount = CountItems(this); |
291 for (int32_t i = 0; i < iCount; i++) { | 291 for (int32_t i = 0; i < iCount; i++) { |
292 CFWL_ListItem* pItem = GetItem(this, i); | 292 CFWL_ListItem* pItem = GetItem(this, i); |
293 if (!pItem) | 293 if (!pItem) |
294 return nullptr; | 294 return nullptr; |
295 if (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Focused) | 295 if (pItem->GetStates() & FWL_ITEMSTATE_LTB_Focused) |
296 return pItem; | 296 return pItem; |
297 } | 297 } |
298 return nullptr; | 298 return nullptr; |
299 } | 299 } |
300 | 300 |
301 void CFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { | 301 void CFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { |
302 CFWL_ListItem* hFocus = GetFocusedItem(); | 302 CFWL_ListItem* hFocus = GetFocusedItem(); |
303 if (pItem == hFocus) | 303 if (pItem == hFocus) |
304 return; | 304 return; |
305 | 305 |
306 if (hFocus) { | 306 if (hFocus) { |
307 uint32_t dwStyle = hFocus->GetStyles(); | 307 uint32_t dwStyle = hFocus->GetStates(); |
308 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; | 308 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; |
309 hFocus->SetStyles(dwStyle); | 309 hFocus->SetStates(dwStyle); |
310 } | 310 } |
311 if (pItem) { | 311 if (pItem) { |
312 uint32_t dwStyle = pItem->GetStyles(); | 312 uint32_t dwStyle = pItem->GetStates(); |
313 dwStyle |= FWL_ITEMSTATE_LTB_Focused; | 313 dwStyle |= FWL_ITEMSTATE_LTB_Focused; |
314 pItem->SetStyles(dwStyle); | 314 pItem->SetStates(dwStyle); |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { | 318 CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { |
319 fx -= m_rtConent.left, fy -= m_rtConent.top; | 319 fx -= m_rtConent.left, fy -= m_rtConent.top; |
320 FX_FLOAT fPosX = 0.0f; | 320 FX_FLOAT fPosX = 0.0f; |
321 if (m_pHorzScrollBar) | 321 if (m_pHorzScrollBar) |
322 fPosX = m_pHorzScrollBar->GetPos(); | 322 fPosX = m_pHorzScrollBar->GetPos(); |
323 | 323 |
324 FX_FLOAT fPosY = 0.0; | 324 FX_FLOAT fPosY = 0.0; |
325 if (m_pVertScrollBar) | 325 if (m_pVertScrollBar) |
326 fPosY = m_pVertScrollBar->GetPos(); | 326 fPosY = m_pVertScrollBar->GetPos(); |
327 | 327 |
328 int32_t nCount = CountItems(this); | 328 int32_t nCount = CountItems(this); |
329 for (int32_t i = 0; i < nCount; i++) { | 329 for (int32_t i = 0; i < nCount; i++) { |
330 CFWL_ListItem* pItem = GetItem(this, i); | 330 CFWL_ListItem* pItem = GetItem(this, i); |
331 if (!pItem) | 331 if (!pItem) |
332 continue; | 332 continue; |
333 | 333 |
334 CFX_RectF rtItem = pItem->GetRect(); | 334 CFX_RectF rtItem = pItem->GetRect(); |
335 rtItem.Offset(-fPosX, -fPosY); | 335 rtItem.Offset(-fPosX, -fPosY); |
336 if (rtItem.Contains(fx, fy)) | 336 if (rtItem.Contains(fx, fy)) |
337 return pItem; | 337 return pItem; |
338 } | 338 } |
339 return nullptr; | 339 return nullptr; |
340 } | 340 } |
341 | 341 |
342 bool CFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { | |
343 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) | |
344 return false; | |
345 return !!(pItem->GetCheckState() & FWL_ITEMSTATE_LTB_Checked); | |
346 } | |
347 | |
348 bool CFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { | |
349 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) | |
350 return false; | |
351 | |
352 pItem->SetCheckState(bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); | |
353 return true; | |
354 } | |
355 | |
356 bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { | 342 bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { |
357 if (!m_pVertScrollBar) | 343 if (!m_pVertScrollBar) |
358 return false; | 344 return false; |
359 | 345 |
360 CFX_RectF rtItem = pItem ? pItem->GetRect() : CFX_RectF(); | 346 CFX_RectF rtItem = pItem ? pItem->GetRect() : CFX_RectF(); |
361 bool bScroll = false; | 347 bool bScroll = false; |
362 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); | 348 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); |
363 rtItem.Offset(0, -fPosY + m_rtConent.top); | 349 rtItem.Offset(0, -fPosY + m_rtConent.top); |
364 if (rtItem.top < m_rtConent.top) { | 350 if (rtItem.top < m_rtConent.top) { |
365 fPosY += rtItem.top - m_rtConent.top; | 351 fPosY += rtItem.top - m_rtConent.top; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 FX_FLOAT fPosY = 0.0f; | 396 FX_FLOAT fPosY = 0.0f; |
411 if (m_pVertScrollBar) | 397 if (m_pVertScrollBar) |
412 fPosY = m_pVertScrollBar->GetPos(); | 398 fPosY = m_pVertScrollBar->GetPos(); |
413 | 399 |
414 CFX_RectF rtView(m_rtConent); | 400 CFX_RectF rtView(m_rtConent); |
415 if (m_pHorzScrollBar) | 401 if (m_pHorzScrollBar) |
416 rtView.height -= m_fScorllBarWidth; | 402 rtView.height -= m_fScorllBarWidth; |
417 if (m_pVertScrollBar) | 403 if (m_pVertScrollBar) |
418 rtView.width -= m_fScorllBarWidth; | 404 rtView.width -= m_fScorllBarWidth; |
419 | 405 |
420 bool bMultiCol = | |
421 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); | |
422 int32_t iCount = CountItems(this); | 406 int32_t iCount = CountItems(this); |
423 for (int32_t i = 0; i < iCount; i++) { | 407 for (int32_t i = 0; i < iCount; i++) { |
424 CFWL_ListItem* pItem = GetItem(this, i); | 408 CFWL_ListItem* pItem = GetItem(this, i); |
425 if (!pItem) | 409 if (!pItem) |
426 continue; | 410 continue; |
427 | 411 |
428 CFX_RectF rtItem = pItem->GetRect(); | 412 CFX_RectF rtItem = pItem->GetRect(); |
429 rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); | 413 rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); |
430 if (rtItem.bottom() < m_rtConent.top) | 414 if (rtItem.bottom() < m_rtConent.top) |
431 continue; | 415 continue; |
432 if (rtItem.top >= m_rtConent.bottom()) | 416 if (rtItem.top >= m_rtConent.bottom()) |
433 break; | 417 break; |
434 if (bMultiCol && rtItem.left > m_rtConent.right()) | 418 DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); |
435 break; | |
436 | |
437 if (!(GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw)) | |
438 DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); | |
439 } | 419 } |
440 } | 420 } |
441 | 421 |
442 void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, | 422 void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, |
443 IFWL_ThemeProvider* pTheme, | 423 IFWL_ThemeProvider* pTheme, |
444 CFWL_ListItem* pItem, | 424 CFWL_ListItem* pItem, |
445 int32_t Index, | 425 int32_t Index, |
446 const CFX_RectF& rtItem, | 426 const CFX_RectF& rtItem, |
447 const CFX_Matrix* pMatrix) { | 427 const CFX_Matrix* pMatrix) { |
448 uint32_t dwItemStyles = pItem ? pItem->GetStyles() : 0; | 428 uint32_t dwItemStyles = pItem ? pItem->GetStates() : 0; |
449 uint32_t dwPartStates = CFWL_PartState_Normal; | 429 uint32_t dwPartStates = CFWL_PartState_Normal; |
450 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 430 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
451 dwPartStates = CFWL_PartState_Disabled; | 431 dwPartStates = CFWL_PartState_Disabled; |
452 else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) | 432 else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) |
453 dwPartStates = CFWL_PartState_Selected; | 433 dwPartStates = CFWL_PartState_Selected; |
454 | 434 |
455 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && | 435 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && |
456 dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { | 436 dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { |
457 dwPartStates |= CFWL_PartState_Focused; | 437 dwPartStates |= CFWL_PartState_Focused; |
458 } | 438 } |
459 | 439 |
460 CFWL_ThemeBackground bg_param; | 440 CFWL_ThemeBackground bg_param; |
461 bg_param.m_pWidget = this; | 441 bg_param.m_pWidget = this; |
462 bg_param.m_iPart = CFWL_Part::ListItem; | 442 bg_param.m_iPart = CFWL_Part::ListItem; |
463 bg_param.m_dwStates = dwPartStates; | 443 bg_param.m_dwStates = dwPartStates; |
464 bg_param.m_pGraphics = pGraphics; | 444 bg_param.m_pGraphics = pGraphics; |
465 bg_param.m_matrix.Concat(*pMatrix); | 445 bg_param.m_matrix.Concat(*pMatrix); |
466 bg_param.m_rtPart = rtItem; | 446 bg_param.m_rtPart = rtItem; |
467 bg_param.m_bMaximize = true; | 447 bg_param.m_bMaximize = true; |
468 CFX_RectF rtFocus(rtItem); | 448 CFX_RectF rtFocus(rtItem); |
469 bg_param.m_pData = &rtFocus; | 449 bg_param.m_pData = &rtFocus; |
470 if (m_pVertScrollBar && !m_pHorzScrollBar && | 450 if (m_pVertScrollBar && !m_pHorzScrollBar && |
471 (dwPartStates & CFWL_PartState_Focused)) { | 451 (dwPartStates & CFWL_PartState_Focused)) { |
472 bg_param.m_rtPart.left += 1; | 452 bg_param.m_rtPart.left += 1; |
473 bg_param.m_rtPart.width -= (m_fScorllBarWidth + 1); | 453 bg_param.m_rtPart.width -= (m_fScorllBarWidth + 1); |
474 rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1); | 454 rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1); |
475 } | 455 } |
476 pTheme->DrawBackground(&bg_param); | 456 pTheme->DrawBackground(&bg_param); |
477 | 457 |
478 bool bHasIcon = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Icon); | |
479 if (bHasIcon) { | |
480 CFX_RectF rtDIB; | |
481 CFX_DIBitmap* pDib = pItem->GetIcon(); | |
482 rtDIB.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); | |
483 if (pDib) { | |
484 CFWL_ThemeBackground param; | |
485 param.m_pWidget = this; | |
486 param.m_iPart = CFWL_Part::Icon; | |
487 param.m_pGraphics = pGraphics; | |
488 param.m_matrix.Concat(*pMatrix); | |
489 param.m_rtPart = rtDIB; | |
490 param.m_bMaximize = true; | |
491 param.m_pImage = pDib; | |
492 pTheme->DrawBackground(¶m); | |
493 } | |
494 } | |
495 | |
496 bool bHasCheck = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Check); | |
497 if (bHasCheck) { | |
498 CFX_RectF rtCheck; | |
499 rtCheck.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); | |
500 rtCheck.Deflate(2, 2, 2, 2); | |
501 pItem->SetCheckRect(rtCheck); | |
502 | |
503 CFWL_ThemeBackground param; | |
504 param.m_pWidget = this; | |
505 param.m_iPart = CFWL_Part::Check; | |
506 param.m_pGraphics = pGraphics; | |
507 if (GetItemChecked(pItem)) | |
508 param.m_dwStates = CFWL_PartState_Checked; | |
509 else | |
510 param.m_dwStates = CFWL_PartState_Normal; | |
511 param.m_matrix.Concat(*pMatrix); | |
512 param.m_rtPart = rtCheck; | |
513 param.m_bMaximize = true; | |
514 pTheme->DrawBackground(¶m); | |
515 } | |
516 | |
517 if (!pItem) | 458 if (!pItem) |
518 return; | 459 return; |
519 | 460 |
520 CFX_WideString wsText = pItem->GetText(); | 461 CFX_WideString wsText = pItem->GetText(); |
521 if (wsText.GetLength() <= 0) | 462 if (wsText.GetLength() <= 0) |
522 return; | 463 return; |
523 | 464 |
524 CFX_RectF rtText(rtItem); | 465 CFX_RectF rtText(rtItem); |
525 rtText.Deflate(kItemTextMargin, kItemTextMargin); | 466 rtText.Deflate(kItemTextMargin, kItemTextMargin); |
526 if (bHasIcon || bHasCheck) | |
527 rtText.Deflate(rtItem.height, 0, 0, 0); | |
528 | 467 |
529 CFWL_ThemeText textParam; | 468 CFWL_ThemeText textParam; |
530 textParam.m_pWidget = this; | 469 textParam.m_pWidget = this; |
531 textParam.m_iPart = CFWL_Part::ListItem; | 470 textParam.m_iPart = CFWL_Part::ListItem; |
532 textParam.m_dwStates = dwPartStates; | 471 textParam.m_dwStates = dwPartStates; |
533 textParam.m_pGraphics = pGraphics; | 472 textParam.m_pGraphics = pGraphics; |
534 textParam.m_matrix.Concat(*pMatrix); | 473 textParam.m_matrix.Concat(*pMatrix); |
535 textParam.m_rtPart = rtText; | 474 textParam.m_rtPart = rtText; |
536 textParam.m_wsText = wsText; | 475 textParam.m_wsText = wsText; |
537 textParam.m_dwTTOStyles = m_dwTTOStyles; | 476 textParam.m_dwTTOStyles = m_dwTTOStyles; |
(...skipping 19 matching lines...) Expand all Loading... |
557 } | 496 } |
558 } | 497 } |
559 | 498 |
560 FX_FLOAT fWidth = GetMaxTextWidth(); | 499 FX_FLOAT fWidth = GetMaxTextWidth(); |
561 fWidth += 2 * kItemTextMargin; | 500 fWidth += 2 * kItemTextMargin; |
562 if (!bAutoSize) { | 501 if (!bAutoSize) { |
563 FX_FLOAT fActualWidth = | 502 FX_FLOAT fActualWidth = |
564 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 503 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
565 fWidth = std::max(fWidth, fActualWidth); | 504 fWidth = std::max(fWidth, fActualWidth); |
566 } | 505 } |
567 | |
568 m_fItemHeight = CalcItemHeight(); | 506 m_fItemHeight = CalcItemHeight(); |
569 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) | |
570 fWidth += m_fItemHeight; | |
571 | 507 |
572 int32_t iCount = CountItems(this); | 508 int32_t iCount = CountItems(this); |
573 CFX_SizeF fs; | 509 CFX_SizeF fs; |
574 for (int32_t i = 0; i < iCount; i++) { | 510 for (int32_t i = 0; i < iCount; i++) { |
575 CFWL_ListItem* htem = GetItem(this, i); | 511 CFWL_ListItem* htem = GetItem(this, i); |
576 fs = GetItemSize(htem, fWidth, m_fItemHeight, bAutoSize); | 512 fs = GetItemSize(htem, fWidth, m_fItemHeight, bAutoSize); |
577 } | 513 } |
578 if (bAutoSize) | 514 if (bAutoSize) |
579 return fs; | 515 return fs; |
580 | 516 |
581 FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 517 FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
582 FX_FLOAT iHeight = m_rtClient.height; | 518 FX_FLOAT iHeight = m_rtClient.height; |
583 bool bShowVertScr = | 519 bool bShowVertScr = false; |
584 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && | 520 bool bShowHorzScr = false; |
585 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); | 521 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) |
586 bool bShowHorzScr = | |
587 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && | |
588 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); | |
589 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && | |
590 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { | |
591 bShowVertScr = (fs.y > iHeight); | 522 bShowVertScr = (fs.y > iHeight); |
592 } | |
593 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) | 523 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) |
594 bShowHorzScr = (fs.x > iWidth); | 524 bShowHorzScr = (fs.x > iWidth); |
595 | 525 |
596 CFX_SizeF szRange; | 526 CFX_SizeF szRange; |
597 if (bShowVertScr) { | 527 if (bShowVertScr) { |
598 if (!m_pVertScrollBar) | 528 if (!m_pVertScrollBar) |
599 InitVerticalScrollBar(); | 529 InitVerticalScrollBar(); |
600 | 530 |
601 CFX_RectF rtScrollBar; | 531 CFX_RectF rtScrollBar; |
602 rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, | 532 rtScrollBar.Set(m_rtClient.right() - m_fScorllBarWidth, m_rtClient.top, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, | 593 m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, |
664 m_fScorllBarWidth); | 594 m_fScorllBarWidth); |
665 } | 595 } |
666 return fs; | 596 return fs; |
667 } | 597 } |
668 | 598 |
669 CFX_SizeF CFWL_ListBox::GetItemSize(CFWL_ListItem* pItem, | 599 CFX_SizeF CFWL_ListBox::GetItemSize(CFWL_ListItem* pItem, |
670 FX_FLOAT fWidth, | 600 FX_FLOAT fWidth, |
671 FX_FLOAT fItemHeight, | 601 FX_FLOAT fItemHeight, |
672 bool bAutoSize) { | 602 bool bAutoSize) { |
673 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) | |
674 return CFX_SizeF(); | |
675 | |
676 CFX_SizeF size; | 603 CFX_SizeF size; |
677 if (!bAutoSize && pItem) { | 604 if (!bAutoSize && pItem) { |
678 CFX_RectF rtItem; | 605 CFX_RectF rtItem; |
679 rtItem.Set(0, size.y, fWidth, fItemHeight); | 606 rtItem.Set(0, size.y, fWidth, fItemHeight); |
680 pItem->SetRect(rtItem); | 607 pItem->SetRect(rtItem); |
681 } | 608 } |
682 size.x = fWidth; | 609 size.x = fWidth; |
683 size.y += fItemHeight; | 610 size.y += fItemHeight; |
684 return size; | 611 return size; |
685 } | 612 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 SetSelection(m_hAnchor, pItem, true); | 782 SetSelection(m_hAnchor, pItem, true); |
856 else | 783 else |
857 SetSelectionDirect(pItem, true); | 784 SetSelectionDirect(pItem, true); |
858 } else { | 785 } else { |
859 SetSelection(pItem, pItem, true); | 786 SetSelection(pItem, pItem, true); |
860 m_hAnchor = pItem; | 787 m_hAnchor = pItem; |
861 } | 788 } |
862 } else { | 789 } else { |
863 SetSelection(pItem, pItem, true); | 790 SetSelection(pItem, pItem, true); |
864 } | 791 } |
865 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) { | |
866 CFWL_ListItem* hSelectedItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | |
867 CFX_RectF rtCheck; | |
868 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) | |
869 rtCheck = hSelectedItem->GetCheckRect(); | |
870 | 792 |
871 bool bChecked = GetItemChecked(pItem); | |
872 if (rtCheck.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
873 SetItemChecked(pItem, !bChecked); | |
874 Update(); | |
875 } | |
876 } | |
877 SetFocusItem(pItem); | 793 SetFocusItem(pItem); |
878 ScrollToVisible(pItem); | 794 ScrollToVisible(pItem); |
879 SetGrab(true); | 795 SetGrab(true); |
880 RepaintRect(m_rtClient); | 796 RepaintRect(m_rtClient); |
881 } | 797 } |
882 | 798 |
883 void CFWL_ListBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { | 799 void CFWL_ListBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
884 if (!m_bLButtonDown) | 800 if (!m_bLButtonDown) |
885 return; | 801 return; |
886 | 802 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 void CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { | 948 void CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { |
1033 int32_t nIndex = GetItemIndex(this, pItem); | 949 int32_t nIndex = GetItemIndex(this, pItem); |
1034 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) | 950 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) |
1035 return; | 951 return; |
1036 | 952 |
1037 int32_t iSel = nIndex + 1; | 953 int32_t iSel = nIndex + 1; |
1038 if (iSel >= CountItems(this)) | 954 if (iSel >= CountItems(this)) |
1039 iSel = nIndex - 1; | 955 iSel = nIndex - 1; |
1040 if (iSel >= 0) { | 956 if (iSel >= 0) { |
1041 if (CFWL_ListItem* item = GetItem(this, iSel)) | 957 if (CFWL_ListItem* item = GetItem(this, iSel)) |
1042 item->SetStyles(item->GetStyles() | FWL_ITEMSTATE_LTB_Selected); | 958 item->SetStates(item->GetStates() | FWL_ITEMSTATE_LTB_Selected); |
1043 } | 959 } |
1044 | 960 |
1045 m_ItemArray.erase(m_ItemArray.begin() + nIndex); | 961 m_ItemArray.erase(m_ItemArray.begin() + nIndex); |
1046 } | 962 } |
1047 | 963 |
1048 void CFWL_ListBox::DeleteAll() { | 964 void CFWL_ListBox::DeleteAll() { |
1049 m_ItemArray.clear(); | 965 m_ItemArray.clear(); |
1050 } | 966 } |
OLD | NEW |