From 1770c021cf998ff1b33855b1397f6ea8ff9f7cd7 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 14 Mar 2016 14:14:16 -0400 Subject: Move xfa/src up to xfa/. This CL moves the xfa/src files up to the xfa/ directory and fixes the includes, include guards, and build files. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1803723002 . --- xfa/fwl/lightwidget/app.cpp | 33 +++ xfa/fwl/lightwidget/barcode.cpp | 45 ++++ xfa/fwl/lightwidget/caret.cpp | 47 +++++ xfa/fwl/lightwidget/checkbox.cpp | 57 +++++ xfa/fwl/lightwidget/combobox.cpp | 370 +++++++++++++++++++++++++++++++++ xfa/fwl/lightwidget/datetimepicker.cpp | 144 +++++++++++++ xfa/fwl/lightwidget/edit.cpp | 211 +++++++++++++++++++ xfa/fwl/lightwidget/listbox.cpp | 302 +++++++++++++++++++++++++++ xfa/fwl/lightwidget/picturebox.cpp | 119 +++++++++++ xfa/fwl/lightwidget/pushbutton.cpp | 56 +++++ xfa/fwl/lightwidget/scrollbar.cpp | 93 +++++++++ xfa/fwl/lightwidget/theme.cpp | 135 ++++++++++++ xfa/fwl/lightwidget/tooltipctrl.cpp | 111 ++++++++++ xfa/fwl/lightwidget/widget.cpp | 318 ++++++++++++++++++++++++++++ 14 files changed, 2041 insertions(+) create mode 100644 xfa/fwl/lightwidget/app.cpp create mode 100644 xfa/fwl/lightwidget/barcode.cpp create mode 100644 xfa/fwl/lightwidget/caret.cpp create mode 100644 xfa/fwl/lightwidget/checkbox.cpp create mode 100644 xfa/fwl/lightwidget/combobox.cpp create mode 100644 xfa/fwl/lightwidget/datetimepicker.cpp create mode 100644 xfa/fwl/lightwidget/edit.cpp create mode 100644 xfa/fwl/lightwidget/listbox.cpp create mode 100644 xfa/fwl/lightwidget/picturebox.cpp create mode 100644 xfa/fwl/lightwidget/pushbutton.cpp create mode 100644 xfa/fwl/lightwidget/scrollbar.cpp create mode 100644 xfa/fwl/lightwidget/theme.cpp create mode 100644 xfa/fwl/lightwidget/tooltipctrl.cpp create mode 100644 xfa/fwl/lightwidget/widget.cpp (limited to 'xfa/fwl/lightwidget') diff --git a/xfa/fwl/lightwidget/app.cpp b/xfa/fwl/lightwidget/app.cpp new file mode 100644 index 0000000000..31a39c17f0 --- /dev/null +++ b/xfa/fwl/lightwidget/app.cpp @@ -0,0 +1,33 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/app.h" + +#include "core/include/fxcrt/fx_coordinates.h" +#include "xfa/include/fwl/core/fwl_app.h" +#include "xfa/include/fwl/core/fwl_error.h" +#include "xfa/include/fwl/lightwidget/theme.h" + +CFWL_App::CFWL_App() : m_pIface(IFWL_App::Create(nullptr)), m_pTheme(nullptr) {} +CFWL_App::~CFWL_App() { + if (m_pTheme) { + m_pTheme->Finalize(); + delete m_pTheme; + m_pTheme = NULL; + } + m_pIface->Release(); +} +FWL_ERR CFWL_App::Initialize() { + m_pTheme = new CFWL_Theme; + m_pTheme->Initialize(); + m_pIface->SetThemeProvider(m_pTheme); + return m_pIface->Initialize(); +} +FWL_ERR CFWL_App::Exit(int32_t iExitCode) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->Exit(iExitCode); +} diff --git a/xfa/fwl/lightwidget/barcode.cpp b/xfa/fwl/lightwidget/barcode.cpp new file mode 100644 index 0000000000..4f05837352 --- /dev/null +++ b/xfa/fwl/lightwidget/barcode.cpp @@ -0,0 +1,45 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/barcode.h" + +#include + +CFWL_Barcode* CFWL_Barcode::Create() { + return new CFWL_Barcode; +} +FWL_ERR CFWL_Barcode::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pBarcode(IFWL_Barcode::Create( + m_pProperties->MakeWidgetImpProperties(&m_barcodeData))); + FWL_ERR ret = pBarcode->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pBarcode.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +CFWL_Barcode::CFWL_Barcode() {} +CFWL_Barcode::~CFWL_Barcode() {} +void CFWL_Barcode::SetType(BC_TYPE type) { + if (!m_pIface) + return; + static_cast(m_pIface)->SetType(type); +} +FX_BOOL CFWL_Barcode::IsProtectedType() { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->IsProtectedType(); +} +FWL_ERR CFWL_Barcode::CFWL_BarcodeDP::GetCaption(IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + return FWL_ERR_Succeeded; +} diff --git a/xfa/fwl/lightwidget/caret.cpp b/xfa/fwl/lightwidget/caret.cpp new file mode 100644 index 0000000000..279ea2d6f9 --- /dev/null +++ b/xfa/fwl/lightwidget/caret.cpp @@ -0,0 +1,47 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/caret.h" + +#include + +#include "xfa/fwl/core/fwl_targetimp.h" +#include "xfa/include/fwl/basewidget/fwl_caret.h" +#include "xfa/include/fwl/lightwidget/edit.h" + +CFWL_Caret* CFWL_Caret::Create() { + return new CFWL_Caret; +} +FWL_ERR CFWL_Caret::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pCaret(IFWL_Caret::Create( + m_pProperties->MakeWidgetImpProperties(nullptr), nullptr)); + FWL_ERR ret = pCaret->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pCaret.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_Caret::ShowCaret(FX_BOOL bFlag) { + return static_cast(m_pIface)->ShowCaret(bFlag); +} +FWL_ERR CFWL_Caret::GetFrequency(FX_DWORD& elapse) { + return static_cast(m_pIface)->GetFrequency(elapse); +} +FWL_ERR CFWL_Caret::SetFrequency(FX_DWORD elapse) { + return static_cast(m_pIface)->SetFrequency(elapse); +} +FWL_ERR CFWL_Caret::SetColor(CFX_Color crFill) { + return static_cast(m_pIface)->SetColor(crFill); +} +CFWL_Caret::CFWL_Caret() {} +CFWL_Caret::~CFWL_Caret() {} diff --git a/xfa/fwl/lightwidget/checkbox.cpp b/xfa/fwl/lightwidget/checkbox.cpp new file mode 100644 index 0000000000..6b7a370973 --- /dev/null +++ b/xfa/fwl/lightwidget/checkbox.cpp @@ -0,0 +1,57 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/checkbox.h" + +#include + +#include "xfa/include/fwl/core/fwl_error.h" + +CFWL_CheckBox* CFWL_CheckBox::Create() { + return new CFWL_CheckBox; +} +FWL_ERR CFWL_CheckBox::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pCheckBox(IFWL_CheckBox::Create( + m_pProperties->MakeWidgetImpProperties(&m_checkboxData), nullptr)); + FWL_ERR ret = pCheckBox->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pCheckBox.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_CheckBox::SetCaption(const CFX_WideStringC& wsCaption) { + m_checkboxData.m_wsCaption = wsCaption; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_CheckBox::SetBoxSize(FX_FLOAT fHeight) { + m_checkboxData.m_fBoxHeight = fHeight; + return FWL_ERR_Succeeded; +} +int32_t CFWL_CheckBox::GetCheckState() { + return static_cast(m_pIface)->GetCheckState(); +} +FWL_ERR CFWL_CheckBox::SetCheckState(int32_t iCheck) { + return static_cast(m_pIface)->SetCheckState(iCheck); +} +CFWL_CheckBox::CFWL_CheckBox() {} +CFWL_CheckBox::~CFWL_CheckBox() {} +CFWL_CheckBox::CFWL_CheckBoxDP::CFWL_CheckBoxDP() + : m_fBoxHeight(16.0f), m_wsCaption(L"Check box") {} +FWL_ERR CFWL_CheckBox::CFWL_CheckBoxDP::GetCaption(IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + wsCaption = m_wsCaption; + return FWL_ERR_Succeeded; +} +FX_FLOAT CFWL_CheckBox::CFWL_CheckBoxDP::GetBoxSize(IFWL_Widget* pWidget) { + return m_fBoxHeight; +} diff --git a/xfa/fwl/lightwidget/combobox.cpp b/xfa/fwl/lightwidget/combobox.cpp new file mode 100644 index 0000000000..aadb0d5ab6 --- /dev/null +++ b/xfa/fwl/lightwidget/combobox.cpp @@ -0,0 +1,370 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/combobox.h" + +#include + +#include "xfa/include/fwl/core/fwl_error.h" +#include "xfa/include/fwl/core/fwl_widget.h" + +CFWL_ComboBox* CFWL_ComboBox::Create() { + return new CFWL_ComboBox; +} +FWL_ERR CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pComboBox(IFWL_ComboBox::Create( + m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); + FWL_ERR ret = pComboBox->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pComboBox.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { + std::unique_ptr pItem(new CFWL_ComboBoxItem); + pItem->m_wsText = wsText; + pItem->m_dwStyles = 0; + m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); + return m_comboBoxData.m_ItemArray.size() - 1; +} +int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText, + CFX_DIBitmap* pIcon) { + std::unique_ptr pItem(new CFWL_ComboBoxItem); + pItem->m_wsText = wsText; + pItem->m_dwStyles = 0; + pItem->m_pDIB = pIcon; + m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); + return m_comboBoxData.m_ItemArray.size() - 1; +} +bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { + if (iIndex < 0 || + static_cast(iIndex) >= m_comboBoxData.m_ItemArray.size()) { + return false; + } + m_comboBoxData.m_ItemArray.erase(m_comboBoxData.m_ItemArray.begin() + iIndex); + return true; +} +void CFWL_ComboBox::RemoveAll() { + m_comboBoxData.m_ItemArray.clear(); +} +int32_t CFWL_ComboBox::CountItems() { + return m_comboBoxData.CountItems(GetWidget()); +} +FWL_ERR CFWL_ComboBox::GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) { + CFWL_ComboBoxItem* pItem = reinterpret_cast( + m_comboBoxData.GetItem(m_pIface, iIndex)); + if (!pItem) + return FWL_ERR_Indefinite; + wsText = pItem->m_wsText; + return FWL_ERR_Succeeded; +} +int32_t CFWL_ComboBox::GetCurSel() { + if (!m_pIface) + return -1; + return static_cast(m_pIface)->GetCurSel(); +} +FWL_ERR CFWL_ComboBox::SetCurSel(int32_t iSel) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetCurSel(iSel); +} +FWL_ERR CFWL_ComboBox::SetEditText(const CFX_WideStringC& wsText) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetEditText(wsText); +} +int32_t CFWL_ComboBox::GetEditTextLength() const { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetEditTextLength(); +} +FWL_ERR CFWL_ComboBox::GetEditText(CFX_WideString& wsText, + int32_t nStart, + int32_t nCount) const { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface) + ->GetEditText(wsText, nStart, nCount); +} +FWL_ERR CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetEditSelRange(nStart, nCount); +} +int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetEditSelRange(nIndex, nStart); +} +int32_t CFWL_ComboBox::GetEditLimit() { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetEditLimit(); +} +FWL_ERR CFWL_ComboBox::SetEditLimit(int32_t nLimit) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetEditLimit(nLimit); +} +FWL_ERR CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->EditDoClipboard(iCmd); +} +FX_BOOL CFWL_ComboBox::EditRedo(const CFX_ByteStringC& bsRecord) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditRedo(bsRecord); +} +FX_BOOL CFWL_ComboBox::EditUndo(const CFX_ByteStringC& bsRecord) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditUndo(bsRecord); +} +FWL_ERR CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { + m_comboBoxData.m_fMaxListHeight = fMaxHeight; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { + CFWL_ComboBoxItem* pItem = reinterpret_cast( + m_comboBoxData.GetItem(m_pIface, iIndex)); + if (!pItem) + return FWL_ERR_Indefinite; + pItem->m_pData = pData; + return FWL_ERR_Succeeded; +} +void* CFWL_ComboBox::GetItemData(int32_t iIndex) { + CFWL_ComboBoxItem* pItem = reinterpret_cast( + m_comboBoxData.GetItem(m_pIface, iIndex)); + if (!pItem) + return NULL; + return pItem->m_pData; +} +FWL_ERR CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { + return static_cast(m_pIface)->GetListBoxt()->SetThemeProvider( + pTheme); +} +FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { + return static_cast(m_pIface)->AfterFocusShowDropList(); +} +FWL_ERR CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { + return static_cast(m_pIface)->OpenDropDownList(bActivate); +} +FX_BOOL CFWL_ComboBox::EditCanUndo() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCanUndo(); +} +FX_BOOL CFWL_ComboBox::EditCanRedo() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCanRedo(); +} +FX_BOOL CFWL_ComboBox::EditUndo() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditUndo(); +} +FX_BOOL CFWL_ComboBox::EditRedo() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditRedo(); +} +FX_BOOL CFWL_ComboBox::EditCanCopy() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCanCopy(); +} +FX_BOOL CFWL_ComboBox::EditCanCut() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCanCut(); +} +FX_BOOL CFWL_ComboBox::EditCanSelectAll() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCanSelectAll(); +} +FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCopy(wsCopy); +} +FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditCut(wsCut); +} +FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditPaste(wsPaste); +} +FX_BOOL CFWL_ComboBox::EditSelectAll() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditSelectAll(); +} +FX_BOOL CFWL_ComboBox::EditDelete() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditDelete(); +} +FX_BOOL CFWL_ComboBox::EditDeSelect() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->EditDeSelect(); +} +FWL_ERR CFWL_ComboBox::GetBBox(CFX_RectF& rect) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->GetBBox(rect); +} +FWL_ERR CFWL_ComboBox::EditModifyStylesEx(FX_DWORD dwStylesExAdded, + FX_DWORD dwStylesExRemoved) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface) + ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); +} +CFWL_ComboBox::CFWL_ComboBox() {} +CFWL_ComboBox::~CFWL_ComboBox() {} +CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { + m_fItemHeight = 0; + m_fMaxListHeight = 0; +} +CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() {} +int32_t CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(IFWL_Widget* pWidget) { + return m_ItemArray.size(); +} +FWL_HLISTITEM CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget* pWidget, + int32_t nIndex) { + if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) + return nullptr; + + return reinterpret_cast(m_ItemArray[nIndex].get()); +} +int32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + auto it = std::find_if( + m_ItemArray.begin(), m_ItemArray.end(), + [hItem](const std::unique_ptr& candidate) { + return candidate.get() == reinterpret_cast(hItem); + }); + return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; +} +FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + int32_t nIndex) { + if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) + return FALSE; + + m_ItemArray[nIndex].reset(reinterpret_cast(hItem)); + return TRUE; +} +FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + if (!hItem) + return 0; + return reinterpret_cast(hItem)->m_dwStyles; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + CFX_WideString& wsText) { + if (!hItem) + return FWL_ERR_Indefinite; + wsText = reinterpret_cast(hItem)->m_wsText; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemRect(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + CFX_RectF& rtItem) { + if (!hItem) + return FWL_ERR_Indefinite; + CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); + rtItem.Set(pItem->m_rtItem.left, pItem->m_rtItem.top, pItem->m_rtItem.width, + pItem->m_rtItem.height); + return FWL_ERR_Succeeded; +} +void* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemData(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + if (!hItem) + return NULL; + CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); + return pItem->m_pData; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemStyles(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + FX_DWORD dwStyle) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_dwStyles = dwStyle; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemText(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + const FX_WCHAR* pszText) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_wsText = pszText; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemRect(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + const CFX_RectF& rtItem) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_rtItem = rtItem; + return FWL_ERR_Succeeded; +} +FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetItemHeight(IFWL_Widget* pWidget) { + return m_fItemHeight; +} +CFX_DIBitmap* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIcon(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + if (!hItem) + return NULL; + return reinterpret_cast(hItem)->m_pDIB; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckRect(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + CFX_RectF& rtCheck) { + CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); + rtCheck = pItem->m_rtCheckBox; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckRect( + IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + const CFX_RectF& rtCheck) { + CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); + pItem->m_rtCheckBox = rtCheck; + return FWL_ERR_Succeeded; +} +FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckState( + IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); + return pItem->m_dwCheckState; +} +FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckState( + IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + FX_DWORD dwCheckState) { + CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); + pItem->m_dwCheckState = dwCheckState; + return FWL_ERR_Succeeded; +} +FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { + return m_fMaxListHeight; +} diff --git a/xfa/fwl/lightwidget/datetimepicker.cpp b/xfa/fwl/lightwidget/datetimepicker.cpp new file mode 100644 index 0000000000..bf1d976d90 --- /dev/null +++ b/xfa/fwl/lightwidget/datetimepicker.cpp @@ -0,0 +1,144 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/datetimepicker.h" + +#include + +#include "xfa/include/fwl/basewidget/fwl_datetimepicker.h" +#include "xfa/include/fwl/core/fwl_error.h" +#include "xfa/include/fwl/core/fwl_note.h" +#include "xfa/include/fwl/core/fwl_widget.h" + +CFWL_DateTimePicker* CFWL_DateTimePicker::Create() { + return new CFWL_DateTimePicker; +} +FWL_ERR CFWL_DateTimePicker::Initialize( + const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pDateTimePicker( + IFWL_DateTimePicker::Create( + m_pProperties->MakeWidgetImpProperties(&m_DateTimePickerDP), + nullptr)); + FWL_ERR ret = pDateTimePicker->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pDateTimePicker.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} + +FWL_ERR CFWL_DateTimePicker::SetToday(int32_t iYear, + int32_t iMonth, + int32_t iDay) { + m_DateTimePickerDP.m_iYear = iYear; + m_DateTimePickerDP.m_iMonth = iMonth; + m_DateTimePickerDP.m_iDay = iDay; + return FWL_ERR_Succeeded; +} +int32_t CFWL_DateTimePicker::CountSelRanges() { + return static_cast(m_pIface)->CountSelRanges(); +} +int32_t CFWL_DateTimePicker::GetSelRange(int32_t nIndex, int32_t& nStart) { + return static_cast(m_pIface) + ->GetSelRange(nIndex, nStart); +} +FWL_ERR CFWL_DateTimePicker::GetEditText(CFX_WideString& wsText) { + return static_cast(m_pIface)->GetEditText(wsText); +} +FWL_ERR CFWL_DateTimePicker::SetEditText(const CFX_WideStringC& wsText) { + return static_cast(m_pIface)->SetEditText(wsText); +} +FWL_ERR CFWL_DateTimePicker::GetCurSel(int32_t& iYear, + int32_t& iMonth, + int32_t& iDay) { + return static_cast(m_pIface) + ->GetCurSel(iYear, iMonth, iDay); +} +FWL_ERR CFWL_DateTimePicker::SetCurSel(int32_t iYear, + int32_t iMonth, + int32_t iDay) { + return static_cast(m_pIface) + ->SetCurSel(iYear, iMonth, iDay); +} +CFWL_DateTimePicker::CFWL_DateTimePicker() {} +CFWL_DateTimePicker::~CFWL_DateTimePicker() {} +CFWL_DateTimePicker::CFWL_DateTimePickerDP::CFWL_DateTimePickerDP() { + m_iYear = 2011; + m_iMonth = 1; + m_iDay = 1; +} +FWL_ERR CFWL_DateTimePicker::CFWL_DateTimePickerDP::GetCaption( + IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + wsCaption = m_wsData; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_DateTimePicker::CFWL_DateTimePickerDP::GetToday( + IFWL_Widget* pWidget, + int32_t& iYear, + int32_t& iMonth, + int32_t& iDay) { + iYear = m_iYear; + iMonth = m_iMonth; + iDay = m_iDay; + return FWL_ERR_Succeeded; +} +FX_BOOL CFWL_DateTimePicker::CanUndo() { + return static_cast(m_pIface)->CanUndo(); +} +FX_BOOL CFWL_DateTimePicker::CanRedo() { + return static_cast(m_pIface)->CanRedo(); +} +FX_BOOL CFWL_DateTimePicker::Undo() { + return static_cast(m_pIface)->Undo(); +} +FX_BOOL CFWL_DateTimePicker::Redo() { + return static_cast(m_pIface)->Redo(); +} +FX_BOOL CFWL_DateTimePicker::CanCopy() { + return static_cast(m_pIface)->CanCopy(); +} +FX_BOOL CFWL_DateTimePicker::CanCut() { + return static_cast(m_pIface)->CanCut(); +} +FX_BOOL CFWL_DateTimePicker::CanSelectAll() { + return static_cast(m_pIface)->CanSelectAll(); +} +FX_BOOL CFWL_DateTimePicker::Copy(CFX_WideString& wsCopy) { + return static_cast(m_pIface)->Copy(wsCopy); +} +FX_BOOL CFWL_DateTimePicker::Cut(CFX_WideString& wsCut) { + return static_cast(m_pIface)->Copy(wsCut); +} +FX_BOOL CFWL_DateTimePicker::Paste(const CFX_WideString& wsPaste) { + return static_cast(m_pIface)->Paste(wsPaste); +} +FX_BOOL CFWL_DateTimePicker::SelectAll() { + return static_cast(m_pIface)->SelectAll(); +} +FX_BOOL CFWL_DateTimePicker::Delete() { + return static_cast(m_pIface)->Delete(); +} +FX_BOOL CFWL_DateTimePicker::DeSelect() { + return static_cast(m_pIface)->DeSelect(); +} +FWL_ERR CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) { + return static_cast(m_pIface)->GetBBox(rect); +} +FWL_ERR CFWL_DateTimePicker::SetEditLimit(int32_t nLimit) { + return static_cast(m_pIface)->SetEditLimit(nLimit); +} +FWL_ERR CFWL_DateTimePicker::ModifyEditStylesEx(FX_DWORD dwStylesExAdded, + FX_DWORD dwStylesExRemoved) { + return static_cast(m_pIface) + ->ModifyEditStylesEx(dwStylesExAdded, dwStylesExRemoved); +} diff --git a/xfa/fwl/lightwidget/edit.cpp b/xfa/fwl/lightwidget/edit.cpp new file mode 100644 index 0000000000..303943a8f6 --- /dev/null +++ b/xfa/fwl/lightwidget/edit.cpp @@ -0,0 +1,211 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/edit.h" + +#include +#include + +#include "xfa/include/fwl/basewidget/fwl_edit.h" + +CFWL_Edit* CFWL_Edit::Create() { + return new CFWL_Edit; +} +FWL_ERR CFWL_Edit::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pEdit(IFWL_Edit::Create( + m_pProperties->MakeWidgetImpProperties(nullptr), nullptr)); + FWL_ERR ret = pEdit->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pEdit.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_Edit::SetText(const CFX_WideString& wsText) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetText(wsText); +} +int32_t CFWL_Edit::GetTextLength() const { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetTextLength(); +} +FWL_ERR CFWL_Edit::GetText(CFX_WideString& wsText, + int32_t nStart, + int32_t nCount) const { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->GetText(wsText, nStart, nCount); +} +FWL_ERR CFWL_Edit::ClearText() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->ClearText(); +} +int32_t CFWL_Edit::GetCaretPos() const { + if (!m_pIface) + return -1; + return static_cast(m_pIface)->GetCaretPos(); +} +int32_t CFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) { + if (!m_pIface) + return -1; + return static_cast(m_pIface)->SetCaretPos(nIndex, bBefore); +} +FWL_ERR CFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount) { + if (!m_pIface) + return FWL_ERR_Indefinite; + static_cast(m_pIface)->AddSelRange(nStart, nCount); + int32_t pos = 0; + int32_t sum = static_cast(m_pIface)->GetTextLength(); + if (nCount == -1) { + pos = sum; + } else { + pos = nStart + nCount; + } + return static_cast(m_pIface)->SetCaretPos(pos); +} +int32_t CFWL_Edit::CountSelRanges() { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->CountSelRanges(); +} +int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetSelRange(nIndex, nStart); +} +FWL_ERR CFWL_Edit::ClearSelections() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->ClearSelections(); +} +int32_t CFWL_Edit::GetLimit() { + if (!m_pIface) + return -1; + return static_cast(m_pIface)->GetLimit(); +} +FWL_ERR CFWL_Edit::SetLimit(int32_t nLimit) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetLimit(nLimit); +} +FWL_ERR CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetAliasChar(wAlias); +} +FWL_ERR CFWL_Edit::Insert(int32_t nStart, + const FX_WCHAR* lpText, + int32_t nLen) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->Insert(nStart, lpText, nLen); +} +FWL_ERR CFWL_Edit::DeleteSelections() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->DeleteSelections(); +} +FWL_ERR CFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->DeleteRange(nStart, nCount); +} +FWL_ERR CFWL_Edit::ReplaceSelections(const CFX_WideStringC& wsReplace) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->ReplaceSelections(wsReplace); +} +FWL_ERR CFWL_Edit::Replace(int32_t nStart, + int32_t nLen, + const CFX_WideStringC& wsReplace) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->Replace(nStart, nLen, wsReplace); +} +FWL_ERR CFWL_Edit::DoClipboard(int32_t iCmd) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->DoClipboard(iCmd); +} +FX_BOOL CFWL_Edit::Redo(const CFX_ByteStringC& bsRecord) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->Redo(bsRecord); +} +FX_BOOL CFWL_Edit::Undo(const CFX_ByteStringC& bsRecord) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->Undo(bsRecord); +} +FWL_ERR CFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface) + ->SetTabWidth(fTabWidth, bEquidistant); +} +FWL_ERR CFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax) { + if (iMin > iMax) { + return FWL_ERR_Parameter_Invalid; + } + return static_cast(m_pIface)->SetNumberRange(iMin, iMax); +} +FWL_ERR CFWL_Edit::SetBackColor(FX_DWORD dwColor) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetBackColor(dwColor); +} +FWL_ERR CFWL_Edit::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetFont(wsFont, fSize); +} +FX_BOOL CFWL_Edit::CanUndo() { + return static_cast(m_pIface)->CanUndo(); +} +FX_BOOL CFWL_Edit::CanRedo() { + return static_cast(m_pIface)->CanRedo(); +} +FX_BOOL CFWL_Edit::Undo() { + return static_cast(m_pIface)->Undo(); +} +FX_BOOL CFWL_Edit::Redo() { + return static_cast(m_pIface)->Undo(); +} +FX_BOOL CFWL_Edit::Copy(CFX_WideString& wsCopy) { + return static_cast(m_pIface)->Copy(wsCopy); +} +FX_BOOL CFWL_Edit::Cut(CFX_WideString& wsCut) { + return static_cast(m_pIface)->Cut(wsCut); +} +FX_BOOL CFWL_Edit::Paste(const CFX_WideString& wsPaste) { + return static_cast(m_pIface)->Paste(wsPaste); +} +FX_BOOL CFWL_Edit::Delete() { + return static_cast(m_pIface)->Delete(); +} +void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { + return static_cast(m_pIface)->SetScrollOffset(fScrollOffset); +} +FX_BOOL CFWL_Edit::GetSuggestWords(CFX_PointF pointf, + std::vector& sSuggest) { + return static_cast(m_pIface)->GetSuggestWords(pointf, sSuggest); +} +FX_BOOL CFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf, + const CFX_ByteStringC& bsReplace) { + return static_cast(m_pIface) + ->ReplaceSpellCheckWord(pointf, bsReplace); +} +CFWL_Edit::CFWL_Edit() {} +CFWL_Edit::~CFWL_Edit() {} diff --git a/xfa/fwl/lightwidget/listbox.cpp b/xfa/fwl/lightwidget/listbox.cpp new file mode 100644 index 0000000000..6a7a26cd1b --- /dev/null +++ b/xfa/fwl/lightwidget/listbox.cpp @@ -0,0 +1,302 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/listbox.h" + +#include + +#include "third_party/base/stl_util.h" + +CFWL_ListBox* CFWL_ListBox::Create() { + return new CFWL_ListBox; +} +FWL_ERR CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pListBox(IFWL_ListBox::Create( + m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr)); + FWL_ERR ret = pListBox->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pListBox.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, FWL_HLISTITEM hItem) { + reinterpret_cast(hItem)->m_pDIB = pDIB; + return FWL_ERR_Succeeded; +} +FWL_HLISTITEM CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, + FX_BOOL bSelect) { + std::unique_ptr pItem(new CFWL_ListItem); + pItem->m_dwStates = 0; + pItem->m_wsText = wsAdd; + pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; + m_ListBoxDP.m_ItemArray.push_back(std::move(pItem)); + return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray.back().get(); +} +FX_BOOL CFWL_ListBox::DeleteString(FWL_HLISTITEM hItem) { + int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem); + if (nIndex < 0 || + static_cast(nIndex) >= m_ListBoxDP.m_ItemArray.size()) { + return FALSE; + } + int32_t iCount = m_ListBoxDP.CountItems(m_pIface); + int32_t iSel = nIndex + 1; + if (iSel >= iCount) { + iSel = nIndex - 1; + if (iSel < 0) { + iSel = -1; + } + } + if (iSel >= 0) { + CFWL_ListItem* pSel = + reinterpret_cast(m_ListBoxDP.GetItem(m_pIface, iSel)); + pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; + } + m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex); + return TRUE; +} +void CFWL_ListBox::DeleteAll() { + m_ListBoxDP.m_ItemArray.clear(); +} +int32_t CFWL_ListBox::CountSelItems() { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->CountSelItems(); +} +FWL_HLISTITEM CFWL_ListBox::GetSelItem(int32_t nIndexSel) { + if (!m_pIface) + return NULL; + return static_cast(m_pIface)->GetSelItem(nIndexSel); +} +int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetSelIndex(nIndex); +} +FWL_ERR CFWL_ListBox::SetSelItem(FWL_HLISTITEM hItem, FX_BOOL bSelect) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetSelItem(hItem, bSelect); +} +FWL_ERR CFWL_ListBox::GetItemText(FWL_HLISTITEM hItem, CFX_WideString& wsText) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->GetItemText(hItem, wsText); +} +FWL_ERR CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->GetScrollPos(fPos, bVert); +} +FWL_ERR CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) { + m_ListBoxDP.m_fItemHeight = fItemHeight; + return FWL_ERR_Succeeded; +} +FWL_HLISTITEM CFWL_ListBox::GetFocusItem() { + for (const auto& hItem : m_ListBoxDP.m_ItemArray) { + if (hItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused) + return (FWL_HLISTITEM)hItem.get(); + } + return nullptr; +} +FWL_ERR CFWL_ListBox::SetFocusItem(FWL_HLISTITEM hItem) { + int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem); + m_ListBoxDP.m_ItemArray[nIndex]->m_dwStates |= FWL_ITEMSTATE_LTB_Focused; + return FWL_ERR_Succeeded; +} +FWL_ERR* CFWL_ListBox::Sort(IFWL_ListBoxCompare* pCom) { + return static_cast(m_pIface)->Sort(pCom); +} +int32_t CFWL_ListBox::CountItems() { + return pdfium::CollectionSize(m_ListBoxDP.m_ItemArray); +} +FWL_HLISTITEM CFWL_ListBox::GetItem(int32_t nIndex) { + if (nIndex < 0 || nIndex >= CountItems()) + return nullptr; + + return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray[nIndex].get(); +} +FWL_ERR CFWL_ListBox::SetItemString(FWL_HLISTITEM hItem, + const CFX_WideStringC& wsText) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_wsText = wsText; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::GetItemString(FWL_HLISTITEM hItem, + CFX_WideString& wsText) { + if (!hItem) + return FWL_ERR_Indefinite; + wsText = reinterpret_cast(hItem)->m_wsText; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::SetItemData(FWL_HLISTITEM hItem, void* pData) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_pData = pData; + return FWL_ERR_Succeeded; +} +void* CFWL_ListBox::GetItemData(FWL_HLISTITEM hItem) { + if (!hItem) + return NULL; + return reinterpret_cast(hItem)->m_pData; +} +FWL_HLISTITEM CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { + CFX_RectF rtClient; + m_pIface->GetClientRect(rtClient); + fx -= rtClient.left; + fy -= rtClient.top; + FX_FLOAT fPosX = 0; + FX_FLOAT fPosY = 0; + static_cast(m_pIface)->GetScrollPos(fx); + static_cast(m_pIface)->GetScrollPos(fy, FALSE); + int32_t nCount = m_ListBoxDP.CountItems(NULL); + for (int32_t i = 0; i < nCount; i++) { + FWL_HLISTITEM hItem = m_ListBoxDP.GetItem(NULL, i); + if (!hItem) { + continue; + } + CFX_RectF rtItem; + m_ListBoxDP.GetItemRect(NULL, hItem, rtItem); + rtItem.Offset(-fPosX, -fPosY); + if (rtItem.Contains(fx, fy)) { + return hItem; + } + } + return NULL; +} +FX_DWORD CFWL_ListBox::GetItemStates(FWL_HLISTITEM hItem) { + if (!hItem) + return 0; + CFWL_ListItem* pItem = reinterpret_cast(hItem); + return pItem->m_dwStates | pItem->m_dwCheckState; +} +CFWL_ListBox::CFWL_ListBox() {} +CFWL_ListBox::~CFWL_ListBox() {} +CFWL_ListBox::CFWL_ListBoxDP::CFWL_ListBoxDP() {} +CFWL_ListBox::CFWL_ListBoxDP::~CFWL_ListBoxDP() {} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetCaption(IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + wsCaption = m_wsData; + return FWL_ERR_Succeeded; +} +int32_t CFWL_ListBox::CFWL_ListBoxDP::CountItems(IFWL_Widget* pWidget) { + return pdfium::CollectionSize(m_ItemArray); +} +FWL_HLISTITEM CFWL_ListBox::CFWL_ListBoxDP::GetItem(IFWL_Widget* pWidget, + int32_t nIndex) { + if (nIndex < 0 || nIndex >= CountItems(pWidget)) + return nullptr; + + return (FWL_HLISTITEM)m_ItemArray[nIndex].get(); +} +int32_t CFWL_ListBox::CFWL_ListBoxDP::GetItemIndex(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + auto it = std::find_if( + m_ItemArray.begin(), m_ItemArray.end(), + [hItem](const std::unique_ptr& candidate) { + return candidate.get() == reinterpret_cast(hItem); + }); + return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; +} +FX_BOOL CFWL_ListBox::CFWL_ListBoxDP::SetItemIndex(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + int32_t nIndex) { + if (nIndex < 0 || nIndex >= CountItems(pWidget)) + return FALSE; + m_ItemArray[nIndex].reset(reinterpret_cast(hItem)); + return TRUE; +} +FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemStyles(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + if (!hItem) + return -1; + return reinterpret_cast(hItem)->m_dwStates; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemText(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + CFX_WideString& wsText) { + if (!hItem) + return FWL_ERR_Indefinite; + wsText = reinterpret_cast(hItem)->m_wsText; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemRect(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + CFX_RectF& rtItem) { + if (!hItem) + return FWL_ERR_Indefinite; + CFWL_ListItem* pItem = reinterpret_cast(hItem); + rtItem = pItem->m_rtItem; + return FWL_ERR_Succeeded; +} +void* CFWL_ListBox::CFWL_ListBoxDP::GetItemData(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + if (!hItem) + return NULL; + CFWL_ListItem* pItem = reinterpret_cast(hItem); + return pItem->m_pData; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemStyles(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + FX_DWORD dwStyle) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_dwStates = dwStyle; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemText(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + const FX_WCHAR* pszText) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_wsText = pszText; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemRect(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + const CFX_RectF& rtItem) { + if (!hItem) + return FWL_ERR_Indefinite; + reinterpret_cast(hItem)->m_rtItem = rtItem; + return FWL_ERR_Succeeded; +} +FX_FLOAT CFWL_ListBox::CFWL_ListBoxDP::GetItemHeight(IFWL_Widget* pWidget) { + return m_fItemHeight; +} +CFX_DIBitmap* CFWL_ListBox::CFWL_ListBoxDP::GetItemIcon(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + return reinterpret_cast(hItem)->m_pDIB; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemCheckRect(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + CFX_RectF& rtCheck) { + rtCheck = reinterpret_cast(hItem)->m_rtCheckBox; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemCheckRect( + IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + const CFX_RectF& rtCheck) { + reinterpret_cast(hItem)->m_rtCheckBox = rtCheck; + return FWL_ERR_Succeeded; +} +FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemCheckState(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem) { + return reinterpret_cast(hItem)->m_dwCheckState; +} +FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemCheckState(IFWL_Widget* pWidget, + FWL_HLISTITEM hItem, + FX_DWORD dwCheckState) { + reinterpret_cast(hItem)->m_dwCheckState = dwCheckState; + return FWL_ERR_Succeeded; +} diff --git a/xfa/fwl/lightwidget/picturebox.cpp b/xfa/fwl/lightwidget/picturebox.cpp new file mode 100644 index 0000000000..e35741c3ac --- /dev/null +++ b/xfa/fwl/lightwidget/picturebox.cpp @@ -0,0 +1,119 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/picturebox.h" + +#include + +CFWL_PictureBox* CFWL_PictureBox::Create() { + return new CFWL_PictureBox; +} +FWL_ERR CFWL_PictureBox::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pPictureBox(IFWL_PictureBox::Create( + m_pProperties->MakeWidgetImpProperties(&m_PictureBoxDP), nullptr)); + FWL_ERR ret = pPictureBox->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pPictureBox.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +CFX_DIBitmap* CFWL_PictureBox::GetPicture() { + return m_PictureBoxDP.m_pBitmap; +} +FWL_ERR CFWL_PictureBox::SetPicture(CFX_DIBitmap* pBitmap) { + m_PictureBoxDP.m_pBitmap = pBitmap; + return FWL_ERR_Succeeded; +} +FX_FLOAT CFWL_PictureBox::GetRotation() { + return m_PictureBoxDP.m_fRotation; +} +FWL_ERR CFWL_PictureBox::SetRotation(FX_FLOAT fRotation) { + m_PictureBoxDP.m_fRotation = fRotation; + return FWL_ERR_Succeeded; +} +int32_t CFWL_PictureBox::GetFlipMode() { + return m_PictureBoxDP.GetFlipMode(m_pIface); +} +FWL_ERR CFWL_PictureBox::SetFlipMode(int32_t iFlipMode) { + m_PictureBoxDP.m_iFlipMode = iFlipMode; + return FWL_ERR_Succeeded; +} +int32_t CFWL_PictureBox::GetOpacity() { + return m_PictureBoxDP.GetOpacity(m_pIface); +} +FWL_ERR CFWL_PictureBox::SetOpacity(int32_t iOpacity) { + m_PictureBoxDP.m_iOpacity = iOpacity; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_PictureBox::GetScale(FX_FLOAT& fScaleX, FX_FLOAT& fScaleY) { + CFX_Matrix matrix; + m_PictureBoxDP.GetMatrix(m_pIface, matrix); + matrix.Scale(fScaleX, fScaleY); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_PictureBox::SetScale(FX_FLOAT fScaleX, FX_FLOAT fScaleY) { + m_PictureBoxDP.m_fScaleX = fScaleX; + m_PictureBoxDP.m_fScaleY = fScaleY; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_PictureBox::GetOffset(FX_FLOAT& fx, FX_FLOAT& fy) { + CFX_Matrix matrix; + m_PictureBoxDP.GetMatrix(m_pIface, matrix); + fx = matrix.e; + fy = matrix.f; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_PictureBox::SetOffset(FX_FLOAT fx, FX_FLOAT fy) { + m_PictureBoxDP.m_fOffSetX = fx; + m_PictureBoxDP.m_fOffSetY = fy; + return FWL_ERR_Succeeded; +} +CFWL_PictureBox::CFWL_PictureBox() {} +CFWL_PictureBox::~CFWL_PictureBox() {} +FWL_ERR CFWL_PictureBox::CFWL_PictureBoxDP::GetCaption( + IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + return FWL_ERR_Succeeded; +} +CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetPicture( + IFWL_Widget* pWidget) { + return m_pBitmap; +} +CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetErrorPicture( + IFWL_Widget* pWidget) { + return m_pBitmap; +} +CFX_DIBitmap* CFWL_PictureBox::CFWL_PictureBoxDP::GetInitialPicture( + IFWL_Widget* pWidget) { + return m_pBitmap; +} +int32_t CFWL_PictureBox::CFWL_PictureBoxDP::GetOpacity(IFWL_Widget* pWidget) { + return m_iOpacity; +} +FWL_ERR CFWL_PictureBox::CFWL_PictureBoxDP::GetMatrix(IFWL_Widget* pWidget, + CFX_Matrix& matrix) { + CFX_RectF rect; + pWidget->GetClientRect(rect); + FX_FLOAT fLen = rect.width / 2; + FX_FLOAT fWid = rect.height / 2; + matrix.SetIdentity(); + matrix.Translate(-fLen, -fWid); + matrix.Rotate(m_fRotation); + matrix.Translate(fLen, fWid); + matrix.Scale(m_fScaleX, m_fScaleY); + matrix.Translate(m_fOffSetX, m_fOffSetY); + return FWL_ERR_Succeeded; +} +int32_t CFWL_PictureBox::CFWL_PictureBoxDP::GetFlipMode(IFWL_Widget* pWidget) { + return m_iFlipMode; +} diff --git a/xfa/fwl/lightwidget/pushbutton.cpp b/xfa/fwl/lightwidget/pushbutton.cpp new file mode 100644 index 0000000000..c9fb74e5f5 --- /dev/null +++ b/xfa/fwl/lightwidget/pushbutton.cpp @@ -0,0 +1,56 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/pushbutton.h" + +#include + +CFWL_PushButton* CFWL_PushButton::Create() { + return new CFWL_PushButton; +} +FWL_ERR CFWL_PushButton::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pPushButton(IFWL_PushButton::Create( + m_pProperties->MakeWidgetImpProperties(&m_buttonData), nullptr)); + FWL_ERR ret = pPushButton->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pPushButton.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_PushButton::GetCaption(CFX_WideString& wsCaption) { + wsCaption = m_buttonData.m_wsCaption; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_PushButton::SetCaption(const CFX_WideStringC& wsCaption) { + m_buttonData.m_wsCaption = wsCaption; + return FWL_ERR_Succeeded; +} +CFX_DIBitmap* CFWL_PushButton::GetPicture() { + return m_buttonData.m_pBitmap; +} +FWL_ERR CFWL_PushButton::SetPicture(CFX_DIBitmap* pBitmap) { + m_buttonData.m_pBitmap = pBitmap; + return FWL_ERR_Succeeded; +} +CFWL_PushButton::CFWL_PushButton() {} +CFWL_PushButton::~CFWL_PushButton() {} +FWL_ERR CFWL_PushButton::CFWL_PushButtonDP::GetCaption( + IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + wsCaption = m_wsCaption; + return FWL_ERR_Succeeded; +} +CFX_DIBitmap* CFWL_PushButton::CFWL_PushButtonDP::GetPicture( + IFWL_Widget* pWidget) { + return m_pBitmap; +} diff --git a/xfa/fwl/lightwidget/scrollbar.cpp b/xfa/fwl/lightwidget/scrollbar.cpp new file mode 100644 index 0000000000..cc927e724e --- /dev/null +++ b/xfa/fwl/lightwidget/scrollbar.cpp @@ -0,0 +1,93 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/scrollbar.h" + +#include + +#include "xfa/include/fwl/basewidget/fwl_scrollbar.h" + +CFWL_ScrollBar* CFWL_ScrollBar::Create() { + return new CFWL_ScrollBar; +} +FWL_ERR CFWL_ScrollBar::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pScrollBar(IFWL_ScrollBar::Create( + m_pProperties->MakeWidgetImpProperties(nullptr), nullptr)); + FWL_ERR ret = pScrollBar->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pScrollBar.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FX_BOOL CFWL_ScrollBar::IsVertical() { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->IsVertical(); +} +FWL_ERR CFWL_ScrollBar::GetRange(FX_FLOAT& fMin, FX_FLOAT& fMax) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->GetRange(fMin, fMax); +} +FWL_ERR CFWL_ScrollBar::SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetRange(fMin, fMax); +} +FX_FLOAT CFWL_ScrollBar::GetPageSize() { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetPageSize(); +} +FWL_ERR CFWL_ScrollBar::SetPageSize(FX_FLOAT fPageSize) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetPageSize(fPageSize); +} +FX_FLOAT CFWL_ScrollBar::GetStepSize() { + if (!m_pIface) + return 0; + return static_cast(m_pIface)->GetStepSize(); +} +FWL_ERR CFWL_ScrollBar::SetStepSize(FX_FLOAT fStepSize) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetStepSize(fStepSize); +} +FX_FLOAT CFWL_ScrollBar::GetPos() { + if (!m_pIface) + return -1; + return static_cast(m_pIface)->GetPos(); +} +FWL_ERR CFWL_ScrollBar::SetPos(FX_FLOAT fPos) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetPos(fPos); +} +FX_FLOAT CFWL_ScrollBar::GetTrackPos() { + if (!m_pIface) + return -1; + return static_cast(m_pIface)->GetTrackPos(); +} +FWL_ERR CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return static_cast(m_pIface)->SetTrackPos(fTrackPos); +} +FX_BOOL CFWL_ScrollBar::DoScroll(FX_DWORD dwCode, FX_FLOAT fPos) { + if (!m_pIface) + return FALSE; + return static_cast(m_pIface)->DoScroll(dwCode, fPos); +} +CFWL_ScrollBar::CFWL_ScrollBar() {} +CFWL_ScrollBar::~CFWL_ScrollBar() {} diff --git a/xfa/fwl/lightwidget/theme.cpp b/xfa/fwl/lightwidget/theme.cpp new file mode 100644 index 0000000000..fe9f55928b --- /dev/null +++ b/xfa/fwl/lightwidget/theme.cpp @@ -0,0 +1,135 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/theme.h" + +#include + +#include "xfa/include/fwl/theme/barcodetp.h" +#include "xfa/include/fwl/theme/carettp.h" +#include "xfa/include/fwl/theme/checkboxtp.h" +#include "xfa/include/fwl/theme/comboboxtp.h" +#include "xfa/include/fwl/theme/datetimepickertp.h" +#include "xfa/include/fwl/theme/edittp.h" +#include "xfa/include/fwl/theme/formtp.h" +#include "xfa/include/fwl/theme/listboxtp.h" +#include "xfa/include/fwl/theme/monthcalendartp.h" +#include "xfa/include/fwl/theme/pictureboxtp.h" +#include "xfa/include/fwl/theme/pushbuttontp.h" +#include "xfa/include/fwl/theme/scrollbartp.h" + +CFWL_Theme::CFWL_Theme() { + m_ThemesArray.push_back(std::unique_ptr(new CFWL_FormTP)); + m_ThemesArray.push_back( + std::unique_ptr(new CFWL_PushButtonTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_CheckBoxTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_ListBoxTP)); + m_ThemesArray.push_back( + std::unique_ptr(new CFWL_PictureBoxTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_ScrollBarTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_EditTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_ComboBoxTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_BarcodeTP)); + m_ThemesArray.push_back( + std::unique_ptr(new CFWL_DateTimePickerTP)); + m_ThemesArray.push_back( + std::unique_ptr(new CFWL_MonthCalendarTP)); + m_ThemesArray.push_back(std::unique_ptr(new CFWL_CaretTP)); +} + +CFWL_Theme::~CFWL_Theme() {} + +FX_BOOL CFWL_Theme::IsValidWidget(IFWL_Widget* pWidget) { + return !!GetTheme(pWidget); +} + +FX_DWORD CFWL_Theme::GetThemeID(IFWL_Widget* pWidget) { + return GetTheme(pWidget)->GetThemeID(pWidget); +} + +FX_DWORD CFWL_Theme::SetThemeID(IFWL_Widget* pWidget, + FX_DWORD dwThemeID, + FX_BOOL bChildren) { + FX_DWORD dwID; + for (const auto& pTheme : m_ThemesArray) { + dwID = pTheme->GetThemeID(pWidget); + pTheme->SetThemeID(pWidget, dwThemeID, FALSE); + } + return dwID; +} + +FWL_ERR CFWL_Theme::GetThemeMatrix(IFWL_Widget* pWidget, CFX_Matrix& matrix) { + return FWL_ERR_Succeeded; +} + +FWL_ERR CFWL_Theme::SetThemeMatrix(IFWL_Widget* pWidget, + const CFX_Matrix& matrix) { + return FWL_ERR_Succeeded; +} + +FX_BOOL CFWL_Theme::DrawBackground(CFWL_ThemeBackground* pParams) { + return GetTheme(pParams->m_pWidget)->DrawBackground(pParams); +} + +FX_BOOL CFWL_Theme::DrawText(CFWL_ThemeText* pParams) { + return GetTheme(pParams->m_pWidget)->DrawText(pParams); +} + +void* CFWL_Theme::GetCapacity(CFWL_ThemePart* pThemePart, FX_DWORD dwCapacity) { + return GetTheme(pThemePart->m_pWidget)->GetCapacity(pThemePart, dwCapacity); +} + +FX_BOOL CFWL_Theme::IsCustomizedLayout(IFWL_Widget* pWidget) { + return GetTheme(pWidget)->IsCustomizedLayout(pWidget); +} + +FWL_ERR CFWL_Theme::GetPartRect(CFWL_ThemePart* pThemePart, CFX_RectF& rtPart) { + return GetTheme(pThemePart->m_pWidget)->GetPartRect(pThemePart, rtPart); +} + +FX_BOOL CFWL_Theme::IsInPart(CFWL_ThemePart* pThemePart, + FX_FLOAT fx, + FX_FLOAT fy) { + return GetTheme(pThemePart->m_pWidget)->IsInPart(pThemePart, fx, fy); +} + +FX_BOOL CFWL_Theme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) { + return GetTheme(pParams->m_pWidget)->CalcTextRect(pParams, rect); +} + +FWL_ERR CFWL_Theme::Initialize() { + for (const auto& pTheme : m_ThemesArray) + pTheme->Initialize(); + + FWLTHEME_Init(); + return FWL_ERR_Succeeded; +} + +FWL_ERR CFWL_Theme::Finalize() { + for (const auto& pTheme : m_ThemesArray) + pTheme->Finalize(); + + FWLTHEME_Release(); + return FWL_ERR_Succeeded; +} + +FWL_ERR CFWL_Theme::SetFont(IFWL_Widget* pWidget, + const FX_WCHAR* strFont, + FX_FLOAT fFontSize, + FX_ARGB rgbFont) { + for (const auto& pTheme : m_ThemesArray) + pTheme->SetFont(pWidget, strFont, fFontSize, rgbFont); + + return FWL_ERR_Succeeded; +} + +CFWL_WidgetTP* CFWL_Theme::GetTheme(IFWL_Widget* pWidget) { + for (const auto& pTheme : m_ThemesArray) { + if (pTheme->IsValidWidget(pWidget)) + return pTheme.get(); + } + return nullptr; +} diff --git a/xfa/fwl/lightwidget/tooltipctrl.cpp b/xfa/fwl/lightwidget/tooltipctrl.cpp new file mode 100644 index 0000000000..323eed0282 --- /dev/null +++ b/xfa/fwl/lightwidget/tooltipctrl.cpp @@ -0,0 +1,111 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/tooltipctrl.h" + +#include + +#include "xfa/fwl/core/fwl_formimp.h" +#include "xfa/fwl/core/fwl_noteimp.h" +#include "xfa/fwl/core/fwl_panelimp.h" +#include "xfa/fwl/core/fwl_targetimp.h" +#include "xfa/fwl/core/fwl_threadimp.h" +#include "xfa/fwl/core/fwl_widgetimp.h" + +CFWL_ToolTip* CFWL_ToolTip::Create() { + return new CFWL_ToolTip; +} +FWL_ERR CFWL_ToolTip::Initialize(const CFWL_WidgetProperties* pProperties) { + if (m_pIface) + return FWL_ERR_Indefinite; + if (pProperties) { + *m_pProperties = *pProperties; + } + std::unique_ptr pToolTip(IFWL_ToolTip::Create( + m_pProperties->MakeWidgetImpProperties(&m_tooltipData), nullptr)); + FWL_ERR ret = pToolTip->Initialize(); + if (ret != FWL_ERR_Succeeded) { + return ret; + } + m_pIface = pToolTip.release(); + CFWL_Widget::Initialize(); + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ToolTip::GetCaption(CFX_WideString& wsCaption) { + wsCaption = m_tooltipData.m_wsCaption; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ToolTip::SetCaption(const CFX_WideStringC& wsCaption) { + m_tooltipData.m_wsCaption = wsCaption; + return FWL_ERR_Succeeded; +} +int32_t CFWL_ToolTip::GetInitialDelay() { + return m_tooltipData.m_nInitDelayTime; +} +int32_t CFWL_ToolTip::SetInitialDelay(int32_t nDelayTime) { + m_tooltipData.m_nInitDelayTime = nDelayTime; + return FWL_ERR_Succeeded; +} +int32_t CFWL_ToolTip::GetAutoPopDelay() { + return m_tooltipData.m_nAutoPopDelayTime; +} +int32_t CFWL_ToolTip::SetAutoPopDelay(int32_t nDelayTime) { + m_tooltipData.m_nAutoPopDelayTime = nDelayTime; + return FWL_ERR_Succeeded; +} +CFX_DIBitmap* CFWL_ToolTip::GetToolTipIcon() { + return m_tooltipData.m_pBitmap; +} +FWL_ERR CFWL_ToolTip::SetToolTipIcon(CFX_DIBitmap* pBitmap) { + m_tooltipData.m_pBitmap = pBitmap; + return FWL_ERR_Succeeded; +} +CFX_SizeF CFWL_ToolTip::GetToolTipIconSize() { + return m_tooltipData.m_fIconSize; +} +FWL_ERR CFWL_ToolTip::SetToolTipIconSize(CFX_SizeF fSize) { + m_tooltipData.m_fIconSize = fSize; + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_ToolTip::SetAnchor(const CFX_RectF& rtAnchor) { + return static_cast(m_pIface)->SetAnchor(rtAnchor); +} +FWL_ERR CFWL_ToolTip::Show() { + return static_cast(m_pIface)->Show(); +} +FWL_ERR CFWL_ToolTip::Hide() { + return static_cast(m_pIface)->Hide(); +} +CFWL_ToolTip::CFWL_ToolTip() {} +CFWL_ToolTip::~CFWL_ToolTip() {} +CFWL_ToolTip::CFWL_ToolTipDP::CFWL_ToolTipDP() : m_pBitmap(NULL) { + m_wsCaption = L""; + m_nInitDelayTime = 500; + m_nAutoPopDelayTime = 50000; + m_fAnchor.Set(0.0, 0.0, 0.0, 0.0); +} +FWL_ERR CFWL_ToolTip::CFWL_ToolTipDP::GetCaption(IFWL_Widget* pWidget, + CFX_WideString& wsCaption) { + wsCaption = m_wsCaption; + return FWL_ERR_Succeeded; +} +int32_t CFWL_ToolTip::CFWL_ToolTipDP::GetInitialDelay(IFWL_Widget* pWidget) { + return m_nInitDelayTime; +} +int32_t CFWL_ToolTip::CFWL_ToolTipDP::GetAutoPopDelay(IFWL_Widget* pWidget) { + return m_nAutoPopDelayTime; +} +CFX_DIBitmap* CFWL_ToolTip::CFWL_ToolTipDP::GetToolTipIcon( + IFWL_Widget* pWidget) { + return m_pBitmap; +} +CFX_SizeF CFWL_ToolTip::CFWL_ToolTipDP::GetToolTipIconSize( + IFWL_Widget* pWidget) { + return m_fIconSize; +} +CFX_RectF CFWL_ToolTip::CFWL_ToolTipDP::GetAnchor() { + return m_fAnchor; +} diff --git a/xfa/fwl/lightwidget/widget.cpp b/xfa/fwl/lightwidget/widget.cpp new file mode 100644 index 0000000000..daaab3c300 --- /dev/null +++ b/xfa/fwl/lightwidget/widget.cpp @@ -0,0 +1,318 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/include/fwl/lightwidget/widget.h" + +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/core/fwl_noteimp.h" +#include "xfa/fwl/core/fwl_noteimp.h" +#include "xfa/fwl/core/fwl_targetimp.h" +#include "xfa/fwl/core/fwl_widgetimp.h" +#include "xfa/fwl/core/fwl_widgetmgrimp.h" +#include "xfa/include/fwl/core/fwl_theme.h" +#include "xfa/include/fwl/core/fwl_thread.h" + +CFWL_WidgetImpProperties CFWL_WidgetProperties::MakeWidgetImpProperties( + IFWL_DataProvider* pDataProvider) const { + CFWL_WidgetImpProperties result; + result.m_ctmOnParent = m_ctmOnParent; + result.m_rtWidget = m_rtWidget; + result.m_dwStyles = m_dwStyles; + result.m_dwStyleExes = m_dwStyleExes; + result.m_dwStates = m_dwStates; + if (m_pParent) + result.m_pParent = m_pParent->GetWidget(); + if (m_pOwner) + result.m_pOwner = m_pOwner->GetWidget(); + result.m_pDataProvider = pDataProvider; + return result; +} +IFWL_Widget* CFWL_Widget::GetWidget() { + return m_pIface; +} +FWL_ERR CFWL_Widget::GetClassName(CFX_WideString& wsClass) const { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->GetClassName(wsClass); +} +FX_DWORD CFWL_Widget::GetClassID() const { + if (!m_pIface) + return 0; + return m_pIface->GetClassID(); +} +FX_BOOL CFWL_Widget::IsInstance(const CFX_WideStringC& wsClass) const { + if (!m_pIface) + return FALSE; + return m_pIface->IsInstance(wsClass); +} +static void* gs_pFWLWidget = (void*)FXBSTR_ID('l', 'i', 'g', 't'); +FWL_ERR CFWL_Widget::Initialize(const CFWL_WidgetProperties* pProperties) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->SetPrivateData(gs_pFWLWidget, this, NULL); +} +FWL_ERR CFWL_Widget::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->GetWidgetRect(rect, bAutoSize); +} +FWL_ERR CFWL_Widget::GetGlobalRect(CFX_RectF& rect) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->GetGlobalRect(rect); +} +FWL_ERR CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->SetWidgetRect(rect); +} +FWL_ERR CFWL_Widget::GetClientRect(CFX_RectF& rect) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->GetClientRect(rect); +} +CFWL_Widget* CFWL_Widget::GetParent() { + if (!m_pIface) + return NULL; + IFWL_Widget* parent = m_pIface->GetParent(); + if (parent) { + return static_cast(parent->GetPrivateData(gs_pFWLWidget)); + } + return NULL; +} +FWL_ERR CFWL_Widget::SetParent(CFWL_Widget* pParent) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->SetParent(pParent ? pParent->GetWidget() : NULL); +} +CFWL_Widget* CFWL_Widget::GetOwner() { + if (!m_pIface) + return NULL; + return NULL; +} +FWL_ERR CFWL_Widget::SetOwner(CFWL_Widget* pOwner) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return FWL_ERR_Succeeded; +} +FX_DWORD CFWL_Widget::GetStyles() { + if (!m_pIface) + return 0; + return m_pIface->GetStyles(); +} +FWL_ERR CFWL_Widget::ModifyStyles(FX_DWORD dwStylesAdded, + FX_DWORD dwStylesRemoved) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->ModifyStyles(dwStylesAdded, dwStylesRemoved); +} +FX_DWORD CFWL_Widget::GetStylesEx() { + if (!m_pIface) + return 0; + return m_pIface->GetStylesEx(); +} +FWL_ERR CFWL_Widget::ModifyStylesEx(FX_DWORD dwStylesExAdded, + FX_DWORD dwStylesExRemoved) { + return m_pIface->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); +} +FX_DWORD CFWL_Widget::GetStates() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->GetStates(); +} +FWL_ERR CFWL_Widget::SetStates(FX_DWORD dwStates, FX_BOOL bSet) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->SetStates(dwStates, bSet); +} +FWL_ERR CFWL_Widget::SetPrivateData(void* module_id, + void* pData, + PD_CALLBACK_FREEDATA callback) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->SetPrivateData(module_id, pData, callback); +} +void* CFWL_Widget::GetPrivateData(void* module_id) { + if (!m_pIface) + return NULL; + return m_pIface->GetPrivateData(module_id); +} +FWL_ERR CFWL_Widget::Update() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->Update(); +} +FWL_ERR CFWL_Widget::LockUpdate() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->LockUpdate(); +} +FWL_ERR CFWL_Widget::UnlockUpdate() { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->UnlockUpdate(); +} +FX_DWORD CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (!m_pIface) + return 0; + return m_pIface->HitTest(fx, fy); +} +FWL_ERR CFWL_Widget::TransformTo(CFWL_Widget* pWidget, + FX_FLOAT& fx, + FX_FLOAT& fy) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->TransformTo(pWidget ? pWidget->GetWidget() : NULL, fx, fy); +} +FWL_ERR CFWL_Widget::TransformTo(CFWL_Widget* pWidget, CFX_RectF& rt) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->TransformTo(pWidget ? pWidget->GetWidget() : NULL, rt); +} +FWL_ERR CFWL_Widget::GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->GetMatrix(matrix, bGlobal); +} +FWL_ERR CFWL_Widget::SetMatrix(const CFX_Matrix& matrix) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->SetMatrix(matrix); +} +FWL_ERR CFWL_Widget::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!m_pIface) + return FWL_ERR_Indefinite; + return m_pIface->DrawWidget(pGraphics, pMatrix); +} +IFWL_WidgetDelegate* CFWL_Widget::SetDelegate(IFWL_WidgetDelegate* pDelegate) { + if (!m_pIface) + return NULL; + m_pDelegate = m_pIface->SetDelegate(pDelegate); + return m_pDelegate; +} +CFWL_Widget::CFWL_Widget() + : m_pIface(NULL), m_pDelegate(NULL), m_pProperties(NULL) { + m_pProperties = new CFWL_WidgetProperties; + m_pWidgetMgr = static_cast(FWL_GetWidgetMgr()); + FXSYS_assert(m_pWidgetMgr != NULL); +} +CFWL_Widget::~CFWL_Widget() { + delete m_pProperties; + if (m_pIface) { + m_pIface->Finalize(); + delete m_pIface; + } +} +FWL_ERR CFWL_Widget::Repaint(const CFX_RectF* pRect) { + if (!m_pIface) + return FWL_ERR_Indefinite; + CFX_RectF rect; + if (pRect) { + rect = *pRect; + } else { + m_pIface->GetWidgetRect(rect); + rect.left = rect.top = 0; + } + return m_pWidgetMgr->RepaintWidget(m_pIface, &rect); +} +FWL_ERR CFWL_Widget::SetFocus(FX_BOOL bFocus) { + if (!m_pIface) + return FWL_ERR_Indefinite; + IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); + if (!pThread) + return FWL_ERR_Indefinite; + IFWL_NoteDriver* pDriver = pThread->GetNoteDriver(); + if (!pDriver) + return FWL_ERR_Indefinite; + if (bFocus) { + pDriver->SetFocus(m_pIface); + } else { + if (pDriver->GetFocus() == m_pIface) { + pDriver->SetFocus(NULL); + } + } + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_Widget::SetGrab(FX_BOOL bSet) { + if (!m_pIface) + return FWL_ERR_Indefinite; + IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); + if (!pThread) + return FWL_ERR_Indefinite; + IFWL_NoteDriver* pDriver = pThread->GetNoteDriver(); + if (!pDriver) + return FWL_ERR_Indefinite; + pDriver->SetGrab(m_pIface, bSet); + return FWL_ERR_Succeeded; +} +void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource, + FX_DWORD dwFilter) { + if (!m_pIface) + return; + IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); + if (!pThread) + return; + IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); + if (!pNoteDriver) + return; + IFWL_Widget* pEventSourceImp = + !pEventSource ? NULL : pEventSource->GetWidget(); + pNoteDriver->RegisterEventTarget(GetWidget(), pEventSourceImp, dwFilter); +} +void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) { + if (!m_pIface) + return; + if (m_pIface->GetOuter()) { + return; + } + IFWL_NoteThread* pThread = m_pIface->GetOwnerThread(); + if (!pThread) + return; + IFWL_NoteDriver* pNoteDriver = pThread->GetNoteDriver(); + if (!pNoteDriver) + return; + pNoteDriver->SendNote(pEvent); +} +#define FWL_WGT_CalcHeight 2048 +#define FWL_WGT_CalcWidth 2048 +#define FWL_WGT_CalcMultiLineDefWidth 120.0f +CFX_SizeF CFWL_Widget::CalcTextSize(const CFX_WideString& wsText, + FX_BOOL bMultiLine, + int32_t iLineWidth) { + if (!m_pIface) + return CFX_SizeF(); + IFWL_ThemeProvider* pTheme = m_pIface->GetThemeProvider(); + if (!pTheme) + return CFX_SizeF(); + + CFWL_ThemeText calPart; + calPart.m_pWidget = m_pIface; + calPart.m_wsText = wsText; + calPart.m_dwTTOStyles = + bMultiLine ? FDE_TTOSTYLE_LineWrap : FDE_TTOSTYLE_SingleLine; + calPart.m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; + CFX_RectF rect; + FX_FLOAT fWidth = bMultiLine + ? (iLineWidth > 0 ? (FX_FLOAT)iLineWidth + : FWL_WGT_CalcMultiLineDefWidth) + : FWL_WGT_CalcWidth; + rect.Set(0, 0, fWidth, FWL_WGT_CalcHeight); + pTheme->CalcTextRect(&calPart, rect); + return CFX_SizeF(rect.width, rect.height); +} +CFWL_WidgetDelegate::CFWL_WidgetDelegate() {} +CFWL_WidgetDelegate::~CFWL_WidgetDelegate() {} +int32_t CFWL_WidgetDelegate::OnProcessMessage(CFWL_Message* pMessage) { + return 1; +} +FWL_ERR CFWL_WidgetDelegate::OnProcessEvent(CFWL_Event* pEvent) { + return FWL_ERR_Succeeded; +} +FWL_ERR CFWL_WidgetDelegate::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + return FWL_ERR_Succeeded; +} -- cgit v1.2.3