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