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/basewidget/fwl_listboximp.h" | 7 #include "xfa/fwl/basewidget/fwl_listboximp.h" |
8 | 8 |
9 #include "xfa/fde/tto/fde_textout.h" | 9 #include "xfa/fde/tto/fde_textout.h" |
10 #include "xfa/fwl/basewidget/fwl_comboboximp.h" | 10 #include "xfa/fwl/basewidget/fwl_comboboximp.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 FWL_Error IFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { | 62 FWL_Error IFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { |
63 return static_cast<CFWL_ListBoxImp*>(GetImpl())->GetScrollPos(fPos, bVert); | 63 return static_cast<CFWL_ListBoxImp*>(GetImpl())->GetScrollPos(fPos, bVert); |
64 } | 64 } |
65 | 65 |
66 CFWL_ListBoxImp::CFWL_ListBoxImp(const CFWL_WidgetImpProperties& properties, | 66 CFWL_ListBoxImp::CFWL_ListBoxImp(const CFWL_WidgetImpProperties& properties, |
67 IFWL_Widget* pOuter) | 67 IFWL_Widget* pOuter) |
68 : CFWL_WidgetImp(properties, pOuter), | 68 : CFWL_WidgetImp(properties, pOuter), |
69 m_dwTTOStyles(0), | 69 m_dwTTOStyles(0), |
70 m_iTTOAligns(0), | 70 m_iTTOAligns(0), |
71 m_hAnchor(NULL), | 71 m_hAnchor(nullptr), |
72 m_fScorllBarWidth(0), | 72 m_fScorllBarWidth(0), |
73 m_bLButtonDown(FALSE), | 73 m_bLButtonDown(FALSE), |
74 m_pScrollBarTP(NULL) { | 74 m_pScrollBarTP(nullptr) { |
75 m_rtClient.Reset(); | 75 m_rtClient.Reset(); |
76 m_rtConent.Reset(); | 76 m_rtConent.Reset(); |
77 m_rtStatic.Reset(); | 77 m_rtStatic.Reset(); |
78 } | 78 } |
79 | 79 |
80 CFWL_ListBoxImp::~CFWL_ListBoxImp() {} | 80 CFWL_ListBoxImp::~CFWL_ListBoxImp() {} |
81 | 81 |
82 FWL_Error CFWL_ListBoxImp::GetClassName(CFX_WideString& wsClass) const { | 82 FWL_Error CFWL_ListBoxImp::GetClassName(CFX_WideString& wsClass) const { |
83 wsClass = FWL_CLASS_ListBox; | 83 wsClass = FWL_CLASS_ListBox; |
84 return FWL_Error::Succeeded; | 84 return FWL_Error::Succeeded; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 223 } |
224 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, pItem); | 224 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, pItem); |
225 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { | 225 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { |
226 iRet++; | 226 iRet++; |
227 } | 227 } |
228 } | 228 } |
229 return iRet; | 229 return iRet; |
230 } | 230 } |
231 IFWL_ListItem* CFWL_ListBoxImp::GetSelItem(int32_t nIndexSel) { | 231 IFWL_ListItem* CFWL_ListBoxImp::GetSelItem(int32_t nIndexSel) { |
232 if (!m_pProperties->m_pDataProvider) | 232 if (!m_pProperties->m_pDataProvider) |
233 return NULL; | 233 return nullptr; |
234 int32_t index = 0; | 234 int32_t index = 0; |
235 IFWL_ListBoxDP* pData = | 235 IFWL_ListBoxDP* pData = |
236 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 236 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
237 int32_t iCount = pData->CountItems(m_pInterface); | 237 int32_t iCount = pData->CountItems(m_pInterface); |
238 for (int32_t i = 0; i < iCount; i++) { | 238 for (int32_t i = 0; i < iCount; i++) { |
239 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); | 239 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); |
240 if (!pItem) { | 240 if (!pItem) { |
241 return NULL; | 241 return nullptr; |
242 } | 242 } |
243 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, pItem); | 243 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, pItem); |
244 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { | 244 if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { |
245 if (index == nIndexSel) { | 245 if (index == nIndexSel) { |
246 return pItem; | 246 return pItem; |
247 } else { | 247 } else { |
248 index++; | 248 index++; |
249 } | 249 } |
250 } | 250 } |
251 } | 251 } |
252 return NULL; | 252 return nullptr; |
253 } | 253 } |
254 int32_t CFWL_ListBoxImp::GetSelIndex(int32_t nIndex) { | 254 int32_t CFWL_ListBoxImp::GetSelIndex(int32_t nIndex) { |
255 if (!m_pProperties->m_pDataProvider) | 255 if (!m_pProperties->m_pDataProvider) |
256 return -1; | 256 return -1; |
257 int32_t index = 0; | 257 int32_t index = 0; |
258 IFWL_ListBoxDP* pData = | 258 IFWL_ListBoxDP* pData = |
259 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 259 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
260 int32_t iCount = pData->CountItems(m_pInterface); | 260 int32_t iCount = pData->CountItems(m_pInterface); |
261 for (int32_t i = 0; i < iCount; i++) { | 261 for (int32_t i = 0; i < iCount; i++) { |
262 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); | 262 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); |
(...skipping 12 matching lines...) Expand all Loading... |
275 return -1; | 275 return -1; |
276 } | 276 } |
277 FWL_Error CFWL_ListBoxImp::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { | 277 FWL_Error CFWL_ListBoxImp::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { |
278 if (!m_pProperties->m_pDataProvider) | 278 if (!m_pProperties->m_pDataProvider) |
279 return FWL_Error::Indefinite; | 279 return FWL_Error::Indefinite; |
280 if (!pItem) { | 280 if (!pItem) { |
281 if (bSelect) { | 281 if (bSelect) { |
282 SelectAll(); | 282 SelectAll(); |
283 } else { | 283 } else { |
284 ClearSelection(); | 284 ClearSelection(); |
285 SetFocusItem(NULL); | 285 SetFocusItem(nullptr); |
286 } | 286 } |
287 return FWL_Error::Indefinite; | 287 return FWL_Error::Indefinite; |
288 } | 288 } |
289 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 289 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { |
290 SetSelectionDirect(pItem, bSelect); | 290 SetSelectionDirect(pItem, bSelect); |
291 } else { | 291 } else { |
292 SetSelection(pItem, pItem, bSelect); | 292 SetSelection(pItem, pItem, bSelect); |
293 } | 293 } |
294 return FWL_Error::Succeeded; | 294 return FWL_Error::Succeeded; |
295 } | 295 } |
(...skipping 14 matching lines...) Expand all Loading... |
310 IFWL_ScrollBar* pScrollBar = | 310 IFWL_ScrollBar* pScrollBar = |
311 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); | 311 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); |
312 fPos = pScrollBar->GetPos(); | 312 fPos = pScrollBar->GetPos(); |
313 return FWL_Error::Succeeded; | 313 return FWL_Error::Succeeded; |
314 } | 314 } |
315 return FWL_Error::Indefinite; | 315 return FWL_Error::Indefinite; |
316 } | 316 } |
317 | 317 |
318 IFWL_ListItem* CFWL_ListBoxImp::GetItem(IFWL_ListItem* pItem, | 318 IFWL_ListItem* CFWL_ListBoxImp::GetItem(IFWL_ListItem* pItem, |
319 uint32_t dwKeyCode) { | 319 uint32_t dwKeyCode) { |
320 IFWL_ListItem* hRet = NULL; | 320 IFWL_ListItem* hRet = nullptr; |
321 switch (dwKeyCode) { | 321 switch (dwKeyCode) { |
322 case FWL_VKEY_Up: | 322 case FWL_VKEY_Up: |
323 case FWL_VKEY_Down: | 323 case FWL_VKEY_Down: |
324 case FWL_VKEY_Home: | 324 case FWL_VKEY_Home: |
325 case FWL_VKEY_End: { | 325 case FWL_VKEY_End: { |
326 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 326 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
327 const bool bDown = dwKeyCode == FWL_VKEY_Down; | 327 const bool bDown = dwKeyCode == FWL_VKEY_Down; |
328 const bool bHome = dwKeyCode == FWL_VKEY_Home; | 328 const bool bHome = dwKeyCode == FWL_VKEY_Home; |
329 IFWL_ListBoxDP* pData = | 329 IFWL_ListBoxDP* pData = |
330 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 330 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 SetSelection(pItemStart, pItemEnd, FALSE); | 415 SetSelection(pItemStart, pItemEnd, FALSE); |
416 } | 416 } |
417 } | 417 } |
418 IFWL_ListItem* CFWL_ListBoxImp::GetFocusedItem() { | 418 IFWL_ListItem* CFWL_ListBoxImp::GetFocusedItem() { |
419 IFWL_ListBoxDP* pData = | 419 IFWL_ListBoxDP* pData = |
420 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 420 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
421 int32_t iCount = pData->CountItems(m_pInterface); | 421 int32_t iCount = pData->CountItems(m_pInterface); |
422 for (int32_t i = 0; i < iCount; i++) { | 422 for (int32_t i = 0; i < iCount; i++) { |
423 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); | 423 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); |
424 if (!pItem) | 424 if (!pItem) |
425 return NULL; | 425 return nullptr; |
426 if (pData->GetItemStyles(m_pInterface, pItem) & FWL_ITEMSTATE_LTB_Focused) { | 426 if (pData->GetItemStyles(m_pInterface, pItem) & FWL_ITEMSTATE_LTB_Focused) { |
427 return pItem; | 427 return pItem; |
428 } | 428 } |
429 } | 429 } |
430 return NULL; | 430 return nullptr; |
431 } | 431 } |
432 void CFWL_ListBoxImp::SetFocusItem(IFWL_ListItem* pItem) { | 432 void CFWL_ListBoxImp::SetFocusItem(IFWL_ListItem* pItem) { |
433 IFWL_ListBoxDP* pData = | 433 IFWL_ListBoxDP* pData = |
434 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 434 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
435 IFWL_ListItem* hFocus = GetFocusedItem(); | 435 IFWL_ListItem* hFocus = GetFocusedItem(); |
436 if (pItem != hFocus) { | 436 if (pItem != hFocus) { |
437 if (hFocus) { | 437 if (hFocus) { |
438 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, hFocus); | 438 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, hFocus); |
439 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; | 439 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; |
440 pData->SetItemStyles(m_pInterface, hFocus, dwStyle); | 440 pData->SetItemStyles(m_pInterface, hFocus, dwStyle); |
(...skipping 23 matching lines...) Expand all Loading... |
464 if (!pItem) { | 464 if (!pItem) { |
465 continue; | 465 continue; |
466 } | 466 } |
467 CFX_RectF rtItem; | 467 CFX_RectF rtItem; |
468 pData->GetItemRect(m_pInterface, pItem, rtItem); | 468 pData->GetItemRect(m_pInterface, pItem, rtItem); |
469 rtItem.Offset(-fPosX, -fPosY); | 469 rtItem.Offset(-fPosX, -fPosY); |
470 if (rtItem.Contains(fx, fy)) { | 470 if (rtItem.Contains(fx, fy)) { |
471 return pItem; | 471 return pItem; |
472 } | 472 } |
473 } | 473 } |
474 return NULL; | 474 return nullptr; |
475 } | 475 } |
476 FX_BOOL CFWL_ListBoxImp::GetItemCheckRect(IFWL_ListItem* pItem, | 476 FX_BOOL CFWL_ListBoxImp::GetItemCheckRect(IFWL_ListItem* pItem, |
477 CFX_RectF& rtCheck) { | 477 CFX_RectF& rtCheck) { |
478 if (!m_pProperties->m_pDataProvider) | 478 if (!m_pProperties->m_pDataProvider) |
479 return FALSE; | 479 return FALSE; |
480 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { | 480 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { |
481 return FALSE; | 481 return FALSE; |
482 } | 482 } |
483 IFWL_ListBoxDP* pData = | 483 IFWL_ListBoxDP* pData = |
484 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 484 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || | 951 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || |
952 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); | 952 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); |
953 } | 953 } |
954 void CFWL_ListBoxImp::ProcessSelChanged() { | 954 void CFWL_ListBoxImp::ProcessSelChanged() { |
955 CFWL_EvtLtbSelChanged selEvent; | 955 CFWL_EvtLtbSelChanged selEvent; |
956 selEvent.m_pSrcTarget = m_pInterface; | 956 selEvent.m_pSrcTarget = m_pInterface; |
957 CFX_Int32Array arrSels; | 957 CFX_Int32Array arrSels; |
958 int32_t iCount = CountSelItems(); | 958 int32_t iCount = CountSelItems(); |
959 for (int32_t i = 0; i < iCount; i++) { | 959 for (int32_t i = 0; i < iCount; i++) { |
960 IFWL_ListItem* item = GetSelItem(i); | 960 IFWL_ListItem* item = GetSelItem(i); |
961 if (item == NULL) { | 961 if (!item) { |
962 continue; | 962 continue; |
963 } | 963 } |
964 selEvent.iarraySels.Add(i); | 964 selEvent.iarraySels.Add(i); |
965 } | 965 } |
966 DispatchEvent(&selEvent); | 966 DispatchEvent(&selEvent); |
967 } | 967 } |
968 | 968 |
969 CFWL_ListBoxImpDelegate::CFWL_ListBoxImpDelegate(CFWL_ListBoxImp* pOwner) | 969 CFWL_ListBoxImpDelegate::CFWL_ListBoxImpDelegate(CFWL_ListBoxImp* pOwner) |
970 : m_pOwner(pOwner) {} | 970 : m_pOwner(pOwner) {} |
971 | 971 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 m_pOwner->m_bLButtonDown = FALSE; | 1110 m_pOwner->m_bLButtonDown = FALSE; |
1111 m_pOwner->SetGrab(FALSE); | 1111 m_pOwner->SetGrab(FALSE); |
1112 DispatchSelChangedEv(); | 1112 DispatchSelChangedEv(); |
1113 } | 1113 } |
1114 } | 1114 } |
1115 void CFWL_ListBoxImpDelegate::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { | 1115 void CFWL_ListBoxImpDelegate::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { |
1116 if (!m_pOwner->IsShowScrollBar(TRUE)) { | 1116 if (!m_pOwner->IsShowScrollBar(TRUE)) { |
1117 return; | 1117 return; |
1118 } | 1118 } |
1119 IFWL_WidgetDelegate* pDelegate = | 1119 IFWL_WidgetDelegate* pDelegate = |
1120 m_pOwner->m_pVertScrollBar->SetDelegate(NULL); | 1120 m_pOwner->m_pVertScrollBar->SetDelegate(nullptr); |
1121 pDelegate->OnProcessMessage(pMsg); | 1121 pDelegate->OnProcessMessage(pMsg); |
1122 } | 1122 } |
1123 void CFWL_ListBoxImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { | 1123 void CFWL_ListBoxImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { |
1124 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1124 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1125 switch (dwKeyCode) { | 1125 switch (dwKeyCode) { |
1126 case FWL_VKEY_Tab: | 1126 case FWL_VKEY_Tab: |
1127 case FWL_VKEY_Up: | 1127 case FWL_VKEY_Up: |
1128 case FWL_VKEY_Down: | 1128 case FWL_VKEY_Down: |
1129 case FWL_VKEY_Home: | 1129 case FWL_VKEY_Home: |
1130 case FWL_VKEY_End: { | 1130 case FWL_VKEY_End: { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 pScrollBar->SetTrackPos(fPos); | 1226 pScrollBar->SetTrackPos(fPos); |
1227 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1227 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
1228 } | 1228 } |
1229 return TRUE; | 1229 return TRUE; |
1230 } | 1230 } |
1231 void CFWL_ListBoxImpDelegate::DispatchSelChangedEv() { | 1231 void CFWL_ListBoxImpDelegate::DispatchSelChangedEv() { |
1232 CFWL_EvtLtbSelChanged ev; | 1232 CFWL_EvtLtbSelChanged ev; |
1233 ev.m_pSrcTarget = m_pOwner->m_pInterface; | 1233 ev.m_pSrcTarget = m_pOwner->m_pInterface; |
1234 m_pOwner->DispatchEvent(&ev); | 1234 m_pOwner->DispatchEvent(&ev); |
1235 } | 1235 } |
OLD | NEW |