Chromium Code Reviews

Side by Side Diff: xfa/fwl/basewidget/fwl_listboximp.cpp

Issue 2031873003: Get rid of NULLs in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@nullptr_fpdfsdk
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « xfa/fwl/basewidget/fwl_listboximp.h ('k') | xfa/fwl/basewidget/fwl_monthcalendarimp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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...)
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...)
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...)
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...)
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;
321 switch (dwKeyCode) { 320 switch (dwKeyCode) {
322 case FWL_VKEY_Up: 321 case FWL_VKEY_Up:
323 case FWL_VKEY_Down: 322 case FWL_VKEY_Down:
324 case FWL_VKEY_Home: 323 case FWL_VKEY_Home:
325 case FWL_VKEY_End: { 324 case FWL_VKEY_End: {
326 const bool bUp = dwKeyCode == FWL_VKEY_Up; 325 const bool bUp = dwKeyCode == FWL_VKEY_Up;
327 const bool bDown = dwKeyCode == FWL_VKEY_Down; 326 const bool bDown = dwKeyCode == FWL_VKEY_Down;
328 const bool bHome = dwKeyCode == FWL_VKEY_Home; 327 const bool bHome = dwKeyCode == FWL_VKEY_Home;
329 IFWL_ListBoxDP* pData = 328 IFWL_ListBoxDP* pData =
330 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); 329 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider);
331 int32_t iDstItem = -1; 330 int32_t iDstItem = -1;
332 if (bUp || bDown) { 331 if (bUp || bDown) {
333 int32_t index = pData->GetItemIndex(m_pInterface, pItem); 332 int32_t index = pData->GetItemIndex(m_pInterface, pItem);
334 iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1; 333 iDstItem = dwKeyCode == FWL_VKEY_Up ? index - 1 : index + 1;
335 } else if (bHome) { 334 } else if (bHome) {
336 iDstItem = 0; 335 iDstItem = 0;
337 } else { 336 } else {
338 int32_t iCount = pData->CountItems(m_pInterface); 337 int32_t iCount = pData->CountItems(m_pInterface);
339 iDstItem = iCount - 1; 338 iDstItem = iCount - 1;
340 } 339 }
341 hRet = pData->GetItem(m_pInterface, iDstItem); 340 return pData->GetItem(m_pInterface, iDstItem);
342 break;
343 } 341 }
344 default: {} 342 default:
343 return nullptr;
345 } 344 }
346 return hRet;
347 } 345 }
348 void CFWL_ListBoxImp::SetSelection(IFWL_ListItem* hStart, 346 void CFWL_ListBoxImp::SetSelection(IFWL_ListItem* hStart,
349 IFWL_ListItem* hEnd, 347 IFWL_ListItem* hEnd,
350 FX_BOOL bSelected) { 348 FX_BOOL bSelected) {
351 IFWL_ListBoxDP* pData = 349 IFWL_ListBoxDP* pData =
352 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); 350 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider);
353 int32_t iStart = pData->GetItemIndex(m_pInterface, hStart); 351 int32_t iStart = pData->GetItemIndex(m_pInterface, hStart);
354 int32_t iEnd = pData->GetItemIndex(m_pInterface, hEnd); 352 int32_t iEnd = pData->GetItemIndex(m_pInterface, hEnd);
355 if (iStart > iEnd) { 353 if (iStart > iEnd) {
356 int32_t iTemp = iStart; 354 int32_t iTemp = iStart;
(...skipping 58 matching lines...)
415 SetSelection(pItemStart, pItemEnd, FALSE); 413 SetSelection(pItemStart, pItemEnd, FALSE);
416 } 414 }
417 } 415 }
418 IFWL_ListItem* CFWL_ListBoxImp::GetFocusedItem() { 416 IFWL_ListItem* CFWL_ListBoxImp::GetFocusedItem() {
419 IFWL_ListBoxDP* pData = 417 IFWL_ListBoxDP* pData =
420 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); 418 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider);
421 int32_t iCount = pData->CountItems(m_pInterface); 419 int32_t iCount = pData->CountItems(m_pInterface);
422 for (int32_t i = 0; i < iCount; i++) { 420 for (int32_t i = 0; i < iCount; i++) {
423 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i); 421 IFWL_ListItem* pItem = pData->GetItem(m_pInterface, i);
424 if (!pItem) 422 if (!pItem)
425 return NULL; 423 return nullptr;
426 if (pData->GetItemStyles(m_pInterface, pItem) & FWL_ITEMSTATE_LTB_Focused) { 424 if (pData->GetItemStyles(m_pInterface, pItem) & FWL_ITEMSTATE_LTB_Focused) {
427 return pItem; 425 return pItem;
428 } 426 }
429 } 427 }
430 return NULL; 428 return nullptr;
431 } 429 }
432 void CFWL_ListBoxImp::SetFocusItem(IFWL_ListItem* pItem) { 430 void CFWL_ListBoxImp::SetFocusItem(IFWL_ListItem* pItem) {
433 IFWL_ListBoxDP* pData = 431 IFWL_ListBoxDP* pData =
434 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); 432 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider);
435 IFWL_ListItem* hFocus = GetFocusedItem(); 433 IFWL_ListItem* hFocus = GetFocusedItem();
436 if (pItem != hFocus) { 434 if (pItem != hFocus) {
437 if (hFocus) { 435 if (hFocus) {
438 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, hFocus); 436 uint32_t dwStyle = pData->GetItemStyles(m_pInterface, hFocus);
439 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; 437 dwStyle &= ~FWL_ITEMSTATE_LTB_Focused;
440 pData->SetItemStyles(m_pInterface, hFocus, dwStyle); 438 pData->SetItemStyles(m_pInterface, hFocus, dwStyle);
(...skipping 23 matching lines...)
464 if (!pItem) { 462 if (!pItem) {
465 continue; 463 continue;
466 } 464 }
467 CFX_RectF rtItem; 465 CFX_RectF rtItem;
468 pData->GetItemRect(m_pInterface, pItem, rtItem); 466 pData->GetItemRect(m_pInterface, pItem, rtItem);
469 rtItem.Offset(-fPosX, -fPosY); 467 rtItem.Offset(-fPosX, -fPosY);
470 if (rtItem.Contains(fx, fy)) { 468 if (rtItem.Contains(fx, fy)) {
471 return pItem; 469 return pItem;
472 } 470 }
473 } 471 }
474 return NULL; 472 return nullptr;
475 } 473 }
476 FX_BOOL CFWL_ListBoxImp::GetItemCheckRect(IFWL_ListItem* pItem, 474 FX_BOOL CFWL_ListBoxImp::GetItemCheckRect(IFWL_ListItem* pItem,
477 CFX_RectF& rtCheck) { 475 CFX_RectF& rtCheck) {
478 if (!m_pProperties->m_pDataProvider) 476 if (!m_pProperties->m_pDataProvider)
479 return FALSE; 477 return FALSE;
480 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) { 478 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) {
481 return FALSE; 479 return FALSE;
482 } 480 }
483 IFWL_ListBoxDP* pData = 481 IFWL_ListBoxDP* pData =
484 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); 482 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider);
(...skipping 465 matching lines...)
950 return !(m_pProperties->m_dwStyleExes & 948 return !(m_pProperties->m_dwStyleExes &
951 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || 949 FWL_STYLEEXT_LTB_ShowScrollBarFocus) ||
952 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); 950 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused);
953 } 951 }
954 void CFWL_ListBoxImp::ProcessSelChanged() { 952 void CFWL_ListBoxImp::ProcessSelChanged() {
955 CFWL_EvtLtbSelChanged selEvent; 953 CFWL_EvtLtbSelChanged selEvent;
956 selEvent.m_pSrcTarget = m_pInterface; 954 selEvent.m_pSrcTarget = m_pInterface;
957 CFX_Int32Array arrSels; 955 CFX_Int32Array arrSels;
958 int32_t iCount = CountSelItems(); 956 int32_t iCount = CountSelItems();
959 for (int32_t i = 0; i < iCount; i++) { 957 for (int32_t i = 0; i < iCount; i++) {
960 IFWL_ListItem* item = GetSelItem(i); 958 if (!GetSelItem(i))
961 if (item == NULL) {
962 continue; 959 continue;
963 } 960
964 selEvent.iarraySels.Add(i); 961 selEvent.iarraySels.Add(i);
965 } 962 }
966 DispatchEvent(&selEvent); 963 DispatchEvent(&selEvent);
967 } 964 }
968 965
969 CFWL_ListBoxImpDelegate::CFWL_ListBoxImpDelegate(CFWL_ListBoxImp* pOwner) 966 CFWL_ListBoxImpDelegate::CFWL_ListBoxImpDelegate(CFWL_ListBoxImp* pOwner)
970 : m_pOwner(pOwner) {} 967 : m_pOwner(pOwner) {}
971 968
972 void CFWL_ListBoxImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { 969 void CFWL_ListBoxImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {
973 if (!pMessage) 970 if (!pMessage)
(...skipping 136 matching lines...)
1110 m_pOwner->m_bLButtonDown = FALSE; 1107 m_pOwner->m_bLButtonDown = FALSE;
1111 m_pOwner->SetGrab(FALSE); 1108 m_pOwner->SetGrab(FALSE);
1112 DispatchSelChangedEv(); 1109 DispatchSelChangedEv();
1113 } 1110 }
1114 } 1111 }
1115 void CFWL_ListBoxImpDelegate::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { 1112 void CFWL_ListBoxImpDelegate::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) {
1116 if (!m_pOwner->IsShowScrollBar(TRUE)) { 1113 if (!m_pOwner->IsShowScrollBar(TRUE)) {
1117 return; 1114 return;
1118 } 1115 }
1119 IFWL_WidgetDelegate* pDelegate = 1116 IFWL_WidgetDelegate* pDelegate =
1120 m_pOwner->m_pVertScrollBar->SetDelegate(NULL); 1117 m_pOwner->m_pVertScrollBar->SetDelegate(nullptr);
1121 pDelegate->OnProcessMessage(pMsg); 1118 pDelegate->OnProcessMessage(pMsg);
1122 } 1119 }
1123 void CFWL_ListBoxImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { 1120 void CFWL_ListBoxImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) {
1124 uint32_t dwKeyCode = pMsg->m_dwKeyCode; 1121 uint32_t dwKeyCode = pMsg->m_dwKeyCode;
1125 switch (dwKeyCode) { 1122 switch (dwKeyCode) {
1126 case FWL_VKEY_Tab: 1123 case FWL_VKEY_Tab:
1127 case FWL_VKEY_Up: 1124 case FWL_VKEY_Up:
1128 case FWL_VKEY_Down: 1125 case FWL_VKEY_Down:
1129 case FWL_VKEY_Home: 1126 case FWL_VKEY_Home:
1130 case FWL_VKEY_End: { 1127 case FWL_VKEY_End: {
(...skipping 95 matching lines...)
1226 pScrollBar->SetTrackPos(fPos); 1223 pScrollBar->SetTrackPos(fPos);
1227 m_pOwner->Repaint(&m_pOwner->m_rtClient); 1224 m_pOwner->Repaint(&m_pOwner->m_rtClient);
1228 } 1225 }
1229 return TRUE; 1226 return TRUE;
1230 } 1227 }
1231 void CFWL_ListBoxImpDelegate::DispatchSelChangedEv() { 1228 void CFWL_ListBoxImpDelegate::DispatchSelChangedEv() {
1232 CFWL_EvtLtbSelChanged ev; 1229 CFWL_EvtLtbSelChanged ev;
1233 ev.m_pSrcTarget = m_pOwner->m_pInterface; 1230 ev.m_pSrcTarget = m_pOwner->m_pInterface;
1234 m_pOwner->DispatchEvent(&ev); 1231 m_pOwner->DispatchEvent(&ev);
1235 } 1232 }
OLDNEW
« no previous file with comments | « xfa/fwl/basewidget/fwl_listboximp.h ('k') | xfa/fwl/basewidget/fwl_monthcalendarimp.h » ('j') | no next file with comments »

Powered by Google App Engine