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_combobox.h" | 7 #include "xfa/fwl/core/ifwl_combobox.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 if (m_iCurSel >= 0) { | 201 if (m_iCurSel >= 0) { |
202 if (!m_pListBox) | 202 if (!m_pListBox) |
203 return; | 203 return; |
204 | 204 |
205 CFX_WideString wsText; | 205 CFX_WideString wsText; |
206 IFWL_ComboBox::DataProvider* pData = | 206 IFWL_ComboBox::DataProvider* pData = |
207 static_cast<IFWL_ComboBox::DataProvider*>( | 207 static_cast<IFWL_ComboBox::DataProvider*>( |
208 m_pProperties->m_pDataProvider); | 208 m_pProperties->m_pDataProvider); |
209 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 209 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
210 m_pListBox->GetItemText(hItem, wsText); | 210 m_pListBox->GetDataProviderItemText(hItem, wsText); |
211 | 211 |
212 CFWL_ThemeText theme_text; | 212 CFWL_ThemeText theme_text; |
213 theme_text.m_pWidget = this; | 213 theme_text.m_pWidget = this; |
214 theme_text.m_iPart = CFWL_Part::Caption; | 214 theme_text.m_iPart = CFWL_Part::Caption; |
215 theme_text.m_dwStates = m_iBtnState; | 215 theme_text.m_dwStates = m_iBtnState; |
216 theme_text.m_pGraphics = pGraphics; | 216 theme_text.m_pGraphics = pGraphics; |
217 theme_text.m_matrix.Concat(*pMatrix); | 217 theme_text.m_matrix.Concat(*pMatrix); |
218 theme_text.m_rtPart = rtTextBk; | 218 theme_text.m_rtPart = rtTextBk; |
219 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 219 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
220 ? CFWL_PartState_Selected | 220 ? CFWL_PartState_Selected |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 bool bClearSel = iSel < 0 || iSel >= iCount; | 254 bool bClearSel = iSel < 0 || iSel >= iCount; |
255 if (IsDropDownStyle() && m_pEdit) { | 255 if (IsDropDownStyle() && m_pEdit) { |
256 if (bClearSel) { | 256 if (bClearSel) { |
257 m_pEdit->SetText(CFX_WideString()); | 257 m_pEdit->SetText(CFX_WideString()); |
258 } else { | 258 } else { |
259 CFX_WideString wsText; | 259 CFX_WideString wsText; |
260 IFWL_ComboBox::DataProvider* pData = | 260 IFWL_ComboBox::DataProvider* pData = |
261 static_cast<IFWL_ComboBox::DataProvider*>( | 261 static_cast<IFWL_ComboBox::DataProvider*>( |
262 m_pProperties->m_pDataProvider); | 262 m_pProperties->m_pDataProvider); |
263 CFWL_ListItem* hItem = pData->GetItem(this, iSel); | 263 CFWL_ListItem* hItem = pData->GetItem(this, iSel); |
264 m_pListBox->GetItemText(hItem, wsText); | 264 m_pListBox->GetDataProviderItemText(hItem, wsText); |
265 m_pEdit->SetText(wsText); | 265 m_pEdit->SetText(wsText); |
266 } | 266 } |
267 m_pEdit->Update(); | 267 m_pEdit->Update(); |
268 } | 268 } |
269 m_iCurSel = bClearSel ? -1 : iSel; | 269 m_iCurSel = bClearSel ? -1 : iSel; |
270 } | 270 } |
271 | 271 |
272 void IFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { | 272 void IFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { |
273 if (IsDropDownStyle() && m_pEdit) | 273 if (IsDropDownStyle() && m_pEdit) |
274 m_pEdit->SetStates(dwStates, bSet); | 274 m_pEdit->SetStates(dwStates, bSet); |
(...skipping 16 matching lines...) Expand all Loading... |
291 if (m_pEdit) { | 291 if (m_pEdit) { |
292 m_pEdit->GetText(wsText, nStart, nCount); | 292 m_pEdit->GetText(wsText, nStart, nCount); |
293 return; | 293 return; |
294 } | 294 } |
295 if (!m_pListBox) | 295 if (!m_pListBox) |
296 return; | 296 return; |
297 | 297 |
298 IFWL_ComboBox::DataProvider* pData = | 298 IFWL_ComboBox::DataProvider* pData = |
299 static_cast<IFWL_ComboBox::DataProvider*>(m_pProperties->m_pDataProvider); | 299 static_cast<IFWL_ComboBox::DataProvider*>(m_pProperties->m_pDataProvider); |
300 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 300 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
301 m_pListBox->GetItemText(hItem, wsText); | 301 m_pListBox->GetDataProviderItemText(hItem, wsText); |
302 } | 302 } |
303 | 303 |
304 void IFWL_ComboBox::OpenDropDownList(bool bActivate) { | 304 void IFWL_ComboBox::OpenDropDownList(bool bActivate) { |
305 ShowDropList(bActivate); | 305 ShowDropList(bActivate); |
306 } | 306 } |
307 | 307 |
308 void IFWL_ComboBox::GetBBox(CFX_RectF& rect) const { | 308 void IFWL_ComboBox::GetBBox(CFX_RectF& rect) const { |
309 if (m_pWidgetMgr->IsFormDisabled()) { | 309 if (m_pWidgetMgr->IsFormDisabled()) { |
310 DisForm_GetBBox(rect); | 310 DisForm_GetBBox(rect); |
311 return; | 311 return; |
312 } | 312 } |
313 | 313 |
314 rect = m_pProperties->m_rtWidget; | 314 rect = m_pProperties->m_rtWidget; |
315 if (!m_pListBox || !IsDropListVisible()) | 315 if (!m_pListBox || !IsDropListVisible()) |
316 return; | 316 return; |
317 | 317 |
318 CFX_RectF rtList; | 318 CFX_RectF rtList; |
319 m_pListBox->GetWidgetRect(rtList); | 319 m_pListBox->GetWidgetRect(rtList); |
320 rtList.Offset(rect.left, rect.top); | 320 rtList.Offset(rect.left, rect.top); |
321 rect.Union(rtList); | 321 rect.Union(rtList); |
322 } | 322 } |
323 | 323 |
324 void IFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | 324 void IFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, |
325 uint32_t dwStylesExRemoved) { | 325 uint32_t dwStylesExRemoved) { |
326 if (m_pEdit) | 326 if (m_pEdit) |
327 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 327 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
328 } | 328 } |
329 | 329 |
330 FX_FLOAT IFWL_ComboBox::GetListHeight() { | 330 FX_FLOAT IFWL_ComboBox::GetDataProviderListHeight() { |
331 return static_cast<IFWL_ComboBox::DataProvider*>( | 331 return static_cast<IFWL_ComboBox::DataProvider*>( |
332 m_pProperties->m_pDataProvider) | 332 m_pProperties->m_pDataProvider) |
333 ->GetListHeight(this); | 333 ->GetListHeight(this); |
334 } | 334 } |
335 | 335 |
336 void IFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, | 336 void IFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, |
337 const CFX_Matrix* pMatrix) { | 337 const CFX_Matrix* pMatrix) { |
338 CFWL_ThemeBackground param; | 338 CFWL_ThemeBackground param; |
339 param.m_pGraphics = pGraphics; | 339 param.m_pGraphics = pGraphics; |
340 param.m_iPart = CFWL_Part::StretchHandler; | 340 param.m_iPart = CFWL_Part::StretchHandler; |
(...skipping 23 matching lines...) Expand all Loading... |
364 return; | 364 return; |
365 } | 365 } |
366 | 366 |
367 m_pListBox->ChangeSelected(m_iCurSel); | 367 m_pListBox->ChangeSelected(m_iCurSel); |
368 ResetListItemAlignment(); | 368 ResetListItemAlignment(); |
369 | 369 |
370 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & | 370 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & |
371 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); | 371 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); |
372 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); | 372 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); |
373 m_pListBox->GetWidgetRect(m_rtList, true); | 373 m_pListBox->GetWidgetRect(m_rtList, true); |
374 FX_FLOAT fHeight = GetListHeight(); | 374 FX_FLOAT fHeight = GetDataProviderListHeight(); |
375 if (fHeight > 0 && m_rtList.height > GetListHeight()) { | 375 if (fHeight > 0 && m_rtList.height > fHeight) { |
376 m_rtList.height = GetListHeight(); | 376 m_rtList.height = fHeight; |
377 m_pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll, 0); | 377 m_pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll, 0); |
378 } | 378 } |
379 | 379 |
380 CFX_RectF rtAnchor; | 380 CFX_RectF rtAnchor; |
381 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, | 381 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, |
382 m_pProperties->m_rtWidget.height); | 382 m_pProperties->m_rtWidget.height); |
383 | 383 |
384 m_rtList.width = std::max(m_rtList.width, m_rtClient.width); | 384 m_rtList.width = std::max(m_rtList.width, m_rtClient.width); |
385 m_rtProxy = m_rtList; | 385 m_rtProxy = m_rtList; |
386 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) | 386 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 m_pEdit->SetSelected(); | 428 m_pEdit->SetSelected(); |
429 } | 429 } |
430 m_iCurSel = iMatch; | 430 m_iCurSel = iMatch; |
431 } | 431 } |
432 | 432 |
433 void IFWL_ComboBox::SyncEditText(int32_t iListItem) { | 433 void IFWL_ComboBox::SyncEditText(int32_t iListItem) { |
434 CFX_WideString wsText; | 434 CFX_WideString wsText; |
435 IFWL_ComboBox::DataProvider* pData = | 435 IFWL_ComboBox::DataProvider* pData = |
436 static_cast<IFWL_ComboBox::DataProvider*>(m_pProperties->m_pDataProvider); | 436 static_cast<IFWL_ComboBox::DataProvider*>(m_pProperties->m_pDataProvider); |
437 CFWL_ListItem* hItem = pData->GetItem(this, iListItem); | 437 CFWL_ListItem* hItem = pData->GetItem(this, iListItem); |
438 m_pListBox->GetItemText(hItem, wsText); | 438 m_pListBox->GetDataProviderItemText(hItem, wsText); |
439 m_pEdit->SetText(wsText); | 439 m_pEdit->SetText(wsText); |
440 m_pEdit->Update(); | 440 m_pEdit->Update(); |
441 m_pEdit->SetSelected(); | 441 m_pEdit->SetSelected(); |
442 } | 442 } |
443 | 443 |
444 void IFWL_ComboBox::Layout() { | 444 void IFWL_ComboBox::Layout() { |
445 if (m_pWidgetMgr->IsFormDisabled()) | 445 if (m_pWidgetMgr->IsFormDisabled()) |
446 return DisForm_Layout(); | 446 return DisForm_Layout(); |
447 | 447 |
448 GetClientRect(m_rtClient); | 448 GetClientRect(m_rtClient); |
(...skipping 12 matching lines...) Expand all Loading... |
461 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, | 461 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, |
462 m_rtClient.height); | 462 m_rtClient.height); |
463 m_pEdit->SetWidgetRect(rtEdit); | 463 m_pEdit->SetWidgetRect(rtEdit); |
464 | 464 |
465 if (m_iCurSel >= 0) { | 465 if (m_iCurSel >= 0) { |
466 CFX_WideString wsText; | 466 CFX_WideString wsText; |
467 IFWL_ComboBox::DataProvider* pData = | 467 IFWL_ComboBox::DataProvider* pData = |
468 static_cast<IFWL_ComboBox::DataProvider*>( | 468 static_cast<IFWL_ComboBox::DataProvider*>( |
469 m_pProperties->m_pDataProvider); | 469 m_pProperties->m_pDataProvider); |
470 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 470 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
471 m_pListBox->GetItemText(hItem, wsText); | 471 m_pListBox->GetDataProviderItemText(hItem, wsText); |
472 m_pEdit->LockUpdate(); | 472 m_pEdit->LockUpdate(); |
473 m_pEdit->SetText(wsText); | 473 m_pEdit->SetText(wsText); |
474 m_pEdit->UnlockUpdate(); | 474 m_pEdit->UnlockUpdate(); |
475 } | 475 } |
476 m_pEdit->Update(); | 476 m_pEdit->Update(); |
477 } | 477 } |
478 | 478 |
479 void IFWL_ComboBox::ResetTheme() { | 479 void IFWL_ComboBox::ResetTheme() { |
480 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 480 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
481 if (!pTheme) { | 481 if (!pTheme) { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, | 797 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, |
798 m_rtContent.height); | 798 m_rtContent.height); |
799 m_pEdit->SetWidgetRect(rtEdit); | 799 m_pEdit->SetWidgetRect(rtEdit); |
800 | 800 |
801 if (m_iCurSel >= 0) { | 801 if (m_iCurSel >= 0) { |
802 CFX_WideString wsText; | 802 CFX_WideString wsText; |
803 IFWL_ComboBox::DataProvider* pData = | 803 IFWL_ComboBox::DataProvider* pData = |
804 static_cast<IFWL_ComboBox::DataProvider*>( | 804 static_cast<IFWL_ComboBox::DataProvider*>( |
805 m_pProperties->m_pDataProvider); | 805 m_pProperties->m_pDataProvider); |
806 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 806 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
807 m_pListBox->GetItemText(hItem, wsText); | 807 m_pListBox->GetDataProviderItemText(hItem, wsText); |
808 m_pEdit->LockUpdate(); | 808 m_pEdit->LockUpdate(); |
809 m_pEdit->SetText(wsText); | 809 m_pEdit->SetText(wsText); |
810 m_pEdit->UnlockUpdate(); | 810 m_pEdit->UnlockUpdate(); |
811 } | 811 } |
812 m_pEdit->Update(); | 812 m_pEdit->Update(); |
813 } | 813 } |
814 | 814 |
815 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { | 815 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { |
816 if (m_pWidgetMgr->IsFormDisabled()) { | 816 if (m_pWidgetMgr->IsFormDisabled()) { |
817 DisForm_OnProcessMessage(pMessage); | 817 DisForm_OnProcessMessage(pMessage); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 if (bDropDown && m_pEdit) { | 983 if (bDropDown && m_pEdit) { |
984 CFX_WideString wsText; | 984 CFX_WideString wsText; |
985 m_pEdit->GetText(wsText); | 985 m_pEdit->GetText(wsText); |
986 iCurSel = m_pListBox->MatchItem(wsText); | 986 iCurSel = m_pListBox->MatchItem(wsText); |
987 if (iCurSel >= 0) { | 987 if (iCurSel >= 0) { |
988 CFX_WideString wsTemp; | 988 CFX_WideString wsTemp; |
989 IFWL_ComboBox::DataProvider* pData = | 989 IFWL_ComboBox::DataProvider* pData = |
990 static_cast<IFWL_ComboBox::DataProvider*>( | 990 static_cast<IFWL_ComboBox::DataProvider*>( |
991 m_pProperties->m_pDataProvider); | 991 m_pProperties->m_pDataProvider); |
992 CFWL_ListItem* hItem = pData->GetItem(this, iCurSel); | 992 CFWL_ListItem* hItem = pData->GetItem(this, iCurSel); |
993 m_pListBox->GetItemText(hItem, wsTemp); | 993 m_pListBox->GetDataProviderItemText(hItem, wsTemp); |
994 bMatchEqual = wsText == wsTemp; | 994 bMatchEqual = wsText == wsTemp; |
995 } | 995 } |
996 } | 996 } |
997 if (iCurSel < 0) { | 997 if (iCurSel < 0) { |
998 iCurSel = 0; | 998 iCurSel = 0; |
999 } else if (!bDropDown || bMatchEqual) { | 999 } else if (!bDropDown || bMatchEqual) { |
1000 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) | 1000 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
1001 return; | 1001 return; |
1002 if (bUp) | 1002 if (bUp) |
1003 iCurSel--; | 1003 iCurSel--; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 | 1119 |
1120 bool bMatchEqual = false; | 1120 bool bMatchEqual = false; |
1121 int32_t iCurSel = m_iCurSel; | 1121 int32_t iCurSel = m_iCurSel; |
1122 if (m_pEdit) { | 1122 if (m_pEdit) { |
1123 CFX_WideString wsText; | 1123 CFX_WideString wsText; |
1124 m_pEdit->GetText(wsText); | 1124 m_pEdit->GetText(wsText); |
1125 iCurSel = pComboList->MatchItem(wsText); | 1125 iCurSel = pComboList->MatchItem(wsText); |
1126 if (iCurSel >= 0) { | 1126 if (iCurSel >= 0) { |
1127 CFX_WideString wsTemp; | 1127 CFX_WideString wsTemp; |
1128 CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); | 1128 CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); |
1129 m_pListBox->GetItemText(item, wsTemp); | 1129 m_pListBox->GetDataProviderItemText(item, wsTemp); |
1130 bMatchEqual = wsText == wsTemp; | 1130 bMatchEqual = wsText == wsTemp; |
1131 } | 1131 } |
1132 } | 1132 } |
1133 if (iCurSel < 0) { | 1133 if (iCurSel < 0) { |
1134 iCurSel = 0; | 1134 iCurSel = 0; |
1135 } else if (bMatchEqual) { | 1135 } else if (bMatchEqual) { |
1136 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) | 1136 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
1137 return; | 1137 return; |
1138 if (bUp) | 1138 if (bUp) |
1139 iCurSel--; | 1139 iCurSel--; |
1140 else | 1140 else |
1141 iCurSel++; | 1141 iCurSel++; |
1142 } | 1142 } |
1143 m_iCurSel = iCurSel; | 1143 m_iCurSel = iCurSel; |
1144 SyncEditText(m_iCurSel); | 1144 SyncEditText(m_iCurSel); |
1145 return; | 1145 return; |
1146 } | 1146 } |
1147 if (m_pEdit) | 1147 if (m_pEdit) |
1148 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1148 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1149 } | 1149 } |
OLD | NEW |