| 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" |
| 11 #include "xfa/fwl/core/cfwl_msgkey.h" | 11 #include "xfa/fwl/core/cfwl_msgkey.h" |
| 12 #include "xfa/fwl/core/cfwl_msgmouse.h" | 12 #include "xfa/fwl/core/cfwl_msgmouse.h" |
| 13 #include "xfa/fwl/core/cfwl_msgmousewheel.h" | 13 #include "xfa/fwl/core/cfwl_msgmousewheel.h" |
| 14 #include "xfa/fwl/core/cfwl_themebackground.h" | 14 #include "xfa/fwl/core/cfwl_themebackground.h" |
| 15 #include "xfa/fwl/core/cfwl_themepart.h" | 15 #include "xfa/fwl/core/cfwl_themepart.h" |
| 16 #include "xfa/fwl/core/cfwl_themetext.h" | 16 #include "xfa/fwl/core/cfwl_themetext.h" |
| 17 #include "xfa/fwl/core/ifwl_app.h" | 17 #include "xfa/fwl/core/ifwl_app.h" |
| 18 #include "xfa/fwl/core/ifwl_listbox.h" |
| 18 #include "xfa/fwl/core/ifwl_themeprovider.h" | 19 #include "xfa/fwl/core/ifwl_themeprovider.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 const int kItemTextMargin = 2; | 23 const int kItemTextMargin = 2; |
| 23 | 24 |
| 24 } // namespace | 25 } // namespace |
| 25 | 26 |
| 26 IFWL_ListBox::IFWL_ListBox(const IFWL_App* app, | 27 IFWL_ListBox::IFWL_ListBox(const IFWL_App* app, |
| 27 std::unique_ptr<CFWL_WidgetProperties> properties, | 28 std::unique_ptr<CFWL_WidgetProperties> properties, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 void IFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | 140 void IFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { |
| 140 if (pThemeProvider) | 141 if (pThemeProvider) |
| 141 m_pProperties->m_pThemeProvider = pThemeProvider; | 142 m_pProperties->m_pThemeProvider = pThemeProvider; |
| 142 } | 143 } |
| 143 | 144 |
| 144 int32_t IFWL_ListBox::CountSelItems() { | 145 int32_t IFWL_ListBox::CountSelItems() { |
| 145 if (!m_pProperties->m_pDataProvider) | 146 if (!m_pProperties->m_pDataProvider) |
| 146 return 0; | 147 return 0; |
| 147 | 148 |
| 148 int32_t iRet = 0; | 149 int32_t iRet = 0; |
| 149 IFWL_ListBoxDP* pData = | 150 IFWL_ListBox::DataProvider* pData = |
| 150 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 151 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 151 int32_t iCount = pData->CountItems(this); | 152 int32_t iCount = pData->CountItems(this); |
| 152 for (int32_t i = 0; i < iCount; i++) { | 153 for (int32_t i = 0; i < iCount; i++) { |
| 153 CFWL_ListItem* pItem = pData->GetItem(this, i); | 154 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 154 if (!pItem) | 155 if (!pItem) |
| 155 continue; | 156 continue; |
| 156 | 157 |
| 157 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | 158 uint32_t dwStyle = pData->GetItemStyles(this, pItem); |
| 158 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) | 159 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) |
| 159 iRet++; | 160 iRet++; |
| 160 } | 161 } |
| 161 return iRet; | 162 return iRet; |
| 162 } | 163 } |
| 163 | 164 |
| 164 CFWL_ListItem* IFWL_ListBox::GetSelItem(int32_t nIndexSel) { | 165 CFWL_ListItem* IFWL_ListBox::GetSelItem(int32_t nIndexSel) { |
| 165 int32_t idx = GetSelIndex(nIndexSel); | 166 int32_t idx = GetSelIndex(nIndexSel); |
| 166 if (idx < 0) | 167 if (idx < 0) |
| 167 return nullptr; | 168 return nullptr; |
| 168 IFWL_ListBoxDP* pData = | 169 IFWL_ListBox::DataProvider* pData = |
| 169 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 170 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 170 return pData->GetItem(this, idx); | 171 return pData->GetItem(this, idx); |
| 171 } | 172 } |
| 172 | 173 |
| 173 int32_t IFWL_ListBox::GetSelIndex(int32_t nIndex) { | 174 int32_t IFWL_ListBox::GetSelIndex(int32_t nIndex) { |
| 174 if (!m_pProperties->m_pDataProvider) | 175 if (!m_pProperties->m_pDataProvider) |
| 175 return -1; | 176 return -1; |
| 176 | 177 |
| 177 int32_t index = 0; | 178 int32_t index = 0; |
| 178 IFWL_ListBoxDP* pData = | 179 IFWL_ListBox::DataProvider* pData = |
| 179 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 180 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 180 int32_t iCount = pData->CountItems(this); | 181 int32_t iCount = pData->CountItems(this); |
| 181 for (int32_t i = 0; i < iCount; i++) { | 182 for (int32_t i = 0; i < iCount; i++) { |
| 182 CFWL_ListItem* pItem = pData->GetItem(this, i); | 183 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 183 if (!pItem) | 184 if (!pItem) |
| 184 return -1; | 185 return -1; |
| 185 | 186 |
| 186 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | 187 uint32_t dwStyle = pData->GetItemStyles(this, pItem); |
| 187 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { | 188 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { |
| 188 if (index == nIndex) | 189 if (index == nIndex) |
| 189 return i; | 190 return i; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 208 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) | 209 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) |
| 209 SetSelectionDirect(pItem, bSelect); | 210 SetSelectionDirect(pItem, bSelect); |
| 210 else | 211 else |
| 211 SetSelection(pItem, pItem, bSelect); | 212 SetSelection(pItem, pItem, bSelect); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void IFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) { | 215 void IFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) { |
| 215 if (!m_pProperties->m_pDataProvider) | 216 if (!m_pProperties->m_pDataProvider) |
| 216 return; | 217 return; |
| 217 | 218 |
| 218 IFWL_ListBoxDP* pData = | 219 IFWL_ListBox::DataProvider* pData = |
| 219 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 220 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 220 if (!pItem) | 221 if (!pItem) |
| 221 return; | 222 return; |
| 222 | 223 |
| 223 pData->GetItemText(this, pItem, wsText); | 224 pData->GetItemText(this, pItem, wsText); |
| 224 } | 225 } |
| 225 | 226 |
| 226 CFWL_ListItem* IFWL_ListBox::GetItem(CFWL_ListItem* pItem, uint32_t dwKeyCode) { | 227 CFWL_ListItem* IFWL_ListBox::GetItem(CFWL_ListItem* pItem, uint32_t dwKeyCode) { |
| 227 CFWL_ListItem* hRet = nullptr; | 228 CFWL_ListItem* hRet = nullptr; |
| 228 switch (dwKeyCode) { | 229 switch (dwKeyCode) { |
| 229 case FWL_VKEY_Up: | 230 case FWL_VKEY_Up: |
| 230 case FWL_VKEY_Down: | 231 case FWL_VKEY_Down: |
| 231 case FWL_VKEY_Home: | 232 case FWL_VKEY_Home: |
| 232 case FWL_VKEY_End: { | 233 case FWL_VKEY_End: { |
| 233 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 234 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
| 234 const bool bDown = dwKeyCode == FWL_VKEY_Down; | 235 const bool bDown = dwKeyCode == FWL_VKEY_Down; |
| 235 const bool bHome = dwKeyCode == FWL_VKEY_Home; | 236 const bool bHome = dwKeyCode == FWL_VKEY_Home; |
| 236 IFWL_ListBoxDP* pData = | 237 IFWL_ListBox::DataProvider* pData = |
| 237 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 238 static_cast<IFWL_ListBox::DataProvider*>( |
| 239 m_pProperties->m_pDataProvider); |
| 238 int32_t iDstItem = -1; | 240 int32_t iDstItem = -1; |
| 239 if (bUp || bDown) { | 241 if (bUp || bDown) { |
| 240 int32_t index = pData->GetItemIndex(this, pItem); | 242 int32_t index = pData->GetItemIndex(this, pItem); |
| 241 iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; | 243 iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; |
| 242 } else if (bHome) { | 244 } else if (bHome) { |
| 243 iDstItem = 0; | 245 iDstItem = 0; |
| 244 } else { | 246 } else { |
| 245 int32_t iCount = pData->CountItems(this); | 247 int32_t iCount = pData->CountItems(this); |
| 246 iDstItem = iCount - 1; | 248 iDstItem = iCount - 1; |
| 247 } | 249 } |
| 248 hRet = pData->GetItem(this, iDstItem); | 250 hRet = pData->GetItem(this, iDstItem); |
| 249 break; | 251 break; |
| 250 } | 252 } |
| 251 default: | 253 default: |
| 252 break; | 254 break; |
| 253 } | 255 } |
| 254 return hRet; | 256 return hRet; |
| 255 } | 257 } |
| 256 | 258 |
| 257 void IFWL_ListBox::SetSelection(CFWL_ListItem* hStart, | 259 void IFWL_ListBox::SetSelection(CFWL_ListItem* hStart, |
| 258 CFWL_ListItem* hEnd, | 260 CFWL_ListItem* hEnd, |
| 259 bool bSelected) { | 261 bool bSelected) { |
| 260 IFWL_ListBoxDP* pData = | 262 IFWL_ListBox::DataProvider* pData = |
| 261 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 263 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 262 int32_t iStart = pData->GetItemIndex(this, hStart); | 264 int32_t iStart = pData->GetItemIndex(this, hStart); |
| 263 int32_t iEnd = pData->GetItemIndex(this, hEnd); | 265 int32_t iEnd = pData->GetItemIndex(this, hEnd); |
| 264 if (iStart > iEnd) { | 266 if (iStart > iEnd) { |
| 265 int32_t iTemp = iStart; | 267 int32_t iTemp = iStart; |
| 266 iStart = iEnd; | 268 iStart = iEnd; |
| 267 iEnd = iTemp; | 269 iEnd = iTemp; |
| 268 } | 270 } |
| 269 if (bSelected) { | 271 if (bSelected) { |
| 270 int32_t iCount = pData->CountItems(this); | 272 int32_t iCount = pData->CountItems(this); |
| 271 for (int32_t i = 0; i < iCount; i++) { | 273 for (int32_t i = 0; i < iCount; i++) { |
| 272 CFWL_ListItem* pItem = pData->GetItem(this, i); | 274 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 273 SetSelectionDirect(pItem, false); | 275 SetSelectionDirect(pItem, false); |
| 274 } | 276 } |
| 275 } | 277 } |
| 276 for (; iStart <= iEnd; iStart++) { | 278 for (; iStart <= iEnd; iStart++) { |
| 277 CFWL_ListItem* pItem = pData->GetItem(this, iStart); | 279 CFWL_ListItem* pItem = pData->GetItem(this, iStart); |
| 278 SetSelectionDirect(pItem, bSelected); | 280 SetSelectionDirect(pItem, bSelected); |
| 279 } | 281 } |
| 280 } | 282 } |
| 281 | 283 |
| 282 void IFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { | 284 void IFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { |
| 283 IFWL_ListBoxDP* pData = | 285 IFWL_ListBox::DataProvider* pData = |
| 284 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 286 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 285 uint32_t dwOldStyle = pData->GetItemStyles(this, pItem); | 287 uint32_t dwOldStyle = pData->GetItemStyles(this, pItem); |
| 286 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected | 288 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected |
| 287 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; | 289 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; |
| 288 pData->SetItemStyles(this, pItem, dwOldStyle); | 290 pData->SetItemStyles(this, pItem, dwOldStyle); |
| 289 } | 291 } |
| 290 | 292 |
| 291 bool IFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { | 293 bool IFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { |
| 292 IFWL_ListBoxDP* pData = | 294 IFWL_ListBox::DataProvider* pData = |
| 293 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 295 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 294 uint32_t dwState = pData->GetItemStyles(this, pItem); | 296 uint32_t dwState = pData->GetItemStyles(this, pItem); |
| 295 return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; | 297 return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; |
| 296 } | 298 } |
| 297 | 299 |
| 298 void IFWL_ListBox::ClearSelection() { | 300 void IFWL_ListBox::ClearSelection() { |
| 299 bool bMulti = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; | 301 bool bMulti = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; |
| 300 IFWL_ListBoxDP* pData = | 302 IFWL_ListBox::DataProvider* pData = |
| 301 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 303 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 302 int32_t iCount = pData->CountItems(this); | 304 int32_t iCount = pData->CountItems(this); |
| 303 for (int32_t i = 0; i < iCount; i++) { | 305 for (int32_t i = 0; i < iCount; i++) { |
| 304 CFWL_ListItem* pItem = pData->GetItem(this, i); | 306 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 305 uint32_t dwState = pData->GetItemStyles(this, pItem); | 307 uint32_t dwState = pData->GetItemStyles(this, pItem); |
| 306 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) | 308 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) |
| 307 continue; | 309 continue; |
| 308 SetSelectionDirect(pItem, false); | 310 SetSelectionDirect(pItem, false); |
| 309 if (!bMulti) | 311 if (!bMulti) |
| 310 return; | 312 return; |
| 311 } | 313 } |
| 312 } | 314 } |
| 313 | 315 |
| 314 void IFWL_ListBox::SelectAll() { | 316 void IFWL_ListBox::SelectAll() { |
| 315 if (!m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) | 317 if (!m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) |
| 316 return; | 318 return; |
| 317 | 319 |
| 318 IFWL_ListBoxDP* pData = | 320 IFWL_ListBox::DataProvider* pData = |
| 319 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 321 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 320 int32_t iCount = pData->CountItems(this); | 322 int32_t iCount = pData->CountItems(this); |
| 321 if (iCount <= 0) | 323 if (iCount <= 0) |
| 322 return; | 324 return; |
| 323 | 325 |
| 324 CFWL_ListItem* pItemStart = pData->GetItem(this, 0); | 326 CFWL_ListItem* pItemStart = pData->GetItem(this, 0); |
| 325 CFWL_ListItem* pItemEnd = pData->GetItem(this, iCount - 1); | 327 CFWL_ListItem* pItemEnd = pData->GetItem(this, iCount - 1); |
| 326 SetSelection(pItemStart, pItemEnd, false); | 328 SetSelection(pItemStart, pItemEnd, false); |
| 327 } | 329 } |
| 328 | 330 |
| 329 CFWL_ListItem* IFWL_ListBox::GetFocusedItem() { | 331 CFWL_ListItem* IFWL_ListBox::GetFocusedItem() { |
| 330 IFWL_ListBoxDP* pData = | 332 IFWL_ListBox::DataProvider* pData = |
| 331 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 333 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 332 int32_t iCount = pData->CountItems(this); | 334 int32_t iCount = pData->CountItems(this); |
| 333 for (int32_t i = 0; i < iCount; i++) { | 335 for (int32_t i = 0; i < iCount; i++) { |
| 334 CFWL_ListItem* pItem = pData->GetItem(this, i); | 336 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 335 if (!pItem) | 337 if (!pItem) |
| 336 return nullptr; | 338 return nullptr; |
| 337 if (pData->GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) | 339 if (pData->GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) |
| 338 return pItem; | 340 return pItem; |
| 339 } | 341 } |
| 340 return nullptr; | 342 return nullptr; |
| 341 } | 343 } |
| 342 | 344 |
| 343 void IFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { | 345 void IFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { |
| 344 IFWL_ListBoxDP* pData = | 346 IFWL_ListBox::DataProvider* pData = |
| 345 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 347 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 346 CFWL_ListItem* hFocus = GetFocusedItem(); | 348 CFWL_ListItem* hFocus = GetFocusedItem(); |
| 347 if (pItem == hFocus) | 349 if (pItem == hFocus) |
| 348 return; | 350 return; |
| 349 | 351 |
| 350 if (hFocus) { | 352 if (hFocus) { |
| 351 uint32_t dwStyle = pData->GetItemStyles(this, hFocus); | 353 uint32_t dwStyle = pData->GetItemStyles(this, hFocus); |
| 352 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; | 354 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; |
| 353 pData->SetItemStyles(this, hFocus, dwStyle); | 355 pData->SetItemStyles(this, hFocus, dwStyle); |
| 354 } | 356 } |
| 355 if (pItem) { | 357 if (pItem) { |
| 356 uint32_t dwStyle = pData->GetItemStyles(this, pItem); | 358 uint32_t dwStyle = pData->GetItemStyles(this, pItem); |
| 357 dwStyle |= FWL_ITEMSTATE_LTB_Focused; | 359 dwStyle |= FWL_ITEMSTATE_LTB_Focused; |
| 358 pData->SetItemStyles(this, pItem, dwStyle); | 360 pData->SetItemStyles(this, pItem, dwStyle); |
| 359 } | 361 } |
| 360 } | 362 } |
| 361 | 363 |
| 362 CFWL_ListItem* IFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { | 364 CFWL_ListItem* IFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { |
| 363 fx -= m_rtConent.left, fy -= m_rtConent.top; | 365 fx -= m_rtConent.left, fy -= m_rtConent.top; |
| 364 FX_FLOAT fPosX = 0.0f; | 366 FX_FLOAT fPosX = 0.0f; |
| 365 if (m_pHorzScrollBar) | 367 if (m_pHorzScrollBar) |
| 366 fPosX = m_pHorzScrollBar->GetPos(); | 368 fPosX = m_pHorzScrollBar->GetPos(); |
| 367 | 369 |
| 368 FX_FLOAT fPosY = 0.0; | 370 FX_FLOAT fPosY = 0.0; |
| 369 if (m_pVertScrollBar) | 371 if (m_pVertScrollBar) |
| 370 fPosY = m_pVertScrollBar->GetPos(); | 372 fPosY = m_pVertScrollBar->GetPos(); |
| 371 | 373 |
| 372 IFWL_ListBoxDP* pData = | 374 IFWL_ListBox::DataProvider* pData = |
| 373 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 375 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 374 int32_t nCount = pData->CountItems(this); | 376 int32_t nCount = pData->CountItems(this); |
| 375 for (int32_t i = 0; i < nCount; i++) { | 377 for (int32_t i = 0; i < nCount; i++) { |
| 376 CFWL_ListItem* pItem = pData->GetItem(this, i); | 378 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 377 if (!pItem) | 379 if (!pItem) |
| 378 continue; | 380 continue; |
| 379 | 381 |
| 380 CFX_RectF rtItem; | 382 CFX_RectF rtItem; |
| 381 pData->GetItemRect(this, pItem, rtItem); | 383 pData->GetItemRect(this, pItem, rtItem); |
| 382 rtItem.Offset(-fPosX, -fPosY); | 384 rtItem.Offset(-fPosX, -fPosY); |
| 383 if (rtItem.Contains(fx, fy)) | 385 if (rtItem.Contains(fx, fy)) |
| 384 return pItem; | 386 return pItem; |
| 385 } | 387 } |
| 386 return nullptr; | 388 return nullptr; |
| 387 } | 389 } |
| 388 | 390 |
| 389 bool IFWL_ListBox::GetItemCheckRect(CFWL_ListItem* pItem, CFX_RectF& rtCheck) { | 391 bool IFWL_ListBox::GetItemCheckRect(CFWL_ListItem* pItem, CFX_RectF& rtCheck) { |
| 390 if (!m_pProperties->m_pDataProvider) | 392 if (!m_pProperties->m_pDataProvider) |
| 391 return false; | 393 return false; |
| 392 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) | 394 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) |
| 393 return false; | 395 return false; |
| 394 | 396 |
| 395 IFWL_ListBoxDP* pData = | 397 IFWL_ListBox::DataProvider* pData = |
| 396 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 398 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 397 pData->GetItemCheckRect(this, pItem, rtCheck); | 399 pData->GetItemCheckRect(this, pItem, rtCheck); |
| 398 return true; | 400 return true; |
| 399 } | 401 } |
| 400 | 402 |
| 401 bool IFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { | 403 bool IFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { |
| 402 if (!m_pProperties->m_pDataProvider) | 404 if (!m_pProperties->m_pDataProvider) |
| 403 return false; | 405 return false; |
| 404 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) | 406 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) |
| 405 return false; | 407 return false; |
| 406 | 408 |
| 407 IFWL_ListBoxDP* pData = | 409 IFWL_ListBox::DataProvider* pData = |
| 408 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 410 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 409 return !!(pData->GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); | 411 return !!(pData->GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); |
| 410 } | 412 } |
| 411 | 413 |
| 412 bool IFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { | 414 bool IFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { |
| 413 if (!m_pProperties->m_pDataProvider) | 415 if (!m_pProperties->m_pDataProvider) |
| 414 return false; | 416 return false; |
| 415 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) | 417 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) |
| 416 return false; | 418 return false; |
| 417 | 419 |
| 418 IFWL_ListBoxDP* pData = | 420 IFWL_ListBox::DataProvider* pData = |
| 419 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 421 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 420 pData->SetItemCheckState(this, pItem, | 422 pData->SetItemCheckState(this, pItem, |
| 421 bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); | 423 bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); |
| 422 return true; | 424 return true; |
| 423 } | 425 } |
| 424 | 426 |
| 425 bool IFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { | 427 bool IFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { |
| 426 if (!m_pVertScrollBar) | 428 if (!m_pVertScrollBar) |
| 427 return false; | 429 return false; |
| 428 | 430 |
| 429 CFX_RectF rtItem; | 431 CFX_RectF rtItem; |
| 430 IFWL_ListBoxDP* pData = | 432 IFWL_ListBox::DataProvider* pData = |
| 431 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 433 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 432 pData->GetItemRect(this, pItem, rtItem); | 434 pData->GetItemRect(this, pItem, rtItem); |
| 433 | 435 |
| 434 bool bScroll = false; | 436 bool bScroll = false; |
| 435 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); | 437 FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); |
| 436 rtItem.Offset(0, -fPosY + m_rtConent.top); | 438 rtItem.Offset(0, -fPosY + m_rtConent.top); |
| 437 if (rtItem.top < m_rtConent.top) { | 439 if (rtItem.top < m_rtConent.top) { |
| 438 fPosY += rtItem.top - m_rtConent.top; | 440 fPosY += rtItem.top - m_rtConent.top; |
| 439 bScroll = true; | 441 bScroll = true; |
| 440 } else if (rtItem.bottom() > m_rtConent.bottom()) { | 442 } else if (rtItem.bottom() > m_rtConent.bottom()) { |
| 441 fPosY += rtItem.bottom() - m_rtConent.bottom(); | 443 fPosY += rtItem.bottom() - m_rtConent.bottom(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 fPosY = m_pVertScrollBar->GetPos(); | 487 fPosY = m_pVertScrollBar->GetPos(); |
| 486 | 488 |
| 487 CFX_RectF rtView(m_rtConent); | 489 CFX_RectF rtView(m_rtConent); |
| 488 if (m_pHorzScrollBar) | 490 if (m_pHorzScrollBar) |
| 489 rtView.height -= m_fScorllBarWidth; | 491 rtView.height -= m_fScorllBarWidth; |
| 490 if (m_pVertScrollBar) | 492 if (m_pVertScrollBar) |
| 491 rtView.width -= m_fScorllBarWidth; | 493 rtView.width -= m_fScorllBarWidth; |
| 492 | 494 |
| 493 bool bMultiCol = | 495 bool bMultiCol = |
| 494 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); | 496 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn); |
| 495 IFWL_ListBoxDP* pData = | 497 IFWL_ListBox::DataProvider* pData = |
| 496 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 498 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 497 int32_t iCount = pData->CountItems(this); | 499 int32_t iCount = pData->CountItems(this); |
| 498 for (int32_t i = 0; i < iCount; i++) { | 500 for (int32_t i = 0; i < iCount; i++) { |
| 499 CFWL_ListItem* pItem = pData->GetItem(this, i); | 501 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 500 if (!pItem) | 502 if (!pItem) |
| 501 continue; | 503 continue; |
| 502 | 504 |
| 503 CFX_RectF rtItem; | 505 CFX_RectF rtItem; |
| 504 pData->GetItemRect(this, pItem, rtItem); | 506 pData->GetItemRect(this, pItem, rtItem); |
| 505 rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); | 507 rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); |
| 506 if (rtItem.bottom() < m_rtConent.top) | 508 if (rtItem.bottom() < m_rtConent.top) |
| 507 continue; | 509 continue; |
| 508 if (rtItem.top >= m_rtConent.bottom()) | 510 if (rtItem.top >= m_rtConent.bottom()) |
| 509 break; | 511 break; |
| 510 if (bMultiCol && rtItem.left > m_rtConent.right()) | 512 if (bMultiCol && rtItem.left > m_rtConent.right()) |
| 511 break; | 513 break; |
| 512 | 514 |
| 513 if (!(GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw)) | 515 if (!(GetStylesEx() & FWL_STYLEEXT_LTB_OwnerDraw)) |
| 514 DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); | 516 DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix); |
| 515 } | 517 } |
| 516 } | 518 } |
| 517 | 519 |
| 518 void IFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, | 520 void IFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, |
| 519 IFWL_ThemeProvider* pTheme, | 521 IFWL_ThemeProvider* pTheme, |
| 520 CFWL_ListItem* pItem, | 522 CFWL_ListItem* pItem, |
| 521 int32_t Index, | 523 int32_t Index, |
| 522 const CFX_RectF& rtItem, | 524 const CFX_RectF& rtItem, |
| 523 const CFX_Matrix* pMatrix) { | 525 const CFX_Matrix* pMatrix) { |
| 524 IFWL_ListBoxDP* pData = | 526 IFWL_ListBox::DataProvider* pData = |
| 525 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 527 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 526 uint32_t dwItemStyles = pData->GetItemStyles(this, pItem); | 528 uint32_t dwItemStyles = pData->GetItemStyles(this, pItem); |
| 527 uint32_t dwPartStates = CFWL_PartState_Normal; | 529 uint32_t dwPartStates = CFWL_PartState_Normal; |
| 528 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 530 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 529 dwPartStates = CFWL_PartState_Disabled; | 531 dwPartStates = CFWL_PartState_Disabled; |
| 530 else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) | 532 else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected) |
| 531 dwPartStates = CFWL_PartState_Selected; | 533 dwPartStates = CFWL_PartState_Selected; |
| 532 | 534 |
| 533 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && | 535 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && |
| 534 dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { | 536 dwItemStyles & FWL_ITEMSTATE_LTB_Focused) { |
| 535 dwPartStates |= CFWL_PartState_Focused; | 537 dwPartStates |= CFWL_PartState_Focused; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( | 630 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( |
| 629 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); | 631 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); |
| 630 if (pUIMargin) { | 632 if (pUIMargin) { |
| 631 m_rtConent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | 633 m_rtConent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, |
| 632 pUIMargin->height); | 634 pUIMargin->height); |
| 633 } | 635 } |
| 634 } | 636 } |
| 635 | 637 |
| 636 FX_FLOAT fWidth = 0; | 638 FX_FLOAT fWidth = 0; |
| 637 if (m_pProperties->m_pThemeProvider->IsCustomizedLayout(this)) { | 639 if (m_pProperties->m_pThemeProvider->IsCustomizedLayout(this)) { |
| 638 IFWL_ListBoxDP* pData = | 640 IFWL_ListBox::DataProvider* pData = |
| 639 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 641 static_cast<IFWL_ListBox::DataProvider*>( |
| 642 m_pProperties->m_pDataProvider); |
| 640 int32_t iCount = pData->CountItems(this); | 643 int32_t iCount = pData->CountItems(this); |
| 641 for (int32_t i = 0; i < iCount; i++) { | 644 for (int32_t i = 0; i < iCount; i++) { |
| 642 CFWL_ListItem* pItem = pData->GetItem(this, i); | 645 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 643 if (!bAutoSize) { | 646 if (!bAutoSize) { |
| 644 CFX_RectF rtItem; | 647 CFX_RectF rtItem; |
| 645 rtItem.Set(m_rtClient.left, m_rtClient.top + fs.y, 0, 0); | 648 rtItem.Set(m_rtClient.left, m_rtClient.top + fs.y, 0, 0); |
| 646 IFWL_ListBoxDP* pBox = | 649 IFWL_ListBox::DataProvider* pBox = |
| 647 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 650 static_cast<IFWL_ListBox::DataProvider*>( |
| 651 m_pProperties->m_pDataProvider); |
| 648 pBox->SetItemRect(this, pItem, rtItem); | 652 pBox->SetItemRect(this, pItem, rtItem); |
| 649 } | 653 } |
| 650 if (fs.x < 0) { | 654 if (fs.x < 0) { |
| 651 fs.x = 0; | 655 fs.x = 0; |
| 652 fWidth = 0; | 656 fWidth = 0; |
| 653 } | 657 } |
| 654 } | 658 } |
| 655 } else { | 659 } else { |
| 656 fWidth = GetMaxTextWidth(); | 660 fWidth = GetMaxTextWidth(); |
| 657 fWidth += 2 * kItemTextMargin; | 661 fWidth += 2 * kItemTextMargin; |
| 658 if (!bAutoSize) { | 662 if (!bAutoSize) { |
| 659 FX_FLOAT fActualWidth = | 663 FX_FLOAT fActualWidth = |
| 660 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 664 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
| 661 fWidth = std::max(fWidth, fActualWidth); | 665 fWidth = std::max(fWidth, fActualWidth); |
| 662 } | 666 } |
| 663 | 667 |
| 664 IFWL_ListBoxDP* pData = | 668 IFWL_ListBox::DataProvider* pData = |
| 665 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 669 static_cast<IFWL_ListBox::DataProvider*>( |
| 670 m_pProperties->m_pDataProvider); |
| 666 m_fItemHeight = CalcItemHeight(); | 671 m_fItemHeight = CalcItemHeight(); |
| 667 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) | 672 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) |
| 668 fWidth += m_fItemHeight; | 673 fWidth += m_fItemHeight; |
| 669 | 674 |
| 670 int32_t iCount = pData->CountItems(this); | 675 int32_t iCount = pData->CountItems(this); |
| 671 for (int32_t i = 0; i < iCount; i++) { | 676 for (int32_t i = 0; i < iCount; i++) { |
| 672 CFWL_ListItem* htem = pData->GetItem(this, i); | 677 CFWL_ListItem* htem = pData->GetItem(this, i); |
| 673 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); | 678 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); |
| 674 } | 679 } |
| 675 } | 680 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 CFWL_ListItem* pItem, | 773 CFWL_ListItem* pItem, |
| 769 FX_FLOAT fWidth, | 774 FX_FLOAT fWidth, |
| 770 FX_FLOAT fItemHeight, | 775 FX_FLOAT fItemHeight, |
| 771 bool bAutoSize) { | 776 bool bAutoSize) { |
| 772 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) | 777 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) |
| 773 return; | 778 return; |
| 774 | 779 |
| 775 if (!bAutoSize) { | 780 if (!bAutoSize) { |
| 776 CFX_RectF rtItem; | 781 CFX_RectF rtItem; |
| 777 rtItem.Set(0, size.y, fWidth, fItemHeight); | 782 rtItem.Set(0, size.y, fWidth, fItemHeight); |
| 778 IFWL_ListBoxDP* pData = | 783 IFWL_ListBox::DataProvider* pData = |
| 779 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 784 static_cast<IFWL_ListBox::DataProvider*>( |
| 785 m_pProperties->m_pDataProvider); |
| 780 pData->SetItemRect(this, pItem, rtItem); | 786 pData->SetItemRect(this, pItem, rtItem); |
| 781 } | 787 } |
| 782 size.x = fWidth; | 788 size.x = fWidth; |
| 783 size.y += fItemHeight; | 789 size.y += fItemHeight; |
| 784 } | 790 } |
| 785 | 791 |
| 786 FX_FLOAT IFWL_ListBox::GetMaxTextWidth() { | 792 FX_FLOAT IFWL_ListBox::GetMaxTextWidth() { |
| 787 FX_FLOAT fRet = 0.0f; | 793 FX_FLOAT fRet = 0.0f; |
| 788 IFWL_ListBoxDP* pData = | 794 IFWL_ListBox::DataProvider* pData = |
| 789 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 795 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 790 int32_t iCount = pData->CountItems(this); | 796 int32_t iCount = pData->CountItems(this); |
| 791 for (int32_t i = 0; i < iCount; i++) { | 797 for (int32_t i = 0; i < iCount; i++) { |
| 792 CFWL_ListItem* pItem = pData->GetItem(this, i); | 798 CFWL_ListItem* pItem = pData->GetItem(this, i); |
| 793 if (!pItem) | 799 if (!pItem) |
| 794 continue; | 800 continue; |
| 795 | 801 |
| 796 CFX_WideString wsText; | 802 CFX_WideString wsText; |
| 797 pData->GetItemText(this, pItem, wsText); | 803 pData->GetItemText(this, pItem, wsText); |
| 798 CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider); | 804 CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider); |
| 799 fRet = std::max(fRet, sz.x); | 805 fRet = std::max(fRet, sz.x); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 case FWL_SCBCODE::EndScroll: | 1078 case FWL_SCBCODE::EndScroll: |
| 1073 return false; | 1079 return false; |
| 1074 } | 1080 } |
| 1075 if (iCurPos != fPos) { | 1081 if (iCurPos != fPos) { |
| 1076 pScrollBar->SetPos(fPos); | 1082 pScrollBar->SetPos(fPos); |
| 1077 pScrollBar->SetTrackPos(fPos); | 1083 pScrollBar->SetTrackPos(fPos); |
| 1078 Repaint(&m_rtClient); | 1084 Repaint(&m_rtClient); |
| 1079 } | 1085 } |
| 1080 return true; | 1086 return true; |
| 1081 } | 1087 } |
| OLD | NEW |