CPVT_FloatRect CPDF_VariableText::OutToIn(const CFX_FloatRect& rect) const { CFX_FloatPoint ptLeftTop = OutToIn(CFX_FloatPoint(rect.left, rect.top)); CFX_FloatPoint ptRightBottom = OutToIn(CFX_FloatPoint(rect.right, rect.bottom)); return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x, ptRightBottom.y); }
CPDF_Rect CFX_ListCtrl::OutToIn(const CPDF_Rect & rect) const { CPDF_Point ptLeftBottom = OutToIn(CPDF_Point(rect.left,rect.bottom)); CPDF_Point ptRightTop = OutToIn(CPDF_Point(rect.right,rect.top)); return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y); }
int32_t CFX_ListCtrl::GetItemIndex(const CFX_PointF& point) const { CFX_PointF pt = OuterToInner(OutToIn(point)); bool bFirst = true; bool bLast = true; for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) { if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) { CLST_Rect rcListItem = pListItem->GetRect(); if (IsFloatBigger(pt.y, rcListItem.top)) { bFirst = false; } if (IsFloatSmaller(pt.y, rcListItem.bottom)) { bLast = false; } if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) { return i; } } } if (bFirst) return 0; if (bLast) return m_aListItems.GetSize() - 1; return -1; }
CPVT_WordPlace CPDF_VariableText::SearchWordPlace( const CFX_FloatPoint& point) const { CFX_FloatPoint pt = OutToIn(point); CPVT_WordPlace place = GetBeginWordPlace(); int32_t nLeft = 0; int32_t nRight = m_SectionArray.GetSize() - 1; int32_t nMid = m_SectionArray.GetSize() / 2; FX_BOOL bUp = TRUE; FX_BOOL bDown = TRUE; while (nLeft <= nRight) { if (CSection* pSection = m_SectionArray.GetAt(nMid)) { if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.top)) { bUp = FALSE; } if (IsFloatBigger(pSection->m_SecInfo.rcSection.bottom, pt.y)) { bDown = FALSE; } if (IsFloatSmaller(pt.y, pSection->m_SecInfo.rcSection.top)) { nRight = nMid - 1; nMid = (nLeft + nRight) / 2; continue; } else if (IsFloatBigger(pt.y, pSection->m_SecInfo.rcSection.bottom)) { nLeft = nMid + 1; nMid = (nLeft + nRight) / 2; continue; } else { place = pSection->SearchWordPlace( CFX_FloatPoint(pt.x - pSection->m_SecInfo.rcSection.left, pt.y - pSection->m_SecInfo.rcSection.top)); place.nSecIndex = nMid; return place; } } else { break; } } if (bUp) place = GetBeginWordPlace(); if (bDown) place = GetEndWordPlace(); return place; }
CPVT_WordPlace CPDF_VariableText::GetDownWordPlace( const CPVT_WordPlace& place, const CFX_FloatPoint& point) const { if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) { CPVT_WordPlace temp = place; CFX_FloatPoint pt = OutToIn(point); if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) { return pSection->SearchWordPlace( pt.x - pSection->m_SecInfo.rcSection.left, temp); } if (temp.nSecIndex++ < m_SectionArray.GetSize() - 1) { if (CSection* pNextSection = m_SectionArray.GetAt(temp.nSecIndex)) { temp.nLineIndex = 0; return pNextSection->SearchWordPlace( pt.x - pSection->m_SecInfo.rcSection.left, temp); } } } return place; }
int32_t CFX_ListCtrl::GetItemIndex(const CPDF_Point & point) const { return CFX_List::GetItemIndex(OutToIn(point)); }
CFX_FloatRect CFX_ListCtrl::OutToIn(const CFX_FloatRect& rect) const { CFX_PointF ptLeftBottom = OutToIn(CFX_PointF(rect.left, rect.bottom)); CFX_PointF ptRightTop = OutToIn(CFX_PointF(rect.right, rect.top)); return CFX_FloatRect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y); }