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