From 732f6a01f11749192badba3d5151a33460560b7f Mon Sep 17 00:00:00 2001 From: thestig Date: Thu, 12 May 2016 10:41:56 -0700 Subject: IFX_Edit::NewEdit never returns nullptr. Review-Url: https://codereview.chromium.org/1969353002 --- fpdfsdk/fsdk_baseform.cpp | 430 +++++++++++++++++++------------------ fpdfsdk/fxedit/fxet_list.cpp | 27 +-- fpdfsdk/pdfwindow/PWL_EditCtrl.cpp | 61 ++---- fpdfsdk/pdfwindow/PWL_Label.cpp | 10 +- fpdfsdk/pdfwindow/PWL_Utils.cpp | 384 ++++++++++++++++----------------- 5 files changed, 437 insertions(+), 475 deletions(-) diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp index a5cb562a3b..46e9c46fb1 100644 --- a/fpdfsdk/fsdk_baseform.cpp +++ b/fpdfsdk/fsdk_baseform.cpp @@ -1352,62 +1352,61 @@ void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { rcButton.left = rcButton.right - 13; rcButton.Normalize(); - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->EnableRefresh(FALSE); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->EnableRefresh(FALSE); - CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); - CPDFDoc_Environment* pEnv = pDoc->GetEnv(); - CBA_FontMap font_map(this, pEnv->GetSysHandler()); - pEdit->SetFontMap(&font_map); + CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); + CPDFDoc_Environment* pEnv = pDoc->GetEnv(); + CBA_FontMap font_map(this, pEnv->GetSysHandler()); + pEdit->SetFontMap(&font_map); - CFX_FloatRect rcEdit = rcClient; - rcEdit.right = rcButton.left; - rcEdit.Normalize(); + CFX_FloatRect rcEdit = rcClient; + rcEdit.right = rcButton.left; + rcEdit.Normalize(); - pEdit->SetPlateRect(rcEdit); - pEdit->SetAlignmentV(1); + pEdit->SetPlateRect(rcEdit); + pEdit->SetAlignmentV(1); - FX_FLOAT fFontSize = GetFontSize(); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(TRUE); - else - pEdit->SetFontSize(fFontSize); + FX_FLOAT fFontSize = GetFontSize(); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(TRUE); + else + pEdit->SetFontSize(fFontSize); - pEdit->Initialize(); + pEdit->Initialize(); - if (sValue) { - pEdit->SetText(sValue); - } else { - int32_t nCurSel = pField->GetSelectedIndex(0); - - if (nCurSel < 0) - pEdit->SetText(pField->GetValue().c_str()); - else - pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); - } + if (sValue) { + pEdit->SetText(sValue); + } else { + int32_t nCurSel = pField->GetSelectedIndex(0); - CFX_FloatRect rcContent = pEdit->GetContentRect(); + if (nCurSel < 0) + pEdit->SetText(pField->GetValue().c_str()); + else + pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); + } - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); - if (sEdit.GetLength() > 0) { - sBody << "/Tx BMC\n" - << "q\n"; - if (rcContent.Width() > rcEdit.Width() || - rcContent.Height() > rcEdit.Height()) { - sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() - << " " << rcEdit.Height() << " re\nW\nn\n"; - } + CFX_FloatRect rcContent = pEdit->GetContentRect(); - CPWL_Color crText = GetTextPWLColor(); - sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit - << "ET\n" - << "Q\nEMC\n"; + CFX_ByteString sEdit = + CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); + if (sEdit.GetLength() > 0) { + sBody << "/Tx BMC\n" + << "q\n"; + if (rcContent.Width() > rcEdit.Width() || + rcContent.Height() > rcEdit.Height()) { + sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() + << " " << rcEdit.Height() << " re\nW\nn\n"; } - IFX_Edit::DelEdit(pEdit); + CPWL_Color crText = GetTextPWLColor(); + sBody << "BT\n" + << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" + << "Q\nEMC\n"; } + IFX_Edit::DelEdit(pEdit); + sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + @@ -1422,83 +1421,85 @@ void CPDFSDK_Widget::ResetAppearance_ListBox() { CFX_FloatRect rcClient = GetClientRect(); CFX_ByteTextBuf sBody, sLines; - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->EnableRefresh(FALSE); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->EnableRefresh(FALSE); - CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); - CPDFDoc_Environment* pEnv = pDoc->GetEnv(); + CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); + CPDFDoc_Environment* pEnv = pDoc->GetEnv(); - CBA_FontMap font_map(this, pEnv->GetSysHandler()); - pEdit->SetFontMap(&font_map); + CBA_FontMap font_map(this, pEnv->GetSysHandler()); + pEdit->SetFontMap(&font_map); - pEdit->SetPlateRect( - CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); + pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); - FX_FLOAT fFontSize = GetFontSize(); + FX_FLOAT fFontSize = GetFontSize(); - if (IsFloatZero(fFontSize)) - pEdit->SetFontSize(12.0f); - else - pEdit->SetFontSize(fFontSize); + if (IsFloatZero(fFontSize)) + pEdit->SetFontSize(12.0f); + else + pEdit->SetFontSize(fFontSize); - pEdit->Initialize(); + pEdit->Initialize(); - CFX_ByteTextBuf sList; - FX_FLOAT fy = rcClient.top; + CFX_ByteTextBuf sList; + FX_FLOAT fy = rcClient.top; - int32_t nTop = pField->GetTopVisibleIndex(); - int32_t nCount = pField->CountOptions(); - int32_t nSelCount = pField->CountSelectedItems(); + int32_t nTop = pField->GetTopVisibleIndex(); + int32_t nCount = pField->CountOptions(); + int32_t nSelCount = pField->CountSelectedItems(); - for (int32_t i = nTop; i < nCount; i++) { - FX_BOOL bSelected = FALSE; - for (int32_t j = 0; j < nSelCount; j++) { - if (pField->GetSelectedIndex(j) == i) { - bSelected = TRUE; - break; - } + for (int32_t i = nTop; i < nCount; i++) { + FX_BOOL bSelected = FALSE; + for (int32_t j = 0; j < nSelCount; j++) { + if (pField->GetSelectedIndex(j) == i) { + bSelected = TRUE; + break; } + } - pEdit->SetText(pField->GetOptionLabel(i).c_str()); - - CFX_FloatRect rcContent = pEdit->GetContentRect(); - FX_FLOAT fItemHeight = rcContent.Height(); - - if (bSelected) { - CFX_FloatRect rcItem = - CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); - sList << "q\n" << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, - 113.0f / 255.0f), - TRUE) - << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() - << " " << rcItem.Height() << " re f\n" - << "Q\n"; - - sList << "BT\n" << CPWL_Utils::GetColorAppStream( - CPWL_Color(COLORTYPE_GRAY, 1), TRUE) - << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) - << "ET\n"; - } else { - CPWL_Color crText = GetTextPWLColor(); - sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText, TRUE) - << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) - << "ET\n"; - } + pEdit->SetText(pField->GetOptionLabel(i).c_str()); - fy -= fItemHeight; + CFX_FloatRect rcContent = pEdit->GetContentRect(); + FX_FLOAT fItemHeight = rcContent.Height(); + + if (bSelected) { + CFX_FloatRect rcItem = + CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); + sList << "q\n" + << CPWL_Utils::GetColorAppStream( + CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, + 113.0f / 255.0f), + TRUE) + << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() + << " " << rcItem.Height() << " re f\n" + << "Q\n"; + + sList << "BT\n" + << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), + TRUE) + << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) + << "ET\n"; + } else { + CPWL_Color crText = GetTextPWLColor(); + sList << "BT\n" + << CPWL_Utils::GetColorAppStream(crText, TRUE) + << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) + << "ET\n"; } - if (sList.GetSize() > 0) { - sBody << "/Tx BMC\n" - << "q\n" << rcClient.left << " " << rcClient.bottom << " " - << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; - sBody << sList << "Q\nEMC\n"; - } + fy -= fItemHeight; + } - IFX_Edit::DelEdit(pEdit); + if (sList.GetSize() > 0) { + sBody << "/Tx BMC\n" + << "q\n" + << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() + << " " << rcClient.Height() << " re\nW\nn\n"; + sBody << sList << "Q\nEMC\n"; } + IFX_Edit::DelEdit(pEdit); + CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.AsStringC() + sBody.AsStringC(); @@ -1510,144 +1511,145 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { CPDF_FormField* pField = pControl->GetField(); CFX_ByteTextBuf sBody, sLines; - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->EnableRefresh(FALSE); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->EnableRefresh(FALSE); - CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); - CPDFDoc_Environment* pEnv = pDoc->GetEnv(); + CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); + CPDFDoc_Environment* pEnv = pDoc->GetEnv(); - CBA_FontMap font_map(this, pEnv->GetSysHandler()); - pEdit->SetFontMap(&font_map); + CBA_FontMap font_map(this, pEnv->GetSysHandler()); + pEdit->SetFontMap(&font_map); - CFX_FloatRect rcClient = GetClientRect(); - pEdit->SetPlateRect(rcClient); - pEdit->SetAlignmentH(pControl->GetControlAlignment()); + CFX_FloatRect rcClient = GetClientRect(); + pEdit->SetPlateRect(rcClient); + pEdit->SetAlignmentH(pControl->GetControlAlignment()); - uint32_t dwFieldFlags = pField->GetFieldFlags(); - FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; + uint32_t dwFieldFlags = pField->GetFieldFlags(); + FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; - if (bMultiLine) { - pEdit->SetMultiLine(TRUE); - pEdit->SetAutoReturn(TRUE); - } else { - pEdit->SetAlignmentV(1); - } + if (bMultiLine) { + pEdit->SetMultiLine(TRUE); + pEdit->SetAutoReturn(TRUE); + } else { + pEdit->SetAlignmentV(1); + } - uint16_t subWord = 0; - if ((dwFieldFlags >> 13) & 1) { - subWord = '*'; - pEdit->SetPasswordChar(subWord); - } + uint16_t subWord = 0; + if ((dwFieldFlags >> 13) & 1) { + subWord = '*'; + pEdit->SetPasswordChar(subWord); + } - int nMaxLen = pField->GetMaxLen(); - FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; - FX_FLOAT fFontSize = GetFontSize(); + int nMaxLen = pField->GetMaxLen(); + FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; + FX_FLOAT fFontSize = GetFontSize(); #ifdef PDF_ENABLE_XFA - CFX_WideString sValueTmp; - if (!sValue && GetMixXFAWidget()) { - sValueTmp = GetValue(TRUE); - sValue = sValueTmp.c_str(); - } + CFX_WideString sValueTmp; + if (!sValue && GetMixXFAWidget()) { + sValueTmp = GetValue(TRUE); + sValue = sValueTmp.c_str(); + } #endif // PDF_ENABLE_XFA - if (nMaxLen > 0) { - if (bCharArray) { - pEdit->SetCharArray(nMaxLen); + if (nMaxLen > 0) { + if (bCharArray) { + pEdit->SetCharArray(nMaxLen); - if (IsFloatZero(fFontSize)) { - fFontSize = CPWL_Edit::GetCharArrayAutoFontSize( - font_map.GetPDFFont(0), rcClient, nMaxLen); - } - } else { - if (sValue) - nMaxLen = wcslen((const wchar_t*)sValue); - pEdit->SetLimitChar(nMaxLen); + if (IsFloatZero(fFontSize)) { + fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), + rcClient, nMaxLen); } + } else { + if (sValue) + nMaxLen = wcslen((const wchar_t*)sValue); + pEdit->SetLimitChar(nMaxLen); } + } - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(TRUE); - else - pEdit->SetFontSize(fFontSize); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(TRUE); + else + pEdit->SetFontSize(fFontSize); - pEdit->Initialize(); + pEdit->Initialize(); - if (sValue) - pEdit->SetText(sValue); - else - pEdit->SetText(pField->GetValue().c_str()); + if (sValue) + pEdit->SetText(sValue); + else + pEdit->SetText(pField->GetValue().c_str()); - CFX_FloatRect rcContent = pEdit->GetContentRect(); + CFX_FloatRect rcContent = pEdit->GetContentRect(); - CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( - pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord); + CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( + pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord); - if (sEdit.GetLength() > 0) { - sBody << "/Tx BMC\n" - << "q\n"; - if (rcContent.Width() > rcClient.Width() || - rcContent.Height() > rcClient.Height()) { - sBody << rcClient.left << " " << rcClient.bottom << " " - << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; - } - CPWL_Color crText = GetTextPWLColor(); - sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit - << "ET\n" - << "Q\nEMC\n"; + if (sEdit.GetLength() > 0) { + sBody << "/Tx BMC\n" + << "q\n"; + if (rcContent.Width() > rcClient.Width() || + rcContent.Height() > rcClient.Height()) { + sBody << rcClient.left << " " << rcClient.bottom << " " + << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; } - - if (bCharArray) { - switch (GetBorderStyle()) { - case BBS_SOLID: { - CFX_ByteString sColor = - CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); - if (sColor.GetLength() > 0) { - sLines << "q\n" << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) - << " 2 J 0 j\n"; - - for (int32_t i = 1; i < nMaxLen; i++) { - sLines << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.top << " l S\n"; - } - - sLines << "Q\n"; + CPWL_Color crText = GetTextPWLColor(); + sBody << "BT\n" + << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" + << "Q\nEMC\n"; + } + + if (bCharArray) { + switch (GetBorderStyle()) { + case BBS_SOLID: { + CFX_ByteString sColor = + CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); + if (sColor.GetLength() > 0) { + sLines << "q\n" + << GetBorderWidth() << " w\n" + << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) + << " 2 J 0 j\n"; + + for (int32_t i = 1; i < nMaxLen; i++) { + sLines << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.top << " l S\n"; } - } break; - case BBS_DASH: { - CFX_ByteString sColor = - CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); - if (sColor.GetLength() > 0) { - CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); - - sLines << "q\n" << GetBorderWidth() << " w\n" - << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) - << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " - << dsBorder.nPhase << " d\n"; - - for (int32_t i = 1; i < nMaxLen; i++) { - sLines << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.bottom << " m\n" - << rcClient.left + - ((rcClient.right - rcClient.left) / nMaxLen) * i - << " " << rcClient.top << " l S\n"; - } - sLines << "Q\n"; + sLines << "Q\n"; + } + } break; + case BBS_DASH: { + CFX_ByteString sColor = + CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); + if (sColor.GetLength() > 0) { + CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); + + sLines << "q\n" + << GetBorderWidth() << " w\n" + << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) + << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " + << dsBorder.nPhase << " d\n"; + + for (int32_t i = 1; i < nMaxLen; i++) { + sLines << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.bottom << " m\n" + << rcClient.left + + ((rcClient.right - rcClient.left) / nMaxLen) * i + << " " << rcClient.top << " l S\n"; } - } break; - } - } - IFX_Edit::DelEdit(pEdit); + sLines << "Q\n"; + } + } break; + } } + IFX_Edit::DelEdit(pEdit); + CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLines.AsStringC() + sBody.AsStringC(); WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); diff --git a/fpdfsdk/fxedit/fxet_list.cpp b/fpdfsdk/fxedit/fxet_list.cpp index 63465ebe44..639569898e 100644 --- a/fpdfsdk/fxedit/fxet_list.cpp +++ b/fpdfsdk/fxedit/fxet_list.cpp @@ -10,10 +10,9 @@ #include "fpdfsdk/fxedit/include/fxet_edit.h" CFX_ListItem::CFX_ListItem() - : m_pEdit(NULL), + : m_pEdit(IFX_Edit::NewEdit()), m_bSelected(FALSE), m_rcListItem(0.0f, 0.0f, 0.0f, 0.0f) { - m_pEdit = IFX_Edit::NewEdit(); m_pEdit->SetAlignmentV(1); m_pEdit->Initialize(); } @@ -23,8 +22,7 @@ CFX_ListItem::~CFX_ListItem() { } void CFX_ListItem::SetFontMap(IPVT_FontMap* pFontMap) { - if (m_pEdit) - m_pEdit->SetFontMap(pFontMap); + m_pEdit->SetFontMap(pFontMap); } IFX_Edit* CFX_ListItem::GetEdit() const { @@ -32,10 +30,7 @@ IFX_Edit* CFX_ListItem::GetEdit() const { } IFX_Edit_Iterator* CFX_ListItem::GetIterator() const { - if (m_pEdit) - return m_pEdit->GetIterator(); - - return NULL; + return m_pEdit->GetIterator(); } void CFX_ListItem::SetRect(const CLST_Rect& rect) { @@ -55,20 +50,15 @@ void CFX_ListItem::SetSelect(FX_BOOL bSelected) { } void CFX_ListItem::SetText(const FX_WCHAR* text) { - if (m_pEdit) - m_pEdit->SetText(text); + m_pEdit->SetText(text); } void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize) { - if (m_pEdit) - m_pEdit->SetFontSize(fFontSize); + m_pEdit->SetFontSize(fFontSize); } FX_FLOAT CFX_ListItem::GetItemHeight() const { - if (m_pEdit) - return m_pEdit->GetContentRect().Height(); - - return 0.0f; + return m_pEdit->GetContentRect().Height(); } uint16_t CFX_ListItem::GetFirstChar() const { @@ -83,10 +73,7 @@ uint16_t CFX_ListItem::GetFirstChar() const { } CFX_WideString CFX_ListItem::GetText() const { - if (m_pEdit) - return m_pEdit->GetText(); - - return L""; + return m_pEdit->GetText(); } CFX_List::CFX_List() diff --git a/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp b/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp index 07ac4af781..8a0dea1980 100644 --- a/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp +++ b/fpdfsdk/pdfwindow/PWL_EditCtrl.cpp @@ -21,15 +21,12 @@ #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) CPWL_EditCtrl::CPWL_EditCtrl() - : m_pEdit(NULL), + : m_pEdit(IFX_Edit::NewEdit()), m_pEditCaret(NULL), m_bMouseDown(FALSE), m_pEditNotify(NULL), m_nCharSet(DEFAULT_CHARSET), - m_nCodePage(0) { - m_pEdit = IFX_Edit::NewEdit(); - ASSERT(m_pEdit); -} + m_nCodePage(0) {} CPWL_EditCtrl::~CPWL_EditCtrl() { IFX_Edit::DelEdit(m_pEdit); @@ -121,19 +118,20 @@ void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { } void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { - if (!m_pEditCaret) { - m_pEditCaret = new CPWL_Caret; - m_pEditCaret->SetInvalidRect(GetClientRect()); - - PWL_CREATEPARAM ecp = cp; - ecp.pParentWnd = this; - ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; - ecp.dwBorderWidth = 0; - ecp.nBorderStyle = PBS_SOLID; - ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); - - m_pEditCaret->Create(ecp); - } + if (m_pEditCaret) + return; + + m_pEditCaret = new CPWL_Caret; + m_pEditCaret->SetInvalidRect(GetClientRect()); + + PWL_CREATEPARAM ecp = cp; + ecp.pParentWnd = this; + ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; + ecp.dwBorderWidth = 0; + ecp.nBorderStyle = PBS_SOLID; + ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); + + m_pEditCaret->Create(ecp); } void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) { @@ -409,44 +407,31 @@ void CPWL_EditCtrl::SelectAll() { } void CPWL_EditCtrl::Paint() { - if (m_pEdit) - m_pEdit->Paint(); + m_pEdit->Paint(); } void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) { - if (m_pEdit) - m_pEdit->EnableRefresh(bRefresh); + m_pEdit->EnableRefresh(bRefresh); } int32_t CPWL_EditCtrl::GetCaret() const { - if (m_pEdit) - return m_pEdit->GetCaret(); - - return -1; + return m_pEdit->GetCaret(); } void CPWL_EditCtrl::SetCaret(int32_t nPos) { - if (m_pEdit) - m_pEdit->SetCaret(nPos); + m_pEdit->SetCaret(nPos); } int32_t CPWL_EditCtrl::GetTotalWords() const { - if (m_pEdit) - return m_pEdit->GetTotalWords(); - - return 0; + return m_pEdit->GetTotalWords(); } void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) { - if (m_pEdit) - m_pEdit->SetScrollPos(point); + m_pEdit->SetScrollPos(point); } CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const { - if (m_pEdit) - return m_pEdit->GetScrollPos(); - - return CFX_FloatPoint(0.0f, 0.0f); + return m_pEdit->GetScrollPos(); } CPDF_Font* CPWL_EditCtrl::GetCaretFont() const { diff --git a/fpdfsdk/pdfwindow/PWL_Label.cpp b/fpdfsdk/pdfwindow/PWL_Label.cpp index 9cb9791444..7abeb0d558 100644 --- a/fpdfsdk/pdfwindow/PWL_Label.cpp +++ b/fpdfsdk/pdfwindow/PWL_Label.cpp @@ -9,10 +9,7 @@ #include "fpdfsdk/pdfwindow/PWL_Utils.h" #include "fpdfsdk/pdfwindow/PWL_Wnd.h" -CPWL_Label::CPWL_Label() : m_pEdit(NULL) { - m_pEdit = IFX_Edit::NewEdit(); - ASSERT(m_pEdit); -} +CPWL_Label::CPWL_Label() : m_pEdit(IFX_Edit::NewEdit()) {} CPWL_Label::~CPWL_Label() { IFX_Edit::DelEdit(m_pEdit); @@ -144,8 +141,5 @@ void CPWL_Label::SetLimitChar(int32_t nLimitChar) { } int32_t CPWL_Label::GetTotalWords() { - if (m_pEdit) - return m_pEdit->GetTotalWords(); - - return 0; + return m_pEdit->GetTotalWords(); } diff --git a/fpdfsdk/pdfwindow/PWL_Utils.cpp b/fpdfsdk/pdfwindow/PWL_Utils.cpp index 2c52309b3f..2e60471927 100644 --- a/fpdfsdk/pdfwindow/PWL_Utils.cpp +++ b/fpdfsdk/pdfwindow/PWL_Utils.cpp @@ -441,29 +441,26 @@ CFX_ByteString CPWL_Utils::GetTextAppStream(const CFX_FloatRect& rcBBox, const CPWL_Color& crText) { CFX_ByteTextBuf sRet; - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->SetFontMap(pFontMap); - pEdit->SetPlateRect(rcBBox); - pEdit->SetAlignmentH(nAlignmentH); - pEdit->SetAlignmentV(nAlignmentV); - pEdit->SetMultiLine(bMultiLine); - pEdit->SetAutoReturn(bAutoReturn); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(TRUE); - else - pEdit->SetFontSize(fFontSize); - - pEdit->Initialize(); - pEdit->SetText(sText.c_str()); + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->SetFontMap(pFontMap); + pEdit->SetPlateRect(rcBBox); + pEdit->SetAlignmentH(nAlignmentH); + pEdit->SetAlignmentV(nAlignmentV); + pEdit->SetMultiLine(bMultiLine); + pEdit->SetAutoReturn(bAutoReturn); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(TRUE); + else + pEdit->SetFontSize(fFontSize); - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); - if (sEdit.GetLength() > 0) { - sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit - << "ET\n"; - } - IFX_Edit::DelEdit(pEdit); - } + pEdit->Initialize(); + pEdit->SetText(sText.c_str()); + + CFX_ByteString sEdit = + CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); + if (sEdit.GetLength() > 0) + sRet << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; + IFX_Edit::DelEdit(pEdit); return sRet.AsStringC(); } @@ -478,222 +475,219 @@ CFX_ByteString CPWL_Utils::GetPushButtonAppStream(const CFX_FloatRect& rcBBox, int32_t nLayOut) { const FX_FLOAT fAutoFontScale = 1.0f / 3.0f; - if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { - pEdit->SetFontMap(pFontMap); - pEdit->SetAlignmentH(1); - pEdit->SetAlignmentV(1); - pEdit->SetMultiLine(FALSE); - pEdit->SetAutoReturn(FALSE); - if (IsFloatZero(fFontSize)) - pEdit->SetAutoFontSize(TRUE); - else - pEdit->SetFontSize(fFontSize); - - pEdit->Initialize(); - pEdit->SetText(sLabel.c_str()); - - CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); - CPWL_Icon Icon; - PWL_CREATEPARAM cp; - cp.dwFlags = PWS_VISIBLE; - Icon.Create(cp); - Icon.SetIconFit(&IconFit); - Icon.SetPDFStream(pIconStream); - - CFX_FloatRect rcLabel = CFX_FloatRect(0, 0, 0, 0); - CFX_FloatRect rcIcon = CFX_FloatRect(0, 0, 0, 0); - FX_FLOAT fWidth = 0.0f; - FX_FLOAT fHeight = 0.0f; - - switch (nLayOut) { - case PPBL_LABEL: - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - break; - case PPBL_ICON: - rcIcon = rcBBox; - rcLabel = CFX_FloatRect(0, 0, 0, 0); - break; - case PPBL_ICONTOPLABELBOTTOM: + IFX_Edit* pEdit = IFX_Edit::NewEdit(); + pEdit->SetFontMap(pFontMap); + pEdit->SetAlignmentH(1); + pEdit->SetAlignmentV(1); + pEdit->SetMultiLine(FALSE); + pEdit->SetAutoReturn(FALSE); + if (IsFloatZero(fFontSize)) + pEdit->SetAutoFontSize(TRUE); + else + pEdit->SetFontSize(fFontSize); + + pEdit->Initialize(); + pEdit->SetText(sLabel.c_str()); + + CFX_FloatRect rcLabelContent = pEdit->GetContentRect(); + CPWL_Icon Icon; + PWL_CREATEPARAM cp; + cp.dwFlags = PWS_VISIBLE; + Icon.Create(cp); + Icon.SetIconFit(&IconFit); + Icon.SetPDFStream(pIconStream); + + CFX_FloatRect rcLabel = CFX_FloatRect(0, 0, 0, 0); + CFX_FloatRect rcIcon = CFX_FloatRect(0, 0, 0, 0); + FX_FLOAT fWidth = 0.0f; + FX_FLOAT fHeight = 0.0f; + + switch (nLayOut) { + case PPBL_LABEL: + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + break; + case PPBL_ICON: + rcIcon = rcBBox; + rcLabel = CFX_FloatRect(0, 0, 0, 0); + break; + case PPBL_ICONTOPLABELBOTTOM: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fHeight = rcBBox.top - rcBBox.bottom; + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcBBox.bottom + fHeight * fAutoFontScale); + rcIcon = + CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top); + } else { + fHeight = rcLabelContent.Height(); - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fHeight = rcBBox.top - rcBBox.bottom; + if (rcBBox.bottom + fHeight > rcBBox.top) { + rcIcon = CFX_FloatRect(0, 0, 0, 0); + rcLabel = rcBBox; + } else { rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcBBox.bottom + fHeight * fAutoFontScale); + rcBBox.bottom + fHeight); rcIcon = CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, rcBBox.top); - } else { - fHeight = rcLabelContent.Height(); - - if (rcBBox.bottom + fHeight > rcBBox.top) { - rcIcon = CFX_FloatRect(0, 0, 0, 0); - rcLabel = rcBBox; - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcBBox.bottom + fHeight); - rcIcon = CFX_FloatRect(rcBBox.left, rcLabel.top, rcBBox.right, - rcBBox.top); - } } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } - break; - case PPBL_LABELTOPICONBOTTOM: + break; + case PPBL_LABELTOPICONBOTTOM: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fHeight = rcBBox.top - rcBBox.bottom; + rcLabel = + CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight * fAutoFontScale, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, + rcLabel.bottom); + } else { + fHeight = rcLabelContent.Height(); - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fHeight = rcBBox.top - rcBBox.bottom; - rcLabel = CFX_FloatRect(rcBBox.left, - rcBBox.top - fHeight * fAutoFontScale, + if (rcBBox.bottom + fHeight > rcBBox.top) { + rcIcon = CFX_FloatRect(0, 0, 0, 0); + rcLabel = rcBBox; + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight, rcBBox.right, rcBBox.top); rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, rcLabel.bottom); - } else { - fHeight = rcLabelContent.Height(); - - if (rcBBox.bottom + fHeight > rcBBox.top) { - rcIcon = CFX_FloatRect(0, 0, 0, 0); - rcLabel = rcBBox; - } else { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.top - fHeight, - rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcBBox.right, - rcLabel.bottom); - } } - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } - break; - case PPBL_ICONLEFTLABELRIGHT: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fWidth = rcBBox.right - rcBBox.left; - rcLabel = CFX_FloatRect(rcBBox.right - fWidth * fAutoFontScale, - rcBBox.bottom, rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); + break; + case PPBL_ICONLEFTLABELRIGHT: - if (rcLabelContent.Width() < fWidth * fAutoFontScale) { - } else { - if (rcLabelContent.Width() < fWidth) { - rcLabel = - CFX_FloatRect(rcBBox.right - rcLabelContent.Width(), + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fWidth = rcBBox.right - rcBBox.left; + rcLabel = CFX_FloatRect(rcBBox.right - fWidth * fAutoFontScale, rcBBox.bottom, rcBBox.right, rcBBox.top); - rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, - rcBBox.top); - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - } - } else { - fWidth = rcLabelContent.Width(); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, + rcBBox.top); - if (rcBBox.left + fWidth > rcBBox.right) { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } else { - rcLabel = CFX_FloatRect(rcBBox.right - fWidth, rcBBox.bottom, - rcBBox.right, rcBBox.top); + if (rcLabelContent.Width() < fWidth * fAutoFontScale) { + } else { + if (rcLabelContent.Width() < fWidth) { + rcLabel = CFX_FloatRect(rcBBox.right - rcLabelContent.Width(), + rcBBox.bottom, rcBBox.right, rcBBox.top); rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, rcBBox.top); + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); } } } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } + fWidth = rcLabelContent.Width(); - break; - case PPBL_LABELLEFTICONRIGHT: - - if (pIconStream) { - if (IsFloatZero(fFontSize)) { - fWidth = rcBBox.right - rcBBox.left; - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + fWidth * fAutoFontScale, - rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + if (rcBBox.left + fWidth > rcBBox.right) { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } else { + rcLabel = CFX_FloatRect(rcBBox.right - fWidth, rcBBox.bottom, + rcBBox.right, rcBBox.top); + rcIcon = CFX_FloatRect(rcBBox.left, rcBBox.bottom, rcLabel.left, rcBBox.top); + } + } + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } - if (rcLabelContent.Width() < fWidth * fAutoFontScale) { - } else { - if (rcLabelContent.Width() < fWidth) { - rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + rcLabelContent.Width(), - rcBBox.top); - rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, - rcBBox.right, rcBBox.top); - } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } - } + break; + case PPBL_LABELLEFTICONRIGHT: + + if (pIconStream) { + if (IsFloatZero(fFontSize)) { + fWidth = rcBBox.right - rcBBox.left; + rcLabel = + CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + fWidth * fAutoFontScale, rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + + if (rcLabelContent.Width() < fWidth * fAutoFontScale) { } else { - fWidth = rcLabelContent.Width(); - - if (rcBBox.left + fWidth > rcBBox.right) { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } else { + if (rcLabelContent.Width() < fWidth) { rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, - rcBBox.left + fWidth, rcBBox.top); + rcBBox.left + rcLabelContent.Width(), + rcBBox.top); rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, rcBBox.top); + } else { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); } } } else { - rcLabel = rcBBox; - rcIcon = CFX_FloatRect(0, 0, 0, 0); - } + fWidth = rcLabelContent.Width(); - break; - case PPBL_LABELOVERICON: + if (rcBBox.left + fWidth > rcBBox.right) { + rcLabel = rcBBox; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } else { + rcLabel = CFX_FloatRect(rcBBox.left, rcBBox.bottom, + rcBBox.left + fWidth, rcBBox.top); + rcIcon = CFX_FloatRect(rcLabel.right, rcBBox.bottom, rcBBox.right, + rcBBox.top); + } + } + } else { rcLabel = rcBBox; - rcIcon = rcBBox; - break; - } - - CFX_ByteTextBuf sAppStream, sTemp; + rcIcon = CFX_FloatRect(0, 0, 0, 0); + } - if (!rcIcon.IsEmpty()) { - Icon.Move(rcIcon, FALSE, FALSE); - sTemp << Icon.GetImageAppStream(); - } + break; + case PPBL_LABELOVERICON: + rcLabel = rcBBox; + rcIcon = rcBBox; + break; + } - Icon.Destroy(); + CFX_ByteTextBuf sAppStream, sTemp; - if (!rcLabel.IsEmpty()) { - pEdit->SetPlateRect(rcLabel); - CFX_ByteString sEdit = - CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); - if (sEdit.GetLength() > 0) { - sTemp << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit - << "ET\n"; - } - } + if (!rcIcon.IsEmpty()) { + Icon.Move(rcIcon, FALSE, FALSE); + sTemp << Icon.GetImageAppStream(); + } - IFX_Edit::DelEdit(pEdit); + Icon.Destroy(); - if (sTemp.GetSize() > 0) { - sAppStream << "q\n" << rcBBox.left << " " << rcBBox.bottom << " " - << rcBBox.right - rcBBox.left << " " - << rcBBox.top - rcBBox.bottom << " re W n\n"; - sAppStream << sTemp << "Q\n"; + if (!rcLabel.IsEmpty()) { + pEdit->SetPlateRect(rcLabel); + CFX_ByteString sEdit = + CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); + if (sEdit.GetLength() > 0) { + sTemp << "BT\n" + << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"; } + } - return sAppStream.AsStringC(); + IFX_Edit::DelEdit(pEdit); + + if (sTemp.GetSize() > 0) { + sAppStream << "q\n" + << rcBBox.left << " " << rcBBox.bottom << " " + << rcBBox.right - rcBBox.left << " " + << rcBBox.top - rcBBox.bottom << " re W n\n"; + sAppStream << sTemp << "Q\n"; } - return ""; + return sAppStream.AsStringC(); } CFX_ByteString CPWL_Utils::GetColorAppStream(const CPWL_Color& color, -- cgit v1.2.3