| OLD | NEW |
| (Empty) |
| 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 | |
| 7 #include "xfa/include/fwl/lightwidget/combobox.h" | |
| 8 | |
| 9 #include <utility> | |
| 10 | |
| 11 #include "xfa/include/fwl/core/fwl_error.h" | |
| 12 #include "xfa/include/fwl/core/fwl_widget.h" | |
| 13 | |
| 14 CFWL_ComboBox* CFWL_ComboBox::Create() { | |
| 15 return new CFWL_ComboBox; | |
| 16 } | |
| 17 FWL_ERR CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) { | |
| 18 if (m_pIface) | |
| 19 return FWL_ERR_Indefinite; | |
| 20 if (pProperties) { | |
| 21 *m_pProperties = *pProperties; | |
| 22 } | |
| 23 std::unique_ptr<IFWL_ComboBox> pComboBox(IFWL_ComboBox::Create( | |
| 24 m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); | |
| 25 FWL_ERR ret = pComboBox->Initialize(); | |
| 26 if (ret != FWL_ERR_Succeeded) { | |
| 27 return ret; | |
| 28 } | |
| 29 m_pIface = pComboBox.release(); | |
| 30 CFWL_Widget::Initialize(); | |
| 31 return FWL_ERR_Succeeded; | |
| 32 } | |
| 33 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { | |
| 34 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); | |
| 35 pItem->m_wsText = wsText; | |
| 36 pItem->m_dwStyles = 0; | |
| 37 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); | |
| 38 return m_comboBoxData.m_ItemArray.size() - 1; | |
| 39 } | |
| 40 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText, | |
| 41 CFX_DIBitmap* pIcon) { | |
| 42 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); | |
| 43 pItem->m_wsText = wsText; | |
| 44 pItem->m_dwStyles = 0; | |
| 45 pItem->m_pDIB = pIcon; | |
| 46 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); | |
| 47 return m_comboBoxData.m_ItemArray.size() - 1; | |
| 48 } | |
| 49 bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { | |
| 50 if (iIndex < 0 || | |
| 51 static_cast<size_t>(iIndex) >= m_comboBoxData.m_ItemArray.size()) { | |
| 52 return false; | |
| 53 } | |
| 54 m_comboBoxData.m_ItemArray.erase(m_comboBoxData.m_ItemArray.begin() + iIndex); | |
| 55 return true; | |
| 56 } | |
| 57 void CFWL_ComboBox::RemoveAll() { | |
| 58 m_comboBoxData.m_ItemArray.clear(); | |
| 59 } | |
| 60 int32_t CFWL_ComboBox::CountItems() { | |
| 61 return m_comboBoxData.CountItems(GetWidget()); | |
| 62 } | |
| 63 FWL_ERR CFWL_ComboBox::GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) { | |
| 64 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>( | |
| 65 m_comboBoxData.GetItem(m_pIface, iIndex)); | |
| 66 if (!pItem) | |
| 67 return FWL_ERR_Indefinite; | |
| 68 wsText = pItem->m_wsText; | |
| 69 return FWL_ERR_Succeeded; | |
| 70 } | |
| 71 int32_t CFWL_ComboBox::GetCurSel() { | |
| 72 if (!m_pIface) | |
| 73 return -1; | |
| 74 return static_cast<IFWL_ComboBox*>(m_pIface)->GetCurSel(); | |
| 75 } | |
| 76 FWL_ERR CFWL_ComboBox::SetCurSel(int32_t iSel) { | |
| 77 if (!m_pIface) | |
| 78 return FWL_ERR_Indefinite; | |
| 79 return static_cast<IFWL_ComboBox*>(m_pIface)->SetCurSel(iSel); | |
| 80 } | |
| 81 FWL_ERR CFWL_ComboBox::SetEditText(const CFX_WideStringC& wsText) { | |
| 82 if (!m_pIface) | |
| 83 return FWL_ERR_Indefinite; | |
| 84 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditText(wsText); | |
| 85 } | |
| 86 int32_t CFWL_ComboBox::GetEditTextLength() const { | |
| 87 if (!m_pIface) | |
| 88 return 0; | |
| 89 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditTextLength(); | |
| 90 } | |
| 91 FWL_ERR CFWL_ComboBox::GetEditText(CFX_WideString& wsText, | |
| 92 int32_t nStart, | |
| 93 int32_t nCount) const { | |
| 94 if (!m_pIface) | |
| 95 return FWL_ERR_Indefinite; | |
| 96 return static_cast<IFWL_ComboBox*>(m_pIface) | |
| 97 ->GetEditText(wsText, nStart, nCount); | |
| 98 } | |
| 99 FWL_ERR CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { | |
| 100 if (!m_pIface) | |
| 101 return FWL_ERR_Indefinite; | |
| 102 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditSelRange(nStart, nCount); | |
| 103 } | |
| 104 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { | |
| 105 if (!m_pIface) | |
| 106 return 0; | |
| 107 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditSelRange(nIndex, nStart); | |
| 108 } | |
| 109 int32_t CFWL_ComboBox::GetEditLimit() { | |
| 110 if (!m_pIface) | |
| 111 return 0; | |
| 112 return static_cast<IFWL_ComboBox*>(m_pIface)->GetEditLimit(); | |
| 113 } | |
| 114 FWL_ERR CFWL_ComboBox::SetEditLimit(int32_t nLimit) { | |
| 115 if (!m_pIface) | |
| 116 return FWL_ERR_Indefinite; | |
| 117 return static_cast<IFWL_ComboBox*>(m_pIface)->SetEditLimit(nLimit); | |
| 118 } | |
| 119 FWL_ERR CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { | |
| 120 if (!m_pIface) | |
| 121 return FWL_ERR_Indefinite; | |
| 122 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDoClipboard(iCmd); | |
| 123 } | |
| 124 FX_BOOL CFWL_ComboBox::EditRedo(const CFX_ByteStringC& bsRecord) { | |
| 125 if (!m_pIface) | |
| 126 return FALSE; | |
| 127 return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(bsRecord); | |
| 128 } | |
| 129 FX_BOOL CFWL_ComboBox::EditUndo(const CFX_ByteStringC& bsRecord) { | |
| 130 if (!m_pIface) | |
| 131 return FALSE; | |
| 132 return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(bsRecord); | |
| 133 } | |
| 134 FWL_ERR CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { | |
| 135 m_comboBoxData.m_fMaxListHeight = fMaxHeight; | |
| 136 return FWL_ERR_Succeeded; | |
| 137 } | |
| 138 FWL_ERR CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { | |
| 139 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>( | |
| 140 m_comboBoxData.GetItem(m_pIface, iIndex)); | |
| 141 if (!pItem) | |
| 142 return FWL_ERR_Indefinite; | |
| 143 pItem->m_pData = pData; | |
| 144 return FWL_ERR_Succeeded; | |
| 145 } | |
| 146 void* CFWL_ComboBox::GetItemData(int32_t iIndex) { | |
| 147 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>( | |
| 148 m_comboBoxData.GetItem(m_pIface, iIndex)); | |
| 149 if (!pItem) | |
| 150 return NULL; | |
| 151 return pItem->m_pData; | |
| 152 } | |
| 153 FWL_ERR CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { | |
| 154 return static_cast<IFWL_ComboBox*>(m_pIface)->GetListBoxt()->SetThemeProvider( | |
| 155 pTheme); | |
| 156 } | |
| 157 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { | |
| 158 return static_cast<IFWL_ComboBox*>(m_pIface)->AfterFocusShowDropList(); | |
| 159 } | |
| 160 FWL_ERR CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { | |
| 161 return static_cast<IFWL_ComboBox*>(m_pIface)->OpenDropDownList(bActivate); | |
| 162 } | |
| 163 FX_BOOL CFWL_ComboBox::EditCanUndo() { | |
| 164 if (!m_pIface) | |
| 165 return FALSE; | |
| 166 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanUndo(); | |
| 167 } | |
| 168 FX_BOOL CFWL_ComboBox::EditCanRedo() { | |
| 169 if (!m_pIface) | |
| 170 return FALSE; | |
| 171 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanRedo(); | |
| 172 } | |
| 173 FX_BOOL CFWL_ComboBox::EditUndo() { | |
| 174 if (!m_pIface) | |
| 175 return FALSE; | |
| 176 return static_cast<IFWL_ComboBox*>(m_pIface)->EditUndo(); | |
| 177 } | |
| 178 FX_BOOL CFWL_ComboBox::EditRedo() { | |
| 179 if (!m_pIface) | |
| 180 return FALSE; | |
| 181 return static_cast<IFWL_ComboBox*>(m_pIface)->EditRedo(); | |
| 182 } | |
| 183 FX_BOOL CFWL_ComboBox::EditCanCopy() { | |
| 184 if (!m_pIface) | |
| 185 return FALSE; | |
| 186 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCopy(); | |
| 187 } | |
| 188 FX_BOOL CFWL_ComboBox::EditCanCut() { | |
| 189 if (!m_pIface) | |
| 190 return FALSE; | |
| 191 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanCut(); | |
| 192 } | |
| 193 FX_BOOL CFWL_ComboBox::EditCanSelectAll() { | |
| 194 if (!m_pIface) | |
| 195 return FALSE; | |
| 196 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCanSelectAll(); | |
| 197 } | |
| 198 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { | |
| 199 if (!m_pIface) | |
| 200 return FALSE; | |
| 201 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCopy(wsCopy); | |
| 202 } | |
| 203 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { | |
| 204 if (!m_pIface) | |
| 205 return FALSE; | |
| 206 return static_cast<IFWL_ComboBox*>(m_pIface)->EditCut(wsCut); | |
| 207 } | |
| 208 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { | |
| 209 if (!m_pIface) | |
| 210 return FALSE; | |
| 211 return static_cast<IFWL_ComboBox*>(m_pIface)->EditPaste(wsPaste); | |
| 212 } | |
| 213 FX_BOOL CFWL_ComboBox::EditSelectAll() { | |
| 214 if (!m_pIface) | |
| 215 return FALSE; | |
| 216 return static_cast<IFWL_ComboBox*>(m_pIface)->EditSelectAll(); | |
| 217 } | |
| 218 FX_BOOL CFWL_ComboBox::EditDelete() { | |
| 219 if (!m_pIface) | |
| 220 return FALSE; | |
| 221 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDelete(); | |
| 222 } | |
| 223 FX_BOOL CFWL_ComboBox::EditDeSelect() { | |
| 224 if (!m_pIface) | |
| 225 return FALSE; | |
| 226 return static_cast<IFWL_ComboBox*>(m_pIface)->EditDeSelect(); | |
| 227 } | |
| 228 FWL_ERR CFWL_ComboBox::GetBBox(CFX_RectF& rect) { | |
| 229 if (!m_pIface) | |
| 230 return FALSE; | |
| 231 return static_cast<IFWL_ComboBox*>(m_pIface)->GetBBox(rect); | |
| 232 } | |
| 233 FWL_ERR CFWL_ComboBox::EditModifyStylesEx(FX_DWORD dwStylesExAdded, | |
| 234 FX_DWORD dwStylesExRemoved) { | |
| 235 if (!m_pIface) | |
| 236 return FALSE; | |
| 237 return static_cast<IFWL_ComboBox*>(m_pIface) | |
| 238 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 239 } | |
| 240 CFWL_ComboBox::CFWL_ComboBox() {} | |
| 241 CFWL_ComboBox::~CFWL_ComboBox() {} | |
| 242 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { | |
| 243 m_fItemHeight = 0; | |
| 244 m_fMaxListHeight = 0; | |
| 245 } | |
| 246 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() {} | |
| 247 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(IFWL_Widget* pWidget) { | |
| 248 return m_ItemArray.size(); | |
| 249 } | |
| 250 FWL_HLISTITEM CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget* pWidget, | |
| 251 int32_t nIndex) { | |
| 252 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) | |
| 253 return nullptr; | |
| 254 | |
| 255 return reinterpret_cast<FWL_HLISTITEM>(m_ItemArray[nIndex].get()); | |
| 256 } | |
| 257 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget* pWidget, | |
| 258 FWL_HLISTITEM hItem) { | |
| 259 auto it = std::find_if( | |
| 260 m_ItemArray.begin(), m_ItemArray.end(), | |
| 261 [hItem](const std::unique_ptr<CFWL_ComboBoxItem>& candidate) { | |
| 262 return candidate.get() == reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 263 }); | |
| 264 return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; | |
| 265 } | |
| 266 FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget* pWidget, | |
| 267 FWL_HLISTITEM hItem, | |
| 268 int32_t nIndex) { | |
| 269 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) | |
| 270 return FALSE; | |
| 271 | |
| 272 m_ItemArray[nIndex].reset(reinterpret_cast<CFWL_ComboBoxItem*>(hItem)); | |
| 273 return TRUE; | |
| 274 } | |
| 275 FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget* pWidget, | |
| 276 FWL_HLISTITEM hItem) { | |
| 277 if (!hItem) | |
| 278 return 0; | |
| 279 return reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_dwStyles; | |
| 280 } | |
| 281 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget* pWidget, | |
| 282 FWL_HLISTITEM hItem, | |
| 283 CFX_WideString& wsText) { | |
| 284 if (!hItem) | |
| 285 return FWL_ERR_Indefinite; | |
| 286 wsText = reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_wsText; | |
| 287 return FWL_ERR_Succeeded; | |
| 288 } | |
| 289 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemRect(IFWL_Widget* pWidget, | |
| 290 FWL_HLISTITEM hItem, | |
| 291 CFX_RectF& rtItem) { | |
| 292 if (!hItem) | |
| 293 return FWL_ERR_Indefinite; | |
| 294 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 295 rtItem.Set(pItem->m_rtItem.left, pItem->m_rtItem.top, pItem->m_rtItem.width, | |
| 296 pItem->m_rtItem.height); | |
| 297 return FWL_ERR_Succeeded; | |
| 298 } | |
| 299 void* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemData(IFWL_Widget* pWidget, | |
| 300 FWL_HLISTITEM hItem) { | |
| 301 if (!hItem) | |
| 302 return NULL; | |
| 303 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 304 return pItem->m_pData; | |
| 305 } | |
| 306 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemStyles(IFWL_Widget* pWidget, | |
| 307 FWL_HLISTITEM hItem, | |
| 308 FX_DWORD dwStyle) { | |
| 309 if (!hItem) | |
| 310 return FWL_ERR_Indefinite; | |
| 311 reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_dwStyles = dwStyle; | |
| 312 return FWL_ERR_Succeeded; | |
| 313 } | |
| 314 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemText(IFWL_Widget* pWidget, | |
| 315 FWL_HLISTITEM hItem, | |
| 316 const FX_WCHAR* pszText) { | |
| 317 if (!hItem) | |
| 318 return FWL_ERR_Indefinite; | |
| 319 reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_wsText = pszText; | |
| 320 return FWL_ERR_Succeeded; | |
| 321 } | |
| 322 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemRect(IFWL_Widget* pWidget, | |
| 323 FWL_HLISTITEM hItem, | |
| 324 const CFX_RectF& rtItem) { | |
| 325 if (!hItem) | |
| 326 return FWL_ERR_Indefinite; | |
| 327 reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_rtItem = rtItem; | |
| 328 return FWL_ERR_Succeeded; | |
| 329 } | |
| 330 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetItemHeight(IFWL_Widget* pWidget) { | |
| 331 return m_fItemHeight; | |
| 332 } | |
| 333 CFX_DIBitmap* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIcon(IFWL_Widget* pWidget, | |
| 334 FWL_HLISTITEM hItem) { | |
| 335 if (!hItem) | |
| 336 return NULL; | |
| 337 return reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_pDIB; | |
| 338 } | |
| 339 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckRect(IFWL_Widget* pWidget, | |
| 340 FWL_HLISTITEM hItem, | |
| 341 CFX_RectF& rtCheck) { | |
| 342 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 343 rtCheck = pItem->m_rtCheckBox; | |
| 344 return FWL_ERR_Succeeded; | |
| 345 } | |
| 346 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckRect( | |
| 347 IFWL_Widget* pWidget, | |
| 348 FWL_HLISTITEM hItem, | |
| 349 const CFX_RectF& rtCheck) { | |
| 350 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 351 pItem->m_rtCheckBox = rtCheck; | |
| 352 return FWL_ERR_Succeeded; | |
| 353 } | |
| 354 FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckState( | |
| 355 IFWL_Widget* pWidget, | |
| 356 FWL_HLISTITEM hItem) { | |
| 357 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 358 return pItem->m_dwCheckState; | |
| 359 } | |
| 360 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckState( | |
| 361 IFWL_Widget* pWidget, | |
| 362 FWL_HLISTITEM hItem, | |
| 363 FX_DWORD dwCheckState) { | |
| 364 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); | |
| 365 pItem->m_dwCheckState = dwCheckState; | |
| 366 return FWL_ERR_Succeeded; | |
| 367 } | |
| 368 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { | |
| 369 return m_fMaxListHeight; | |
| 370 } | |
| OLD | NEW |