summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-05-12 14:04:06 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-05-15 13:47:55 +0000
commitb084c1f615e9b5d82a36aeedcff2339b7ac91265 (patch)
treeeb436fb5d228c92ec379ad1f15860ba493ca086d /fpdfsdk
parentdc3a87c88da1ac710eadabeb2e5cf01aecb63f4b (diff)
downloadpdfium-b084c1f615e9b5d82a36aeedcff2339b7ac91265.tar.xz
Smells like a leak in PWL_ComboBox.cpp
Change-Id: I519d79b2b22d2b947c546c6285195b8ca52f4993 Reviewed-on: https://pdfium-review.googlesource.com/5471 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/pdfwindow/PWL_ComboBox.cpp124
-rw-r--r--fpdfsdk/pdfwindow/PWL_ComboBox.h12
2 files changed, 70 insertions, 66 deletions
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
index 5adf4561f2..9321e0f606 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
@@ -181,14 +181,13 @@ bool CPWL_CBButton::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
}
CPWL_ComboBox::CPWL_ComboBox()
- : m_pEdit(nullptr),
- m_pButton(nullptr),
- m_pList(nullptr),
- m_bPopup(false),
+ : m_bPopup(false),
m_nPopupWhere(0),
m_nSelectItem(-1),
m_pFillerNotify(nullptr) {}
+CPWL_ComboBox::~CPWL_ComboBox() {}
+
CFX_ByteString CPWL_ComboBox::GetClassName() const {
return "CPWL_ComboBox";
}
@@ -262,72 +261,74 @@ void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) {
}
void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
- if (!m_pEdit) {
- m_pEdit = new CPWL_CBEdit;
- m_pEdit->AttachFFLData(m_pFormFiller);
+ if (m_pEdit)
+ return;
- PWL_CREATEPARAM ecp = cp;
- ecp.pParentWnd = this;
- ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
- PES_AUTOSCROLL | PES_UNDO;
+ m_pEdit = pdfium::MakeUnique<CPWL_CBEdit>();
+ m_pEdit->AttachFFLData(m_pFormFiller);
- if (HasFlag(PWS_AUTOFONTSIZE))
- ecp.dwFlags |= PWS_AUTOFONTSIZE;
+ PWL_CREATEPARAM ecp = cp;
+ ecp.pParentWnd = this;
+ ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER |
+ PES_AUTOSCROLL | PES_UNDO;
- if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
- ecp.dwFlags |= PWS_READONLY;
+ if (HasFlag(PWS_AUTOFONTSIZE))
+ ecp.dwFlags |= PWS_AUTOFONTSIZE;
- ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
- ecp.dwBorderWidth = 0;
- ecp.nBorderStyle = BorderStyle::SOLID;
+ if (!HasFlag(PCBS_ALLOWCUSTOMTEXT))
+ ecp.dwFlags |= PWS_READONLY;
- m_pEdit->Create(ecp);
- }
+ ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
+ ecp.dwBorderWidth = 0;
+ ecp.nBorderStyle = BorderStyle::SOLID;
+ m_pEdit->Create(ecp);
}
void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) {
- if (!m_pButton) {
- m_pButton = new CPWL_CBButton;
-
- PWL_CREATEPARAM bcp = cp;
- bcp.pParentWnd = this;
- bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
- bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
- bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
- bcp.dwBorderWidth = 2;
- bcp.nBorderStyle = BorderStyle::BEVELED;
- bcp.eCursorType = FXCT_ARROW;
-
- m_pButton->Create(bcp);
- }
+ if (m_pButton)
+ return;
+
+ m_pButton = pdfium::MakeUnique<CPWL_CBButton>();
+
+ PWL_CREATEPARAM bcp = cp;
+ bcp.pParentWnd = this;
+ bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND;
+ bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR;
+ bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
+ bcp.dwBorderWidth = 2;
+ bcp.nBorderStyle = BorderStyle::BEVELED;
+ bcp.eCursorType = FXCT_ARROW;
+ m_pButton->Create(bcp);
}
void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
- if (!m_pList) {
- m_pList = new CPWL_CBListBox;
- m_pList->AttachFFLData(m_pFormFiller);
- PWL_CREATEPARAM lcp = cp;
- lcp.pParentWnd = this;
- lcp.dwFlags =
- PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
- lcp.nBorderStyle = BorderStyle::SOLID;
- lcp.dwBorderWidth = 1;
- lcp.eCursorType = FXCT_ARROW;
- lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
-
- if (cp.dwFlags & PWS_AUTOFONTSIZE)
- lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
- else
- lcp.fFontSize = cp.fFontSize;
-
- if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
- lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
-
- if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
- lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
-
- m_pList->Create(lcp);
- }
+ if (m_pList)
+ return;
+
+ m_pList = pdfium::MakeUnique<CPWL_CBListBox>();
+ m_pList->AttachFFLData(m_pFormFiller);
+
+ PWL_CREATEPARAM lcp = cp;
+ lcp.pParentWnd = this;
+ lcp.dwFlags =
+ PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL;
+ lcp.nBorderStyle = BorderStyle::SOLID;
+ lcp.dwBorderWidth = 1;
+ lcp.eCursorType = FXCT_ARROW;
+ lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
+
+ if (cp.dwFlags & PWS_AUTOFONTSIZE)
+ lcp.fFontSize = PWLCB_DEFAULTFONTSIZE;
+ else
+ lcp.fFontSize = cp.fFontSize;
+
+ if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT)
+ lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR;
+
+ if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT)
+ lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR;
+
+ m_pList->Create(lcp);
}
void CPWL_ComboBox::RePosChildWnd() {
@@ -584,14 +585,14 @@ void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd,
intptr_t lParam) {
switch (msg) {
case PNM_LBUTTONDOWN:
- if (pWnd == m_pButton) {
+ if (pWnd == m_pButton.get()) {
SetPopup(!m_bPopup);
return;
}
break;
case PNM_LBUTTONUP:
if (m_pEdit && m_pList) {
- if (pWnd == m_pList) {
+ if (pWnd == m_pList.get()) {
SetSelectText();
SelectAll();
m_pEdit->SetFocus();
@@ -599,6 +600,7 @@ void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd,
return;
}
}
+ break;
}
CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.h b/fpdfsdk/pdfwindow/PWL_ComboBox.h
index e1a8df7561..a687eb8e94 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_
#define FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_
+#include <memory>
+
#include "fpdfsdk/pdfwindow/PWL_Edit.h"
#include "fpdfsdk/pdfwindow/PWL_ListBox.h"
#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
@@ -47,9 +49,9 @@ class CPWL_CBButton : public CPWL_Wnd {
class CPWL_ComboBox : public CPWL_Wnd {
public:
CPWL_ComboBox();
- ~CPWL_ComboBox() override {}
+ ~CPWL_ComboBox() override;
- CPWL_Edit* GetEdit() const { return m_pEdit; }
+ CPWL_Edit* GetEdit() const { return m_pEdit.get(); }
// CPWL_Wnd:
CFX_ByteString GetClassName() const override;
@@ -90,9 +92,9 @@ class CPWL_ComboBox : public CPWL_Wnd {
void CreateListBox(const PWL_CREATEPARAM& cp);
void SetPopup(bool bPopup);
- CPWL_CBEdit* m_pEdit;
- CPWL_CBButton* m_pButton;
- CPWL_CBListBox* m_pList;
+ std::unique_ptr<CPWL_CBEdit> m_pEdit;
+ std::unique_ptr<CPWL_CBButton> m_pButton;
+ std::unique_ptr<CPWL_CBListBox> m_pList;
bool m_bPopup;
CFX_FloatRect m_rcOldWindow;
int32_t m_nPopupWhere;