John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/PWL_ComboBox.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
dsinclair | 48baa5f | 2016-04-06 10:00:40 -0700 | [diff] [blame] | 9 | #include "core/fxge/include/fx_ge.h" |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 10 | #include "fpdfsdk/fxedit/include/fxet_list.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 11 | #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
| 12 | #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 13 | #include "fpdfsdk/pdfwindow/PWL_ListBox.h" |
| 14 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 15 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 16 | #include "public/fpdf_fwlevent.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 18 | #define PWLCB_DEFAULTFONTSIZE 12.0f |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 19 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 20 | #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
| 21 | #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
| 22 | #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
| 23 | #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 25 | FX_BOOL CPWL_CBListBox::OnLButtonUp(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 26 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 27 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | if (m_bMouseDown) { |
| 30 | ReleaseCapture(); |
| 31 | m_bMouseDown = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | if (ClientHitTest(point)) { |
| 34 | if (CPWL_Wnd* pParent = GetParentWindow()) { |
| 35 | pParent->OnNotify(this, PNM_LBUTTONUP, 0, |
| 36 | PWL_MAKEDWORD(point.x, point.y)); |
| 37 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 38 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | FX_BOOL bExit = FALSE; |
| 40 | OnNotifySelChanged(FALSE, bExit, nFlag); |
| 41 | if (bExit) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 42 | return FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 43 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 45 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 49 | FX_BOOL CPWL_CBListBox::OnKeyDownWithExit(uint16_t nChar, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | FX_BOOL& bExit, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 51 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | if (!m_pList) |
| 53 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | switch (nChar) { |
| 56 | default: |
| 57 | return FALSE; |
| 58 | case FWL_VKEY_Up: |
| 59 | case FWL_VKEY_Down: |
| 60 | case FWL_VKEY_Home: |
| 61 | case FWL_VKEY_Left: |
| 62 | case FWL_VKEY_End: |
| 63 | case FWL_VKEY_Right: |
| 64 | break; |
| 65 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | switch (nChar) { |
| 68 | case FWL_VKEY_Up: |
| 69 | m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 70 | break; |
| 71 | case FWL_VKEY_Down: |
| 72 | m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 73 | break; |
| 74 | case FWL_VKEY_Home: |
| 75 | m_pList->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 76 | break; |
| 77 | case FWL_VKEY_Left: |
| 78 | m_pList->OnVK_LEFT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 79 | break; |
| 80 | case FWL_VKEY_End: |
| 81 | m_pList->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 82 | break; |
| 83 | case FWL_VKEY_Right: |
| 84 | m_pList->OnVK_RIGHT(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 85 | break; |
| 86 | case FWL_VKEY_Delete: |
| 87 | break; |
| 88 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | OnNotifySelChanged(TRUE, bExit, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | return TRUE; |
| 93 | } |
| 94 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 95 | FX_BOOL CPWL_CBListBox::OnCharWithExit(uint16_t nChar, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | FX_BOOL& bExit, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 97 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | if (!m_pList) |
| 99 | return FALSE; |
| 100 | |
| 101 | if (!m_pList->OnChar(nChar, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag))) |
| 102 | return FALSE; |
| 103 | |
| 104 | if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetParentWindow()) { |
| 105 | pComboBox->SetSelectText(); |
| 106 | } |
| 107 | |
| 108 | OnNotifySelChanged(TRUE, bExit, nFlag); |
| 109 | |
| 110 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 114 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 115 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 116 | CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | if (IsVisible() && !rectWnd.IsEmpty()) { |
| 119 | CFX_ByteTextBuf sButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 121 | CFX_FloatPoint ptCenter = GetCenterPoint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 123 | CFX_FloatPoint pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 124 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 125 | CFX_FloatPoint pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 126 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 127 | CFX_FloatPoint pt3(ptCenter.x, |
| 128 | ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | if (IsFloatBigger(rectWnd.right - rectWnd.left, |
| 131 | PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && |
| 132 | IsFloatBigger(rectWnd.top - rectWnd.bottom, |
| 133 | PWL_CBBUTTON_TRIANGLE_HALFLEN)) { |
| 134 | sButton << "0 g\n"; |
| 135 | sButton << pt1.x << " " << pt1.y << " m\n"; |
| 136 | sButton << pt2.x << " " << pt2.y << " l\n"; |
| 137 | sButton << pt3.x << " " << pt3.y << " l\n"; |
| 138 | sButton << pt1.x << " " << pt1.y << " l f\n"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 139 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | sAppStream << "q\n" << sButton << "Q\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 141 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 146 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 148 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 149 | CFX_FloatRect rectWnd = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | if (IsVisible() && !rectWnd.IsEmpty()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 152 | CFX_FloatPoint ptCenter = GetCenterPoint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 153 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 154 | CFX_FloatPoint pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 155 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 156 | CFX_FloatPoint pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 157 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 158 | CFX_FloatPoint pt3(ptCenter.x, |
| 159 | ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | if (IsFloatBigger(rectWnd.right - rectWnd.left, |
| 162 | PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && |
| 163 | IsFloatBigger(rectWnd.top - rectWnd.bottom, |
| 164 | PWL_CBBUTTON_TRIANGLE_HALFLEN)) { |
| 165 | CFX_PathData path; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | path.SetPointCount(4); |
| 168 | path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO); |
| 169 | path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO); |
| 170 | path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO); |
| 171 | path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 172 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 173 | pDevice->DrawPath(&path, pUser2Device, nullptr, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR, |
| 175 | GetTransparency()), |
| 176 | 0, FXFILL_ALTERNATE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 177 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 181 | FX_BOOL CPWL_CBButton::OnLButtonDown(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 182 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 184 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | SetCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 186 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | if (CPWL_Wnd* pParent = GetParentWindow()) { |
| 188 | pParent->OnNotify(this, PNM_LBUTTONDOWN, 0, |
| 189 | PWL_MAKEDWORD(point.x, point.y)); |
| 190 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 191 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 195 | FX_BOOL CPWL_CBButton::OnLButtonUp(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 196 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 198 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 199 | ReleaseCapture(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 200 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | CPWL_ComboBox::CPWL_ComboBox() |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 205 | : m_pEdit(nullptr), |
| 206 | m_pButton(nullptr), |
| 207 | m_pList(nullptr), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 208 | m_bPopup(FALSE), |
| 209 | m_nPopupWhere(0), |
| 210 | m_nSelectItem(-1), |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 211 | m_pFillerNotify(nullptr) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 212 | |
| 213 | CFX_ByteString CPWL_ComboBox::GetClassName() const { |
| 214 | return "CPWL_ComboBox"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) { |
| 218 | cp.dwFlags &= ~PWS_HSCROLL; |
| 219 | cp.dwFlags &= ~PWS_VSCROLL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | void CPWL_ComboBox::SetFocus() { |
| 223 | if (m_pEdit) |
| 224 | m_pEdit->SetFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | void CPWL_ComboBox::KillFocus() { |
| 228 | SetPopup(FALSE); |
| 229 | CPWL_Wnd::KillFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | CFX_WideString CPWL_ComboBox::GetText() const { |
| 233 | if (m_pEdit) { |
| 234 | return m_pEdit->GetText(); |
| 235 | } |
| 236 | return CFX_WideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | void CPWL_ComboBox::SetText(const FX_WCHAR* text) { |
| 240 | if (m_pEdit) |
| 241 | m_pEdit->SetText(text); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 244 | void CPWL_ComboBox::AddString(const FX_WCHAR* str) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | if (m_pList) |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 246 | m_pList->AddString(str); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | int32_t CPWL_ComboBox::GetSelect() const { |
| 250 | return m_nSelectItem; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { |
| 254 | if (m_pList) |
| 255 | m_pList->Select(nItemIndex); |
| 256 | |
| 257 | m_pEdit->SetText(m_pList->GetText().c_str()); |
| 258 | |
| 259 | m_nSelectItem = nItemIndex; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { |
| 263 | if (m_pEdit) { |
| 264 | m_pEdit->SetSel(nStartChar, nEndChar); |
| 265 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 269 | nStartChar = -1; |
| 270 | nEndChar = -1; |
| 271 | |
| 272 | if (m_pEdit) { |
| 273 | m_pEdit->GetSel(nStartChar, nEndChar); |
| 274 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | void CPWL_ComboBox::Clear() { |
| 278 | if (m_pEdit) { |
| 279 | m_pEdit->Clear(); |
| 280 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 284 | CreateEdit(cp); |
| 285 | CreateButton(cp); |
| 286 | CreateListBox(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { |
| 290 | if (!m_pEdit) { |
| 291 | m_pEdit = new CPWL_CBEdit; |
| 292 | m_pEdit->AttachFFLData(m_pFormFiller); |
| 293 | |
| 294 | PWL_CREATEPARAM ecp = cp; |
| 295 | ecp.pParentWnd = this; |
| 296 | ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | |
| 297 | PES_AUTOSCROLL | PES_UNDO; |
| 298 | |
| 299 | if (HasFlag(PWS_AUTOFONTSIZE)) |
| 300 | ecp.dwFlags |= PWS_AUTOFONTSIZE; |
| 301 | |
| 302 | if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 303 | ecp.dwFlags |= PWS_READONLY; |
| 304 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 305 | ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 306 | ecp.dwBorderWidth = 0; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 307 | ecp.nBorderStyle = BorderStyle::SOLID; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | |
| 309 | m_pEdit->Create(ecp); |
| 310 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { |
| 314 | if (!m_pButton) { |
| 315 | m_pButton = new CPWL_CBButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 316 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | PWL_CREATEPARAM bcp = cp; |
| 318 | bcp.pParentWnd = this; |
| 319 | bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; |
| 320 | bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR; |
| 321 | bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 322 | bcp.dwBorderWidth = 2; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 323 | bcp.nBorderStyle = BorderStyle::BEVELED; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 324 | bcp.eCursorType = FXCT_ARROW; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 325 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 326 | m_pButton->Create(bcp); |
| 327 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { |
| 331 | if (!m_pList) { |
| 332 | m_pList = new CPWL_CBListBox; |
| 333 | m_pList->AttachFFLData(m_pFormFiller); |
| 334 | PWL_CREATEPARAM lcp = cp; |
| 335 | lcp.pParentWnd = this; |
| 336 | lcp.dwFlags = |
| 337 | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 338 | lcp.nBorderStyle = BorderStyle::SOLID; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 339 | lcp.dwBorderWidth = 1; |
| 340 | lcp.eCursorType = FXCT_ARROW; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 341 | lcp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 342 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | if (cp.dwFlags & PWS_AUTOFONTSIZE) |
| 344 | lcp.fFontSize = PWLCB_DEFAULTFONTSIZE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 345 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | lcp.fFontSize = cp.fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 347 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) |
| 349 | lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 350 | |
| 351 | if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) |
| 352 | lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 353 | |
| 354 | m_pList->Create(lcp); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | void CPWL_ComboBox::RePosChildWnd() { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 359 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | |
| 361 | if (m_bPopup) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 362 | CFX_FloatRect rclient = GetClientRect(); |
| 363 | CFX_FloatRect rcButton = rclient; |
| 364 | CFX_FloatRect rcEdit = rcClient; |
| 365 | CFX_FloatRect rcList = CPWL_Wnd::GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | |
| 367 | FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height(); |
| 368 | FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; |
| 369 | |
| 370 | switch (m_nPopupWhere) { |
| 371 | case 0: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 372 | rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 373 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | if (rcButton.left < rclient.left) |
| 375 | rcButton.left = rclient.left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 376 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | rcButton.bottom = rcButton.top - fOldClientHeight; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 378 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 379 | rcEdit.right = rcButton.left - 1.0f; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 380 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 381 | if (rcEdit.left < rclient.left) |
| 382 | rcEdit.left = rclient.left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 383 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 384 | if (rcEdit.right < rcEdit.left) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | rcEdit.right = rcEdit.left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 386 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | rcEdit.bottom = rcEdit.top - fOldClientHeight; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 388 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | rcList.top -= fOldWindowHeight; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 390 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 391 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | case 1: |
| 393 | rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; |
| 394 | |
| 395 | if (rcButton.left < rclient.left) |
| 396 | rcButton.left = rclient.left; |
| 397 | |
| 398 | rcButton.top = rcButton.bottom + fOldClientHeight; |
| 399 | |
| 400 | rcEdit.right = rcButton.left - 1.0f; |
| 401 | |
| 402 | if (rcEdit.left < rclient.left) |
| 403 | rcEdit.left = rclient.left; |
| 404 | |
| 405 | if (rcEdit.right < rcEdit.left) |
| 406 | rcEdit.right = rcEdit.left; |
| 407 | |
| 408 | rcEdit.top = rcEdit.bottom + fOldClientHeight; |
| 409 | |
| 410 | rcList.bottom += fOldWindowHeight; |
| 411 | |
| 412 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 413 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 414 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | if (m_pButton) |
| 416 | m_pButton->Move(rcButton, TRUE, FALSE); |
| 417 | |
| 418 | if (m_pEdit) |
| 419 | m_pEdit->Move(rcEdit, TRUE, FALSE); |
| 420 | |
| 421 | if (m_pList) { |
| 422 | m_pList->SetVisible(TRUE); |
| 423 | m_pList->Move(rcList, TRUE, FALSE); |
| 424 | m_pList->ScrollToListItem(m_nSelectItem); |
| 425 | } |
| 426 | } else { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 427 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | |
| 429 | rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; |
| 430 | |
| 431 | if (rcButton.left < rcClient.left) |
| 432 | rcButton.left = rcClient.left; |
| 433 | |
| 434 | if (m_pButton) |
| 435 | m_pButton->Move(rcButton, TRUE, FALSE); |
| 436 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 437 | CFX_FloatRect rcEdit = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 438 | rcEdit.right = rcButton.left - 1.0f; |
| 439 | |
| 440 | if (rcEdit.left < rcClient.left) |
| 441 | rcEdit.left = rcClient.left; |
| 442 | |
| 443 | if (rcEdit.right < rcEdit.left) |
| 444 | rcEdit.right = rcEdit.left; |
| 445 | |
| 446 | if (m_pEdit) |
| 447 | m_pEdit->Move(rcEdit, TRUE, FALSE); |
| 448 | |
| 449 | if (m_pList) |
| 450 | m_pList->SetVisible(FALSE); |
| 451 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | void CPWL_ComboBox::SelectAll() { |
| 455 | if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 456 | m_pEdit->SelectAll(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 459 | CFX_FloatRect CPWL_ComboBox::GetFocusRect() const { |
| 460 | return CFX_FloatRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | void CPWL_ComboBox::SetPopup(FX_BOOL bPopup) { |
| 464 | if (!m_pList) |
| 465 | return; |
| 466 | if (bPopup == m_bPopup) |
| 467 | return; |
| 468 | FX_FLOAT fListHeight = m_pList->GetContentRect().Height(); |
| 469 | if (!IsFloatBigger(fListHeight, 0.0f)) |
| 470 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 471 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | if (bPopup) { |
| 473 | if (m_pFillerNotify) { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 474 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | FX_BOOL bExit = FALSE; |
| 476 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0); |
| 477 | if (bExit) |
| 478 | return; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 479 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 480 | int32_t nWhere = 0; |
| 481 | FX_FLOAT fPopupRet = 0.0f; |
| 482 | FX_FLOAT fPopupMin = 0.0f; |
| 483 | if (m_pList->GetCount() > 3) |
| 484 | fPopupMin = |
| 485 | m_pList->GetFirstHeight() * 3 + m_pList->GetBorderWidth() * 2; |
| 486 | FX_FLOAT fPopupMax = fListHeight + m_pList->GetBorderWidth() * 2; |
| 487 | m_pFillerNotify->QueryWherePopup(GetAttachedData(), fPopupMin, fPopupMax, |
| 488 | nWhere, fPopupRet); |
| 489 | |
| 490 | if (IsFloatBigger(fPopupRet, 0.0f)) { |
| 491 | m_bPopup = bPopup; |
| 492 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 493 | CFX_FloatRect rcWindow = CPWL_Wnd::GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 494 | m_rcOldWindow = rcWindow; |
| 495 | switch (nWhere) { |
| 496 | default: |
| 497 | case 0: |
| 498 | rcWindow.bottom -= fPopupRet; |
| 499 | break; |
| 500 | case 1: |
| 501 | rcWindow.top += fPopupRet; |
| 502 | break; |
| 503 | } |
| 504 | |
| 505 | m_nPopupWhere = nWhere; |
| 506 | Move(rcWindow, TRUE, TRUE); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 507 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | bExit = FALSE; |
| 509 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0); |
| 510 | if (bExit) |
| 511 | return; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 512 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | } else { |
| 516 | m_bPopup = bPopup; |
| 517 | Move(m_rcOldWindow, TRUE, TRUE); |
| 518 | } |
| 519 | } |
| 520 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 521 | FX_BOOL CPWL_ComboBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | if (!m_pList) |
| 523 | return FALSE; |
| 524 | if (!m_pEdit) |
| 525 | return FALSE; |
| 526 | |
| 527 | m_nSelectItem = -1; |
| 528 | |
| 529 | switch (nChar) { |
| 530 | case FWL_VKEY_Up: |
| 531 | if (m_pList->GetCurSel() > 0) { |
| 532 | FX_BOOL bExit = FALSE; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 533 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 534 | if (m_pFillerNotify) { |
| 535 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); |
| 536 | if (bExit) |
| 537 | return FALSE; |
| 538 | bExit = FALSE; |
| 539 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); |
| 540 | if (bExit) |
| 541 | return FALSE; |
| 542 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 543 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { |
| 545 | if (bExit) |
| 546 | return FALSE; |
| 547 | SetSelectText(); |
| 548 | } |
| 549 | } |
| 550 | return TRUE; |
| 551 | case FWL_VKEY_Down: |
| 552 | if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { |
| 553 | FX_BOOL bExit = FALSE; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 554 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 555 | if (m_pFillerNotify) { |
| 556 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); |
| 557 | if (bExit) |
| 558 | return FALSE; |
| 559 | bExit = FALSE; |
| 560 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); |
| 561 | if (bExit) |
| 562 | return FALSE; |
| 563 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 564 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { |
| 566 | if (bExit) |
| 567 | return FALSE; |
| 568 | SetSelectText(); |
| 569 | } |
| 570 | } |
| 571 | return TRUE; |
| 572 | } |
| 573 | |
| 574 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 575 | return m_pEdit->OnKeyDown(nChar, nFlag); |
| 576 | |
| 577 | return FALSE; |
| 578 | } |
| 579 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 580 | FX_BOOL CPWL_ComboBox::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 581 | if (!m_pList) |
| 582 | return FALSE; |
| 583 | |
| 584 | if (!m_pEdit) |
| 585 | return FALSE; |
| 586 | |
| 587 | m_nSelectItem = -1; |
| 588 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 589 | return m_pEdit->OnChar(nChar, nFlag); |
| 590 | |
| 591 | FX_BOOL bExit = FALSE; |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 592 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 593 | if (m_pFillerNotify) { |
| 594 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); |
| 595 | if (bExit) |
| 596 | return FALSE; |
| 597 | |
| 598 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); |
| 599 | if (bExit) |
| 600 | return FALSE; |
| 601 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 602 | #endif // PDF_ENABLE_XFA |
Tom Sepez | dfbf8e7 | 2015-10-14 14:17:26 -0700 | [diff] [blame] | 603 | return m_pList->OnCharWithExit(nChar, bExit, nFlag) ? bExit : FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 607 | uint32_t msg, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 608 | intptr_t wParam, |
| 609 | intptr_t lParam) { |
| 610 | switch (msg) { |
| 611 | case PNM_LBUTTONDOWN: |
| 612 | if (pWnd == m_pButton) { |
| 613 | SetPopup(!m_bPopup); |
| 614 | return; |
| 615 | } |
| 616 | break; |
| 617 | case PNM_LBUTTONUP: |
| 618 | if (m_pEdit && m_pList) { |
| 619 | if (pWnd == m_pList) { |
| 620 | SetSelectText(); |
| 621 | SelectAll(); |
| 622 | m_pEdit->SetFocus(); |
| 623 | SetPopup(FALSE); |
| 624 | return; |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); |
| 630 | } |
| 631 | |
| 632 | FX_BOOL CPWL_ComboBox::IsPopup() const { |
| 633 | return m_bPopup; |
| 634 | } |
| 635 | |
| 636 | void CPWL_ComboBox::SetSelectText() { |
| 637 | CFX_WideString swText = m_pList->GetText(); |
| 638 | m_pEdit->SelectAll(); |
| 639 | m_pEdit->ReplaceSel(m_pList->GetText().c_str()); |
| 640 | m_pEdit->SelectAll(); |
| 641 | |
| 642 | m_nSelectItem = m_pList->GetCurSel(); |
| 643 | } |
| 644 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { |
| 646 | m_pFillerNotify = pNotify; |
| 647 | |
| 648 | if (m_pEdit) |
| 649 | m_pEdit->SetFillerNotify(pNotify); |
| 650 | |
| 651 | if (m_pList) |
| 652 | m_pList->SetFillerNotify(pNotify); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 653 | } |