Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fwl/core/ifwl_combobox.h" | 7 #include "xfa/fwl/core/ifwl_combobox.h" |
| 8 | 8 |
| 9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
| 10 #include "xfa/fde/cfde_txtedtengine.h" | 10 #include "xfa/fde/cfde_txtedtengine.h" |
| 11 #include "xfa/fde/tto/fde_textout.h" | 11 #include "xfa/fde/tto/fde_textout.h" |
| 12 #include "xfa/fwl/core/cfwl_message.h" | 12 #include "xfa/fwl/core/cfwl_message.h" |
| 13 #include "xfa/fwl/core/cfwl_themebackground.h" | 13 #include "xfa/fwl/core/cfwl_themebackground.h" |
| 14 #include "xfa/fwl/core/cfwl_themepart.h" | 14 #include "xfa/fwl/core/cfwl_themepart.h" |
| 15 #include "xfa/fwl/core/cfwl_themetext.h" | 15 #include "xfa/fwl/core/cfwl_themetext.h" |
| 16 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 16 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
| 17 #include "xfa/fwl/core/fwl_noteimp.h" | 17 #include "xfa/fwl/core/fwl_noteimp.h" |
| 18 #include "xfa/fwl/core/ifwl_app.h" | 18 #include "xfa/fwl/core/ifwl_app.h" |
| 19 #include "xfa/fwl/core/ifwl_comboboxproxy.h" | |
| 20 #include "xfa/fwl/core/ifwl_comboedit.h" | |
| 21 #include "xfa/fwl/core/ifwl_formproxy.h" | 19 #include "xfa/fwl/core/ifwl_formproxy.h" |
| 22 #include "xfa/fwl/core/ifwl_themeprovider.h" | 20 #include "xfa/fwl/core/ifwl_themeprovider.h" |
| 23 | 21 |
| 24 IFWL_ComboBox::IFWL_ComboBox(const IFWL_App* app, | 22 IFWL_ComboBox::IFWL_ComboBox(const IFWL_App* app, |
| 25 std::unique_ptr<CFWL_WidgetProperties> properties) | 23 std::unique_ptr<CFWL_WidgetProperties> properties) |
| 26 : IFWL_Widget(app, std::move(properties), nullptr), | 24 : IFWL_Widget(app, std::move(properties), nullptr), |
| 27 m_pComboBoxProxy(nullptr), | 25 m_pComboBoxProxy(nullptr), |
| 28 m_bLButtonDown(false), | 26 m_bLButtonDown(false), |
| 29 m_iCurSel(-1), | 27 m_iCurSel(-1), |
| 30 m_iBtnState(CFWL_PartState_Normal), | 28 m_iBtnState(CFWL_PartState_Normal), |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 58 SetStates(m_pProperties->m_dwStates); | 56 SetStates(m_pProperties->m_dwStates); |
| 59 } | 57 } |
| 60 | 58 |
| 61 IFWL_ComboBox::~IFWL_ComboBox() {} | 59 IFWL_ComboBox::~IFWL_ComboBox() {} |
| 62 | 60 |
| 63 FWL_Type IFWL_ComboBox::GetClassID() const { | 61 FWL_Type IFWL_ComboBox::GetClassID() const { |
| 64 return FWL_Type::ComboBox; | 62 return FWL_Type::ComboBox; |
| 65 } | 63 } |
| 66 | 64 |
| 67 void IFWL_ComboBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 65 void IFWL_ComboBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
| 68 if (bAutoSize) { | 66 if (!bAutoSize) { |
| 69 rect.Reset(); | 67 rect = m_pProperties->m_rtWidget; |
| 70 bool bIsDropDown = IsDropDownStyle(); | 68 return; |
| 71 if (bIsDropDown && m_pEdit) { | 69 } |
| 72 m_pEdit->GetWidgetRect(rect, true); | 70 |
| 73 } else { | 71 rect.Reset(); |
| 74 rect.width = 100; | 72 if (IsDropDownStyle() && m_pEdit) { |
| 75 rect.height = 16; | 73 m_pEdit->GetWidgetRect(rect, true); |
| 76 } | |
| 77 if (!m_pProperties->m_pThemeProvider) { | |
| 78 ResetTheme(); | |
| 79 } | |
| 80 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
| 81 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 82 if (!pFWidth) | |
| 83 return; | |
| 84 rect.Inflate(0, 0, *pFWidth, 0); | |
| 85 IFWL_Widget::GetWidgetRect(rect, true); | |
| 86 } else { | 74 } else { |
| 87 rect = m_pProperties->m_rtWidget; | 75 rect.width = 100; |
| 76 rect.height = 16; | |
| 88 } | 77 } |
| 78 if (!m_pProperties->m_pThemeProvider) | |
| 79 ResetTheme(); | |
| 80 | |
| 81 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
| 82 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 83 if (!pFWidth) | |
| 84 return; | |
| 85 | |
| 86 rect.Inflate(0, 0, *pFWidth, 0); | |
| 87 IFWL_Widget::GetWidgetRect(rect, true); | |
| 89 } | 88 } |
| 90 | 89 |
| 91 void IFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, | 90 void IFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, |
| 92 uint32_t dwStylesExRemoved) { | 91 uint32_t dwStylesExRemoved) { |
| 93 if (m_pWidgetMgr->IsFormDisabled()) { | 92 if (m_pWidgetMgr->IsFormDisabled()) { |
| 94 DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 93 DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 95 return; | 94 return; |
| 96 } | 95 } |
| 96 | |
| 97 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 97 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
| 98 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); | 98 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); |
| 99 if (bAddDropDown && !m_pEdit) { | 99 if (bAddDropDown && !m_pEdit) { |
| 100 m_pEdit.reset(new IFWL_ComboEdit( | 100 m_pEdit = pdfium::MakeUnique<IFWL_ComboEdit>( |
| 101 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr)); | 101 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
| 102 m_pEdit->SetOuter(this); | 102 m_pEdit->SetOuter(this); |
| 103 m_pEdit->SetParent(this); | 103 m_pEdit->SetParent(this); |
| 104 } else if (bRemoveDropDown && m_pEdit) { | 104 } else if (bRemoveDropDown && m_pEdit) { |
| 105 m_pEdit->SetStates(FWL_WGTSTATE_Invisible, true); | 105 m_pEdit->SetStates(FWL_WGTSTATE_Invisible, true); |
| 106 } | 106 } |
| 107 IFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 107 IFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void IFWL_ComboBox::Update() { | 110 void IFWL_ComboBox::Update() { |
| 111 if (m_pWidgetMgr->IsFormDisabled()) { | 111 if (m_pWidgetMgr->IsFormDisabled()) { |
| 112 DisForm_Update(); | 112 DisForm_Update(); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 if (IsLocked()) { | 115 if (IsLocked()) |
| 116 return; | 116 return; |
| 117 } | 117 |
| 118 ResetTheme(); | 118 ResetTheme(); |
| 119 bool bDropDown = IsDropDownStyle(); | 119 if (IsDropDownStyle() && m_pEdit) |
| 120 if (bDropDown && m_pEdit) { | |
| 121 ResetEditAlignment(); | 120 ResetEditAlignment(); |
| 122 } | 121 if (!m_pProperties->m_pThemeProvider) |
| 123 if (!m_pProperties->m_pThemeProvider) { | |
| 124 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 122 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 125 } | 123 |
| 126 Layout(); | 124 Layout(); |
| 127 CFWL_ThemePart part; | 125 CFWL_ThemePart part; |
| 128 part.m_pWidget = this; | 126 part.m_pWidget = this; |
| 129 m_fComboFormHandler = | 127 m_fComboFormHandler = |
| 130 *static_cast<FX_FLOAT*>(m_pProperties->m_pThemeProvider->GetCapacity( | 128 *static_cast<FX_FLOAT*>(m_pProperties->m_pThemeProvider->GetCapacity( |
| 131 &part, CFWL_WidgetCapacity::ComboFormHandler)); | 129 &part, CFWL_WidgetCapacity::ComboFormHandler)); |
| 132 } | 130 } |
| 133 | 131 |
| 134 FWL_WidgetHit IFWL_ComboBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 132 FWL_WidgetHit IFWL_ComboBox::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 135 if (m_pWidgetMgr->IsFormDisabled()) { | 133 if (m_pWidgetMgr->IsFormDisabled()) |
| 136 return DisForm_HitTest(fx, fy); | 134 return DisForm_HitTest(fx, fy); |
| 137 } | |
| 138 return IFWL_Widget::HitTest(fx, fy); | 135 return IFWL_Widget::HitTest(fx, fy); |
| 139 } | 136 } |
| 140 | 137 |
| 141 void IFWL_ComboBox::DrawWidget(CFX_Graphics* pGraphics, | 138 void IFWL_ComboBox::DrawWidget(CFX_Graphics* pGraphics, |
| 142 const CFX_Matrix* pMatrix) { | 139 const CFX_Matrix* pMatrix) { |
| 143 if (m_pWidgetMgr->IsFormDisabled()) { | 140 if (m_pWidgetMgr->IsFormDisabled()) { |
| 144 DisForm_DrawWidget(pGraphics, pMatrix); | 141 DisForm_DrawWidget(pGraphics, pMatrix); |
| 145 return; | 142 return; |
| 146 } | 143 } |
| 144 | |
| 147 if (!pGraphics) | 145 if (!pGraphics) |
| 148 return; | 146 return; |
| 149 if (!m_pProperties->m_pThemeProvider) | 147 if (!m_pProperties->m_pThemeProvider) |
| 150 return; | 148 return; |
| 149 | |
| 151 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 150 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 152 bool bIsDropDown = IsDropDownStyle(); | 151 if (HasBorder()) |
| 153 if (HasBorder()) { | |
| 154 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 152 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
| 155 } | 153 if (HasEdge()) |
| 156 if (HasEdge()) { | |
| 157 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 154 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
| 158 } | 155 |
| 159 if (!bIsDropDown) { | 156 if (!IsDropDownStyle()) { |
| 160 CFX_RectF rtTextBk(m_rtClient); | 157 CFX_RectF rtTextBk(m_rtClient); |
| 161 rtTextBk.width -= m_rtBtn.width; | 158 rtTextBk.width -= m_rtBtn.width; |
| 159 | |
| 162 CFWL_ThemeBackground param; | 160 CFWL_ThemeBackground param; |
| 163 param.m_pWidget = this; | 161 param.m_pWidget = this; |
| 164 param.m_iPart = CFWL_Part::Background; | 162 param.m_iPart = CFWL_Part::Background; |
| 165 param.m_pGraphics = pGraphics; | 163 param.m_pGraphics = pGraphics; |
| 166 if (pMatrix) { | 164 if (pMatrix) |
| 167 param.m_matrix.Concat(*pMatrix); | 165 param.m_matrix.Concat(*pMatrix); |
| 168 } | |
| 169 param.m_rtPart = rtTextBk; | 166 param.m_rtPart = rtTextBk; |
| 167 | |
| 170 if (m_iCurSel >= 0) { | 168 if (m_iCurSel >= 0) { |
| 171 IFWL_ListBoxDP* pData = | 169 IFWL_ListBoxDP* pData = |
| 172 static_cast<IFWL_ListBoxDP*>(m_pListBox->GetDataProvider()); | 170 static_cast<IFWL_ListBoxDP*>(m_pListBox->GetDataProvider()); |
| 173 void* p = pData->GetItemData(m_pListBox.get(), | 171 void* p = pData->GetItemData(m_pListBox.get(), |
| 174 pData->GetItem(m_pListBox.get(), m_iCurSel)); | 172 pData->GetItem(m_pListBox.get(), m_iCurSel)); |
| 175 if (p) { | 173 if (p) |
| 176 param.m_pData = p; | 174 param.m_pData = p; |
| 177 } | |
| 178 } | 175 } |
| 176 | |
| 179 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | 177 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { |
| 180 param.m_dwStates = CFWL_PartState_Disabled; | 178 param.m_dwStates = CFWL_PartState_Disabled; |
| 181 } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && | 179 } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && |
| 182 (m_iCurSel >= 0)) { | 180 (m_iCurSel >= 0)) { |
| 183 param.m_dwStates = CFWL_PartState_Selected; | 181 param.m_dwStates = CFWL_PartState_Selected; |
| 184 } else { | 182 } else { |
| 185 param.m_dwStates = CFWL_PartState_Normal; | 183 param.m_dwStates = CFWL_PartState_Normal; |
| 186 } | 184 } |
| 187 pTheme->DrawBackground(¶m); | 185 pTheme->DrawBackground(¶m); |
| 186 | |
| 188 if (m_iCurSel >= 0) { | 187 if (m_iCurSel >= 0) { |
| 189 if (!m_pListBox) | 188 if (!m_pListBox) |
| 190 return; | 189 return; |
| 190 | |
| 191 CFX_WideString wsText; | 191 CFX_WideString wsText; |
| 192 IFWL_ComboBoxDP* pData = | 192 IFWL_ComboBoxDP* pData = |
| 193 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 193 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 194 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 194 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
| 195 m_pListBox->GetItemText(hItem, wsText); | 195 m_pListBox->GetItemText(hItem, wsText); |
| 196 | |
| 196 CFWL_ThemeText theme_text; | 197 CFWL_ThemeText theme_text; |
| 197 theme_text.m_pWidget = this; | 198 theme_text.m_pWidget = this; |
| 198 theme_text.m_iPart = CFWL_Part::Caption; | 199 theme_text.m_iPart = CFWL_Part::Caption; |
| 199 theme_text.m_dwStates = m_iBtnState; | 200 theme_text.m_dwStates = m_iBtnState; |
| 200 theme_text.m_pGraphics = pGraphics; | 201 theme_text.m_pGraphics = pGraphics; |
| 201 theme_text.m_matrix.Concat(*pMatrix); | 202 theme_text.m_matrix.Concat(*pMatrix); |
| 202 theme_text.m_rtPart = rtTextBk; | 203 theme_text.m_rtPart = rtTextBk; |
| 203 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 204 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
| 204 ? CFWL_PartState_Selected | 205 ? CFWL_PartState_Selected |
| 205 : CFWL_PartState_Normal; | 206 : CFWL_PartState_Normal; |
| 206 theme_text.m_wsText = wsText; | 207 theme_text.m_wsText = wsText; |
| 207 theme_text.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | 208 theme_text.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; |
| 208 theme_text.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | 209 theme_text.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; |
| 209 pTheme->DrawText(&theme_text); | 210 pTheme->DrawText(&theme_text); |
| 210 } | 211 } |
| 211 } | 212 } |
| 212 { | 213 |
| 213 CFWL_ThemeBackground param; | 214 CFWL_ThemeBackground param; |
| 214 param.m_pWidget = this; | 215 param.m_pWidget = this; |
| 215 param.m_iPart = CFWL_Part::DropDownButton; | 216 param.m_iPart = CFWL_Part::DropDownButton; |
| 216 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 217 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 217 ? CFWL_PartState_Disabled | 218 ? CFWL_PartState_Disabled |
| 218 : m_iBtnState; | 219 : m_iBtnState; |
| 219 param.m_pGraphics = pGraphics; | 220 param.m_pGraphics = pGraphics; |
| 220 param.m_matrix.Concat(*pMatrix); | 221 param.m_matrix.Concat(*pMatrix); |
| 221 param.m_rtPart = m_rtBtn; | 222 param.m_rtPart = m_rtBtn; |
| 222 pTheme->DrawBackground(¶m); | 223 pTheme->DrawBackground(¶m); |
| 223 } | |
| 224 } | 224 } |
| 225 | 225 |
| 226 void IFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | 226 void IFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { |
| 227 if (!pThemeProvider) | 227 if (!pThemeProvider) |
| 228 return; | 228 return; |
| 229 | |
| 229 m_pProperties->m_pThemeProvider = pThemeProvider; | 230 m_pProperties->m_pThemeProvider = pThemeProvider; |
| 230 if (m_pListBox) | 231 if (m_pListBox) |
| 231 m_pListBox->SetThemeProvider(pThemeProvider); | 232 m_pListBox->SetThemeProvider(pThemeProvider); |
| 232 if (m_pEdit) | 233 if (m_pEdit) |
| 233 m_pEdit->SetThemeProvider(pThemeProvider); | 234 m_pEdit->SetThemeProvider(pThemeProvider); |
| 234 } | 235 } |
| 235 | 236 |
| 236 int32_t IFWL_ComboBox::GetCurSel() const { | |
| 237 return m_iCurSel; | |
| 238 } | |
| 239 | |
| 240 void IFWL_ComboBox::SetCurSel(int32_t iSel) { | 237 void IFWL_ComboBox::SetCurSel(int32_t iSel) { |
| 241 int32_t iCount = m_pListBox->CountItems(); | 238 int32_t iCount = m_pListBox->CountItems(); |
| 242 bool bClearSel = iSel < 0 || iSel >= iCount; | 239 bool bClearSel = iSel < 0 || iSel >= iCount; |
| 243 bool bDropDown = IsDropDownStyle(); | 240 if (IsDropDownStyle() && m_pEdit) { |
| 244 if (bDropDown && m_pEdit) { | |
| 245 if (bClearSel) { | 241 if (bClearSel) { |
| 246 m_pEdit->SetText(CFX_WideString()); | 242 m_pEdit->SetText(CFX_WideString()); |
| 247 } else { | 243 } else { |
| 248 CFX_WideString wsText; | 244 CFX_WideString wsText; |
| 249 IFWL_ComboBoxDP* pData = | 245 IFWL_ComboBoxDP* pData = |
| 250 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 246 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 251 CFWL_ListItem* hItem = pData->GetItem(this, iSel); | 247 CFWL_ListItem* hItem = pData->GetItem(this, iSel); |
| 252 m_pListBox->GetItemText(hItem, wsText); | 248 m_pListBox->GetItemText(hItem, wsText); |
| 253 m_pEdit->SetText(wsText); | 249 m_pEdit->SetText(wsText); |
| 254 } | 250 } |
| 255 m_pEdit->Update(); | 251 m_pEdit->Update(); |
| 256 } | 252 } |
| 257 m_iCurSel = bClearSel ? -1 : iSel; | 253 m_iCurSel = bClearSel ? -1 : iSel; |
| 258 } | 254 } |
| 259 | 255 |
| 260 void IFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { | 256 void IFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { |
| 261 bool bIsDropDown = IsDropDownStyle(); | 257 if (IsDropDownStyle() && m_pEdit) |
| 262 if (bIsDropDown && m_pEdit) | |
| 263 m_pEdit->SetStates(dwStates, bSet); | 258 m_pEdit->SetStates(dwStates, bSet); |
| 264 if (m_pListBox) | 259 if (m_pListBox) |
| 265 m_pListBox->SetStates(dwStates, bSet); | 260 m_pListBox->SetStates(dwStates, bSet); |
| 266 IFWL_Widget::SetStates(dwStates, bSet); | 261 IFWL_Widget::SetStates(dwStates, bSet); |
| 267 } | 262 } |
| 268 | 263 |
| 269 void IFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { | 264 void IFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { |
| 270 if (!m_pEdit) | 265 if (!m_pEdit) |
| 271 return; | 266 return; |
| 267 | |
| 272 m_pEdit->SetText(wsText); | 268 m_pEdit->SetText(wsText); |
| 273 m_pEdit->Update(); | 269 m_pEdit->Update(); |
| 274 } | 270 } |
| 275 | 271 |
| 276 void IFWL_ComboBox::GetEditText(CFX_WideString& wsText, | 272 void IFWL_ComboBox::GetEditText(CFX_WideString& wsText, |
| 277 int32_t nStart, | 273 int32_t nStart, |
| 278 int32_t nCount) const { | 274 int32_t nCount) const { |
| 279 if (m_pEdit) { | 275 if (m_pEdit) { |
| 280 m_pEdit->GetText(wsText, nStart, nCount); | 276 m_pEdit->GetText(wsText, nStart, nCount); |
| 281 return; | 277 return; |
| 282 } | 278 } |
| 283 if (!m_pListBox) | 279 if (!m_pListBox) |
| 284 return; | 280 return; |
| 285 | 281 |
| 286 IFWL_ComboBoxDP* pData = | 282 IFWL_ComboBoxDP* pData = |
| 287 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 283 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 288 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 284 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
| 289 m_pListBox->GetItemText(hItem, wsText); | 285 m_pListBox->GetItemText(hItem, wsText); |
| 290 } | 286 } |
| 291 | 287 |
| 292 void IFWL_ComboBox::OpenDropDownList(bool bActivate) { | 288 void IFWL_ComboBox::OpenDropDownList(bool bActivate) { |
| 293 ShowDropList(bActivate); | 289 ShowDropList(bActivate); |
| 294 } | 290 } |
| 295 | 291 |
| 296 bool IFWL_ComboBox::EditCanUndo() { | 292 void IFWL_ComboBox::GetBBox(CFX_RectF& rect) const { |
| 297 return m_pEdit->CanUndo(); | |
| 298 } | |
| 299 | |
| 300 bool IFWL_ComboBox::EditCanRedo() { | |
| 301 return m_pEdit->CanRedo(); | |
| 302 } | |
| 303 | |
| 304 bool IFWL_ComboBox::EditUndo() { | |
| 305 return m_pEdit->Undo(); | |
| 306 } | |
| 307 | |
| 308 bool IFWL_ComboBox::EditRedo() { | |
| 309 return m_pEdit->Redo(); | |
| 310 } | |
| 311 | |
| 312 bool IFWL_ComboBox::EditCanCopy() { | |
| 313 return m_pEdit->CountSelRanges() > 0; | |
| 314 } | |
| 315 | |
| 316 bool IFWL_ComboBox::EditCanCut() { | |
| 317 if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) { | |
| 318 return false; | |
| 319 } | |
| 320 return m_pEdit->CountSelRanges() > 0; | |
| 321 } | |
| 322 | |
| 323 bool IFWL_ComboBox::EditCanSelectAll() { | |
| 324 return m_pEdit->GetTextLength() > 0; | |
| 325 } | |
| 326 | |
| 327 bool IFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { | |
| 328 return m_pEdit->Copy(wsCopy); | |
| 329 } | |
| 330 | |
| 331 bool IFWL_ComboBox::EditCut(CFX_WideString& wsCut) { | |
| 332 return m_pEdit->Cut(wsCut); | |
| 333 } | |
| 334 | |
| 335 bool IFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { | |
| 336 return m_pEdit->Paste(wsPaste); | |
| 337 } | |
| 338 | |
| 339 bool IFWL_ComboBox::EditSelectAll() { | |
| 340 m_pEdit->AddSelRange(0); | |
| 341 return true; | |
| 342 } | |
| 343 | |
| 344 bool IFWL_ComboBox::EditDelete() { | |
| 345 m_pEdit->ClearText(); | |
| 346 return true; | |
| 347 } | |
| 348 | |
| 349 bool IFWL_ComboBox::EditDeSelect() { | |
| 350 m_pEdit->ClearSelections(); | |
| 351 return true; | |
| 352 } | |
| 353 | |
| 354 void IFWL_ComboBox::GetBBox(CFX_RectF& rect) { | |
| 355 if (m_pWidgetMgr->IsFormDisabled()) { | 293 if (m_pWidgetMgr->IsFormDisabled()) { |
| 356 DisForm_GetBBox(rect); | 294 DisForm_GetBBox(rect); |
| 357 return; | 295 return; |
| 358 } | 296 } |
| 297 | |
| 359 rect = m_pProperties->m_rtWidget; | 298 rect = m_pProperties->m_rtWidget; |
| 360 if (m_pListBox && IsDropListVisible()) { | 299 if (!m_pListBox || !IsDropListVisible()) |
| 361 CFX_RectF rtList; | 300 return; |
| 362 m_pListBox->GetWidgetRect(rtList); | 301 |
| 363 rtList.Offset(rect.left, rect.top); | 302 CFX_RectF rtList; |
| 364 rect.Union(rtList); | 303 m_pListBox->GetWidgetRect(rtList); |
| 365 } | 304 rtList.Offset(rect.left, rect.top); |
| 305 rect.Union(rtList); | |
| 366 } | 306 } |
| 367 | 307 |
| 368 void IFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | 308 void IFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, |
| 369 uint32_t dwStylesExRemoved) { | 309 uint32_t dwStylesExRemoved) { |
| 370 if (m_pEdit) | 310 if (m_pEdit) |
| 371 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 311 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 372 } | 312 } |
| 373 | 313 |
| 374 FX_FLOAT IFWL_ComboBox::GetListHeight() { | 314 FX_FLOAT IFWL_ComboBox::GetListHeight() { |
| 375 return static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider) | 315 return static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider) |
| 376 ->GetListHeight(this); | 316 ->GetListHeight(this); |
| 377 } | 317 } |
| 378 | 318 |
| 379 void IFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, | 319 void IFWL_ComboBox::DrawStretchHandler(CFX_Graphics* pGraphics, |
| 380 const CFX_Matrix* pMatrix) { | 320 const CFX_Matrix* pMatrix) { |
| 381 CFWL_ThemeBackground param; | 321 CFWL_ThemeBackground param; |
| 382 param.m_pGraphics = pGraphics; | 322 param.m_pGraphics = pGraphics; |
| 383 param.m_iPart = CFWL_Part::StretchHandler; | 323 param.m_iPart = CFWL_Part::StretchHandler; |
| 384 param.m_dwStates = CFWL_PartState_Normal; | 324 param.m_dwStates = CFWL_PartState_Normal; |
| 385 param.m_pWidget = this; | 325 param.m_pWidget = this; |
| 386 if (pMatrix) { | 326 if (pMatrix) |
| 387 param.m_matrix.Concat(*pMatrix); | 327 param.m_matrix.Concat(*pMatrix); |
| 388 } | |
| 389 param.m_rtPart = m_rtHandler; | 328 param.m_rtPart = m_rtHandler; |
| 390 m_pProperties->m_pThemeProvider->DrawBackground(¶m); | 329 m_pProperties->m_pThemeProvider->DrawBackground(¶m); |
| 391 } | 330 } |
| 392 | 331 |
| 393 void IFWL_ComboBox::ShowDropList(bool bActivate) { | 332 void IFWL_ComboBox::ShowDropList(bool bActivate) { |
| 394 if (m_pWidgetMgr->IsFormDisabled()) | 333 if (m_pWidgetMgr->IsFormDisabled()) |
| 395 return DisForm_ShowDropList(bActivate); | 334 return DisForm_ShowDropList(bActivate); |
| 396 | 335 if (IsDropListVisible() == bActivate) |
| 397 bool bDropList = IsDropListVisible(); | |
| 398 if (bDropList == bActivate) | |
| 399 return; | 336 return; |
| 400 if (!m_pComboBoxProxy) | 337 if (!m_pComboBoxProxy) |
| 401 InitProxyForm(); | 338 InitProxyForm(); |
| 402 | 339 |
| 403 m_pComboBoxProxy->Reset(); | 340 m_pComboBoxProxy->Reset(); |
| 404 if (bActivate) { | 341 if (!bActivate) { |
| 405 m_pListBox->ChangeSelected(m_iCurSel); | |
| 406 ResetListItemAlignment(); | |
| 407 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & | |
| 408 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); | |
| 409 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); | |
| 410 m_pListBox->GetWidgetRect(m_rtList, true); | |
| 411 FX_FLOAT fHeight = GetListHeight(); | |
| 412 if (fHeight > 0) { | |
| 413 if (m_rtList.height > GetListHeight()) { | |
| 414 m_rtList.height = GetListHeight(); | |
| 415 m_pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll, 0); | |
| 416 } | |
| 417 } | |
| 418 CFX_RectF rtAnchor; | |
| 419 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 420 m_pProperties->m_rtWidget.height); | |
| 421 FX_FLOAT fMinHeight = 0; | |
| 422 if (m_rtList.width < m_rtClient.width) { | |
| 423 m_rtList.width = m_rtClient.width; | |
| 424 } | |
| 425 m_rtProxy = m_rtList; | |
| 426 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { | |
| 427 m_rtProxy.height += m_fComboFormHandler; | |
| 428 } | |
| 429 GetPopupPos(fMinHeight, m_rtProxy.height, rtAnchor, m_rtProxy); | |
| 430 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { | |
| 431 FX_FLOAT fx = 0; | |
| 432 FX_FLOAT fy = m_rtClient.top + m_rtClient.height / 2; | |
| 433 TransformTo(nullptr, fx, fy); | |
| 434 m_bUpFormHandler = fy > m_rtProxy.top; | |
| 435 if (m_bUpFormHandler) { | |
| 436 m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); | |
| 437 m_rtList.top = m_fComboFormHandler; | |
| 438 } else { | |
| 439 m_rtHandler.Set(0, m_rtList.height, m_rtList.width, | |
| 440 m_fComboFormHandler); | |
| 441 } | |
| 442 } | |
| 443 m_pComboBoxProxy->SetWidgetRect(m_rtProxy); | |
| 444 m_pComboBoxProxy->Update(); | |
| 445 m_pListBox->SetWidgetRect(m_rtList); | |
| 446 m_pListBox->Update(); | |
| 447 CFWL_EvtCmbPreDropDown ev; | |
| 448 ev.m_pSrcTarget = this; | |
| 449 DispatchEvent(&ev); | |
| 450 m_fItemHeight = m_pListBox->GetItemHeight(); | |
| 451 m_pListBox->SetFocus(true); | |
| 452 m_pComboBoxProxy->DoModal(); | |
| 453 m_pListBox->SetFocus(false); | |
| 454 } else { | |
| 455 m_pComboBoxProxy->EndDoModal(); | 342 m_pComboBoxProxy->EndDoModal(); |
| 343 | |
| 456 CFWL_EvtCmbCloseUp ev; | 344 CFWL_EvtCmbCloseUp ev; |
| 457 ev.m_pSrcTarget = this; | 345 ev.m_pSrcTarget = this; |
| 458 DispatchEvent(&ev); | 346 DispatchEvent(&ev); |
| 347 | |
| 459 m_bLButtonDown = false; | 348 m_bLButtonDown = false; |
| 460 m_pListBox->SetNotifyOwner(true); | 349 m_pListBox->SetNotifyOwner(true); |
| 461 SetFocus(true); | 350 SetFocus(true); |
| 351 return; | |
| 462 } | 352 } |
| 463 } | |
| 464 | 353 |
| 465 bool IFWL_ComboBox::IsDropListVisible() { | 354 m_pListBox->ChangeSelected(m_iCurSel); |
| 466 return m_pComboBoxProxy && | 355 ResetListItemAlignment(); |
| 467 !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); | 356 |
| 357 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & | |
| 358 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); | |
| 359 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); | |
| 360 m_pListBox->GetWidgetRect(m_rtList, true); | |
| 361 FX_FLOAT fHeight = GetListHeight(); | |
| 362 if (fHeight > 0 && m_rtList.height > GetListHeight()) { | |
| 363 m_rtList.height = GetListHeight(); | |
| 364 m_pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll, 0); | |
| 365 } | |
| 366 | |
| 367 CFX_RectF rtAnchor; | |
| 368 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 369 m_pProperties->m_rtWidget.height); | |
| 370 | |
| 371 m_rtList.width = std::max(m_rtList.width, m_rtClient.width); | |
| 372 m_rtProxy = m_rtList; | |
| 373 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) | |
| 374 m_rtProxy.height += m_fComboFormHandler; | |
| 375 | |
| 376 FX_FLOAT fMinHeight = 0; | |
| 377 GetPopupPos(fMinHeight, m_rtProxy.height, rtAnchor, m_rtProxy); | |
| 378 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { | |
| 379 FX_FLOAT fx = 0; | |
| 380 FX_FLOAT fy = m_rtClient.top + m_rtClient.height / 2; | |
| 381 TransformTo(nullptr, fx, fy); | |
| 382 | |
| 383 m_bUpFormHandler = fy > m_rtProxy.top; | |
| 384 if (m_bUpFormHandler) { | |
| 385 m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); | |
| 386 m_rtList.top = m_fComboFormHandler; | |
| 387 } else { | |
| 388 m_rtHandler.Set(0, m_rtList.height, m_rtList.width, m_fComboFormHandler); | |
| 389 } | |
| 390 } | |
| 391 m_pComboBoxProxy->SetWidgetRect(m_rtProxy); | |
| 392 m_pComboBoxProxy->Update(); | |
| 393 m_pListBox->SetWidgetRect(m_rtList); | |
| 394 m_pListBox->Update(); | |
| 395 | |
| 396 CFWL_EvtCmbPreDropDown ev; | |
| 397 ev.m_pSrcTarget = this; | |
| 398 DispatchEvent(&ev); | |
| 399 | |
| 400 m_fItemHeight = m_pListBox->GetItemHeight(); | |
| 401 m_pListBox->SetFocus(true); | |
| 402 m_pComboBoxProxy->DoModal(); | |
| 403 m_pListBox->SetFocus(false); | |
| 468 } | 404 } |
| 469 | 405 |
| 470 void IFWL_ComboBox::MatchEditText() { | 406 void IFWL_ComboBox::MatchEditText() { |
| 471 CFX_WideString wsText; | 407 CFX_WideString wsText; |
| 472 m_pEdit->GetText(wsText); | 408 m_pEdit->GetText(wsText); |
| 473 int32_t iMatch = m_pListBox->MatchItem(wsText); | 409 int32_t iMatch = m_pListBox->MatchItem(wsText); |
| 474 if (iMatch != m_iCurSel) { | 410 if (iMatch != m_iCurSel) { |
| 475 m_pListBox->ChangeSelected(iMatch); | 411 m_pListBox->ChangeSelected(iMatch); |
| 476 if (iMatch >= 0) { | 412 if (iMatch >= 0) |
| 477 SyncEditText(iMatch); | 413 SyncEditText(iMatch); |
| 478 } | |
| 479 } else if (iMatch >= 0) { | 414 } else if (iMatch >= 0) { |
| 480 m_pEdit->SetSelected(); | 415 m_pEdit->SetSelected(); |
| 481 } | 416 } |
| 482 m_iCurSel = iMatch; | 417 m_iCurSel = iMatch; |
| 483 } | 418 } |
| 484 | 419 |
| 485 void IFWL_ComboBox::SyncEditText(int32_t iListItem) { | 420 void IFWL_ComboBox::SyncEditText(int32_t iListItem) { |
| 486 CFX_WideString wsText; | 421 CFX_WideString wsText; |
| 487 IFWL_ComboBoxDP* pData = | 422 IFWL_ComboBoxDP* pData = |
| 488 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 423 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 489 CFWL_ListItem* hItem = pData->GetItem(this, iListItem); | 424 CFWL_ListItem* hItem = pData->GetItem(this, iListItem); |
| 490 m_pListBox->GetItemText(hItem, wsText); | 425 m_pListBox->GetItemText(hItem, wsText); |
| 491 m_pEdit->SetText(wsText); | 426 m_pEdit->SetText(wsText); |
| 492 m_pEdit->Update(); | 427 m_pEdit->Update(); |
| 493 m_pEdit->SetSelected(); | 428 m_pEdit->SetSelected(); |
| 494 } | 429 } |
| 495 | 430 |
| 496 void IFWL_ComboBox::Layout() { | 431 void IFWL_ComboBox::Layout() { |
| 497 if (m_pWidgetMgr->IsFormDisabled()) { | 432 if (m_pWidgetMgr->IsFormDisabled()) |
| 498 return DisForm_Layout(); | 433 return DisForm_Layout(); |
| 499 } | 434 |
| 500 GetClientRect(m_rtClient); | 435 GetClientRect(m_rtClient); |
| 501 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 436 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
| 502 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 437 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
| 503 if (!pFWidth) | 438 if (!pFWidth) |
| 504 return; | 439 return; |
| 440 | |
| 505 FX_FLOAT fBtn = *pFWidth; | 441 FX_FLOAT fBtn = *pFWidth; |
| 506 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, | 442 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, |
| 507 m_rtClient.height); | 443 m_rtClient.height); |
| 508 bool bIsDropDown = IsDropDownStyle(); | 444 if (!IsDropDownStyle() || !m_pEdit) |
| 509 if (bIsDropDown && m_pEdit) { | 445 return; |
| 510 CFX_RectF rtEdit; | 446 |
| 511 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, | 447 CFX_RectF rtEdit; |
| 512 m_rtClient.height); | 448 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, |
| 513 m_pEdit->SetWidgetRect(rtEdit); | 449 m_rtClient.height); |
| 514 if (m_iCurSel >= 0) { | 450 m_pEdit->SetWidgetRect(rtEdit); |
| 515 CFX_WideString wsText; | 451 |
| 516 IFWL_ComboBoxDP* pData = | 452 if (m_iCurSel >= 0) { |
| 517 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 453 CFX_WideString wsText; |
| 518 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 454 IFWL_ComboBoxDP* pData = |
| 519 m_pListBox->GetItemText(hItem, wsText); | 455 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 520 m_pEdit->LockUpdate(); | 456 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
| 521 m_pEdit->SetText(wsText); | 457 m_pListBox->GetItemText(hItem, wsText); |
| 522 m_pEdit->UnlockUpdate(); | 458 m_pEdit->LockUpdate(); |
| 523 } | 459 m_pEdit->SetText(wsText); |
| 524 m_pEdit->Update(); | 460 m_pEdit->UnlockUpdate(); |
| 525 } | 461 } |
| 462 m_pEdit->Update(); | |
| 526 } | 463 } |
| 527 | 464 |
| 528 void IFWL_ComboBox::ResetTheme() { | 465 void IFWL_ComboBox::ResetTheme() { |
| 529 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 466 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 530 if (!pTheme) { | 467 if (!pTheme) { |
| 531 pTheme = GetAvailableTheme(); | 468 pTheme = GetAvailableTheme(); |
| 532 m_pProperties->m_pThemeProvider = pTheme; | 469 m_pProperties->m_pThemeProvider = pTheme; |
| 533 } | 470 } |
| 534 if (m_pListBox && !m_pListBox->GetThemeProvider()) | 471 if (m_pListBox && !m_pListBox->GetThemeProvider()) |
| 535 m_pListBox->SetThemeProvider(pTheme); | 472 m_pListBox->SetThemeProvider(pTheme); |
| 536 if (m_pEdit && !m_pEdit->GetThemeProvider()) | 473 if (m_pEdit && !m_pEdit->GetThemeProvider()) |
| 537 m_pEdit->SetThemeProvider(pTheme); | 474 m_pEdit->SetThemeProvider(pTheme); |
| 538 } | 475 } |
| 539 | 476 |
| 540 void IFWL_ComboBox::ResetEditAlignment() { | 477 void IFWL_ComboBox::ResetEditAlignment() { |
| 541 if (!m_pEdit) | 478 if (!m_pEdit) |
| 542 return; | 479 return; |
| 543 uint32_t dwStylExes = m_pProperties->m_dwStyleExes; | 480 |
| 544 uint32_t dwAdd = 0; | 481 uint32_t dwAdd = 0; |
| 545 switch (dwStylExes & FWL_STYLEEXT_CMB_EditHAlignMask) { | 482 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditHAlignMask) { |
| 546 case FWL_STYLEEXT_CMB_EditHCenter: { | 483 case FWL_STYLEEXT_CMB_EditHCenter: { |
| 547 dwAdd |= FWL_STYLEEXT_EDT_HCenter; | 484 dwAdd |= FWL_STYLEEXT_EDT_HCenter; |
| 548 break; | 485 break; |
| 549 } | 486 } |
| 550 case FWL_STYLEEXT_CMB_EditHFar: { | 487 case FWL_STYLEEXT_CMB_EditHFar: { |
| 551 dwAdd |= FWL_STYLEEXT_EDT_HFar; | 488 dwAdd |= FWL_STYLEEXT_EDT_HFar; |
| 552 break; | 489 break; |
| 553 } | 490 } |
| 554 default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } | 491 default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } |
| 555 } | 492 } |
| 556 switch (dwStylExes & FWL_STYLEEXT_CMB_EditVAlignMask) { | 493 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditVAlignMask) { |
| 557 case FWL_STYLEEXT_CMB_EditVCenter: { | 494 case FWL_STYLEEXT_CMB_EditVCenter: { |
| 558 dwAdd |= FWL_STYLEEXT_EDT_VCenter; | 495 dwAdd |= FWL_STYLEEXT_EDT_VCenter; |
| 559 break; | 496 break; |
| 560 } | 497 } |
| 561 case FWL_STYLEEXT_CMB_EditVFar: { | 498 case FWL_STYLEEXT_CMB_EditVFar: { |
| 562 dwAdd |= FWL_STYLEEXT_EDT_VFar; | 499 dwAdd |= FWL_STYLEEXT_EDT_VFar; |
| 563 break; | 500 break; |
| 564 } | 501 } |
| 565 default: { dwAdd |= FWL_STYLEEXT_EDT_VNear; } | 502 default: { |
| 503 dwAdd |= FWL_STYLEEXT_EDT_VNear; | |
| 504 break; | |
| 505 } | |
| 566 } | 506 } |
| 567 if (dwStylExes & FWL_STYLEEXT_CMB_EditJustified) { | 507 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditJustified) |
| 568 dwAdd |= FWL_STYLEEXT_EDT_Justified; | 508 dwAdd |= FWL_STYLEEXT_EDT_Justified; |
| 569 } | 509 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditDistributed) |
| 570 if (dwStylExes & FWL_STYLEEXT_CMB_EditDistributed) { | |
| 571 dwAdd |= FWL_STYLEEXT_EDT_Distributed; | 510 dwAdd |= FWL_STYLEEXT_EDT_Distributed; |
| 572 } | 511 |
| 573 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | | 512 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | |
| 574 FWL_STYLEEXT_EDT_HAlignModeMask | | 513 FWL_STYLEEXT_EDT_HAlignModeMask | |
| 575 FWL_STYLEEXT_EDT_VAlignMask); | 514 FWL_STYLEEXT_EDT_VAlignMask); |
| 576 } | 515 } |
| 577 | 516 |
| 578 void IFWL_ComboBox::ResetListItemAlignment() { | 517 void IFWL_ComboBox::ResetListItemAlignment() { |
| 579 if (!m_pListBox) | 518 if (!m_pListBox) |
| 580 return; | 519 return; |
| 581 uint32_t dwStylExes = m_pProperties->m_dwStyleExes; | 520 |
| 582 uint32_t dwAdd = 0; | 521 uint32_t dwAdd = 0; |
| 583 switch (dwStylExes & FWL_STYLEEXT_CMB_ListItemAlignMask) { | 522 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemAlignMask) { |
| 584 case FWL_STYLEEXT_CMB_ListItemCenterAlign: { | 523 case FWL_STYLEEXT_CMB_ListItemCenterAlign: { |
| 585 dwAdd |= FWL_STYLEEXT_LTB_CenterAlign; | 524 dwAdd |= FWL_STYLEEXT_LTB_CenterAlign; |
| 525 break; | |
| 586 } | 526 } |
| 587 case FWL_STYLEEXT_CMB_ListItemRightAlign: { | 527 case FWL_STYLEEXT_CMB_ListItemRightAlign: { |
| 588 dwAdd |= FWL_STYLEEXT_LTB_RightAlign; | 528 dwAdd |= FWL_STYLEEXT_LTB_RightAlign; |
| 529 break; | |
| 589 } | 530 } |
| 590 default: { dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; } | 531 default: { |
| 532 dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; | |
| 533 break; | |
| 534 } | |
| 591 } | 535 } |
| 592 m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); | 536 m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); |
| 593 } | 537 } |
| 594 | 538 |
| 595 void IFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { | 539 void IFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { |
| 596 IFWL_ComboBoxDP* pDatas = | 540 IFWL_ComboBoxDP* pDatas = |
| 597 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 541 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 598 m_iCurSel = pDatas->GetItemIndex(this, m_pListBox->GetSelItem(0)); | 542 m_iCurSel = pDatas->GetItemIndex(this, m_pListBox->GetSelItem(0)); |
| 599 bool bDropDown = IsDropDownStyle(); | 543 if (!IsDropDownStyle()) { |
| 600 if (bDropDown) { | |
| 601 IFWL_ComboBoxDP* pData = | |
| 602 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 603 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | |
| 604 if (hItem) { | |
| 605 CFX_WideString wsText; | |
| 606 pData->GetItemText(this, hItem, wsText); | |
| 607 if (m_pEdit) { | |
| 608 m_pEdit->SetText(wsText); | |
| 609 m_pEdit->Update(); | |
| 610 m_pEdit->SetSelected(); | |
| 611 } | |
| 612 CFWL_EvtCmbSelChanged ev; | |
| 613 ev.bLButtonUp = bLButtonUp; | |
| 614 ev.m_pSrcTarget = this; | |
| 615 ev.iArraySels.Add(m_iCurSel); | |
| 616 DispatchEvent(&ev); | |
| 617 } | |
| 618 } else { | |
| 619 Repaint(&m_rtClient); | 544 Repaint(&m_rtClient); |
| 545 return; | |
| 620 } | 546 } |
| 547 | |
| 548 IFWL_ComboBoxDP* pData = | |
| 549 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 550 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | |
| 551 if (!hItem) | |
| 552 return; | |
| 553 | |
| 554 CFX_WideString wsText; | |
| 555 pData->GetItemText(this, hItem, wsText); | |
| 556 if (m_pEdit) { | |
| 557 m_pEdit->SetText(wsText); | |
| 558 m_pEdit->Update(); | |
| 559 m_pEdit->SetSelected(); | |
| 560 } | |
| 561 | |
| 562 CFWL_EvtCmbSelChanged ev; | |
| 563 ev.bLButtonUp = bLButtonUp; | |
| 564 ev.m_pSrcTarget = this; | |
| 565 ev.iArraySels.Add(m_iCurSel); | |
| 566 DispatchEvent(&ev); | |
| 621 } | 567 } |
| 622 | 568 |
| 623 void IFWL_ComboBox::InitProxyForm() { | 569 void IFWL_ComboBox::InitProxyForm() { |
| 624 if (m_pComboBoxProxy) | 570 if (m_pComboBoxProxy) |
| 625 return; | 571 return; |
| 626 if (!m_pListBox) | 572 if (!m_pListBox) |
| 627 return; | 573 return; |
| 628 | 574 |
| 629 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 575 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
| 630 prop->m_pOwner = this; | 576 prop->m_pOwner = this; |
| 631 prop->m_dwStyles = FWL_WGTSTYLE_Popup; | 577 prop->m_dwStyles = FWL_WGTSTYLE_Popup; |
| 632 prop->m_dwStates = FWL_WGTSTATE_Invisible; | 578 prop->m_dwStates = FWL_WGTSTATE_Invisible; |
| 633 | 579 |
| 580 // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure | |
| 581 // if the SetParent call is going to transfer ownership. | |
| 634 m_pComboBoxProxy = new IFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), | 582 m_pComboBoxProxy = new IFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), |
| 635 m_pListBox.get()); | 583 m_pListBox.get()); |
| 636 m_pListBox->SetParent(m_pComboBoxProxy); | 584 m_pListBox->SetParent(m_pComboBoxProxy); |
| 637 } | 585 } |
| 638 | 586 |
| 639 void IFWL_ComboBox::DisForm_InitComboList() { | 587 void IFWL_ComboBox::DisForm_InitComboList() { |
| 640 if (m_pListBox) | 588 if (m_pListBox) |
| 641 return; | 589 return; |
| 642 | 590 |
| 643 auto prop = | 591 auto prop = |
| 644 pdfium::MakeUnique<CFWL_WidgetProperties>(m_pProperties->m_pDataProvider); | 592 pdfium::MakeUnique<CFWL_WidgetProperties>(m_pProperties->m_pDataProvider); |
| 645 prop->m_pParent = this; | 593 prop->m_pParent = this; |
| 646 prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | 594 prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
| 647 prop->m_dwStates = FWL_WGTSTATE_Invisible; | 595 prop->m_dwStates = FWL_WGTSTATE_Invisible; |
| 648 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 596 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
| 649 m_pListBox.reset(new IFWL_ComboList(m_pOwnerApp, std::move(prop), this)); | 597 |
| 598 m_pListBox = | |
| 599 pdfium::MakeUnique<IFWL_ComboList>(m_pOwnerApp, std::move(prop), this); | |
| 650 } | 600 } |
| 651 | 601 |
| 652 void IFWL_ComboBox::DisForm_InitComboEdit() { | 602 void IFWL_ComboBox::DisForm_InitComboEdit() { |
| 653 if (m_pEdit) | 603 if (m_pEdit) |
| 654 return; | 604 return; |
| 655 | 605 |
| 656 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 606 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
| 657 prop->m_pParent = this; | 607 prop->m_pParent = this; |
| 658 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 608 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
| 659 m_pEdit.reset(new IFWL_ComboEdit(m_pOwnerApp, std::move(prop), this)); | 609 |
| 610 m_pEdit = | |
| 611 pdfium::MakeUnique<IFWL_ComboEdit>(m_pOwnerApp, std::move(prop), this); | |
| 660 m_pEdit->SetOuter(this); | 612 m_pEdit->SetOuter(this); |
| 661 } | 613 } |
| 662 | 614 |
| 663 void IFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { | 615 void IFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { |
| 664 bool bDropList = DisForm_IsDropListVisible(); | 616 if (DisForm_IsDropListVisible() == bActivate) |
| 665 if (bDropList == bActivate) { | |
| 666 return; | 617 return; |
| 667 } | 618 |
| 668 if (bActivate) { | 619 if (bActivate) { |
| 669 CFWL_EvtCmbPreDropDown preEvent; | 620 CFWL_EvtCmbPreDropDown preEvent; |
| 670 preEvent.m_pSrcTarget = this; | 621 preEvent.m_pSrcTarget = this; |
| 671 DispatchEvent(&preEvent); | 622 DispatchEvent(&preEvent); |
| 623 | |
| 672 IFWL_ComboList* pComboList = m_pListBox.get(); | 624 IFWL_ComboList* pComboList = m_pListBox.get(); |
| 673 int32_t iItems = pComboList->CountItems(); | 625 int32_t iItems = pComboList->CountItems(); |
| 674 if (iItems < 1) { | 626 if (iItems < 1) |
| 675 return; | 627 return; |
| 676 } | 628 |
| 677 ResetListItemAlignment(); | 629 ResetListItemAlignment(); |
| 678 pComboList->ChangeSelected(m_iCurSel); | 630 pComboList->ChangeSelected(m_iCurSel); |
| 631 | |
| 679 FX_FLOAT fItemHeight = pComboList->CalcItemHeight(); | 632 FX_FLOAT fItemHeight = pComboList->CalcItemHeight(); |
| 680 FX_FLOAT fBorder = GetBorderSize(); | 633 FX_FLOAT fBorder = GetBorderSize(); |
| 681 FX_FLOAT fPopupMin = 0.0f; | 634 FX_FLOAT fPopupMin = 0.0f; |
| 682 if (iItems > 3) { | 635 if (iItems > 3) |
| 683 fPopupMin = fItemHeight * 3 + fBorder * 2; | 636 fPopupMin = fItemHeight * 3 + fBorder * 2; |
| 684 } | 637 |
| 685 FX_FLOAT fPopupMax = fItemHeight * iItems + fBorder * 2; | 638 FX_FLOAT fPopupMax = fItemHeight * iItems + fBorder * 2; |
| 686 CFX_RectF rtList; | 639 CFX_RectF rtList; |
| 687 rtList.left = m_rtClient.left; | 640 rtList.left = m_rtClient.left; |
| 688 rtList.width = m_pProperties->m_rtWidget.width; | 641 rtList.width = m_pProperties->m_rtWidget.width; |
| 689 rtList.top = 0; | 642 rtList.top = 0; |
| 690 rtList.height = 0; | 643 rtList.height = 0; |
| 691 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); | 644 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); |
| 645 | |
| 692 m_pListBox->SetWidgetRect(rtList); | 646 m_pListBox->SetWidgetRect(rtList); |
| 693 m_pListBox->Update(); | 647 m_pListBox->Update(); |
| 694 } else { | 648 } else { |
| 695 SetFocus(true); | 649 SetFocus(true); |
| 696 } | 650 } |
| 651 | |
| 697 m_pListBox->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | 652 m_pListBox->SetStates(FWL_WGTSTATE_Invisible, !bActivate); |
| 698 if (bActivate) { | 653 if (bActivate) { |
| 699 CFWL_EvtCmbPostDropDown postEvent; | 654 CFWL_EvtCmbPostDropDown postEvent; |
| 700 postEvent.m_pSrcTarget = this; | 655 postEvent.m_pSrcTarget = this; |
| 701 DispatchEvent(&postEvent); | 656 DispatchEvent(&postEvent); |
| 702 } | 657 } |
| 658 | |
| 703 CFX_RectF rect; | 659 CFX_RectF rect; |
| 704 m_pListBox->GetWidgetRect(rect); | 660 m_pListBox->GetWidgetRect(rect); |
| 705 rect.Inflate(2, 2); | 661 rect.Inflate(2, 2); |
| 706 Repaint(&rect); | 662 Repaint(&rect); |
| 707 } | 663 } |
| 708 | 664 |
| 709 void IFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | 665 void IFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, |
| 710 uint32_t dwStylesExRemoved) { | 666 uint32_t dwStylesExRemoved) { |
| 711 if (!m_pEdit) | 667 if (!m_pEdit) |
| 712 DisForm_InitComboEdit(); | 668 DisForm_InitComboEdit(); |
| 713 | 669 |
| 714 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 670 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
| 715 bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); | 671 bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); |
| 672 | |
| 716 dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown; | 673 dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown; |
| 717 m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown; | 674 m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown; |
| 718 if (bAddDropDown) { | 675 |
| 676 if (bAddDropDown) | |
| 719 m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly); | 677 m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly); |
| 720 } else if (bDelDropDown) { | 678 else if (bDelDropDown) |
| 721 m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0); | 679 m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0); |
| 722 } | |
| 723 IFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 680 IFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 724 } | 681 } |
| 725 | 682 |
| 726 void IFWL_ComboBox::DisForm_Update() { | 683 void IFWL_ComboBox::DisForm_Update() { |
| 727 if (m_iLock) { | 684 if (m_iLock) |
| 728 return; | 685 return; |
| 729 } | 686 if (m_pEdit) |
| 730 if (m_pEdit) { | |
| 731 ResetEditAlignment(); | 687 ResetEditAlignment(); |
| 732 } | |
| 733 ResetTheme(); | 688 ResetTheme(); |
| 734 Layout(); | 689 Layout(); |
| 735 } | 690 } |
| 736 | 691 |
| 737 FWL_WidgetHit IFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 692 FWL_WidgetHit IFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 738 CFX_RectF rect; | 693 CFX_RectF rect; |
| 739 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, | 694 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, |
| 740 m_pProperties->m_rtWidget.height); | 695 m_pProperties->m_rtWidget.height); |
| 741 if (rect.Contains(fx, fy)) | 696 if (rect.Contains(fx, fy)) |
| 742 return FWL_WidgetHit::Edit; | 697 return FWL_WidgetHit::Edit; |
| 743 if (m_rtBtn.Contains(fx, fy)) | 698 if (m_rtBtn.Contains(fx, fy)) |
| 744 return FWL_WidgetHit::Client; | 699 return FWL_WidgetHit::Client; |
| 745 if (DisForm_IsDropListVisible()) { | 700 if (DisForm_IsDropListVisible()) { |
| 746 m_pListBox->GetWidgetRect(rect); | 701 m_pListBox->GetWidgetRect(rect); |
| 747 if (rect.Contains(fx, fy)) | 702 if (rect.Contains(fx, fy)) |
| 748 return FWL_WidgetHit::Client; | 703 return FWL_WidgetHit::Client; |
| 749 } | 704 } |
| 750 return FWL_WidgetHit::Unknown; | 705 return FWL_WidgetHit::Unknown; |
| 751 } | 706 } |
| 752 | 707 |
| 753 void IFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, | 708 void IFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, |
| 754 const CFX_Matrix* pMatrix) { | 709 const CFX_Matrix* pMatrix) { |
| 755 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 710 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 756 CFX_Matrix mtOrg; | 711 CFX_Matrix mtOrg; |
| 757 mtOrg.Set(1, 0, 0, 1, 0, 0); | 712 mtOrg.Set(1, 0, 0, 1, 0, 0); |
| 758 if (pMatrix) { | 713 if (pMatrix) |
| 759 mtOrg = *pMatrix; | 714 mtOrg = *pMatrix; |
| 760 } | 715 |
| 761 bool bListShowed = m_pListBox && DisForm_IsDropListVisible(); | |
| 762 pGraphics->SaveGraphState(); | 716 pGraphics->SaveGraphState(); |
| 763 pGraphics->ConcatMatrix(&mtOrg); | 717 pGraphics->ConcatMatrix(&mtOrg); |
| 764 if (!m_rtBtn.IsEmpty(0.1f)) { | 718 if (!m_rtBtn.IsEmpty(0.1f)) { |
| 765 CFWL_ThemeBackground param; | 719 CFWL_ThemeBackground param; |
| 766 param.m_pWidget = this; | 720 param.m_pWidget = this; |
| 767 param.m_iPart = CFWL_Part::DropDownButton; | 721 param.m_iPart = CFWL_Part::DropDownButton; |
| 768 param.m_dwStates = m_iBtnState; | 722 param.m_dwStates = m_iBtnState; |
| 769 param.m_pGraphics = pGraphics; | 723 param.m_pGraphics = pGraphics; |
| 770 param.m_rtPart = m_rtBtn; | 724 param.m_rtPart = m_rtBtn; |
| 771 pTheme->DrawBackground(¶m); | 725 pTheme->DrawBackground(¶m); |
| 772 } | 726 } |
| 773 pGraphics->RestoreGraphState(); | 727 pGraphics->RestoreGraphState(); |
| 728 | |
| 774 if (m_pEdit) { | 729 if (m_pEdit) { |
| 775 CFX_RectF rtEdit; | 730 CFX_RectF rtEdit; |
| 776 m_pEdit->GetWidgetRect(rtEdit); | 731 m_pEdit->GetWidgetRect(rtEdit); |
| 777 CFX_Matrix mt; | 732 CFX_Matrix mt; |
| 778 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); | 733 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); |
| 779 mt.Concat(mtOrg); | 734 mt.Concat(mtOrg); |
| 780 m_pEdit->DrawWidget(pGraphics, &mt); | 735 m_pEdit->DrawWidget(pGraphics, &mt); |
| 781 } | 736 } |
| 782 if (bListShowed) { | 737 if (m_pListBox && DisForm_IsDropListVisible()) { |
| 783 CFX_RectF rtList; | 738 CFX_RectF rtList; |
| 784 m_pListBox->GetWidgetRect(rtList); | 739 m_pListBox->GetWidgetRect(rtList); |
| 785 CFX_Matrix mt; | 740 CFX_Matrix mt; |
| 786 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); | 741 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); |
| 787 mt.Concat(mtOrg); | 742 mt.Concat(mtOrg); |
| 788 m_pListBox->DrawWidget(pGraphics, &mt); | 743 m_pListBox->DrawWidget(pGraphics, &mt); |
| 789 } | 744 } |
| 790 } | 745 } |
| 791 | 746 |
| 792 void IFWL_ComboBox::DisForm_GetBBox(CFX_RectF& rect) { | 747 void IFWL_ComboBox::DisForm_GetBBox(CFX_RectF& rect) const { |
| 793 rect = m_pProperties->m_rtWidget; | 748 rect = m_pProperties->m_rtWidget; |
| 794 if (m_pListBox && DisForm_IsDropListVisible()) { | 749 if (!m_pListBox || !DisForm_IsDropListVisible()) |
| 795 CFX_RectF rtList; | 750 return; |
| 796 m_pListBox->GetWidgetRect(rtList); | 751 |
| 797 rtList.Offset(rect.left, rect.top); | 752 CFX_RectF rtList; |
| 798 rect.Union(rtList); | 753 m_pListBox->GetWidgetRect(rtList); |
| 799 } | 754 rtList.Offset(rect.left, rect.top); |
| 755 rect.Union(rtList); | |
| 800 } | 756 } |
| 801 | 757 |
| 802 void IFWL_ComboBox::DisForm_Layout() { | 758 void IFWL_ComboBox::DisForm_Layout() { |
| 803 GetClientRect(m_rtClient); | 759 GetClientRect(m_rtClient); |
| 804 m_rtContent = m_rtClient; | 760 m_rtContent = m_rtClient; |
| 805 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 761 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
| 806 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 762 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
| 807 if (!pFWidth) | 763 if (!pFWidth) |
| 808 return; | 764 return; |
| 765 | |
| 809 FX_FLOAT borderWidth = 1; | 766 FX_FLOAT borderWidth = 1; |
| 810 FX_FLOAT fBtn = *pFWidth; | 767 FX_FLOAT fBtn = *pFWidth; |
| 811 if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { | 768 if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { |
| 812 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, | 769 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, |
| 813 fBtn - borderWidth, m_rtClient.height - 2 * borderWidth); | 770 fBtn - borderWidth, m_rtClient.height - 2 * borderWidth); |
| 814 } | 771 } |
| 772 | |
| 815 CFX_RectF* pUIMargin = | 773 CFX_RectF* pUIMargin = |
| 816 static_cast<CFX_RectF*>(GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); | 774 static_cast<CFX_RectF*>(GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); |
| 817 if (pUIMargin) { | 775 if (pUIMargin) { |
| 818 m_rtContent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | 776 m_rtContent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, |
| 819 pUIMargin->height); | 777 pUIMargin->height); |
| 820 } | 778 } |
| 821 bool bIsDropDown = IsDropDownStyle(); | 779 |
| 822 if (bIsDropDown && m_pEdit) { | 780 if (!IsDropDownStyle() || !m_pEdit) |
| 823 CFX_RectF rtEdit; | 781 return; |
| 824 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, | 782 |
| 825 m_rtContent.height); | 783 CFX_RectF rtEdit; |
| 826 m_pEdit->SetWidgetRect(rtEdit); | 784 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, |
| 827 if (m_iCurSel >= 0) { | 785 m_rtContent.height); |
| 828 CFX_WideString wsText; | 786 m_pEdit->SetWidgetRect(rtEdit); |
| 829 IFWL_ComboBoxDP* pData = | 787 |
| 830 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 788 if (m_iCurSel >= 0) { |
| 831 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 789 CFX_WideString wsText; |
| 832 m_pListBox->GetItemText(hItem, wsText); | 790 IFWL_ComboBoxDP* pData = |
| 833 m_pEdit->LockUpdate(); | 791 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
| 834 m_pEdit->SetText(wsText); | 792 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
| 835 m_pEdit->UnlockUpdate(); | 793 m_pListBox->GetItemText(hItem, wsText); |
| 836 } | 794 m_pEdit->LockUpdate(); |
| 837 m_pEdit->Update(); | 795 m_pEdit->SetText(wsText); |
| 796 m_pEdit->UnlockUpdate(); | |
| 838 } | 797 } |
| 798 m_pEdit->Update(); | |
| 839 } | 799 } |
| 840 | 800 |
| 841 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { | 801 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { |
| 842 if (m_pWidgetMgr->IsFormDisabled()) { | 802 if (m_pWidgetMgr->IsFormDisabled()) { |
| 843 DisForm_OnProcessMessage(pMessage); | 803 DisForm_OnProcessMessage(pMessage); |
| 844 return; | 804 return; |
| 845 } | 805 } |
| 846 if (!pMessage) | 806 if (!pMessage) |
| 847 return; | 807 return; |
| 848 | 808 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 DispatchEvent(&pTemp); | 872 DispatchEvent(&pTemp); |
| 913 } | 873 } |
| 914 } | 874 } |
| 915 | 875 |
| 916 void IFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, | 876 void IFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, |
| 917 const CFX_Matrix* pMatrix) { | 877 const CFX_Matrix* pMatrix) { |
| 918 DrawWidget(pGraphics, pMatrix); | 878 DrawWidget(pGraphics, pMatrix); |
| 919 } | 879 } |
| 920 | 880 |
| 921 void IFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { | 881 void IFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
| 922 IFWL_Widget* pDstTarget = pMsg->m_pDstTarget; | |
| 923 IFWL_Widget* pSrcTarget = pMsg->m_pSrcTarget; | |
| 924 bool bDropDown = IsDropDownStyle(); | |
| 925 if (bSet) { | 882 if (bSet) { |
| 926 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 883 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 927 if (bDropDown && pSrcTarget != m_pListBox.get()) { | 884 if (IsDropDownStyle() && pMsg->m_pSrcTarget != m_pListBox.get()) { |
| 928 if (!m_pEdit) | 885 if (!m_pEdit) |
| 929 return; | 886 return; |
| 930 m_pEdit->SetSelected(); | 887 m_pEdit->SetSelected(); |
| 931 } else { | 888 return; |
| 932 Repaint(&m_rtClient); | |
| 933 } | 889 } |
| 934 } else { | 890 |
| 935 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 891 Repaint(&m_rtClient); |
| 936 if (bDropDown && pDstTarget != m_pListBox.get()) { | 892 return; |
| 937 if (!m_pEdit) | |
| 938 return; | |
| 939 m_pEdit->FlagFocus(false); | |
| 940 m_pEdit->ClearSelected(); | |
| 941 } else { | |
| 942 Repaint(&m_rtClient); | |
| 943 } | |
| 944 } | 893 } |
| 894 | |
| 895 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 896 if (IsDropDownStyle() && pMsg->m_pDstTarget != m_pListBox.get()) { | |
| 897 if (!m_pEdit) | |
| 898 return; | |
| 899 m_pEdit->FlagFocus(false); | |
| 900 m_pEdit->ClearSelected(); | |
| 901 return; | |
| 902 } | |
| 903 | |
| 904 Repaint(&m_rtClient); | |
|
npm
2016/11/16 18:37:57
nit: you could make this be in the if instead of t
dsinclair
2016/11/16 18:57:14
Done.
| |
| 945 } | 905 } |
| 946 | 906 |
| 947 void IFWL_ComboBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 907 void IFWL_ComboBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| 948 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 908 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 949 return; | 909 return; |
| 950 | 910 |
| 951 bool bDropDown = IsDropDownStyle(); | 911 CFX_RectF& rtBtn = IsDropDownStyle() ? m_rtBtn : m_rtClient; |
| 952 CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient; | 912 if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 953 bool bClickBtn = rtBtn.Contains(pMsg->m_fx, pMsg->m_fy); | |
| 954 if (!bClickBtn) | |
| 955 return; | 913 return; |
| 956 | 914 |
| 957 if (bDropDown && m_pEdit) | 915 if (IsDropDownStyle() && m_pEdit) |
| 958 MatchEditText(); | 916 MatchEditText(); |
| 959 | 917 |
| 960 m_bLButtonDown = true; | 918 m_bLButtonDown = true; |
| 961 m_iBtnState = CFWL_PartState_Pressed; | 919 m_iBtnState = CFWL_PartState_Pressed; |
| 962 Repaint(&m_rtClient); | 920 Repaint(&m_rtClient); |
| 921 | |
| 963 ShowDropList(true); | 922 ShowDropList(true); |
| 964 m_iBtnState = CFWL_PartState_Normal; | 923 m_iBtnState = CFWL_PartState_Normal; |
| 965 Repaint(&m_rtClient); | 924 Repaint(&m_rtClient); |
| 966 } | 925 } |
| 967 | 926 |
| 968 void IFWL_ComboBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 927 void IFWL_ComboBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
| 969 m_bLButtonDown = false; | 928 m_bLButtonDown = false; |
| 970 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) | 929 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 971 m_iBtnState = CFWL_PartState_Hovered; | 930 m_iBtnState = CFWL_PartState_Hovered; |
| 972 else | 931 else |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 iCurSel++; | 1004 iCurSel++; |
| 1046 } | 1005 } |
| 1047 m_iCurSel = iCurSel; | 1006 m_iCurSel = iCurSel; |
| 1048 if (bDropDown && m_pEdit) | 1007 if (bDropDown && m_pEdit) |
| 1049 SyncEditText(m_iCurSel); | 1008 SyncEditText(m_iCurSel); |
| 1050 else | 1009 else |
| 1051 Repaint(&m_rtClient); | 1010 Repaint(&m_rtClient); |
| 1052 return; | 1011 return; |
| 1053 } | 1012 } |
| 1054 | 1013 |
| 1055 bool bDropDown = IsDropDownStyle(); | 1014 if (IsDropDownStyle()) |
| 1056 if (bDropDown) | |
| 1057 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1015 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
| 1058 } | 1016 } |
| 1059 | 1017 |
| 1060 void IFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { | 1018 void IFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { |
| 1061 if (!pMessage) | 1019 if (!pMessage) |
| 1062 return; | 1020 return; |
| 1063 | 1021 |
| 1064 bool backDefault = true; | 1022 bool backDefault = true; |
| 1065 switch (pMessage->GetClassID()) { | 1023 switch (pMessage->GetClassID()) { |
| 1066 case CFWL_MessageType::SetFocus: { | 1024 case CFWL_MessageType::SetFocus: { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 else | 1139 else |
| 1182 iCurSel++; | 1140 iCurSel++; |
| 1183 } | 1141 } |
| 1184 m_iCurSel = iCurSel; | 1142 m_iCurSel = iCurSel; |
| 1185 SyncEditText(m_iCurSel); | 1143 SyncEditText(m_iCurSel); |
| 1186 return; | 1144 return; |
| 1187 } | 1145 } |
| 1188 if (m_pEdit) | 1146 if (m_pEdit) |
| 1189 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1147 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
| 1190 } | 1148 } |
| OLD | NEW |