Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: fpdfsdk/src/fxedit/fxet_edit.cpp

Issue 1512763013: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fxedit/fxet_ap.cpp ('k') | fpdfsdk/src/fxedit/fxet_list.cpp » ('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 "fpdfsdk/include/fxedit/fxet_edit.h" 7 #include "fpdfsdk/include/fxedit/fxet_edit.h"
8 #include "fpdfsdk/include/fxedit/fxet_stub.h" 8 #include "fpdfsdk/include/fxedit/fxet_stub.h"
9 9
10 #define FX_EDIT_UNDO_MAXITEM 10000 10 #define FX_EDIT_UNDO_MAXITEM 10000
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 IFX_Edit* CFX_Edit_Iterator::GetEdit() const { 87 IFX_Edit* CFX_Edit_Iterator::GetEdit() const {
88 return m_pEdit; 88 return m_pEdit;
89 } 89 }
90 90
91 /* --------------------------- CFX_Edit_Provider ------------------------------- 91 /* --------------------------- CFX_Edit_Provider -------------------------------
92 */ 92 */
93 93
94 CFX_Edit_Provider::CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap) 94 CFX_Edit_Provider::CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap)
95 : m_pFontMap(pFontMap) { 95 : m_pFontMap(pFontMap) {
96 ASSERT(m_pFontMap != NULL); 96 ASSERT(m_pFontMap);
97 } 97 }
98 98
99 CFX_Edit_Provider::~CFX_Edit_Provider() {} 99 CFX_Edit_Provider::~CFX_Edit_Provider() {}
100 100
101 IFX_Edit_FontMap* CFX_Edit_Provider::GetFontMap() { 101 IFX_Edit_FontMap* CFX_Edit_Provider::GetFontMap() {
102 return m_pFontMap; 102 return m_pFontMap;
103 } 103 }
104 104
105 int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex, 105 int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex,
106 FX_WORD word, 106 FX_WORD word,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 FX_BOOL CFX_Edit_Undo::CanUndo() const { 280 FX_BOOL CFX_Edit_Undo::CanUndo() const {
281 return m_nCurUndoPos > 0; 281 return m_nCurUndoPos > 0;
282 } 282 }
283 283
284 void CFX_Edit_Undo::Undo() { 284 void CFX_Edit_Undo::Undo() {
285 m_bWorking = TRUE; 285 m_bWorking = TRUE;
286 286
287 if (m_nCurUndoPos > 0) { 287 if (m_nCurUndoPos > 0) {
288 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos - 1); 288 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos - 1);
289 ASSERT(pItem != NULL);
290
291 pItem->Undo(); 289 pItem->Undo();
292 290
293 m_nCurUndoPos--; 291 m_nCurUndoPos--;
294 m_bModified = (m_nCurUndoPos != 0); 292 m_bModified = (m_nCurUndoPos != 0);
295 } 293 }
296 294
297 m_bWorking = FALSE; 295 m_bWorking = FALSE;
298 } 296 }
299 297
300 FX_BOOL CFX_Edit_Undo::CanRedo() const { 298 FX_BOOL CFX_Edit_Undo::CanRedo() const {
301 return m_nCurUndoPos < m_UndoItemStack.GetSize(); 299 return m_nCurUndoPos < m_UndoItemStack.GetSize();
302 } 300 }
303 301
304 void CFX_Edit_Undo::Redo() { 302 void CFX_Edit_Undo::Redo() {
305 m_bWorking = TRUE; 303 m_bWorking = TRUE;
306 304
307 int32_t nStackSize = m_UndoItemStack.GetSize(); 305 int32_t nStackSize = m_UndoItemStack.GetSize();
308 306
309 if (m_nCurUndoPos < nStackSize) { 307 if (m_nCurUndoPos < nStackSize) {
310 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos); 308 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos);
311 ASSERT(pItem != NULL);
312
313 pItem->Redo(); 309 pItem->Redo();
314 310
315 m_nCurUndoPos++; 311 m_nCurUndoPos++;
316 m_bModified = (m_nCurUndoPos != 0); 312 m_bModified = (m_nCurUndoPos != 0);
317 } 313 }
318 314
319 m_bWorking = FALSE; 315 m_bWorking = FALSE;
320 } 316 }
321 317
322 FX_BOOL CFX_Edit_Undo::IsWorking() const { 318 FX_BOOL CFX_Edit_Undo::IsWorking() const {
323 return m_bWorking; 319 return m_bWorking;
324 } 320 }
325 321
326 void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) { 322 void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) {
327 ASSERT(!m_bWorking); 323 ASSERT(!m_bWorking);
328 ASSERT(pItem != NULL); 324 ASSERT(pItem);
329 ASSERT(m_nBufSize > 1); 325 ASSERT(m_nBufSize > 1);
330 326
331 if (m_nCurUndoPos < m_UndoItemStack.GetSize()) 327 if (m_nCurUndoPos < m_UndoItemStack.GetSize())
332 RemoveTails(); 328 RemoveTails();
333 329
334 if (m_UndoItemStack.GetSize() >= m_nBufSize) { 330 if (m_UndoItemStack.GetSize() >= m_nBufSize) {
335 RemoveHeads(); 331 RemoveHeads();
336 m_bVirgin = FALSE; 332 m_bVirgin = FALSE;
337 } 333 }
338 334
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 379
384 CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() { 380 CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() {
385 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) { 381 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) {
386 delete m_Items[i]; 382 delete m_Items[i];
387 } 383 }
388 384
389 m_Items.RemoveAll(); 385 m_Items.RemoveAll();
390 } 386 }
391 387
392 void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) { 388 void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) {
393 ASSERT(pUndoItem != NULL);
394
395 pUndoItem->SetFirst(FALSE); 389 pUndoItem->SetFirst(FALSE);
396 pUndoItem->SetLast(FALSE); 390 pUndoItem->SetLast(FALSE);
397 391
398 m_Items.Add(pUndoItem); 392 m_Items.Add(pUndoItem);
399 393
400 if (m_sTitle.IsEmpty()) 394 if (m_sTitle.IsEmpty())
401 m_sTitle = pUndoItem->GetUndoTitle(); 395 m_sTitle = pUndoItem->GetUndoTitle();
402 } 396 }
403 397
404 void CFX_Edit_GroupUndoItem::UpdateItems() { 398 void CFX_Edit_GroupUndoItem::UpdateItems() {
405 if (m_Items.GetSize() > 0) { 399 if (m_Items.GetSize() > 0) {
406 CFX_Edit_UndoItem* pFirstItem = m_Items[0]; 400 CFX_Edit_UndoItem* pFirstItem = m_Items[0];
407 ASSERT(pFirstItem != NULL);
408 pFirstItem->SetFirst(TRUE); 401 pFirstItem->SetFirst(TRUE);
409 402
410 CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1]; 403 CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1];
411 ASSERT(pLastItem != NULL);
412 pLastItem->SetLast(TRUE); 404 pLastItem->SetLast(TRUE);
413 } 405 }
414 } 406 }
415 407
416 void CFX_Edit_GroupUndoItem::Undo() { 408 void CFX_Edit_GroupUndoItem::Undo() {
417 for (int i = m_Items.GetSize() - 1; i >= 0; i--) { 409 for (int i = m_Items.GetSize() - 1; i >= 0; i--) {
418 CFX_Edit_UndoItem* pUndoItem = m_Items[i]; 410 CFX_Edit_UndoItem* pUndoItem = m_Items[i];
419 ASSERT(pUndoItem != NULL);
420
421 pUndoItem->Undo(); 411 pUndoItem->Undo();
422 } 412 }
423 } 413 }
424 414
425 void CFX_Edit_GroupUndoItem::Redo() { 415 void CFX_Edit_GroupUndoItem::Redo() {
426 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) { 416 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) {
427 CFX_Edit_UndoItem* pUndoItem = m_Items[i]; 417 CFX_Edit_UndoItem* pUndoItem = m_Items[i];
428 ASSERT(pUndoItem != NULL);
429
430 pUndoItem->Redo(); 418 pUndoItem->Redo();
431 } 419 }
432 } 420 }
433 421
434 CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() { 422 CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() {
435 return m_sTitle; 423 return m_sTitle;
436 } 424 }
437 425
438 /* ------------------------------------- CFX_Edit_UndoItem derived classes 426 /* ------------------------------------- CFX_Edit_UndoItem derived classes
439 * ------------------------------------- */ 427 * ------------------------------------- */
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 m_Undo(FX_EDIT_UNDO_MAXITEM), 799 m_Undo(FX_EDIT_UNDO_MAXITEM),
812 m_nAlignment(0), 800 m_nAlignment(0),
813 m_bNotifyFlag(FALSE), 801 m_bNotifyFlag(FALSE),
814 m_bEnableOverflow(FALSE), 802 m_bEnableOverflow(FALSE),
815 m_bEnableRefresh(TRUE), 803 m_bEnableRefresh(TRUE),
816 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), 804 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f),
817 m_bEnableUndo(TRUE), 805 m_bEnableUndo(TRUE),
818 m_bNotify(TRUE), 806 m_bNotify(TRUE),
819 m_bOprNotify(FALSE), 807 m_bOprNotify(FALSE),
820 m_pGroupUndoItem(NULL) { 808 m_pGroupUndoItem(NULL) {
821 ASSERT(pVT != NULL); 809 ASSERT(pVT);
822 } 810 }
823 811
824 CFX_Edit::~CFX_Edit() { 812 CFX_Edit::~CFX_Edit() {
825 delete m_pVTProvide; 813 delete m_pVTProvide;
826 m_pVTProvide = NULL; 814 m_pVTProvide = NULL;
827 delete m_pIterator; 815 delete m_pIterator;
828 m_pIterator = NULL; 816 m_pIterator = NULL;
829 ASSERT(m_pGroupUndoItem == NULL); 817 ASSERT(m_pGroupUndoItem == NULL);
830 } 818 }
831 819
(...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after
3100 return nOldCharset; 3088 return nOldCharset;
3101 } 3089 }
3102 3090
3103 void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle) { 3091 void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle) {
3104 ASSERT(m_pGroupUndoItem == NULL); 3092 ASSERT(m_pGroupUndoItem == NULL);
3105 3093
3106 m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle); 3094 m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle);
3107 } 3095 }
3108 3096
3109 void CFX_Edit::EndGroupUndo() { 3097 void CFX_Edit::EndGroupUndo() {
3110 ASSERT(m_pGroupUndoItem != NULL);
3111
3112 m_pGroupUndoItem->UpdateItems(); 3098 m_pGroupUndoItem->UpdateItems();
3113 m_Undo.AddItem(m_pGroupUndoItem); 3099 m_Undo.AddItem(m_pGroupUndoItem);
3114 if (m_bOprNotify && m_pOprNotify) 3100 if (m_bOprNotify && m_pOprNotify)
3115 m_pOprNotify->OnAddUndo(m_pGroupUndoItem); 3101 m_pOprNotify->OnAddUndo(m_pGroupUndoItem);
3116 m_pGroupUndoItem = NULL; 3102 m_pGroupUndoItem = NULL;
3117 } 3103 }
3118 3104
3119 void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) { 3105 void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) {
3120 if (m_pGroupUndoItem) 3106 if (m_pGroupUndoItem)
3121 m_pGroupUndoItem->AddUndoItem(pEditUndoItem); 3107 m_pGroupUndoItem->AddUndoItem(pEditUndoItem);
3122 else { 3108 else {
3123 m_Undo.AddItem(pEditUndoItem); 3109 m_Undo.AddItem(pEditUndoItem);
3124 if (m_bOprNotify && m_pOprNotify) 3110 if (m_bOprNotify && m_pOprNotify)
3125 m_pOprNotify->OnAddUndo(pEditUndoItem); 3111 m_pOprNotify->OnAddUndo(pEditUndoItem);
3126 } 3112 }
3127 } 3113 }
3128 3114
3129 void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) { 3115 void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) {
3130 m_Undo.AddItem(pUndoItem); 3116 m_Undo.AddItem(pUndoItem);
3131 if (m_bOprNotify && m_pOprNotify) 3117 if (m_bOprNotify && m_pOprNotify)
3132 m_pOprNotify->OnAddUndo(pUndoItem); 3118 m_pOprNotify->OnAddUndo(pUndoItem);
3133 } 3119 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fxedit/fxet_ap.cpp ('k') | fpdfsdk/src/fxedit/fxet_list.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698