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