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