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 <memory>
8
9#include "xfa/src/foxitlib.h"
10
11CFWL_DateTimePicker* CFWL_DateTimePicker::Create() {
12  return new CFWL_DateTimePicker;
13}
14FWL_ERR CFWL_DateTimePicker::Initialize(
15    const CFWL_WidgetProperties* pProperties) {
16  if (m_pIface)
17    return FWL_ERR_Indefinite;
18  if (pProperties) {
19    *m_pProperties = *pProperties;
20  }
21  std::unique_ptr<IFWL_DateTimePicker> pDateTimePicker(
22      IFWL_DateTimePicker::Create(
23          m_pProperties->MakeWidgetImpProperties(&m_DateTimePickerDP),
24          nullptr));
25  FWL_ERR ret = pDateTimePicker->Initialize();
26  if (ret != FWL_ERR_Succeeded) {
27    return ret;
28  }
29  m_pIface = pDateTimePicker.release();
30  CFWL_Widget::Initialize();
31  return FWL_ERR_Succeeded;
32}
33
34FWL_ERR CFWL_DateTimePicker::SetToday(int32_t iYear,
35                                      int32_t iMonth,
36                                      int32_t iDay) {
37  m_DateTimePickerDP.m_iYear = iYear;
38  m_DateTimePickerDP.m_iMonth = iMonth;
39  m_DateTimePickerDP.m_iDay = iDay;
40  return FWL_ERR_Succeeded;
41}
42int32_t CFWL_DateTimePicker::CountSelRanges() {
43  return static_cast<IFWL_DateTimePicker*>(m_pIface)->CountSelRanges();
44}
45int32_t CFWL_DateTimePicker::GetSelRange(int32_t nIndex, int32_t& nStart) {
46  return static_cast<IFWL_DateTimePicker*>(m_pIface)
47      ->GetSelRange(nIndex, nStart);
48}
49FWL_ERR CFWL_DateTimePicker::GetEditText(CFX_WideString& wsText) {
50  return static_cast<IFWL_DateTimePicker*>(m_pIface)->GetEditText(wsText);
51}
52FWL_ERR CFWL_DateTimePicker::SetEditText(const CFX_WideStringC& wsText) {
53  return static_cast<IFWL_DateTimePicker*>(m_pIface)->SetEditText(wsText);
54}
55FWL_ERR CFWL_DateTimePicker::GetCurSel(int32_t& iYear,
56                                       int32_t& iMonth,
57                                       int32_t& iDay) {
58  return static_cast<IFWL_DateTimePicker*>(m_pIface)
59      ->GetCurSel(iYear, iMonth, iDay);
60}
61FWL_ERR CFWL_DateTimePicker::SetCurSel(int32_t iYear,
62                                       int32_t iMonth,
63                                       int32_t iDay) {
64  return static_cast<IFWL_DateTimePicker*>(m_pIface)
65      ->SetCurSel(iYear, iMonth, iDay);
66}
67CFWL_DateTimePicker::CFWL_DateTimePicker() {}
68CFWL_DateTimePicker::~CFWL_DateTimePicker() {}
69CFWL_DateTimePicker::CFWL_DateTimePickerDP::CFWL_DateTimePickerDP() {
70  m_iYear = 2011;
71  m_iMonth = 1;
72  m_iDay = 1;
73}
74FWL_ERR CFWL_DateTimePicker::CFWL_DateTimePickerDP::GetCaption(
75    IFWL_Widget* pWidget,
76    CFX_WideString& wsCaption) {
77  wsCaption = m_wsData;
78  return FWL_ERR_Succeeded;
79}
80FWL_ERR CFWL_DateTimePicker::CFWL_DateTimePickerDP::GetToday(
81    IFWL_Widget* pWidget,
82    int32_t& iYear,
83    int32_t& iMonth,
84    int32_t& iDay) {
85  iYear = m_iYear;
86  iMonth = m_iMonth;
87  iDay = m_iDay;
88  return FWL_ERR_Succeeded;
89}
90FX_BOOL CFWL_DateTimePicker::CanUndo() {
91  return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanUndo();
92}
93FX_BOOL CFWL_DateTimePicker::CanRedo() {
94  return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanRedo();
95}
96FX_BOOL CFWL_DateTimePicker::Undo() {
97  return static_cast<IFWL_DateTimePicker*>(m_pIface)->Undo();
98}
99FX_BOOL CFWL_DateTimePicker::Redo() {
100  return static_cast<IFWL_DateTimePicker*>(m_pIface)->Redo();
101}
102FX_BOOL CFWL_DateTimePicker::CanCopy() {
103  return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanCopy();
104}
105FX_BOOL CFWL_DateTimePicker::CanCut() {
106  return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanCut();
107}
108FX_BOOL CFWL_DateTimePicker::CanSelectAll() {
109  return static_cast<IFWL_DateTimePicker*>(m_pIface)->CanSelectAll();
110}
111FX_BOOL CFWL_DateTimePicker::Copy(CFX_WideString& wsCopy) {
112  return static_cast<IFWL_DateTimePicker*>(m_pIface)->Copy(wsCopy);
113}
114FX_BOOL CFWL_DateTimePicker::Cut(CFX_WideString& wsCut) {
115  return static_cast<IFWL_DateTimePicker*>(m_pIface)->Copy(wsCut);
116}
117FX_BOOL CFWL_DateTimePicker::Paste(const CFX_WideString& wsPaste) {
118  return static_cast<IFWL_DateTimePicker*>(m_pIface)->Paste(wsPaste);
119}
120FX_BOOL CFWL_DateTimePicker::SelectAll() {
121  return static_cast<IFWL_DateTimePicker*>(m_pIface)->SelectAll();
122}
123FX_BOOL CFWL_DateTimePicker::Delete() {
124  return static_cast<IFWL_DateTimePicker*>(m_pIface)->Delete();
125}
126FX_BOOL CFWL_DateTimePicker::DeSelect() {
127  return static_cast<IFWL_DateTimePicker*>(m_pIface)->DeSelect();
128}
129FWL_ERR CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) {
130  return static_cast<IFWL_DateTimePicker*>(m_pIface)->GetBBox(rect);
131}
132FWL_ERR CFWL_DateTimePicker::SetEditLimit(int32_t nLimit) {
133  return static_cast<IFWL_DateTimePicker*>(m_pIface)->SetEditLimit(nLimit);
134}
135FWL_ERR CFWL_DateTimePicker::ModifyEditStylesEx(FX_DWORD dwStylesExAdded,
136                                                FX_DWORD dwStylesExRemoved) {
137  return static_cast<IFWL_DateTimePicker*>(m_pIface)
138      ->ModifyEditStylesEx(dwStylesExAdded, dwStylesExRemoved);
139}
140