Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [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. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 7 | #include "xfa/fwl/cfwl_combobox.h" |
Dan Sinclair | e73c5ce | 2016-02-25 13:38:37 -0500 | [diff] [blame] | 8 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 9 | #include <algorithm> |
| 10 | #include <memory> |
Tom Sepez | e059b5b | 2016-02-05 11:49:27 -0800 | [diff] [blame] | 11 | #include <utility> |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 12 | |
dsinclair | 6fe8795 | 2016-11-01 18:48:19 -0700 | [diff] [blame] | 13 | #include "third_party/base/ptr_util.h" |
Dan Sinclair | bccf573 | 2017-03-30 14:10:32 -0400 | [diff] [blame] | 14 | #include "xfa/fde/cfde_textout.h" |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 15 | #include "xfa/fde/cfde_txtedtengine.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 16 | #include "xfa/fwl/cfwl_app.h" |
| 17 | #include "xfa/fwl/cfwl_event.h" |
| 18 | #include "xfa/fwl/cfwl_eventselectchanged.h" |
| 19 | #include "xfa/fwl/cfwl_eventtextchanged.h" |
| 20 | #include "xfa/fwl/cfwl_formproxy.h" |
| 21 | #include "xfa/fwl/cfwl_listbox.h" |
| 22 | #include "xfa/fwl/cfwl_messagekey.h" |
| 23 | #include "xfa/fwl/cfwl_messagekillfocus.h" |
| 24 | #include "xfa/fwl/cfwl_messagemouse.h" |
| 25 | #include "xfa/fwl/cfwl_messagesetfocus.h" |
| 26 | #include "xfa/fwl/cfwl_notedriver.h" |
| 27 | #include "xfa/fwl/cfwl_themebackground.h" |
| 28 | #include "xfa/fwl/cfwl_themepart.h" |
| 29 | #include "xfa/fwl/cfwl_themetext.h" |
| 30 | #include "xfa/fwl/cfwl_widgetmgr.h" |
| 31 | #include "xfa/fwl/ifwl_themeprovider.h" |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 32 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 33 | CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app) |
| 34 | : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr), |
| 35 | m_pComboBoxProxy(nullptr), |
| 36 | m_bLButtonDown(false), |
| 37 | m_iCurSel(-1), |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 38 | m_iBtnState(CFWL_PartState_Normal) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 39 | m_rtClient.Reset(); |
| 40 | m_rtBtn.Reset(); |
| 41 | m_rtHandler.Reset(); |
dsinclair | 42cb645 | 2016-10-31 12:50:04 -0700 | [diff] [blame] | 42 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 43 | if (m_pWidgetMgr->IsFormDisabled()) { |
| 44 | DisForm_InitComboList(); |
| 45 | DisForm_InitComboEdit(); |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
| 50 | prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
| 51 | prop->m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 52 | m_pListBox = pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp.Get(), |
| 53 | std::move(prop), this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 54 | |
| 55 | if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { |
tsepez | a9caab9 | 2016-12-14 05:57:10 -0800 | [diff] [blame] | 56 | m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 57 | m_pOwnerApp.Get(), pdfium::MakeUnique<CFWL_WidgetProperties>(), this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 58 | m_pEdit->SetOuter(this); |
| 59 | } |
| 60 | if (m_pEdit) |
| 61 | m_pEdit->SetParent(this); |
| 62 | |
| 63 | SetStates(m_pProperties->m_dwStates); |
dsinclair | 42cb645 | 2016-10-31 12:50:04 -0700 | [diff] [blame] | 64 | } |
| 65 | |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 66 | CFWL_ComboBox::~CFWL_ComboBox() {} |
| 67 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 68 | FWL_Type CFWL_ComboBox::GetClassID() const { |
| 69 | return FWL_Type::ComboBox; |
| 70 | } |
dsinclair | 2085538 | 2016-10-31 07:29:34 -0700 | [diff] [blame] | 71 | |
Dan Sinclair | 0ced827 | 2016-11-23 12:20:47 -0500 | [diff] [blame] | 72 | void CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 73 | m_pListBox->AddString(wsText); |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 74 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 75 | |
dsinclair | 603f57b | 2016-12-14 06:25:02 -0800 | [diff] [blame] | 76 | void CFWL_ComboBox::RemoveAt(int32_t iIndex) { |
| 77 | m_pListBox->RemoveAt(iIndex); |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 78 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 79 | |
Tom Sepez | e059b5b | 2016-02-05 11:49:27 -0800 | [diff] [blame] | 80 | void CFWL_ComboBox::RemoveAll() { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 81 | m_pListBox->DeleteAll(); |
| 82 | } |
| 83 | |
| 84 | void CFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, |
| 85 | uint32_t dwStylesExRemoved) { |
| 86 | if (m_pWidgetMgr->IsFormDisabled()) { |
| 87 | DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
| 92 | bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); |
| 93 | if (bAddDropDown && !m_pEdit) { |
| 94 | m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 95 | m_pOwnerApp.Get(), pdfium::MakeUnique<CFWL_WidgetProperties>(), |
| 96 | nullptr); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 97 | m_pEdit->SetOuter(this); |
| 98 | m_pEdit->SetParent(this); |
| 99 | } else if (bRemoveDropDown && m_pEdit) { |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 100 | m_pEdit->SetStates(FWL_WGTSTATE_Invisible); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 101 | } |
| 102 | CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 103 | } |
| 104 | |
| 105 | void CFWL_ComboBox::Update() { |
| 106 | if (m_pWidgetMgr->IsFormDisabled()) { |
| 107 | DisForm_Update(); |
| 108 | return; |
| 109 | } |
| 110 | if (IsLocked()) |
| 111 | return; |
| 112 | |
| 113 | ResetTheme(); |
| 114 | if (IsDropDownStyle() && m_pEdit) |
| 115 | ResetEditAlignment(); |
| 116 | if (!m_pProperties->m_pThemeProvider) |
| 117 | m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 118 | |
| 119 | Layout(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 122 | FWL_WidgetHit CFWL_ComboBox::HitTest(const CFX_PointF& point) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 123 | if (m_pWidgetMgr->IsFormDisabled()) |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 124 | return DisForm_HitTest(point); |
| 125 | return CFWL_Widget::HitTest(point); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void CFWL_ComboBox::DrawWidget(CFX_Graphics* pGraphics, |
| 129 | const CFX_Matrix* pMatrix) { |
| 130 | if (m_pWidgetMgr->IsFormDisabled()) { |
| 131 | DisForm_DrawWidget(pGraphics, pMatrix); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | if (!pGraphics) |
| 136 | return; |
| 137 | if (!m_pProperties->m_pThemeProvider) |
| 138 | return; |
| 139 | |
| 140 | IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 141 | if (HasBorder()) |
| 142 | DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 143 | |
| 144 | if (!IsDropDownStyle()) { |
| 145 | CFX_RectF rtTextBk(m_rtClient); |
| 146 | rtTextBk.width -= m_rtBtn.width; |
| 147 | |
| 148 | CFWL_ThemeBackground param; |
| 149 | param.m_pWidget = this; |
| 150 | param.m_iPart = CFWL_Part::Background; |
| 151 | param.m_pGraphics = pGraphics; |
| 152 | if (pMatrix) |
| 153 | param.m_matrix.Concat(*pMatrix); |
| 154 | param.m_rtPart = rtTextBk; |
| 155 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 156 | if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { |
| 157 | param.m_dwStates = CFWL_PartState_Disabled; |
| 158 | } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && |
| 159 | (m_iCurSel >= 0)) { |
| 160 | param.m_dwStates = CFWL_PartState_Selected; |
| 161 | } else { |
| 162 | param.m_dwStates = CFWL_PartState_Normal; |
| 163 | } |
| 164 | pTheme->DrawBackground(¶m); |
| 165 | |
| 166 | if (m_iCurSel >= 0) { |
| 167 | if (!m_pListBox) |
| 168 | return; |
| 169 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 170 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 171 | |
| 172 | CFWL_ThemeText theme_text; |
| 173 | theme_text.m_pWidget = this; |
| 174 | theme_text.m_iPart = CFWL_Part::Caption; |
| 175 | theme_text.m_dwStates = m_iBtnState; |
| 176 | theme_text.m_pGraphics = pGraphics; |
| 177 | theme_text.m_matrix.Concat(*pMatrix); |
| 178 | theme_text.m_rtPart = rtTextBk; |
| 179 | theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
| 180 | ? CFWL_PartState_Selected |
| 181 | : CFWL_PartState_Normal; |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 182 | theme_text.m_wsText = hItem ? hItem->GetText() : L""; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 183 | theme_text.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; |
| 184 | theme_text.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; |
| 185 | pTheme->DrawText(&theme_text); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | CFWL_ThemeBackground param; |
| 190 | param.m_pWidget = this; |
| 191 | param.m_iPart = CFWL_Part::DropDownButton; |
| 192 | param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 193 | ? CFWL_PartState_Disabled |
| 194 | : m_iBtnState; |
| 195 | param.m_pGraphics = pGraphics; |
| 196 | param.m_matrix.Concat(*pMatrix); |
| 197 | param.m_rtPart = m_rtBtn; |
| 198 | pTheme->DrawBackground(¶m); |
| 199 | } |
| 200 | |
| 201 | void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { |
| 202 | if (!pThemeProvider) |
| 203 | return; |
| 204 | |
| 205 | m_pProperties->m_pThemeProvider = pThemeProvider; |
| 206 | if (m_pListBox) |
| 207 | m_pListBox->SetThemeProvider(pThemeProvider); |
| 208 | if (m_pEdit) |
| 209 | m_pEdit->SetThemeProvider(pThemeProvider); |
Dan Sinclair | 0ced827 | 2016-11-23 12:20:47 -0500 | [diff] [blame] | 210 | } |
| 211 | |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 212 | CFX_WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 213 | CFWL_ListItem* pItem = static_cast<CFWL_ListItem*>( |
| 214 | m_pListBox->GetItem(m_pListBox.get(), iIndex)); |
dsinclair | 603f57b | 2016-12-14 06:25:02 -0800 | [diff] [blame] | 215 | return pItem ? pItem->GetText() : L""; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 216 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 217 | |
dsinclair | 27e6675 | 2016-11-11 18:09:57 -0800 | [diff] [blame] | 218 | void CFWL_ComboBox::SetCurSel(int32_t iSel) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 219 | int32_t iCount = m_pListBox->CountItems(nullptr); |
| 220 | bool bClearSel = iSel < 0 || iSel >= iCount; |
| 221 | if (IsDropDownStyle() && m_pEdit) { |
| 222 | if (bClearSel) { |
| 223 | m_pEdit->SetText(CFX_WideString()); |
| 224 | } else { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 225 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 226 | m_pEdit->SetText(hItem ? hItem->GetText() : L""); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 227 | } |
| 228 | m_pEdit->Update(); |
| 229 | } |
| 230 | m_iCurSel = bClearSel ? -1 : iSel; |
| 231 | } |
| 232 | |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 233 | void CFWL_ComboBox::SetStates(uint32_t dwStates) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 234 | if (IsDropDownStyle() && m_pEdit) |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 235 | m_pEdit->SetStates(dwStates); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 236 | if (m_pListBox) |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 237 | m_pListBox->SetStates(dwStates); |
| 238 | CFWL_Widget::SetStates(dwStates); |
| 239 | } |
| 240 | |
| 241 | void CFWL_ComboBox::RemoveStates(uint32_t dwStates) { |
| 242 | if (IsDropDownStyle() && m_pEdit) |
| 243 | m_pEdit->RemoveStates(dwStates); |
| 244 | if (m_pListBox) |
| 245 | m_pListBox->RemoveStates(dwStates); |
| 246 | CFWL_Widget::RemoveStates(dwStates); |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 247 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 248 | |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 249 | void CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 250 | if (!m_pEdit) |
| 251 | return; |
| 252 | |
| 253 | m_pEdit->SetText(wsText); |
| 254 | m_pEdit->Update(); |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 255 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 256 | |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 257 | CFX_WideString CFWL_ComboBox::GetEditText() const { |
| 258 | if (m_pEdit) |
| 259 | return m_pEdit->GetText(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 260 | if (!m_pListBox) |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 261 | return L""; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 262 | |
| 263 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 264 | return hItem ? hItem->GetText() : L""; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 265 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 266 | |
dsinclair | 27e6675 | 2016-11-11 18:09:57 -0800 | [diff] [blame] | 267 | void CFWL_ComboBox::OpenDropDownList(bool bActivate) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 268 | ShowDropList(bActivate); |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 269 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 270 | |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 271 | CFX_RectF CFWL_ComboBox::GetBBox() const { |
| 272 | if (m_pWidgetMgr->IsFormDisabled()) |
| 273 | return DisForm_GetBBox(); |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 274 | |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 275 | CFX_RectF rect = m_pProperties->m_rtWidget; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 276 | if (!m_pListBox || !IsDropListVisible()) |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 277 | return rect; |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 278 | |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 279 | CFX_RectF rtList = m_pListBox->GetWidgetRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 280 | rtList.Offset(rect.left, rect.top); |
| 281 | rect.Union(rtList); |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 282 | return rect; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 283 | } |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 284 | |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 285 | void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, |
| 286 | uint32_t dwStylesExRemoved) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 287 | if (m_pEdit) |
| 288 | m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 289 | } |
| 290 | |
| 291 | void CFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, |
| 292 | const CFX_Matrix* pMatrix) { |
| 293 | CFWL_ThemeBackground param; |
| 294 | param.m_pGraphics = pGraphics; |
| 295 | param.m_iPart = CFWL_Part::StretchHandler; |
| 296 | param.m_dwStates = CFWL_PartState_Normal; |
| 297 | param.m_pWidget = this; |
| 298 | if (pMatrix) |
| 299 | param.m_matrix.Concat(*pMatrix); |
| 300 | param.m_rtPart = m_rtHandler; |
| 301 | m_pProperties->m_pThemeProvider->DrawBackground(¶m); |
| 302 | } |
| 303 | |
| 304 | void CFWL_ComboBox::ShowDropList(bool bActivate) { |
| 305 | if (m_pWidgetMgr->IsFormDisabled()) |
| 306 | return DisForm_ShowDropList(bActivate); |
| 307 | if (IsDropListVisible() == bActivate) |
| 308 | return; |
| 309 | if (!m_pComboBoxProxy) |
| 310 | InitProxyForm(); |
| 311 | |
| 312 | m_pComboBoxProxy->Reset(); |
| 313 | if (!bActivate) { |
| 314 | m_pComboBoxProxy->EndDoModal(); |
| 315 | |
| 316 | m_bLButtonDown = false; |
| 317 | m_pListBox->SetNotifyOwner(true); |
| 318 | SetFocus(true); |
| 319 | return; |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 320 | } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 321 | |
| 322 | m_pListBox->ChangeSelected(m_iCurSel); |
| 323 | ResetListItemAlignment(); |
| 324 | |
| 325 | uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & |
| 326 | (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); |
| 327 | m_pListBox->ModifyStylesEx(dwStyleAdd, 0); |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 328 | m_rtList = m_pListBox->GetAutosizedWidgetRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 329 | |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 330 | CFX_RectF rtAnchor(0, 0, m_pProperties->m_rtWidget.width, |
| 331 | m_pProperties->m_rtWidget.height); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 332 | |
| 333 | m_rtList.width = std::max(m_rtList.width, m_rtClient.width); |
| 334 | m_rtProxy = m_rtList; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 335 | |
| 336 | GetPopupPos(0, m_rtProxy.height, rtAnchor, m_rtProxy); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 337 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 338 | m_pComboBoxProxy->SetWidgetRect(m_rtProxy); |
| 339 | m_pComboBoxProxy->Update(); |
| 340 | m_pListBox->SetWidgetRect(m_rtList); |
| 341 | m_pListBox->Update(); |
| 342 | |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 343 | CFWL_Event ev(CFWL_Event::Type::PreDropDown, this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 344 | DispatchEvent(&ev); |
| 345 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 346 | m_pListBox->SetFocus(true); |
| 347 | m_pComboBoxProxy->DoModal(); |
| 348 | m_pListBox->SetFocus(false); |
| 349 | } |
| 350 | |
| 351 | void CFWL_ComboBox::MatchEditText() { |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 352 | CFX_WideString wsText = m_pEdit->GetText(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 353 | int32_t iMatch = m_pListBox->MatchItem(wsText); |
| 354 | if (iMatch != m_iCurSel) { |
| 355 | m_pListBox->ChangeSelected(iMatch); |
| 356 | if (iMatch >= 0) |
| 357 | SyncEditText(iMatch); |
| 358 | } else if (iMatch >= 0) { |
| 359 | m_pEdit->SetSelected(); |
| 360 | } |
| 361 | m_iCurSel = iMatch; |
| 362 | } |
| 363 | |
| 364 | void CFWL_ComboBox::SyncEditText(int32_t iListItem) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 365 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, iListItem); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 366 | m_pEdit->SetText(hItem ? hItem->GetText() : L""); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 367 | m_pEdit->Update(); |
| 368 | m_pEdit->SetSelected(); |
| 369 | } |
| 370 | |
| 371 | void CFWL_ComboBox::Layout() { |
| 372 | if (m_pWidgetMgr->IsFormDisabled()) |
| 373 | return DisForm_Layout(); |
| 374 | |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 375 | m_rtClient = GetClientRect(); |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 376 | IFWL_ThemeProvider* theme = GetAvailableTheme(); |
| 377 | if (!theme) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 378 | return; |
| 379 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 380 | float fBtn = theme->GetScrollBarWidth(); |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 381 | m_rtBtn = CFX_RectF(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, |
| 382 | m_rtClient.height); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 383 | if (!IsDropDownStyle() || !m_pEdit) |
| 384 | return; |
| 385 | |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 386 | CFX_RectF rtEdit(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, |
| 387 | m_rtClient.height); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 388 | m_pEdit->SetWidgetRect(rtEdit); |
| 389 | |
| 390 | if (m_iCurSel >= 0) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 391 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 392 | m_pEdit->LockUpdate(); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 393 | m_pEdit->SetText(hItem ? hItem->GetText() : L""); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 394 | m_pEdit->UnlockUpdate(); |
| 395 | } |
| 396 | m_pEdit->Update(); |
| 397 | } |
| 398 | |
| 399 | void CFWL_ComboBox::ResetTheme() { |
| 400 | IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 401 | if (!pTheme) { |
| 402 | pTheme = GetAvailableTheme(); |
| 403 | m_pProperties->m_pThemeProvider = pTheme; |
| 404 | } |
| 405 | if (m_pListBox && !m_pListBox->GetThemeProvider()) |
| 406 | m_pListBox->SetThemeProvider(pTheme); |
| 407 | if (m_pEdit && !m_pEdit->GetThemeProvider()) |
| 408 | m_pEdit->SetThemeProvider(pTheme); |
| 409 | } |
| 410 | |
| 411 | void CFWL_ComboBox::ResetEditAlignment() { |
| 412 | if (!m_pEdit) |
| 413 | return; |
| 414 | |
| 415 | uint32_t dwAdd = 0; |
| 416 | switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditHAlignMask) { |
| 417 | case FWL_STYLEEXT_CMB_EditHCenter: { |
| 418 | dwAdd |= FWL_STYLEEXT_EDT_HCenter; |
| 419 | break; |
| 420 | } |
dsinclair | 727a304 | 2016-12-14 13:07:47 -0800 | [diff] [blame] | 421 | default: { |
| 422 | dwAdd |= FWL_STYLEEXT_EDT_HNear; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 423 | break; |
| 424 | } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 425 | } |
| 426 | switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditVAlignMask) { |
| 427 | case FWL_STYLEEXT_CMB_EditVCenter: { |
| 428 | dwAdd |= FWL_STYLEEXT_EDT_VCenter; |
| 429 | break; |
| 430 | } |
| 431 | case FWL_STYLEEXT_CMB_EditVFar: { |
| 432 | dwAdd |= FWL_STYLEEXT_EDT_VFar; |
| 433 | break; |
| 434 | } |
| 435 | default: { |
| 436 | dwAdd |= FWL_STYLEEXT_EDT_VNear; |
| 437 | break; |
| 438 | } |
| 439 | } |
| 440 | if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditJustified) |
| 441 | dwAdd |= FWL_STYLEEXT_EDT_Justified; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 442 | |
| 443 | m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | |
| 444 | FWL_STYLEEXT_EDT_HAlignModeMask | |
| 445 | FWL_STYLEEXT_EDT_VAlignMask); |
| 446 | } |
| 447 | |
| 448 | void CFWL_ComboBox::ResetListItemAlignment() { |
| 449 | if (!m_pListBox) |
| 450 | return; |
| 451 | |
| 452 | uint32_t dwAdd = 0; |
| 453 | switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemAlignMask) { |
| 454 | case FWL_STYLEEXT_CMB_ListItemCenterAlign: { |
| 455 | dwAdd |= FWL_STYLEEXT_LTB_CenterAlign; |
| 456 | break; |
| 457 | } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 458 | default: { |
| 459 | dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); |
| 464 | } |
| 465 | |
| 466 | void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { |
| 467 | m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0)); |
| 468 | if (!IsDropDownStyle()) { |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 469 | RepaintRect(m_rtClient); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 470 | return; |
| 471 | } |
| 472 | |
| 473 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); |
| 474 | if (!hItem) |
| 475 | return; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 476 | if (m_pEdit) { |
dsinclair | 603f57b | 2016-12-14 06:25:02 -0800 | [diff] [blame] | 477 | m_pEdit->SetText(hItem->GetText()); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 478 | m_pEdit->Update(); |
| 479 | m_pEdit->SetSelected(); |
| 480 | } |
| 481 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 482 | CFWL_EventSelectChanged ev(this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 483 | ev.bLButtonUp = bLButtonUp; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 484 | DispatchEvent(&ev); |
| 485 | } |
| 486 | |
| 487 | void CFWL_ComboBox::InitProxyForm() { |
| 488 | if (m_pComboBoxProxy) |
| 489 | return; |
| 490 | if (!m_pListBox) |
| 491 | return; |
| 492 | |
| 493 | auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
| 494 | prop->m_pOwner = this; |
| 495 | prop->m_dwStyles = FWL_WGTSTYLE_Popup; |
| 496 | prop->m_dwStates = FWL_WGTSTATE_Invisible; |
| 497 | |
| 498 | // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure |
| 499 | // if the SetParent call is going to transfer ownership. |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 500 | m_pComboBoxProxy = new CFWL_ComboBoxProxy(this, m_pOwnerApp.Get(), |
| 501 | std::move(prop), m_pListBox.get()); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 502 | m_pListBox->SetParent(m_pComboBoxProxy); |
| 503 | } |
| 504 | |
| 505 | void CFWL_ComboBox::DisForm_InitComboList() { |
| 506 | if (m_pListBox) |
| 507 | return; |
| 508 | |
| 509 | auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
| 510 | prop->m_pParent = this; |
| 511 | prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
| 512 | prop->m_dwStates = FWL_WGTSTATE_Invisible; |
| 513 | prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 514 | m_pListBox = pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp.Get(), |
| 515 | std::move(prop), this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void CFWL_ComboBox::DisForm_InitComboEdit() { |
| 519 | if (m_pEdit) |
| 520 | return; |
| 521 | |
| 522 | auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
| 523 | prop->m_pParent = this; |
| 524 | prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
| 525 | |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame^] | 526 | m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>(m_pOwnerApp.Get(), |
| 527 | std::move(prop), this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 528 | m_pEdit->SetOuter(this); |
| 529 | } |
| 530 | |
| 531 | void CFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { |
| 532 | if (DisForm_IsDropListVisible() == bActivate) |
| 533 | return; |
| 534 | |
| 535 | if (bActivate) { |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 536 | CFWL_Event preEvent(CFWL_Event::Type::PreDropDown, this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 537 | DispatchEvent(&preEvent); |
| 538 | |
| 539 | CFWL_ComboList* pComboList = m_pListBox.get(); |
| 540 | int32_t iItems = pComboList->CountItems(nullptr); |
| 541 | if (iItems < 1) |
| 542 | return; |
| 543 | |
| 544 | ResetListItemAlignment(); |
| 545 | pComboList->ChangeSelected(m_iCurSel); |
| 546 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 547 | float fItemHeight = pComboList->CalcItemHeight(); |
| 548 | float fBorder = GetBorderSize(true); |
| 549 | float fPopupMin = 0.0f; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 550 | if (iItems > 3) |
| 551 | fPopupMin = fItemHeight * 3 + fBorder * 2; |
| 552 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 553 | float fPopupMax = fItemHeight * iItems + fBorder * 2; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 554 | CFX_RectF rtList(m_rtClient.left, 0, m_pProperties->m_rtWidget.width, 0); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 555 | GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); |
| 556 | |
| 557 | m_pListBox->SetWidgetRect(rtList); |
| 558 | m_pListBox->Update(); |
| 559 | } else { |
| 560 | SetFocus(true); |
| 561 | } |
| 562 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 563 | if (bActivate) { |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 564 | m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 565 | CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 566 | DispatchEvent(&postEvent); |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 567 | } else { |
| 568 | m_pListBox->SetStates(FWL_WGTSTATE_Invisible); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 569 | } |
| 570 | |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 571 | CFX_RectF rect = m_pListBox->GetWidgetRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 572 | rect.Inflate(2, 2); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 573 | RepaintRect(rect); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, |
| 577 | uint32_t dwStylesExRemoved) { |
| 578 | if (!m_pEdit) |
| 579 | DisForm_InitComboEdit(); |
| 580 | |
| 581 | bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
| 582 | bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); |
| 583 | |
| 584 | dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown; |
| 585 | m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown; |
| 586 | |
| 587 | if (bAddDropDown) |
| 588 | m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly); |
| 589 | else if (bDelDropDown) |
| 590 | m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0); |
| 591 | CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 592 | } |
| 593 | |
| 594 | void CFWL_ComboBox::DisForm_Update() { |
| 595 | if (m_iLock) |
| 596 | return; |
| 597 | if (m_pEdit) |
| 598 | ResetEditAlignment(); |
| 599 | ResetTheme(); |
| 600 | Layout(); |
| 601 | } |
| 602 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 603 | FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(const CFX_PointF& point) { |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 604 | CFX_RectF rect(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, |
| 605 | m_pProperties->m_rtWidget.height); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 606 | if (rect.Contains(point)) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 607 | return FWL_WidgetHit::Edit; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 608 | if (m_rtBtn.Contains(point)) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 609 | return FWL_WidgetHit::Client; |
| 610 | if (DisForm_IsDropListVisible()) { |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 611 | rect = m_pListBox->GetWidgetRect(); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 612 | if (rect.Contains(point)) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 613 | return FWL_WidgetHit::Client; |
| 614 | } |
| 615 | return FWL_WidgetHit::Unknown; |
| 616 | } |
| 617 | |
| 618 | void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, |
| 619 | const CFX_Matrix* pMatrix) { |
| 620 | IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 621 | CFX_Matrix mtOrg(1, 0, 0, 1, 0, 0); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 622 | if (pMatrix) |
| 623 | mtOrg = *pMatrix; |
| 624 | |
| 625 | pGraphics->SaveGraphState(); |
| 626 | pGraphics->ConcatMatrix(&mtOrg); |
| 627 | if (!m_rtBtn.IsEmpty(0.1f)) { |
| 628 | CFWL_ThemeBackground param; |
| 629 | param.m_pWidget = this; |
| 630 | param.m_iPart = CFWL_Part::DropDownButton; |
| 631 | param.m_dwStates = m_iBtnState; |
| 632 | param.m_pGraphics = pGraphics; |
| 633 | param.m_rtPart = m_rtBtn; |
| 634 | pTheme->DrawBackground(¶m); |
| 635 | } |
| 636 | pGraphics->RestoreGraphState(); |
| 637 | |
| 638 | if (m_pEdit) { |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 639 | CFX_RectF rtEdit = m_pEdit->GetWidgetRect(); |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 640 | CFX_Matrix mt(1, 0, 0, 1, rtEdit.left, rtEdit.top); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 641 | mt.Concat(mtOrg); |
| 642 | m_pEdit->DrawWidget(pGraphics, &mt); |
| 643 | } |
| 644 | if (m_pListBox && DisForm_IsDropListVisible()) { |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 645 | CFX_RectF rtList = m_pListBox->GetWidgetRect(); |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 646 | CFX_Matrix mt(1, 0, 0, 1, rtList.left, rtList.top); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 647 | mt.Concat(mtOrg); |
| 648 | m_pListBox->DrawWidget(pGraphics, &mt); |
| 649 | } |
| 650 | } |
| 651 | |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 652 | CFX_RectF CFWL_ComboBox::DisForm_GetBBox() const { |
| 653 | CFX_RectF rect = m_pProperties->m_rtWidget; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 654 | if (!m_pListBox || !DisForm_IsDropListVisible()) |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 655 | return rect; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 656 | |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 657 | CFX_RectF rtList = m_pListBox->GetWidgetRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 658 | rtList.Offset(rect.left, rect.top); |
| 659 | rect.Union(rtList); |
dsinclair | a2cbc57 | 2016-12-07 18:10:16 -0800 | [diff] [blame] | 660 | return rect; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | void CFWL_ComboBox::DisForm_Layout() { |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 664 | m_rtClient = GetClientRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 665 | m_rtContent = m_rtClient; |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 666 | IFWL_ThemeProvider* theme = GetAvailableTheme(); |
| 667 | if (!theme) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 668 | return; |
| 669 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 670 | float borderWidth = 1; |
| 671 | float fBtn = theme->GetScrollBarWidth(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 672 | if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 673 | m_rtBtn = |
| 674 | CFX_RectF(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, |
| 675 | fBtn - borderWidth, m_rtClient.height - 2 * borderWidth); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Dan Sinclair | c635c93 | 2017-01-03 15:46:55 -0500 | [diff] [blame] | 678 | CFWL_ThemePart part; |
| 679 | part.m_pWidget = this; |
| 680 | CFX_RectF pUIMargin = theme->GetUIMargin(&part); |
| 681 | m_rtContent.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width, |
| 682 | pUIMargin.height); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 683 | |
| 684 | if (!IsDropDownStyle() || !m_pEdit) |
| 685 | return; |
| 686 | |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 687 | CFX_RectF rtEdit(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, |
| 688 | m_rtContent.height); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 689 | m_pEdit->SetWidgetRect(rtEdit); |
| 690 | |
| 691 | if (m_iCurSel >= 0) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 692 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 693 | m_pEdit->LockUpdate(); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 694 | m_pEdit->SetText(hItem ? hItem->GetText() : L""); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 695 | m_pEdit->UnlockUpdate(); |
| 696 | } |
| 697 | m_pEdit->Update(); |
| 698 | } |
| 699 | |
| 700 | void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { |
| 701 | if (m_pWidgetMgr->IsFormDisabled()) { |
| 702 | DisForm_OnProcessMessage(pMessage); |
| 703 | return; |
| 704 | } |
| 705 | if (!pMessage) |
| 706 | return; |
| 707 | |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 708 | switch (pMessage->GetType()) { |
| 709 | case CFWL_Message::Type::SetFocus: |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 710 | OnFocusChanged(pMessage, true); |
| 711 | break; |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 712 | case CFWL_Message::Type::KillFocus: |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 713 | OnFocusChanged(pMessage, false); |
| 714 | break; |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 715 | case CFWL_Message::Type::Mouse: { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 716 | CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 717 | switch (pMsg->m_dwCmd) { |
| 718 | case FWL_MouseCommand::LeftButtonDown: |
| 719 | OnLButtonDown(pMsg); |
| 720 | break; |
| 721 | case FWL_MouseCommand::LeftButtonUp: |
| 722 | OnLButtonUp(pMsg); |
| 723 | break; |
| 724 | case FWL_MouseCommand::Move: |
| 725 | OnMouseMove(pMsg); |
| 726 | break; |
| 727 | case FWL_MouseCommand::Leave: |
| 728 | OnMouseLeave(pMsg); |
| 729 | break; |
| 730 | default: |
| 731 | break; |
| 732 | } |
| 733 | break; |
| 734 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 735 | case CFWL_Message::Type::Key: |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 736 | OnKey(static_cast<CFWL_MessageKey*>(pMessage)); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 737 | break; |
| 738 | default: |
| 739 | break; |
| 740 | } |
| 741 | |
| 742 | CFWL_Widget::OnProcessMessage(pMessage); |
| 743 | } |
| 744 | |
| 745 | void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) { |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 746 | CFWL_Event::Type type = pEvent->GetType(); |
| 747 | if (type == CFWL_Event::Type::Scroll) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 748 | CFWL_EventScroll* pScrollEvent = static_cast<CFWL_EventScroll*>(pEvent); |
| 749 | CFWL_EventScroll pScrollEv(this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 750 | pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode; |
| 751 | pScrollEv.m_fPos = pScrollEvent->m_fPos; |
| 752 | DispatchEvent(&pScrollEv); |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 753 | } else if (type == CFWL_Event::Type::TextChanged) { |
| 754 | CFWL_Event pTemp(CFWL_Event::Type::EditChanged, this); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 755 | DispatchEvent(&pTemp); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | void CFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, |
| 760 | const CFX_Matrix* pMatrix) { |
| 761 | DrawWidget(pGraphics, pMatrix); |
| 762 | } |
| 763 | |
| 764 | void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
| 765 | if (bSet) { |
| 766 | m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 767 | if (IsDropDownStyle() && pMsg->m_pSrcTarget != m_pListBox.get()) { |
| 768 | if (!m_pEdit) |
| 769 | return; |
| 770 | m_pEdit->SetSelected(); |
| 771 | return; |
| 772 | } |
| 773 | |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 774 | RepaintRect(m_rtClient); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 775 | return; |
| 776 | } |
| 777 | |
| 778 | m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
| 779 | if (!IsDropDownStyle() || pMsg->m_pDstTarget == m_pListBox.get()) { |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 780 | RepaintRect(m_rtClient); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 781 | return; |
| 782 | } |
| 783 | if (!m_pEdit) |
| 784 | return; |
| 785 | |
| 786 | m_pEdit->FlagFocus(false); |
| 787 | m_pEdit->ClearSelected(); |
| 788 | } |
| 789 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 790 | void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 791 | if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 792 | return; |
| 793 | |
| 794 | CFX_RectF& rtBtn = IsDropDownStyle() ? m_rtBtn : m_rtClient; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 795 | if (!rtBtn.Contains(pMsg->m_pos)) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 796 | return; |
| 797 | |
| 798 | if (IsDropDownStyle() && m_pEdit) |
| 799 | MatchEditText(); |
| 800 | |
| 801 | m_bLButtonDown = true; |
| 802 | m_iBtnState = CFWL_PartState_Pressed; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 803 | RepaintRect(m_rtClient); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 804 | |
| 805 | ShowDropList(true); |
| 806 | m_iBtnState = CFWL_PartState_Normal; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 807 | RepaintRect(m_rtClient); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 808 | } |
| 809 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 810 | void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 811 | m_bLButtonDown = false; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 812 | if (m_rtBtn.Contains(pMsg->m_pos)) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 813 | m_iBtnState = CFWL_PartState_Hovered; |
| 814 | else |
| 815 | m_iBtnState = CFWL_PartState_Normal; |
| 816 | |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 817 | RepaintRect(m_rtBtn); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 818 | } |
| 819 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 820 | void CFWL_ComboBox::OnMouseMove(CFWL_MessageMouse* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 821 | int32_t iOldState = m_iBtnState; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 822 | if (m_rtBtn.Contains(pMsg->m_pos)) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 823 | m_iBtnState = |
| 824 | m_bLButtonDown ? CFWL_PartState_Pressed : CFWL_PartState_Hovered; |
| 825 | } else { |
| 826 | m_iBtnState = CFWL_PartState_Normal; |
| 827 | } |
| 828 | if ((iOldState != m_iBtnState) && |
| 829 | !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == |
| 830 | FWL_WGTSTATE_Disabled)) { |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 831 | RepaintRect(m_rtBtn); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 835 | void CFWL_ComboBox::OnMouseLeave(CFWL_MessageMouse* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 836 | if (!IsDropListVisible() && |
| 837 | !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == |
| 838 | FWL_WGTSTATE_Disabled)) { |
| 839 | m_iBtnState = CFWL_PartState_Normal; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 840 | RepaintRect(m_rtBtn); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 844 | void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 845 | uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 846 | if (dwKeyCode == FWL_VKEY_Tab) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 847 | return; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 848 | if (pMsg->m_pDstTarget == this) |
| 849 | DoSubCtrlKey(pMsg); |
| 850 | } |
| 851 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 852 | void CFWL_ComboBox::DoSubCtrlKey(CFWL_MessageKey* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 853 | uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
| 854 | const bool bUp = dwKeyCode == FWL_VKEY_Up; |
| 855 | const bool bDown = dwKeyCode == FWL_VKEY_Down; |
| 856 | if (bUp || bDown) { |
| 857 | int32_t iCount = m_pListBox->CountItems(nullptr); |
| 858 | if (iCount < 1) |
| 859 | return; |
| 860 | |
| 861 | bool bMatchEqual = false; |
| 862 | int32_t iCurSel = m_iCurSel; |
| 863 | bool bDropDown = IsDropDownStyle(); |
| 864 | if (bDropDown && m_pEdit) { |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 865 | CFX_WideString wsText = m_pEdit->GetText(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 866 | iCurSel = m_pListBox->MatchItem(wsText); |
| 867 | if (iCurSel >= 0) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 868 | CFWL_ListItem* hItem = m_pListBox->GetItem(this, iCurSel); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 869 | bMatchEqual = wsText == (hItem ? hItem->GetText() : L""); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 870 | } |
| 871 | } |
| 872 | if (iCurSel < 0) { |
| 873 | iCurSel = 0; |
| 874 | } else if (!bDropDown || bMatchEqual) { |
| 875 | if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
| 876 | return; |
| 877 | if (bUp) |
| 878 | iCurSel--; |
| 879 | else |
| 880 | iCurSel++; |
| 881 | } |
| 882 | m_iCurSel = iCurSel; |
| 883 | if (bDropDown && m_pEdit) |
| 884 | SyncEditText(m_iCurSel); |
| 885 | else |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 886 | RepaintRect(m_rtClient); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 887 | return; |
| 888 | } |
| 889 | |
| 890 | if (IsDropDownStyle()) |
| 891 | m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
| 892 | } |
| 893 | |
| 894 | void CFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { |
| 895 | if (!pMessage) |
| 896 | return; |
| 897 | |
| 898 | bool backDefault = true; |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 899 | switch (pMessage->GetType()) { |
| 900 | case CFWL_Message::Type::SetFocus: { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 901 | backDefault = false; |
| 902 | DisForm_OnFocusChanged(pMessage, true); |
| 903 | break; |
| 904 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 905 | case CFWL_Message::Type::KillFocus: { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 906 | backDefault = false; |
| 907 | DisForm_OnFocusChanged(pMessage, false); |
| 908 | break; |
| 909 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 910 | case CFWL_Message::Type::Mouse: { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 911 | backDefault = false; |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 912 | CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 913 | switch (pMsg->m_dwCmd) { |
| 914 | case FWL_MouseCommand::LeftButtonDown: |
| 915 | DisForm_OnLButtonDown(pMsg); |
| 916 | break; |
| 917 | case FWL_MouseCommand::LeftButtonUp: |
| 918 | OnLButtonUp(pMsg); |
| 919 | break; |
| 920 | default: |
| 921 | break; |
| 922 | } |
| 923 | break; |
| 924 | } |
dsinclair | 4614b45 | 2016-12-07 17:01:58 -0800 | [diff] [blame] | 925 | case CFWL_Message::Type::Key: { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 926 | backDefault = false; |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 927 | CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 928 | if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp) |
| 929 | break; |
| 930 | if (DisForm_IsDropListVisible() && |
| 931 | pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
| 932 | bool bListKey = pKey->m_dwKeyCode == FWL_VKEY_Up || |
| 933 | pKey->m_dwKeyCode == FWL_VKEY_Down || |
| 934 | pKey->m_dwKeyCode == FWL_VKEY_Return || |
| 935 | pKey->m_dwKeyCode == FWL_VKEY_Escape; |
| 936 | if (bListKey) { |
| 937 | m_pListBox->GetDelegate()->OnProcessMessage(pMessage); |
| 938 | break; |
| 939 | } |
| 940 | } |
| 941 | DisForm_OnKey(pKey); |
| 942 | break; |
| 943 | } |
| 944 | default: |
| 945 | break; |
| 946 | } |
| 947 | if (backDefault) |
| 948 | CFWL_Widget::OnProcessMessage(pMessage); |
| 949 | } |
| 950 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 951 | void CFWL_ComboBox::DisForm_OnLButtonDown(CFWL_MessageMouse* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 952 | bool bDropDown = DisForm_IsDropListVisible(); |
| 953 | CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 954 | if (!rtBtn.Contains(pMsg->m_pos)) |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 955 | return; |
| 956 | |
| 957 | if (DisForm_IsDropListVisible()) { |
| 958 | DisForm_ShowDropList(false); |
| 959 | return; |
| 960 | } |
| 961 | if (m_pEdit) |
| 962 | MatchEditText(); |
| 963 | DisForm_ShowDropList(true); |
| 964 | } |
| 965 | |
| 966 | void CFWL_ComboBox::DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
| 967 | if (bSet) { |
| 968 | m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 969 | if ((m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) { |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 970 | CFWL_MessageSetFocus msg(nullptr, m_pEdit.get()); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 971 | m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
| 972 | } |
| 973 | } else { |
| 974 | m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
| 975 | DisForm_ShowDropList(false); |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 976 | CFWL_MessageKillFocus msg(m_pEdit.get()); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 977 | m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
| 978 | } |
| 979 | } |
| 980 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 981 | void CFWL_ComboBox::DisForm_OnKey(CFWL_MessageKey* pMsg) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 982 | uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
| 983 | const bool bUp = dwKeyCode == FWL_VKEY_Up; |
| 984 | const bool bDown = dwKeyCode == FWL_VKEY_Down; |
| 985 | if (bUp || bDown) { |
| 986 | CFWL_ComboList* pComboList = m_pListBox.get(); |
| 987 | int32_t iCount = pComboList->CountItems(nullptr); |
| 988 | if (iCount < 1) |
| 989 | return; |
| 990 | |
| 991 | bool bMatchEqual = false; |
| 992 | int32_t iCurSel = m_iCurSel; |
| 993 | if (m_pEdit) { |
dan sinclair | 0354ccf | 2016-11-24 10:45:29 -0500 | [diff] [blame] | 994 | CFX_WideString wsText = m_pEdit->GetText(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 995 | iCurSel = pComboList->MatchItem(wsText); |
| 996 | if (iCurSel >= 0) { |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 997 | CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); |
Dan Sinclair | b38c5df | 2017-01-02 13:38:17 -0500 | [diff] [blame] | 998 | bMatchEqual = wsText == (item ? item->GetText() : L""); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | if (iCurSel < 0) { |
| 1002 | iCurSel = 0; |
| 1003 | } else if (bMatchEqual) { |
| 1004 | if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
| 1005 | return; |
| 1006 | if (bUp) |
| 1007 | iCurSel--; |
| 1008 | else |
| 1009 | iCurSel++; |
| 1010 | } |
| 1011 | m_iCurSel = iCurSel; |
| 1012 | SyncEditText(m_iCurSel); |
| 1013 | return; |
| 1014 | } |
| 1015 | if (m_pEdit) |
| 1016 | m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 1017 | } |