| 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 11 matching lines...) Expand all Loading... |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 IFWL_ListBox::IFWL_ListBox(const IFWL_App* app, | 24 IFWL_ListBox::IFWL_ListBox(const IFWL_App* app, |
| 25 const CFWL_WidgetImpProperties& properties, | 25 const CFWL_WidgetImpProperties& properties, |
| 26 IFWL_Widget* pOuter) | 26 IFWL_Widget* pOuter) |
| 27 : IFWL_Widget(app, properties, pOuter), | 27 : IFWL_Widget(app, properties, pOuter), |
| 28 m_dwTTOStyles(0), | 28 m_dwTTOStyles(0), |
| 29 m_iTTOAligns(0), | 29 m_iTTOAligns(0), |
| 30 m_hAnchor(nullptr), | 30 m_hAnchor(nullptr), |
| 31 m_fScorllBarWidth(0), | 31 m_fScorllBarWidth(0), |
| 32 m_bLButtonDown(FALSE), | 32 m_bLButtonDown(false), |
| 33 m_pScrollBarTP(nullptr) { | 33 m_pScrollBarTP(nullptr) { |
| 34 m_rtClient.Reset(); | 34 m_rtClient.Reset(); |
| 35 m_rtConent.Reset(); | 35 m_rtConent.Reset(); |
| 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 FWL_Error IFWL_ListBox::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 45 FWL_Error IFWL_ListBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
| 46 if (bAutoSize) { | 46 if (bAutoSize) { |
| 47 rect.Set(0, 0, 0, 0); | 47 rect.Set(0, 0, 0, 0); |
| 48 if (!m_pProperties->m_pThemeProvider) { | 48 if (!m_pProperties->m_pThemeProvider) { |
| 49 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 49 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 50 } | 50 } |
| 51 CFX_SizeF fs = CalcSize(TRUE); | 51 CFX_SizeF fs = CalcSize(true); |
| 52 rect.Set(0, 0, fs.x, fs.y); | 52 rect.Set(0, 0, fs.x, fs.y); |
| 53 IFWL_Widget::GetWidgetRect(rect, TRUE); | 53 IFWL_Widget::GetWidgetRect(rect, true); |
| 54 } else { | 54 } else { |
| 55 rect = m_pProperties->m_rtWidget; | 55 rect = m_pProperties->m_rtWidget; |
| 56 } | 56 } |
| 57 return FWL_Error::Succeeded; | 57 return FWL_Error::Succeeded; |
| 58 } | 58 } |
| 59 | 59 |
| 60 FWL_Error IFWL_ListBox::Update() { | 60 FWL_Error IFWL_ListBox::Update() { |
| 61 if (IsLocked()) { | 61 if (IsLocked()) { |
| 62 return FWL_Error::Indefinite; | 62 return FWL_Error::Indefinite; |
| 63 } | 63 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { | 80 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { |
| 81 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | 81 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; |
| 82 } | 82 } |
| 83 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; | 83 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; |
| 84 m_fScorllBarWidth = GetScrollWidth(); | 84 m_fScorllBarWidth = GetScrollWidth(); |
| 85 CalcSize(); | 85 CalcSize(); |
| 86 return FWL_Error::Succeeded; | 86 return FWL_Error::Succeeded; |
| 87 } | 87 } |
| 88 | 88 |
| 89 FWL_WidgetHit IFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 89 FWL_WidgetHit IFWL_ListBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 90 if (IsShowScrollBar(FALSE)) { | 90 if (IsShowScrollBar(false)) { |
| 91 CFX_RectF rect; | 91 CFX_RectF rect; |
| 92 m_pHorzScrollBar->GetWidgetRect(rect); | 92 m_pHorzScrollBar->GetWidgetRect(rect); |
| 93 if (rect.Contains(fx, fy)) | 93 if (rect.Contains(fx, fy)) |
| 94 return FWL_WidgetHit::HScrollBar; | 94 return FWL_WidgetHit::HScrollBar; |
| 95 } | 95 } |
| 96 if (IsShowScrollBar(TRUE)) { | 96 if (IsShowScrollBar(true)) { |
| 97 CFX_RectF rect; | 97 CFX_RectF rect; |
| 98 m_pVertScrollBar->GetWidgetRect(rect); | 98 m_pVertScrollBar->GetWidgetRect(rect); |
| 99 if (rect.Contains(fx, fy)) | 99 if (rect.Contains(fx, fy)) |
| 100 return FWL_WidgetHit::VScrollBar; | 100 return FWL_WidgetHit::VScrollBar; |
| 101 } | 101 } |
| 102 if (m_rtClient.Contains(fx, fy)) | 102 if (m_rtClient.Contains(fx, fy)) |
| 103 return FWL_WidgetHit::Client; | 103 return FWL_WidgetHit::Client; |
| 104 return FWL_WidgetHit::Unknown; | 104 return FWL_WidgetHit::Unknown; |
| 105 } | 105 } |
| 106 | 106 |
| 107 FWL_Error IFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, | 107 FWL_Error IFWL_ListBox::DrawWidget(CFX_Graphics* pGraphics, |
| 108 const CFX_Matrix* pMatrix) { | 108 const CFX_Matrix* pMatrix) { |
| 109 if (!pGraphics) | 109 if (!pGraphics) |
| 110 return FWL_Error::Indefinite; | 110 return FWL_Error::Indefinite; |
| 111 if (!m_pProperties->m_pThemeProvider) | 111 if (!m_pProperties->m_pThemeProvider) |
| 112 return FWL_Error::Indefinite; | 112 return FWL_Error::Indefinite; |
| 113 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 113 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 114 pGraphics->SaveGraphState(); | 114 pGraphics->SaveGraphState(); |
| 115 if (HasBorder()) { | 115 if (HasBorder()) { |
| 116 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 116 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
| 117 } | 117 } |
| 118 if (HasEdge()) { | 118 if (HasEdge()) { |
| 119 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 119 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
| 120 } | 120 } |
| 121 CFX_RectF rtClip(m_rtConent); | 121 CFX_RectF rtClip(m_rtConent); |
| 122 if (IsShowScrollBar(FALSE)) { | 122 if (IsShowScrollBar(false)) { |
| 123 rtClip.height -= m_fScorllBarWidth; | 123 rtClip.height -= m_fScorllBarWidth; |
| 124 } | 124 } |
| 125 if (IsShowScrollBar(TRUE)) { | 125 if (IsShowScrollBar(true)) { |
| 126 rtClip.width -= m_fScorllBarWidth; | 126 rtClip.width -= m_fScorllBarWidth; |
| 127 } | 127 } |
| 128 if (pMatrix) { | 128 if (pMatrix) { |
| 129 pMatrix->TransformRect(rtClip); | 129 pMatrix->TransformRect(rtClip); |
| 130 } | 130 } |
| 131 pGraphics->SetClipRect(rtClip); | 131 pGraphics->SetClipRect(rtClip); |
| 132 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0) { | 132 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0) { |
| 133 DrawBkground(pGraphics, pTheme, pMatrix); | 133 DrawBkground(pGraphics, pTheme, pMatrix); |
| 134 } | 134 } |
| 135 DrawItems(pGraphics, pTheme, pMatrix); | 135 DrawItems(pGraphics, pTheme, pMatrix); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (index == nIndex) { | 204 if (index == nIndex) { |
| 205 return i; | 205 return i; |
| 206 } else { | 206 } else { |
| 207 index++; | 207 index++; |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 return -1; | 211 return -1; |
| 212 } | 212 } |
| 213 | 213 |
| 214 FWL_Error IFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { | 214 FWL_Error IFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, bool bSelect) { |
| 215 if (!m_pProperties->m_pDataProvider) | 215 if (!m_pProperties->m_pDataProvider) |
| 216 return FWL_Error::Indefinite; | 216 return FWL_Error::Indefinite; |
| 217 if (!pItem) { | 217 if (!pItem) { |
| 218 if (bSelect) { | 218 if (bSelect) { |
| 219 SelectAll(); | 219 SelectAll(); |
| 220 } else { | 220 } else { |
| 221 ClearSelection(); | 221 ClearSelection(); |
| 222 SetFocusItem(nullptr); | 222 SetFocusItem(nullptr); |
| 223 } | 223 } |
| 224 return FWL_Error::Indefinite; | 224 return FWL_Error::Indefinite; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 236 if (!m_pProperties->m_pDataProvider) | 236 if (!m_pProperties->m_pDataProvider) |
| 237 return FWL_Error::Indefinite; | 237 return FWL_Error::Indefinite; |
| 238 IFWL_ListBoxDP* pData = | 238 IFWL_ListBoxDP* pData = |
| 239 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 239 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 240 if (!pItem) | 240 if (!pItem) |
| 241 return FWL_Error::Indefinite; | 241 return FWL_Error::Indefinite; |
| 242 pData->GetItemText(this, pItem, wsText); | 242 pData->GetItemText(this, pItem, wsText); |
| 243 return FWL_Error::Succeeded; | 243 return FWL_Error::Succeeded; |
| 244 } | 244 } |
| 245 | 245 |
| 246 FWL_Error IFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { | 246 FWL_Error IFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, bool bVert) { |
| 247 if ((bVert && IsShowScrollBar(TRUE)) || (!bVert && IsShowScrollBar(FALSE))) { | 247 if ((bVert && IsShowScrollBar(true)) || (!bVert && IsShowScrollBar(false))) { |
| 248 IFWL_ScrollBar* pScrollBar = | 248 IFWL_ScrollBar* pScrollBar = |
| 249 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); | 249 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); |
| 250 fPos = pScrollBar->GetPos(); | 250 fPos = pScrollBar->GetPos(); |
| 251 return FWL_Error::Succeeded; | 251 return FWL_Error::Succeeded; |
| 252 } | 252 } |
| 253 return FWL_Error::Indefinite; | 253 return FWL_Error::Indefinite; |
| 254 } | 254 } |
| 255 | 255 |
| 256 IFWL_ListItem* IFWL_ListBox::GetItem(IFWL_ListItem* pItem, uint32_t dwKeyCode) { | 256 IFWL_ListItem* IFWL_ListBox::GetItem(IFWL_ListItem* pItem, uint32_t dwKeyCode) { |
| 257 IFWL_ListItem* hRet = nullptr; | 257 IFWL_ListItem* hRet = nullptr; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 278 hRet = pData->GetItem(this, iDstItem); | 278 hRet = pData->GetItem(this, iDstItem); |
| 279 break; | 279 break; |
| 280 } | 280 } |
| 281 default: {} | 281 default: {} |
| 282 } | 282 } |
| 283 return hRet; | 283 return hRet; |
| 284 } | 284 } |
| 285 | 285 |
| 286 void IFWL_ListBox::SetSelection(IFWL_ListItem* hStart, | 286 void IFWL_ListBox::SetSelection(IFWL_ListItem* hStart, |
| 287 IFWL_ListItem* hEnd, | 287 IFWL_ListItem* hEnd, |
| 288 FX_BOOL bSelected) { | 288 bool bSelected) { |
| 289 IFWL_ListBoxDP* pData = | 289 IFWL_ListBoxDP* pData = |
| 290 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 290 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 291 int32_t iStart = pData->GetItemIndex(this, hStart); | 291 int32_t iStart = pData->GetItemIndex(this, hStart); |
| 292 int32_t iEnd = pData->GetItemIndex(this, hEnd); | 292 int32_t iEnd = pData->GetItemIndex(this, hEnd); |
| 293 if (iStart > iEnd) { | 293 if (iStart > iEnd) { |
| 294 int32_t iTemp = iStart; | 294 int32_t iTemp = iStart; |
| 295 iStart = iEnd; | 295 iStart = iEnd; |
| 296 iEnd = iTemp; | 296 iEnd = iTemp; |
| 297 } | 297 } |
| 298 if (bSelected) { | 298 if (bSelected) { |
| 299 int32_t iCount = pData->CountItems(this); | 299 int32_t iCount = pData->CountItems(this); |
| 300 for (int32_t i = 0; i < iCount; i++) { | 300 for (int32_t i = 0; i < iCount; i++) { |
| 301 IFWL_ListItem* pItem = pData->GetItem(this, i); | 301 IFWL_ListItem* pItem = pData->GetItem(this, i); |
| 302 SetSelectionDirect(pItem, FALSE); | 302 SetSelectionDirect(pItem, false); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 for (; iStart <= iEnd; iStart++) { | 305 for (; iStart <= iEnd; iStart++) { |
| 306 IFWL_ListItem* pItem = pData->GetItem(this, iStart); | 306 IFWL_ListItem* pItem = pData->GetItem(this, iStart); |
| 307 SetSelectionDirect(pItem, bSelected); | 307 SetSelectionDirect(pItem, bSelected); |
| 308 } | 308 } |
| 309 } | 309 } |
| 310 | 310 |
| 311 void IFWL_ListBox::SetSelectionDirect(IFWL_ListItem* pItem, FX_BOOL bSelect) { | 311 void IFWL_ListBox::SetSelectionDirect(IFWL_ListItem* pItem, bool bSelect) { |
| 312 IFWL_ListBoxDP* pData = | 312 IFWL_ListBoxDP* pData = |
| 313 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 313 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 314 uint32_t dwOldStyle = pData->GetItemStyles(this, pItem); | 314 uint32_t dwOldStyle = pData->GetItemStyles(this, pItem); |
| 315 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected | 315 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected |
| 316 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; | 316 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; |
| 317 pData->SetItemStyles(this, pItem, dwOldStyle); | 317 pData->SetItemStyles(this, pItem, dwOldStyle); |
| 318 } | 318 } |
| 319 | 319 |
| 320 FX_BOOL IFWL_ListBox::IsItemSelected(IFWL_ListItem* pItem) { | 320 bool IFWL_ListBox::IsItemSelected(IFWL_ListItem* pItem) { |
| 321 IFWL_ListBoxDP* pData = | 321 IFWL_ListBoxDP* pData = |
| 322 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 322 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 323 uint32_t dwState = pData->GetItemStyles(this, pItem); | 323 uint32_t dwState = pData->GetItemStyles(this, pItem); |
| 324 return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; | 324 return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void IFWL_ListBox::ClearSelection() { | 327 void IFWL_ListBox::ClearSelection() { |
| 328 FX_BOOL bMulti = | 328 bool bMulti = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; |
| 329 m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; | |
| 330 IFWL_ListBoxDP* pData = | 329 IFWL_ListBoxDP* pData = |
| 331 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 330 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 332 int32_t iCount = pData->CountItems(this); | 331 int32_t iCount = pData->CountItems(this); |
| 333 for (int32_t i = 0; i < iCount; i++) { | 332 for (int32_t i = 0; i < iCount; i++) { |
| 334 IFWL_ListItem* pItem = pData->GetItem(this, i); | 333 IFWL_ListItem* pItem = pData->GetItem(this, i); |
| 335 uint32_t dwState = pData->GetItemStyles(this, pItem); | 334 uint32_t dwState = pData->GetItemStyles(this, pItem); |
| 336 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) | 335 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) |
| 337 continue; | 336 continue; |
| 338 SetSelectionDirect(pItem, FALSE); | 337 SetSelectionDirect(pItem, false); |
| 339 if (!bMulti) | 338 if (!bMulti) |
| 340 return; | 339 return; |
| 341 } | 340 } |
| 342 } | 341 } |
| 343 | 342 |
| 344 void IFWL_ListBox::SelectAll() { | 343 void IFWL_ListBox::SelectAll() { |
| 345 FX_BOOL bMulti = | 344 bool bMulti = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; |
| 346 m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; | |
| 347 if (!bMulti) { | 345 if (!bMulti) { |
| 348 return; | 346 return; |
| 349 } | 347 } |
| 350 IFWL_ListBoxDP* pData = | 348 IFWL_ListBoxDP* pData = |
| 351 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 349 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 352 int32_t iCount = pData->CountItems(this); | 350 int32_t iCount = pData->CountItems(this); |
| 353 if (iCount > 0) { | 351 if (iCount > 0) { |
| 354 IFWL_ListItem* pItemStart = pData->GetItem(this, 0); | 352 IFWL_ListItem* pItemStart = pData->GetItem(this, 0); |
| 355 IFWL_ListItem* pItemEnd = pData->GetItem(this, iCount - 1); | 353 IFWL_ListItem* pItemEnd = pData->GetItem(this, iCount - 1); |
| 356 SetSelection(pItemStart, pItemEnd, FALSE); | 354 SetSelection(pItemStart, pItemEnd, false); |
| 357 } | 355 } |
| 358 } | 356 } |
| 359 | 357 |
| 360 IFWL_ListItem* IFWL_ListBox::GetFocusedItem() { | 358 IFWL_ListItem* IFWL_ListBox::GetFocusedItem() { |
| 361 IFWL_ListBoxDP* pData = | 359 IFWL_ListBoxDP* pData = |
| 362 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 360 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 363 int32_t iCount = pData->CountItems(this); | 361 int32_t iCount = pData->CountItems(this); |
| 364 for (int32_t i = 0; i < iCount; i++) { | 362 for (int32_t i = 0; i < iCount; i++) { |
| 365 IFWL_ListItem* pItem = pData->GetItem(this, i); | 363 IFWL_ListItem* pItem = pData->GetItem(this, i); |
| 366 if (!pItem) | 364 if (!pItem) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 CFX_RectF rtItem; | 409 CFX_RectF rtItem; |
| 412 pData->GetItemRect(this, pItem, rtItem); | 410 pData->GetItemRect(this, pItem, rtItem); |
| 413 rtItem.Offset(-fPosX, -fPosY); | 411 rtItem.Offset(-fPosX, -fPosY); |
| 414 if (rtItem.Contains(fx, fy)) { | 412 if (rtItem.Contains(fx, fy)) { |
| 415 return pItem; | 413 return pItem; |
| 416 } | 414 } |
| 417 } | 415 } |
| 418 return nullptr; | 416 return nullptr; |
| 419 } | 417 } |
| 420 | 418 |
| 421 FX_BOOL IFWL_ListBox::GetItemCheckRect(IFWL_ListItem* pItem, | 419 bool IFWL_ListBox::GetItemCheckRect(IFWL_ListItem* pItem, CFX_RectF& rtCheck) { |
| 422 CFX_RectF& rtCheck) { | |
| 423 if (!m_pProperties->m_pDataProvider) | 420 if (!m_pProperties->m_pDataProvider) |
| 424 return FALSE; | 421 return false; |
| 425 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 422 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { |
| 426 return FALSE; | 423 return false; |
| 427 } | 424 } |
| 428 IFWL_ListBoxDP* pData = | 425 IFWL_ListBoxDP* pData = |
| 429 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 426 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 430 pData->GetItemCheckRect(this, pItem, rtCheck); | 427 pData->GetItemCheckRect(this, pItem, rtCheck); |
| 431 return TRUE; | 428 return true; |
| 432 } | 429 } |
| 433 | 430 |
| 434 FX_BOOL IFWL_ListBox::GetItemChecked(IFWL_ListItem* pItem) { | 431 bool IFWL_ListBox::GetItemChecked(IFWL_ListItem* pItem) { |
| 435 if (!m_pProperties->m_pDataProvider) | 432 if (!m_pProperties->m_pDataProvider) |
| 436 return FALSE; | 433 return false; |
| 437 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 434 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { |
| 438 return FALSE; | 435 return false; |
| 439 } | 436 } |
| 440 IFWL_ListBoxDP* pData = | 437 IFWL_ListBoxDP* pData = |
| 441 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 438 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 442 return !!(pData->GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); | 439 return !!(pData->GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); |
| 443 } | 440 } |
| 444 | 441 |
| 445 FX_BOOL IFWL_ListBox::SetItemChecked(IFWL_ListItem* pItem, FX_BOOL bChecked) { | 442 bool IFWL_ListBox::SetItemChecked(IFWL_ListItem* pItem, bool bChecked) { |
| 446 if (!m_pProperties->m_pDataProvider) | 443 if (!m_pProperties->m_pDataProvider) |
| 447 return FALSE; | 444 return false; |
| 448 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 445 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { |
| 449 return FALSE; | 446 return false; |
| 450 } | 447 } |
| 451 IFWL_ListBoxDP* pData = | 448 IFWL_ListBoxDP* pData = |
| 452 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 449 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 453 pData->SetItemCheckState(this, pItem, | 450 pData->SetItemCheckState(this, pItem, |
| 454 bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); | 451 bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); |
| 455 return TRUE; | 452 return true; |
| 456 } | 453 } |
| 457 | 454 |
| 458 FX_BOOL IFWL_ListBox::ScrollToVisible(IFWL_ListItem* pItem) { | 455 bool IFWL_ListBox::ScrollToVisible(IFWL_ListItem* pItem) { |
| 459 if (!m_pVertScrollBar) | 456 if (!m_pVertScrollBar) |
| 460 return FALSE; | 457 return false; |
| 461 CFX_RectF rtItem; | 458 CFX_RectF rtItem; |
| 462 IFWL_ListBoxDP* pData = | 459 IFWL_ListBoxDP* pData = |
| 463 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 460 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 464 pData->GetItemRect(this, pItem, rtItem); | 461 pData->GetItemRect(this, pItem, rtItem); |
| 465 FX_BOOL bScroll = FALSE; | 462 bool bScroll = false; |
| 466 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); | 463 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); |
| 467 rtItem.Offset(0, -fPosY + m_rtConent.top); | 464 rtItem.Offset(0, -fPosY + m_rtConent.top); |
| 468 if (rtItem.top < m_rtConent.top) { | 465 if (rtItem.top < m_rtConent.top) { |
| 469 fPosY += rtItem.top - m_rtConent.top; | 466 fPosY += rtItem.top - m_rtConent.top; |
| 470 bScroll = TRUE; | 467 bScroll = true; |
| 471 } else if (rtItem.bottom() > m_rtConent.bottom()) { | 468 } else if (rtItem.bottom() > m_rtConent.bottom()) { |
| 472 fPosY += rtItem.bottom() - m_rtConent.bottom(); | 469 fPosY += rtItem.bottom() - m_rtConent.bottom(); |
| 473 bScroll = TRUE; | 470 bScroll = true; |
| 474 } | 471 } |
| 475 if (!bScroll) { | 472 if (!bScroll) { |
| 476 return FALSE; | 473 return false; |
| 477 } | 474 } |
| 478 m_pVertScrollBar->SetPos(fPosY); | 475 m_pVertScrollBar->SetPos(fPosY); |
| 479 m_pVertScrollBar->SetTrackPos(fPosY); | 476 m_pVertScrollBar->SetTrackPos(fPosY); |
| 480 Repaint(&m_rtClient); | 477 Repaint(&m_rtClient); |
| 481 return TRUE; | 478 return true; |
| 482 } | 479 } |
| 483 | 480 |
| 484 void IFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, | 481 void IFWL_ListBox::DrawBkground(CFX_Graphics* pGraphics, |
| 485 IFWL_ThemeProvider* pTheme, | 482 IFWL_ThemeProvider* pTheme, |
| 486 const CFX_Matrix* pMatrix) { | 483 const CFX_Matrix* pMatrix) { |
| 487 if (!pGraphics) | 484 if (!pGraphics) |
| 488 return; | 485 return; |
| 489 if (!pTheme) | 486 if (!pTheme) |
| 490 return; | 487 return; |
| 491 CFWL_ThemeBackground param; | 488 CFWL_ThemeBackground param; |
| 492 param.m_pWidget = this; | 489 param.m_pWidget = this; |
| 493 param.m_iPart = CFWL_Part::Background; | 490 param.m_iPart = CFWL_Part::Background; |
| 494 param.m_dwStates = 0; | 491 param.m_dwStates = 0; |
| 495 param.m_pGraphics = pGraphics; | 492 param.m_pGraphics = pGraphics; |
| 496 param.m_matrix.Concat(*pMatrix); | 493 param.m_matrix.Concat(*pMatrix); |
| 497 param.m_rtPart = m_rtClient; | 494 param.m_rtPart = m_rtClient; |
| 498 if (IsShowScrollBar(FALSE) && IsShowScrollBar(TRUE)) { | 495 if (IsShowScrollBar(false) && IsShowScrollBar(true)) { |
| 499 param.m_pData = &m_rtStatic; | 496 param.m_pData = &m_rtStatic; |
| 500 } | 497 } |
| 501 if (!IsEnabled()) { | 498 if (!IsEnabled()) { |
| 502 param.m_dwStates = CFWL_PartState_Disabled; | 499 param.m_dwStates = CFWL_PartState_Disabled; |
| 503 } | 500 } |
| 504 pTheme->DrawBackground(¶m); | 501 pTheme->DrawBackground(¶m); |
| 505 } | 502 } |
| 506 | 503 |
| 507 void IFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, | 504 void IFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, |
| 508 IFWL_ThemeProvider* pTheme, | 505 IFWL_ThemeProvider* pTheme, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 textParam.m_matrix.Concat(*pMatrix); | 649 textParam.m_matrix.Concat(*pMatrix); |
| 653 textParam.m_rtPart = rtText; | 650 textParam.m_rtPart = rtText; |
| 654 textParam.m_wsText = wsText; | 651 textParam.m_wsText = wsText; |
| 655 textParam.m_dwTTOStyles = m_dwTTOStyles; | 652 textParam.m_dwTTOStyles = m_dwTTOStyles; |
| 656 textParam.m_iTTOAlign = m_iTTOAligns; | 653 textParam.m_iTTOAlign = m_iTTOAligns; |
| 657 textParam.m_bMaximize = true; | 654 textParam.m_bMaximize = true; |
| 658 pTheme->DrawText(&textParam); | 655 pTheme->DrawText(&textParam); |
| 659 } | 656 } |
| 660 } | 657 } |
| 661 | 658 |
| 662 CFX_SizeF IFWL_ListBox::CalcSize(FX_BOOL bAutoSize) { | 659 CFX_SizeF IFWL_ListBox::CalcSize(bool bAutoSize) { |
| 663 CFX_SizeF fs; | 660 CFX_SizeF fs; |
| 664 if (!m_pProperties->m_pThemeProvider) | 661 if (!m_pProperties->m_pThemeProvider) |
| 665 return fs; | 662 return fs; |
| 666 | 663 |
| 667 GetClientRect(m_rtClient); | 664 GetClientRect(m_rtClient); |
| 668 m_rtConent = m_rtClient; | 665 m_rtConent = m_rtClient; |
| 669 CFX_RectF rtUIMargin; | 666 CFX_RectF rtUIMargin; |
| 670 rtUIMargin.Set(0, 0, 0, 0); | 667 rtUIMargin.Set(0, 0, 0, 0); |
| 671 if (!m_pOuter) { | 668 if (!m_pOuter) { |
| 672 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( | 669 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 for (int32_t i = 0; i < iCount; i++) { | 712 for (int32_t i = 0; i < iCount; i++) { |
| 716 IFWL_ListItem* htem = pData->GetItem(this, i); | 713 IFWL_ListItem* htem = pData->GetItem(this, i); |
| 717 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); | 714 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); |
| 718 } | 715 } |
| 719 } | 716 } |
| 720 if (bAutoSize) { | 717 if (bAutoSize) { |
| 721 return fs; | 718 return fs; |
| 722 } | 719 } |
| 723 FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 720 FX_FLOAT iWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
| 724 FX_FLOAT iHeight = m_rtClient.height; | 721 FX_FLOAT iHeight = m_rtClient.height; |
| 725 FX_BOOL bShowVertScr = | 722 bool bShowVertScr = |
| 726 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && | 723 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && |
| 727 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); | 724 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll); |
| 728 FX_BOOL bShowHorzScr = | 725 bool bShowHorzScr = |
| 729 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && | 726 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarAlaways) && |
| 730 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); | 727 (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll); |
| 731 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && | 728 if (!bShowVertScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll && |
| 732 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { | 729 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) == 0) { |
| 733 bShowVertScr = (fs.y > iHeight); | 730 bShowVertScr = (fs.y > iHeight); |
| 734 } | 731 } |
| 735 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) { | 732 if (!bShowHorzScr && m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) { |
| 736 bShowHorzScr = (fs.x > iWidth); | 733 bShowHorzScr = (fs.x > iWidth); |
| 737 } | 734 } |
| 738 CFX_SizeF szRange; | 735 CFX_SizeF szRange; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 759 fPos = 0; | 756 fPos = 0; |
| 760 } | 757 } |
| 761 if (fPos > szRange.y) { | 758 if (fPos > szRange.y) { |
| 762 fPos = szRange.y; | 759 fPos = szRange.y; |
| 763 } | 760 } |
| 764 m_pVertScrollBar->SetPos(fPos); | 761 m_pVertScrollBar->SetPos(fPos); |
| 765 m_pVertScrollBar->SetTrackPos(fPos); | 762 m_pVertScrollBar->SetTrackPos(fPos); |
| 766 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == | 763 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == |
| 767 0 || | 764 0 || |
| 768 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { | 765 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { |
| 769 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE); | 766 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
| 770 } | 767 } |
| 771 m_pVertScrollBar->Update(); | 768 m_pVertScrollBar->Update(); |
| 772 } else if (m_pVertScrollBar) { | 769 } else if (m_pVertScrollBar) { |
| 773 m_pVertScrollBar->SetPos(0); | 770 m_pVertScrollBar->SetPos(0); |
| 774 m_pVertScrollBar->SetTrackPos(0); | 771 m_pVertScrollBar->SetTrackPos(0); |
| 775 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE); | 772 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
| 776 } | 773 } |
| 777 if (bShowHorzScr) { | 774 if (bShowHorzScr) { |
| 778 if (!m_pHorzScrollBar) { | 775 if (!m_pHorzScrollBar) { |
| 779 InitScrollBar(FALSE); | 776 InitScrollBar(false); |
| 780 } | 777 } |
| 781 CFX_RectF rtScrollBar; | 778 CFX_RectF rtScrollBar; |
| 782 rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, | 779 rtScrollBar.Set(m_rtClient.left, m_rtClient.bottom() - m_fScorllBarWidth, |
| 783 m_rtClient.width, m_fScorllBarWidth); | 780 m_rtClient.width, m_fScorllBarWidth); |
| 784 if (bShowVertScr) { | 781 if (bShowVertScr) { |
| 785 rtScrollBar.width -= m_fScorllBarWidth; | 782 rtScrollBar.width -= m_fScorllBarWidth; |
| 786 } | 783 } |
| 787 m_pHorzScrollBar->SetWidgetRect(rtScrollBar); | 784 m_pHorzScrollBar->SetWidgetRect(rtScrollBar); |
| 788 szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; | 785 szRange.x = 0, szRange.y = fs.x - rtScrollBar.width; |
| 789 m_pHorzScrollBar->SetRange(szRange.x, szRange.y); | 786 m_pHorzScrollBar->SetRange(szRange.x, szRange.y); |
| 790 m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10); | 787 m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10); |
| 791 m_pHorzScrollBar->SetStepSize(fWidth / 10); | 788 m_pHorzScrollBar->SetStepSize(fWidth / 10); |
| 792 FX_FLOAT fPos = m_pHorzScrollBar->GetPos(); | 789 FX_FLOAT fPos = m_pHorzScrollBar->GetPos(); |
| 793 if (fPos < 0) { | 790 if (fPos < 0) { |
| 794 fPos = 0; | 791 fPos = 0; |
| 795 } | 792 } |
| 796 if (fPos > szRange.y) { | 793 if (fPos > szRange.y) { |
| 797 fPos = szRange.y; | 794 fPos = szRange.y; |
| 798 } | 795 } |
| 799 m_pHorzScrollBar->SetPos(fPos); | 796 m_pHorzScrollBar->SetPos(fPos); |
| 800 m_pHorzScrollBar->SetTrackPos(fPos); | 797 m_pHorzScrollBar->SetTrackPos(fPos); |
| 801 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == | 798 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) == |
| 802 0 || | 799 0 || |
| 803 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { | 800 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) { |
| 804 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE); | 801 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
| 805 } | 802 } |
| 806 m_pHorzScrollBar->Update(); | 803 m_pHorzScrollBar->Update(); |
| 807 } else if (m_pHorzScrollBar) { | 804 } else if (m_pHorzScrollBar) { |
| 808 m_pHorzScrollBar->SetPos(0); | 805 m_pHorzScrollBar->SetPos(0); |
| 809 m_pHorzScrollBar->SetTrackPos(0); | 806 m_pHorzScrollBar->SetTrackPos(0); |
| 810 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE); | 807 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
| 811 } | 808 } |
| 812 if (bShowVertScr && bShowHorzScr) { | 809 if (bShowVertScr && bShowHorzScr) { |
| 813 m_rtStatic.Set(m_rtClient.right() - m_fScorllBarWidth, | 810 m_rtStatic.Set(m_rtClient.right() - m_fScorllBarWidth, |
| 814 m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, | 811 m_rtClient.bottom() - m_fScorllBarWidth, m_fScorllBarWidth, |
| 815 m_fScorllBarWidth); | 812 m_fScorllBarWidth); |
| 816 } | 813 } |
| 817 return fs; | 814 return fs; |
| 818 } | 815 } |
| 819 | 816 |
| 820 void IFWL_ListBox::GetItemSize(CFX_SizeF& size, | 817 void IFWL_ListBox::GetItemSize(CFX_SizeF& size, |
| 821 IFWL_ListItem* pItem, | 818 IFWL_ListItem* pItem, |
| 822 FX_FLOAT fWidth, | 819 FX_FLOAT fWidth, |
| 823 FX_FLOAT fItemHeight, | 820 FX_FLOAT fItemHeight, |
| 824 FX_BOOL bAutoSize) { | 821 bool bAutoSize) { |
| 825 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) { | 822 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) { |
| 826 } else { | 823 } else { |
| 827 if (!bAutoSize) { | 824 if (!bAutoSize) { |
| 828 CFX_RectF rtItem; | 825 CFX_RectF rtItem; |
| 829 rtItem.Set(0, size.y, fWidth, fItemHeight); | 826 rtItem.Set(0, size.y, fWidth, fItemHeight); |
| 830 IFWL_ListBoxDP* pData = | 827 IFWL_ListBoxDP* pData = |
| 831 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 828 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 832 pData->SetItemRect(this, pItem, rtItem); | 829 pData->SetItemRect(this, pItem, rtItem); |
| 833 } | 830 } |
| 834 size.x = fWidth; | 831 size.x = fWidth; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 865 } | 862 } |
| 866 | 863 |
| 867 FX_FLOAT IFWL_ListBox::GetItemHeigt() { | 864 FX_FLOAT IFWL_ListBox::GetItemHeigt() { |
| 868 FX_FLOAT* pfFont = | 865 FX_FLOAT* pfFont = |
| 869 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); | 866 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); |
| 870 if (!pfFont) | 867 if (!pfFont) |
| 871 return 20; | 868 return 20; |
| 872 return *pfFont + 2 * kItemTextMargin; | 869 return *pfFont + 2 * kItemTextMargin; |
| 873 } | 870 } |
| 874 | 871 |
| 875 void IFWL_ListBox::InitScrollBar(FX_BOOL bVert) { | 872 void IFWL_ListBox::InitScrollBar(bool bVert) { |
| 876 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) { | 873 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) { |
| 877 return; | 874 return; |
| 878 } | 875 } |
| 879 CFWL_WidgetImpProperties prop; | 876 CFWL_WidgetImpProperties prop; |
| 880 prop.m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; | 877 prop.m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; |
| 881 prop.m_dwStates = FWL_WGTSTATE_Invisible; | 878 prop.m_dwStates = FWL_WGTSTATE_Invisible; |
| 882 prop.m_pParent = this; | 879 prop.m_pParent = this; |
| 883 prop.m_pThemeProvider = m_pScrollBarTP; | 880 prop.m_pThemeProvider = m_pScrollBarTP; |
| 884 (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar) | 881 (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar) |
| 885 ->reset(new IFWL_ScrollBar(m_pOwnerApp, prop, this)); | 882 ->reset(new IFWL_ScrollBar(m_pOwnerApp, prop, this)); |
| 886 } | 883 } |
| 887 | 884 |
| 888 FX_BOOL IFWL_ListBox::IsShowScrollBar(FX_BOOL bVert) { | 885 bool IFWL_ListBox::IsShowScrollBar(bool bVert) { |
| 889 IFWL_ScrollBar* pScrollbar = | 886 IFWL_ScrollBar* pScrollbar = |
| 890 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); | 887 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); |
| 891 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) { | 888 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) { |
| 892 return FALSE; | 889 return false; |
| 893 } | 890 } |
| 894 return !(m_pProperties->m_dwStyleExes & | 891 return !(m_pProperties->m_dwStyleExes & |
| 895 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || | 892 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || |
| 896 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); | 893 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); |
| 897 } | 894 } |
| 898 | 895 |
| 899 void IFWL_ListBox::ProcessSelChanged() { | 896 void IFWL_ListBox::ProcessSelChanged() { |
| 900 CFWL_EvtLtbSelChanged selEvent; | 897 CFWL_EvtLtbSelChanged selEvent; |
| 901 selEvent.m_pSrcTarget = this; | 898 selEvent.m_pSrcTarget = this; |
| 902 CFX_Int32Array arrSels; | 899 CFX_Int32Array arrSels; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 913 | 910 |
| 914 void IFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) { | 911 void IFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) { |
| 915 if (!pMessage) | 912 if (!pMessage) |
| 916 return; | 913 return; |
| 917 if (!IsEnabled()) | 914 if (!IsEnabled()) |
| 918 return; | 915 return; |
| 919 | 916 |
| 920 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 917 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
| 921 switch (dwMsgCode) { | 918 switch (dwMsgCode) { |
| 922 case CFWL_MessageType::SetFocus: | 919 case CFWL_MessageType::SetFocus: |
| 923 OnFocusChanged(pMessage, TRUE); | 920 OnFocusChanged(pMessage, true); |
| 924 break; | 921 break; |
| 925 case CFWL_MessageType::KillFocus: | 922 case CFWL_MessageType::KillFocus: |
| 926 OnFocusChanged(pMessage, FALSE); | 923 OnFocusChanged(pMessage, false); |
| 927 break; | 924 break; |
| 928 case CFWL_MessageType::Mouse: { | 925 case CFWL_MessageType::Mouse: { |
| 929 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 926 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
| 930 switch (pMsg->m_dwCmd) { | 927 switch (pMsg->m_dwCmd) { |
| 931 case FWL_MouseCommand::LeftButtonDown: | 928 case FWL_MouseCommand::LeftButtonDown: |
| 932 OnLButtonDown(pMsg); | 929 OnLButtonDown(pMsg); |
| 933 break; | 930 break; |
| 934 case FWL_MouseCommand::LeftButtonUp: | 931 case FWL_MouseCommand::LeftButtonUp: |
| 935 OnLButtonUp(pMsg); | 932 OnLButtonUp(pMsg); |
| 936 break; | 933 break; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 967 OnScroll(static_cast<IFWL_ScrollBar*>(pSrcTarget), | 964 OnScroll(static_cast<IFWL_ScrollBar*>(pSrcTarget), |
| 968 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); | 965 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); |
| 969 } | 966 } |
| 970 } | 967 } |
| 971 | 968 |
| 972 void IFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, | 969 void IFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, |
| 973 const CFX_Matrix* pMatrix) { | 970 const CFX_Matrix* pMatrix) { |
| 974 DrawWidget(pGraphics, pMatrix); | 971 DrawWidget(pGraphics, pMatrix); |
| 975 } | 972 } |
| 976 | 973 |
| 977 void IFWL_ListBox::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { | 974 void IFWL_ListBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
| 978 if (GetStylesEx() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) { | 975 if (GetStylesEx() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) { |
| 979 if (m_pVertScrollBar) | 976 if (m_pVertScrollBar) |
| 980 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, !bSet); | 977 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, !bSet); |
| 981 if (m_pHorzScrollBar) | 978 if (m_pHorzScrollBar) |
| 982 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, !bSet); | 979 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, !bSet); |
| 983 } | 980 } |
| 984 if (bSet) | 981 if (bSet) |
| 985 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 982 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
| 986 else | 983 else |
| 987 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 984 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
| 988 | 985 |
| 989 Repaint(&m_rtClient); | 986 Repaint(&m_rtClient); |
| 990 } | 987 } |
| 991 | 988 |
| 992 void IFWL_ListBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 989 void IFWL_ListBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| 993 m_bLButtonDown = TRUE; | 990 m_bLButtonDown = true; |
| 994 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 991 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
| 995 SetFocus(TRUE); | 992 SetFocus(true); |
| 996 | 993 |
| 997 IFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 994 IFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 998 if (!pItem) | 995 if (!pItem) |
| 999 return; | 996 return; |
| 1000 | 997 |
| 1001 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 998 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { |
| 1002 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { | 999 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { |
| 1003 FX_BOOL bSelected = IsItemSelected(pItem); | 1000 bool bSelected = IsItemSelected(pItem); |
| 1004 SetSelectionDirect(pItem, !bSelected); | 1001 SetSelectionDirect(pItem, !bSelected); |
| 1005 m_hAnchor = pItem; | 1002 m_hAnchor = pItem; |
| 1006 } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) { | 1003 } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) { |
| 1007 if (m_hAnchor) | 1004 if (m_hAnchor) |
| 1008 SetSelection(m_hAnchor, pItem, TRUE); | 1005 SetSelection(m_hAnchor, pItem, true); |
| 1009 else | 1006 else |
| 1010 SetSelectionDirect(pItem, TRUE); | 1007 SetSelectionDirect(pItem, true); |
| 1011 } else { | 1008 } else { |
| 1012 SetSelection(pItem, pItem, TRUE); | 1009 SetSelection(pItem, pItem, true); |
| 1013 m_hAnchor = pItem; | 1010 m_hAnchor = pItem; |
| 1014 } | 1011 } |
| 1015 } else { | 1012 } else { |
| 1016 SetSelection(pItem, pItem, TRUE); | 1013 SetSelection(pItem, pItem, true); |
| 1017 } | 1014 } |
| 1018 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) { | 1015 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) { |
| 1019 IFWL_ListItem* hSelectedItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 1016 IFWL_ListItem* hSelectedItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 1020 CFX_RectF rtCheck; | 1017 CFX_RectF rtCheck; |
| 1021 GetItemCheckRect(hSelectedItem, rtCheck); | 1018 GetItemCheckRect(hSelectedItem, rtCheck); |
| 1022 FX_BOOL bChecked = GetItemChecked(pItem); | 1019 bool bChecked = GetItemChecked(pItem); |
| 1023 if (rtCheck.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1020 if (rtCheck.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 1024 SetItemChecked(pItem, !bChecked); | 1021 SetItemChecked(pItem, !bChecked); |
| 1025 Update(); | 1022 Update(); |
| 1026 } | 1023 } |
| 1027 } | 1024 } |
| 1028 SetFocusItem(pItem); | 1025 SetFocusItem(pItem); |
| 1029 ScrollToVisible(pItem); | 1026 ScrollToVisible(pItem); |
| 1030 SetGrab(TRUE); | 1027 SetGrab(true); |
| 1031 ProcessSelChanged(); | 1028 ProcessSelChanged(); |
| 1032 Repaint(&m_rtClient); | 1029 Repaint(&m_rtClient); |
| 1033 } | 1030 } |
| 1034 | 1031 |
| 1035 void IFWL_ListBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 1032 void IFWL_ListBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
| 1036 if (!m_bLButtonDown) | 1033 if (!m_bLButtonDown) |
| 1037 return; | 1034 return; |
| 1038 | 1035 |
| 1039 m_bLButtonDown = FALSE; | 1036 m_bLButtonDown = false; |
| 1040 SetGrab(FALSE); | 1037 SetGrab(false); |
| 1041 DispatchSelChangedEv(); | 1038 DispatchSelChangedEv(); |
| 1042 } | 1039 } |
| 1043 | 1040 |
| 1044 void IFWL_ListBox::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { | 1041 void IFWL_ListBox::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { |
| 1045 if (IsShowScrollBar(TRUE)) | 1042 if (IsShowScrollBar(true)) |
| 1046 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); | 1043 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); |
| 1047 } | 1044 } |
| 1048 | 1045 |
| 1049 void IFWL_ListBox::OnKeyDown(CFWL_MsgKey* pMsg) { | 1046 void IFWL_ListBox::OnKeyDown(CFWL_MsgKey* pMsg) { |
| 1050 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1047 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
| 1051 switch (dwKeyCode) { | 1048 switch (dwKeyCode) { |
| 1052 case FWL_VKEY_Tab: | 1049 case FWL_VKEY_Tab: |
| 1053 case FWL_VKEY_Up: | 1050 case FWL_VKEY_Up: |
| 1054 case FWL_VKEY_Down: | 1051 case FWL_VKEY_Down: |
| 1055 case FWL_VKEY_Home: | 1052 case FWL_VKEY_Home: |
| 1056 case FWL_VKEY_End: { | 1053 case FWL_VKEY_End: { |
| 1057 IFWL_ListItem* pItem = GetFocusedItem(); | 1054 IFWL_ListItem* pItem = GetFocusedItem(); |
| 1058 pItem = GetItem(pItem, dwKeyCode); | 1055 pItem = GetItem(pItem, dwKeyCode); |
| 1059 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); | 1056 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); |
| 1060 bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); | 1057 bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); |
| 1061 OnVK(pItem, bShift, bCtrl); | 1058 OnVK(pItem, bShift, bCtrl); |
| 1062 DispatchSelChangedEv(); | 1059 DispatchSelChangedEv(); |
| 1063 ProcessSelChanged(); | 1060 ProcessSelChanged(); |
| 1064 break; | 1061 break; |
| 1065 } | 1062 } |
| 1066 default: | 1063 default: |
| 1067 break; | 1064 break; |
| 1068 } | 1065 } |
| 1069 } | 1066 } |
| 1070 | 1067 |
| 1071 void IFWL_ListBox::OnVK(IFWL_ListItem* pItem, FX_BOOL bShift, FX_BOOL bCtrl) { | 1068 void IFWL_ListBox::OnVK(IFWL_ListItem* pItem, bool bShift, bool bCtrl) { |
| 1072 if (!pItem) | 1069 if (!pItem) |
| 1073 return; | 1070 return; |
| 1074 | 1071 |
| 1075 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 1072 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { |
| 1076 if (bCtrl) { | 1073 if (bCtrl) { |
| 1077 } else if (bShift) { | 1074 } else if (bShift) { |
| 1078 if (m_hAnchor) | 1075 if (m_hAnchor) |
| 1079 SetSelection(m_hAnchor, pItem, TRUE); | 1076 SetSelection(m_hAnchor, pItem, true); |
| 1080 else | 1077 else |
| 1081 SetSelectionDirect(pItem, TRUE); | 1078 SetSelectionDirect(pItem, true); |
| 1082 } else { | 1079 } else { |
| 1083 SetSelection(pItem, pItem, TRUE); | 1080 SetSelection(pItem, pItem, true); |
| 1084 m_hAnchor = pItem; | 1081 m_hAnchor = pItem; |
| 1085 } | 1082 } |
| 1086 } else { | 1083 } else { |
| 1087 SetSelection(pItem, pItem, TRUE); | 1084 SetSelection(pItem, pItem, true); |
| 1088 } | 1085 } |
| 1089 | 1086 |
| 1090 SetFocusItem(pItem); | 1087 SetFocusItem(pItem); |
| 1091 ScrollToVisible(pItem); | 1088 ScrollToVisible(pItem); |
| 1092 | 1089 |
| 1093 CFX_RectF rtInvalidate; | 1090 CFX_RectF rtInvalidate; |
| 1094 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 1091 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
| 1095 m_pProperties->m_rtWidget.height); | 1092 m_pProperties->m_rtWidget.height); |
| 1096 Repaint(&rtInvalidate); | 1093 Repaint(&rtInvalidate); |
| 1097 } | 1094 } |
| 1098 | 1095 |
| 1099 FX_BOOL IFWL_ListBox::OnScroll(IFWL_ScrollBar* pScrollBar, | 1096 bool IFWL_ListBox::OnScroll(IFWL_ScrollBar* pScrollBar, |
| 1100 uint32_t dwCode, | 1097 uint32_t dwCode, |
| 1101 FX_FLOAT fPos) { | 1098 FX_FLOAT fPos) { |
| 1102 CFX_SizeF fs; | 1099 CFX_SizeF fs; |
| 1103 pScrollBar->GetRange(fs.x, fs.y); | 1100 pScrollBar->GetRange(fs.x, fs.y); |
| 1104 FX_FLOAT iCurPos = pScrollBar->GetPos(); | 1101 FX_FLOAT iCurPos = pScrollBar->GetPos(); |
| 1105 FX_FLOAT fStep = pScrollBar->GetStepSize(); | 1102 FX_FLOAT fStep = pScrollBar->GetStepSize(); |
| 1106 switch (dwCode) { | 1103 switch (dwCode) { |
| 1107 case FWL_SCBCODE_Min: { | 1104 case FWL_SCBCODE_Min: { |
| 1108 fPos = fs.x; | 1105 fPos = fs.x; |
| 1109 break; | 1106 break; |
| 1110 } | 1107 } |
| 1111 case FWL_SCBCODE_Max: { | 1108 case FWL_SCBCODE_Max: { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1133 case FWL_SCBCODE_PageForward: { | 1130 case FWL_SCBCODE_PageForward: { |
| 1134 fPos += pScrollBar->GetPageSize(); | 1131 fPos += pScrollBar->GetPageSize(); |
| 1135 if (fPos > fs.y) | 1132 if (fPos > fs.y) |
| 1136 fPos = fs.y; | 1133 fPos = fs.y; |
| 1137 break; | 1134 break; |
| 1138 } | 1135 } |
| 1139 case FWL_SCBCODE_Pos: | 1136 case FWL_SCBCODE_Pos: |
| 1140 case FWL_SCBCODE_TrackPos: | 1137 case FWL_SCBCODE_TrackPos: |
| 1141 break; | 1138 break; |
| 1142 case FWL_SCBCODE_EndScroll: | 1139 case FWL_SCBCODE_EndScroll: |
| 1143 return FALSE; | 1140 return false; |
| 1144 } | 1141 } |
| 1145 if (iCurPos != fPos) { | 1142 if (iCurPos != fPos) { |
| 1146 pScrollBar->SetPos(fPos); | 1143 pScrollBar->SetPos(fPos); |
| 1147 pScrollBar->SetTrackPos(fPos); | 1144 pScrollBar->SetTrackPos(fPos); |
| 1148 Repaint(&m_rtClient); | 1145 Repaint(&m_rtClient); |
| 1149 } | 1146 } |
| 1150 return TRUE; | 1147 return true; |
| 1151 } | 1148 } |
| 1152 | 1149 |
| 1153 void IFWL_ListBox::DispatchSelChangedEv() { | 1150 void IFWL_ListBox::DispatchSelChangedEv() { |
| 1154 CFWL_EvtLtbSelChanged ev; | 1151 CFWL_EvtLtbSelChanged ev; |
| 1155 ev.m_pSrcTarget = this; | 1152 ev.m_pSrcTarget = this; |
| 1156 DispatchEvent(&ev); | 1153 DispatchEvent(&ev); |
| 1157 } | 1154 } |
| OLD | NEW |