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 | |
| 7 | #include "../../include/pdfwindow/PDFWindow.h" |
| 8 | #include "../../include/pdfwindow/PWL_Wnd.h" |
| 9 | #include "../../include/pdfwindow/PWL_EditCtrl.h" |
| 10 | #include "../../include/pdfwindow/PWL_Edit.h" |
| 11 | #include "../../include/pdfwindow/PWL_ListBox.h" |
| 12 | #include "../../include/pdfwindow/PWL_ComboBox.h" |
| 13 | #include "../../include/pdfwindow/PWL_Utils.h" |
| 14 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 15 | #define PWLCB_DEFAULTFONTSIZE 12.0f |
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 IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
| 18 | #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
| 19 | #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
| 20 | #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | |
| 22 | /* ---------------------------- CPWL_CBListBox ---------------------------- */ |
| 23 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | FX_BOOL CPWL_CBListBox::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) { |
| 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 | |
| 111 | /* ---------------------------- CPWL_CBButton ---------------------------- */ |
| 112 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | void CPWL_CBButton::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 114 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | if (IsVisible() && !rectWnd.IsEmpty()) { |
| 119 | CFX_ByteTextBuf sButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | CPDF_Point ptCenter = GetCenterPoint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 122 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 124 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 125 | CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 126 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 127 | CPDF_Point pt3(ptCenter.x, |
| 128 | ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 129 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | if (IsFloatBigger(rectWnd.right - rectWnd.left, |
| 131 | PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && |
| 132 | IsFloatBigger(rectWnd.top - rectWnd.bottom, |
| 133 | PWL_CBBUTTON_TRIANGLE_HALFLEN)) { |
| 134 | sButton << "0 g\n"; |
| 135 | sButton << pt1.x << " " << pt1.y << " m\n"; |
| 136 | sButton << pt2.x << " " << pt2.y << " l\n"; |
| 137 | sButton << pt3.x << " " << pt3.y << " l\n"; |
| 138 | sButton << pt1.x << " " << pt1.y << " l f\n"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 139 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | sAppStream << "q\n" << sButton << "Q\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 141 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | void CPWL_CBButton::DrawThisAppearance(CFX_RenderDevice* pDevice, |
| 146 | CPDF_Matrix* pUser2Device) { |
| 147 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 148 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 149 | CPDF_Rect rectWnd = CPWL_Wnd::GetWindowRect(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | if (IsVisible() && !rectWnd.IsEmpty()) { |
| 152 | CPDF_Point ptCenter = GetCenterPoint(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 153 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 154 | CPDF_Point pt1(ptCenter.x - PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 155 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 156 | CPDF_Point pt2(ptCenter.x + PWL_CBBUTTON_TRIANGLE_HALFLEN, |
| 157 | ptCenter.y + PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
| 158 | CPDF_Point pt3(ptCenter.x, |
| 159 | ptCenter.y - PWL_CBBUTTON_TRIANGLE_HALFLEN * 0.5f); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | if (IsFloatBigger(rectWnd.right - rectWnd.left, |
| 162 | PWL_CBBUTTON_TRIANGLE_HALFLEN * 2) && |
| 163 | IsFloatBigger(rectWnd.top - rectWnd.bottom, |
| 164 | PWL_CBBUTTON_TRIANGLE_HALFLEN)) { |
| 165 | CFX_PathData path; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 166 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | path.SetPointCount(4); |
| 168 | path.SetPoint(0, pt1.x, pt1.y, FXPT_MOVETO); |
| 169 | path.SetPoint(1, pt2.x, pt2.y, FXPT_LINETO); |
| 170 | path.SetPoint(2, pt3.x, pt3.y, FXPT_LINETO); |
| 171 | path.SetPoint(3, pt1.x, pt1.y, FXPT_LINETO); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 172 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | pDevice->DrawPath(&path, pUser2Device, NULL, |
| 174 | CPWL_Utils::PWLColorToFXColor(PWL_DEFAULT_BLACKCOLOR, |
| 175 | GetTransparency()), |
| 176 | 0, FXFILL_ALTERNATE); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 177 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 181 | FX_BOOL CPWL_CBButton::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) { |
| 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 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | FX_BOOL CPWL_CBButton::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) { |
| 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 | |
| 202 | /* ---------------------------- CPWL_ComboBox ---------------------------- */ |
| 203 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | CPWL_ComboBox::CPWL_ComboBox() |
| 205 | : m_pEdit(NULL), |
| 206 | m_pButton(NULL), |
| 207 | m_pList(NULL), |
| 208 | m_bPopup(FALSE), |
| 209 | m_nPopupWhere(0), |
| 210 | m_nSelectItem(-1), |
| 211 | m_pFillerNotify(NULL) {} |
| 212 | |
| 213 | CFX_ByteString CPWL_ComboBox::GetClassName() const { |
| 214 | return "CPWL_ComboBox"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | void CPWL_ComboBox::OnCreate(PWL_CREATEPARAM& cp) { |
| 218 | cp.dwFlags &= ~PWS_HSCROLL; |
| 219 | cp.dwFlags &= ~PWS_VSCROLL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 222 | void CPWL_ComboBox::SetFocus() { |
| 223 | if (m_pEdit) |
| 224 | m_pEdit->SetFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | void CPWL_ComboBox::KillFocus() { |
| 228 | SetPopup(FALSE); |
| 229 | CPWL_Wnd::KillFocus(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | CFX_WideString CPWL_ComboBox::GetText() const { |
| 233 | if (m_pEdit) { |
| 234 | return m_pEdit->GetText(); |
| 235 | } |
| 236 | return CFX_WideString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 239 | void CPWL_ComboBox::SetText(const FX_WCHAR* text) { |
| 240 | if (m_pEdit) |
| 241 | m_pEdit->SetText(text); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | void CPWL_ComboBox::AddString(const FX_WCHAR* string) { |
| 245 | if (m_pList) |
| 246 | m_pList->AddString(string); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | int32_t CPWL_ComboBox::GetSelect() const { |
| 250 | return m_nSelectItem; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | void CPWL_ComboBox::SetSelect(int32_t nItemIndex) { |
| 254 | if (m_pList) |
| 255 | m_pList->Select(nItemIndex); |
| 256 | |
| 257 | m_pEdit->SetText(m_pList->GetText().c_str()); |
| 258 | |
| 259 | m_nSelectItem = nItemIndex; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | void CPWL_ComboBox::SetEditSel(int32_t nStartChar, int32_t nEndChar) { |
| 263 | if (m_pEdit) { |
| 264 | m_pEdit->SetSel(nStartChar, nEndChar); |
| 265 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 268 | void CPWL_ComboBox::GetEditSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 269 | nStartChar = -1; |
| 270 | nEndChar = -1; |
| 271 | |
| 272 | if (m_pEdit) { |
| 273 | m_pEdit->GetSel(nStartChar, nEndChar); |
| 274 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | void CPWL_ComboBox::Clear() { |
| 278 | if (m_pEdit) { |
| 279 | m_pEdit->Clear(); |
| 280 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | void CPWL_ComboBox::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 284 | CreateEdit(cp); |
| 285 | CreateButton(cp); |
| 286 | CreateListBox(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 289 | void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) { |
| 290 | if (!m_pEdit) { |
| 291 | m_pEdit = new CPWL_CBEdit; |
| 292 | m_pEdit->AttachFFLData(m_pFormFiller); |
| 293 | |
| 294 | PWL_CREATEPARAM ecp = cp; |
| 295 | ecp.pParentWnd = this; |
| 296 | ecp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PES_CENTER | |
| 297 | PES_AUTOSCROLL | PES_UNDO; |
| 298 | |
| 299 | if (HasFlag(PWS_AUTOFONTSIZE)) |
| 300 | ecp.dwFlags |= PWS_AUTOFONTSIZE; |
| 301 | |
| 302 | if (!HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 303 | ecp.dwFlags |= PWS_READONLY; |
| 304 | |
| 305 | ecp.rcRectWnd = CPDF_Rect(0, 0, 0, 0); |
| 306 | ecp.dwBorderWidth = 0; |
| 307 | ecp.nBorderStyle = PBS_SOLID; |
| 308 | |
| 309 | m_pEdit->Create(ecp); |
| 310 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | void CPWL_ComboBox::CreateButton(const PWL_CREATEPARAM& cp) { |
| 314 | if (!m_pButton) { |
| 315 | m_pButton = new CPWL_CBButton; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 316 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 317 | PWL_CREATEPARAM bcp = cp; |
| 318 | bcp.pParentWnd = this; |
| 319 | bcp.dwFlags = PWS_VISIBLE | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND; |
| 320 | bcp.sBackgroundColor = PWL_SCROLLBAR_BKCOLOR; |
| 321 | bcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 322 | bcp.dwBorderWidth = 2; |
| 323 | bcp.nBorderStyle = PBS_BEVELED; |
| 324 | bcp.eCursorType = FXCT_ARROW; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 325 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 326 | m_pButton->Create(bcp); |
| 327 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) { |
| 331 | if (!m_pList) { |
| 332 | m_pList = new CPWL_CBListBox; |
| 333 | m_pList->AttachFFLData(m_pFormFiller); |
| 334 | PWL_CREATEPARAM lcp = cp; |
| 335 | lcp.pParentWnd = this; |
| 336 | lcp.dwFlags = |
| 337 | PWS_CHILD | PWS_BORDER | PWS_BACKGROUND | PLBS_HOVERSEL | PWS_VSCROLL; |
| 338 | lcp.nBorderStyle = PBS_SOLID; |
| 339 | lcp.dwBorderWidth = 1; |
| 340 | lcp.eCursorType = FXCT_ARROW; |
| 341 | lcp.rcRectWnd = CPDF_Rect(0, 0, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 342 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | if (cp.dwFlags & PWS_AUTOFONTSIZE) |
| 344 | lcp.fFontSize = PWLCB_DEFAULTFONTSIZE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 345 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | lcp.fFontSize = cp.fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 347 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | if (cp.sBorderColor.nColorType == COLORTYPE_TRANSPARENT) |
| 349 | lcp.sBorderColor = PWL_DEFAULT_BLACKCOLOR; |
| 350 | |
| 351 | if (cp.sBackgroundColor.nColorType == COLORTYPE_TRANSPARENT) |
| 352 | lcp.sBackgroundColor = PWL_DEFAULT_WHITECOLOR; |
| 353 | |
| 354 | m_pList->Create(lcp); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | void CPWL_ComboBox::RePosChildWnd() { |
| 359 | CPDF_Rect rcClient = GetClientRect(); |
| 360 | |
| 361 | if (m_bPopup) { |
| 362 | CPDF_Rect rclient = GetClientRect(); |
| 363 | CPDF_Rect rcButton = rclient; |
| 364 | CPDF_Rect rcEdit = rcClient; |
| 365 | CPDF_Rect rcList = CPWL_Wnd::GetWindowRect(); |
| 366 | |
| 367 | FX_FLOAT fOldWindowHeight = m_rcOldWindow.Height(); |
| 368 | FX_FLOAT fOldClientHeight = fOldWindowHeight - GetBorderWidth() * 2; |
| 369 | |
| 370 | switch (m_nPopupWhere) { |
| 371 | case 0: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 372 | rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 373 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | if (rcButton.left < rclient.left) |
| 375 | rcButton.left = rclient.left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 376 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 377 | rcButton.bottom = rcButton.top - fOldClientHeight; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 378 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 379 | rcEdit.right = rcButton.left - 1.0f; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 380 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 381 | if (rcEdit.left < rclient.left) |
| 382 | rcEdit.left = rclient.left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 383 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 384 | if (rcEdit.right < rcEdit.left) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | rcEdit.right = rcEdit.left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 386 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 387 | rcEdit.bottom = rcEdit.top - fOldClientHeight; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 388 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | rcList.top -= fOldWindowHeight; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 390 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 391 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 392 | case 1: |
| 393 | rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; |
| 394 | |
| 395 | if (rcButton.left < rclient.left) |
| 396 | rcButton.left = rclient.left; |
| 397 | |
| 398 | rcButton.top = rcButton.bottom + fOldClientHeight; |
| 399 | |
| 400 | rcEdit.right = rcButton.left - 1.0f; |
| 401 | |
| 402 | if (rcEdit.left < rclient.left) |
| 403 | rcEdit.left = rclient.left; |
| 404 | |
| 405 | if (rcEdit.right < rcEdit.left) |
| 406 | rcEdit.right = rcEdit.left; |
| 407 | |
| 408 | rcEdit.top = rcEdit.bottom + fOldClientHeight; |
| 409 | |
| 410 | rcList.bottom += fOldWindowHeight; |
| 411 | |
| 412 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 413 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 414 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | if (m_pButton) |
| 416 | m_pButton->Move(rcButton, TRUE, FALSE); |
| 417 | |
| 418 | if (m_pEdit) |
| 419 | m_pEdit->Move(rcEdit, TRUE, FALSE); |
| 420 | |
| 421 | if (m_pList) { |
| 422 | m_pList->SetVisible(TRUE); |
| 423 | m_pList->Move(rcList, TRUE, FALSE); |
| 424 | m_pList->ScrollToListItem(m_nSelectItem); |
| 425 | } |
| 426 | } else { |
| 427 | CPDF_Rect rcButton = rcClient; |
| 428 | |
| 429 | rcButton.left = rcButton.right - PWL_COMBOBOX_BUTTON_WIDTH; |
| 430 | |
| 431 | if (rcButton.left < rcClient.left) |
| 432 | rcButton.left = rcClient.left; |
| 433 | |
| 434 | if (m_pButton) |
| 435 | m_pButton->Move(rcButton, TRUE, FALSE); |
| 436 | |
| 437 | CPDF_Rect rcEdit = rcClient; |
| 438 | rcEdit.right = rcButton.left - 1.0f; |
| 439 | |
| 440 | if (rcEdit.left < rcClient.left) |
| 441 | rcEdit.left = rcClient.left; |
| 442 | |
| 443 | if (rcEdit.right < rcEdit.left) |
| 444 | rcEdit.right = rcEdit.left; |
| 445 | |
| 446 | if (m_pEdit) |
| 447 | m_pEdit->Move(rcEdit, TRUE, FALSE); |
| 448 | |
| 449 | if (m_pList) |
| 450 | m_pList->SetVisible(FALSE); |
| 451 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 454 | void CPWL_ComboBox::SelectAll() { |
| 455 | if (m_pEdit && HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 456 | m_pEdit->SelectAll(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | CPDF_Rect CPWL_ComboBox::GetFocusRect() const { |
| 460 | return CPDF_Rect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | void CPWL_ComboBox::SetPopup(FX_BOOL bPopup) { |
| 464 | if (!m_pList) |
| 465 | return; |
| 466 | if (bPopup == m_bPopup) |
| 467 | return; |
| 468 | FX_FLOAT fListHeight = m_pList->GetContentRect().Height(); |
| 469 | if (!IsFloatBigger(fListHeight, 0.0f)) |
| 470 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 471 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | if (bPopup) { |
| 473 | if (m_pFillerNotify) { |
| 474 | FX_BOOL bExit = FALSE; |
| 475 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0); |
| 476 | if (bExit) |
| 477 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 478 | |
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 | |
| 492 | CPDF_Rect rcWindow = CPWL_Wnd::GetWindowRect(); |
| 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); |
| 506 | |
| 507 | bExit = FALSE; |
| 508 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0); |
| 509 | if (bExit) |
| 510 | return; |
| 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; |
| 531 | |
| 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 | } |
| 541 | if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { |
| 542 | if (bExit) |
| 543 | return FALSE; |
| 544 | SetSelectText(); |
| 545 | } |
| 546 | } |
| 547 | return TRUE; |
| 548 | case FWL_VKEY_Down: |
| 549 | if (m_pList->GetCurSel() < m_pList->GetCount() - 1) { |
| 550 | FX_BOOL bExit = FALSE; |
| 551 | |
| 552 | if (m_pFillerNotify) { |
| 553 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); |
| 554 | if (bExit) |
| 555 | return FALSE; |
| 556 | bExit = FALSE; |
| 557 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); |
| 558 | if (bExit) |
| 559 | return FALSE; |
| 560 | } |
| 561 | if (m_pList->OnKeyDownWithExit(nChar, bExit, nFlag)) { |
| 562 | if (bExit) |
| 563 | return FALSE; |
| 564 | SetSelectText(); |
| 565 | } |
| 566 | } |
| 567 | return TRUE; |
| 568 | } |
| 569 | |
| 570 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 571 | return m_pEdit->OnKeyDown(nChar, nFlag); |
| 572 | |
| 573 | return FALSE; |
| 574 | } |
| 575 | |
| 576 | FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag) { |
| 577 | if (!m_pList) |
| 578 | return FALSE; |
| 579 | |
| 580 | if (!m_pEdit) |
| 581 | return FALSE; |
| 582 | |
| 583 | m_nSelectItem = -1; |
| 584 | if (HasFlag(PCBS_ALLOWCUSTOMTEXT)) |
| 585 | return m_pEdit->OnChar(nChar, nFlag); |
| 586 | |
| 587 | FX_BOOL bExit = FALSE; |
| 588 | if (m_pFillerNotify) { |
| 589 | m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag); |
| 590 | if (bExit) |
| 591 | return FALSE; |
| 592 | |
| 593 | m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag); |
| 594 | if (bExit) |
| 595 | return FALSE; |
| 596 | } |
| 597 | if (m_pList->OnCharWithExit(nChar, bExit, nFlag)) |
| 598 | return bExit; |
| 599 | |
| 600 | return FALSE; |
| 601 | } |
| 602 | |
| 603 | void CPWL_ComboBox::OnNotify(CPWL_Wnd* pWnd, |
| 604 | FX_DWORD msg, |
| 605 | intptr_t wParam, |
| 606 | intptr_t lParam) { |
| 607 | switch (msg) { |
| 608 | case PNM_LBUTTONDOWN: |
| 609 | if (pWnd == m_pButton) { |
| 610 | SetPopup(!m_bPopup); |
| 611 | return; |
| 612 | } |
| 613 | break; |
| 614 | case PNM_LBUTTONUP: |
| 615 | if (m_pEdit && m_pList) { |
| 616 | if (pWnd == m_pList) { |
| 617 | SetSelectText(); |
| 618 | SelectAll(); |
| 619 | m_pEdit->SetFocus(); |
| 620 | SetPopup(FALSE); |
| 621 | return; |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); |
| 627 | } |
| 628 | |
| 629 | FX_BOOL CPWL_ComboBox::IsPopup() const { |
| 630 | return m_bPopup; |
| 631 | } |
| 632 | |
| 633 | void CPWL_ComboBox::SetSelectText() { |
| 634 | CFX_WideString swText = m_pList->GetText(); |
| 635 | m_pEdit->SelectAll(); |
| 636 | m_pEdit->ReplaceSel(m_pList->GetText().c_str()); |
| 637 | m_pEdit->SelectAll(); |
| 638 | |
| 639 | m_nSelectItem = m_pList->GetCurSel(); |
| 640 | } |
| 641 | |
| 642 | FX_BOOL CPWL_ComboBox::IsModified() const { |
| 643 | return m_pEdit->IsModified(); |
| 644 | } |
| 645 | |
| 646 | void CPWL_ComboBox::SetFillerNotify(IPWL_Filler_Notify* pNotify) { |
| 647 | m_pFillerNotify = pNotify; |
| 648 | |
| 649 | if (m_pEdit) |
| 650 | m_pEdit->SetFillerNotify(pNotify); |
| 651 | |
| 652 | if (m_pList) |
| 653 | m_pList->SetFillerNotify(pNotify); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 654 | } |