1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "xfa/src/foxitlib.h" 8 #include "fde_iterator.h" 9 IFDE_VisualSetIterator* IFDE_VisualSetIterator::Create() { 10 return new CFDE_VisualSetIterator; 11 } 12 CFDE_VisualSetIterator::CFDE_VisualSetIterator() : m_dwFilter(0) {} 13 CFDE_VisualSetIterator::~CFDE_VisualSetIterator() { 14 m_CanvasStack.RemoveAll(); 15 } 16 FX_BOOL CFDE_VisualSetIterator::AttachCanvas(IFDE_CanvasSet* pCanvas) { 17 FXSYS_assert(pCanvas != NULL); 18 m_CanvasStack.RemoveAll(); 19 FDE_CANVASITEM canvas; 20 canvas.hCanvas = NULL; 21 canvas.pCanvas = pCanvas; 22 canvas.hPos = pCanvas->GetFirstPosition(NULL); 23 if (canvas.hPos == NULL) { 24 return FALSE; 25 } 26 return m_CanvasStack.Push(canvas) == 0; 27 } 28 FX_BOOL CFDE_VisualSetIterator::FilterObjects(FX_DWORD dwObjects) { 29 if (m_CanvasStack.GetSize() == 0) { 30 return FALSE; 31 } 32 while (m_CanvasStack.GetSize() > 1) { 33 m_CanvasStack.Pop(); 34 } 35 m_dwFilter = dwObjects & ~(FX_DWORD)FDE_VISUALOBJ_Widget; 36 if (dwObjects & FDE_VISUALOBJ_Widget) { 37 m_dwFilter |= 0xFF00; 38 } 39 FDE_LPCANVASITEM pCanvas = m_CanvasStack.GetTopElement(); 40 FXSYS_assert(pCanvas != NULL && pCanvas->pCanvas != NULL); 41 pCanvas->hPos = pCanvas->pCanvas->GetFirstPosition(NULL); 42 return pCanvas->hPos != NULL; 43 } 44 void CFDE_VisualSetIterator::Reset() { 45 FilterObjects(m_dwFilter); 46 } 47 FDE_HVISUALOBJ CFDE_VisualSetIterator::GetNext(IFDE_VisualSet*& pVisualSet, 48 FDE_HVISUALOBJ* phCanvasObj, 49 IFDE_CanvasSet** ppCanvasSet) { 50 while (m_CanvasStack.GetSize() > 0) { 51 FDE_LPCANVASITEM pCanvas = m_CanvasStack.GetTopElement(); 52 FXSYS_assert(pCanvas != NULL && pCanvas->pCanvas != NULL); 53 if (pCanvas->hPos == NULL) { 54 if (m_CanvasStack.GetSize() == 1) { 55 break; 56 } 57 m_CanvasStack.Pop(); 58 continue; 59 } 60 do { 61 FDE_HVISUALOBJ hObj = pCanvas->pCanvas->GetNext( 62 pCanvas->hCanvas, pCanvas->hPos, pVisualSet); 63 FXSYS_assert(hObj != NULL); 64 FDE_VISUALOBJTYPE eType = pVisualSet->GetType(); 65 if (eType == FDE_VISUALOBJ_Canvas) { 66 FDE_CANVASITEM canvas; 67 canvas.hCanvas = hObj; 68 canvas.pCanvas = (IFDE_CanvasSet*)pVisualSet; 69 canvas.hPos = canvas.pCanvas->GetFirstPosition(hObj); 70 m_CanvasStack.Push(canvas); 71 break; 72 } 73 FX_DWORD dwObj = 74 (eType == FDE_VISUALOBJ_Widget) 75 ? (FX_DWORD)((IFDE_WidgetSet*)pVisualSet)->GetWidgetType(hObj) 76 : (FX_DWORD)eType; 77 if ((m_dwFilter & dwObj) != 0) { 78 if (ppCanvasSet) { 79 *ppCanvasSet = pCanvas->pCanvas; 80 } 81 if (phCanvasObj) { 82 *phCanvasObj = pCanvas->hCanvas; 83 } 84 return hObj; 85 } 86 } while (pCanvas->hPos != NULL); 87 } 88 if (ppCanvasSet) { 89 *ppCanvasSet = NULL; 90 } 91 if (phCanvasObj) { 92 *phCanvasObj = NULL; 93 } 94 pVisualSet = NULL; 95 return NULL; 96 } 97