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