| 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/cfwl_combobox.h" | 7 #include "xfa/fwl/core/cfwl_combobox.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "xfa/fwl/core/fwl_error.h" | 11 #include "xfa/fwl/core/fwl_error.h" |
| 12 #include "xfa/fwl/core/ifwl_widget.h" | 12 #include "xfa/fwl/core/ifwl_widget.h" |
| 13 | 13 |
| 14 namespace { |
| 15 |
| 16 IFWL_ComboBox* ToComboBox(IFWL_Widget* widget) { |
| 17 return static_cast<IFWL_ComboBox*>(widget); |
| 18 } |
| 19 |
| 20 const IFWL_ComboBox* ToComboBox(const IFWL_Widget* widget) { |
| 21 return static_cast<const IFWL_ComboBox*>(widget); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 14 CFWL_ComboBox::CFWL_ComboBox(const IFWL_App* app) : CFWL_Widget(app) {} | 26 CFWL_ComboBox::CFWL_ComboBox(const IFWL_App* app) : CFWL_Widget(app) {} |
| 15 | 27 |
| 16 CFWL_ComboBox::~CFWL_ComboBox() {} | 28 CFWL_ComboBox::~CFWL_ComboBox() {} |
| 17 | 29 |
| 18 void CFWL_ComboBox::Initialize() { | 30 void CFWL_ComboBox::Initialize() { |
| 19 ASSERT(!m_pIface); | 31 ASSERT(!m_pIface); |
| 20 | 32 |
| 21 std::unique_ptr<IFWL_ComboBox> pComboBox(new IFWL_ComboBox( | 33 std::unique_ptr<IFWL_ComboBox> pComboBox(new IFWL_ComboBox( |
| 22 m_pApp, m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); | 34 m_pApp, m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); |
| 23 pComboBox->Initialize(); | 35 pComboBox->Initialize(); |
| 24 | 36 |
| 25 m_pIface = std::move(pComboBox); | 37 m_pIface = std::move(pComboBox); |
| 26 CFWL_Widget::Initialize(); | 38 CFWL_Widget::Initialize(); |
| 27 } | 39 } |
| 28 | 40 |
| 29 IFWL_ComboBox* CFWL_ComboBox::GetWidget() { | |
| 30 return static_cast<IFWL_ComboBox*>(m_pIface.get()); | |
| 31 } | |
| 32 | |
| 33 const IFWL_ComboBox* CFWL_ComboBox::GetWidget() const { | |
| 34 return static_cast<IFWL_ComboBox*>(m_pIface.get()); | |
| 35 } | |
| 36 | |
| 37 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { | 41 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { |
| 38 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); | 42 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); |
| 39 pItem->m_wsText = wsText; | 43 pItem->m_wsText = wsText; |
| 40 pItem->m_dwStyles = 0; | 44 pItem->m_dwStyles = 0; |
| 41 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); | 45 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); |
| 42 return m_comboBoxData.m_ItemArray.size() - 1; | 46 return m_comboBoxData.m_ItemArray.size() - 1; |
| 43 } | 47 } |
| 44 | 48 |
| 45 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText, | 49 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText, |
| 46 CFX_DIBitmap* pIcon) { | 50 CFX_DIBitmap* pIcon) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 CFX_WideString& wsText) { | 77 CFX_WideString& wsText) { |
| 74 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( | 78 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( |
| 75 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); | 79 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); |
| 76 if (!pItem) | 80 if (!pItem) |
| 77 return FWL_Error::Indefinite; | 81 return FWL_Error::Indefinite; |
| 78 wsText = pItem->m_wsText; | 82 wsText = pItem->m_wsText; |
| 79 return FWL_Error::Succeeded; | 83 return FWL_Error::Succeeded; |
| 80 } | 84 } |
| 81 | 85 |
| 82 int32_t CFWL_ComboBox::GetCurSel() { | 86 int32_t CFWL_ComboBox::GetCurSel() { |
| 83 return GetWidget() ? GetWidget()->GetCurSel() : -1; | 87 return GetWidget() ? ToComboBox(GetWidget())->GetCurSel() : -1; |
| 84 } | 88 } |
| 85 | 89 |
| 86 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) { | 90 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) { |
| 87 return GetWidget() ? GetWidget()->SetCurSel(iSel) : FWL_Error::Indefinite; | 91 return GetWidget() ? ToComboBox(GetWidget())->SetCurSel(iSel) |
| 92 : FWL_Error::Indefinite; |
| 88 } | 93 } |
| 89 | 94 |
| 90 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { | 95 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { |
| 91 return GetWidget() ? GetWidget()->SetEditText(wsText) : FWL_Error::Indefinite; | 96 return GetWidget() ? ToComboBox(GetWidget())->SetEditText(wsText) |
| 97 : FWL_Error::Indefinite; |
| 92 } | 98 } |
| 93 | 99 |
| 94 int32_t CFWL_ComboBox::GetEditTextLength() const { | 100 int32_t CFWL_ComboBox::GetEditTextLength() const { |
| 95 return GetWidget() ? GetWidget()->GetEditTextLength() : 0; | 101 return GetWidget() ? ToComboBox(GetWidget())->GetEditTextLength() : 0; |
| 96 } | 102 } |
| 97 | 103 |
| 98 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText, | 104 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText, |
| 99 int32_t nStart, | 105 int32_t nStart, |
| 100 int32_t nCount) const { | 106 int32_t nCount) const { |
| 101 return GetWidget() ? GetWidget()->GetEditText(wsText, nStart, nCount) | 107 return GetWidget() |
| 102 : FWL_Error::Indefinite; | 108 ? ToComboBox(GetWidget())->GetEditText(wsText, nStart, nCount) |
| 109 : FWL_Error::Indefinite; |
| 103 } | 110 } |
| 104 | 111 |
| 105 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { | 112 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { |
| 106 return GetWidget() ? GetWidget()->SetEditSelRange(nStart, nCount) | 113 return GetWidget() ? ToComboBox(GetWidget())->SetEditSelRange(nStart, nCount) |
| 107 : FWL_Error::Indefinite; | 114 : FWL_Error::Indefinite; |
| 108 } | 115 } |
| 109 | 116 |
| 110 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { | 117 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { |
| 111 return GetWidget() ? GetWidget()->GetEditSelRange(nIndex, nStart) : 0; | 118 return GetWidget() ? ToComboBox(GetWidget())->GetEditSelRange(nIndex, nStart) |
| 119 : 0; |
| 112 } | 120 } |
| 113 | 121 |
| 114 int32_t CFWL_ComboBox::GetEditLimit() { | 122 int32_t CFWL_ComboBox::GetEditLimit() { |
| 115 return GetWidget() ? GetWidget()->GetEditLimit() : 0; | 123 return GetWidget() ? ToComboBox(GetWidget())->GetEditLimit() : 0; |
| 116 } | 124 } |
| 117 | 125 |
| 118 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) { | 126 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) { |
| 119 return GetWidget() ? GetWidget()->SetEditLimit(nLimit) | 127 return GetWidget() ? ToComboBox(GetWidget())->SetEditLimit(nLimit) |
| 120 : FWL_Error::Indefinite; | 128 : FWL_Error::Indefinite; |
| 121 } | 129 } |
| 122 | 130 |
| 123 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { | 131 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { |
| 124 return GetWidget() ? GetWidget()->EditDoClipboard(iCmd) | 132 return GetWidget() ? ToComboBox(GetWidget())->EditDoClipboard(iCmd) |
| 125 : FWL_Error::Indefinite; | 133 : FWL_Error::Indefinite; |
| 126 } | 134 } |
| 127 | 135 |
| 128 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { | 136 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { |
| 129 return GetWidget() ? GetWidget()->EditRedo(pRecord) : FALSE; | 137 return GetWidget() ? ToComboBox(GetWidget())->EditRedo(pRecord) : FALSE; |
| 130 } | 138 } |
| 131 | 139 |
| 132 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { | 140 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { |
| 133 return GetWidget() ? GetWidget()->EditUndo(pRecord) : FALSE; | 141 return GetWidget() ? ToComboBox(GetWidget())->EditUndo(pRecord) : FALSE; |
| 134 } | 142 } |
| 135 | 143 |
| 136 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { | 144 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { |
| 137 m_comboBoxData.m_fMaxListHeight = fMaxHeight; | 145 m_comboBoxData.m_fMaxListHeight = fMaxHeight; |
| 138 return FWL_Error::Succeeded; | 146 return FWL_Error::Succeeded; |
| 139 } | 147 } |
| 140 | 148 |
| 141 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { | 149 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { |
| 142 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( | 150 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( |
| 143 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); | 151 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); |
| 144 if (!pItem) | 152 if (!pItem) |
| 145 return FWL_Error::Indefinite; | 153 return FWL_Error::Indefinite; |
| 146 pItem->m_pData = pData; | 154 pItem->m_pData = pData; |
| 147 return FWL_Error::Succeeded; | 155 return FWL_Error::Succeeded; |
| 148 } | 156 } |
| 149 | 157 |
| 150 void* CFWL_ComboBox::GetItemData(int32_t iIndex) { | 158 void* CFWL_ComboBox::GetItemData(int32_t iIndex) { |
| 151 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( | 159 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( |
| 152 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); | 160 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); |
| 153 return pItem ? pItem->m_pData : nullptr; | 161 return pItem ? pItem->m_pData : nullptr; |
| 154 } | 162 } |
| 155 | 163 |
| 156 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { | 164 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { |
| 157 return GetWidget()->GetListBoxt()->SetThemeProvider(pTheme); | 165 return ToComboBox(GetWidget())->GetListBoxt()->SetThemeProvider(pTheme); |
| 158 } | 166 } |
| 159 | 167 |
| 160 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { | 168 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { |
| 161 return GetWidget()->AfterFocusShowDropList(); | 169 return ToComboBox(GetWidget())->AfterFocusShowDropList(); |
| 162 } | 170 } |
| 163 | 171 |
| 164 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { | 172 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { |
| 165 return GetWidget()->OpenDropDownList(bActivate); | 173 return ToComboBox(GetWidget())->OpenDropDownList(bActivate); |
| 166 } | 174 } |
| 167 | 175 |
| 168 FX_BOOL CFWL_ComboBox::EditCanUndo() { | 176 FX_BOOL CFWL_ComboBox::EditCanUndo() { |
| 169 return GetWidget() ? GetWidget()->EditCanUndo() : FALSE; | 177 return GetWidget() ? ToComboBox(GetWidget())->EditCanUndo() : FALSE; |
| 170 } | 178 } |
| 171 | 179 |
| 172 FX_BOOL CFWL_ComboBox::EditCanRedo() { | 180 FX_BOOL CFWL_ComboBox::EditCanRedo() { |
| 173 return GetWidget() ? GetWidget()->EditCanRedo() : FALSE; | 181 return GetWidget() ? ToComboBox(GetWidget())->EditCanRedo() : FALSE; |
| 174 } | 182 } |
| 175 | 183 |
| 176 FX_BOOL CFWL_ComboBox::EditUndo() { | 184 FX_BOOL CFWL_ComboBox::EditUndo() { |
| 177 return GetWidget() ? GetWidget()->EditUndo() : FALSE; | 185 return GetWidget() ? ToComboBox(GetWidget())->EditUndo() : FALSE; |
| 178 } | 186 } |
| 179 | 187 |
| 180 FX_BOOL CFWL_ComboBox::EditRedo() { | 188 FX_BOOL CFWL_ComboBox::EditRedo() { |
| 181 return GetWidget() ? GetWidget()->EditRedo() : FALSE; | 189 return GetWidget() ? ToComboBox(GetWidget())->EditRedo() : FALSE; |
| 182 } | 190 } |
| 183 | 191 |
| 184 FX_BOOL CFWL_ComboBox::EditCanCopy() { | 192 FX_BOOL CFWL_ComboBox::EditCanCopy() { |
| 185 return GetWidget() ? GetWidget()->EditCanCopy() : FALSE; | 193 return GetWidget() ? ToComboBox(GetWidget())->EditCanCopy() : FALSE; |
| 186 } | 194 } |
| 187 | 195 |
| 188 FX_BOOL CFWL_ComboBox::EditCanCut() { | 196 FX_BOOL CFWL_ComboBox::EditCanCut() { |
| 189 return GetWidget() ? GetWidget()->EditCanCut() : FALSE; | 197 return GetWidget() ? ToComboBox(GetWidget())->EditCanCut() : FALSE; |
| 190 } | 198 } |
| 191 | 199 |
| 192 FX_BOOL CFWL_ComboBox::EditCanSelectAll() { | 200 FX_BOOL CFWL_ComboBox::EditCanSelectAll() { |
| 193 return GetWidget() ? GetWidget()->EditCanSelectAll() : FALSE; | 201 return GetWidget() ? ToComboBox(GetWidget())->EditCanSelectAll() : FALSE; |
| 194 } | 202 } |
| 195 | 203 |
| 196 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { | 204 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { |
| 197 return GetWidget() ? GetWidget()->EditCopy(wsCopy) : FALSE; | 205 return GetWidget() ? ToComboBox(GetWidget())->EditCopy(wsCopy) : FALSE; |
| 198 } | 206 } |
| 199 | 207 |
| 200 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { | 208 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { |
| 201 return GetWidget() ? GetWidget()->EditCut(wsCut) : FALSE; | 209 return GetWidget() ? ToComboBox(GetWidget())->EditCut(wsCut) : FALSE; |
| 202 } | 210 } |
| 203 | 211 |
| 204 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { | 212 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { |
| 205 return GetWidget() ? GetWidget()->EditPaste(wsPaste) : FALSE; | 213 return GetWidget() ? ToComboBox(GetWidget())->EditPaste(wsPaste) : FALSE; |
| 206 } | 214 } |
| 207 | 215 |
| 208 FX_BOOL CFWL_ComboBox::EditSelectAll() { | 216 FX_BOOL CFWL_ComboBox::EditSelectAll() { |
| 209 return GetWidget() ? GetWidget()->EditSelectAll() : FALSE; | 217 return GetWidget() ? ToComboBox(GetWidget())->EditSelectAll() : FALSE; |
| 210 } | 218 } |
| 211 | 219 |
| 212 FX_BOOL CFWL_ComboBox::EditDelete() { | 220 FX_BOOL CFWL_ComboBox::EditDelete() { |
| 213 return GetWidget() ? GetWidget()->EditDelete() : FALSE; | 221 return GetWidget() ? ToComboBox(GetWidget())->EditDelete() : FALSE; |
| 214 } | 222 } |
| 215 | 223 |
| 216 FX_BOOL CFWL_ComboBox::EditDeSelect() { | 224 FX_BOOL CFWL_ComboBox::EditDeSelect() { |
| 217 return GetWidget() ? GetWidget()->EditDeSelect() : FALSE; | 225 return GetWidget() ? ToComboBox(GetWidget())->EditDeSelect() : FALSE; |
| 218 } | 226 } |
| 219 | 227 |
| 220 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) { | 228 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) { |
| 221 return GetWidget() ? GetWidget()->GetBBox(rect) : FWL_Error::Indefinite; | 229 return GetWidget() ? ToComboBox(GetWidget())->GetBBox(rect) |
| 230 : FWL_Error::Indefinite; |
| 222 } | 231 } |
| 223 | 232 |
| 224 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | 233 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, |
| 225 uint32_t dwStylesExRemoved) { | 234 uint32_t dwStylesExRemoved) { |
| 226 return GetWidget() | 235 return GetWidget() |
| 227 ? GetWidget()->EditModifyStylesEx(dwStylesExAdded, | 236 ? ToComboBox(GetWidget()) |
| 228 dwStylesExRemoved) | 237 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved) |
| 229 : FWL_Error::Indefinite; | 238 : FWL_Error::Indefinite; |
| 230 } | 239 } |
| 231 | 240 |
| 232 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { | 241 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { |
| 233 m_fItemHeight = 0; | 242 m_fItemHeight = 0; |
| 234 m_fMaxListHeight = 0; | 243 m_fMaxListHeight = 0; |
| 235 } | 244 } |
| 236 | 245 |
| 237 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() {} | 246 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() {} |
| 238 | 247 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 return FWL_Error::Succeeded; | 382 return FWL_Error::Succeeded; |
| 374 } | 383 } |
| 375 | 384 |
| 376 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { | 385 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { |
| 377 return m_fMaxListHeight; | 386 return m_fMaxListHeight; |
| 378 } | 387 } |
| 379 | 388 |
| 380 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {} | 389 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {} |
| 381 | 390 |
| 382 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {} | 391 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {} |
| OLD | NEW |